2 * Copyright (C) 2010, 2011, 2012 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 "WebFrameLoaderClient.h"
29 #include "AuthenticationManager.h"
30 #include "DataReference.h"
31 #include "DrawingArea.h"
32 #include "InjectedBundle.h"
33 #include "InjectedBundleBackForwardListItem.h"
34 #include "InjectedBundleDOMWindowExtension.h"
35 #include "InjectedBundleNavigationAction.h"
36 #include "InjectedBundleUserMessageCoders.h"
37 #include "NavigationActionData.h"
38 #include "PluginView.h"
39 #include "WKBundleAPICast.h"
40 #include "WebBackForwardListProxy.h"
41 #include "WebContextMessages.h"
42 #include "WebCoreArgumentCoders.h"
43 #include "WebDocumentLoader.h"
44 #include "WebErrors.h"
47 #include "WebFrameNetworkingContext.h"
48 #include "WebFullScreenManager.h"
49 #include "WebIconDatabaseMessages.h"
50 #include "WebNavigationDataStore.h"
52 #include "WebPageProxyMessages.h"
53 #include "WebProcess.h"
54 #include "WebProcessProxyMessages.h"
55 #include <JavaScriptCore/APICast.h>
56 #include <JavaScriptCore/JSObject.h>
57 #include <WebCore/CertificateInfo.h>
58 #include <WebCore/Chrome.h>
59 #include <WebCore/DOMWrapperWorld.h>
60 #include <WebCore/DocumentLoader.h>
61 #include <WebCore/FormState.h>
62 #include <WebCore/FrameLoadRequest.h>
63 #include <WebCore/FrameLoader.h>
64 #include <WebCore/FrameView.h>
65 #include <WebCore/HTMLAppletElement.h>
66 #include <WebCore/HTMLFormElement.h>
67 #include <WebCore/HistoryController.h>
68 #include <WebCore/HistoryItem.h>
69 #include <WebCore/MIMETypeRegistry.h>
70 #include <WebCore/MainFrame.h>
71 #include <WebCore/MouseEvent.h>
72 #include <WebCore/NotImplemented.h>
73 #include <WebCore/Page.h>
74 #include <WebCore/PluginData.h>
75 #include <WebCore/PluginDocument.h>
76 #include <WebCore/ProgressTracker.h>
77 #include <WebCore/ResourceBuffer.h>
78 #include <WebCore/ResourceError.h>
79 #include <WebCore/ScriptController.h>
80 #include <WebCore/Settings.h>
81 #include <WebCore/SubframeLoader.h>
82 #include <WebCore/UIEventWithKeyState.h>
83 #include <WebCore/Widget.h>
84 #include <WebCore/WindowFeatures.h>
85 #include <wtf/NeverDestroyed.h>
87 using namespace WebCore;
91 WebFrameLoaderClient::WebFrameLoaderClient()
93 , m_hasSentResponseToPluginView(false)
94 , m_didCompletePageTransition(false)
95 , m_frameHasCustomContentProvider(false)
96 , m_frameCameFromPageCache(false)
100 WebFrameLoaderClient::~WebFrameLoaderClient()
104 void WebFrameLoaderClient::frameLoaderDestroyed()
106 if (WebPage* webPage = m_frame->page())
107 webPage->injectedBundleLoaderClient().willDestroyFrame(webPage, m_frame);
109 m_frame->invalidate();
111 // Balances explicit ref() in WebFrame::create().
115 bool WebFrameLoaderClient::hasHTMLView() const
117 return !m_frameHasCustomContentProvider;
120 bool WebFrameLoaderClient::hasWebView() const
122 return m_frame->page();
125 void WebFrameLoaderClient::makeRepresentation(DocumentLoader*)
130 void WebFrameLoaderClient::forceLayoutForNonHTML()
135 void WebFrameLoaderClient::setCopiesOnScroll()
140 void WebFrameLoaderClient::detachedFromParent2()
142 WebPage* webPage = m_frame->page();
146 RefPtr<API::Object> userData;
148 // Notify the bundle client.
149 webPage->injectedBundleLoaderClient().didRemoveFrameFromHierarchy(webPage, m_frame, userData);
151 // Notify the UIProcess.
152 webPage->send(Messages::WebPageProxy::DidRemoveFrameFromHierarchy(m_frame->frameID(), InjectedBundleUserMessageEncoder(userData.get())));
156 void WebFrameLoaderClient::detachedFromParent3()
161 void WebFrameLoaderClient::assignIdentifierToInitialRequest(unsigned long identifier, DocumentLoader* loader, const ResourceRequest& request)
163 WebPage* webPage = m_frame->page();
167 bool pageIsProvisionallyLoading = false;
168 if (FrameLoader* frameLoader = loader->frameLoader())
169 pageIsProvisionallyLoading = frameLoader->provisionalDocumentLoader() == loader;
171 webPage->injectedBundleResourceLoadClient().didInitiateLoadForResource(webPage, m_frame, identifier, request, pageIsProvisionallyLoading);
172 webPage->addResourceRequest(identifier, request);
175 void WebFrameLoaderClient::dispatchWillSendRequest(DocumentLoader*, unsigned long identifier, ResourceRequest& request, const ResourceResponse& redirectResponse)
177 WebPage* webPage = m_frame->page();
181 webPage->injectedBundleResourceLoadClient().willSendRequestForFrame(webPage, m_frame, identifier, request, redirectResponse);
184 bool WebFrameLoaderClient::shouldUseCredentialStorage(DocumentLoader*, unsigned long identifier)
186 WebPage* webPage = m_frame->page();
190 return webPage->injectedBundleResourceLoadClient().shouldUseCredentialStorage(webPage, m_frame, identifier);
193 void WebFrameLoaderClient::dispatchDidReceiveAuthenticationChallenge(DocumentLoader*, unsigned long, const AuthenticationChallenge& challenge)
195 // FIXME: Authentication is a per-resource concept, but we don't do per-resource handling in the UIProcess at the API level quite yet.
196 // Once we do, we might need to make sure authentication fits with our solution.
198 WebPage* webPage = m_frame->page();
202 WebProcess::shared().supplement<AuthenticationManager>()->didReceiveAuthenticationChallenge(m_frame, challenge);
205 void WebFrameLoaderClient::dispatchDidCancelAuthenticationChallenge(DocumentLoader*, unsigned long /*identifier*/, const AuthenticationChallenge&)
210 #if USE(PROTECTION_SPACE_AUTH_CALLBACK)
211 bool WebFrameLoaderClient::canAuthenticateAgainstProtectionSpace(DocumentLoader*, unsigned long, const ProtectionSpace& protectionSpace)
213 // FIXME: Authentication is a per-resource concept, but we don't do per-resource handling in the UIProcess at the API level quite yet.
214 // Once we do, we might need to make sure authentication fits with our solution.
216 WebPage* webPage = m_frame->page();
220 bool canAuthenticate;
221 if (!webPage->sendSync(Messages::WebPageProxy::CanAuthenticateAgainstProtectionSpaceInFrame(m_frame->frameID(), protectionSpace), Messages::WebPageProxy::CanAuthenticateAgainstProtectionSpaceInFrame::Reply(canAuthenticate)))
224 return canAuthenticate;
228 void WebFrameLoaderClient::dispatchDidReceiveResponse(DocumentLoader*, unsigned long identifier, const ResourceResponse& response)
230 WebPage* webPage = m_frame->page();
234 webPage->injectedBundleResourceLoadClient().didReceiveResponseForResource(webPage, m_frame, identifier, response);
237 void WebFrameLoaderClient::dispatchDidReceiveContentLength(DocumentLoader*, unsigned long identifier, int dataLength)
239 WebPage* webPage = m_frame->page();
243 webPage->injectedBundleResourceLoadClient().didReceiveContentLengthForResource(webPage, m_frame, identifier, dataLength);
246 void WebFrameLoaderClient::dispatchDidFinishLoading(DocumentLoader*, unsigned long identifier)
248 WebPage* webPage = m_frame->page();
252 webPage->injectedBundleResourceLoadClient().didFinishLoadForResource(webPage, m_frame, identifier);
253 webPage->removeResourceRequest(identifier);
256 void WebFrameLoaderClient::dispatchDidFailLoading(DocumentLoader*, unsigned long identifier, const ResourceError& error)
258 WebPage* webPage = m_frame->page();
262 webPage->injectedBundleResourceLoadClient().didFailLoadForResource(webPage, m_frame, identifier, error);
263 webPage->removeResourceRequest(identifier);
266 bool WebFrameLoaderClient::dispatchDidLoadResourceFromMemoryCache(DocumentLoader*, const ResourceRequest&, const ResourceResponse&, int /*length*/)
272 void WebFrameLoaderClient::dispatchDidHandleOnloadEvents()
274 WebPage* webPage = m_frame->page();
278 // Notify the bundle client.
279 webPage->injectedBundleLoaderClient().didHandleOnloadEventsForFrame(webPage, m_frame);
282 void WebFrameLoaderClient::dispatchDidReceiveServerRedirectForProvisionalLoad()
284 WebPage* webPage = m_frame->page();
288 WebDocumentLoader& documentLoader = static_cast<WebDocumentLoader&>(*m_frame->coreFrame()->loader().provisionalDocumentLoader());
289 const String& url = documentLoader.url().string();
290 RefPtr<API::Object> userData;
292 // Notify the bundle client.
293 webPage->injectedBundleLoaderClient().didReceiveServerRedirectForProvisionalLoadForFrame(webPage, m_frame, userData);
295 // Notify the UIProcess.
296 webPage->send(Messages::WebPageProxy::DidReceiveServerRedirectForProvisionalLoadForFrame(m_frame->frameID(), documentLoader.navigationID(), url, InjectedBundleUserMessageEncoder(userData.get())));
299 void WebFrameLoaderClient::dispatchDidCancelClientRedirect()
301 WebPage* webPage = m_frame->page();
305 // Notify the bundle client.
306 webPage->injectedBundleLoaderClient().didCancelClientRedirectForFrame(webPage, m_frame);
309 void WebFrameLoaderClient::dispatchWillPerformClientRedirect(const URL& url, double interval, double fireDate)
311 WebPage* webPage = m_frame->page();
315 // Notify the bundle client.
316 webPage->injectedBundleLoaderClient().willPerformClientRedirectForFrame(webPage, m_frame, url.string(), interval, fireDate);
319 void WebFrameLoaderClient::dispatchDidChangeLocationWithinPage()
321 WebPage* webPage = m_frame->page();
325 RefPtr<API::Object> userData;
327 // Notify the bundle client.
328 webPage->injectedBundleLoaderClient().didSameDocumentNavigationForFrame(webPage, m_frame, SameDocumentNavigationAnchorNavigation, userData);
330 // Notify the UIProcess.
331 WebDocumentLoader& documentLoader = static_cast<WebDocumentLoader&>(*m_frame->coreFrame()->loader().documentLoader());
332 webPage->send(Messages::WebPageProxy::DidSameDocumentNavigationForFrame(m_frame->frameID(), documentLoader.navigationID(), SameDocumentNavigationAnchorNavigation, m_frame->coreFrame()->document()->url().string(), InjectedBundleUserMessageEncoder(userData.get())));
335 void WebFrameLoaderClient::dispatchDidPushStateWithinPage()
337 WebPage* webPage = m_frame->page();
341 RefPtr<API::Object> userData;
343 // Notify the bundle client.
344 webPage->injectedBundleLoaderClient().didSameDocumentNavigationForFrame(webPage, m_frame, SameDocumentNavigationSessionStatePush, userData);
346 // Notify the UIProcess.
347 WebDocumentLoader& documentLoader = static_cast<WebDocumentLoader&>(*m_frame->coreFrame()->loader().documentLoader());
348 webPage->send(Messages::WebPageProxy::DidSameDocumentNavigationForFrame(m_frame->frameID(), documentLoader.navigationID(), SameDocumentNavigationSessionStatePush, m_frame->coreFrame()->document()->url().string(), InjectedBundleUserMessageEncoder(userData.get())));
351 void WebFrameLoaderClient::dispatchDidReplaceStateWithinPage()
353 WebPage* webPage = m_frame->page();
357 RefPtr<API::Object> userData;
359 // Notify the bundle client.
360 webPage->injectedBundleLoaderClient().didSameDocumentNavigationForFrame(webPage, m_frame, SameDocumentNavigationSessionStateReplace, userData);
362 // Notify the UIProcess.
363 WebDocumentLoader& documentLoader = static_cast<WebDocumentLoader&>(*m_frame->coreFrame()->loader().documentLoader());
364 webPage->send(Messages::WebPageProxy::DidSameDocumentNavigationForFrame(m_frame->frameID(), documentLoader.navigationID(), SameDocumentNavigationSessionStateReplace, m_frame->coreFrame()->document()->url().string(), InjectedBundleUserMessageEncoder(userData.get())));
367 void WebFrameLoaderClient::dispatchDidPopStateWithinPage()
369 WebPage* webPage = m_frame->page();
373 RefPtr<API::Object> userData;
375 // Notify the bundle client.
376 webPage->injectedBundleLoaderClient().didSameDocumentNavigationForFrame(webPage, m_frame, SameDocumentNavigationSessionStatePop, userData);
378 // Notify the UIProcess.
379 WebDocumentLoader& documentLoader = static_cast<WebDocumentLoader&>(*m_frame->coreFrame()->loader().documentLoader());
380 webPage->send(Messages::WebPageProxy::DidSameDocumentNavigationForFrame(m_frame->frameID(), documentLoader.navigationID(), SameDocumentNavigationSessionStatePop, m_frame->coreFrame()->document()->url().string(), InjectedBundleUserMessageEncoder(userData.get())));
383 void WebFrameLoaderClient::dispatchWillClose()
388 void WebFrameLoaderClient::dispatchDidReceiveIcon()
390 WebProcess::shared().parentProcessConnection()->send(Messages::WebIconDatabase::DidReceiveIconForPageURL(m_frame->url()), 0);
393 void WebFrameLoaderClient::dispatchDidStartProvisionalLoad()
395 WebPage* webPage = m_frame->page();
399 #if ENABLE(FULLSCREEN_API)
400 Element* documentElement = m_frame->coreFrame()->document()->documentElement();
401 if (documentElement && documentElement->containsFullScreenElement())
402 webPage->fullScreenManager()->exitFullScreenForElement(webPage->fullScreenManager()->element());
405 webPage->findController().hideFindUI();
406 webPage->sandboxExtensionTracker().didStartProvisionalLoad(m_frame);
408 WebDocumentLoader& provisionalLoader = static_cast<WebDocumentLoader&>(*m_frame->coreFrame()->loader().provisionalDocumentLoader());
409 const String& url = provisionalLoader.url().string();
410 RefPtr<API::Object> userData;
412 // Notify the bundle client.
413 webPage->injectedBundleLoaderClient().didStartProvisionalLoadForFrame(webPage, m_frame, userData);
415 String unreachableURL = provisionalLoader.unreachableURL().string();
417 // Notify the UIProcess.
418 webPage->send(Messages::WebPageProxy::DidStartProvisionalLoadForFrame(m_frame->frameID(), provisionalLoader.navigationID(), url, unreachableURL, InjectedBundleUserMessageEncoder(userData.get())));
421 void WebFrameLoaderClient::dispatchDidReceiveTitle(const StringWithDirection& title)
423 WebPage* webPage = m_frame->page();
427 RefPtr<API::Object> userData;
429 // Notify the bundle client.
430 // FIXME: use direction of title.
431 webPage->injectedBundleLoaderClient().didReceiveTitleForFrame(webPage, title.string(), m_frame, userData);
433 // Notify the UIProcess.
434 webPage->send(Messages::WebPageProxy::DidReceiveTitleForFrame(m_frame->frameID(), title.string(), InjectedBundleUserMessageEncoder(userData.get())));
437 void WebFrameLoaderClient::dispatchDidChangeIcons(WebCore::IconType)
442 void WebFrameLoaderClient::dispatchDidCommitLoad()
444 WebPage* webPage = m_frame->page();
448 WebDocumentLoader& documentLoader = static_cast<WebDocumentLoader&>(*m_frame->coreFrame()->loader().documentLoader());
449 RefPtr<API::Object> userData;
451 // Notify the bundle client.
452 webPage->injectedBundleLoaderClient().didCommitLoadForFrame(webPage, m_frame, userData);
454 webPage->sandboxExtensionTracker().didCommitProvisionalLoad(m_frame);
456 // Notify the UIProcess.
458 webPage->send(Messages::WebPageProxy::DidCommitLoadForFrame(m_frame->frameID(), documentLoader.navigationID(), documentLoader.response().mimeType(), m_frameHasCustomContentProvider, static_cast<uint32_t>(m_frame->coreFrame()->loader().loadType()), CertificateInfo(documentLoader.response()), InjectedBundleUserMessageEncoder(userData.get())));
459 webPage->didCommitLoad(m_frame);
462 void WebFrameLoaderClient::dispatchDidFailProvisionalLoad(const ResourceError& error)
464 WebPage* webPage = m_frame->page();
468 RefPtr<API::Object> userData;
470 uint64_t navigationID = static_cast<WebDocumentLoader*>(m_frame->coreFrame()->loader().provisionalDocumentLoader())->navigationID();
472 // Notify the bundle client.
473 webPage->injectedBundleLoaderClient().didFailProvisionalLoadWithErrorForFrame(webPage, m_frame, error, userData);
475 webPage->sandboxExtensionTracker().didFailProvisionalLoad(m_frame);
477 // Notify the UIProcess.
478 webPage->send(Messages::WebPageProxy::DidFailProvisionalLoadForFrame(m_frame->frameID(), navigationID, error, InjectedBundleUserMessageEncoder(userData.get())));
480 // If we have a load listener, notify it.
481 if (WebFrame::LoadListener* loadListener = m_frame->loadListener())
482 loadListener->didFailLoad(m_frame, error.isCancellation());
485 void WebFrameLoaderClient::dispatchDidFailLoad(const ResourceError& error)
487 WebPage* webPage = m_frame->page();
491 RefPtr<API::Object> userData;
493 // Notify the bundle client.
494 webPage->injectedBundleLoaderClient().didFailLoadWithErrorForFrame(webPage, m_frame, error, userData);
496 // Notify the UIProcess.
497 WebDocumentLoader& documentLoader = static_cast<WebDocumentLoader&>(*m_frame->coreFrame()->loader().documentLoader());
498 webPage->send(Messages::WebPageProxy::DidFailLoadForFrame(m_frame->frameID(), documentLoader.navigationID(), error, InjectedBundleUserMessageEncoder(userData.get())));
500 // If we have a load listener, notify it.
501 if (WebFrame::LoadListener* loadListener = m_frame->loadListener())
502 loadListener->didFailLoad(m_frame, error.isCancellation());
505 void WebFrameLoaderClient::dispatchDidFinishDocumentLoad()
507 WebPage* webPage = m_frame->page();
511 webPage->didFinishDocumentLoad(m_frame);
513 RefPtr<API::Object> userData;
515 // Notify the bundle client.
516 webPage->injectedBundleLoaderClient().didFinishDocumentLoadForFrame(webPage, m_frame, userData);
518 WebDocumentLoader& documentLoader = static_cast<WebDocumentLoader&>(*m_frame->coreFrame()->loader().documentLoader());
520 // Notify the UIProcess.
521 webPage->send(Messages::WebPageProxy::DidFinishDocumentLoadForFrame(m_frame->frameID(), documentLoader.navigationID(), InjectedBundleUserMessageEncoder(userData.get())));
524 void WebFrameLoaderClient::dispatchDidFinishLoad()
526 WebPage* webPage = m_frame->page();
530 RefPtr<API::Object> userData;
532 // Notify the bundle client.
533 webPage->injectedBundleLoaderClient().didFinishLoadForFrame(webPage, m_frame, userData);
535 WebDocumentLoader& documentLoader = static_cast<WebDocumentLoader&>(*m_frame->coreFrame()->loader().documentLoader());
537 // Notify the UIProcess.
538 webPage->send(Messages::WebPageProxy::DidFinishLoadForFrame(m_frame->frameID(), documentLoader.navigationID(), InjectedBundleUserMessageEncoder(userData.get())));
540 // If we have a load listener, notify it.
541 if (WebFrame::LoadListener* loadListener = m_frame->loadListener())
542 loadListener->didFinishLoad(m_frame);
544 webPage->didFinishLoad(m_frame);
547 void WebFrameLoaderClient::forcePageTransitionIfNeeded()
549 if (m_didCompletePageTransition)
552 WebPage* webPage = m_frame->page();
556 webPage->didCompletePageTransition();
557 m_didCompletePageTransition = true;
560 void WebFrameLoaderClient::dispatchDidLayout(LayoutMilestones milestones)
562 WebPage* webPage = m_frame->page();
566 RefPtr<API::Object> userData;
568 if (milestones & DidFirstLayout) {
569 // FIXME: We should consider removing the old didFirstLayout API since this is doing double duty with the
570 // new didLayout API.
571 webPage->injectedBundleLoaderClient().didFirstLayoutForFrame(webPage, m_frame, userData);
572 webPage->send(Messages::WebPageProxy::DidFirstLayoutForFrame(m_frame->frameID(), InjectedBundleUserMessageEncoder(userData.get())));
575 // FIXME: Do this on DidFirstVisuallyNonEmptyLayout when Mac Safari is able to handle it (<rdar://problem/17580021>)
576 if (m_frame->isMainFrame() && !m_didCompletePageTransition && !webPage->corePage()->settings().suppressesIncrementalRendering()) {
577 webPage->didCompletePageTransition();
578 m_didCompletePageTransition = true;
582 #if USE(TILED_BACKING_STORE)
583 // Make sure viewport properties are dispatched on the main frame by the time the first layout happens.
584 ASSERT(!webPage->useFixedLayout() || m_frame != m_frame->page()->mainWebFrame() || m_frame->coreFrame()->document()->didDispatchViewportPropertiesChanged());
588 // Send this after DidFirstLayout-specific calls since some clients expect to get those messages first.
589 webPage->injectedBundleLoaderClient().didLayout(webPage, milestones, userData);
590 webPage->send(Messages::WebPageProxy::DidLayout(milestones, InjectedBundleUserMessageEncoder(userData.get())));
592 if (milestones & DidFirstVisuallyNonEmptyLayout) {
593 if (m_frame->isMainFrame() && !m_didCompletePageTransition && !webPage->corePage()->settings().suppressesIncrementalRendering()) {
594 webPage->didCompletePageTransition();
595 m_didCompletePageTransition = true;
598 // FIXME: We should consider removing the old didFirstVisuallyNonEmptyLayoutForFrame API since this is doing
599 // double duty with the new didLayout API.
600 webPage->injectedBundleLoaderClient().didFirstVisuallyNonEmptyLayoutForFrame(webPage, m_frame, userData);
601 webPage->send(Messages::WebPageProxy::DidFirstVisuallyNonEmptyLayoutForFrame(m_frame->frameID(), InjectedBundleUserMessageEncoder(userData.get())));
605 void WebFrameLoaderClient::dispatchDidLayout()
607 WebPage* webPage = m_frame->page();
611 // Notify the bundle client.
612 webPage->injectedBundleLoaderClient().didLayoutForFrame(webPage, m_frame);
614 webPage->recomputeShortCircuitHorizontalWheelEventsState();
617 webPage->updateSelectionAppearance();
620 // NOTE: Unlike the other layout notifications, this does not notify the
621 // the UIProcess for every call.
623 if (m_frame == m_frame->page()->mainWebFrame()) {
624 // FIXME: Remove at the soonest possible time.
625 webPage->send(Messages::WebPageProxy::SetRenderTreeSize(webPage->renderTreeSize()));
626 webPage->mainFrameDidLayout();
630 Frame* WebFrameLoaderClient::dispatchCreatePage(const NavigationAction& navigationAction)
632 WebPage* webPage = m_frame->page();
636 // Just call through to the chrome client.
637 Page* newPage = webPage->corePage()->chrome().createWindow(m_frame->coreFrame(), FrameLoadRequest(m_frame->coreFrame()->document()->securityOrigin(), navigationAction.resourceRequest()), WindowFeatures(), navigationAction);
641 return &newPage->mainFrame();
644 void WebFrameLoaderClient::dispatchShow()
646 WebPage* webPage = m_frame->page();
653 void WebFrameLoaderClient::dispatchDecidePolicyForResponse(const ResourceResponse& response, const ResourceRequest& request, FramePolicyFunction function)
655 WebPage* webPage = m_frame->page();
659 if (!request.url().string()) {
664 RefPtr<API::Object> userData;
666 // Notify the bundle client.
667 WKBundlePagePolicyAction policy = webPage->injectedBundlePolicyClient().decidePolicyForResponse(webPage, m_frame, response, request, userData);
668 if (policy == WKBundlePagePolicyActionUse) {
673 bool canShowMIMEType = webPage->canShowMIMEType(response.mimeType());
675 uint64_t listenerID = m_frame->setUpPolicyListener(WTF::move(function));
676 bool receivedPolicyAction;
677 uint64_t policyAction;
680 unsigned syncSendFlags = IPC::InformPlatformProcessWillSuspend;
681 if (WebPage::synchronousMessagesShouldSpinRunLoop())
682 syncSendFlags |= IPC::SpinRunLoopWhileWaitingForReply;
683 if (!webPage->sendSync(Messages::WebPageProxy::DecidePolicyForResponseSync(m_frame->frameID(), response, request, canShowMIMEType, listenerID, InjectedBundleUserMessageEncoder(userData.get())), Messages::WebPageProxy::DecidePolicyForResponseSync::Reply(receivedPolicyAction, policyAction, downloadID), std::chrono::milliseconds::max(), syncSendFlags))
686 // We call this synchronously because CFNetwork can only convert a loading connection to a download from its didReceiveResponse callback.
687 if (receivedPolicyAction)
688 m_frame->didReceivePolicyDecision(listenerID, static_cast<PolicyAction>(policyAction), 0, downloadID);
691 void WebFrameLoaderClient::dispatchDecidePolicyForNewWindowAction(const NavigationAction& navigationAction, const ResourceRequest& request, PassRefPtr<FormState> formState, const String& frameName, FramePolicyFunction function)
693 WebPage* webPage = m_frame->page();
697 RefPtr<API::Object> userData;
699 RefPtr<InjectedBundleNavigationAction> action = InjectedBundleNavigationAction::create(m_frame, navigationAction, formState);
701 // Notify the bundle client.
702 WKBundlePagePolicyAction policy = webPage->injectedBundlePolicyClient().decidePolicyForNewWindowAction(webPage, m_frame, action.get(), request, frameName, userData);
703 if (policy == WKBundlePagePolicyActionUse) {
709 uint64_t listenerID = m_frame->setUpPolicyListener(WTF::move(function));
711 NavigationActionData navigationActionData;
712 navigationActionData.navigationType = action->navigationType();
713 navigationActionData.modifiers = action->modifiers();
714 navigationActionData.mouseButton = action->mouseButton();
715 navigationActionData.isProcessingUserGesture = navigationAction.processingUserGesture();
716 navigationActionData.canHandleRequest = webPage->canHandleRequest(request);
718 webPage->send(Messages::WebPageProxy::DecidePolicyForNewWindowAction(m_frame->frameID(), navigationActionData, request, frameName, listenerID, InjectedBundleUserMessageEncoder(userData.get())));
721 void WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction(const NavigationAction& navigationAction, const ResourceRequest& request, PassRefPtr<FormState> prpFormState, FramePolicyFunction function)
723 WebPage* webPage = m_frame->page();
727 // Always ignore requests with empty URLs.
728 if (request.isEmpty()) {
729 function(PolicyIgnore);
733 RefPtr<API::Object> userData;
734 RefPtr<FormState> formState = prpFormState;
736 RefPtr<InjectedBundleNavigationAction> action = InjectedBundleNavigationAction::create(m_frame, navigationAction, formState);
738 // Notify the bundle client.
739 WKBundlePagePolicyAction policy = webPage->injectedBundlePolicyClient().decidePolicyForNavigationAction(webPage, m_frame, action.get(), request, userData);
740 if (policy == WKBundlePagePolicyActionUse) {
745 uint64_t listenerID = m_frame->setUpPolicyListener(WTF::move(function));
746 bool receivedPolicyAction;
747 uint64_t newNavigationID;
748 uint64_t policyAction;
751 RefPtr<WebFrame> originatingFrame;
752 switch (action->navigationType()) {
753 case NavigationTypeLinkClicked:
754 if (EventTarget* target = navigationAction.event()->target()) {
755 if (Node* node = target->toNode()) {
756 if (Frame* frame = node->document().frame())
757 originatingFrame = WebFrame::fromCoreFrame(*frame);
761 case NavigationTypeFormSubmitted:
762 case NavigationTypeFormResubmitted:
764 originatingFrame = WebFrame::fromCoreFrame(*formState->sourceDocument()->frame());
766 case NavigationTypeBackForward:
767 case NavigationTypeReload:
768 case NavigationTypeOther:
772 NavigationActionData navigationActionData;
773 navigationActionData.navigationType = action->navigationType();
774 navigationActionData.modifiers = action->modifiers();
775 navigationActionData.mouseButton = action->mouseButton();
776 navigationActionData.isProcessingUserGesture = navigationAction.processingUserGesture();
777 navigationActionData.canHandleRequest = webPage->canHandleRequest(request);
779 WebCore::Frame* coreFrame = m_frame->coreFrame();
780 WebDocumentLoader* documentLoader = static_cast<WebDocumentLoader*>(coreFrame->loader().policyDocumentLoader());
782 documentLoader = static_cast<WebDocumentLoader*>(coreFrame->loader().documentLoader());
784 // Notify the UIProcess.
785 if (!webPage->sendSync(Messages::WebPageProxy::DecidePolicyForNavigationAction(m_frame->frameID(), documentLoader->navigationID(), navigationActionData, originatingFrame ? originatingFrame->frameID() : 0, navigationAction.resourceRequest(), request, listenerID, InjectedBundleUserMessageEncoder(userData.get())), Messages::WebPageProxy::DecidePolicyForNavigationAction::Reply(receivedPolicyAction, newNavigationID, policyAction, downloadID)))
788 // We call this synchronously because WebCore cannot gracefully handle a frame load without a synchronous navigation policy reply.
789 if (receivedPolicyAction)
790 m_frame->didReceivePolicyDecision(listenerID, static_cast<PolicyAction>(policyAction), newNavigationID, downloadID);
793 void WebFrameLoaderClient::cancelPolicyCheck()
795 m_frame->invalidatePolicyListener();
798 void WebFrameLoaderClient::dispatchUnableToImplementPolicy(const ResourceError& error)
800 WebPage* webPage = m_frame->page();
804 RefPtr<API::Object> userData;
806 // Notify the bundle client.
807 webPage->injectedBundlePolicyClient().unableToImplementPolicy(webPage, m_frame, error, userData);
809 // Notify the UIProcess.
810 webPage->send(Messages::WebPageProxy::UnableToImplementPolicy(m_frame->frameID(), error, InjectedBundleUserMessageEncoder(userData.get())));
813 void WebFrameLoaderClient::dispatchWillSendSubmitEvent(PassRefPtr<FormState> prpFormState)
815 WebPage* webPage = m_frame->page();
819 RefPtr<FormState> formState = prpFormState;
820 HTMLFormElement* form = formState->form();
822 WebFrame* sourceFrame = WebFrame::fromCoreFrame(*formState->sourceDocument()->frame());
825 webPage->injectedBundleFormClient().willSendSubmitEvent(webPage, form, m_frame, sourceFrame, formState->textFieldValues());
828 void WebFrameLoaderClient::dispatchWillSubmitForm(PassRefPtr<FormState> prpFormState, FramePolicyFunction function)
830 WebPage* webPage = m_frame->page();
834 // FIXME: Pass more of the form state.
835 RefPtr<FormState> formState = prpFormState;
837 HTMLFormElement* form = formState->form();
839 WebFrame* sourceFrame = WebFrame::fromCoreFrame(*formState->sourceDocument()->frame());
842 const Vector<std::pair<String, String>>& values = formState->textFieldValues();
844 RefPtr<API::Object> userData;
845 webPage->injectedBundleFormClient().willSubmitForm(webPage, form, m_frame, sourceFrame, values, userData);
848 uint64_t listenerID = m_frame->setUpPolicyListener(WTF::move(function));
850 webPage->send(Messages::WebPageProxy::WillSubmitForm(m_frame->frameID(), sourceFrame->frameID(), values, listenerID, InjectedBundleUserMessageEncoder(userData.get())));
853 void WebFrameLoaderClient::revertToProvisionalState(DocumentLoader*)
858 void WebFrameLoaderClient::setMainDocumentError(DocumentLoader*, const ResourceError& error)
863 m_pluginView->manualLoadDidFail(error);
864 m_pluginView = nullptr;
865 m_hasSentResponseToPluginView = false;
868 void WebFrameLoaderClient::setMainFrameDocumentReady(bool)
873 void WebFrameLoaderClient::startDownload(const ResourceRequest& request, const String& /* suggestedName */)
875 m_frame->startDownload(request);
878 void WebFrameLoaderClient::willChangeTitle(DocumentLoader*)
883 void WebFrameLoaderClient::didChangeTitle(DocumentLoader*)
888 void WebFrameLoaderClient::committedLoad(DocumentLoader* loader, const char* data, int length)
890 // If we're loading a custom representation, we don't want to hand off the data to WebCore.
891 if (m_frameHasCustomContentProvider)
895 loader->commitData(data, length);
897 // If the document is a stand-alone media document, now is the right time to cancel the WebKit load.
898 // FIXME: This code should be shared across all ports. <http://webkit.org/b/48762>.
899 if (m_frame->coreFrame()->document()->isMediaDocument())
900 loader->cancelMainResourceLoad(pluginWillHandleLoadError(loader->response()));
902 // Calling commitData did not create the plug-in view.
906 if (!m_hasSentResponseToPluginView) {
907 m_pluginView->manualLoadDidReceiveResponse(loader->response());
908 // manualLoadDidReceiveResponse sets up a new stream to the plug-in. on a full-page plug-in, a failure in
909 // setting up this stream can cause the main document load to be cancelled, setting m_pluginView
913 m_hasSentResponseToPluginView = true;
915 m_pluginView->manualLoadDidReceiveData(data, length);
918 void WebFrameLoaderClient::finishedLoading(DocumentLoader* loader)
921 if (m_frameHasCustomContentProvider) {
922 WebPage* webPage = m_frame->page();
926 RefPtr<ResourceBuffer> mainResourceData = loader->mainResourceData();
927 IPC::DataReference dataReference(reinterpret_cast<const uint8_t*>(mainResourceData ? mainResourceData->data() : 0), mainResourceData ? mainResourceData->size() : 0);
928 webPage->send(Messages::WebPageProxy::DidFinishLoadingDataForCustomContentProvider(loader->response().suggestedFilename(), dataReference));
934 // If we just received an empty response without any data, we won't have sent a response to the plug-in view.
935 // Make sure to do this before calling manualLoadDidFinishLoading.
936 if (!m_hasSentResponseToPluginView) {
937 m_pluginView->manualLoadDidReceiveResponse(loader->response());
939 // Protect against the above call nulling out the plug-in (by trying to cancel the load for example).
944 m_pluginView->manualLoadDidFinishLoading();
945 m_pluginView = nullptr;
946 m_hasSentResponseToPluginView = false;
949 void WebFrameLoaderClient::updateGlobalHistory()
951 WebPage* webPage = m_frame->page();
952 if (!webPage || !webPage->pageGroup()->isVisibleToHistoryClient())
955 DocumentLoader* loader = m_frame->coreFrame()->loader().documentLoader();
957 WebNavigationDataStore data;
958 data.url = loader->url().string();
959 // FIXME: use direction of title.
960 data.title = loader->title().string();
961 data.originalRequest = loader->originalRequestCopy();
962 data.response = loader->response();
964 WebProcess::shared().parentProcessConnection()->send(Messages::WebProcessProxy::DidNavigateWithNavigationData(webPage->pageID(), data, m_frame->frameID()), 0);
967 void WebFrameLoaderClient::updateGlobalHistoryRedirectLinks()
969 WebPage* webPage = m_frame->page();
970 if (!webPage || !webPage->pageGroup()->isVisibleToHistoryClient())
973 DocumentLoader* loader = m_frame->coreFrame()->loader().documentLoader();
974 ASSERT(loader->unreachableURL().isEmpty());
977 if (!loader->clientRedirectSourceForHistory().isNull()) {
978 WebProcess::shared().parentProcessConnection()->send(Messages::WebProcessProxy::DidPerformClientRedirect(webPage->pageID(),
979 loader->clientRedirectSourceForHistory(), loader->clientRedirectDestinationForHistory(), m_frame->frameID()), 0);
983 if (!loader->serverRedirectSourceForHistory().isNull()) {
984 WebProcess::shared().parentProcessConnection()->send(Messages::WebProcessProxy::DidPerformServerRedirect(webPage->pageID(),
985 loader->serverRedirectSourceForHistory(), loader->serverRedirectDestinationForHistory(), m_frame->frameID()), 0);
989 bool WebFrameLoaderClient::shouldGoToHistoryItem(HistoryItem* item) const
991 WebPage* webPage = m_frame->page();
995 uint64_t itemID = WebBackForwardListProxy::idForItem(item);
997 // We should never be considering navigating to an item that is not actually in the back/forward list.
998 ASSERT_NOT_REACHED();
1002 RefPtr<InjectedBundleBackForwardListItem> bundleItem = InjectedBundleBackForwardListItem::create(item);
1003 RefPtr<API::Object> userData;
1005 // Ask the bundle client first
1006 bool shouldGoToBackForwardListItem = webPage->injectedBundleLoaderClient().shouldGoToBackForwardListItem(webPage, bundleItem.get(), userData);
1007 if (!shouldGoToBackForwardListItem)
1010 webPage->send(Messages::WebPageProxy::WillGoToBackForwardListItem(itemID, InjectedBundleUserMessageEncoder(userData.get())));
1014 void WebFrameLoaderClient::didDisplayInsecureContent()
1016 WebPage* webPage = m_frame->page();
1020 RefPtr<API::Object> userData;
1022 webPage->injectedBundleLoaderClient().didDisplayInsecureContentForFrame(webPage, m_frame, userData);
1024 webPage->send(Messages::WebPageProxy::DidDisplayInsecureContentForFrame(m_frame->frameID(), InjectedBundleUserMessageEncoder(userData.get())));
1027 void WebFrameLoaderClient::didRunInsecureContent(SecurityOrigin*, const URL&)
1029 WebPage* webPage = m_frame->page();
1033 RefPtr<API::Object> userData;
1035 webPage->injectedBundleLoaderClient().didRunInsecureContentForFrame(webPage, m_frame, userData);
1037 webPage->send(Messages::WebPageProxy::DidRunInsecureContentForFrame(m_frame->frameID(), InjectedBundleUserMessageEncoder(userData.get())));
1040 void WebFrameLoaderClient::didDetectXSS(const URL&, bool)
1042 WebPage* webPage = m_frame->page();
1046 RefPtr<API::Object> userData;
1048 webPage->injectedBundleLoaderClient().didDetectXSSForFrame(webPage, m_frame, userData);
1050 webPage->send(Messages::WebPageProxy::DidDetectXSSForFrame(m_frame->frameID(), InjectedBundleUserMessageEncoder(userData.get())));
1053 ResourceError WebFrameLoaderClient::cancelledError(const ResourceRequest& request)
1055 return WebKit::cancelledError(request);
1058 ResourceError WebFrameLoaderClient::blockedError(const ResourceRequest& request)
1060 return WebKit::blockedError(request);
1063 ResourceError WebFrameLoaderClient::cannotShowURLError(const ResourceRequest& request)
1065 return WebKit::cannotShowURLError(request);
1068 ResourceError WebFrameLoaderClient::interruptedForPolicyChangeError(const ResourceRequest& request)
1070 return WebKit::interruptedForPolicyChangeError(request);
1073 ResourceError WebFrameLoaderClient::cannotShowMIMETypeError(const ResourceResponse& response)
1075 return WebKit::cannotShowMIMETypeError(response);
1078 ResourceError WebFrameLoaderClient::fileDoesNotExistError(const ResourceResponse& response)
1080 return WebKit::fileDoesNotExistError(response);
1083 ResourceError WebFrameLoaderClient::pluginWillHandleLoadError(const ResourceResponse& response)
1085 return WebKit::pluginWillHandleLoadError(response);
1088 bool WebFrameLoaderClient::shouldFallBack(const ResourceError& error)
1090 static NeverDestroyed<const ResourceError> cancelledError(this->cancelledError(ResourceRequest()));
1091 static NeverDestroyed<const ResourceError> pluginWillHandleLoadError(this->pluginWillHandleLoadError(ResourceResponse()));
1093 if (error.errorCode() == cancelledError.get().errorCode() && error.domain() == cancelledError.get().domain())
1096 if (error.errorCode() == pluginWillHandleLoadError.get().errorCode() && error.domain() == pluginWillHandleLoadError.get().domain())
1102 bool WebFrameLoaderClient::canHandleRequest(const ResourceRequest&) const
1108 bool WebFrameLoaderClient::canShowMIMEType(const String& /*MIMEType*/) const
1114 bool WebFrameLoaderClient::canShowMIMETypeAsHTML(const String& /*MIMEType*/) const
1119 bool WebFrameLoaderClient::representationExistsForURLScheme(const String& /*URLScheme*/) const
1125 String WebFrameLoaderClient::generatedMIMETypeForURLScheme(const String& /*URLScheme*/) const
1131 void WebFrameLoaderClient::frameLoadCompleted()
1133 // Note: Can be called multiple times.
1134 WebPage* webPage = m_frame->page();
1138 if (m_frame->isMainFrame() && !m_didCompletePageTransition) {
1139 webPage->didCompletePageTransition();
1140 m_didCompletePageTransition = true;
1145 void WebFrameLoaderClient::saveViewStateToItem(HistoryItem*)
1150 void WebFrameLoaderClient::restoreViewState()
1152 // Inform the UI process of the scale factor.
1153 double scaleFactor = m_frame->coreFrame()->loader().history().currentItem()->pageScaleFactor();
1155 // A scale factor of 0 means the history item has the default scale factor, thus we do not need to update it.
1157 m_frame->page()->send(Messages::WebPageProxy::PageScaleFactorDidChange(scaleFactor));
1159 // FIXME: This should not be necessary. WebCore should be correctly invalidating
1160 // the view on restores from the back/forward cache.
1161 if (m_frame == m_frame->page()->mainWebFrame())
1162 m_frame->page()->drawingArea()->setNeedsDisplay();
1166 void WebFrameLoaderClient::provisionalLoadStarted()
1168 WebPage* webPage = m_frame->page();
1172 if (m_frame->isMainFrame()) {
1173 webPage->didStartPageTransition();
1174 m_didCompletePageTransition = false;
1178 void WebFrameLoaderClient::didFinishLoad()
1180 // If we have a load listener, notify it.
1181 if (WebFrame::LoadListener* loadListener = m_frame->loadListener())
1182 loadListener->didFinishLoad(m_frame);
1185 void WebFrameLoaderClient::prepareForDataSourceReplacement()
1190 PassRefPtr<DocumentLoader> WebFrameLoaderClient::createDocumentLoader(const ResourceRequest& request, const SubstituteData& substituteData)
1192 return m_frame->page()->createDocumentLoader(*m_frame->coreFrame(), request, substituteData);
1195 void WebFrameLoaderClient::setTitle(const StringWithDirection& title, const URL& url)
1197 WebPage* webPage = m_frame->page();
1198 if (!webPage || !webPage->pageGroup()->isVisibleToHistoryClient())
1201 // FIXME: use direction of title.
1202 WebProcess::shared().parentProcessConnection()->send(Messages::WebProcessProxy::DidUpdateHistoryTitle(webPage->pageID(),
1203 title.string(), url.string(), m_frame->frameID()), 0);
1206 String WebFrameLoaderClient::userAgent(const URL& url)
1208 WebPage* webPage = m_frame->page();
1212 return webPage->userAgent(m_frame, url);
1215 void WebFrameLoaderClient::savePlatformDataToCachedFrame(CachedFrame*)
1219 void WebFrameLoaderClient::transitionToCommittedFromCachedFrame(CachedFrame*)
1221 const ResourceResponse& response = m_frame->coreFrame()->loader().documentLoader()->response();
1222 m_frameHasCustomContentProvider = m_frame->isMainFrame() && m_frame->page()->shouldUseCustomContentProviderForResponse(response);
1223 m_frameCameFromPageCache = true;
1226 void WebFrameLoaderClient::transitionToCommittedForNewPage()
1228 WebPage* webPage = m_frame->page();
1230 Color backgroundColor = webPage->drawsTransparentBackground() ? Color::transparent : Color::white;
1231 bool isMainFrame = m_frame->isMainFrame();
1232 bool isTransparent = !webPage->drawsBackground();
1233 bool shouldUseFixedLayout = isMainFrame && webPage->useFixedLayout();
1234 bool shouldDisableScrolling = isMainFrame && !webPage->mainFrameIsScrollable();
1235 bool shouldHideScrollbars = shouldUseFixedLayout || shouldDisableScrolling;
1236 IntRect fixedVisibleContentRect;
1238 #if USE(TILED_BACKING_STORE)
1239 if (m_frame->coreFrame()->view())
1240 fixedVisibleContentRect = m_frame->coreFrame()->view()->fixedVisibleContentRect();
1243 const ResourceResponse& response = m_frame->coreFrame()->loader().documentLoader()->response();
1244 m_frameHasCustomContentProvider = isMainFrame && webPage->shouldUseCustomContentProviderForResponse(response);
1245 m_frameCameFromPageCache = false;
1247 ScrollbarMode defaultScrollbarMode = shouldHideScrollbars ? ScrollbarAlwaysOff : ScrollbarAuto;
1249 m_frame->coreFrame()->createView(webPage->size(), backgroundColor, isTransparent,
1250 IntSize(), fixedVisibleContentRect, shouldUseFixedLayout,
1251 defaultScrollbarMode, /* lock */ shouldHideScrollbars, defaultScrollbarMode, /* lock */ shouldHideScrollbars);
1253 if (int minimumLayoutWidth = webPage->minimumLayoutSize().width()) {
1254 int minimumLayoutHeight = std::max(webPage->minimumLayoutSize().height(), 1);
1255 int maximumSize = std::numeric_limits<int>::max();
1256 m_frame->coreFrame()->view()->enableAutoSizeMode(true, IntSize(minimumLayoutWidth, minimumLayoutHeight), IntSize(maximumSize, maximumSize));
1257 m_frame->coreFrame()->view()->setAutoSizeFixedMinimumHeight(webPage->size().height());
1260 m_frame->coreFrame()->view()->setProhibitsScrolling(shouldDisableScrolling);
1261 m_frame->coreFrame()->view()->setVisualUpdatesAllowedByClient(!webPage->shouldExtendIncrementalRenderingSuppression());
1263 m_frame->coreFrame()->view()->setExposedRect(webPage->drawingArea()->exposedRect());
1266 m_frame->coreFrame()->view()->setDelegatesScrolling(true);
1269 if (webPage->scrollPinningBehavior() != DoNotPin)
1270 m_frame->coreFrame()->view()->setScrollPinningBehavior(webPage->scrollPinningBehavior());
1272 #if USE(TILED_BACKING_STORE)
1273 if (shouldUseFixedLayout) {
1274 m_frame->coreFrame()->view()->setDelegatesScrolling(shouldUseFixedLayout);
1275 m_frame->coreFrame()->view()->setPaintsEntireContents(shouldUseFixedLayout);
1281 void WebFrameLoaderClient::didSaveToPageCache()
1283 WebPage* webPage = m_frame->page();
1287 webPage->send(Messages::WebPageProxy::DidSaveToPageCache());
1290 void WebFrameLoaderClient::didRestoreFromPageCache()
1292 m_frameCameFromPageCache = true;
1295 void WebFrameLoaderClient::dispatchDidBecomeFrameset(bool value)
1297 WebPage* webPage = m_frame->page();
1301 webPage->send(Messages::WebPageProxy::FrameDidBecomeFrameSet(m_frame->frameID(), value));
1304 bool WebFrameLoaderClient::canCachePage() const
1306 // We cannot cache frames that have custom representations because they are
1307 // rendered in the UIProcess.
1308 return !m_frameHasCustomContentProvider;
1311 void WebFrameLoaderClient::convertMainResourceLoadToDownload(DocumentLoader *documentLoader, const ResourceRequest& request, const ResourceResponse& response)
1313 m_frame->convertMainResourceLoadToDownload(documentLoader, request, response);
1316 PassRefPtr<Frame> WebFrameLoaderClient::createFrame(const URL& url, const String& name, HTMLFrameOwnerElement* ownerElement,
1317 const String& referrer, bool /*allowsScrolling*/, int /*marginWidth*/, int /*marginHeight*/)
1319 WebPage* webPage = m_frame->page();
1321 RefPtr<WebFrame> subframe = WebFrame::createSubframe(webPage, name, ownerElement);
1323 Frame* coreSubframe = subframe->coreFrame();
1327 // The creation of the frame may have run arbitrary JavaScript that removed it from the page already.
1328 if (!coreSubframe->page())
1331 m_frame->coreFrame()->loader().loadURLIntoChildFrame(url, referrer, coreSubframe);
1333 // The frame's onload handler may have removed it from the document.
1334 if (!subframe->coreFrame())
1336 ASSERT(subframe->coreFrame() == coreSubframe);
1337 if (!coreSubframe->tree().parent())
1340 return coreSubframe;
1343 PassRefPtr<Widget> WebFrameLoaderClient::createPlugin(const IntSize&, HTMLPlugInElement* pluginElement, const URL& url, const Vector<String>& paramNames, const Vector<String>& paramValues, const String& mimeType, bool loadManually)
1345 ASSERT(paramNames.size() == paramValues.size());
1346 ASSERT(m_frame->page());
1348 Plugin::Parameters parameters;
1349 parameters.url = url;
1350 parameters.names = paramNames;
1351 parameters.values = paramValues;
1352 parameters.mimeType = mimeType;
1353 parameters.isFullFramePlugin = loadManually;
1354 parameters.shouldUseManualLoader = parameters.isFullFramePlugin && !m_frameCameFromPageCache;
1356 parameters.layerHostingMode = m_frame->page()->layerHostingMode();
1359 #if ENABLE(NETSCAPE_PLUGIN_API)
1360 RefPtr<Plugin> plugin = m_frame->page()->createPlugin(m_frame, pluginElement, parameters, parameters.mimeType);
1364 return PluginView::create(pluginElement, plugin.release(), parameters);
1366 UNUSED_PARAM(pluginElement);
1371 void WebFrameLoaderClient::recreatePlugin(Widget* widget)
1373 #if ENABLE(NETSCAPE_PLUGIN_API)
1374 ASSERT(widget && widget->isPluginViewBase());
1375 ASSERT(m_frame->page());
1377 PluginView* pluginView = static_cast<PluginView*>(widget);
1379 RefPtr<Plugin> plugin = m_frame->page()->createPlugin(m_frame, pluginView->pluginElement(), pluginView->initialParameters(), newMIMEType);
1380 pluginView->recreateAndInitialize(plugin.release());
1382 UNUSED_PARAM(widget);
1386 void WebFrameLoaderClient::redirectDataToPlugin(Widget* pluginWidget)
1389 m_pluginView = static_cast<PluginView*>(pluginWidget);
1393 WebCore::WebGLLoadPolicy WebFrameLoaderClient::webGLPolicyForURL(const String& url) const
1395 if (WebPage* webPage = m_frame->page())
1396 return webPage->webGLPolicyForURL(m_frame, url);
1398 return WebGLAllowCreation;
1401 WebCore::WebGLLoadPolicy WebFrameLoaderClient::resolveWebGLPolicyForURL(const String& url) const
1403 if (WebPage* webPage = m_frame->page())
1404 return webPage->resolveWebGLPolicyForURL(m_frame, url);
1406 return WebGLAllowCreation;
1408 #endif // ENABLE(WEBGL)
1410 PassRefPtr<Widget> WebFrameLoaderClient::createJavaAppletWidget(const IntSize& pluginSize, HTMLAppletElement* appletElement, const URL&, const Vector<String>& paramNames, const Vector<String>& paramValues)
1412 #if ENABLE(NETSCAPE_PLUGIN_API)
1413 RefPtr<Widget> plugin = createPlugin(pluginSize, appletElement, URL(), paramNames, paramValues, appletElement->serviceType(), false);
1415 if (WebPage* webPage = m_frame->page()) {
1416 String frameURLString = m_frame->coreFrame()->loader().documentLoader()->responseURL().string();
1417 String pageURLString = webPage->corePage()->mainFrame().loader().documentLoader()->responseURL().string();
1418 webPage->send(Messages::WebPageProxy::DidFailToInitializePlugin(appletElement->serviceType(), frameURLString, pageURLString));
1421 return plugin.release();
1423 UNUSED_PARAM(pluginSize);
1424 UNUSED_PARAM(appletElement);
1425 UNUSED_PARAM(paramNames);
1426 UNUSED_PARAM(paramValues);
1431 static bool pluginSupportsExtension(const PluginData& pluginData, const String& extension)
1433 ASSERT(extension.lower() == extension);
1435 for (size_t i = 0; i < pluginData.mimes().size(); ++i) {
1436 const MimeClassInfo& mimeClassInfo = pluginData.mimes()[i];
1438 if (mimeClassInfo.extensions.contains(extension))
1444 ObjectContentType WebFrameLoaderClient::objectContentType(const URL& url, const String& mimeTypeIn, bool shouldPreferPlugInsForImages)
1446 // FIXME: This should be merged with WebCore::FrameLoader::defaultObjectContentType when the plugin code
1449 String mimeType = mimeTypeIn;
1450 if (mimeType.isEmpty()) {
1451 String extension = url.path().substring(url.path().reverseFind('.') + 1).lower();
1453 // Try to guess the MIME type from the extension.
1454 mimeType = MIMETypeRegistry::getMIMETypeForExtension(extension);
1456 if (mimeType.isEmpty()) {
1457 // Check if there's a plug-in around that can handle the extension.
1458 if (WebPage* webPage = m_frame->page()) {
1459 if (pluginSupportsExtension(webPage->corePage()->pluginData(), extension))
1460 return ObjectContentNetscapePlugin;
1465 if (mimeType.isEmpty())
1466 return ObjectContentFrame;
1468 bool plugInSupportsMIMEType = false;
1469 if (WebPage* webPage = m_frame->page()) {
1470 const PluginData& pluginData = webPage->corePage()->pluginData();
1471 if (pluginData.supportsMimeType(mimeType, PluginData::AllPlugins) && webFrame()->coreFrame()->loader().subframeLoader().allowPlugins(NotAboutToInstantiatePlugin))
1472 plugInSupportsMIMEType = true;
1473 else if (pluginData.supportsMimeType(mimeType, PluginData::OnlyApplicationPlugins))
1474 plugInSupportsMIMEType = true;
1477 if (MIMETypeRegistry::isSupportedImageMIMEType(mimeType))
1478 return shouldPreferPlugInsForImages && plugInSupportsMIMEType ? ObjectContentNetscapePlugin : ObjectContentImage;
1480 if (plugInSupportsMIMEType)
1481 return ObjectContentNetscapePlugin;
1483 if (MIMETypeRegistry::isSupportedNonImageMIMEType(mimeType))
1484 return ObjectContentFrame;
1486 return ObjectContentNone;
1489 String WebFrameLoaderClient::overrideMediaType() const
1495 void WebFrameLoaderClient::dispatchDidClearWindowObjectInWorld(DOMWrapperWorld& world)
1497 WebPage* webPage = m_frame->page();
1501 webPage->injectedBundleLoaderClient().didClearWindowObjectForFrame(webPage, m_frame, world);
1503 #if HAVE(ACCESSIBILITY) && (PLATFORM(GTK) || PLATFORM(EFL))
1504 // Ensure the accessibility hierarchy is updated.
1505 webPage->updateAccessibilityTree();
1510 void WebFrameLoaderClient::dispatchGlobalObjectAvailable(DOMWrapperWorld& world)
1512 WebPage* webPage = m_frame->page();
1516 webPage->injectedBundleLoaderClient().globalObjectIsAvailableForFrame(webPage, m_frame, world);
1519 void WebFrameLoaderClient::dispatchWillDisconnectDOMWindowExtensionFromGlobalObject(WebCore::DOMWindowExtension* extension)
1521 WebPage* webPage = m_frame->page();
1525 webPage->injectedBundleLoaderClient().willDisconnectDOMWindowExtensionFromGlobalObject(webPage, extension);
1528 void WebFrameLoaderClient::dispatchDidReconnectDOMWindowExtensionToGlobalObject(WebCore::DOMWindowExtension* extension)
1530 WebPage* webPage = m_frame->page();
1534 webPage->injectedBundleLoaderClient().didReconnectDOMWindowExtensionToGlobalObject(webPage, extension);
1537 void WebFrameLoaderClient::dispatchWillDestroyGlobalObjectForDOMWindowExtension(WebCore::DOMWindowExtension* extension)
1539 WebPage* webPage = m_frame->page();
1543 webPage->injectedBundleLoaderClient().willDestroyGlobalObjectForDOMWindowExtension(webPage, extension);
1546 void WebFrameLoaderClient::registerForIconNotification(bool /*listen*/)
1553 RemoteAXObjectRef WebFrameLoaderClient::accessibilityRemoteObject()
1555 WebPage* webPage = m_frame->page();
1559 return webPage->accessibilityRemoteObject();
1562 NSCachedURLResponse* WebFrameLoaderClient::willCacheResponse(DocumentLoader*, unsigned long identifier, NSCachedURLResponse* response) const
1564 WebPage* webPage = m_frame->page();
1568 return webPage->injectedBundleResourceLoadClient().shouldCacheResponse(webPage, m_frame, identifier) ? response : nil;
1571 #endif // PLATFORM(COCOA)
1573 bool WebFrameLoaderClient::shouldAlwaysUsePluginDocument(const String& /*mimeType*/) const
1579 void WebFrameLoaderClient::didChangeScrollOffset()
1581 WebPage* webPage = m_frame->page();
1585 webPage->didChangeScrollOffsetForFrame(m_frame->coreFrame());
1588 bool WebFrameLoaderClient::allowScript(bool enabledPerSettings)
1590 if (!enabledPerSettings)
1593 Frame* coreFrame = m_frame->coreFrame();
1595 if (coreFrame->document()->isPluginDocument()) {
1596 PluginDocument* pluginDocument = static_cast<PluginDocument*>(coreFrame->document());
1598 if (pluginDocument->pluginWidget() && pluginDocument->pluginWidget()->isPluginView()) {
1599 PluginView* pluginView = static_cast<PluginView*>(pluginDocument->pluginWidget());
1601 if (!pluginView->shouldAllowScripting())
1609 bool WebFrameLoaderClient::shouldForceUniversalAccessFromLocalURL(const WebCore::URL& url)
1611 WebPage* webPage = m_frame->page();
1615 return webPage->injectedBundleLoaderClient().shouldForceUniversalAccessFromLocalURL(webPage, url.string());
1618 PassRefPtr<FrameNetworkingContext> WebFrameLoaderClient::createNetworkingContext()
1620 RefPtr<WebFrameNetworkingContext> context = WebFrameNetworkingContext::create(m_frame);
1621 return context.release();
1624 void WebFrameLoaderClient::willChangeCurrentHistoryItem()
1626 WebPage* webPage = m_frame->page();
1629 if (!m_frame->isMainFrame())
1632 webPage->willChangeCurrentHistoryItemForMainFrame();
1635 #if USE(CONTENT_FILTERING)
1636 void WebFrameLoaderClient::contentFilterDidBlockLoad(std::unique_ptr<WebCore::ContentFilter> contentFilter)
1638 if (WebPage* webPage = m_frame->page())
1639 webPage->send(Messages::WebPageProxy::ContentFilterDidBlockLoadForFrame(*contentFilter, m_frame->frameID()));
1643 } // namespace WebKit