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 "WebFramePolicyListenerProxy.h"
31 #include "WebPageMessages.h"
32 #include "WebPageProxy.h"
33 #include "WebPasteboardProxy.h"
34 #include "WebProcessPool.h"
35 #include <WebCore/Image.h>
36 #include <WebCore/MIMETypeRegistry.h>
38 #include <wtf/text/WTFString.h>
40 using namespace WebCore;
44 WebFrameProxy::WebFrameProxy(WebPageProxy* page, uint64_t frameID)
49 WebProcessPool::statistics().wkFrameCount++;
52 WebFrameProxy::~WebFrameProxy()
54 WebProcessPool::statistics().wkFrameCount--;
56 WebPasteboardProxy::singleton().didDestroyFrame(this);
60 void WebFrameProxy::webProcessWillShutDown()
64 if (m_activeListener) {
65 m_activeListener->invalidate();
66 m_activeListener = nullptr;
70 bool WebFrameProxy::isMainFrame() const
75 return this == m_page->mainFrame();
78 void WebFrameProxy::loadURL(const URL& url)
83 m_page->process().send(Messages::WebPage::LoadURLInFrame(url, m_frameID), m_page->pageID());
86 void WebFrameProxy::stopLoading() const
91 if (!m_page->isValid())
94 m_page->process().send(Messages::WebPage::StopLoadingFrame(m_frameID), m_page->pageID());
97 bool WebFrameProxy::canProvideSource() const
99 return isDisplayingMarkupDocument();
102 bool WebFrameProxy::canShowMIMEType(const String& mimeType) const
107 return m_page->canShowMIMEType(mimeType);
110 bool WebFrameProxy::isDisplayingStandaloneImageDocument() const
112 return Image::supportsType(m_MIMEType);
115 bool WebFrameProxy::isDisplayingStandaloneMediaDocument() const
117 return MIMETypeRegistry::isSupportedMediaMIMEType(m_MIMEType);
120 bool WebFrameProxy::isDisplayingMarkupDocument() const
122 // FIXME: This should be a call to a single MIMETypeRegistry function; adding a new one if needed.
123 // FIXME: This is doing case sensitive comparisons on MIME types, should be using ASCII case insensitive instead.
124 return m_MIMEType == "text/html" || m_MIMEType == "image/svg+xml" || m_MIMEType == "application/x-webarchive" || MIMETypeRegistry::isXMLMIMEType(m_MIMEType);
127 bool WebFrameProxy::isDisplayingPDFDocument() const
129 return MIMETypeRegistry::isPDFOrPostScriptMIMEType(m_MIMEType);
132 void WebFrameProxy::didStartProvisionalLoad(const URL& url)
134 m_provisionalLoadRedirectChain = { url };
136 m_frameLoadState.didStartProvisionalLoad(url);
139 void WebFrameProxy::didReceiveServerRedirectForProvisionalLoad(const URL& url)
141 // didReceiveServerRedirectForProvisionalLoad() often gets called twice for the same redirect.
142 if (m_provisionalLoadRedirectChain.isEmpty() || m_provisionalLoadRedirectChain.last() != url)
143 m_provisionalLoadRedirectChain.append(url);
145 m_frameLoadState.didReceiveServerRedirectForProvisionalLoad(url);
148 void WebFrameProxy::didFailProvisionalLoad()
150 m_provisionalLoadRedirectChain.clear();
151 m_frameLoadState.didFailProvisionalLoad();
154 void WebFrameProxy::didCommitLoad(const String& contentType, WebCertificateInfo& certificateInfo, bool containsPluginDocument)
156 m_frameLoadState.didCommitLoad();
159 m_MIMEType = contentType;
160 m_isFrameSet = false;
161 m_certificateInfo = &certificateInfo;
162 m_containsPluginDocument = containsPluginDocument;
165 void WebFrameProxy::didFinishLoad()
167 m_provisionalLoadRedirectChain.clear();
168 m_frameLoadState.didFinishLoad();
171 void WebFrameProxy::didFailLoad()
173 m_provisionalLoadRedirectChain.clear();
174 m_frameLoadState.didFailLoad();
177 void WebFrameProxy::didSameDocumentNavigation(const URL& url)
179 m_frameLoadState.didSameDocumentNotification(url);
182 void WebFrameProxy::didChangeTitle(const String& title)
187 void WebFrameProxy::receivedPolicyDecision(PolicyAction action, uint64_t listenerID, API::Navigation* navigation, const WebsitePolicies& websitePolicies)
192 ASSERT(m_activeListener);
193 ASSERT(m_activeListener->listenerID() == listenerID);
194 m_page->receivedPolicyDecision(action, *this, listenerID, navigation, websitePolicies);
197 WebFramePolicyListenerProxy& WebFrameProxy::setUpPolicyListenerProxy(uint64_t listenerID)
199 if (m_activeListener)
200 m_activeListener->invalidate();
201 m_activeListener = WebFramePolicyListenerProxy::create(this, listenerID);
202 return *static_cast<WebFramePolicyListenerProxy*>(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