OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Implements the Chrome Extensions WebNavigation API. | 5 // Implements the Chrome Extensions WebNavigation API. |
6 | 6 |
7 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h" | 7 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h" |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api_consta
nts.h" | 10 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api_consta
nts.h" |
11 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api_helper
s.h" | 11 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api_helper
s.h" |
12 #include "chrome/browser/extensions/event_router.h" | 12 #include "chrome/browser/extensions/event_router.h" |
13 #include "chrome/browser/extensions/extension_system.h" | 13 #include "chrome/browser/extensions/extension_system.h" |
14 #include "chrome/browser/extensions/extension_tab_util.h" | 14 #include "chrome/browser/extensions/extension_tab_util.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/tab_contents/retargeting_details.h" | 16 #include "chrome/browser/tab_contents/retargeting_details.h" |
17 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
18 #include "chrome/browser/ui/browser_list.h" | 18 #include "chrome/browser/ui/browser_list.h" |
19 #include "chrome/browser/view_type_utils.h" | 19 #include "chrome/browser/view_type_utils.h" |
20 #include "chrome/common/chrome_notification_types.h" | 20 #include "chrome/common/chrome_notification_types.h" |
21 #include "chrome/common/extensions/api/web_navigation.h" | 21 #include "chrome/common/extensions/api/web_navigation.h" |
22 #include "content/public/browser/resource_request_details.h" | 22 #include "content/public/browser/resource_request_details.h" |
23 #include "content/public/browser/navigation_details.h" | 23 #include "content/public/browser/navigation_details.h" |
24 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
25 #include "content/public/browser/notification_types.h" | 25 #include "content/public/browser/notification_types.h" |
26 #include "content/public/browser/render_process_host.h" | 26 #include "content/public/browser/render_process_host.h" |
27 #include "content/public/browser/render_view_host.h" | 27 #include "content/public/browser/render_view_host.h" |
28 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
| 29 #include "content/public/common/url_constants.h" |
29 #include "net/base/net_errors.h" | 30 #include "net/base/net_errors.h" |
30 | 31 |
31 namespace GetFrame = extensions::api::web_navigation::GetFrame; | 32 namespace GetFrame = extensions::api::web_navigation::GetFrame; |
32 namespace GetAllFrames = extensions::api::web_navigation::GetAllFrames; | 33 namespace GetAllFrames = extensions::api::web_navigation::GetAllFrames; |
33 | 34 |
34 DEFINE_WEB_CONTENTS_USER_DATA_KEY(extensions::WebNavigationTabObserver) | 35 DEFINE_WEB_CONTENTS_USER_DATA_KEY(extensions::WebNavigationTabObserver) |
35 | 36 |
36 namespace extensions { | 37 namespace extensions { |
37 | 38 |
38 namespace helpers = web_navigation_api_helpers; | 39 namespace helpers = web_navigation_api_helpers; |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 return; | 370 return; |
370 | 371 |
371 FrameNavigationState::FrameID frame_id(frame_num, render_view_host); | 372 FrameNavigationState::FrameID frame_id(frame_num, render_view_host); |
372 FrameNavigationState::FrameID parent_frame_id( | 373 FrameNavigationState::FrameID parent_frame_id( |
373 parent_frame_num, render_view_host); | 374 parent_frame_num, render_view_host); |
374 | 375 |
375 navigation_state_.TrackFrame(frame_id, | 376 navigation_state_.TrackFrame(frame_id, |
376 parent_frame_id, | 377 parent_frame_id, |
377 validated_url, | 378 validated_url, |
378 is_main_frame, | 379 is_main_frame, |
379 is_error_page); | 380 is_error_page, |
| 381 is_iframe_srcdoc); |
| 382 |
380 if (!navigation_state_.CanSendEvents(frame_id)) | 383 if (!navigation_state_.CanSendEvents(frame_id)) |
381 return; | 384 return; |
382 | 385 |
383 helpers::DispatchOnBeforeNavigate( | 386 helpers::DispatchOnBeforeNavigate( |
384 web_contents(), | 387 web_contents(), |
385 render_view_host->GetProcess()->GetID(), | 388 render_view_host->GetProcess()->GetID(), |
386 frame_num, | 389 frame_num, |
387 is_main_frame, | 390 is_main_frame, |
388 parent_frame_num, | 391 parent_frame_num, |
389 navigation_state_.IsMainFrame(parent_frame_id), | 392 navigation_state_.IsMainFrame(parent_frame_id), |
390 validated_url); | 393 navigation_state_.GetUrl(frame_id)); |
391 } | 394 } |
392 | 395 |
393 void WebNavigationTabObserver::DidCommitProvisionalLoadForFrame( | 396 void WebNavigationTabObserver::DidCommitProvisionalLoadForFrame( |
394 int64 frame_num, | 397 int64 frame_num, |
395 bool is_main_frame, | 398 bool is_main_frame, |
396 const GURL& url, | 399 const GURL& url, |
397 content::PageTransition transition_type, | 400 content::PageTransition transition_type, |
398 content::RenderViewHost* render_view_host) { | 401 content::RenderViewHost* render_view_host) { |
399 if (render_view_host != render_view_host_ && | 402 if (render_view_host != render_view_host_ && |
400 render_view_host != pending_render_view_host_) | 403 render_view_host != pending_render_view_host_) |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 | 437 |
435 if (!navigation_state_.CanSendEvents(frame_id)) | 438 if (!navigation_state_.CanSendEvents(frame_id)) |
436 return; | 439 return; |
437 | 440 |
438 if (is_reference_fragment_navigation) { | 441 if (is_reference_fragment_navigation) { |
439 helpers::DispatchOnCommitted( | 442 helpers::DispatchOnCommitted( |
440 keys::kOnReferenceFragmentUpdated, | 443 keys::kOnReferenceFragmentUpdated, |
441 web_contents(), | 444 web_contents(), |
442 frame_num, | 445 frame_num, |
443 is_main_frame, | 446 is_main_frame, |
444 url, | 447 navigation_state_.GetUrl(frame_id), |
445 transition_type); | 448 transition_type); |
446 } else if (is_history_state_modification) { | 449 } else if (is_history_state_modification) { |
447 helpers::DispatchOnCommitted( | 450 helpers::DispatchOnCommitted( |
448 keys::kOnHistoryStateUpdated, | 451 keys::kOnHistoryStateUpdated, |
449 web_contents(), | 452 web_contents(), |
450 frame_num, | 453 frame_num, |
451 is_main_frame, | 454 is_main_frame, |
452 url, | 455 navigation_state_.GetUrl(frame_id), |
453 transition_type); | 456 transition_type); |
454 } else { | 457 } else { |
455 if (navigation_state_.GetIsServerRedirected(frame_id)) { | 458 if (navigation_state_.GetIsServerRedirected(frame_id)) { |
456 transition_type = static_cast<content::PageTransition>( | 459 transition_type = static_cast<content::PageTransition>( |
457 transition_type | content::PAGE_TRANSITION_SERVER_REDIRECT); | 460 transition_type | content::PAGE_TRANSITION_SERVER_REDIRECT); |
458 } | 461 } |
459 helpers::DispatchOnCommitted( | 462 helpers::DispatchOnCommitted( |
460 keys::kOnCommitted, | 463 keys::kOnCommitted, |
461 web_contents(), | 464 web_contents(), |
462 frame_num, | 465 frame_num, |
463 is_main_frame, | 466 is_main_frame, |
464 url, | 467 navigation_state_.GetUrl(frame_id), |
465 transition_type); | 468 transition_type); |
466 } | 469 } |
467 } | 470 } |
468 | 471 |
469 void WebNavigationTabObserver::DidFailProvisionalLoad( | 472 void WebNavigationTabObserver::DidFailProvisionalLoad( |
470 int64 frame_num, | 473 int64 frame_num, |
471 bool is_main_frame, | 474 bool is_main_frame, |
472 const GURL& validated_url, | 475 const GURL& validated_url, |
473 int error_code, | 476 int error_code, |
474 const string16& error_description, | 477 const string16& error_description, |
475 content::RenderViewHost* render_view_host) { | 478 content::RenderViewHost* render_view_host) { |
476 if (render_view_host != render_view_host_ && | 479 if (render_view_host != render_view_host_ && |
477 render_view_host != pending_render_view_host_) | 480 render_view_host != pending_render_view_host_) |
478 return; | 481 return; |
479 bool stop_tracking_frames = false; | 482 bool stop_tracking_frames = false; |
480 if (render_view_host == pending_render_view_host_) { | 483 if (render_view_host == pending_render_view_host_) { |
481 pending_render_view_host_ = NULL; | 484 pending_render_view_host_ = NULL; |
482 stop_tracking_frames = true; | 485 stop_tracking_frames = true; |
483 } | 486 } |
484 | 487 |
485 FrameNavigationState::FrameID frame_id(frame_num, render_view_host); | 488 FrameNavigationState::FrameID frame_id(frame_num, render_view_host); |
486 if (navigation_state_.CanSendEvents(frame_id)) { | 489 if (navigation_state_.CanSendEvents(frame_id)) { |
487 helpers::DispatchOnErrorOccurred( | 490 helpers::DispatchOnErrorOccurred( |
488 web_contents(), render_view_host->GetProcess()->GetID(), validated_url, | 491 web_contents(), |
489 frame_num, is_main_frame, error_code); | 492 render_view_host->GetProcess()->GetID(), |
| 493 navigation_state_.GetUrl(frame_id), |
| 494 frame_num, |
| 495 is_main_frame, |
| 496 error_code); |
490 } | 497 } |
491 navigation_state_.SetErrorOccurredInFrame(frame_id); | 498 navigation_state_.SetErrorOccurredInFrame(frame_id); |
492 if (stop_tracking_frames) { | 499 if (stop_tracking_frames) { |
493 navigation_state_.StopTrackingFramesInRVH(render_view_host, | 500 navigation_state_.StopTrackingFramesInRVH(render_view_host, |
494 FrameNavigationState::FrameID()); | 501 FrameNavigationState::FrameID()); |
495 } | 502 } |
496 } | 503 } |
497 | 504 |
498 void WebNavigationTabObserver::DocumentLoadedInFrame( | 505 void WebNavigationTabObserver::DocumentLoadedInFrame( |
499 int64 frame_num, | 506 int64 frame_num, |
(...skipping 17 matching lines...) Expand all Loading... |
517 if (render_view_host != render_view_host_) | 524 if (render_view_host != render_view_host_) |
518 return; | 525 return; |
519 FrameNavigationState::FrameID frame_id(frame_num, render_view_host); | 526 FrameNavigationState::FrameID frame_id(frame_num, render_view_host); |
520 // When showing replacement content, we might get load signals for frames | 527 // When showing replacement content, we might get load signals for frames |
521 // that weren't reguarly loaded. | 528 // that weren't reguarly loaded. |
522 if (!navigation_state_.IsValidFrame(frame_id)) | 529 if (!navigation_state_.IsValidFrame(frame_id)) |
523 return; | 530 return; |
524 navigation_state_.SetNavigationCompleted(frame_id); | 531 navigation_state_.SetNavigationCompleted(frame_id); |
525 if (!navigation_state_.CanSendEvents(frame_id)) | 532 if (!navigation_state_.CanSendEvents(frame_id)) |
526 return; | 533 return; |
527 DCHECK_EQ(navigation_state_.GetUrl(frame_id), validated_url); | 534 DCHECK(navigation_state_.GetUrl(frame_id) == validated_url || |
| 535 (navigation_state_.GetUrl(frame_id) == GURL(chrome::kAboutSrcDocURL) && |
| 536 validated_url == GURL(chrome::kAboutBlankURL))); |
528 DCHECK_EQ(navigation_state_.IsMainFrame(frame_id), is_main_frame); | 537 DCHECK_EQ(navigation_state_.IsMainFrame(frame_id), is_main_frame); |
529 helpers::DispatchOnCompleted(web_contents(), | 538 helpers::DispatchOnCompleted(web_contents(), |
530 validated_url, | 539 navigation_state_.GetUrl(frame_id), |
531 is_main_frame, | 540 is_main_frame, |
532 frame_num); | 541 frame_num); |
533 } | 542 } |
534 | 543 |
535 void WebNavigationTabObserver::DidFailLoad( | 544 void WebNavigationTabObserver::DidFailLoad( |
536 int64 frame_num, | 545 int64 frame_num, |
537 const GURL& validated_url, | 546 const GURL& validated_url, |
538 bool is_main_frame, | 547 bool is_main_frame, |
539 int error_code, | 548 int error_code, |
540 const string16& error_description, | 549 const string16& error_description, |
541 content::RenderViewHost* render_view_host) { | 550 content::RenderViewHost* render_view_host) { |
542 if (render_view_host != render_view_host_) | 551 if (render_view_host != render_view_host_) |
543 return; | 552 return; |
544 FrameNavigationState::FrameID frame_id(frame_num, render_view_host); | 553 FrameNavigationState::FrameID frame_id(frame_num, render_view_host); |
545 // When showing replacement content, we might get load signals for frames | 554 // When showing replacement content, we might get load signals for frames |
546 // that weren't reguarly loaded. | 555 // that weren't reguarly loaded. |
547 if (!navigation_state_.IsValidFrame(frame_id)) | 556 if (!navigation_state_.IsValidFrame(frame_id)) |
548 return; | 557 return; |
549 if (navigation_state_.CanSendEvents(frame_id)) { | 558 if (navigation_state_.CanSendEvents(frame_id)) { |
550 helpers::DispatchOnErrorOccurred( | 559 helpers::DispatchOnErrorOccurred( |
551 web_contents(), render_view_host->GetProcess()->GetID(), validated_url, | 560 web_contents(), |
552 frame_num, is_main_frame, error_code); | 561 render_view_host->GetProcess()->GetID(), |
| 562 navigation_state_.GetUrl(frame_id), |
| 563 frame_num, |
| 564 is_main_frame, |
| 565 error_code); |
553 } | 566 } |
554 navigation_state_.SetErrorOccurredInFrame(frame_id); | 567 navigation_state_.SetErrorOccurredInFrame(frame_id); |
555 } | 568 } |
556 | 569 |
557 void WebNavigationTabObserver::DidOpenRequestedURL( | 570 void WebNavigationTabObserver::DidOpenRequestedURL( |
558 content::WebContents* new_contents, | 571 content::WebContents* new_contents, |
559 const GURL& url, | 572 const GURL& url, |
560 const content::Referrer& referrer, | 573 const content::Referrer& referrer, |
561 WindowOpenDisposition disposition, | 574 WindowOpenDisposition disposition, |
562 content::PageTransition transition, | 575 content::PageTransition transition, |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
772 static base::LazyInstance<ProfileKeyedAPIFactory<WebNavigationAPI> > | 785 static base::LazyInstance<ProfileKeyedAPIFactory<WebNavigationAPI> > |
773 g_factory = LAZY_INSTANCE_INITIALIZER; | 786 g_factory = LAZY_INSTANCE_INITIALIZER; |
774 | 787 |
775 template <> | 788 template <> |
776 ProfileKeyedAPIFactory<WebNavigationAPI>* | 789 ProfileKeyedAPIFactory<WebNavigationAPI>* |
777 ProfileKeyedAPIFactory<WebNavigationAPI>::GetInstance() { | 790 ProfileKeyedAPIFactory<WebNavigationAPI>::GetInstance() { |
778 return &g_factory.Get(); | 791 return &g_factory.Get(); |
779 } | 792 } |
780 | 793 |
781 } // namespace extensions | 794 } // namespace extensions |
OLD | NEW |