2 * Copyright (C) 2010 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
27 #include "WebFrameProxy.h"
29 #include "WebCertificateInfo.h"
30 #include "WebContext.h"
31 #include "WebFormSubmissionListenerProxy.h"
32 #include "WebFramePolicyListenerProxy.h"
33 #include "WebPageMessages.h"
34 #include "WebPageProxy.h"
35 #include <WebCore/DOMImplementation.h>
36 #include <WebCore/Image.h>
38 #include <wtf/text/WTFString.h>
40 using namespace WebCore;
45 WebFrameProxy::WebFrameProxy(WebPageProxy* page, uint64_t frameID)
49 , m_previousSibling(0)
52 , m_loadState(LoadStateFinished)
56 WebContext::statistics().wkFrameCount++;
59 WebFrameProxy::~WebFrameProxy()
61 WebContext::statistics().wkFrameCount--;
64 void WebFrameProxy::disconnect()
69 m_previousSibling = 0;
73 if (m_activeListener) {
74 m_activeListener->invalidate();
79 bool WebFrameProxy::isMainFrame() const
84 return this == m_page->mainFrame();
87 void WebFrameProxy::stopLoading() const
92 if (!m_page->isValid())
95 m_page->process()->send(Messages::WebPage::StopLoadingFrame(m_frameID), m_page->pageID());
98 bool WebFrameProxy::canProvideSource() const
100 return isDisplayingMarkupDocument();
103 bool WebFrameProxy::canShowMIMEType(const String& mimeType) const
108 if (m_page->canShowMIMEType(mimeType))
112 // On Mac, we can show PDFs in the main frame.
113 if (isMainFrame() && !mimeType.isEmpty())
114 return WebContext::pdfAndPostScriptMIMETypes().contains(mimeType);
120 bool WebFrameProxy::isDisplayingStandaloneImageDocument() const
122 return Image::supportsType(m_MIMEType);
125 bool WebFrameProxy::isDisplayingMarkupDocument() const
127 // FIXME: This check should be moved to somewhere in WebCore.
128 // FIXME: This returns false when displaying a web archive.
129 return m_MIMEType == "text/html" || m_MIMEType == "image/svg+xml" || DOMImplementation::isXMLMIMEType(m_MIMEType);
132 void WebFrameProxy::didStartProvisionalLoad(const String& url)
134 ASSERT(m_loadState == LoadStateFinished);
135 ASSERT(m_provisionalURL.isEmpty());
136 m_loadState = LoadStateProvisional;
137 m_provisionalURL = url;
140 void WebFrameProxy::didReceiveServerRedirectForProvisionalLoad(const String& url)
142 ASSERT(m_loadState == LoadStateProvisional);
143 m_provisionalURL = url;
146 void WebFrameProxy::didFailProvisionalLoad()
148 ASSERT(m_loadState == LoadStateProvisional);
149 m_loadState = LoadStateFinished;
150 m_provisionalURL = String();
151 m_unreachableURL = m_lastUnreachableURL;
154 void WebFrameProxy::didCommitLoad(const String& contentType, const PlatformCertificateInfo& certificateInfo)
156 ASSERT(m_loadState == LoadStateProvisional);
157 m_loadState = LoadStateCommitted;
158 m_url = m_provisionalURL;
159 m_provisionalURL = String();
161 m_MIMEType = contentType;
162 m_isFrameSet = false;
163 m_certificateInfo = WebCertificateInfo::create(certificateInfo);
166 void WebFrameProxy::didFinishLoad()
168 ASSERT(m_loadState == LoadStateCommitted);
169 ASSERT(m_provisionalURL.isEmpty());
170 m_loadState = LoadStateFinished;
173 void WebFrameProxy::didFailLoad()
175 ASSERT(m_loadState == LoadStateCommitted);
176 ASSERT(m_provisionalURL.isEmpty());
177 m_loadState = LoadStateFinished;
181 void WebFrameProxy::didSameDocumentNavigation(const String& url)
186 void WebFrameProxy::didChangeTitle(const String& title)
191 void WebFrameProxy::appendChild(WebFrameProxy* child)
193 ASSERT(child->page() == page());
194 ASSERT(!child->m_parentFrame);
195 ASSERT(!child->m_nextSibling);
196 ASSERT(!child->m_previousSibling);
198 child->m_parentFrame = this;
200 WebFrameProxy* oldLast = m_lastChild;
204 ASSERT(!oldLast->m_nextSibling);
205 child->m_previousSibling = oldLast;
206 oldLast->m_nextSibling = child;
208 m_firstChild = child;
211 void WebFrameProxy::removeChild(WebFrameProxy* child)
213 child->m_parentFrame = 0;
215 WebFrameProxy*& newLocationForNext = m_firstChild == child ? m_firstChild : child->m_previousSibling->m_nextSibling;
216 WebFrameProxy*& newLocationForPrevious = m_lastChild == child ? m_lastChild : child->m_nextSibling->m_previousSibling;
217 swap(newLocationForNext, child->m_nextSibling);
218 swap(newLocationForPrevious, child->m_previousSibling);
219 child->m_previousSibling = 0;
220 child->m_nextSibling = 0;
223 bool WebFrameProxy::isDescendantOf(const WebFrameProxy* ancestor) const
228 if (m_page != ancestor->m_page)
231 for (const WebFrameProxy* frame = this; frame; frame = frame->m_parentFrame) {
232 if (frame == ancestor)
239 void WebFrameProxy::dumpFrameTreeToSTDOUT(unsigned indent)
241 if (!indent && m_parentFrame)
242 printf("NOTE: Printing subtree.\n");
244 for (unsigned i = 0; i < indent; ++i)
246 printf("| FRAME %d %s\n", (int)m_frameID, m_url.utf8().data());
248 for (WebFrameProxy* child = m_firstChild; child; child = child->m_nextSibling)
249 child->dumpFrameTreeToSTDOUT(indent + 4);
252 void WebFrameProxy::didRemoveFromHierarchy()
255 m_parentFrame->removeChild(this);
258 PassRefPtr<ImmutableArray> WebFrameProxy::childFrames()
261 return ImmutableArray::create();
263 Vector<RefPtr<APIObject> > vector;
264 for (WebFrameProxy* child = m_firstChild; child; child = child->m_nextSibling)
265 vector.append(child);
267 return ImmutableArray::adopt(vector);
270 void WebFrameProxy::receivedPolicyDecision(WebCore::PolicyAction action, uint64_t listenerID)
275 ASSERT(m_activeListener);
276 ASSERT(m_activeListener->listenerID() == listenerID);
277 m_page->receivedPolicyDecision(action, this, listenerID);
280 WebFramePolicyListenerProxy* WebFrameProxy::setUpPolicyListenerProxy(uint64_t listenerID)
282 if (m_activeListener)
283 m_activeListener->invalidate();
284 m_activeListener = WebFramePolicyListenerProxy::create(this, listenerID);
285 return static_cast<WebFramePolicyListenerProxy*>(m_activeListener.get());
288 WebFormSubmissionListenerProxy* WebFrameProxy::setUpFormSubmissionListenerProxy(uint64_t listenerID)
290 if (m_activeListener)
291 m_activeListener->invalidate();
292 m_activeListener = WebFormSubmissionListenerProxy::create(this, listenerID);
293 return static_cast<WebFormSubmissionListenerProxy*>(m_activeListener.get());
296 void WebFrameProxy::getWebArchive(PassRefPtr<DataCallback> callback)
299 callback->invalidate();
303 m_page->getWebArchiveOfFrame(this, callback);
306 void WebFrameProxy::getMainResourceData(PassRefPtr<DataCallback> callback)
309 callback->invalidate();
313 m_page->getMainResourceDataOfFrame(this, callback);
316 void WebFrameProxy::getResourceData(WebURL* resourceURL, PassRefPtr<DataCallback> callback)
319 callback->invalidate();
323 m_page->getResourceDataFromFrame(this, resourceURL, callback);
326 void WebFrameProxy::setUnreachableURL(const String& unreachableURL)
328 m_lastUnreachableURL = m_unreachableURL;
329 m_unreachableURL = unreachableURL;
332 } // namespace WebKit