2 * Copyright (C) 2010, 2011 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 "WebFormSubmissionListenerProxy.h"
31 #include "WebFramePolicyListenerProxy.h"
32 #include "WebPageMessages.h"
33 #include "WebPageProxy.h"
34 #include "WebPasteboardProxy.h"
35 #include "WebProcessPool.h"
36 #include <WebCore/Image.h>
37 #include <WebCore/MIMETypeRegistry.h>
39 #include <wtf/text/WTFString.h>
41 using namespace WebCore;
45 WebFrameProxy::WebFrameProxy(WebPageProxy* page, uint64_t frameID)
50 WebProcessPool::statistics().wkFrameCount++;
53 WebFrameProxy::~WebFrameProxy()
55 WebProcessPool::statistics().wkFrameCount--;
57 WebPasteboardProxy::singleton().didDestroyFrame(this);
61 void WebFrameProxy::webProcessWillShutDown()
65 if (m_activeListener) {
66 m_activeListener->invalidate();
67 m_activeListener = nullptr;
71 bool WebFrameProxy::isMainFrame() const
76 return this == m_page->mainFrame();
79 void WebFrameProxy::loadURL(const URL& url)
84 m_page->process().send(Messages::WebPage::LoadURLInFrame(url, m_frameID), m_page->pageID());
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 return m_page->canShowMIMEType(mimeType);
111 bool WebFrameProxy::isDisplayingStandaloneImageDocument() const
113 return Image::supportsType(m_MIMEType);
116 bool WebFrameProxy::isDisplayingStandaloneMediaDocument() const
118 return MIMETypeRegistry::isSupportedMediaMIMEType(m_MIMEType);
121 bool WebFrameProxy::isDisplayingMarkupDocument() const
123 // FIXME: This should be a call to a single MIMETypeRegistry function; adding a new one if needed.
124 // FIXME: This is doing case sensitive comparisons on MIME types, should be using ASCII case insensitive instead.
125 return m_MIMEType == "text/html" || m_MIMEType == "image/svg+xml" || m_MIMEType == "application/x-webarchive" || MIMETypeRegistry::isXMLMIMEType(m_MIMEType);
128 bool WebFrameProxy::isDisplayingPDFDocument() const
130 return MIMETypeRegistry::isPDFOrPostScriptMIMEType(m_MIMEType);
133 void WebFrameProxy::didStartProvisionalLoad(const URL& url)
135 m_frameLoadState.didStartProvisionalLoad(url);
138 void WebFrameProxy::didReceiveServerRedirectForProvisionalLoad(const URL& url)
140 m_frameLoadState.didReceiveServerRedirectForProvisionalLoad(url);
143 void WebFrameProxy::didFailProvisionalLoad()
145 m_frameLoadState.didFailProvisionalLoad();
148 void WebFrameProxy::didCommitLoad(const String& contentType, WebCertificateInfo& certificateInfo, bool containsPluginDocument)
150 m_frameLoadState.didCommitLoad();
153 m_MIMEType = contentType;
154 m_isFrameSet = false;
155 m_certificateInfo = &certificateInfo;
156 m_containsPluginDocument = containsPluginDocument;
159 void WebFrameProxy::didFinishLoad()
161 m_frameLoadState.didFinishLoad();
164 void WebFrameProxy::didFailLoad()
166 m_frameLoadState.didFailLoad();
169 void WebFrameProxy::didSameDocumentNavigation(const URL& url)
171 m_frameLoadState.didSameDocumentNotification(url);
174 void WebFrameProxy::didChangeTitle(const String& title)
179 void WebFrameProxy::receivedPolicyDecision(PolicyAction action, uint64_t listenerID, API::Navigation* navigation, const WebsitePolicies& websitePolicies)
184 ASSERT(m_activeListener);
185 ASSERT(m_activeListener->listenerID() == listenerID);
186 m_page->receivedPolicyDecision(action, *this, listenerID, navigation, websitePolicies);
189 WebFramePolicyListenerProxy& WebFrameProxy::setUpPolicyListenerProxy(uint64_t listenerID)
191 if (m_activeListener)
192 m_activeListener->invalidate();
193 m_activeListener = WebFramePolicyListenerProxy::create(this, listenerID);
194 return *static_cast<WebFramePolicyListenerProxy*>(m_activeListener.get());
197 WebFormSubmissionListenerProxy& WebFrameProxy::setUpFormSubmissionListenerProxy(uint64_t listenerID)
199 if (m_activeListener)
200 m_activeListener->invalidate();
201 m_activeListener = WebFormSubmissionListenerProxy::create(this, listenerID);
202 return *static_cast<WebFormSubmissionListenerProxy*>(m_activeListener.get());
205 void WebFrameProxy::getWebArchive(Function<void (API::Data*, CallbackBase::Error)>&& callbackFunction)
208 callbackFunction(nullptr, CallbackBase::Error::Unknown);
212 m_page->getWebArchiveOfFrame(this, WTFMove(callbackFunction));
215 void WebFrameProxy::getMainResourceData(Function<void (API::Data*, CallbackBase::Error)>&& callbackFunction)
218 callbackFunction(nullptr, CallbackBase::Error::Unknown);
222 m_page->getMainResourceDataOfFrame(this, WTFMove(callbackFunction));
225 void WebFrameProxy::getResourceData(API::URL* resourceURL, Function<void (API::Data*, CallbackBase::Error)>&& callbackFunction)
228 callbackFunction(nullptr, CallbackBase::Error::Unknown);
232 m_page->getResourceDataFromFrame(this, resourceURL, WTFMove(callbackFunction));
235 void WebFrameProxy::setUnreachableURL(const URL& unreachableURL)
237 m_frameLoadState.setUnreachableURL(unreachableURL);
240 #if ENABLE(CONTENT_FILTERING)
241 bool WebFrameProxy::didHandleContentFilterUnblockNavigation(const ResourceRequest& request)
243 if (!m_contentFilterUnblockHandler.canHandleRequest(request)) {
244 m_contentFilterUnblockHandler = { };
248 RefPtr<WebPageProxy> page { m_page };
250 m_contentFilterUnblockHandler.requestUnblockAsync([page](bool unblocked) {
259 void WebFrameProxy::collapseSelection()
264 m_page->process().send(Messages::WebPage::CollapseSelectionInFrame(m_frameID), m_page->pageID());
268 } // namespace WebKit