Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: chrome/browser/extensions/api/web_navigation/web_navigation_api.cc

Issue 9959097: Move webNavigation extension api into a separate directory (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/extension_webnavigation_api.h" 7 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h"
8 8
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
11 #include "base/string_number_conversions.h" 11 #include "base/string_number_conversions.h"
12 #include "base/time.h" 12 #include "base/time.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api_consta nts.h"
14 #include "chrome/browser/extensions/extension_event_router.h" 15 #include "chrome/browser/extensions/extension_event_router.h"
15 #include "chrome/browser/extensions/extension_tab_util.h" 16 #include "chrome/browser/extensions/extension_tab_util.h"
16 #include "chrome/browser/extensions/extension_webnavigation_api_constants.h"
17 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/tab_contents/retargeting_details.h" 18 #include "chrome/browser/tab_contents/retargeting_details.h"
19 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 19 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
20 #include "chrome/common/chrome_notification_types.h" 20 #include "chrome/common/chrome_notification_types.h"
21 #include "chrome/common/url_constants.h" 21 #include "chrome/common/url_constants.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_view_host.h" 26 #include "content/public/browser/render_view_host.h"
27 #include "content/public/browser/render_view_host_delegate.h" 27 #include "content/public/browser/render_view_host_delegate.h"
28 #include "content/public/browser/web_contents.h" 28 #include "content/public/browser/web_contents.h"
29 #include "net/base/net_errors.h" 29 #include "net/base/net_errors.h"
30 30
31 namespace keys = extension_webnavigation_api_constants;
32
33 using content::BrowserContext; 31 using content::BrowserContext;
34 using content::ResourceRedirectDetails; 32 using content::ResourceRedirectDetails;
35 using content::WebContents; 33 using content::WebContents;
36 34
35 namespace extensions {
36
37 namespace keys = web_navigation_api_constants;
38
37 namespace { 39 namespace {
38 40
39 typedef std::map<WebContents*, ExtensionWebNavigationTabObserver*> 41 typedef std::map<WebContents*, WebNavigationTabObserver*> TabObserverMap;
40 TabObserverMap;
41 static base::LazyInstance<TabObserverMap> g_tab_observer = 42 static base::LazyInstance<TabObserverMap> g_tab_observer =
42 LAZY_INSTANCE_INITIALIZER; 43 LAZY_INSTANCE_INITIALIZER;
43 44
44 // URL schemes for which we'll send events. 45 // URL schemes for which we'll send events.
45 const char* kValidSchemes[] = { 46 const char* kValidSchemes[] = {
46 chrome::kHttpScheme, 47 chrome::kHttpScheme,
47 chrome::kHttpsScheme, 48 chrome::kHttpsScheme,
48 chrome::kFileScheme, 49 chrome::kFileScheme,
49 chrome::kFtpScheme, 50 chrome::kFtpScheme,
50 chrome::kJavaScriptScheme, 51 chrome::kJavaScriptScheme,
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 } 360 }
360 361
361 bool FrameNavigationState::GetIsServerRedirected(int64 frame_id) const { 362 bool FrameNavigationState::GetIsServerRedirected(int64 frame_id) const {
362 FrameIdToStateMap::const_iterator frame_state = 363 FrameIdToStateMap::const_iterator frame_state =
363 frame_state_map_.find(frame_id); 364 frame_state_map_.find(frame_id);
364 return (frame_state != frame_state_map_.end() && 365 return (frame_state != frame_state_map_.end() &&
365 frame_state->second.is_server_redirected); 366 frame_state->second.is_server_redirected);
366 } 367 }
367 368
368 369
369 // ExtensionWebNavigtionEventRouter ------------------------------------------- 370 // WebNavigtionEventRouter -------------------------------------------
370 371
371 ExtensionWebNavigationEventRouter::PendingWebContents::PendingWebContents() 372 WebNavigationEventRouter::PendingWebContents::PendingWebContents()
372 : source_web_contents(NULL), 373 : source_web_contents(NULL),
373 source_frame_id(0), 374 source_frame_id(0),
374 source_frame_is_main_frame(false), 375 source_frame_is_main_frame(false),
375 target_web_contents(NULL), 376 target_web_contents(NULL),
376 target_url() { 377 target_url() {
377 } 378 }
378 379
379 ExtensionWebNavigationEventRouter::PendingWebContents::PendingWebContents( 380 WebNavigationEventRouter::PendingWebContents::PendingWebContents(
380 WebContents* source_web_contents, 381 WebContents* source_web_contents,
381 int64 source_frame_id, 382 int64 source_frame_id,
382 bool source_frame_is_main_frame, 383 bool source_frame_is_main_frame,
383 WebContents* target_web_contents, 384 WebContents* target_web_contents,
384 const GURL& target_url) 385 const GURL& target_url)
385 : source_web_contents(source_web_contents), 386 : source_web_contents(source_web_contents),
386 source_frame_id(source_frame_id), 387 source_frame_id(source_frame_id),
387 source_frame_is_main_frame(source_frame_is_main_frame), 388 source_frame_is_main_frame(source_frame_is_main_frame),
388 target_web_contents(target_web_contents), 389 target_web_contents(target_web_contents),
389 target_url(target_url) { 390 target_url(target_url) {
390 } 391 }
391 392
392 ExtensionWebNavigationEventRouter::PendingWebContents::~PendingWebContents() {} 393 WebNavigationEventRouter::PendingWebContents::~PendingWebContents() {}
393 394
394 ExtensionWebNavigationEventRouter::ExtensionWebNavigationEventRouter( 395 WebNavigationEventRouter::WebNavigationEventRouter(Profile* profile)
395 Profile* profile) : profile_(profile) {} 396 : profile_(profile) {}
396 397
397 ExtensionWebNavigationEventRouter::~ExtensionWebNavigationEventRouter() {} 398 WebNavigationEventRouter::~WebNavigationEventRouter() {}
398 399
399 void ExtensionWebNavigationEventRouter::Init() { 400 void WebNavigationEventRouter::Init() {
400 if (registrar_.IsEmpty()) { 401 if (registrar_.IsEmpty()) {
401 registrar_.Add(this, 402 registrar_.Add(this,
402 chrome::NOTIFICATION_RETARGETING, 403 chrome::NOTIFICATION_RETARGETING,
403 content::NotificationService::AllSources()); 404 content::NotificationService::AllSources());
404 registrar_.Add(this, 405 registrar_.Add(this,
405 content::NOTIFICATION_TAB_ADDED, 406 content::NOTIFICATION_TAB_ADDED,
406 content::NotificationService::AllSources()); 407 content::NotificationService::AllSources());
407 registrar_.Add(this, 408 registrar_.Add(this,
408 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 409 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
409 content::NotificationService::AllSources()); 410 content::NotificationService::AllSources());
410 } 411 }
411 } 412 }
412 413
413 void ExtensionWebNavigationEventRouter::Observe( 414 void WebNavigationEventRouter::Observe(
414 int type, 415 int type,
415 const content::NotificationSource& source, 416 const content::NotificationSource& source,
416 const content::NotificationDetails& details) { 417 const content::NotificationDetails& details) {
417 switch (type) { 418 switch (type) {
418 case chrome::NOTIFICATION_RETARGETING: { 419 case chrome::NOTIFICATION_RETARGETING: {
419 Profile* profile = content::Source<Profile>(source).ptr(); 420 Profile* profile = content::Source<Profile>(source).ptr();
420 if (profile->GetOriginalProfile() == profile_) { 421 if (profile->GetOriginalProfile() == profile_) {
421 Retargeting( 422 Retargeting(
422 content::Details<const RetargetingDetails>(details).ptr()); 423 content::Details<const RetargetingDetails>(details).ptr());
423 } 424 }
424 break; 425 break;
425 } 426 }
426 427
427 case content::NOTIFICATION_TAB_ADDED: 428 case content::NOTIFICATION_TAB_ADDED:
428 TabAdded(content::Details<WebContents>(details).ptr()); 429 TabAdded(content::Details<WebContents>(details).ptr());
429 break; 430 break;
430 431
431 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED: 432 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED:
432 TabDestroyed(content::Source<WebContents>(source).ptr()); 433 TabDestroyed(content::Source<WebContents>(source).ptr());
433 break; 434 break;
434 435
435 default: 436 default:
436 NOTREACHED(); 437 NOTREACHED();
437 } 438 }
438 } 439 }
439 440
440 void ExtensionWebNavigationEventRouter::Retargeting( 441 void WebNavigationEventRouter::Retargeting(const RetargetingDetails* details) {
441 const RetargetingDetails* details) {
442 if (details->source_frame_id == 0) 442 if (details->source_frame_id == 0)
443 return; 443 return;
444 ExtensionWebNavigationTabObserver* tab_observer = 444 WebNavigationTabObserver* tab_observer =
445 ExtensionWebNavigationTabObserver::Get(details->source_web_contents); 445 WebNavigationTabObserver::Get(details->source_web_contents);
446 if (!tab_observer) { 446 if (!tab_observer) {
447 // If you hit this DCHECK(), please add reproduction steps to 447 // If you hit this DCHECK(), please add reproduction steps to
448 // http://crbug.com/109464. 448 // http://crbug.com/109464.
449 DCHECK(details->source_web_contents->GetViewType() != 449 DCHECK(details->source_web_contents->GetViewType() !=
450 content::VIEW_TYPE_TAB_CONTENTS); 450 content::VIEW_TYPE_TAB_CONTENTS);
451 return; 451 return;
452 } 452 }
453 const FrameNavigationState& frame_navigation_state = 453 const FrameNavigationState& frame_navigation_state =
454 tab_observer->frame_navigation_state(); 454 tab_observer->frame_navigation_state();
455 455
(...skipping 18 matching lines...) Expand all
474 DispatchOnCreatedNavigationTarget( 474 DispatchOnCreatedNavigationTarget(
475 details->source_web_contents, 475 details->source_web_contents,
476 details->target_web_contents->GetBrowserContext(), 476 details->target_web_contents->GetBrowserContext(),
477 details->source_frame_id, 477 details->source_frame_id,
478 frame_navigation_state.IsMainFrame(details->source_frame_id), 478 frame_navigation_state.IsMainFrame(details->source_frame_id),
479 details->target_web_contents, 479 details->target_web_contents,
480 details->target_url); 480 details->target_url);
481 } 481 }
482 } 482 }
483 483
484 void ExtensionWebNavigationEventRouter::TabAdded(WebContents* tab) { 484 void WebNavigationEventRouter::TabAdded(WebContents* tab) {
485 std::map<WebContents*, PendingWebContents>::iterator iter = 485 std::map<WebContents*, PendingWebContents>::iterator iter =
486 pending_web_contents_.find(tab); 486 pending_web_contents_.find(tab);
487 if (iter == pending_web_contents_.end()) 487 if (iter == pending_web_contents_.end())
488 return; 488 return;
489 489
490 DispatchOnCreatedNavigationTarget( 490 DispatchOnCreatedNavigationTarget(
491 iter->second.source_web_contents, 491 iter->second.source_web_contents,
492 iter->second.target_web_contents->GetBrowserContext(), 492 iter->second.target_web_contents->GetBrowserContext(),
493 iter->second.source_frame_id, 493 iter->second.source_frame_id,
494 iter->second.source_frame_is_main_frame, 494 iter->second.source_frame_is_main_frame,
495 iter->second.target_web_contents, 495 iter->second.target_web_contents,
496 iter->second.target_url); 496 iter->second.target_url);
497 pending_web_contents_.erase(iter); 497 pending_web_contents_.erase(iter);
498 } 498 }
499 499
500 void ExtensionWebNavigationEventRouter::TabDestroyed(WebContents* tab) { 500 void WebNavigationEventRouter::TabDestroyed(WebContents* tab) {
501 pending_web_contents_.erase(tab); 501 pending_web_contents_.erase(tab);
502 for (std::map<WebContents*, PendingWebContents>::iterator i = 502 for (std::map<WebContents*, PendingWebContents>::iterator i =
503 pending_web_contents_.begin(); i != pending_web_contents_.end(); ) { 503 pending_web_contents_.begin(); i != pending_web_contents_.end(); ) {
504 if (i->second.source_web_contents == tab) 504 if (i->second.source_web_contents == tab)
505 pending_web_contents_.erase(i++); 505 pending_web_contents_.erase(i++);
506 else 506 else
507 ++i; 507 ++i;
508 } 508 }
509 } 509 }
510 510
511 // ExtensionWebNavigationTabObserver ------------------------------------------ 511 // WebNavigationTabObserver ------------------------------------------
512 512
513 ExtensionWebNavigationTabObserver::ExtensionWebNavigationTabObserver( 513 WebNavigationTabObserver::WebNavigationTabObserver(WebContents* web_contents)
514 WebContents* web_contents)
515 : WebContentsObserver(web_contents) { 514 : WebContentsObserver(web_contents) {
516 g_tab_observer.Get().insert(TabObserverMap::value_type(web_contents, this)); 515 g_tab_observer.Get().insert(TabObserverMap::value_type(web_contents, this));
517 registrar_.Add(this, 516 registrar_.Add(this,
518 content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT, 517 content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
519 content::Source<WebContents>(web_contents)); 518 content::Source<WebContents>(web_contents));
520 } 519 }
521 520
522 ExtensionWebNavigationTabObserver::~ExtensionWebNavigationTabObserver() {} 521 WebNavigationTabObserver::~WebNavigationTabObserver() {}
523 522
524 // static 523 // static
525 ExtensionWebNavigationTabObserver* ExtensionWebNavigationTabObserver::Get( 524 WebNavigationTabObserver* WebNavigationTabObserver::Get(
526 WebContents* web_contents) { 525 WebContents* web_contents) {
527 TabObserverMap::iterator i = g_tab_observer.Get().find(web_contents); 526 TabObserverMap::iterator i = g_tab_observer.Get().find(web_contents);
528 return i == g_tab_observer.Get().end() ? NULL : i->second; 527 return i == g_tab_observer.Get().end() ? NULL : i->second;
529 } 528 }
530 529
531 void ExtensionWebNavigationTabObserver::Observe( 530 void WebNavigationTabObserver::Observe(
532 int type, 531 int type,
533 const content::NotificationSource& source, 532 const content::NotificationSource& source,
534 const content::NotificationDetails& details) { 533 const content::NotificationDetails& details) {
535 switch (type) { 534 switch (type) {
536 case content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT: { 535 case content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT: {
537 ResourceRedirectDetails* resource_redirect_details = 536 ResourceRedirectDetails* resource_redirect_details =
538 content::Details<ResourceRedirectDetails>(details).ptr(); 537 content::Details<ResourceRedirectDetails>(details).ptr();
539 ResourceType::Type resource_type = 538 ResourceType::Type resource_type =
540 resource_redirect_details->resource_type; 539 resource_redirect_details->resource_type;
541 if (resource_type == ResourceType::MAIN_FRAME || 540 if (resource_type == ResourceType::MAIN_FRAME ||
542 resource_type == ResourceType::SUB_FRAME) { 541 resource_type == ResourceType::SUB_FRAME) {
543 int64 frame_id = resource_redirect_details->frame_id; 542 int64 frame_id = resource_redirect_details->frame_id;
544 if (!navigation_state_.CanSendEvents(frame_id)) 543 if (!navigation_state_.CanSendEvents(frame_id))
545 return; 544 return;
546 navigation_state_.SetIsServerRedirected(frame_id); 545 navigation_state_.SetIsServerRedirected(frame_id);
547 } 546 }
548 break; 547 break;
549 } 548 }
550 549
551 default: 550 default:
552 NOTREACHED(); 551 NOTREACHED();
553 } 552 }
554 } 553 }
555 554
556 void ExtensionWebNavigationTabObserver::DidStartProvisionalLoadForFrame( 555 void WebNavigationTabObserver::DidStartProvisionalLoadForFrame(
557 int64 frame_id, 556 int64 frame_id,
558 bool is_main_frame, 557 bool is_main_frame,
559 const GURL& validated_url, 558 const GURL& validated_url,
560 bool is_error_page, 559 bool is_error_page,
561 content::RenderViewHost* render_view_host) { 560 content::RenderViewHost* render_view_host) {
562 // Ignore navigations of sub frames, if the main frame isn't committed yet. 561 // Ignore navigations of sub frames, if the main frame isn't committed yet.
563 // This might happen if a sub frame triggers a navigation for both the main 562 // This might happen if a sub frame triggers a navigation for both the main
564 // frame and itself. Since the sub frame is about to be deleted, and there's 563 // frame and itself. Since the sub frame is about to be deleted, and there's
565 // no way for an extension to tell that these navigations belong to an old 564 // no way for an extension to tell that these navigations belong to an old
566 // frame, we just suppress the events here. 565 // frame, we just suppress the events here.
567 int64 main_frame_id = navigation_state_.GetMainFrameID(); 566 int64 main_frame_id = navigation_state_.GetMainFrameID();
568 if (!is_main_frame && 567 if (!is_main_frame &&
569 !navigation_state_.GetNavigationCommitted(main_frame_id)) { 568 !navigation_state_.GetNavigationCommitted(main_frame_id)) {
570 return; 569 return;
571 } 570 }
572 571
573 navigation_state_.TrackFrame(frame_id, 572 navigation_state_.TrackFrame(frame_id,
574 validated_url, 573 validated_url,
575 is_main_frame, 574 is_main_frame,
576 is_error_page); 575 is_error_page);
577 if (!navigation_state_.CanSendEvents(frame_id)) 576 if (!navigation_state_.CanSendEvents(frame_id))
578 return; 577 return;
579 DispatchOnBeforeNavigate( 578 DispatchOnBeforeNavigate(
580 web_contents(), frame_id, is_main_frame, validated_url); 579 web_contents(), frame_id, is_main_frame, validated_url);
581 } 580 }
582 581
583 void ExtensionWebNavigationTabObserver::DidCommitProvisionalLoadForFrame( 582 void WebNavigationTabObserver::DidCommitProvisionalLoadForFrame(
584 int64 frame_id, 583 int64 frame_id,
585 bool is_main_frame, 584 bool is_main_frame,
586 const GURL& url, 585 const GURL& url,
587 content::PageTransition transition_type) { 586 content::PageTransition transition_type) {
588 if (!navigation_state_.CanSendEvents(frame_id)) 587 if (!navigation_state_.CanSendEvents(frame_id))
589 return; 588 return;
590 589
591 bool is_reference_fragment_navigation = 590 bool is_reference_fragment_navigation =
592 IsReferenceFragmentNavigation(frame_id, url); 591 IsReferenceFragmentNavigation(frame_id, url);
593 592
(...skipping 18 matching lines...) Expand all
612 DispatchOnCommitted( 611 DispatchOnCommitted(
613 keys::kOnCommitted, 612 keys::kOnCommitted,
614 web_contents(), 613 web_contents(),
615 frame_id, 614 frame_id,
616 is_main_frame, 615 is_main_frame,
617 url, 616 url,
618 transition_type); 617 transition_type);
619 } 618 }
620 } 619 }
621 620
622 void ExtensionWebNavigationTabObserver::DidFailProvisionalLoad( 621 void WebNavigationTabObserver::DidFailProvisionalLoad(
623 int64 frame_id, 622 int64 frame_id,
624 bool is_main_frame, 623 bool is_main_frame,
625 const GURL& validated_url, 624 const GURL& validated_url,
626 int error_code, 625 int error_code,
627 const string16& error_description) { 626 const string16& error_description) {
628 if (!navigation_state_.CanSendEvents(frame_id)) 627 if (!navigation_state_.CanSendEvents(frame_id))
629 return; 628 return;
630 navigation_state_.SetErrorOccurredInFrame(frame_id); 629 navigation_state_.SetErrorOccurredInFrame(frame_id);
631 DispatchOnErrorOccurred( 630 DispatchOnErrorOccurred(
632 web_contents(), validated_url, frame_id, is_main_frame, error_code); 631 web_contents(), validated_url, frame_id, is_main_frame, error_code);
633 } 632 }
634 633
635 void ExtensionWebNavigationTabObserver::DocumentLoadedInFrame( 634 void WebNavigationTabObserver::DocumentLoadedInFrame(
636 int64 frame_id) { 635 int64 frame_id) {
637 if (!navigation_state_.CanSendEvents(frame_id)) 636 if (!navigation_state_.CanSendEvents(frame_id))
638 return; 637 return;
639 DispatchOnDOMContentLoaded(web_contents(), 638 DispatchOnDOMContentLoaded(web_contents(),
640 navigation_state_.GetUrl(frame_id), 639 navigation_state_.GetUrl(frame_id),
641 navigation_state_.IsMainFrame(frame_id), 640 navigation_state_.IsMainFrame(frame_id),
642 frame_id); 641 frame_id);
643 } 642 }
644 643
645 void ExtensionWebNavigationTabObserver::DidFinishLoad( 644 void WebNavigationTabObserver::DidFinishLoad(
646 int64 frame_id, 645 int64 frame_id,
647 const GURL& validated_url, 646 const GURL& validated_url,
648 bool is_main_frame) { 647 bool is_main_frame) {
649 if (!navigation_state_.CanSendEvents(frame_id)) 648 if (!navigation_state_.CanSendEvents(frame_id))
650 return; 649 return;
651 navigation_state_.SetNavigationCompleted(frame_id); 650 navigation_state_.SetNavigationCompleted(frame_id);
652 DCHECK_EQ(navigation_state_.GetUrl(frame_id), validated_url); 651 DCHECK_EQ(navigation_state_.GetUrl(frame_id), validated_url);
653 DCHECK_EQ(navigation_state_.IsMainFrame(frame_id), is_main_frame); 652 DCHECK_EQ(navigation_state_.IsMainFrame(frame_id), is_main_frame);
654 DispatchOnCompleted(web_contents(), 653 DispatchOnCompleted(web_contents(),
655 validated_url, 654 validated_url,
656 is_main_frame, 655 is_main_frame,
657 frame_id); 656 frame_id);
658 } 657 }
659 658
660 void ExtensionWebNavigationTabObserver::DidOpenRequestedURL( 659 void WebNavigationTabObserver::DidOpenRequestedURL(
661 WebContents* new_contents, 660 WebContents* new_contents,
662 const GURL& url, 661 const GURL& url,
663 const content::Referrer& referrer, 662 const content::Referrer& referrer,
664 WindowOpenDisposition disposition, 663 WindowOpenDisposition disposition,
665 content::PageTransition transition, 664 content::PageTransition transition,
666 int64 source_frame_id) { 665 int64 source_frame_id) {
667 if (!navigation_state_.CanSendEvents(source_frame_id)) 666 if (!navigation_state_.CanSendEvents(source_frame_id))
668 return; 667 return;
669 668
670 // We only send the onCreatedNavigationTarget if we end up creating a new 669 // We only send the onCreatedNavigationTarget if we end up creating a new
671 // window. 670 // window.
672 if (disposition != SINGLETON_TAB && 671 if (disposition != SINGLETON_TAB &&
673 disposition != NEW_FOREGROUND_TAB && 672 disposition != NEW_FOREGROUND_TAB &&
674 disposition != NEW_BACKGROUND_TAB && 673 disposition != NEW_BACKGROUND_TAB &&
675 disposition != NEW_POPUP && 674 disposition != NEW_POPUP &&
676 disposition != NEW_WINDOW && 675 disposition != NEW_WINDOW &&
677 disposition != OFF_THE_RECORD) 676 disposition != OFF_THE_RECORD)
678 return; 677 return;
679 678
680 DispatchOnCreatedNavigationTarget( 679 DispatchOnCreatedNavigationTarget(
681 web_contents(), 680 web_contents(),
682 new_contents->GetBrowserContext(), 681 new_contents->GetBrowserContext(),
683 source_frame_id, 682 source_frame_id,
684 navigation_state_.IsMainFrame(source_frame_id), 683 navigation_state_.IsMainFrame(source_frame_id),
685 new_contents, 684 new_contents,
686 url); 685 url);
687 } 686 }
688 687
689 void ExtensionWebNavigationTabObserver::WebContentsDestroyed(WebContents* tab) { 688 void WebNavigationTabObserver::WebContentsDestroyed(WebContents* tab) {
690 g_tab_observer.Get().erase(tab); 689 g_tab_observer.Get().erase(tab);
691 for (FrameNavigationState::const_iterator frame = navigation_state_.begin(); 690 for (FrameNavigationState::const_iterator frame = navigation_state_.begin();
692 frame != navigation_state_.end(); ++frame) { 691 frame != navigation_state_.end(); ++frame) {
693 if (!navigation_state_.GetNavigationCompleted(*frame) && 692 if (!navigation_state_.GetNavigationCompleted(*frame) &&
694 navigation_state_.CanSendEvents(*frame)) { 693 navigation_state_.CanSendEvents(*frame)) {
695 DispatchOnErrorOccurred( 694 DispatchOnErrorOccurred(
696 tab, 695 tab,
697 navigation_state_.GetUrl(*frame), 696 navigation_state_.GetUrl(*frame),
698 *frame, 697 *frame,
699 navigation_state_.IsMainFrame(*frame), 698 navigation_state_.IsMainFrame(*frame),
700 net::ERR_ABORTED); 699 net::ERR_ABORTED);
701 } 700 }
702 } 701 }
703 } 702 }
704 703
705 // See also NavigationController::IsURLInPageNavigation. 704 // See also NavigationController::IsURLInPageNavigation.
706 bool ExtensionWebNavigationTabObserver::IsReferenceFragmentNavigation( 705 bool WebNavigationTabObserver::IsReferenceFragmentNavigation(
707 int64 frame_id, 706 int64 frame_id,
708 const GURL& url) { 707 const GURL& url) {
709 GURL existing_url = navigation_state_.GetUrl(frame_id); 708 GURL existing_url = navigation_state_.GetUrl(frame_id);
710 if (existing_url == url) 709 if (existing_url == url)
711 return false; 710 return false;
712 711
713 url_canon::Replacements<char> replacements; 712 url_canon::Replacements<char> replacements;
714 replacements.ClearRef(); 713 replacements.ClearRef();
715 return existing_url.ReplaceComponents(replacements) == 714 return existing_url.ReplaceComponents(replacements) ==
716 url.ReplaceComponents(replacements); 715 url.ReplaceComponents(replacements);
(...skipping 13 matching lines...) Expand all
730 result_.reset(Value::CreateNullValue()); 729 result_.reset(Value::CreateNullValue());
731 730
732 TabContentsWrapper* wrapper; 731 TabContentsWrapper* wrapper;
733 if (!ExtensionTabUtil::GetTabById( 732 if (!ExtensionTabUtil::GetTabById(
734 tab_id, profile(), include_incognito(), NULL, NULL, &wrapper, NULL) || 733 tab_id, profile(), include_incognito(), NULL, NULL, &wrapper, NULL) ||
735 !wrapper) { 734 !wrapper) {
736 return true; 735 return true;
737 } 736 }
738 737
739 WebContents* web_contents = wrapper->web_contents(); 738 WebContents* web_contents = wrapper->web_contents();
740 ExtensionWebNavigationTabObserver* observer = 739 WebNavigationTabObserver* observer =
741 ExtensionWebNavigationTabObserver::Get(web_contents); 740 WebNavigationTabObserver::Get(web_contents);
742 DCHECK(observer); 741 DCHECK(observer);
743 742
744 const FrameNavigationState& frame_navigation_state = 743 const FrameNavigationState& frame_navigation_state =
745 observer->frame_navigation_state(); 744 observer->frame_navigation_state();
746 745
747 if (frame_id == 0) 746 if (frame_id == 0)
748 frame_id = frame_navigation_state.GetMainFrameID(); 747 frame_id = frame_navigation_state.GetMainFrameID();
749 if (!frame_navigation_state.IsValidFrame(frame_id)) 748 if (!frame_navigation_state.IsValidFrame(frame_id))
750 return true; 749 return true;
751 750
(...skipping 21 matching lines...) Expand all
773 result_.reset(Value::CreateNullValue()); 772 result_.reset(Value::CreateNullValue());
774 773
775 TabContentsWrapper* wrapper; 774 TabContentsWrapper* wrapper;
776 if (!ExtensionTabUtil::GetTabById( 775 if (!ExtensionTabUtil::GetTabById(
777 tab_id, profile(), include_incognito(), NULL, NULL, &wrapper, NULL) || 776 tab_id, profile(), include_incognito(), NULL, NULL, &wrapper, NULL) ||
778 !wrapper) { 777 !wrapper) {
779 return true; 778 return true;
780 } 779 }
781 780
782 WebContents* web_contents = wrapper->web_contents(); 781 WebContents* web_contents = wrapper->web_contents();
783 ExtensionWebNavigationTabObserver* observer = 782 WebNavigationTabObserver* observer =
784 ExtensionWebNavigationTabObserver::Get(web_contents); 783 WebNavigationTabObserver::Get(web_contents);
785 DCHECK(observer); 784 DCHECK(observer);
786 785
787 const FrameNavigationState& navigation_state = 786 const FrameNavigationState& navigation_state =
788 observer->frame_navigation_state(); 787 observer->frame_navigation_state();
789 788
790 ListValue* resultList = new ListValue(); 789 ListValue* resultList = new ListValue();
791 for (FrameNavigationState::const_iterator frame = navigation_state.begin(); 790 for (FrameNavigationState::const_iterator frame = navigation_state.begin();
792 frame != navigation_state.end(); ++frame) { 791 frame != navigation_state.end(); ++frame) {
793 GURL frame_url = navigation_state.GetUrl(*frame); 792 GURL frame_url = navigation_state.GetUrl(*frame);
794 if (!navigation_state.IsValidUrl(frame_url)) 793 if (!navigation_state.IsValidUrl(frame_url))
795 continue; 794 continue;
796 DictionaryValue* frameDict = new DictionaryValue(); 795 DictionaryValue* frameDict = new DictionaryValue();
797 frameDict->SetString(keys::kUrlKey, frame_url.spec()); 796 frameDict->SetString(keys::kUrlKey, frame_url.spec());
798 frameDict->SetInteger( 797 frameDict->SetInteger(
799 keys::kFrameIdKey, 798 keys::kFrameIdKey,
800 GetFrameId(navigation_state.IsMainFrame(*frame), *frame)); 799 GetFrameId(navigation_state.IsMainFrame(*frame), *frame));
801 frameDict->SetBoolean( 800 frameDict->SetBoolean(
802 keys::kErrorOccurredKey, 801 keys::kErrorOccurredKey,
803 navigation_state.GetErrorOccurredInFrame(*frame)); 802 navigation_state.GetErrorOccurredInFrame(*frame));
804 resultList->Append(frameDict); 803 resultList->Append(frameDict);
805 } 804 }
806 result_.reset(resultList); 805 result_.reset(resultList);
807 return true; 806 return true;
808 } 807 }
808
809 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698