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 "InjectedBundle.h"
32 #include "InjectedBundleBackForwardListItem.h"
33 #include "InjectedBundleDOMWindowExtension.h"
34 #include "InjectedBundleNavigationAction.h"
35 #include "InjectedBundleUserMessageCoders.h"
36 #include "NavigationActionData.h"
37 #include "PluginView.h"
38 #include "WebBackForwardListProxy.h"
39 #include "WebContextMessages.h"
40 #include "WebCoreArgumentCoders.h"
41 #include "WebErrors.h"
44 #include "WebFrameNetworkingContext.h"
45 #include "WebFullScreenManager.h"
46 #include "WebIconDatabaseMessages.h"
47 #include "WebNavigationDataStore.h"
49 #include "WebPageProxyMessages.h"
50 #include "WebProcess.h"
51 #include "WebProcessProxyMessages.h"
52 #include <JavaScriptCore/APICast.h>
53 #include <JavaScriptCore/JSObject.h>
54 #include <WebCore/AXObjectCache.h>
55 #include <WebCore/CertificateInfo.h>
56 #include <WebCore/Chrome.h>
57 #include <WebCore/DOMWrapperWorld.h>
58 #include <WebCore/DocumentLoader.h>
59 #include <WebCore/FormState.h>
60 #include <WebCore/FrameLoadRequest.h>
61 #include <WebCore/FrameLoader.h>
62 #include <WebCore/FrameView.h>
63 #include <WebCore/HTMLAppletElement.h>
64 #include <WebCore/HTMLFormElement.h>
65 #include <WebCore/HistoryController.h>
66 #include <WebCore/HistoryItem.h>
67 #include <WebCore/MIMETypeRegistry.h>
68 #include <WebCore/MainFrame.h>
69 #include <WebCore/MouseEvent.h>
70 #include <WebCore/NotImplemented.h>
71 #include <WebCore/Page.h>
72 #include <WebCore/PluginData.h>
73 #include <WebCore/PluginDocument.h>
74 #include <WebCore/ProgressTracker.h>
75 #include <WebCore/ResourceBuffer.h>
76 #include <WebCore/ResourceError.h>
77 #include <WebCore/Settings.h>
78 #include <WebCore/SubframeLoader.h>
79 #include <WebCore/UIEventWithKeyState.h>
80 #include <WebCore/Widget.h>
81 #include <WebCore/WindowFeatures.h>
82 #include <wtf/NeverDestroyed.h>
84 using namespace WebCore;
88 WebFrameLoaderClient::WebFrameLoaderClient()
90 , m_hasSentResponseToPluginView(false)
91 , m_didCompletePageTransitionAlready(false)
92 , m_frameCameFromPageCache(false)
96 WebFrameLoaderClient::~WebFrameLoaderClient()
100 void WebFrameLoaderClient::frameLoaderDestroyed()
102 if (WebPage* webPage = m_frame->page())
103 webPage->injectedBundleLoaderClient().willDestroyFrame(webPage, m_frame);
105 m_frame->invalidate();
107 // Balances explicit ref() in WebFrame::create().
111 bool WebFrameLoaderClient::hasWebView() const
113 return m_frame->page();
116 void WebFrameLoaderClient::makeRepresentation(DocumentLoader*)
121 void WebFrameLoaderClient::forceLayout()
126 void WebFrameLoaderClient::forceLayoutForNonHTML()
131 void WebFrameLoaderClient::setCopiesOnScroll()
136 void WebFrameLoaderClient::detachedFromParent2()
138 WebPage* webPage = m_frame->page();
142 RefPtr<API::Object> userData;
144 // Notify the bundle client.
145 webPage->injectedBundleLoaderClient().didRemoveFrameFromHierarchy(webPage, m_frame, userData);
147 // Notify the UIProcess.
148 webPage->send(Messages::WebPageProxy::DidRemoveFrameFromHierarchy(m_frame->frameID(), InjectedBundleUserMessageEncoder(userData.get())));
152 void WebFrameLoaderClient::detachedFromParent3()
157 void WebFrameLoaderClient::assignIdentifierToInitialRequest(unsigned long identifier, DocumentLoader* loader, const ResourceRequest& request)
159 WebPage* webPage = m_frame->page();
163 bool pageIsProvisionallyLoading = false;
164 if (FrameLoader* frameLoader = loader->frameLoader())
165 pageIsProvisionallyLoading = frameLoader->provisionalDocumentLoader() == loader;
167 webPage->injectedBundleResourceLoadClient().didInitiateLoadForResource(webPage, m_frame, identifier, request, pageIsProvisionallyLoading);
170 void WebFrameLoaderClient::dispatchWillSendRequest(DocumentLoader*, unsigned long identifier, ResourceRequest& request, const ResourceResponse& redirectResponse)
172 WebPage* webPage = m_frame->page();
176 webPage->injectedBundleResourceLoadClient().willSendRequestForFrame(webPage, m_frame, identifier, request, redirectResponse);
179 bool WebFrameLoaderClient::shouldUseCredentialStorage(DocumentLoader*, unsigned long identifier)
181 WebPage* webPage = m_frame->page();
185 return webPage->injectedBundleResourceLoadClient().shouldUseCredentialStorage(webPage, m_frame, identifier);
188 void WebFrameLoaderClient::dispatchDidReceiveAuthenticationChallenge(DocumentLoader*, unsigned long, const AuthenticationChallenge& challenge)
190 // FIXME: Authentication is a per-resource concept, but we don't do per-resource handling in the UIProcess at the API level quite yet.
191 // Once we do, we might need to make sure authentication fits with our solution.
193 WebPage* webPage = m_frame->page();
197 WebProcess::shared().supplement<AuthenticationManager>()->didReceiveAuthenticationChallenge(m_frame, challenge);
200 void WebFrameLoaderClient::dispatchDidCancelAuthenticationChallenge(DocumentLoader*, unsigned long /*identifier*/, const AuthenticationChallenge&)
205 #if USE(PROTECTION_SPACE_AUTH_CALLBACK)
206 bool WebFrameLoaderClient::canAuthenticateAgainstProtectionSpace(DocumentLoader*, unsigned long, const ProtectionSpace& protectionSpace)
208 // FIXME: Authentication is a per-resource concept, but we don't do per-resource handling in the UIProcess at the API level quite yet.
209 // Once we do, we might need to make sure authentication fits with our solution.
211 WebPage* webPage = m_frame->page();
215 bool canAuthenticate;
216 if (!webPage->sendSync(Messages::WebPageProxy::CanAuthenticateAgainstProtectionSpaceInFrame(m_frame->frameID(), protectionSpace), Messages::WebPageProxy::CanAuthenticateAgainstProtectionSpaceInFrame::Reply(canAuthenticate)))
219 return canAuthenticate;
223 void WebFrameLoaderClient::dispatchDidReceiveResponse(DocumentLoader*, unsigned long identifier, const ResourceResponse& response)
225 WebPage* webPage = m_frame->page();
229 webPage->injectedBundleResourceLoadClient().didReceiveResponseForResource(webPage, m_frame, identifier, response);
232 void WebFrameLoaderClient::dispatchDidReceiveContentLength(DocumentLoader*, unsigned long identifier, int dataLength)
234 WebPage* webPage = m_frame->page();
238 webPage->injectedBundleResourceLoadClient().didReceiveContentLengthForResource(webPage, m_frame, identifier, dataLength);
241 void WebFrameLoaderClient::dispatchDidFinishLoading(DocumentLoader*, unsigned long identifier)
243 WebPage* webPage = m_frame->page();
247 webPage->injectedBundleResourceLoadClient().didFinishLoadForResource(webPage, m_frame, identifier);
250 void WebFrameLoaderClient::dispatchDidFailLoading(DocumentLoader*, unsigned long identifier, const ResourceError& error)
252 WebPage* webPage = m_frame->page();
256 webPage->injectedBundleResourceLoadClient().didFailLoadForResource(webPage, m_frame, identifier, error);
259 bool WebFrameLoaderClient::dispatchDidLoadResourceFromMemoryCache(DocumentLoader*, const ResourceRequest&, const ResourceResponse&, int /*length*/)
265 void WebFrameLoaderClient::dispatchDidHandleOnloadEvents()
267 WebPage* webPage = m_frame->page();
271 // Notify the bundle client.
272 webPage->injectedBundleLoaderClient().didHandleOnloadEventsForFrame(webPage, m_frame);
275 void WebFrameLoaderClient::dispatchDidReceiveServerRedirectForProvisionalLoad()
277 WebPage* webPage = m_frame->page();
281 DocumentLoader* provisionalLoader = m_frame->coreFrame()->loader().provisionalDocumentLoader();
282 const String& url = provisionalLoader->url().string();
283 RefPtr<API::Object> userData;
285 // Notify the bundle client.
286 webPage->injectedBundleLoaderClient().didReceiveServerRedirectForProvisionalLoadForFrame(webPage, m_frame, userData);
288 // Notify the UIProcess.
289 webPage->send(Messages::WebPageProxy::DidReceiveServerRedirectForProvisionalLoadForFrame(m_frame->frameID(), url, InjectedBundleUserMessageEncoder(userData.get())));
292 void WebFrameLoaderClient::dispatchDidCancelClientRedirect()
294 WebPage* webPage = m_frame->page();
298 // Notify the bundle client.
299 webPage->injectedBundleLoaderClient().didCancelClientRedirectForFrame(webPage, m_frame);
302 void WebFrameLoaderClient::dispatchWillPerformClientRedirect(const URL& url, double interval, double fireDate)
304 WebPage* webPage = m_frame->page();
308 // Notify the bundle client.
309 webPage->injectedBundleLoaderClient().willPerformClientRedirectForFrame(webPage, m_frame, url.string(), interval, fireDate);
312 void WebFrameLoaderClient::dispatchDidChangeLocationWithinPage()
314 WebPage* webPage = m_frame->page();
318 RefPtr<API::Object> userData;
320 // Notify the bundle client.
321 webPage->injectedBundleLoaderClient().didSameDocumentNavigationForFrame(webPage, m_frame, SameDocumentNavigationAnchorNavigation, userData);
323 // Notify the UIProcess.
324 webPage->send(Messages::WebPageProxy::DidSameDocumentNavigationForFrame(m_frame->frameID(), SameDocumentNavigationAnchorNavigation, m_frame->coreFrame()->document()->url().string(), InjectedBundleUserMessageEncoder(userData.get())));
327 void WebFrameLoaderClient::dispatchDidPushStateWithinPage()
329 WebPage* webPage = m_frame->page();
333 RefPtr<API::Object> userData;
335 // Notify the bundle client.
336 webPage->injectedBundleLoaderClient().didSameDocumentNavigationForFrame(webPage, m_frame, SameDocumentNavigationSessionStatePush, userData);
338 // Notify the UIProcess.
339 webPage->send(Messages::WebPageProxy::DidSameDocumentNavigationForFrame(m_frame->frameID(), SameDocumentNavigationSessionStatePush, m_frame->coreFrame()->document()->url().string(), InjectedBundleUserMessageEncoder(userData.get())));
342 void WebFrameLoaderClient::dispatchDidReplaceStateWithinPage()
344 WebPage* webPage = m_frame->page();
348 RefPtr<API::Object> userData;
350 // Notify the bundle client.
351 webPage->injectedBundleLoaderClient().didSameDocumentNavigationForFrame(webPage, m_frame, SameDocumentNavigationSessionStateReplace, userData);
353 // Notify the UIProcess.
354 webPage->send(Messages::WebPageProxy::DidSameDocumentNavigationForFrame(m_frame->frameID(), SameDocumentNavigationSessionStateReplace, m_frame->coreFrame()->document()->url().string(), InjectedBundleUserMessageEncoder(userData.get())));
357 void WebFrameLoaderClient::dispatchDidPopStateWithinPage()
359 WebPage* webPage = m_frame->page();
363 RefPtr<API::Object> userData;
365 // Notify the bundle client.
366 webPage->injectedBundleLoaderClient().didSameDocumentNavigationForFrame(webPage, m_frame, SameDocumentNavigationSessionStatePop, userData);
368 // Notify the UIProcess.
369 webPage->send(Messages::WebPageProxy::DidSameDocumentNavigationForFrame(m_frame->frameID(), SameDocumentNavigationSessionStatePop, m_frame->coreFrame()->document()->url().string(), InjectedBundleUserMessageEncoder(userData.get())));
372 void WebFrameLoaderClient::dispatchWillClose()
377 void WebFrameLoaderClient::dispatchDidReceiveIcon()
379 WebProcess::shared().parentProcessConnection()->send(Messages::WebIconDatabase::DidReceiveIconForPageURL(m_frame->url()), 0);
382 void WebFrameLoaderClient::dispatchDidStartProvisionalLoad()
384 WebPage* webPage = m_frame->page();
388 #if ENABLE(FULLSCREEN_API)
389 Element* documentElement = m_frame->coreFrame()->document()->documentElement();
390 if (documentElement && documentElement->containsFullScreenElement())
391 webPage->fullScreenManager()->exitFullScreenForElement(webPage->fullScreenManager()->element());
394 webPage->findController().hideFindUI();
395 webPage->sandboxExtensionTracker().didStartProvisionalLoad(m_frame);
397 DocumentLoader* provisionalLoader = m_frame->coreFrame()->loader().provisionalDocumentLoader();
398 const String& url = provisionalLoader->url().string();
399 RefPtr<API::Object> userData;
401 // Notify the bundle client.
402 webPage->injectedBundleLoaderClient().didStartProvisionalLoadForFrame(webPage, m_frame, userData);
404 String unreachableURL = provisionalLoader->unreachableURL().string();
406 // Notify the UIProcess.
407 webPage->send(Messages::WebPageProxy::DidStartProvisionalLoadForFrame(m_frame->frameID(), url, unreachableURL, InjectedBundleUserMessageEncoder(userData.get())));
410 void WebFrameLoaderClient::dispatchDidReceiveTitle(const StringWithDirection& title)
412 WebPage* webPage = m_frame->page();
416 RefPtr<API::Object> userData;
418 // Notify the bundle client.
419 // FIXME: use direction of title.
420 webPage->injectedBundleLoaderClient().didReceiveTitleForFrame(webPage, title.string(), m_frame, userData);
422 // Notify the UIProcess.
423 webPage->send(Messages::WebPageProxy::DidReceiveTitleForFrame(m_frame->frameID(), title.string(), InjectedBundleUserMessageEncoder(userData.get())));
426 void WebFrameLoaderClient::dispatchDidChangeIcons(WebCore::IconType)
431 void WebFrameLoaderClient::dispatchDidCommitLoad()
433 WebPage* webPage = m_frame->page();
437 const ResourceResponse& response = m_frame->coreFrame()->loader().documentLoader()->response();
438 RefPtr<API::Object> userData;
440 // Notify the bundle client.
441 webPage->injectedBundleLoaderClient().didCommitLoadForFrame(webPage, m_frame, userData);
443 webPage->sandboxExtensionTracker().didCommitProvisionalLoad(m_frame);
445 // Notify the UIProcess.
447 webPage->send(Messages::WebPageProxy::DidCommitLoadForFrame(m_frame->frameID(), response.mimeType(), m_frame->coreFrame()->loader().loadType(), CertificateInfo(response), InjectedBundleUserMessageEncoder(userData.get())));
449 webPage->didCommitLoad(m_frame);
452 void WebFrameLoaderClient::dispatchDidFailProvisionalLoad(const ResourceError& error)
454 WebPage* webPage = m_frame->page();
458 RefPtr<API::Object> userData;
460 // Notify the bundle client.
461 webPage->injectedBundleLoaderClient().didFailProvisionalLoadWithErrorForFrame(webPage, m_frame, error, userData);
463 webPage->sandboxExtensionTracker().didFailProvisionalLoad(m_frame);
465 // Notify the UIProcess.
466 webPage->send(Messages::WebPageProxy::DidFailProvisionalLoadForFrame(m_frame->frameID(), error, InjectedBundleUserMessageEncoder(userData.get())));
468 // If we have a load listener, notify it.
469 if (WebFrame::LoadListener* loadListener = m_frame->loadListener())
470 loadListener->didFailLoad(m_frame, error.isCancellation());
473 void WebFrameLoaderClient::dispatchDidFailLoad(const ResourceError& error)
475 WebPage* webPage = m_frame->page();
479 RefPtr<API::Object> userData;
481 // Notify the bundle client.
482 webPage->injectedBundleLoaderClient().didFailLoadWithErrorForFrame(webPage, m_frame, error, userData);
484 // Notify the UIProcess.
485 webPage->send(Messages::WebPageProxy::DidFailLoadForFrame(m_frame->frameID(), error, InjectedBundleUserMessageEncoder(userData.get())));
487 // If we have a load listener, notify it.
488 if (WebFrame::LoadListener* loadListener = m_frame->loadListener())
489 loadListener->didFailLoad(m_frame, error.isCancellation());
492 void WebFrameLoaderClient::dispatchDidFinishDocumentLoad()
494 WebPage* webPage = m_frame->page();
498 RefPtr<API::Object> userData;
500 // Notify the bundle client.
501 webPage->injectedBundleLoaderClient().didFinishDocumentLoadForFrame(webPage, m_frame, userData);
503 // Notify the UIProcess.
504 webPage->send(Messages::WebPageProxy::DidFinishDocumentLoadForFrame(m_frame->frameID(), InjectedBundleUserMessageEncoder(userData.get())));
507 void WebFrameLoaderClient::dispatchDidFinishLoad()
509 WebPage* webPage = m_frame->page();
513 RefPtr<API::Object> userData;
515 // Notify the bundle client.
516 webPage->injectedBundleLoaderClient().didFinishLoadForFrame(webPage, m_frame, userData);
518 // Notify the UIProcess.
519 webPage->send(Messages::WebPageProxy::DidFinishLoadForFrame(m_frame->frameID(), InjectedBundleUserMessageEncoder(userData.get())));
521 // If we have a load listener, notify it.
522 if (WebFrame::LoadListener* loadListener = m_frame->loadListener())
523 loadListener->didFinishLoad(m_frame);
525 webPage->didFinishLoad(m_frame);
528 void WebFrameLoaderClient::forcePageTransitionIfNeeded()
530 if (m_didCompletePageTransitionAlready)
533 WebPage* webPage = m_frame->page();
537 webPage->didCompletePageTransition();
538 m_didCompletePageTransitionAlready = true;
541 void WebFrameLoaderClient::dispatchDidLayout(LayoutMilestones milestones)
543 WebPage* webPage = m_frame->page();
547 RefPtr<API::Object> userData;
549 if (milestones & DidFirstLayout) {
550 // FIXME: We should consider removing the old didFirstLayout API since this is doing double duty with the
551 // new didLayout API.
552 webPage->injectedBundleLoaderClient().didFirstLayoutForFrame(webPage, m_frame, userData);
553 webPage->send(Messages::WebPageProxy::DidFirstLayoutForFrame(m_frame->frameID(), InjectedBundleUserMessageEncoder(userData.get())));
555 if (m_frame == m_frame->page()->mainWebFrame()) {
556 if (!webPage->corePage()->settings().suppressesIncrementalRendering() && !m_didCompletePageTransitionAlready) {
557 webPage->didCompletePageTransition();
558 m_didCompletePageTransitionAlready = true;
562 #if USE(TILED_BACKING_STORE)
563 // Make sure viewport properties are dispatched on the main frame by the time the first layout happens.
564 ASSERT(!webPage->useFixedLayout() || m_frame != m_frame->page()->mainWebFrame() || m_frame->coreFrame()->document()->didDispatchViewportPropertiesChanged());
568 // Send this after DidFirstLayout-specific calls since some clients expect to get those messages first.
569 webPage->injectedBundleLoaderClient().didLayout(webPage, milestones, userData);
570 webPage->send(Messages::WebPageProxy::DidLayout(milestones, InjectedBundleUserMessageEncoder(userData.get())));
572 if (milestones & DidFirstVisuallyNonEmptyLayout) {
573 // FIXME: We should consider removing the old didFirstVisuallyNonEmptyLayoutForFrame API since this is doing
574 // double duty with the new didLayout API.
575 webPage->injectedBundleLoaderClient().didFirstVisuallyNonEmptyLayoutForFrame(webPage, m_frame, userData);
576 webPage->send(Messages::WebPageProxy::DidFirstVisuallyNonEmptyLayoutForFrame(m_frame->frameID(), InjectedBundleUserMessageEncoder(userData.get())));
580 void WebFrameLoaderClient::dispatchDidLayout()
582 WebPage* webPage = m_frame->page();
586 // Notify the bundle client.
587 webPage->injectedBundleLoaderClient().didLayoutForFrame(webPage, m_frame);
589 webPage->recomputeShortCircuitHorizontalWheelEventsState();
591 // NOTE: Unlike the other layout notifications, this does not notify the
592 // the UIProcess for every call.
594 if (m_frame == m_frame->page()->mainWebFrame()) {
595 // FIXME: Remove at the soonest possible time.
596 webPage->send(Messages::WebPageProxy::SetRenderTreeSize(webPage->renderTreeSize()));
597 webPage->mainFrameDidLayout();
601 Frame* WebFrameLoaderClient::dispatchCreatePage(const NavigationAction& navigationAction)
603 WebPage* webPage = m_frame->page();
607 // Just call through to the chrome client.
608 Page* newPage = webPage->corePage()->chrome().createWindow(m_frame->coreFrame(), FrameLoadRequest(m_frame->coreFrame()->document()->securityOrigin()), WindowFeatures(), navigationAction);
612 return &newPage->mainFrame();
615 void WebFrameLoaderClient::dispatchShow()
617 WebPage* webPage = m_frame->page();
624 void WebFrameLoaderClient::dispatchDecidePolicyForResponse(const ResourceResponse& response, const ResourceRequest& request, FramePolicyFunction function)
626 WebPage* webPage = m_frame->page();
630 if (!request.url().string()) {
635 RefPtr<API::Object> userData;
637 // Notify the bundle client.
638 WKBundlePagePolicyAction policy = webPage->injectedBundlePolicyClient().decidePolicyForResponse(webPage, m_frame, response, request, userData);
639 if (policy == WKBundlePagePolicyActionUse) {
644 bool canShowMIMEType = webPage->canShowMIMEType(response.mimeType());
646 uint64_t listenerID = m_frame->setUpPolicyListener(std::move(function));
647 bool receivedPolicyAction;
648 uint64_t policyAction;
651 // Notify the UIProcess.
652 // FIXME (126021): It is not good to change IPC behavior conditionally, and SpinRunLoopWhileWaitingForReply was known to cause trouble in other similar cases.
653 unsigned syncSendFlags = (WebCore::AXObjectCache::accessibilityEnabled()) ? IPC::SpinRunLoopWhileWaitingForReply : 0;
654 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))
657 // We call this synchronously because CFNetwork can only convert a loading connection to a download from its didReceiveResponse callback.
658 if (receivedPolicyAction)
659 m_frame->didReceivePolicyDecision(listenerID, static_cast<PolicyAction>(policyAction), downloadID);
662 void WebFrameLoaderClient::dispatchDecidePolicyForNewWindowAction(const NavigationAction& navigationAction, const ResourceRequest& request, PassRefPtr<FormState> formState, const String& frameName, FramePolicyFunction function)
664 WebPage* webPage = m_frame->page();
668 RefPtr<API::Object> userData;
670 RefPtr<InjectedBundleNavigationAction> action = InjectedBundleNavigationAction::create(m_frame, navigationAction, formState);
672 // Notify the bundle client.
673 WKBundlePagePolicyAction policy = webPage->injectedBundlePolicyClient().decidePolicyForNewWindowAction(webPage, m_frame, action.get(), request, frameName, userData);
674 if (policy == WKBundlePagePolicyActionUse) {
680 uint64_t listenerID = m_frame->setUpPolicyListener(std::move(function));
682 NavigationActionData navigationActionData;
683 navigationActionData.navigationType = action->navigationType();
684 navigationActionData.modifiers = action->modifiers();
685 navigationActionData.mouseButton = action->mouseButton();
687 webPage->send(Messages::WebPageProxy::DecidePolicyForNewWindowAction(m_frame->frameID(), navigationActionData, request, frameName, listenerID, InjectedBundleUserMessageEncoder(userData.get())));
690 void WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction(const NavigationAction& navigationAction, const ResourceRequest& request, PassRefPtr<FormState> prpFormState, FramePolicyFunction function)
692 WebPage* webPage = m_frame->page();
696 // Always ignore requests with empty URLs.
697 if (request.isEmpty()) {
698 function(PolicyIgnore);
702 RefPtr<API::Object> userData;
703 RefPtr<FormState> formState = prpFormState;
705 RefPtr<InjectedBundleNavigationAction> action = InjectedBundleNavigationAction::create(m_frame, navigationAction, formState);
707 // Notify the bundle client.
708 WKBundlePagePolicyAction policy = webPage->injectedBundlePolicyClient().decidePolicyForNavigationAction(webPage, m_frame, action.get(), request, userData);
709 if (policy == WKBundlePagePolicyActionUse) {
714 uint64_t listenerID = m_frame->setUpPolicyListener(std::move(function));
715 bool receivedPolicyAction;
716 uint64_t policyAction;
719 RefPtr<WebFrame> originatingFrame;
720 switch (action->navigationType()) {
721 case NavigationTypeLinkClicked:
722 originatingFrame = action->hitTestResult()->frame();
724 case NavigationTypeFormSubmitted:
725 case NavigationTypeFormResubmitted:
727 if (WebFrameLoaderClient* originatingFrameLoaderClient = toWebFrameLoaderClient(formState->sourceDocument()->frame()->loader().client()))
728 originatingFrame = originatingFrameLoaderClient->webFrame();
731 case NavigationTypeBackForward:
732 case NavigationTypeReload:
733 case NavigationTypeOther:
737 NavigationActionData navigationActionData;
738 navigationActionData.navigationType = action->navigationType();
739 navigationActionData.modifiers = action->modifiers();
740 navigationActionData.mouseButton = action->mouseButton();
742 // Notify the UIProcess.
743 if (!webPage->sendSync(Messages::WebPageProxy::DecidePolicyForNavigationAction(m_frame->frameID(), navigationActionData, originatingFrame ? originatingFrame->frameID() : 0, navigationAction.resourceRequest(), request, listenerID, InjectedBundleUserMessageEncoder(userData.get())), Messages::WebPageProxy::DecidePolicyForNavigationAction::Reply(receivedPolicyAction, policyAction, downloadID)))
746 // We call this synchronously because WebCore cannot gracefully handle a frame load without a synchronous navigation policy reply.
747 if (receivedPolicyAction)
748 m_frame->didReceivePolicyDecision(listenerID, static_cast<PolicyAction>(policyAction), downloadID);
751 void WebFrameLoaderClient::cancelPolicyCheck()
753 m_frame->invalidatePolicyListener();
756 void WebFrameLoaderClient::dispatchUnableToImplementPolicy(const ResourceError& error)
758 WebPage* webPage = m_frame->page();
762 RefPtr<API::Object> userData;
764 // Notify the bundle client.
765 webPage->injectedBundlePolicyClient().unableToImplementPolicy(webPage, m_frame, error, userData);
767 // Notify the UIProcess.
768 webPage->send(Messages::WebPageProxy::UnableToImplementPolicy(m_frame->frameID(), error, InjectedBundleUserMessageEncoder(userData.get())));
771 void WebFrameLoaderClient::dispatchWillSendSubmitEvent(PassRefPtr<FormState> prpFormState)
773 WebPage* webPage = m_frame->page();
777 RefPtr<FormState> formState = prpFormState;
778 HTMLFormElement* form = formState->form();
780 WebFrameLoaderClient* webFrameLoaderClient = toWebFrameLoaderClient(formState->sourceDocument()->frame()->loader().client());
781 WebFrame* sourceFrame = webFrameLoaderClient ? webFrameLoaderClient->webFrame() : 0;
784 webPage->injectedBundleFormClient().willSendSubmitEvent(webPage, form, m_frame, sourceFrame, formState->textFieldValues());
787 void WebFrameLoaderClient::dispatchWillSubmitForm(PassRefPtr<FormState> prpFormState, FramePolicyFunction function)
789 WebPage* webPage = m_frame->page();
793 // FIXME: Pass more of the form state.
794 RefPtr<FormState> formState = prpFormState;
796 HTMLFormElement* form = formState->form();
798 WebFrameLoaderClient* webFrameLoaderClient = toWebFrameLoaderClient(formState->sourceDocument()->frame()->loader().client());
799 WebFrame* sourceFrame = webFrameLoaderClient ? webFrameLoaderClient->webFrame() : 0;
802 const Vector<std::pair<String, String>>& values = formState->textFieldValues();
804 RefPtr<API::Object> userData;
805 webPage->injectedBundleFormClient().willSubmitForm(webPage, form, m_frame, sourceFrame, values, userData);
808 uint64_t listenerID = m_frame->setUpPolicyListener(std::move(function));
810 webPage->send(Messages::WebPageProxy::WillSubmitForm(m_frame->frameID(), sourceFrame->frameID(), values, listenerID, InjectedBundleUserMessageEncoder(userData.get())));
813 void WebFrameLoaderClient::revertToProvisionalState(DocumentLoader*)
818 void WebFrameLoaderClient::setMainDocumentError(DocumentLoader*, const ResourceError& error)
823 m_pluginView->manualLoadDidFail(error);
825 m_hasSentResponseToPluginView = false;
828 void WebFrameLoaderClient::setMainFrameDocumentReady(bool)
833 void WebFrameLoaderClient::startDownload(const ResourceRequest& request, const String& /* suggestedName */)
835 m_frame->startDownload(request);
838 void WebFrameLoaderClient::willChangeTitle(DocumentLoader*)
843 void WebFrameLoaderClient::didChangeTitle(DocumentLoader*)
848 void WebFrameLoaderClient::committedLoad(DocumentLoader* loader, const char* data, int length)
851 loader->commitData(data, length);
853 // If the document is a stand-alone media document, now is the right time to cancel the WebKit load.
854 // FIXME: This code should be shared across all ports. <http://webkit.org/b/48762>.
855 if (m_frame->coreFrame()->document()->isMediaDocument())
856 loader->cancelMainResourceLoad(pluginWillHandleLoadError(loader->response()));
858 // Calling commitData did not create the plug-in view.
862 if (!m_hasSentResponseToPluginView) {
863 m_pluginView->manualLoadDidReceiveResponse(loader->response());
864 // manualLoadDidReceiveResponse sets up a new stream to the plug-in. on a full-page plug-in, a failure in
865 // setting up this stream can cause the main document load to be cancelled, setting m_pluginView
869 m_hasSentResponseToPluginView = true;
871 m_pluginView->manualLoadDidReceiveData(data, length);
874 void WebFrameLoaderClient::finishedLoading(DocumentLoader* loader)
879 // If we just received an empty response without any data, we won't have sent a response to the plug-in view.
880 // Make sure to do this before calling manualLoadDidFinishLoading.
881 if (!m_hasSentResponseToPluginView) {
882 m_pluginView->manualLoadDidReceiveResponse(loader->response());
884 // Protect against the above call nulling out the plug-in (by trying to cancel the load for example).
889 m_pluginView->manualLoadDidFinishLoading();
891 m_hasSentResponseToPluginView = false;
894 void WebFrameLoaderClient::updateGlobalHistory()
896 WebPage* webPage = m_frame->page();
897 if (!webPage || !webPage->pageGroup()->isVisibleToHistoryClient())
900 DocumentLoader* loader = m_frame->coreFrame()->loader().documentLoader();
902 WebNavigationDataStore data;
903 data.url = loader->url().string();
904 // FIXME: use direction of title.
905 data.title = loader->title().string();
906 data.originalRequest = loader->originalRequestCopy();
907 data.response = loader->response();
909 WebProcess::shared().parentProcessConnection()->send(Messages::WebProcessProxy::DidNavigateWithNavigationData(webPage->pageID(), data, m_frame->frameID()), 0);
912 void WebFrameLoaderClient::updateGlobalHistoryRedirectLinks()
914 WebPage* webPage = m_frame->page();
915 if (!webPage || !webPage->pageGroup()->isVisibleToHistoryClient())
918 DocumentLoader* loader = m_frame->coreFrame()->loader().documentLoader();
919 ASSERT(loader->unreachableURL().isEmpty());
922 if (!loader->clientRedirectSourceForHistory().isNull()) {
923 WebProcess::shared().parentProcessConnection()->send(Messages::WebProcessProxy::DidPerformClientRedirect(webPage->pageID(),
924 loader->clientRedirectSourceForHistory(), loader->clientRedirectDestinationForHistory(), m_frame->frameID()), 0);
928 if (!loader->serverRedirectSourceForHistory().isNull()) {
929 WebProcess::shared().parentProcessConnection()->send(Messages::WebProcessProxy::DidPerformServerRedirect(webPage->pageID(),
930 loader->serverRedirectSourceForHistory(), loader->serverRedirectDestinationForHistory(), m_frame->frameID()), 0);
934 bool WebFrameLoaderClient::shouldGoToHistoryItem(HistoryItem* item) const
936 WebPage* webPage = m_frame->page();
940 uint64_t itemID = WebBackForwardListProxy::idForItem(item);
942 // We should never be considering navigating to an item that is not actually in the back/forward list.
943 ASSERT_NOT_REACHED();
947 RefPtr<InjectedBundleBackForwardListItem> bundleItem = InjectedBundleBackForwardListItem::create(item);
948 RefPtr<API::Object> userData;
950 // Ask the bundle client first
951 bool shouldGoToBackForwardListItem = webPage->injectedBundleLoaderClient().shouldGoToBackForwardListItem(webPage, bundleItem.get(), userData);
952 if (!shouldGoToBackForwardListItem)
955 webPage->send(Messages::WebPageProxy::WillGoToBackForwardListItem(itemID, InjectedBundleUserMessageEncoder(userData.get())));
959 void WebFrameLoaderClient::didDisplayInsecureContent()
961 WebPage* webPage = m_frame->page();
965 RefPtr<API::Object> userData;
967 webPage->injectedBundleLoaderClient().didDisplayInsecureContentForFrame(webPage, m_frame, userData);
969 webPage->send(Messages::WebPageProxy::DidDisplayInsecureContentForFrame(m_frame->frameID(), InjectedBundleUserMessageEncoder(userData.get())));
972 void WebFrameLoaderClient::didRunInsecureContent(SecurityOrigin*, const URL&)
974 WebPage* webPage = m_frame->page();
978 RefPtr<API::Object> userData;
980 webPage->injectedBundleLoaderClient().didRunInsecureContentForFrame(webPage, m_frame, userData);
982 webPage->send(Messages::WebPageProxy::DidRunInsecureContentForFrame(m_frame->frameID(), InjectedBundleUserMessageEncoder(userData.get())));
985 void WebFrameLoaderClient::didDetectXSS(const URL&, bool)
987 WebPage* webPage = m_frame->page();
991 RefPtr<API::Object> userData;
993 webPage->injectedBundleLoaderClient().didDetectXSSForFrame(webPage, m_frame, userData);
995 webPage->send(Messages::WebPageProxy::DidDetectXSSForFrame(m_frame->frameID(), InjectedBundleUserMessageEncoder(userData.get())));
998 ResourceError WebFrameLoaderClient::cancelledError(const ResourceRequest& request)
1000 return WebKit::cancelledError(request);
1003 ResourceError WebFrameLoaderClient::blockedError(const ResourceRequest& request)
1005 return WebKit::blockedError(request);
1008 ResourceError WebFrameLoaderClient::cannotShowURLError(const ResourceRequest& request)
1010 return WebKit::cannotShowURLError(request);
1013 ResourceError WebFrameLoaderClient::interruptedForPolicyChangeError(const ResourceRequest& request)
1015 return WebKit::interruptedForPolicyChangeError(request);
1018 ResourceError WebFrameLoaderClient::cannotShowMIMETypeError(const ResourceResponse& response)
1020 return WebKit::cannotShowMIMETypeError(response);
1023 ResourceError WebFrameLoaderClient::fileDoesNotExistError(const ResourceResponse& response)
1025 return WebKit::fileDoesNotExistError(response);
1028 ResourceError WebFrameLoaderClient::pluginWillHandleLoadError(const ResourceResponse& response)
1030 return WebKit::pluginWillHandleLoadError(response);
1033 bool WebFrameLoaderClient::shouldFallBack(const ResourceError& error)
1035 static NeverDestroyed<const ResourceError> cancelledError(this->cancelledError(ResourceRequest()));
1036 static NeverDestroyed<const ResourceError> pluginWillHandleLoadError(this->pluginWillHandleLoadError(ResourceResponse()));
1038 if (error.errorCode() == cancelledError.get().errorCode() && error.domain() == cancelledError.get().domain())
1041 if (error.errorCode() == pluginWillHandleLoadError.get().errorCode() && error.domain() == pluginWillHandleLoadError.get().domain())
1047 bool WebFrameLoaderClient::canHandleRequest(const ResourceRequest&) const
1053 bool WebFrameLoaderClient::canShowMIMEType(const String& /*MIMEType*/) const
1059 bool WebFrameLoaderClient::canShowMIMETypeAsHTML(const String& /*MIMEType*/) const
1064 bool WebFrameLoaderClient::representationExistsForURLScheme(const String& /*URLScheme*/) const
1070 String WebFrameLoaderClient::generatedMIMETypeForURLScheme(const String& /*URLScheme*/) const
1076 void WebFrameLoaderClient::frameLoadCompleted()
1078 // Note: Can be called multiple times.
1079 WebPage* webPage = m_frame->page();
1083 if (m_frame == m_frame->page()->mainWebFrame() && !m_didCompletePageTransitionAlready) {
1084 webPage->didCompletePageTransition();
1085 m_didCompletePageTransitionAlready = true;
1089 void WebFrameLoaderClient::saveViewStateToItem(HistoryItem*)
1094 void WebFrameLoaderClient::restoreViewState()
1096 // Inform the UI process of the scale factor.
1097 double scaleFactor = m_frame->coreFrame()->loader().history().currentItem()->pageScaleFactor();
1099 // A scale factor of 0 means the history item has the default scale factor, thus we do not need to update it.
1101 m_frame->page()->send(Messages::WebPageProxy::PageScaleFactorDidChange(scaleFactor));
1103 // FIXME: This should not be necessary. WebCore should be correctly invalidating
1104 // the view on restores from the back/forward cache.
1105 if (m_frame == m_frame->page()->mainWebFrame())
1106 m_frame->page()->drawingArea()->setNeedsDisplay();
1109 void WebFrameLoaderClient::provisionalLoadStarted()
1111 WebPage* webPage = m_frame->page();
1115 if (m_frame == m_frame->page()->mainWebFrame()) {
1116 webPage->didStartPageTransition();
1117 m_didCompletePageTransitionAlready = false;
1121 void WebFrameLoaderClient::didFinishLoad()
1123 // If we have a load listener, notify it.
1124 if (WebFrame::LoadListener* loadListener = m_frame->loadListener())
1125 loadListener->didFinishLoad(m_frame);
1128 void WebFrameLoaderClient::prepareForDataSourceReplacement()
1133 PassRefPtr<DocumentLoader> WebFrameLoaderClient::createDocumentLoader(const ResourceRequest& request, const SubstituteData& data)
1135 return DocumentLoader::create(request, data);
1138 void WebFrameLoaderClient::setTitle(const StringWithDirection& title, const URL& url)
1140 WebPage* webPage = m_frame->page();
1141 if (!webPage || !webPage->pageGroup()->isVisibleToHistoryClient())
1144 // FIXME: use direction of title.
1145 WebProcess::shared().parentProcessConnection()->send(Messages::WebProcessProxy::DidUpdateHistoryTitle(webPage->pageID(),
1146 title.string(), url.string(), m_frame->frameID()), 0);
1149 String WebFrameLoaderClient::userAgent(const URL&)
1151 WebPage* webPage = m_frame->page();
1155 return webPage->userAgent();
1158 void WebFrameLoaderClient::savePlatformDataToCachedFrame(CachedFrame*)
1162 void WebFrameLoaderClient::transitionToCommittedFromCachedFrame(CachedFrame*)
1166 void WebFrameLoaderClient::transitionToCommittedForNewPage()
1168 WebPage* webPage = m_frame->page();
1170 Color backgroundColor = webPage->drawsTransparentBackground() ? Color::transparent : Color::white;
1171 bool isMainFrame = webPage->mainWebFrame() == m_frame;
1172 bool isTransparent = !webPage->drawsBackground();
1173 bool shouldUseFixedLayout = isMainFrame && webPage->useFixedLayout();
1174 bool shouldDisableScrolling = isMainFrame && !webPage->mainFrameIsScrollable();
1175 bool shouldHideScrollbars = shouldUseFixedLayout || shouldDisableScrolling;
1176 IntRect fixedVisibleContentRect;
1178 #if USE(TILED_BACKING_STORE)
1179 if (m_frame->coreFrame()->view())
1180 fixedVisibleContentRect = m_frame->coreFrame()->view()->fixedVisibleContentRect();
1183 m_frameCameFromPageCache = false;
1185 ScrollbarMode defaultScrollbarMode = shouldHideScrollbars ? ScrollbarAlwaysOff : ScrollbarAuto;
1187 m_frame->coreFrame()->createView(webPage->size(), backgroundColor, isTransparent,
1188 IntSize(), fixedVisibleContentRect, shouldUseFixedLayout,
1189 defaultScrollbarMode, /* lock */ shouldHideScrollbars, defaultScrollbarMode, /* lock */ shouldHideScrollbars);
1191 if (int minimumLayoutWidth = webPage->minimumLayoutSize().width()) {
1192 int minimumLayoutHeight = std::max(webPage->minimumLayoutSize().height(), 1);
1193 int maximumSize = std::numeric_limits<int>::max();
1194 m_frame->coreFrame()->view()->enableAutoSizeMode(true, IntSize(minimumLayoutWidth, minimumLayoutHeight), IntSize(maximumSize, maximumSize));
1195 m_frame->coreFrame()->view()->setAutoSizeFixedMinimumHeight(webPage->size().height());
1198 m_frame->coreFrame()->view()->setProhibitsScrolling(shouldDisableScrolling);
1199 m_frame->coreFrame()->view()->setVisualUpdatesAllowedByClient(!webPage->shouldExtendIncrementalRenderingSuppression());
1201 m_frame->coreFrame()->view()->setExposedRect(webPage->drawingArea()->exposedRect());
1204 m_frame->coreFrame()->view()->setDelegatesScrolling(true);
1207 if (webPage->scrollPinningBehavior() != DoNotPin)
1208 m_frame->coreFrame()->view()->setScrollPinningBehavior(webPage->scrollPinningBehavior());
1210 #if USE(TILED_BACKING_STORE)
1211 if (shouldUseFixedLayout) {
1212 m_frame->coreFrame()->view()->setDelegatesScrolling(shouldUseFixedLayout);
1213 m_frame->coreFrame()->view()->setPaintsEntireContents(shouldUseFixedLayout);
1219 void WebFrameLoaderClient::didSaveToPageCache()
1221 WebPage* webPage = m_frame->page();
1225 webPage->send(Messages::WebPageProxy::DidSaveToPageCache());
1228 void WebFrameLoaderClient::didRestoreFromPageCache()
1230 m_frameCameFromPageCache = true;
1233 void WebFrameLoaderClient::dispatchDidBecomeFrameset(bool value)
1235 WebPage* webPage = m_frame->page();
1239 webPage->send(Messages::WebPageProxy::FrameDidBecomeFrameSet(m_frame->frameID(), value));
1242 void WebFrameLoaderClient::convertMainResourceLoadToDownload(DocumentLoader *documentLoader, const ResourceRequest& request, const ResourceResponse& response)
1244 m_frame->convertMainResourceLoadToDownload(documentLoader, request, response);
1247 PassRefPtr<Frame> WebFrameLoaderClient::createFrame(const URL& url, const String& name, HTMLFrameOwnerElement* ownerElement,
1248 const String& referrer, bool /*allowsScrolling*/, int /*marginWidth*/, int /*marginHeight*/)
1250 WebPage* webPage = m_frame->page();
1252 RefPtr<WebFrame> subframe = WebFrame::createSubframe(webPage, name, ownerElement);
1254 Frame* coreSubframe = subframe->coreFrame();
1258 // The creation of the frame may have run arbitrary JavaScript that removed it from the page already.
1259 if (!coreSubframe->page())
1262 m_frame->coreFrame()->loader().loadURLIntoChildFrame(url, referrer, coreSubframe);
1264 // The frame's onload handler may have removed it from the document.
1265 if (!subframe->coreFrame())
1267 ASSERT(subframe->coreFrame() == coreSubframe);
1268 if (!coreSubframe->tree().parent())
1271 return coreSubframe;
1274 PassRefPtr<Widget> WebFrameLoaderClient::createPlugin(const IntSize&, HTMLPlugInElement* pluginElement, const URL& url, const Vector<String>& paramNames, const Vector<String>& paramValues, const String& mimeType, bool loadManually)
1276 ASSERT(paramNames.size() == paramValues.size());
1277 ASSERT(m_frame->page());
1279 Plugin::Parameters parameters;
1280 parameters.url = url;
1281 parameters.names = paramNames;
1282 parameters.values = paramValues;
1283 parameters.mimeType = mimeType;
1284 parameters.isFullFramePlugin = loadManually;
1285 parameters.shouldUseManualLoader = parameters.isFullFramePlugin && !m_frameCameFromPageCache;
1287 parameters.layerHostingMode = m_frame->page()->layerHostingMode();
1290 #if PLUGIN_ARCHITECTURE(X11)
1291 // FIXME: This should really be X11-specific plug-in quirks.
1292 if (equalIgnoringCase(mimeType, "application/x-shockwave-flash")) {
1293 // Currently we don't support transparency and windowed mode.
1294 // Inject wmode=opaque to make Flash work in these conditions.
1295 size_t wmodeIndex = parameters.names.find("wmode");
1296 if (wmodeIndex == notFound) {
1297 parameters.names.append("wmode");
1298 parameters.values.append("opaque");
1299 } else if (equalIgnoringCase(parameters.values[wmodeIndex], "window"))
1300 parameters.values[wmodeIndex] = "opaque";
1301 } else if (equalIgnoringCase(mimeType, "application/x-webkit-test-netscape")) {
1302 parameters.names.append("windowedPlugin");
1303 parameters.values.append("false");
1307 #if ENABLE(NETSCAPE_PLUGIN_API)
1308 RefPtr<Plugin> plugin = m_frame->page()->createPlugin(m_frame, pluginElement, parameters, parameters.mimeType);
1312 return PluginView::create(pluginElement, plugin.release(), parameters);
1314 UNUSED_PARAM(pluginElement);
1319 void WebFrameLoaderClient::recreatePlugin(Widget* widget)
1321 #if ENABLE(NETSCAPE_PLUGIN_API)
1322 ASSERT(widget && widget->isPluginViewBase());
1323 ASSERT(m_frame->page());
1325 PluginView* pluginView = static_cast<PluginView*>(widget);
1327 RefPtr<Plugin> plugin = m_frame->page()->createPlugin(m_frame, pluginView->pluginElement(), pluginView->initialParameters(), newMIMEType);
1328 pluginView->recreateAndInitialize(plugin.release());
1330 UNUSED_PARAM(widget);
1334 void WebFrameLoaderClient::redirectDataToPlugin(Widget* pluginWidget)
1337 m_pluginView = static_cast<PluginView*>(pluginWidget);
1341 WebCore::WebGLLoadPolicy WebFrameLoaderClient::webGLPolicyForURL(const String& url) const
1343 if (WebPage* webPage = m_frame->page())
1344 return webPage->webGLPolicyForURL(m_frame, url);
1348 #endif // ENABLE(WEBGL)
1350 PassRefPtr<Widget> WebFrameLoaderClient::createJavaAppletWidget(const IntSize& pluginSize, HTMLAppletElement* appletElement, const URL&, const Vector<String>& paramNames, const Vector<String>& paramValues)
1352 #if ENABLE(NETSCAPE_PLUGIN_API)
1353 RefPtr<Widget> plugin = createPlugin(pluginSize, appletElement, URL(), paramNames, paramValues, appletElement->serviceType(), false);
1355 if (WebPage* webPage = m_frame->page()) {
1356 String frameURLString = m_frame->coreFrame()->loader().documentLoader()->responseURL().string();
1357 String pageURLString = webPage->corePage()->mainFrame().loader().documentLoader()->responseURL().string();
1358 webPage->send(Messages::WebPageProxy::DidFailToInitializePlugin(appletElement->serviceType(), frameURLString, pageURLString));
1361 return plugin.release();
1363 UNUSED_PARAM(pluginSize);
1364 UNUSED_PARAM(appletElement);
1365 UNUSED_PARAM(paramNames);
1366 UNUSED_PARAM(paramValues);
1371 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
1372 PassRefPtr<Widget> WebFrameLoaderClient::createMediaPlayerProxyPlugin(const IntSize&, HTMLMediaElement*, const URL&, const Vector<String>&, const Vector<String>&, const String&)
1378 void WebFrameLoaderClient::hideMediaPlayerProxyPlugin(Widget*)
1383 void WebFrameLoaderClient::showMediaPlayerProxyPlugin(Widget*)
1389 static bool pluginSupportsExtension(const PluginData& pluginData, const String& extension)
1391 ASSERT(extension.lower() == extension);
1393 for (size_t i = 0; i < pluginData.mimes().size(); ++i) {
1394 const MimeClassInfo& mimeClassInfo = pluginData.mimes()[i];
1396 if (mimeClassInfo.extensions.contains(extension))
1402 ObjectContentType WebFrameLoaderClient::objectContentType(const URL& url, const String& mimeTypeIn, bool shouldPreferPlugInsForImages)
1404 // FIXME: This should be merged with WebCore::FrameLoader::defaultObjectContentType when the plugin code
1407 String mimeType = mimeTypeIn;
1408 if (mimeType.isEmpty()) {
1409 String extension = url.path().substring(url.path().reverseFind('.') + 1).lower();
1411 // Try to guess the MIME type from the extension.
1412 mimeType = MIMETypeRegistry::getMIMETypeForExtension(extension);
1414 if (mimeType.isEmpty()) {
1415 // Check if there's a plug-in around that can handle the extension.
1416 if (WebPage* webPage = m_frame->page()) {
1417 if (pluginSupportsExtension(webPage->corePage()->pluginData(), extension))
1418 return ObjectContentNetscapePlugin;
1423 if (mimeType.isEmpty())
1424 return ObjectContentFrame;
1426 bool plugInSupportsMIMEType = false;
1427 if (WebPage* webPage = m_frame->page()) {
1428 const PluginData& pluginData = webPage->corePage()->pluginData();
1429 if (pluginData.supportsMimeType(mimeType, PluginData::AllPlugins) && webFrame()->coreFrame()->loader().subframeLoader().allowPlugins(NotAboutToInstantiatePlugin))
1430 plugInSupportsMIMEType = true;
1431 else if (pluginData.supportsMimeType(mimeType, PluginData::OnlyApplicationPlugins))
1432 plugInSupportsMIMEType = true;
1435 if (MIMETypeRegistry::isSupportedImageMIMEType(mimeType))
1436 return shouldPreferPlugInsForImages && plugInSupportsMIMEType ? ObjectContentNetscapePlugin : ObjectContentImage;
1438 if (plugInSupportsMIMEType)
1439 return ObjectContentNetscapePlugin;
1441 if (MIMETypeRegistry::isSupportedNonImageMIMEType(mimeType))
1442 return ObjectContentFrame;
1444 return ObjectContentNone;
1447 String WebFrameLoaderClient::overrideMediaType() const
1453 void WebFrameLoaderClient::dispatchDidClearWindowObjectInWorld(DOMWrapperWorld& world)
1455 WebPage* webPage = m_frame->page();
1459 webPage->injectedBundleLoaderClient().didClearWindowObjectForFrame(webPage, m_frame, world);
1461 #if HAVE(ACCESSIBILITY) && (PLATFORM(GTK) || PLATFORM(EFL))
1462 // Ensure the accessibility hierarchy is updated.
1463 webPage->updateAccessibilityTree();
1468 void WebFrameLoaderClient::dispatchGlobalObjectAvailable(DOMWrapperWorld& world)
1470 WebPage* webPage = m_frame->page();
1474 webPage->injectedBundleLoaderClient().globalObjectIsAvailableForFrame(webPage, m_frame, world);
1477 void WebFrameLoaderClient::dispatchWillDisconnectDOMWindowExtensionFromGlobalObject(WebCore::DOMWindowExtension* extension)
1479 WebPage* webPage = m_frame->page();
1483 webPage->injectedBundleLoaderClient().willDisconnectDOMWindowExtensionFromGlobalObject(webPage, extension);
1486 void WebFrameLoaderClient::dispatchDidReconnectDOMWindowExtensionToGlobalObject(WebCore::DOMWindowExtension* extension)
1488 WebPage* webPage = m_frame->page();
1492 webPage->injectedBundleLoaderClient().didReconnectDOMWindowExtensionToGlobalObject(webPage, extension);
1495 void WebFrameLoaderClient::dispatchWillDestroyGlobalObjectForDOMWindowExtension(WebCore::DOMWindowExtension* extension)
1497 WebPage* webPage = m_frame->page();
1501 webPage->injectedBundleLoaderClient().willDestroyGlobalObjectForDOMWindowExtension(webPage, extension);
1504 void WebFrameLoaderClient::registerForIconNotification(bool /*listen*/)
1511 RemoteAXObjectRef WebFrameLoaderClient::accessibilityRemoteObject()
1513 WebPage* webPage = m_frame->page();
1517 return webPage->accessibilityRemoteObject();
1520 NSCachedURLResponse* WebFrameLoaderClient::willCacheResponse(DocumentLoader*, unsigned long identifier, NSCachedURLResponse* response) const
1522 WebPage* webPage = m_frame->page();
1526 return webPage->injectedBundleResourceLoadClient().shouldCacheResponse(webPage, m_frame, identifier) ? response : nil;
1529 #endif // PLATFORM(MAC)
1531 bool WebFrameLoaderClient::shouldAlwaysUsePluginDocument(const String& /*mimeType*/) const
1537 void WebFrameLoaderClient::didChangeScrollOffset()
1539 WebPage* webPage = m_frame->page();
1543 webPage->drawingArea()->didChangeScrollOffsetForAnyFrame();
1545 if (!m_frame->isMainFrame())
1548 // If this is called when tearing down a FrameView, the WebCore::Frame's
1549 // current FrameView will be null.
1550 if (!m_frame->coreFrame()->view())
1553 webPage->updateMainFrameScrollOffsetPinning();
1556 bool WebFrameLoaderClient::allowScript(bool enabledPerSettings)
1558 if (!enabledPerSettings)
1561 Frame* coreFrame = m_frame->coreFrame();
1563 if (coreFrame->document()->isPluginDocument()) {
1564 PluginDocument* pluginDocument = static_cast<PluginDocument*>(coreFrame->document());
1566 if (pluginDocument->pluginWidget() && pluginDocument->pluginWidget()->isPluginView()) {
1567 PluginView* pluginView = static_cast<PluginView*>(pluginDocument->pluginWidget());
1569 if (!pluginView->shouldAllowScripting())
1577 bool WebFrameLoaderClient::shouldForceUniversalAccessFromLocalURL(const WebCore::URL& url)
1579 WebPage* webPage = m_frame->page();
1583 return webPage->injectedBundleLoaderClient().shouldForceUniversalAccessFromLocalURL(webPage, url.string());
1586 PassRefPtr<FrameNetworkingContext> WebFrameLoaderClient::createNetworkingContext()
1588 RefPtr<WebFrameNetworkingContext> context = WebFrameNetworkingContext::create(m_frame);
1589 return context.release();
1592 } // namespace WebKit