| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This file contains the implementation of TestWebViewDelegate, which serves | 5 // This file contains the implementation of TestWebViewDelegate, which serves |
| 6 // as the WebViewDelegate for the TestShellWebHost. The host is expected to | 6 // as the WebViewDelegate for the TestShellWebHost. The host is expected to |
| 7 // have initialized a MessageLoop before these methods are called. | 7 // have initialized a MessageLoop before these methods are called. |
| 8 | 8 |
| 9 #include "config.h" | 9 #include "config.h" |
| 10 | 10 |
| 11 #undef LOG | 11 #undef LOG |
| 12 | 12 |
| 13 #include "webkit/tools/test_shell/test_webview_delegate.h" | 13 #include "webkit/tools/test_shell/test_webview_delegate.h" |
| 14 | 14 |
| 15 #include "base/file_util.h" | 15 #include "base/file_util.h" |
| 16 #include "base/gfx/point.h" | 16 #include "base/gfx/point.h" |
| 17 #include "base/gfx/native_widget_types.h" | 17 #include "base/gfx/native_widget_types.h" |
| 18 #include "base/message_loop.h" | 18 #include "base/message_loop.h" |
| 19 #include "base/process_util.h" | 19 #include "base/process_util.h" |
| 20 #include "base/string_util.h" | 20 #include "base/string_util.h" |
| 21 #include "base/trace_event.h" | 21 #include "base/trace_event.h" |
| 22 #include "net/base/net_errors.h" | 22 #include "net/base/net_errors.h" |
| 23 #include "webkit/api/public/WebCString.h" |
| 23 #include "webkit/api/public/WebData.h" | 24 #include "webkit/api/public/WebData.h" |
| 24 #include "webkit/api/public/WebDataSource.h" | 25 #include "webkit/api/public/WebDataSource.h" |
| 25 #include "webkit/api/public/WebDragData.h" | 26 #include "webkit/api/public/WebDragData.h" |
| 26 #include "webkit/api/public/WebHistoryItem.h" | 27 #include "webkit/api/public/WebHistoryItem.h" |
| 27 #include "webkit/api/public/WebFrame.h" | 28 #include "webkit/api/public/WebFrame.h" |
| 28 #include "webkit/api/public/WebKit.h" | 29 #include "webkit/api/public/WebKit.h" |
| 29 #include "webkit/api/public/WebNode.h" | 30 #include "webkit/api/public/WebNode.h" |
| 30 #include "webkit/api/public/WebPoint.h" | 31 #include "webkit/api/public/WebPoint.h" |
| 31 #include "webkit/api/public/WebRange.h" | 32 #include "webkit/api/public/WebRange.h" |
| 32 #include "webkit/api/public/WebScreenInfo.h" | 33 #include "webkit/api/public/WebScreenInfo.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 57 // TODO(port): make these files work everywhere. | 58 // TODO(port): make these files work everywhere. |
| 58 #include "webkit/tools/test_shell/drag_delegate.h" | 59 #include "webkit/tools/test_shell/drag_delegate.h" |
| 59 #include "webkit/tools/test_shell/drop_delegate.h" | 60 #include "webkit/tools/test_shell/drop_delegate.h" |
| 60 #endif | 61 #endif |
| 61 | 62 |
| 62 using WebKit::WebData; | 63 using WebKit::WebData; |
| 63 using WebKit::WebDataSource; | 64 using WebKit::WebDataSource; |
| 64 using WebKit::WebDragData; | 65 using WebKit::WebDragData; |
| 65 using WebKit::WebDragOperationsMask; | 66 using WebKit::WebDragOperationsMask; |
| 66 using WebKit::WebEditingAction; | 67 using WebKit::WebEditingAction; |
| 68 using WebKit::WebForm; |
| 67 using WebKit::WebFrame; | 69 using WebKit::WebFrame; |
| 68 using WebKit::WebHistoryItem; | 70 using WebKit::WebHistoryItem; |
| 71 using WebKit::WebMediaPlayer; |
| 72 using WebKit::WebMediaPlayerClient; |
| 69 using WebKit::WebNavigationType; | 73 using WebKit::WebNavigationType; |
| 70 using WebKit::WebNavigationPolicy; | 74 using WebKit::WebNavigationPolicy; |
| 71 using WebKit::WebNode; | 75 using WebKit::WebNode; |
| 72 using WebKit::WebPlugin; | 76 using WebKit::WebPlugin; |
| 73 using WebKit::WebPluginParams; | 77 using WebKit::WebPluginParams; |
| 74 using WebKit::WebPoint; | 78 using WebKit::WebPoint; |
| 75 using WebKit::WebRange; | 79 using WebKit::WebRange; |
| 76 using WebKit::WebRect; | 80 using WebKit::WebRect; |
| 77 using WebKit::WebScreenInfo; | 81 using WebKit::WebScreenInfo; |
| 78 using WebKit::WebSize; | 82 using WebKit::WebSize; |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 bool user_gesture, | 248 bool user_gesture, |
| 245 const GURL& creator_url) { | 249 const GURL& creator_url) { |
| 246 return shell_->CreateWebView(webview); | 250 return shell_->CreateWebView(webview); |
| 247 } | 251 } |
| 248 | 252 |
| 249 WebWidget* TestWebViewDelegate::CreatePopupWidget(WebView* webview, | 253 WebWidget* TestWebViewDelegate::CreatePopupWidget(WebView* webview, |
| 250 bool activatable) { | 254 bool activatable) { |
| 251 return shell_->CreatePopupWidget(webview); | 255 return shell_->CreatePopupWidget(webview); |
| 252 } | 256 } |
| 253 | 257 |
| 254 WebPlugin* TestWebViewDelegate::CreatePlugin( | |
| 255 WebFrame* frame, const WebPluginParams& params) { | |
| 256 return new webkit_glue::WebPluginImpl(frame, params, AsWeakPtr()); | |
| 257 } | |
| 258 | |
| 259 WebKit::WebMediaPlayer* TestWebViewDelegate::CreateWebMediaPlayer( | |
| 260 WebKit::WebMediaPlayerClient* client) { | |
| 261 scoped_refptr<media::FilterFactoryCollection> factory = | |
| 262 new media::FilterFactoryCollection(); | |
| 263 | |
| 264 // TODO(hclam): this is the same piece of code as in RenderView, maybe they | |
| 265 // should be grouped together. | |
| 266 webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory = | |
| 267 new webkit_glue::MediaResourceLoaderBridgeFactory( | |
| 268 GURL::EmptyGURL(), // referrer | |
| 269 "null", // frame origin | |
| 270 "null", // main_frame_origin | |
| 271 base::GetCurrentProcId(), | |
| 272 appcache::kNoHostId, | |
| 273 0); | |
| 274 factory->AddFactory(webkit_glue::BufferedDataSource::CreateFactory( | |
| 275 MessageLoop::current(), bridge_factory)); | |
| 276 // TODO(hclam): Use command line switch to determine which data source to use. | |
| 277 return new webkit_glue::WebMediaPlayerImpl(client, factory); | |
| 278 } | |
| 279 | |
| 280 WebWorker* TestWebViewDelegate::CreateWebWorker(WebWorkerClient* client) { | |
| 281 #if ENABLE(WORKERS) | |
| 282 return TestWebWorkerHelper::CreateWebWorker(client); | |
| 283 #else | |
| 284 return NULL; | |
| 285 #endif | |
| 286 } | |
| 287 | |
| 288 void TestWebViewDelegate::OpenURL(WebView* webview, const GURL& url, | |
| 289 const GURL& referrer, | |
| 290 WebNavigationPolicy policy) { | |
| 291 DCHECK_NE(policy, WebKit::WebNavigationPolicyCurrentTab); | |
| 292 TestShell* shell = NULL; | |
| 293 if (TestShell::CreateNewWindow(UTF8ToWide(url.spec()), &shell)) | |
| 294 shell->Show(policy); | |
| 295 } | |
| 296 | |
| 297 void TestWebViewDelegate::WindowObjectCleared(WebFrame* webframe) { | |
| 298 shell_->BindJSObjectsToWindow(webframe); | |
| 299 } | |
| 300 | |
| 301 WebNavigationPolicy TestWebViewDelegate::PolicyForNavigationAction( | |
| 302 WebView* webview, | |
| 303 WebFrame* frame, | |
| 304 const WebURLRequest& request, | |
| 305 WebNavigationType type, | |
| 306 WebNavigationPolicy default_policy, | |
| 307 bool is_redirect) { | |
| 308 WebNavigationPolicy result; | |
| 309 if (policy_delegate_enabled_) { | |
| 310 printf("Policy delegate: attempt to load %s with navigation type '%s'\n", | |
| 311 GetURLDescription(request.url()).c_str(), | |
| 312 WebNavigationTypeToString(type)); | |
| 313 if (policy_delegate_is_permissive_) { | |
| 314 result = WebKit::WebNavigationPolicyCurrentTab; | |
| 315 } else { | |
| 316 result = WebKit::WebNavigationPolicyIgnore; | |
| 317 } | |
| 318 if (policy_delegate_should_notify_done_) | |
| 319 shell_->layout_test_controller()->PolicyDelegateDone(); | |
| 320 } else { | |
| 321 result = default_policy; | |
| 322 } | |
| 323 return result; | |
| 324 } | |
| 325 | |
| 326 void TestWebViewDelegate::AssignIdentifierToRequest( | |
| 327 WebFrame* webframe, | |
| 328 uint32 identifier, | |
| 329 const WebURLRequest& request) { | |
| 330 if (shell_->ShouldDumpResourceLoadCallbacks()) | |
| 331 resource_identifier_map_[identifier] = request.url().spec(); | |
| 332 } | |
| 333 | |
| 334 std::string TestWebViewDelegate::GetResourceDescription(uint32 identifier) { | 258 std::string TestWebViewDelegate::GetResourceDescription(uint32 identifier) { |
| 335 ResourceMap::iterator it = resource_identifier_map_.find(identifier); | 259 ResourceMap::iterator it = resource_identifier_map_.find(identifier); |
| 336 return it != resource_identifier_map_.end() ? it->second : "<unknown>"; | 260 return it != resource_identifier_map_.end() ? it->second : "<unknown>"; |
| 337 } | 261 } |
| 338 | 262 |
| 339 void TestWebViewDelegate::WillSendRequest( | |
| 340 WebFrame* webframe, | |
| 341 uint32 identifier, | |
| 342 WebURLRequest* request, | |
| 343 const WebURLResponse& redirect_response) { | |
| 344 GURL url = request->url(); | |
| 345 std::string request_url = url.possibly_invalid_spec(); | |
| 346 | |
| 347 if (shell_->ShouldDumpResourceLoadCallbacks()) { | |
| 348 GURL main_document_url = request->firstPartyForCookies(); | |
| 349 printf("%s - willSendRequest <NSURLRequest URL %s, main document URL %s," | |
| 350 " http method %s> redirectResponse %s\n", | |
| 351 GetResourceDescription(identifier).c_str(), | |
| 352 request_url.c_str(), | |
| 353 GetURLDescription(main_document_url).c_str(), | |
| 354 request->httpMethod().utf8().data(), | |
| 355 GetResponseDescription(redirect_response).c_str()); | |
| 356 } | |
| 357 | |
| 358 if (!redirect_response.isNull() && block_redirects_) { | |
| 359 printf("Returning null for this redirect\n"); | |
| 360 | |
| 361 // To block the request, we set its URL to an empty one. | |
| 362 request->setURL(WebURL()); | |
| 363 return; | |
| 364 } | |
| 365 | |
| 366 std::string host = url.host(); | |
| 367 if (TestShell::layout_test_mode() && !host.empty() && | |
| 368 (url.SchemeIs("http") || url.SchemeIs("https")) && | |
| 369 host != "127.0.0.1" && | |
| 370 host != "255.255.255.255" && // Used in some tests that expect to get | |
| 371 // back an error. | |
| 372 host != "localhost") { | |
| 373 printf("Blocked access to external URL %s\n", request_url.c_str()); | |
| 374 | |
| 375 // To block the request, we set its URL to an empty one. | |
| 376 request->setURL(WebURL()); | |
| 377 return; | |
| 378 } | |
| 379 | |
| 380 TRACE_EVENT_BEGIN("url.load", identifier, request_url); | |
| 381 // Set the new substituted URL. | |
| 382 request->setURL(GURL(TestShell::RewriteLocalUrl(request_url))); | |
| 383 } | |
| 384 | |
| 385 void TestWebViewDelegate::DidReceiveResponse( | |
| 386 WebFrame* webframe, | |
| 387 uint32 identifier, | |
| 388 const WebURLResponse& response) { | |
| 389 if (shell_->ShouldDumpResourceLoadCallbacks()) { | |
| 390 printf("%s - didReceiveResponse %s\n", | |
| 391 GetResourceDescription(identifier).c_str(), | |
| 392 GetResponseDescription(response).c_str()); | |
| 393 } | |
| 394 } | |
| 395 | |
| 396 void TestWebViewDelegate::DidFinishLoading(WebFrame* webframe, | |
| 397 uint32 identifier) { | |
| 398 TRACE_EVENT_END("url.load", identifier, ""); | |
| 399 if (shell_->ShouldDumpResourceLoadCallbacks()) { | |
| 400 printf("%s - didFinishLoading\n", | |
| 401 GetResourceDescription(identifier).c_str()); | |
| 402 } | |
| 403 | |
| 404 resource_identifier_map_.erase(identifier); | |
| 405 } | |
| 406 | |
| 407 void TestWebViewDelegate::DidFailLoadingWithError(WebFrame* webframe, | |
| 408 uint32 identifier, | |
| 409 const WebURLError& error) { | |
| 410 if (shell_->ShouldDumpResourceLoadCallbacks()) { | |
| 411 printf("%s - didFailLoadingWithError: %s\n", | |
| 412 GetResourceDescription(identifier).c_str(), | |
| 413 GetErrorDescription(error).c_str()); | |
| 414 } | |
| 415 | |
| 416 resource_identifier_map_.erase(identifier); | |
| 417 } | |
| 418 | |
| 419 void TestWebViewDelegate::DidCreateDataSource(WebFrame* frame, | |
| 420 WebDataSource* ds) { | |
| 421 ds->setExtraData(pending_extra_data_.release()); | |
| 422 } | |
| 423 | |
| 424 void TestWebViewDelegate::DidStartProvisionalLoadForFrame( | |
| 425 WebView* webview, | |
| 426 WebFrame* frame, | |
| 427 NavigationGesture gesture) { | |
| 428 if (shell_->ShouldDumpFrameLoadCallbacks()) { | |
| 429 printf("%S - didStartProvisionalLoadForFrame\n", | |
| 430 GetFrameDescription(frame).c_str()); | |
| 431 } | |
| 432 | |
| 433 if (!top_loading_frame_) { | |
| 434 top_loading_frame_ = frame; | |
| 435 } | |
| 436 | |
| 437 if (shell_->layout_test_controller()->StopProvisionalFrameLoads()) { | |
| 438 printf("%S - stopping load in didStartProvisionalLoadForFrame callback\n", | |
| 439 GetFrameDescription(frame).c_str()); | |
| 440 frame->stopLoading(); | |
| 441 } | |
| 442 UpdateAddressBar(webview); | |
| 443 } | |
| 444 | |
| 445 void TestWebViewDelegate::DidReceiveProvisionalLoadServerRedirect( | |
| 446 WebView* webview, | |
| 447 WebFrame* frame) { | |
| 448 if (shell_->ShouldDumpFrameLoadCallbacks()) { | |
| 449 printf("%S - didReceiveServerRedirectForProvisionalLoadForFrame\n", | |
| 450 GetFrameDescription(frame).c_str()); | |
| 451 } | |
| 452 | |
| 453 UpdateAddressBar(webview); | |
| 454 } | |
| 455 | |
| 456 void TestWebViewDelegate::DidFailProvisionalLoadWithError( | |
| 457 WebView* webview, | |
| 458 const WebURLError& error, | |
| 459 WebFrame* frame) { | |
| 460 if (shell_->ShouldDumpFrameLoadCallbacks()) { | |
| 461 printf("%S - didFailProvisionalLoadWithError\n", | |
| 462 GetFrameDescription(frame).c_str()); | |
| 463 } | |
| 464 | |
| 465 LocationChangeDone(frame); | |
| 466 | |
| 467 // Don't display an error page if we're running layout tests, because | |
| 468 // DumpRenderTree doesn't. | |
| 469 if (shell_->layout_test_mode()) | |
| 470 return; | |
| 471 | |
| 472 // Don't display an error page if this is simply a cancelled load. Aside | |
| 473 // from being dumb, WebCore doesn't expect it and it will cause a crash. | |
| 474 if (error.reason == net::ERR_ABORTED) | |
| 475 return; | |
| 476 | |
| 477 const WebDataSource* failed_ds = frame->provisionalDataSource(); | |
| 478 | |
| 479 TestShellExtraData* extra_data = | |
| 480 static_cast<TestShellExtraData*>(failed_ds->extraData()); | |
| 481 bool replace = extra_data && extra_data->pending_page_id != -1; | |
| 482 | |
| 483 const std::string& error_text = | |
| 484 StringPrintf("Error %d when loading url %s", error.reason, | |
| 485 failed_ds->request().url().spec().data()); | |
| 486 | |
| 487 // Make sure we never show errors in view source mode. | |
| 488 frame->enableViewSourceMode(false); | |
| 489 | |
| 490 frame->loadHTMLString( | |
| 491 error_text, GURL("testshell-error:"), error.unreachableURL, replace); | |
| 492 } | |
| 493 | |
| 494 void TestWebViewDelegate::DidCommitLoadForFrame(WebView* webview, | |
| 495 WebFrame* frame, | |
| 496 bool is_new_navigation) { | |
| 497 if (shell_->ShouldDumpFrameLoadCallbacks()) { | |
| 498 printf("%S - didCommitLoadForFrame\n", | |
| 499 GetFrameDescription(frame).c_str()); | |
| 500 } | |
| 501 | |
| 502 UpdateForCommittedLoad(frame, is_new_navigation); | |
| 503 } | |
| 504 | |
| 505 void TestWebViewDelegate::DidReceiveTitle(WebView* webview, | |
| 506 const std::wstring& title, | |
| 507 WebFrame* frame) { | |
| 508 if (shell_->ShouldDumpFrameLoadCallbacks()) { | |
| 509 printf("%S - didReceiveTitle\n", | |
| 510 GetFrameDescription(frame).c_str()); | |
| 511 } | |
| 512 | |
| 513 if (shell_->ShouldDumpTitleChanges()) { | |
| 514 printf("TITLE CHANGED: %S\n", title.c_str()); | |
| 515 } | |
| 516 | |
| 517 SetPageTitle(title); | |
| 518 } | |
| 519 | |
| 520 void TestWebViewDelegate::DidFinishLoadForFrame(WebView* webview, | |
| 521 WebFrame* frame) { | |
| 522 TRACE_EVENT_END("frame.load", this, frame->url().spec()); | |
| 523 if (shell_->ShouldDumpFrameLoadCallbacks()) { | |
| 524 printf("%S - didFinishLoadForFrame\n", | |
| 525 GetFrameDescription(frame).c_str()); | |
| 526 } | |
| 527 | |
| 528 UpdateAddressBar(webview); | |
| 529 LocationChangeDone(frame); | |
| 530 } | |
| 531 | |
| 532 void TestWebViewDelegate::DidFailLoadWithError(WebView* webview, | |
| 533 const WebURLError& error, | |
| 534 WebFrame* frame) { | |
| 535 if (shell_->ShouldDumpFrameLoadCallbacks()) { | |
| 536 printf("%S - didFailLoadWithError\n", | |
| 537 GetFrameDescription(frame).c_str()); | |
| 538 } | |
| 539 | |
| 540 LocationChangeDone(frame); | |
| 541 } | |
| 542 | |
| 543 void TestWebViewDelegate::DidFinishDocumentLoadForFrame(WebView* webview, | |
| 544 WebFrame* frame) { | |
| 545 if (shell_->ShouldDumpFrameLoadCallbacks()) { | |
| 546 printf("%S - didFinishDocumentLoadForFrame\n", | |
| 547 GetFrameDescription(frame).c_str()); | |
| 548 } else { | |
| 549 unsigned pending_unload_events = frame->unloadListenerCount(); | |
| 550 if (pending_unload_events) { | |
| 551 printf("%S - has %u onunload handler(s)\n", | |
| 552 GetFrameDescription(frame).c_str(), pending_unload_events); | |
| 553 } | |
| 554 } | |
| 555 } | |
| 556 | |
| 557 void TestWebViewDelegate::DidHandleOnloadEventsForFrame(WebView* webview, | |
| 558 WebFrame* frame) { | |
| 559 if (shell_->ShouldDumpFrameLoadCallbacks()) { | |
| 560 printf("%S - didHandleOnloadEventsForFrame\n", | |
| 561 GetFrameDescription(frame).c_str()); | |
| 562 } | |
| 563 } | |
| 564 | |
| 565 void TestWebViewDelegate::DidChangeLocationWithinPageForFrame( | |
| 566 WebView* webview, WebFrame* frame, bool is_new_navigation) { | |
| 567 frame->dataSource()->setExtraData(pending_extra_data_.release()); | |
| 568 | |
| 569 if (shell_->ShouldDumpFrameLoadCallbacks()) { | |
| 570 printf("%S - didChangeLocationWithinPageForFrame\n", | |
| 571 GetFrameDescription(frame).c_str()); | |
| 572 } | |
| 573 | |
| 574 UpdateForCommittedLoad(frame, is_new_navigation); | |
| 575 } | |
| 576 | |
| 577 void TestWebViewDelegate::DidReceiveIconForFrame(WebView* webview, | 263 void TestWebViewDelegate::DidReceiveIconForFrame(WebView* webview, |
| 578 WebFrame* frame) { | 264 WebFrame* frame) { |
| 579 if (shell_->ShouldDumpFrameLoadCallbacks()) { | 265 if (shell_->ShouldDumpFrameLoadCallbacks()) { |
| 580 printf("%S - didReceiveIconForFrame\n", | 266 printf("%S - didReceiveIconForFrame\n", |
| 581 GetFrameDescription(frame).c_str()); | 267 GetFrameDescription(frame).c_str()); |
| 582 } | 268 } |
| 583 } | 269 } |
| 584 | 270 |
| 585 void TestWebViewDelegate::WillPerformClientRedirect(WebView* webview, | |
| 586 WebFrame* frame, | |
| 587 const GURL& src_url, | |
| 588 const GURL& dest_url, | |
| 589 unsigned int delay_seconds, | |
| 590 unsigned int fire_date) { | |
| 591 if (shell_->ShouldDumpFrameLoadCallbacks()) { | |
| 592 printf("%S - willPerformClientRedirectToURL: %s \n", | |
| 593 GetFrameDescription(frame).c_str(), | |
| 594 dest_url.possibly_invalid_spec().c_str()); | |
| 595 } | |
| 596 } | |
| 597 | |
| 598 void TestWebViewDelegate::DidCancelClientRedirect(WebView* webview, | |
| 599 WebFrame* frame) { | |
| 600 if (shell_->ShouldDumpFrameLoadCallbacks()) { | |
| 601 printf("%S - didCancelClientRedirectForFrame\n", | |
| 602 GetFrameDescription(frame).c_str()); | |
| 603 } | |
| 604 } | |
| 605 | |
| 606 void TestWebViewDelegate::AddMessageToConsole(WebView* webview, | 271 void TestWebViewDelegate::AddMessageToConsole(WebView* webview, |
| 607 const std::wstring& message, | 272 const std::wstring& message, |
| 608 unsigned int line_no, | 273 unsigned int line_no, |
| 609 const std::wstring& source_id) { | 274 const std::wstring& source_id) { |
| 610 if (!shell_->layout_test_mode()) { | 275 if (!shell_->layout_test_mode()) { |
| 611 logging::LogMessage("CONSOLE", 0).stream() << "\"" | 276 logging::LogMessage("CONSOLE", 0).stream() << "\"" |
| 612 << message.c_str() | 277 << message.c_str() |
| 613 << ",\" source: " | 278 << ",\" source: " |
| 614 << source_id.c_str() | 279 << source_id.c_str() |
| 615 << "(" | 280 << "(" |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 893 } | 558 } |
| 894 } | 559 } |
| 895 | 560 |
| 896 void TestWebViewDelegate::didEndEditing() { | 561 void TestWebViewDelegate::didEndEditing() { |
| 897 if (shell_->ShouldDumpEditingCallbacks()) { | 562 if (shell_->ShouldDumpEditingCallbacks()) { |
| 898 printf("EDITING DELEGATE: " | 563 printf("EDITING DELEGATE: " |
| 899 "webViewDidEndEditing:WebViewDidEndEditingNotification\n"); | 564 "webViewDidEndEditing:WebViewDidEndEditingNotification\n"); |
| 900 } | 565 } |
| 901 } | 566 } |
| 902 | 567 |
| 568 // WebFrameClient ------------------------------------------------------------ |
| 569 |
| 570 WebPlugin* TestWebViewDelegate::createPlugin( |
| 571 WebFrame* frame, const WebPluginParams& params) { |
| 572 return new webkit_glue::WebPluginImpl(frame, params, AsWeakPtr()); |
| 573 } |
| 574 |
| 575 WebWorker* TestWebViewDelegate::createWorker( |
| 576 WebFrame* frame, WebWorkerClient* client) { |
| 577 #if ENABLE(WORKERS) |
| 578 return TestWebWorkerHelper::CreateWebWorker(client); |
| 579 #else |
| 580 return NULL; |
| 581 #endif |
| 582 } |
| 583 |
| 584 WebMediaPlayer* TestWebViewDelegate::createMediaPlayer( |
| 585 WebFrame* frame, WebMediaPlayerClient* client) { |
| 586 scoped_refptr<media::FilterFactoryCollection> factory = |
| 587 new media::FilterFactoryCollection(); |
| 588 |
| 589 // TODO(hclam): this is the same piece of code as in RenderView, maybe they |
| 590 // should be grouped together. |
| 591 webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory = |
| 592 new webkit_glue::MediaResourceLoaderBridgeFactory( |
| 593 GURL::EmptyGURL(), // referrer |
| 594 "null", // frame origin |
| 595 "null", // main_frame_origin |
| 596 base::GetCurrentProcId(), |
| 597 appcache::kNoHostId, |
| 598 0); |
| 599 factory->AddFactory(webkit_glue::BufferedDataSource::CreateFactory( |
| 600 MessageLoop::current(), bridge_factory)); |
| 601 // TODO(hclam): Use command line switch to determine which data source to use. |
| 602 return new webkit_glue::WebMediaPlayerImpl(client, factory); |
| 603 } |
| 604 |
| 605 void TestWebViewDelegate::willClose(WebFrame* frame) { |
| 606 } |
| 607 |
| 608 void TestWebViewDelegate::loadURLExternally( |
| 609 WebFrame* frame, const WebURLRequest& request, |
| 610 WebNavigationPolicy policy) { |
| 611 DCHECK_NE(policy, WebKit::WebNavigationPolicyCurrentTab); |
| 612 TestShell* shell = NULL; |
| 613 if (TestShell::CreateNewWindow(request.url(), &shell)) |
| 614 shell->Show(policy); |
| 615 } |
| 616 |
| 617 WebNavigationPolicy TestWebViewDelegate::decidePolicyForNavigation( |
| 618 WebFrame* frame, const WebURLRequest& request, |
| 619 WebNavigationType type, WebNavigationPolicy default_policy, |
| 620 bool is_redirect) { |
| 621 WebNavigationPolicy result; |
| 622 if (policy_delegate_enabled_) { |
| 623 printf("Policy delegate: attempt to load %s with navigation type '%s'\n", |
| 624 GetURLDescription(request.url()).c_str(), |
| 625 WebNavigationTypeToString(type)); |
| 626 if (policy_delegate_is_permissive_) { |
| 627 result = WebKit::WebNavigationPolicyCurrentTab; |
| 628 } else { |
| 629 result = WebKit::WebNavigationPolicyIgnore; |
| 630 } |
| 631 if (policy_delegate_should_notify_done_) |
| 632 shell_->layout_test_controller()->PolicyDelegateDone(); |
| 633 } else { |
| 634 result = default_policy; |
| 635 } |
| 636 return result; |
| 637 } |
| 638 |
| 639 void TestWebViewDelegate::willSubmitForm(WebFrame* frame, const WebForm&) { |
| 640 // Ignore |
| 641 } |
| 642 |
| 643 void TestWebViewDelegate::willPerformClientRedirect( |
| 644 WebFrame* frame, const WebURL& from, const WebURL& to, |
| 645 double interval, double fire_time) { |
| 646 if (shell_->ShouldDumpFrameLoadCallbacks()) { |
| 647 printf("%S - willPerformClientRedirectToURL: %s \n", |
| 648 GetFrameDescription(frame).c_str(), |
| 649 to.spec().data()); |
| 650 } |
| 651 } |
| 652 |
| 653 void TestWebViewDelegate::didCancelClientRedirect(WebFrame* frame) { |
| 654 if (shell_->ShouldDumpFrameLoadCallbacks()) { |
| 655 printf("%S - didCancelClientRedirectForFrame\n", |
| 656 GetFrameDescription(frame).c_str()); |
| 657 } |
| 658 } |
| 659 |
| 660 void TestWebViewDelegate::didCompleteClientRedirect( |
| 661 WebFrame* frame, const WebURL& from) { |
| 662 } |
| 663 |
| 664 void TestWebViewDelegate::didCreateDataSource( |
| 665 WebFrame* frame, WebDataSource* ds) { |
| 666 ds->setExtraData(pending_extra_data_.release()); |
| 667 } |
| 668 |
| 669 void TestWebViewDelegate::didStartProvisionalLoad(WebFrame* frame) { |
| 670 if (shell_->ShouldDumpFrameLoadCallbacks()) { |
| 671 printf("%S - didStartProvisionalLoadForFrame\n", |
| 672 GetFrameDescription(frame).c_str()); |
| 673 } |
| 674 |
| 675 if (!top_loading_frame_) { |
| 676 top_loading_frame_ = frame; |
| 677 } |
| 678 |
| 679 if (shell_->layout_test_controller()->StopProvisionalFrameLoads()) { |
| 680 printf("%S - stopping load in didStartProvisionalLoadForFrame callback\n", |
| 681 GetFrameDescription(frame).c_str()); |
| 682 frame->stopLoading(); |
| 683 } |
| 684 UpdateAddressBar(frame->view()); |
| 685 } |
| 686 |
| 687 void TestWebViewDelegate::didReceiveServerRedirectForProvisionalLoad( |
| 688 WebFrame* frame) { |
| 689 if (shell_->ShouldDumpFrameLoadCallbacks()) { |
| 690 printf("%S - didReceiveServerRedirectForProvisionalLoadForFrame\n", |
| 691 GetFrameDescription(frame).c_str()); |
| 692 } |
| 693 UpdateAddressBar(frame->view()); |
| 694 } |
| 695 |
| 696 void TestWebViewDelegate::didFailProvisionalLoad( |
| 697 WebFrame* frame, const WebURLError& error) { |
| 698 if (shell_->ShouldDumpFrameLoadCallbacks()) { |
| 699 printf("%S - didFailProvisionalLoadWithError\n", |
| 700 GetFrameDescription(frame).c_str()); |
| 701 } |
| 702 |
| 703 LocationChangeDone(frame); |
| 704 |
| 705 // Don't display an error page if we're running layout tests, because |
| 706 // DumpRenderTree doesn't. |
| 707 if (shell_->layout_test_mode()) |
| 708 return; |
| 709 |
| 710 // Don't display an error page if this is simply a cancelled load. Aside |
| 711 // from being dumb, WebCore doesn't expect it and it will cause a crash. |
| 712 if (error.reason == net::ERR_ABORTED) |
| 713 return; |
| 714 |
| 715 const WebDataSource* failed_ds = frame->provisionalDataSource(); |
| 716 |
| 717 TestShellExtraData* extra_data = |
| 718 static_cast<TestShellExtraData*>(failed_ds->extraData()); |
| 719 bool replace = extra_data && extra_data->pending_page_id != -1; |
| 720 |
| 721 const std::string& error_text = |
| 722 StringPrintf("Error %d when loading url %s", error.reason, |
| 723 failed_ds->request().url().spec().data()); |
| 724 |
| 725 // Make sure we never show errors in view source mode. |
| 726 frame->enableViewSourceMode(false); |
| 727 |
| 728 frame->loadHTMLString( |
| 729 error_text, GURL("testshell-error:"), error.unreachableURL, replace); |
| 730 } |
| 731 |
| 732 void TestWebViewDelegate::didReceiveDocumentData( |
| 733 WebFrame* frame, const char* data, size_t length, |
| 734 bool& preventDefault) { |
| 735 // Ignore |
| 736 } |
| 737 |
| 738 void TestWebViewDelegate::didCommitProvisionalLoad( |
| 739 WebFrame* frame, bool is_new_navigation) { |
| 740 if (shell_->ShouldDumpFrameLoadCallbacks()) { |
| 741 printf("%S - didCommitLoadForFrame\n", |
| 742 GetFrameDescription(frame).c_str()); |
| 743 } |
| 744 UpdateForCommittedLoad(frame, is_new_navigation); |
| 745 } |
| 746 |
| 747 void TestWebViewDelegate::didClearWindowObject(WebFrame* frame) { |
| 748 shell_->BindJSObjectsToWindow(frame); |
| 749 } |
| 750 |
| 751 void TestWebViewDelegate::didCreateDocumentElement(WebFrame* frame) { |
| 752 // Ignore |
| 753 } |
| 754 |
| 755 void TestWebViewDelegate::didReceiveTitle( |
| 756 WebFrame* frame, const WebString& title) { |
| 757 std::wstring wtitle = UTF16ToWideHack(title); |
| 758 |
| 759 if (shell_->ShouldDumpFrameLoadCallbacks()) { |
| 760 printf("%S - didReceiveTitle\n", |
| 761 GetFrameDescription(frame).c_str()); |
| 762 } |
| 763 |
| 764 if (shell_->ShouldDumpTitleChanges()) { |
| 765 printf("TITLE CHANGED: %S\n", wtitle.c_str()); |
| 766 } |
| 767 |
| 768 SetPageTitle(wtitle); |
| 769 } |
| 770 |
| 771 void TestWebViewDelegate::didFinishDocumentLoad(WebFrame* frame) { |
| 772 if (shell_->ShouldDumpFrameLoadCallbacks()) { |
| 773 printf("%S - didFinishDocumentLoadForFrame\n", |
| 774 GetFrameDescription(frame).c_str()); |
| 775 } else { |
| 776 unsigned pending_unload_events = frame->unloadListenerCount(); |
| 777 if (pending_unload_events) { |
| 778 printf("%S - has %u onunload handler(s)\n", |
| 779 GetFrameDescription(frame).c_str(), pending_unload_events); |
| 780 } |
| 781 } |
| 782 } |
| 783 |
| 784 void TestWebViewDelegate::didHandleOnloadEvents(WebFrame* frame) { |
| 785 if (shell_->ShouldDumpFrameLoadCallbacks()) { |
| 786 printf("%S - didHandleOnloadEventsForFrame\n", |
| 787 GetFrameDescription(frame).c_str()); |
| 788 } |
| 789 } |
| 790 |
| 791 void TestWebViewDelegate::didFailLoad( |
| 792 WebFrame* frame, const WebURLError& error) { |
| 793 if (shell_->ShouldDumpFrameLoadCallbacks()) { |
| 794 printf("%S - didFailLoadWithError\n", |
| 795 GetFrameDescription(frame).c_str()); |
| 796 } |
| 797 LocationChangeDone(frame); |
| 798 } |
| 799 |
| 800 void TestWebViewDelegate::didFinishLoad(WebFrame* frame) { |
| 801 TRACE_EVENT_END("frame.load", this, frame->url().spec()); |
| 802 if (shell_->ShouldDumpFrameLoadCallbacks()) { |
| 803 printf("%S - didFinishLoadForFrame\n", |
| 804 GetFrameDescription(frame).c_str()); |
| 805 } |
| 806 UpdateAddressBar(frame->view()); |
| 807 LocationChangeDone(frame); |
| 808 } |
| 809 |
| 810 void TestWebViewDelegate::didChangeLocationWithinPage( |
| 811 WebFrame* frame, bool is_new_navigation) { |
| 812 frame->dataSource()->setExtraData(pending_extra_data_.release()); |
| 813 |
| 814 if (shell_->ShouldDumpFrameLoadCallbacks()) { |
| 815 printf("%S - didChangeLocationWithinPageForFrame\n", |
| 816 GetFrameDescription(frame).c_str()); |
| 817 } |
| 818 |
| 819 UpdateForCommittedLoad(frame, is_new_navigation); |
| 820 } |
| 821 |
| 822 void TestWebViewDelegate::assignIdentifierToRequest( |
| 823 WebFrame* frame, unsigned identifier, const WebURLRequest& request) { |
| 824 if (shell_->ShouldDumpResourceLoadCallbacks()) |
| 825 resource_identifier_map_[identifier] = request.url().spec(); |
| 826 } |
| 827 |
| 828 void TestWebViewDelegate::willSendRequest( |
| 829 WebFrame* frame, unsigned identifier, WebURLRequest& request, |
| 830 const WebURLResponse& redirect_response) { |
| 831 GURL url = request.url(); |
| 832 std::string request_url = url.possibly_invalid_spec(); |
| 833 |
| 834 if (shell_->ShouldDumpResourceLoadCallbacks()) { |
| 835 GURL main_document_url = request.firstPartyForCookies(); |
| 836 printf("%s - willSendRequest <NSURLRequest URL %s, main document URL %s," |
| 837 " http method %s> redirectResponse %s\n", |
| 838 GetResourceDescription(identifier).c_str(), |
| 839 request_url.c_str(), |
| 840 GetURLDescription(main_document_url).c_str(), |
| 841 request.httpMethod().utf8().data(), |
| 842 GetResponseDescription(redirect_response).c_str()); |
| 843 } |
| 844 |
| 845 if (!redirect_response.isNull() && block_redirects_) { |
| 846 printf("Returning null for this redirect\n"); |
| 847 |
| 848 // To block the request, we set its URL to an empty one. |
| 849 request.setURL(WebURL()); |
| 850 return; |
| 851 } |
| 852 |
| 853 std::string host = url.host(); |
| 854 if (TestShell::layout_test_mode() && !host.empty() && |
| 855 (url.SchemeIs("http") || url.SchemeIs("https")) && |
| 856 host != "127.0.0.1" && |
| 857 host != "255.255.255.255" && // Used in some tests that expect to get |
| 858 // back an error. |
| 859 host != "localhost") { |
| 860 printf("Blocked access to external URL %s\n", request_url.c_str()); |
| 861 |
| 862 // To block the request, we set its URL to an empty one. |
| 863 request.setURL(WebURL()); |
| 864 return; |
| 865 } |
| 866 |
| 867 TRACE_EVENT_BEGIN("url.load", identifier, request_url); |
| 868 // Set the new substituted URL. |
| 869 request.setURL(GURL(TestShell::RewriteLocalUrl(request_url))); |
| 870 } |
| 871 |
| 872 void TestWebViewDelegate::didReceiveResponse( |
| 873 WebFrame* frame, unsigned identifier, const WebURLResponse& response) { |
| 874 if (shell_->ShouldDumpResourceLoadCallbacks()) { |
| 875 printf("%s - didReceiveResponse %s\n", |
| 876 GetResourceDescription(identifier).c_str(), |
| 877 GetResponseDescription(response).c_str()); |
| 878 } |
| 879 } |
| 880 |
| 881 void TestWebViewDelegate::didFinishResourceLoad( |
| 882 WebFrame* frame, unsigned identifier) { |
| 883 TRACE_EVENT_END("url.load", identifier, ""); |
| 884 if (shell_->ShouldDumpResourceLoadCallbacks()) { |
| 885 printf("%s - didFinishLoading\n", |
| 886 GetResourceDescription(identifier).c_str()); |
| 887 } |
| 888 resource_identifier_map_.erase(identifier); |
| 889 } |
| 890 |
| 891 void TestWebViewDelegate::didFailResourceLoad( |
| 892 WebFrame* frame, unsigned identifier, const WebURLError& error) { |
| 893 if (shell_->ShouldDumpResourceLoadCallbacks()) { |
| 894 printf("%s - didFailLoadingWithError: %s\n", |
| 895 GetResourceDescription(identifier).c_str(), |
| 896 GetErrorDescription(error).c_str()); |
| 897 } |
| 898 resource_identifier_map_.erase(identifier); |
| 899 } |
| 900 |
| 901 void TestWebViewDelegate::didLoadResourceFromMemoryCache( |
| 902 WebFrame* frame, const WebURLRequest&, |
| 903 const WebURLResponse&) { |
| 904 } |
| 905 |
| 906 void TestWebViewDelegate::didExhaustMemoryAvailableForScript(WebFrame* frame) { |
| 907 } |
| 908 |
| 909 void TestWebViewDelegate::didChangeContentsSize( |
| 910 WebFrame* frame, const WebSize&) { |
| 911 } |
| 912 |
| 913 |
| 903 // Public methods ------------------------------------------------------------ | 914 // Public methods ------------------------------------------------------------ |
| 904 | 915 |
| 905 TestWebViewDelegate::TestWebViewDelegate(TestShell* shell) | 916 TestWebViewDelegate::TestWebViewDelegate(TestShell* shell) |
| 906 : policy_delegate_enabled_(false), | 917 : policy_delegate_enabled_(false), |
| 907 policy_delegate_is_permissive_(false), | 918 policy_delegate_is_permissive_(false), |
| 908 policy_delegate_should_notify_done_(false), | 919 policy_delegate_should_notify_done_(false), |
| 909 shell_(shell), | 920 shell_(shell), |
| 910 top_loading_frame_(NULL), | 921 top_loading_frame_(NULL), |
| 911 page_id_(-1), | 922 page_id_(-1), |
| 912 last_page_id_updated_(-1), | 923 last_page_id_updated_(-1), |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1083 return L"main frame \"" + name + L"\""; | 1094 return L"main frame \"" + name + L"\""; |
| 1084 else | 1095 else |
| 1085 return L"main frame"; | 1096 return L"main frame"; |
| 1086 } else { | 1097 } else { |
| 1087 if (name.length()) | 1098 if (name.length()) |
| 1088 return L"frame \"" + name + L"\""; | 1099 return L"frame \"" + name + L"\""; |
| 1089 else | 1100 else |
| 1090 return L"frame (anonymous)"; | 1101 return L"frame (anonymous)"; |
| 1091 } | 1102 } |
| 1092 } | 1103 } |
| OLD | NEW |