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/google/google_url_tracker.h" | 7 #include "chrome/browser/google/google_url_tracker.h" |
8 #include "chrome/browser/infobars/infobar_service.h" | 8 #include "chrome/browser/infobars/infobar_service.h" |
9 #include "chrome/common/chrome_notification_types.h" | 9 #include "chrome/common/chrome_notification_types.h" |
10 #include "content/public/browser/navigation_controller.h" | 10 #include "content/public/browser/navigation_controller.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 GoogleURLTracker* tracker) { | 24 GoogleURLTracker* tracker) { |
25 DCHECK(tracker); | 25 DCHECK(tracker); |
26 tracker_ = tracker; | 26 tracker_ = tracker; |
27 } | 27 } |
28 | 28 |
29 void GoogleURLTrackerNavigationHelperImpl::SetListeningForNavigationStart( | 29 void GoogleURLTrackerNavigationHelperImpl::SetListeningForNavigationStart( |
30 bool listen) { | 30 bool listen) { |
31 if (listen) { | 31 if (listen) { |
32 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_PENDING, | 32 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_PENDING, |
33 content::NotificationService::AllBrowserContextsAndSources()); | 33 content::NotificationService::AllBrowserContextsAndSources()); |
34 registrar_.Add(this, chrome::NOTIFICATION_INSTANT_COMMITTED, | |
35 content::NotificationService::AllBrowserContextsAndSources()); | |
36 } else { | 34 } else { |
37 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_PENDING, | 35 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_PENDING, |
38 content::NotificationService::AllBrowserContextsAndSources()); | 36 content::NotificationService::AllBrowserContextsAndSources()); |
39 registrar_.Remove(this, chrome::NOTIFICATION_INSTANT_COMMITTED, | |
40 content::NotificationService::AllBrowserContextsAndSources()); | |
41 } | 37 } |
42 } | 38 } |
43 | 39 |
44 bool GoogleURLTrackerNavigationHelperImpl::IsListeningForNavigationStart() { | 40 bool GoogleURLTrackerNavigationHelperImpl::IsListeningForNavigationStart() { |
45 return registrar_.IsRegistered(this, content::NOTIFICATION_NAV_ENTRY_PENDING, | 41 return registrar_.IsRegistered(this, content::NOTIFICATION_NAV_ENTRY_PENDING, |
46 content::NotificationService::AllBrowserContextsAndSources()); | 42 content::NotificationService::AllBrowserContextsAndSources()); |
47 } | 43 } |
48 | 44 |
49 void GoogleURLTrackerNavigationHelperImpl::SetListeningForNavigationCommit( | 45 void GoogleURLTrackerNavigationHelperImpl::SetListeningForNavigationCommit( |
50 const content::NavigationController* nav_controller, | 46 const content::NavigationController* nav_controller, |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 break; | 137 break; |
142 } | 138 } |
143 | 139 |
144 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED: { | 140 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED: { |
145 content::WebContents* web_contents = | 141 content::WebContents* web_contents = |
146 content::Source<content::WebContents>(source).ptr(); | 142 content::Source<content::WebContents>(source).ptr(); |
147 tracker_->OnTabClosed(&web_contents->GetController()); | 143 tracker_->OnTabClosed(&web_contents->GetController()); |
148 break; | 144 break; |
149 } | 145 } |
150 | 146 |
151 case chrome::NOTIFICATION_INSTANT_COMMITTED: { | |
152 content::WebContents* web_contents = | |
153 content::Source<content::WebContents>(source).ptr(); | |
154 content::NavigationController* nav_controller = | |
155 &web_contents->GetController(); | |
156 const GURL& search_url = web_contents->GetURL(); | |
157 if (!search_url.is_valid()) // Not clear if this can happen. | |
158 tracker_->OnTabClosed(nav_controller); | |
159 OnInstantCommitted(nav_controller, | |
160 InfoBarService::FromWebContents(web_contents), | |
161 search_url); | |
162 break; | |
163 } | |
164 | |
165 default: | 147 default: |
166 NOTREACHED() << "Unknown notification received:" << type; | 148 NOTREACHED() << "Unknown notification received:" << type; |
167 } | 149 } |
168 } | 150 } |
169 | |
170 void GoogleURLTrackerNavigationHelperImpl::OnInstantCommitted( | |
171 content::NavigationController* nav_controller, | |
172 InfoBarService* infobar_service, | |
173 const GURL& search_url) { | |
174 // Call OnNavigationPending, giving |tracker_| the option to register for | |
175 // navigation commit messages for this navigation controller. If it does | |
176 // register for them, simulate the commit as well. | |
177 tracker_->OnNavigationPending(nav_controller, infobar_service, 0); | |
178 if (IsListeningForNavigationCommit(nav_controller)) | |
179 tracker_->OnNavigationCommitted(infobar_service, search_url); | |
180 } | |
OLD | NEW |