2 * Copyright (C) 2009, 2012 Google Inc. All rights reserved.
3 * Copyright (C) 2011 Apple Inc. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include "web/FrameLoaderClientImpl.h"
35 #include "bindings/core/v8/ScriptController.h"
36 #include "core/HTMLNames.h"
37 #include "core/dom/Document.h"
38 #include "core/dom/Fullscreen.h"
39 #include "core/events/MessageEvent.h"
40 #include "core/events/MouseEvent.h"
41 #include "core/events/UIEventWithKeyState.h"
42 #include "core/frame/FrameView.h"
43 #include "core/frame/Settings.h"
44 #include "core/html/HTMLMediaElement.h"
45 #include "core/html/HTMLPlugInElement.h"
46 #include "core/input/EventHandler.h"
47 #include "core/layout/HitTestResult.h"
48 #include "core/loader/DocumentLoader.h"
49 #include "core/loader/FrameLoadRequest.h"
50 #include "core/loader/FrameLoader.h"
51 #include "core/loader/HistoryItem.h"
52 #include "core/page/Page.h"
53 #include "core/page/WindowFeatures.h"
54 #include "modules/device_light/DeviceLightController.h"
55 #include "modules/device_orientation/DeviceMotionController.h"
56 #include "modules/device_orientation/DeviceOrientationController.h"
57 #include "modules/encryptedmedia/HTMLMediaElementEncryptedMedia.h"
58 #include "modules/gamepad/NavigatorGamepad.h"
59 #include "modules/serviceworkers/NavigatorServiceWorker.h"
60 #include "modules/storage/DOMWindowStorageController.h"
61 #include "modules/vr/NavigatorVRDevice.h"
62 #include "platform/MIMETypeRegistry.h"
63 #include "platform/RuntimeEnabledFeatures.h"
64 #include "platform/UserGestureIndicator.h"
65 #include "platform/exported/WrappedResourceRequest.h"
66 #include "platform/exported/WrappedResourceResponse.h"
67 #include "platform/network/HTTPParsers.h"
68 #include "platform/plugins/PluginData.h"
69 #include "public/platform/Platform.h"
70 #include "public/platform/WebApplicationCacheHost.h"
71 #include "public/platform/WebMimeRegistry.h"
72 #include "public/platform/WebRTCPeerConnectionHandler.h"
73 #include "public/platform/WebSecurityOrigin.h"
74 #include "public/platform/WebServiceWorkerProvider.h"
75 #include "public/platform/WebServiceWorkerProviderClient.h"
76 #include "public/platform/WebURL.h"
77 #include "public/platform/WebURLError.h"
78 #include "public/platform/WebVector.h"
79 #include "public/web/WebAutofillClient.h"
80 #include "public/web/WebContentSettingsClient.h"
81 #include "public/web/WebDOMEvent.h"
82 #include "public/web/WebDocument.h"
83 #include "public/web/WebFormElement.h"
84 #include "public/web/WebFrameClient.h"
85 #include "public/web/WebNode.h"
86 #include "public/web/WebPlugin.h"
87 #include "public/web/WebPluginParams.h"
88 #include "public/web/WebViewClient.h"
89 #include "web/DevToolsEmulator.h"
90 #include "web/SharedWorkerRepositoryClientImpl.h"
91 #include "web/WebDataSourceImpl.h"
92 #include "web/WebDevToolsAgentImpl.h"
93 #include "web/WebDevToolsFrontendImpl.h"
94 #include "web/WebLocalFrameImpl.h"
95 #include "web/WebPluginContainerImpl.h"
96 #include "web/WebPluginLoadObserver.h"
97 #include "web/WebViewImpl.h"
98 #include "wtf/StringExtras.h"
99 #include "wtf/text/CString.h"
100 #include "wtf/text/WTFString.h"
105 FrameLoaderClientImpl::FrameLoaderClientImpl(WebLocalFrameImpl
* frame
)
110 PassOwnPtrWillBeRawPtr
<FrameLoaderClientImpl
> FrameLoaderClientImpl::create(WebLocalFrameImpl
* frame
)
112 return adoptPtrWillBeNoop(new FrameLoaderClientImpl(frame
));
115 FrameLoaderClientImpl::~FrameLoaderClientImpl()
119 DEFINE_TRACE(FrameLoaderClientImpl
)
121 visitor
->trace(m_webFrame
);
122 FrameLoaderClient::trace(visitor
);
125 void FrameLoaderClientImpl::didCreateNewDocument()
127 if (m_webFrame
->client())
128 m_webFrame
->client()->didCreateNewDocument(m_webFrame
);
131 void FrameLoaderClientImpl::dispatchDidClearWindowObjectInMainWorld()
133 if (m_webFrame
->client()) {
134 m_webFrame
->client()->didClearWindowObject(m_webFrame
);
135 Document
* document
= m_webFrame
->frame()->document();
137 DeviceMotionController::from(*document
);
138 DeviceOrientationController::from(*document
);
139 if (RuntimeEnabledFeatures::deviceLightEnabled())
140 DeviceLightController::from(*document
);
141 NavigatorGamepad::from(*document
);
142 NavigatorServiceWorker::from(*document
);
143 DOMWindowStorageController::from(*document
);
144 if (RuntimeEnabledFeatures::webVREnabled())
145 NavigatorVRDevice::from(*document
);
148 // FIXME: when extensions go out of process, this whole concept stops working.
149 WebDevToolsFrontendImpl
* devToolsFrontend
= m_webFrame
->top()->isWebLocalFrame() ? toWebLocalFrameImpl(m_webFrame
->top())->devToolsFrontend() : nullptr;
150 if (devToolsFrontend
)
151 devToolsFrontend
->didClearWindowObject(m_webFrame
);
154 void FrameLoaderClientImpl::documentElementAvailable()
156 if (m_webFrame
->client())
157 m_webFrame
->client()->didCreateDocumentElement(m_webFrame
);
159 if (m_webFrame
->viewImpl())
160 m_webFrame
->viewImpl()->documentElementAvailable(m_webFrame
);
163 void FrameLoaderClientImpl::didCreateScriptContext(v8::Local
<v8::Context
> context
, int extensionGroup
, int worldId
)
165 if (m_webFrame
->client())
166 m_webFrame
->client()->didCreateScriptContext(m_webFrame
, context
, extensionGroup
, worldId
);
169 void FrameLoaderClientImpl::willReleaseScriptContext(v8::Local
<v8::Context
> context
, int worldId
)
171 if (m_webFrame
->client())
172 m_webFrame
->client()->willReleaseScriptContext(m_webFrame
, context
, worldId
);
175 bool FrameLoaderClientImpl::allowScriptExtension(const String
& extensionName
,
179 if (m_webFrame
->contentSettingsClient())
180 return m_webFrame
->contentSettingsClient()->allowScriptExtension(extensionName
, extensionGroup
, worldId
);
185 void FrameLoaderClientImpl::didChangeScrollOffset()
187 if (m_webFrame
->client())
188 m_webFrame
->client()->didChangeScrollOffset(m_webFrame
);
189 if (WebViewImpl
* webview
= m_webFrame
->viewImpl())
190 webview
->devToolsEmulator()->viewportChanged();
193 void FrameLoaderClientImpl::didUpdateCurrentHistoryItem()
195 if (m_webFrame
->client())
196 m_webFrame
->client()->didUpdateCurrentHistoryItem(m_webFrame
);
199 void FrameLoaderClientImpl::didRemoveAllPendingStylesheet()
201 WebViewImpl
* webview
= m_webFrame
->viewImpl();
203 webview
->didRemoveAllPendingStylesheet(m_webFrame
);
206 bool FrameLoaderClientImpl::allowScript(bool enabledPerSettings
)
208 if (m_webFrame
->contentSettingsClient())
209 return m_webFrame
->contentSettingsClient()->allowScript(enabledPerSettings
);
211 return enabledPerSettings
;
214 bool FrameLoaderClientImpl::allowScriptFromSource(bool enabledPerSettings
, const KURL
& scriptURL
)
216 if (m_webFrame
->contentSettingsClient())
217 return m_webFrame
->contentSettingsClient()->allowScriptFromSource(enabledPerSettings
, scriptURL
);
219 return enabledPerSettings
;
222 bool FrameLoaderClientImpl::allowPlugins(bool enabledPerSettings
)
224 if (m_webFrame
->contentSettingsClient())
225 return m_webFrame
->contentSettingsClient()->allowPlugins(enabledPerSettings
);
227 return enabledPerSettings
;
230 bool FrameLoaderClientImpl::allowImage(bool enabledPerSettings
, const KURL
& imageURL
)
232 if (m_webFrame
->contentSettingsClient())
233 return m_webFrame
->contentSettingsClient()->allowImage(enabledPerSettings
, imageURL
);
235 return enabledPerSettings
;
238 bool FrameLoaderClientImpl::allowMedia(const KURL
& mediaURL
)
240 if (m_webFrame
->contentSettingsClient())
241 return m_webFrame
->contentSettingsClient()->allowMedia(mediaURL
);
246 bool FrameLoaderClientImpl::allowDisplayingInsecureContent(bool enabledPerSettings
, SecurityOrigin
* context
, const KURL
& url
)
248 if (m_webFrame
->contentSettingsClient())
249 return m_webFrame
->contentSettingsClient()->allowDisplayingInsecureContent(enabledPerSettings
, WebSecurityOrigin(context
), WebURL(url
));
251 return enabledPerSettings
;
254 bool FrameLoaderClientImpl::allowRunningInsecureContent(bool enabledPerSettings
, SecurityOrigin
* context
, const KURL
& url
)
256 if (m_webFrame
->contentSettingsClient())
257 return m_webFrame
->contentSettingsClient()->allowRunningInsecureContent(enabledPerSettings
, WebSecurityOrigin(context
), WebURL(url
));
259 return enabledPerSettings
;
262 void FrameLoaderClientImpl::didNotAllowScript()
264 if (m_webFrame
->contentSettingsClient())
265 m_webFrame
->contentSettingsClient()->didNotAllowScript();
268 void FrameLoaderClientImpl::didNotAllowPlugins()
270 if (m_webFrame
->contentSettingsClient())
271 m_webFrame
->contentSettingsClient()->didNotAllowPlugins();
275 bool FrameLoaderClientImpl::hasWebView() const
277 return m_webFrame
->viewImpl();
280 bool FrameLoaderClientImpl::inShadowTree() const
282 return m_webFrame
->inShadowTree();
285 Frame
* FrameLoaderClientImpl::opener() const
287 return toCoreFrame(m_webFrame
->opener());
290 void FrameLoaderClientImpl::setOpener(Frame
* opener
)
292 WebFrame
* openerFrame
= WebFrame::fromFrame(opener
);
293 if (m_webFrame
->client() && m_webFrame
->opener() != openerFrame
)
294 m_webFrame
->client()->didChangeOpener(openerFrame
);
295 m_webFrame
->setOpener(openerFrame
);
298 Frame
* FrameLoaderClientImpl::parent() const
300 return toCoreFrame(m_webFrame
->parent());
303 Frame
* FrameLoaderClientImpl::top() const
305 return toCoreFrame(m_webFrame
->top());
308 Frame
* FrameLoaderClientImpl::previousSibling() const
310 return toCoreFrame(m_webFrame
->previousSibling());
313 Frame
* FrameLoaderClientImpl::nextSibling() const
315 return toCoreFrame(m_webFrame
->nextSibling());
318 Frame
* FrameLoaderClientImpl::firstChild() const
320 return toCoreFrame(m_webFrame
->firstChild());
323 Frame
* FrameLoaderClientImpl::lastChild() const
325 return toCoreFrame(m_webFrame
->lastChild());
328 void FrameLoaderClientImpl::willBeDetached()
330 m_webFrame
->willBeDetached();
333 void FrameLoaderClientImpl::detached(FrameDetachType type
)
335 // Alert the client that the frame is being detached. This is the last
336 // chance we have to communicate with the client.
337 RefPtrWillBeRawPtr
<WebLocalFrameImpl
> protector(m_webFrame
.get());
339 WebFrameClient
* client
= m_webFrame
->client();
343 m_webFrame
->willDetachParent();
345 // Signal that no further communication with WebFrameClient should take
346 // place at this point since we are no longer associated with the Page.
347 m_webFrame
->setClient(0);
349 client
->frameDetached(m_webFrame
, static_cast<WebFrameClient::DetachType
>(type
));
350 // Clear our reference to LocalFrame at the very end, in case the client
352 m_webFrame
->setCoreFrame(nullptr);
355 void FrameLoaderClientImpl::dispatchWillSendRequest(
356 DocumentLoader
* loader
, unsigned long identifier
, ResourceRequest
& request
,
357 const ResourceResponse
& redirectResponse
)
359 // Give the WebFrameClient a crack at the request.
360 if (m_webFrame
->client()) {
361 WrappedResourceRequest
webreq(request
);
362 WrappedResourceResponse
webresp(redirectResponse
);
363 m_webFrame
->client()->willSendRequest(
364 m_webFrame
, identifier
, webreq
, webresp
);
368 void FrameLoaderClientImpl::dispatchDidReceiveResponse(DocumentLoader
* loader
,
369 unsigned long identifier
,
370 const ResourceResponse
& response
)
372 if (m_webFrame
->client()) {
373 WrappedResourceResponse
webresp(response
);
374 m_webFrame
->client()->didReceiveResponse(m_webFrame
, identifier
, webresp
);
378 void FrameLoaderClientImpl::dispatchDidChangeResourcePriority(unsigned long identifier
, ResourceLoadPriority priority
, int intraPriorityValue
)
380 if (m_webFrame
->client())
381 m_webFrame
->client()->didChangeResourcePriority(m_webFrame
, identifier
, static_cast<WebURLRequest::Priority
>(priority
), intraPriorityValue
);
384 // Called when a particular resource load completes
385 void FrameLoaderClientImpl::dispatchDidFinishLoading(DocumentLoader
* loader
,
386 unsigned long identifier
)
388 if (m_webFrame
->client())
389 m_webFrame
->client()->didFinishResourceLoad(m_webFrame
, identifier
);
392 void FrameLoaderClientImpl::dispatchDidFinishDocumentLoad(bool documentIsEmpty
)
394 if (m_webFrame
->client())
395 m_webFrame
->client()->didFinishDocumentLoad(m_webFrame
, documentIsEmpty
);
396 if (WebViewImpl
* webview
= m_webFrame
->viewImpl())
397 webview
->didFinishDocumentLoad(m_webFrame
);
400 void FrameLoaderClientImpl::dispatchDidLoadResourceFromMemoryCache(const ResourceRequest
& request
, const ResourceResponse
& response
)
402 if (m_webFrame
->client())
403 m_webFrame
->client()->didLoadResourceFromMemoryCache(m_webFrame
, WrappedResourceRequest(request
), WrappedResourceResponse(response
));
406 void FrameLoaderClientImpl::dispatchDidHandleOnloadEvents()
408 if (m_webFrame
->client())
409 m_webFrame
->client()->didHandleOnloadEvents(m_webFrame
);
412 void FrameLoaderClientImpl::dispatchDidReceiveServerRedirectForProvisionalLoad()
414 if (m_webFrame
->client())
415 m_webFrame
->client()->didReceiveServerRedirectForProvisionalLoad(m_webFrame
);
418 void FrameLoaderClientImpl::dispatchDidNavigateWithinPage(HistoryItem
* item
, HistoryCommitType commitType
)
420 bool shouldCreateHistoryEntry
= commitType
== StandardCommit
;
421 m_webFrame
->viewImpl()->didCommitLoad(shouldCreateHistoryEntry
, true);
422 if (m_webFrame
->client())
423 m_webFrame
->client()->didNavigateWithinPage(m_webFrame
, WebHistoryItem(item
), static_cast<WebHistoryCommitType
>(commitType
));
426 void FrameLoaderClientImpl::dispatchWillClose()
428 if (m_webFrame
->client())
429 m_webFrame
->client()->willClose(m_webFrame
);
432 void FrameLoaderClientImpl::dispatchDidStartProvisionalLoad(double triggeringEventTime
)
434 if (m_webFrame
->client())
435 m_webFrame
->client()->didStartProvisionalLoad(m_webFrame
, triggeringEventTime
);
438 void FrameLoaderClientImpl::dispatchDidReceiveTitle(const String
& title
)
440 if (m_webFrame
->client())
441 m_webFrame
->client()->didReceiveTitle(m_webFrame
, title
, WebTextDirectionLeftToRight
);
444 void FrameLoaderClientImpl::dispatchDidChangeIcons(IconType type
)
446 if (m_webFrame
->client())
447 m_webFrame
->client()->didChangeIcon(m_webFrame
, static_cast<WebIconURL::Type
>(type
));
450 void FrameLoaderClientImpl::dispatchDidCommitLoad(HistoryItem
* item
, HistoryCommitType commitType
)
452 m_webFrame
->viewImpl()->didCommitLoad(commitType
== StandardCommit
, false);
453 if (m_webFrame
->client())
454 m_webFrame
->client()->didCommitProvisionalLoad(m_webFrame
, WebHistoryItem(item
), static_cast<WebHistoryCommitType
>(commitType
));
455 WebDevToolsAgentImpl
* devToolsAgent
= WebLocalFrameImpl::fromFrame(m_webFrame
->frame()->localFrameRoot())->devToolsAgentImpl();
457 devToolsAgent
->didCommitLoadForLocalFrame(m_webFrame
->frame());
460 void FrameLoaderClientImpl::dispatchDidFailProvisionalLoad(
461 const ResourceError
& error
, HistoryCommitType commitType
)
463 OwnPtr
<WebPluginLoadObserver
> observer
= pluginLoadObserver(m_webFrame
->frame()->loader().provisionalDocumentLoader());
464 m_webFrame
->didFail(error
, true, commitType
);
466 observer
->didFailLoading(error
);
469 void FrameLoaderClientImpl::dispatchDidFailLoad(const ResourceError
& error
, HistoryCommitType commitType
)
471 OwnPtr
<WebPluginLoadObserver
> observer
= pluginLoadObserver(m_webFrame
->frame()->loader().documentLoader());
472 m_webFrame
->didFail(error
, false, commitType
);
474 observer
->didFailLoading(error
);
476 // Don't clear the redirect chain, this will happen in the middle of client
477 // redirects, and we need the context. The chain will be cleared when the
478 // provisional load succeeds or fails, not the "real" one.
481 void FrameLoaderClientImpl::dispatchDidFinishLoad()
483 OwnPtr
<WebPluginLoadObserver
> observer
= pluginLoadObserver(m_webFrame
->frame()->loader().documentLoader());
485 if (m_webFrame
->client())
486 m_webFrame
->client()->didFinishLoad(m_webFrame
);
489 observer
->didFinishLoading();
491 // Don't clear the redirect chain, this will happen in the middle of client
492 // redirects, and we need the context. The chain will be cleared when the
493 // provisional load succeeds or fails, not the "real" one.
496 void FrameLoaderClientImpl::dispatchDidChangeThemeColor()
498 if (m_webFrame
->client())
499 m_webFrame
->client()->didChangeThemeColor();
502 static bool allowCreatingBackgroundTabs()
505 const WebInputEvent
* inputEvent
= WebViewImpl::currentInputEvent();
506 if (!inputEvent
|| (inputEvent
->type
!= WebInputEvent::MouseUp
&& (inputEvent
->type
!= WebInputEvent::RawKeyDown
&& inputEvent
->type
!= WebInputEvent::KeyDown
)
507 && inputEvent
->type
!= WebInputEvent::GestureTap
))
510 unsigned short buttonNumber
;
511 if (WebInputEvent::isMouseEventType(inputEvent
->type
)) {
512 const WebMouseEvent
* mouseEvent
= static_cast<const WebMouseEvent
*>(inputEvent
);
514 switch (mouseEvent
->button
) {
515 case WebMouseEvent::ButtonLeft
:
518 case WebMouseEvent::ButtonMiddle
:
521 case WebMouseEvent::ButtonRight
:
528 // The click is simulated when triggering the keypress event.
531 bool ctrl
= inputEvent
->modifiers
& WebMouseEvent::ControlKey
;
532 bool shift
= inputEvent
->modifiers
& WebMouseEvent::ShiftKey
;
533 bool alt
= inputEvent
->modifiers
& WebMouseEvent::AltKey
;
534 bool meta
= inputEvent
->modifiers
& WebMouseEvent::MetaKey
;
536 NavigationPolicy userPolicy
;
537 if (!navigationPolicyFromMouseEvent(buttonNumber
, ctrl
, shift
, alt
, meta
, &userPolicy
))
539 return userPolicy
== NavigationPolicyNewBackgroundTab
;
542 NavigationPolicy
FrameLoaderClientImpl::decidePolicyForNavigation(const ResourceRequest
& request
, DocumentLoader
* loader
, NavigationPolicy policy
)
544 if (!m_webFrame
->client())
545 return NavigationPolicyIgnore
;
547 if (policy
== NavigationPolicyNewBackgroundTab
&& !allowCreatingBackgroundTabs() && !UIEventWithKeyState::newTabModifierSetFromIsolatedWorld())
548 policy
= NavigationPolicyNewForegroundTab
;
550 WebDataSourceImpl
* ds
= WebDataSourceImpl::fromDocumentLoader(loader
);
552 WrappedResourceRequest
wrappedResourceRequest(request
);
553 WebFrameClient::NavigationPolicyInfo
navigationInfo(wrappedResourceRequest
);
554 navigationInfo
.frame
= m_webFrame
;
555 navigationInfo
.extraData
= ds
->extraData();
556 navigationInfo
.navigationType
= ds
->navigationType();
557 navigationInfo
.defaultPolicy
= static_cast<WebNavigationPolicy
>(policy
);
558 navigationInfo
.isRedirect
= ds
->isRedirect();
560 WebNavigationPolicy webPolicy
= m_webFrame
->client()->decidePolicyForNavigation(navigationInfo
);
561 return static_cast<NavigationPolicy
>(webPolicy
);
564 void FrameLoaderClientImpl::dispatchWillSendSubmitEvent(HTMLFormElement
* form
)
566 if (m_webFrame
->client())
567 m_webFrame
->client()->willSendSubmitEvent(m_webFrame
, WebFormElement(form
));
570 void FrameLoaderClientImpl::dispatchWillSubmitForm(HTMLFormElement
* form
)
572 if (m_webFrame
->client())
573 m_webFrame
->client()->willSubmitForm(m_webFrame
, WebFormElement(form
));
576 void FrameLoaderClientImpl::didStartLoading(LoadStartType loadStartType
)
578 if (m_webFrame
->client())
579 m_webFrame
->client()->didStartLoading(loadStartType
== NavigationToDifferentDocument
);
582 void FrameLoaderClientImpl::progressEstimateChanged(double progressEstimate
)
584 if (m_webFrame
->client())
585 m_webFrame
->client()->didChangeLoadProgress(progressEstimate
);
588 void FrameLoaderClientImpl::didStopLoading()
590 if (m_webFrame
->client())
591 m_webFrame
->client()->didStopLoading();
594 void FrameLoaderClientImpl::loadURLExternally(const ResourceRequest
& request
, NavigationPolicy policy
, const String
& suggestedName
)
596 if (m_webFrame
->client()) {
597 ASSERT(m_webFrame
->frame()->document());
598 Fullscreen::fullyExitFullscreen(*m_webFrame
->frame()->document());
599 WrappedResourceRequest
webreq(request
);
600 m_webFrame
->client()->loadURLExternally(
601 m_webFrame
, webreq
, static_cast<WebNavigationPolicy
>(policy
), suggestedName
);
605 bool FrameLoaderClientImpl::navigateBackForward(int offset
) const
607 WebViewImpl
* webview
= m_webFrame
->viewImpl();
608 if (!webview
->client())
612 if (offset
> webview
->client()->historyForwardListCount())
614 if (offset
< -webview
->client()->historyBackListCount())
616 webview
->client()->navigateBackForwardSoon(offset
);
620 void FrameLoaderClientImpl::didAccessInitialDocument()
622 if (m_webFrame
->client())
623 m_webFrame
->client()->didAccessInitialDocument(m_webFrame
);
626 void FrameLoaderClientImpl::didDisplayInsecureContent()
628 if (m_webFrame
->client())
629 m_webFrame
->client()->didDisplayInsecureContent(m_webFrame
);
632 void FrameLoaderClientImpl::didRunInsecureContent(SecurityOrigin
* origin
, const KURL
& insecureURL
)
634 if (m_webFrame
->client())
635 m_webFrame
->client()->didRunInsecureContent(m_webFrame
, WebSecurityOrigin(origin
), insecureURL
);
638 void FrameLoaderClientImpl::didDetectXSS(const KURL
& insecureURL
, bool didBlockEntirePage
)
640 if (m_webFrame
->client())
641 m_webFrame
->client()->didDetectXSS(m_webFrame
, insecureURL
, didBlockEntirePage
);
644 void FrameLoaderClientImpl::didDispatchPingLoader(const KURL
& url
)
646 if (m_webFrame
->client())
647 m_webFrame
->client()->didDispatchPingLoader(m_webFrame
, url
);
650 void FrameLoaderClientImpl::didChangePerformanceTiming()
652 if (m_webFrame
->client())
653 m_webFrame
->client()->didChangePerformanceTiming();
656 void FrameLoaderClientImpl::selectorMatchChanged(const Vector
<String
>& addedSelectors
, const Vector
<String
>& removedSelectors
)
658 if (WebFrameClient
* client
= m_webFrame
->client())
659 client
->didMatchCSS(m_webFrame
, WebVector
<WebString
>(addedSelectors
), WebVector
<WebString
>(removedSelectors
));
662 PassRefPtrWillBeRawPtr
<DocumentLoader
> FrameLoaderClientImpl::createDocumentLoader(LocalFrame
* frame
, const ResourceRequest
& request
, const SubstituteData
& data
)
664 RefPtrWillBeRawPtr
<WebDataSourceImpl
> ds
= WebDataSourceImpl::create(frame
, request
, data
);
665 if (m_webFrame
->client())
666 m_webFrame
->client()->didCreateDataSource(m_webFrame
, ds
.get());
670 String
FrameLoaderClientImpl::userAgent(const KURL
& url
)
672 WebString override
= m_webFrame
->client()->userAgentOverride(m_webFrame
, WebURL(url
));
673 if (!override
.isEmpty())
676 return Platform::current()->userAgent();
679 String
FrameLoaderClientImpl::doNotTrackValue()
681 WebString doNotTrack
= m_webFrame
->client()->doNotTrackValue(m_webFrame
);
682 if (!doNotTrack
.isEmpty())
687 // Called when the FrameLoader goes into a state in which a new page load
689 void FrameLoaderClientImpl::transitionToCommittedForNewPage()
691 m_webFrame
->createFrameView();
694 PassRefPtrWillBeRawPtr
<LocalFrame
> FrameLoaderClientImpl::createFrame(
695 const FrameLoadRequest
& request
,
696 const AtomicString
& name
,
697 HTMLFrameOwnerElement
* ownerElement
)
699 return m_webFrame
->createChildFrame(request
, name
, ownerElement
);
702 bool FrameLoaderClientImpl::canCreatePluginWithoutRenderer(const String
& mimeType
) const
704 if (!m_webFrame
->client())
707 return m_webFrame
->client()->canCreatePluginWithoutRenderer(mimeType
);
710 PassRefPtrWillBeRawPtr
<Widget
> FrameLoaderClientImpl::createPlugin(
711 HTMLPlugInElement
* element
,
713 const Vector
<String
>& paramNames
,
714 const Vector
<String
>& paramValues
,
715 const String
& mimeType
,
717 DetachedPluginPolicy policy
)
719 if (!m_webFrame
->client())
722 WebPluginParams params
;
724 params
.mimeType
= mimeType
;
725 params
.attributeNames
= paramNames
;
726 params
.attributeValues
= paramValues
;
727 params
.loadManually
= loadManually
;
729 WebPlugin
* webPlugin
= m_webFrame
->client()->createPlugin(m_webFrame
, params
);
733 // The container takes ownership of the WebPlugin.
734 RefPtrWillBeRawPtr
<WebPluginContainerImpl
> container
=
735 WebPluginContainerImpl::create(element
, webPlugin
);
737 if (!webPlugin
->initialize(container
.get())) {
739 container
->dispose();
744 if (policy
!= AllowDetachedPlugin
&& !element
->layoutObject()) {
746 container
->dispose();
754 PassOwnPtr
<WebMediaPlayer
> FrameLoaderClientImpl::createWebMediaPlayer(
755 HTMLMediaElement
& htmlMediaElement
,
757 WebMediaPlayerClient
* client
)
759 WebLocalFrameImpl
* webFrame
= WebLocalFrameImpl::fromFrame(
760 htmlMediaElement
.document().frame());
762 if (!webFrame
|| !webFrame
->client())
765 HTMLMediaElementEncryptedMedia
& encryptedMedia
= HTMLMediaElementEncryptedMedia::from(htmlMediaElement
);
766 return adoptPtr(webFrame
->client()->createMediaPlayer(webFrame
, url
,
767 client
, &encryptedMedia
,
768 encryptedMedia
.contentDecryptionModule()));
771 ObjectContentType
FrameLoaderClientImpl::objectContentType(
773 const String
& explicitMimeType
,
774 bool shouldPreferPlugInsForImages
)
776 // This code is based on Apple's implementation from
777 // WebCoreSupport/WebFrameBridge.mm.
779 String mimeType
= explicitMimeType
;
780 if (mimeType
.isEmpty()) {
781 // Try to guess the MIME type based off the extension.
782 String filename
= url
.lastPathComponent();
783 int extensionPos
= filename
.reverseFind('.');
784 if (extensionPos
>= 0) {
785 String extension
= filename
.substring(extensionPos
+ 1);
786 mimeType
= MIMETypeRegistry::getMIMETypeForExtension(extension
);
787 if (mimeType
.isEmpty()) {
788 // If there's no mimetype registered for the extension, check to see
789 // if a plugin can handle the extension.
790 mimeType
= getPluginMimeTypeFromExtension(extension
);
794 if (mimeType
.isEmpty())
795 return ObjectContentFrame
;
798 // If Chrome is started with the --disable-plugins switch, pluginData is 0.
799 PluginData
* pluginData
= m_webFrame
->frame()->page()->pluginData();
800 bool plugInSupportsMIMEType
= pluginData
&& pluginData
->supportsMimeType(mimeType
);
802 if (MIMETypeRegistry::isSupportedImageMIMEType(mimeType
))
803 return shouldPreferPlugInsForImages
&& plugInSupportsMIMEType
? ObjectContentNetscapePlugin
: ObjectContentImage
;
805 if (plugInSupportsMIMEType
)
806 return ObjectContentNetscapePlugin
;
808 if (MIMETypeRegistry::isSupportedNonImageMIMEType(mimeType
))
809 return ObjectContentFrame
;
811 return ObjectContentNone
;
814 PassOwnPtr
<WebPluginLoadObserver
> FrameLoaderClientImpl::pluginLoadObserver(DocumentLoader
* loader
)
816 return WebDataSourceImpl::fromDocumentLoader(loader
)->releasePluginLoadObserver();
819 WebCookieJar
* FrameLoaderClientImpl::cookieJar() const
821 if (!m_webFrame
->client())
823 return m_webFrame
->client()->cookieJar(m_webFrame
);
826 bool FrameLoaderClientImpl::willCheckAndDispatchMessageEvent(
827 SecurityOrigin
* target
, MessageEvent
* event
, LocalFrame
* sourceFrame
) const
829 if (!m_webFrame
->client())
831 return m_webFrame
->client()->willCheckAndDispatchMessageEvent(
832 WebLocalFrameImpl::fromFrame(sourceFrame
), m_webFrame
, WebSecurityOrigin(target
), WebDOMMessageEvent(event
));
835 void FrameLoaderClientImpl::didChangeName(const String
& name
)
837 if (!m_webFrame
->client())
839 m_webFrame
->client()->didChangeName(m_webFrame
, name
);
842 void FrameLoaderClientImpl::didChangeSandboxFlags(Frame
* childFrame
, SandboxFlags flags
)
844 if (!m_webFrame
->client())
846 m_webFrame
->client()->didChangeSandboxFlags(WebFrame::fromFrame(childFrame
), static_cast<WebSandboxFlags
>(flags
));
849 void FrameLoaderClientImpl::dispatchWillOpenWebSocket(WebSocketHandle
* handle
)
851 m_webFrame
->client()->willOpenWebSocket(handle
);
854 void FrameLoaderClientImpl::dispatchWillStartUsingPeerConnectionHandler(WebRTCPeerConnectionHandler
* handler
)
856 m_webFrame
->client()->willStartUsingPeerConnectionHandler(webFrame(), handler
);
859 void FrameLoaderClientImpl::didRequestAutocomplete(HTMLFormElement
* form
)
861 if (m_webFrame
->autofillClient())
862 m_webFrame
->autofillClient()->didRequestAutocomplete(WebFormElement(form
));
865 bool FrameLoaderClientImpl::allowWebGL(bool enabledPerSettings
)
867 if (m_webFrame
->client())
868 return m_webFrame
->client()->allowWebGL(m_webFrame
, enabledPerSettings
);
870 return enabledPerSettings
;
873 void FrameLoaderClientImpl::didLoseWebGLContext(int arbRobustnessContextLostReason
)
875 if (m_webFrame
->client())
876 m_webFrame
->client()->didLoseWebGLContext(m_webFrame
, arbRobustnessContextLostReason
);
879 void FrameLoaderClientImpl::dispatchWillInsertBody()
881 if (m_webFrame
->client())
882 m_webFrame
->client()->willInsertBody(m_webFrame
);
884 if (m_webFrame
->viewImpl())
885 m_webFrame
->viewImpl()->willInsertBody(m_webFrame
);
888 v8::Local
<v8::Value
> FrameLoaderClientImpl::createTestInterface(const AtomicString
& name
)
890 return m_webFrame
->createTestInterface(name
);
893 PassOwnPtr
<WebServiceWorkerProvider
> FrameLoaderClientImpl::createServiceWorkerProvider()
895 if (!m_webFrame
->client())
897 return adoptPtr(m_webFrame
->client()->createServiceWorkerProvider(m_webFrame
));
900 bool FrameLoaderClientImpl::isControlledByServiceWorker(DocumentLoader
& loader
)
902 return m_webFrame
->client() && m_webFrame
->client()->isControlledByServiceWorker(*WebDataSourceImpl::fromDocumentLoader(&loader
));
905 int64_t FrameLoaderClientImpl::serviceWorkerID(DocumentLoader
& loader
)
907 if (!m_webFrame
->client())
909 return m_webFrame
->client()->serviceWorkerID(*WebDataSourceImpl::fromDocumentLoader(&loader
));
912 SharedWorkerRepositoryClient
* FrameLoaderClientImpl::sharedWorkerRepositoryClient()
914 return m_webFrame
->sharedWorkerRepositoryClient();
917 PassOwnPtr
<WebApplicationCacheHost
> FrameLoaderClientImpl::createApplicationCacheHost(WebApplicationCacheHostClient
* client
)
919 if (!m_webFrame
->client())
921 return adoptPtr(m_webFrame
->client()->createApplicationCacheHost(m_webFrame
, client
));
924 void FrameLoaderClientImpl::didStopAllLoaders()
926 if (m_webFrame
->client())
927 m_webFrame
->client()->didAbortLoading(m_webFrame
);
930 void FrameLoaderClientImpl::dispatchDidChangeManifest()
932 if (m_webFrame
->client())
933 m_webFrame
->client()->didChangeManifest(m_webFrame
);
936 unsigned FrameLoaderClientImpl::backForwardLength()
938 WebViewImpl
* webview
= m_webFrame
->viewImpl();
939 if (!webview
|| !webview
->client())
941 return webview
->client()->historyBackListCount() + 1 + webview
->client()->historyForwardListCount();
944 void FrameLoaderClientImpl::suddenTerminationDisablerChanged(bool present
, SuddenTerminationDisablerType type
)
946 if (m_webFrame
->client()) {
947 m_webFrame
->client()->suddenTerminationDisablerChanged(
948 present
, static_cast<WebFrameClient::SuddenTerminationDisablerType
>(type
));