Home | History | Annotate | Download | only in web
      1 /*
      2  * Copyright (C) 2009, 2012 Google Inc. All rights reserved.
      3  * Copyright (C) 2011 Apple Inc. All rights reserved.
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions are
      7  * met:
      8  *
      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
     14  * distribution.
     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.
     18  *
     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.
     30  */
     31 
     32 #include "config.h"
     33 #include "web/FrameLoaderClientImpl.h"
     34 
     35 #include "bindings/v8/ScriptController.h"
     36 #include "core/HTMLNames.h"
     37 #include "core/dom/Document.h"
     38 #include "core/dom/DocumentFullscreen.h"
     39 #include "core/events/MessageEvent.h"
     40 #include "core/events/MouseEvent.h"
     41 #include "core/frame/FrameView.h"
     42 #include "core/frame/Settings.h"
     43 #include "core/html/HTMLAppletElement.h"
     44 #include "core/loader/DocumentLoader.h"
     45 #include "core/loader/FrameLoadRequest.h"
     46 #include "core/loader/FrameLoader.h"
     47 #include "core/loader/HistoryItem.h"
     48 #include "core/page/Chrome.h"
     49 #include "core/page/EventHandler.h"
     50 #include "core/page/Page.h"
     51 #include "core/page/WindowFeatures.h"
     52 #include "core/rendering/HitTestResult.h"
     53 #include "modules/device_light/DeviceLightController.h"
     54 #include "modules/device_orientation/DeviceMotionController.h"
     55 #include "modules/device_orientation/DeviceOrientationController.h"
     56 #include "modules/gamepad/NavigatorGamepad.h"
     57 #include "modules/serviceworkers/NavigatorServiceWorker.h"
     58 #include "platform/MIMETypeRegistry.h"
     59 #include "platform/RuntimeEnabledFeatures.h"
     60 #include "platform/UserGestureIndicator.h"
     61 #include "platform/exported/WrappedResourceRequest.h"
     62 #include "platform/exported/WrappedResourceResponse.h"
     63 #include "platform/network/HTTPParsers.h"
     64 #include "platform/network/SocketStreamHandleInternal.h"
     65 #include "platform/plugins/PluginData.h"
     66 #include "public/platform/Platform.h"
     67 #include "public/platform/WebApplicationCacheHost.h"
     68 #include "public/platform/WebMimeRegistry.h"
     69 #include "public/platform/WebRTCPeerConnectionHandler.h"
     70 #include "public/platform/WebServiceWorkerProvider.h"
     71 #include "public/platform/WebServiceWorkerProviderClient.h"
     72 #include "public/platform/WebSocketStreamHandle.h"
     73 #include "public/platform/WebURL.h"
     74 #include "public/platform/WebURLError.h"
     75 #include "public/platform/WebVector.h"
     76 #include "public/web/WebAutofillClient.h"
     77 #include "public/web/WebCachedURLRequest.h"
     78 #include "public/web/WebDOMEvent.h"
     79 #include "public/web/WebDocument.h"
     80 #include "public/web/WebFormElement.h"
     81 #include "public/web/WebFrameClient.h"
     82 #include "public/web/WebNode.h"
     83 #include "public/web/WebPermissionClient.h"
     84 #include "public/web/WebPlugin.h"
     85 #include "public/web/WebPluginParams.h"
     86 #include "public/web/WebSecurityOrigin.h"
     87 #include "public/web/WebViewClient.h"
     88 #include "web/SharedWorkerRepositoryClientImpl.h"
     89 #include "web/WebDataSourceImpl.h"
     90 #include "web/WebDevToolsAgentPrivate.h"
     91 #include "web/WebLocalFrameImpl.h"
     92 #include "web/WebPluginContainerImpl.h"
     93 #include "web/WebPluginLoadObserver.h"
     94 #include "web/WebViewImpl.h"
     95 #include "wtf/StringExtras.h"
     96 #include "wtf/text/CString.h"
     97 #include "wtf/text/WTFString.h"
     98 #include <v8.h>
     99 
    100 using namespace WebCore;
    101 
    102 namespace blink {
    103 
    104 FrameLoaderClientImpl::FrameLoaderClientImpl(WebLocalFrameImpl* frame)
    105     : m_webFrame(frame)
    106 {
    107 }
    108 
    109 FrameLoaderClientImpl::~FrameLoaderClientImpl()
    110 {
    111 }
    112 
    113 void FrameLoaderClientImpl::dispatchDidClearWindowObjectInMainWorld()
    114 {
    115     if (m_webFrame->client()) {
    116         m_webFrame->client()->didClearWindowObject(m_webFrame);
    117         Document* document = m_webFrame->frame()->document();
    118         if (document) {
    119             DeviceMotionController::from(*document);
    120             DeviceOrientationController::from(*document);
    121             if (RuntimeEnabledFeatures::deviceLightEnabled())
    122                 DeviceLightController::from(*document);
    123             if (RuntimeEnabledFeatures::gamepadEnabled())
    124                 NavigatorGamepad::from(*document);
    125             if (RuntimeEnabledFeatures::serviceWorkerEnabled())
    126                 NavigatorServiceWorker::from(*document);
    127         }
    128     }
    129 }
    130 
    131 void FrameLoaderClientImpl::documentElementAvailable()
    132 {
    133     if (m_webFrame->client())
    134         m_webFrame->client()->didCreateDocumentElement(m_webFrame);
    135 }
    136 
    137 void FrameLoaderClientImpl::didCreateScriptContext(v8::Handle<v8::Context> context, int extensionGroup, int worldId)
    138 {
    139     WebViewImpl* webview = m_webFrame->viewImpl();
    140     if (webview->devToolsAgentPrivate())
    141         webview->devToolsAgentPrivate()->didCreateScriptContext(m_webFrame, worldId);
    142     if (m_webFrame->client())
    143         m_webFrame->client()->didCreateScriptContext(m_webFrame, context, extensionGroup, worldId);
    144 }
    145 
    146 void FrameLoaderClientImpl::willReleaseScriptContext(v8::Handle<v8::Context> context, int worldId)
    147 {
    148     if (m_webFrame->client())
    149         m_webFrame->client()->willReleaseScriptContext(m_webFrame, context, worldId);
    150 }
    151 
    152 bool FrameLoaderClientImpl::allowScriptExtension(const String& extensionName,
    153                                                  int extensionGroup,
    154                                                  int worldId)
    155 {
    156     if (m_webFrame->permissionClient())
    157         return m_webFrame->permissionClient()->allowScriptExtension(extensionName, extensionGroup, worldId);
    158 
    159     return true;
    160 }
    161 
    162 void FrameLoaderClientImpl::didChangeScrollOffset()
    163 {
    164     if (m_webFrame->client())
    165         m_webFrame->client()->didChangeScrollOffset(m_webFrame);
    166 }
    167 
    168 void FrameLoaderClientImpl::didUpdateCurrentHistoryItem()
    169 {
    170     if (m_webFrame->client())
    171         m_webFrame->client()->didUpdateCurrentHistoryItem(m_webFrame);
    172 }
    173 
    174 bool FrameLoaderClientImpl::allowScript(bool enabledPerSettings)
    175 {
    176     if (m_webFrame->permissionClient())
    177         return m_webFrame->permissionClient()->allowScript(enabledPerSettings);
    178 
    179     return enabledPerSettings;
    180 }
    181 
    182 bool FrameLoaderClientImpl::allowScriptFromSource(bool enabledPerSettings, const KURL& scriptURL)
    183 {
    184     if (m_webFrame->permissionClient())
    185         return m_webFrame->permissionClient()->allowScriptFromSource(enabledPerSettings, scriptURL);
    186 
    187     return enabledPerSettings;
    188 }
    189 
    190 bool FrameLoaderClientImpl::allowPlugins(bool enabledPerSettings)
    191 {
    192     if (m_webFrame->permissionClient())
    193         return m_webFrame->permissionClient()->allowPlugins(enabledPerSettings);
    194 
    195     return enabledPerSettings;
    196 }
    197 
    198 bool FrameLoaderClientImpl::allowImage(bool enabledPerSettings, const KURL& imageURL)
    199 {
    200     if (m_webFrame->permissionClient())
    201         return m_webFrame->permissionClient()->allowImage(enabledPerSettings, imageURL);
    202 
    203     return enabledPerSettings;
    204 }
    205 
    206 bool FrameLoaderClientImpl::allowDisplayingInsecureContent(bool enabledPerSettings, SecurityOrigin* context, const KURL& url)
    207 {
    208     if (m_webFrame->permissionClient())
    209         return m_webFrame->permissionClient()->allowDisplayingInsecureContent(enabledPerSettings, WebSecurityOrigin(context), WebURL(url));
    210 
    211     return enabledPerSettings;
    212 }
    213 
    214 bool FrameLoaderClientImpl::allowRunningInsecureContent(bool enabledPerSettings, SecurityOrigin* context, const KURL& url)
    215 {
    216     if (m_webFrame->permissionClient())
    217         return m_webFrame->permissionClient()->allowRunningInsecureContent(enabledPerSettings, WebSecurityOrigin(context), WebURL(url));
    218 
    219     return enabledPerSettings;
    220 }
    221 
    222 void FrameLoaderClientImpl::didNotAllowScript()
    223 {
    224     if (m_webFrame->permissionClient())
    225         m_webFrame->permissionClient()->didNotAllowScript();
    226 }
    227 
    228 void FrameLoaderClientImpl::didNotAllowPlugins()
    229 {
    230     if (m_webFrame->permissionClient())
    231         m_webFrame->permissionClient()->didNotAllowPlugins();
    232 
    233 }
    234 
    235 bool FrameLoaderClientImpl::hasWebView() const
    236 {
    237     return m_webFrame->viewImpl();
    238 }
    239 
    240 Frame* FrameLoaderClientImpl::opener() const
    241 {
    242     return toWebCoreFrame(m_webFrame->opener());
    243 }
    244 
    245 void FrameLoaderClientImpl::setOpener(Frame* opener)
    246 {
    247     // FIXME: Temporary hack to stage converting locations that really should be Frame.
    248     m_webFrame->setOpener(WebLocalFrameImpl::fromFrame(toLocalFrame(opener)));
    249 }
    250 
    251 Frame* FrameLoaderClientImpl::parent() const
    252 {
    253     return toWebCoreFrame(m_webFrame->parent());
    254 }
    255 
    256 Frame* FrameLoaderClientImpl::top() const
    257 {
    258     return toWebCoreFrame(m_webFrame->top());
    259 }
    260 
    261 Frame* FrameLoaderClientImpl::previousSibling() const
    262 {
    263     return toWebCoreFrame(m_webFrame->previousSibling());
    264 }
    265 
    266 Frame* FrameLoaderClientImpl::nextSibling() const
    267 {
    268     return toWebCoreFrame(m_webFrame->nextSibling());
    269 }
    270 
    271 Frame* FrameLoaderClientImpl::firstChild() const
    272 {
    273     return toWebCoreFrame(m_webFrame->firstChild());
    274 }
    275 
    276 Frame* FrameLoaderClientImpl::lastChild() const
    277 {
    278     return toWebCoreFrame(m_webFrame->lastChild());
    279 }
    280 
    281 void FrameLoaderClientImpl::detachedFromParent()
    282 {
    283     // Alert the client that the frame is being detached. This is the last
    284     // chance we have to communicate with the client.
    285     RefPtr<WebLocalFrameImpl> protector(m_webFrame);
    286 
    287     WebFrameClient* client = m_webFrame->client();
    288     if (!client)
    289         return;
    290 
    291     m_webFrame->willDetachParent();
    292 
    293     // Signal that no further communication with WebFrameClient should take
    294     // place at this point since we are no longer associated with the Page.
    295     m_webFrame->setClient(0);
    296 
    297     client->frameDetached(m_webFrame);
    298     // Clear our reference to WebCore::LocalFrame at the very end, in case the client
    299     // refers to it.
    300     m_webFrame->setWebCoreFrame(nullptr);
    301 }
    302 
    303 void FrameLoaderClientImpl::dispatchWillRequestAfterPreconnect(ResourceRequest& request)
    304 {
    305     if (m_webFrame->client()) {
    306         WrappedResourceRequest webreq(request);
    307         m_webFrame->client()->willRequestAfterPreconnect(m_webFrame, webreq);
    308     }
    309 }
    310 
    311 void FrameLoaderClientImpl::dispatchWillSendRequest(
    312     DocumentLoader* loader, unsigned long identifier, ResourceRequest& request,
    313     const ResourceResponse& redirectResponse)
    314 {
    315     // Give the WebFrameClient a crack at the request.
    316     if (m_webFrame->client()) {
    317         WrappedResourceRequest webreq(request);
    318         WrappedResourceResponse webresp(redirectResponse);
    319         m_webFrame->client()->willSendRequest(
    320             m_webFrame, identifier, webreq, webresp);
    321     }
    322 }
    323 
    324 void FrameLoaderClientImpl::dispatchDidReceiveResponse(DocumentLoader* loader,
    325                                                        unsigned long identifier,
    326                                                        const ResourceResponse& response)
    327 {
    328     if (m_webFrame->client()) {
    329         WrappedResourceResponse webresp(response);
    330         m_webFrame->client()->didReceiveResponse(m_webFrame, identifier, webresp);
    331     }
    332 }
    333 
    334 void FrameLoaderClientImpl::dispatchDidChangeResourcePriority(unsigned long identifier, ResourceLoadPriority priority, int intraPriorityValue)
    335 {
    336     if (m_webFrame->client())
    337         m_webFrame->client()->didChangeResourcePriority(m_webFrame, identifier, static_cast<blink::WebURLRequest::Priority>(priority), intraPriorityValue);
    338 }
    339 
    340 // Called when a particular resource load completes
    341 void FrameLoaderClientImpl::dispatchDidFinishLoading(DocumentLoader* loader,
    342                                                     unsigned long identifier)
    343 {
    344     if (m_webFrame->client())
    345         m_webFrame->client()->didFinishResourceLoad(m_webFrame, identifier);
    346 }
    347 
    348 void FrameLoaderClientImpl::dispatchDidFinishDocumentLoad()
    349 {
    350     if (m_webFrame->client())
    351         m_webFrame->client()->didFinishDocumentLoad(m_webFrame);
    352 }
    353 
    354 void FrameLoaderClientImpl::dispatchDidLoadResourceFromMemoryCache(const ResourceRequest& request, const ResourceResponse& response)
    355 {
    356     if (m_webFrame->client())
    357         m_webFrame->client()->didLoadResourceFromMemoryCache(m_webFrame, WrappedResourceRequest(request), WrappedResourceResponse(response));
    358 }
    359 
    360 void FrameLoaderClientImpl::dispatchDidHandleOnloadEvents()
    361 {
    362     if (m_webFrame->client())
    363         m_webFrame->client()->didHandleOnloadEvents(m_webFrame);
    364 }
    365 
    366 void FrameLoaderClientImpl::dispatchDidReceiveServerRedirectForProvisionalLoad()
    367 {
    368     if (m_webFrame->client())
    369         m_webFrame->client()->didReceiveServerRedirectForProvisionalLoad(m_webFrame);
    370 }
    371 
    372 void FrameLoaderClientImpl::dispatchDidNavigateWithinPage(HistoryItem* item, HistoryCommitType commitType)
    373 {
    374     bool shouldCreateHistoryEntry = commitType == StandardCommit;
    375     m_webFrame->viewImpl()->didCommitLoad(shouldCreateHistoryEntry, true);
    376     if (m_webFrame->client())
    377         m_webFrame->client()->didNavigateWithinPage(m_webFrame, WebHistoryItem(item), static_cast<WebHistoryCommitType>(commitType));
    378 }
    379 
    380 void FrameLoaderClientImpl::dispatchWillClose()
    381 {
    382     if (m_webFrame->client())
    383         m_webFrame->client()->willClose(m_webFrame);
    384 }
    385 
    386 void FrameLoaderClientImpl::dispatchDidStartProvisionalLoad()
    387 {
    388     if (m_webFrame->client())
    389         m_webFrame->client()->didStartProvisionalLoad(m_webFrame);
    390 }
    391 
    392 void FrameLoaderClientImpl::dispatchDidReceiveTitle(const String& title)
    393 {
    394     if (m_webFrame->client())
    395         m_webFrame->client()->didReceiveTitle(m_webFrame, title, WebTextDirectionLeftToRight);
    396 }
    397 
    398 void FrameLoaderClientImpl::dispatchDidChangeIcons(WebCore::IconType type)
    399 {
    400     if (m_webFrame->client())
    401         m_webFrame->client()->didChangeIcon(m_webFrame, static_cast<WebIconURL::Type>(type));
    402 }
    403 
    404 void FrameLoaderClientImpl::dispatchDidCommitLoad(LocalFrame* frame, HistoryItem* item, HistoryCommitType commitType)
    405 {
    406     m_webFrame->viewImpl()->didCommitLoad(commitType == StandardCommit, false);
    407     if (m_webFrame->client())
    408         m_webFrame->client()->didCommitProvisionalLoad(m_webFrame, WebHistoryItem(item), static_cast<WebHistoryCommitType>(commitType));
    409 }
    410 
    411 void FrameLoaderClientImpl::dispatchDidFailProvisionalLoad(
    412     const ResourceError& error)
    413 {
    414     OwnPtr<WebPluginLoadObserver> observer = pluginLoadObserver(m_webFrame->frame()->loader().provisionalDocumentLoader());
    415     m_webFrame->didFail(error, true);
    416     if (observer)
    417         observer->didFailLoading(error);
    418 }
    419 
    420 void FrameLoaderClientImpl::dispatchDidFailLoad(const ResourceError& error)
    421 {
    422     OwnPtr<WebPluginLoadObserver> observer = pluginLoadObserver(m_webFrame->frame()->loader().documentLoader());
    423     m_webFrame->didFail(error, false);
    424     if (observer)
    425         observer->didFailLoading(error);
    426 
    427     // Don't clear the redirect chain, this will happen in the middle of client
    428     // redirects, and we need the context. The chain will be cleared when the
    429     // provisional load succeeds or fails, not the "real" one.
    430 }
    431 
    432 void FrameLoaderClientImpl::dispatchDidFinishLoad()
    433 {
    434     OwnPtr<WebPluginLoadObserver> observer = pluginLoadObserver(m_webFrame->frame()->loader().documentLoader());
    435 
    436     if (m_webFrame->client())
    437         m_webFrame->client()->didFinishLoad(m_webFrame);
    438 
    439     if (observer)
    440         observer->didFinishLoading();
    441 
    442     // Don't clear the redirect chain, this will happen in the middle of client
    443     // redirects, and we need the context. The chain will be cleared when the
    444     // provisional load succeeds or fails, not the "real" one.
    445 }
    446 
    447 void FrameLoaderClientImpl::dispatchDidFirstVisuallyNonEmptyLayout()
    448 {
    449     if (m_webFrame->client())
    450         m_webFrame->client()->didFirstVisuallyNonEmptyLayout(m_webFrame);
    451 }
    452 
    453 void FrameLoaderClientImpl::dispatchDidChangeThemeColor()
    454 {
    455     if (m_webFrame->client())
    456         m_webFrame->client()->didChangeThemeColor();
    457 }
    458 
    459 NavigationPolicy FrameLoaderClientImpl::decidePolicyForNavigation(const ResourceRequest& request, DocumentLoader* loader, NavigationPolicy policy)
    460 {
    461     if (!m_webFrame->client())
    462         return NavigationPolicyIgnore;
    463     WebDataSourceImpl* ds = WebDataSourceImpl::fromDocumentLoader(loader);
    464     WebNavigationPolicy webPolicy = m_webFrame->client()->decidePolicyForNavigation(m_webFrame, ds->extraData(), WrappedResourceRequest(request),
    465         ds->navigationType(), static_cast<WebNavigationPolicy>(policy), ds->isRedirect());
    466     return static_cast<NavigationPolicy>(webPolicy);
    467 }
    468 
    469 void FrameLoaderClientImpl::dispatchWillRequestResource(FetchRequest* request)
    470 {
    471     if (m_webFrame->client()) {
    472         WebCachedURLRequest urlRequest(request);
    473         m_webFrame->client()->willRequestResource(m_webFrame, urlRequest);
    474     }
    475 }
    476 
    477 void FrameLoaderClientImpl::dispatchWillSendSubmitEvent(HTMLFormElement* form)
    478 {
    479     if (m_webFrame->client())
    480         m_webFrame->client()->willSendSubmitEvent(m_webFrame, WebFormElement(form));
    481 }
    482 
    483 void FrameLoaderClientImpl::dispatchWillSubmitForm(HTMLFormElement* form)
    484 {
    485     if (m_webFrame->client())
    486         m_webFrame->client()->willSubmitForm(m_webFrame, WebFormElement(form));
    487 }
    488 
    489 void FrameLoaderClientImpl::didStartLoading(LoadStartType loadStartType)
    490 {
    491     if (m_webFrame->client())
    492         m_webFrame->client()->didStartLoading(loadStartType == NavigationToDifferentDocument);
    493 }
    494 
    495 void FrameLoaderClientImpl::progressEstimateChanged(double progressEstimate)
    496 {
    497     if (m_webFrame->client())
    498         m_webFrame->client()->didChangeLoadProgress(progressEstimate);
    499 }
    500 
    501 void FrameLoaderClientImpl::didStopLoading()
    502 {
    503     if (m_webFrame->client())
    504         m_webFrame->client()->didStopLoading();
    505 }
    506 
    507 void FrameLoaderClientImpl::loadURLExternally(const ResourceRequest& request, NavigationPolicy policy, const String& suggestedName)
    508 {
    509     if (m_webFrame->client()) {
    510         ASSERT(m_webFrame->frame()->document());
    511         DocumentFullscreen::webkitCancelFullScreen(*m_webFrame->frame()->document());
    512         WrappedResourceRequest webreq(request);
    513         m_webFrame->client()->loadURLExternally(
    514             m_webFrame, webreq, static_cast<WebNavigationPolicy>(policy), suggestedName);
    515     }
    516 }
    517 
    518 bool FrameLoaderClientImpl::navigateBackForward(int offset) const
    519 {
    520     WebViewImpl* webview = m_webFrame->viewImpl();
    521     if (!webview->client())
    522         return false;
    523 
    524     ASSERT(offset);
    525     offset = std::min(offset, webview->client()->historyForwardListCount());
    526     offset = std::max(offset, -webview->client()->historyBackListCount());
    527     if (!offset)
    528         return false;
    529     webview->client()->navigateBackForwardSoon(offset);
    530     return true;
    531 }
    532 
    533 void FrameLoaderClientImpl::didAccessInitialDocument()
    534 {
    535     if (m_webFrame->client())
    536         m_webFrame->client()->didAccessInitialDocument(m_webFrame);
    537 }
    538 
    539 void FrameLoaderClientImpl::didDisplayInsecureContent()
    540 {
    541     if (m_webFrame->client())
    542         m_webFrame->client()->didDisplayInsecureContent(m_webFrame);
    543 }
    544 
    545 void FrameLoaderClientImpl::didRunInsecureContent(SecurityOrigin* origin, const KURL& insecureURL)
    546 {
    547     if (m_webFrame->client())
    548         m_webFrame->client()->didRunInsecureContent(m_webFrame, WebSecurityOrigin(origin), insecureURL);
    549 }
    550 
    551 void FrameLoaderClientImpl::didDetectXSS(const KURL& insecureURL, bool didBlockEntirePage)
    552 {
    553     if (m_webFrame->client())
    554         m_webFrame->client()->didDetectXSS(m_webFrame, insecureURL, didBlockEntirePage);
    555 }
    556 
    557 void FrameLoaderClientImpl::didDispatchPingLoader(const KURL& url)
    558 {
    559     if (m_webFrame->client())
    560         m_webFrame->client()->didDispatchPingLoader(m_webFrame, url);
    561 }
    562 
    563 void FrameLoaderClientImpl::selectorMatchChanged(const Vector<String>& addedSelectors, const Vector<String>& removedSelectors)
    564 {
    565     if (WebFrameClient* client = m_webFrame->client())
    566         client->didMatchCSS(m_webFrame, WebVector<WebString>(addedSelectors), WebVector<WebString>(removedSelectors));
    567 }
    568 
    569 PassRefPtr<DocumentLoader> FrameLoaderClientImpl::createDocumentLoader(LocalFrame* frame, const ResourceRequest& request, const SubstituteData& data)
    570 {
    571     RefPtr<WebDataSourceImpl> ds = WebDataSourceImpl::create(frame, request, data);
    572     if (m_webFrame->client())
    573         m_webFrame->client()->didCreateDataSource(m_webFrame, ds.get());
    574     return ds.release();
    575 }
    576 
    577 String FrameLoaderClientImpl::userAgent(const KURL& url)
    578 {
    579     WebString override = m_webFrame->client()->userAgentOverride(m_webFrame, WebURL(url));
    580     if (!override.isEmpty())
    581         return override;
    582 
    583     return blink::Platform::current()->userAgent();
    584 }
    585 
    586 String FrameLoaderClientImpl::doNotTrackValue()
    587 {
    588     WebString doNotTrack = m_webFrame->client()->doNotTrackValue(m_webFrame);
    589     if (!doNotTrack.isEmpty())
    590         return doNotTrack;
    591     return String();
    592 }
    593 
    594 // Called when the FrameLoader goes into a state in which a new page load
    595 // will occur.
    596 void FrameLoaderClientImpl::transitionToCommittedForNewPage()
    597 {
    598     m_webFrame->createFrameView();
    599 }
    600 
    601 PassRefPtr<LocalFrame> FrameLoaderClientImpl::createFrame(
    602     const KURL& url,
    603     const AtomicString& name,
    604     const Referrer& referrer,
    605     HTMLFrameOwnerElement* ownerElement)
    606 {
    607     FrameLoadRequest frameRequest(m_webFrame->frame()->document(),
    608         ResourceRequest(url, referrer), name);
    609     return m_webFrame->createChildFrame(frameRequest, ownerElement);
    610 }
    611 
    612 bool FrameLoaderClientImpl::canCreatePluginWithoutRenderer(const String& mimeType) const
    613 {
    614     if (!m_webFrame->client())
    615         return false;
    616 
    617     return m_webFrame->client()->canCreatePluginWithoutRenderer(mimeType);
    618 }
    619 
    620 PassRefPtr<Widget> FrameLoaderClientImpl::createPlugin(
    621     HTMLPlugInElement* element,
    622     const KURL& url,
    623     const Vector<String>& paramNames,
    624     const Vector<String>& paramValues,
    625     const String& mimeType,
    626     bool loadManually,
    627     DetachedPluginPolicy policy)
    628 {
    629     if (!m_webFrame->client())
    630         return nullptr;
    631 
    632     WebPluginParams params;
    633     params.url = url;
    634     params.mimeType = mimeType;
    635     params.attributeNames = paramNames;
    636     params.attributeValues = paramValues;
    637     params.loadManually = loadManually;
    638 
    639     WebPlugin* webPlugin = m_webFrame->client()->createPlugin(m_webFrame, params);
    640     if (!webPlugin)
    641         return nullptr;
    642 
    643     // The container takes ownership of the WebPlugin.
    644     RefPtr<WebPluginContainerImpl> container =
    645         WebPluginContainerImpl::create(element, webPlugin);
    646 
    647     if (!webPlugin->initialize(container.get()))
    648         return nullptr;
    649 
    650     if (policy != AllowDetachedPlugin && !element->renderer())
    651         return nullptr;
    652 
    653     return container;
    654 }
    655 
    656 PassRefPtr<Widget> FrameLoaderClientImpl::createJavaAppletWidget(
    657     HTMLAppletElement* element,
    658     const KURL& /* baseURL */,
    659     const Vector<String>& paramNames,
    660     const Vector<String>& paramValues)
    661 {
    662     return createPlugin(element, KURL(), paramNames, paramValues,
    663         "application/x-java-applet", false, FailOnDetachedPlugin);
    664 }
    665 
    666 ObjectContentType FrameLoaderClientImpl::objectContentType(
    667     const KURL& url,
    668     const String& explicitMimeType,
    669     bool shouldPreferPlugInsForImages)
    670 {
    671     // This code is based on Apple's implementation from
    672     // WebCoreSupport/WebFrameBridge.mm.
    673 
    674     String mimeType = explicitMimeType;
    675     if (mimeType.isEmpty()) {
    676         // Try to guess the MIME type based off the extension.
    677         String filename = url.lastPathComponent();
    678         int extensionPos = filename.reverseFind('.');
    679         if (extensionPos >= 0) {
    680             String extension = filename.substring(extensionPos + 1);
    681             mimeType = MIMETypeRegistry::getMIMETypeForExtension(extension);
    682             if (mimeType.isEmpty()) {
    683                 // If there's no mimetype registered for the extension, check to see
    684                 // if a plugin can handle the extension.
    685                 mimeType = getPluginMimeTypeFromExtension(extension);
    686             }
    687         }
    688 
    689         if (mimeType.isEmpty())
    690             return ObjectContentFrame;
    691     }
    692 
    693     // If Chrome is started with the --disable-plugins switch, pluginData is 0.
    694     PluginData* pluginData = m_webFrame->frame()->page()->pluginData();
    695     bool plugInSupportsMIMEType = pluginData && pluginData->supportsMimeType(mimeType);
    696 
    697     if (MIMETypeRegistry::isSupportedImageMIMEType(mimeType))
    698         return shouldPreferPlugInsForImages && plugInSupportsMIMEType ? ObjectContentNetscapePlugin : ObjectContentImage;
    699 
    700     if (plugInSupportsMIMEType)
    701         return ObjectContentNetscapePlugin;
    702 
    703     if (MIMETypeRegistry::isSupportedNonImageMIMEType(mimeType))
    704         return ObjectContentFrame;
    705 
    706     return ObjectContentNone;
    707 }
    708 
    709 PassOwnPtr<WebPluginLoadObserver> FrameLoaderClientImpl::pluginLoadObserver(DocumentLoader* loader)
    710 {
    711     return WebDataSourceImpl::fromDocumentLoader(loader)->releasePluginLoadObserver();
    712 }
    713 
    714 WebCookieJar* FrameLoaderClientImpl::cookieJar() const
    715 {
    716     if (!m_webFrame->client())
    717         return 0;
    718     return m_webFrame->client()->cookieJar(m_webFrame);
    719 }
    720 
    721 bool FrameLoaderClientImpl::willCheckAndDispatchMessageEvent(
    722     SecurityOrigin* target, MessageEvent* event) const
    723 {
    724     if (!m_webFrame->client())
    725         return false;
    726 
    727     WebLocalFrame* source = 0;
    728     if (event && event->source() && event->source()->toDOMWindow() && event->source()->toDOMWindow()->document())
    729         source = WebLocalFrameImpl::fromFrame(event->source()->toDOMWindow()->document()->frame());
    730     return m_webFrame->client()->willCheckAndDispatchMessageEvent(
    731         source, m_webFrame, WebSecurityOrigin(target), WebDOMMessageEvent(event));
    732 }
    733 
    734 void FrameLoaderClientImpl::didChangeName(const String& name)
    735 {
    736     if (!m_webFrame->client())
    737         return;
    738     m_webFrame->client()->didChangeName(m_webFrame, name);
    739 }
    740 
    741 void FrameLoaderClientImpl::dispatchWillOpenSocketStream(SocketStreamHandle* handle)
    742 {
    743     m_webFrame->client()->willOpenSocketStream(SocketStreamHandleInternal::toWebSocketStreamHandle(handle));
    744 }
    745 
    746 void FrameLoaderClientImpl::dispatchWillOpenWebSocket(blink::WebSocketHandle* handle)
    747 {
    748     m_webFrame->client()->willOpenWebSocket(handle);
    749 }
    750 
    751 void FrameLoaderClientImpl::dispatchWillStartUsingPeerConnectionHandler(blink::WebRTCPeerConnectionHandler* handler)
    752 {
    753     m_webFrame->client()->willStartUsingPeerConnectionHandler(webFrame(), handler);
    754 }
    755 
    756 void FrameLoaderClientImpl::didRequestAutocomplete(HTMLFormElement* form)
    757 {
    758     if (m_webFrame->viewImpl() && m_webFrame->viewImpl()->autofillClient())
    759         m_webFrame->viewImpl()->autofillClient()->didRequestAutocomplete(WebFormElement(form));
    760 }
    761 
    762 bool FrameLoaderClientImpl::allowWebGL(bool enabledPerSettings)
    763 {
    764     if (m_webFrame->client())
    765         return m_webFrame->client()->allowWebGL(m_webFrame, enabledPerSettings);
    766 
    767     return enabledPerSettings;
    768 }
    769 
    770 void FrameLoaderClientImpl::didLoseWebGLContext(int arbRobustnessContextLostReason)
    771 {
    772     if (m_webFrame->client())
    773         m_webFrame->client()->didLoseWebGLContext(m_webFrame, arbRobustnessContextLostReason);
    774 }
    775 
    776 void FrameLoaderClientImpl::dispatchWillInsertBody()
    777 {
    778     if (m_webFrame->client())
    779         m_webFrame->client()->willInsertBody(m_webFrame);
    780 
    781     if (m_webFrame->viewImpl())
    782         m_webFrame->viewImpl()->willInsertBody(m_webFrame);
    783 }
    784 
    785 PassOwnPtr<WebServiceWorkerProvider> FrameLoaderClientImpl::createServiceWorkerProvider()
    786 {
    787     if (!m_webFrame->client())
    788         return nullptr;
    789     return adoptPtr(m_webFrame->client()->createServiceWorkerProvider(m_webFrame));
    790 }
    791 
    792 SharedWorkerRepositoryClient* FrameLoaderClientImpl::sharedWorkerRepositoryClient()
    793 {
    794     return m_webFrame->sharedWorkerRepositoryClient();
    795 }
    796 
    797 PassOwnPtr<WebApplicationCacheHost> FrameLoaderClientImpl::createApplicationCacheHost(WebApplicationCacheHostClient* client)
    798 {
    799     if (!m_webFrame->client())
    800         return nullptr;
    801     return adoptPtr(m_webFrame->client()->createApplicationCacheHost(m_webFrame, client));
    802 }
    803 
    804 void FrameLoaderClientImpl::didStopAllLoaders()
    805 {
    806     if (m_webFrame->client())
    807         m_webFrame->client()->didAbortLoading(m_webFrame);
    808 }
    809 
    810 void FrameLoaderClientImpl::dispatchDidChangeManifest()
    811 {
    812     if (m_webFrame->client())
    813         m_webFrame->client()->didChangeManifest(m_webFrame);
    814 }
    815 
    816 } // namespace blink
    817