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