Chromium Code Reviews| 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 #include "chrome/browser/google/google_url_tracker_navigation_helper_impl.h" | 5 #include "chrome/browser/google/google_url_tracker_navigation_helper_impl.h" |
| 6 | 6 |
| 7 #include "chrome/browser/chrome_notification_types.h" | 7 #include "chrome/browser/chrome_notification_types.h" |
| 8 #include "chrome/browser/google/google_url_tracker.h" | 8 #include "chrome/browser/google/google_url_tracker.h" |
| 9 #include "chrome/browser/infobars/infobar_service.h" | 9 #include "chrome/browser/infobars/infobar_service.h" |
| 10 #include "content/public/browser/navigation_controller.h" | 10 #include "content/public/browser/navigation_controller.h" |
| 11 #include "content/public/browser/navigation_entry.h" | 11 #include "content/public/browser/navigation_entry.h" |
| 12 #include "content/public/browser/notification_service.h" | 12 #include "content/public/browser/notification_service.h" |
| 13 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
| 14 | 14 |
| 15 GoogleURLTrackerNavigationHelperImpl:: | 15 GoogleURLTrackerNavigationHelperImpl::GoogleURLTrackerNavigationHelperImpl( |
| 16 GoogleURLTrackerNavigationHelperImpl() : tracker_(NULL) { | 16 content::WebContents* web_contents, |
| 17 GoogleURLTracker* tracker) | |
| 18 : GoogleURLTrackerNavigationHelper(tracker), | |
| 19 web_contents_(web_contents) { | |
| 17 } | 20 } |
| 18 | 21 |
| 19 GoogleURLTrackerNavigationHelperImpl:: | 22 GoogleURLTrackerNavigationHelperImpl::~GoogleURLTrackerNavigationHelperImpl() { |
| 20 ~GoogleURLTrackerNavigationHelperImpl() { | |
| 21 } | |
| 22 | |
| 23 void GoogleURLTrackerNavigationHelperImpl::SetGoogleURLTracker( | |
| 24 GoogleURLTracker* tracker) { | |
| 25 DCHECK(tracker); | |
| 26 tracker_ = tracker; | |
| 27 } | 23 } |
| 28 | 24 |
| 29 void GoogleURLTrackerNavigationHelperImpl::SetListeningForNavigationCommit( | 25 void GoogleURLTrackerNavigationHelperImpl::SetListeningForNavigationCommit( |
| 30 const content::NavigationController* nav_controller, | |
| 31 bool listen) { | 26 bool listen) { |
| 32 content::NotificationSource navigation_controller_source = | 27 content::NotificationSource navigation_controller_source = |
| 33 content::Source<content::NavigationController>(nav_controller); | 28 content::Source<content::NavigationController>( |
| 29 &web_contents_->GetController()); | |
| 34 if (listen) { | 30 if (listen) { |
| 35 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 31 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 36 navigation_controller_source); | 32 navigation_controller_source); |
| 37 } else { | 33 } else { |
| 38 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 34 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 39 navigation_controller_source); | 35 navigation_controller_source); |
| 40 } | 36 } |
| 41 } | 37 } |
| 42 | 38 |
| 43 bool GoogleURLTrackerNavigationHelperImpl::IsListeningForNavigationCommit( | 39 bool GoogleURLTrackerNavigationHelperImpl::IsListeningForNavigationCommit() { |
| 44 const content::NavigationController* nav_controller) { | |
| 45 content::NotificationSource navigation_controller_source = | 40 content::NotificationSource navigation_controller_source = |
| 46 content::Source<content::NavigationController>(nav_controller); | 41 content::Source<content::NavigationController>( |
| 42 &web_contents_->GetController()); | |
| 47 return registrar_.IsRegistered( | 43 return registrar_.IsRegistered( |
| 48 this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 44 this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 49 navigation_controller_source); | 45 navigation_controller_source); |
| 50 } | 46 } |
| 51 | 47 |
| 52 void GoogleURLTrackerNavigationHelperImpl::SetListeningForTabDestruction( | 48 void GoogleURLTrackerNavigationHelperImpl::SetListeningForTabDestruction( |
| 53 const content::NavigationController* nav_controller, | |
| 54 bool listen) { | 49 bool listen) { |
| 55 content::NotificationSource navigation_controller_source = | 50 content::NotificationSource web_contents_source = |
| 56 content::Source<content::NavigationController>(nav_controller); | 51 content::Source<content::WebContents>(web_contents_); |
| 57 if (listen) { | 52 if (listen) { |
| 58 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 53 registrar_.Add(this, |
| 59 GetWebContentsSource(navigation_controller_source)); | 54 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 55 web_contents_source); | |
| 60 } else { | 56 } else { |
| 61 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 57 registrar_.Remove(this, |
| 62 GetWebContentsSource(navigation_controller_source)); | 58 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 59 web_contents_source); | |
| 63 } | 60 } |
| 64 } | 61 } |
| 65 | 62 |
| 66 bool GoogleURLTrackerNavigationHelperImpl::IsListeningForTabDestruction( | 63 bool GoogleURLTrackerNavigationHelperImpl::IsListeningForTabDestruction() { |
| 67 const content::NavigationController* nav_controller) { | |
| 68 content::NotificationSource navigation_controller_source = | |
| 69 content::Source<content::NavigationController>(nav_controller); | |
| 70 return registrar_.IsRegistered( | 64 return registrar_.IsRegistered( |
| 71 this, | 65 this, |
| 72 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 66 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 73 GetWebContentsSource(navigation_controller_source)); | 67 content::Source<content::WebContents>(web_contents_)); |
| 74 } | |
| 75 | |
| 76 content::NotificationSource | |
| 77 GoogleURLTrackerNavigationHelperImpl::GetWebContentsSource( | |
| 78 const content::NotificationSource& nav_controller_source) { | |
| 79 content::NavigationController* controller = | |
| 80 content::Source<content::NavigationController>( | |
| 81 nav_controller_source).ptr(); | |
| 82 content::WebContents* web_contents = controller->GetWebContents(); | |
| 83 return content::Source<content::WebContents>(web_contents); | |
| 84 } | 68 } |
| 85 | 69 |
| 86 void GoogleURLTrackerNavigationHelperImpl::Observe( | 70 void GoogleURLTrackerNavigationHelperImpl::Observe( |
| 87 int type, | 71 int type, |
| 88 const content::NotificationSource& source, | 72 const content::NotificationSource& source, |
| 89 const content::NotificationDetails& details) { | 73 const content::NotificationDetails& details) { |
| 90 switch (type) { | 74 switch (type) { |
| 91 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: { | 75 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: { |
| 92 content::NavigationController* controller = | 76 content::NavigationController* controller = |
| 93 content::Source<content::NavigationController>(source).ptr(); | 77 content::Source<content::NavigationController>(source).ptr(); |
| 78 DCHECK_EQ(controller->GetWebContents(), web_contents_); | |
|
Peter Kasting
2014/05/16 23:38:13
Nit: (expected, actual) (2 places)
blundell
2014/05/17 19:23:54
Done.
| |
| 79 | |
| 94 // Here we're only listening to notifications where we already know | 80 // Here we're only listening to notifications where we already know |
| 95 // there's an associated InfoBarService. | 81 // there's an associated InfoBarService. |
| 96 content::WebContents* web_contents = controller->GetWebContents(); | |
| 97 InfoBarService* infobar_service = | 82 InfoBarService* infobar_service = |
| 98 InfoBarService::FromWebContents(web_contents); | 83 InfoBarService::FromWebContents(web_contents_); |
| 99 DCHECK(infobar_service); | 84 DCHECK(infobar_service); |
| 100 const GURL& search_url = controller->GetActiveEntry()->GetURL(); | 85 const GURL& search_url = controller->GetActiveEntry()->GetURL(); |
| 101 if (!search_url.is_valid()) // Not clear if this can happen. | 86 if (!search_url.is_valid()) // Not clear if this can happen. |
| 102 tracker_->OnTabClosed(controller); | 87 google_url_tracker()->OnTabClosed(this); |
| 103 tracker_->OnNavigationCommitted(infobar_service, search_url); | 88 google_url_tracker()->OnNavigationCommitted(infobar_service, search_url); |
| 104 break; | 89 break; |
| 105 } | 90 } |
| 106 | 91 |
| 107 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED: { | 92 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED: { |
| 108 content::WebContents* web_contents = | 93 DCHECK_EQ(content::Source<content::WebContents>(source).ptr(), |
| 109 content::Source<content::WebContents>(source).ptr(); | 94 web_contents_); |
| 110 tracker_->OnTabClosed(&web_contents->GetController()); | 95 google_url_tracker()->OnTabClosed(this); |
| 111 break; | 96 break; |
| 112 } | 97 } |
| 113 | 98 |
| 114 default: | 99 default: |
| 115 NOTREACHED() << "Unknown notification received:" << type; | 100 NOTREACHED() << "Unknown notification received:" << type; |
| 116 } | 101 } |
| 117 } | 102 } |
| OLD | NEW |