Index: chrome/browser/google/chrome_google_url_tracker_client.cc |
diff --git a/chrome/browser/google/chrome_google_url_tracker_client.cc b/chrome/browser/google/chrome_google_url_tracker_client.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..62da4f9faec2d4c3dfaac3762f24eaf7946b3328 |
--- /dev/null |
+++ b/chrome/browser/google/chrome_google_url_tracker_client.cc |
@@ -0,0 +1,70 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/google/chrome_google_url_tracker_client.h" |
+ |
+#include "chrome/browser/chrome_notification_types.h" |
+#include "chrome/browser/google/google_url_tracker.h" |
+#include "chrome/browser/infobars/infobar_service.h" |
+#include "content/public/browser/navigation_controller.h" |
+#include "content/public/browser/navigation_entry.h" |
+#include "content/public/browser/notification_service.h" |
+#include "content/public/browser/web_contents.h" |
+ |
+ChromeGoogleURLTrackerClient:: |
+ ChromeGoogleURLTrackerClient() : tracker_(NULL) { |
Peter Kasting
2014/05/14 23:30:28
Nit: Linebreak not necessary (everything will fit
blundell
2014/05/15 07:58:03
Done.
|
+} |
+ |
+ChromeGoogleURLTrackerClient:: |
+ ~ChromeGoogleURLTrackerClient() { |
Peter Kasting
2014/05/14 23:30:28
Nit: Linebreak not necessary
blundell
2014/05/15 07:58:03
Done.
|
+} |
+ |
+void ChromeGoogleURLTrackerClient::SetGoogleURLTracker( |
+ GoogleURLTracker* tracker) { |
+ DCHECK(tracker); |
+ tracker_ = tracker; |
+} |
+ |
+void ChromeGoogleURLTrackerClient::SetListeningForNavigationStart( |
+ bool listen) { |
+ if (listen) { |
+ registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_PENDING, |
+ content::NotificationService::AllBrowserContextsAndSources()); |
+ } else { |
+ registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_PENDING, |
+ content::NotificationService::AllBrowserContextsAndSources()); |
+ } |
+} |
+ |
+bool ChromeGoogleURLTrackerClient::IsListeningForNavigationStart() { |
+ return registrar_.IsRegistered(this, content::NOTIFICATION_NAV_ENTRY_PENDING, |
+ content::NotificationService::AllBrowserContextsAndSources()); |
+} |
+ |
+void ChromeGoogleURLTrackerClient::Observe( |
+ int type, |
+ const content::NotificationSource& source, |
+ const content::NotificationDetails& details) { |
+ switch (type) { |
Peter Kasting
2014/05/14 23:30:28
Nit: Simpler:
DCHECK_EQ(content::NOTIFICATION_N
blundell
2014/05/15 07:58:03
Done.
|
+ case content::NOTIFICATION_NAV_ENTRY_PENDING: { |
+ content::NavigationController* controller = |
+ content::Source<content::NavigationController>(source).ptr(); |
+ content::WebContents* web_contents = controller->GetWebContents(); |
+ InfoBarService* infobar_service = |
+ InfoBarService::FromWebContents(web_contents); |
+ // Because we're listening to all sources, there may be no |
+ // InfoBarService for some notifications, e.g. navigations in |
+ // bubbles/balloons etc. |
+ if (infobar_service) { |
+ tracker_->OnNavigationPending( |
+ controller, infobar_service, |
+ controller->GetPendingEntry()->GetUniqueID()); |
+ } |
+ break; |
+ } |
+ |
+ default: |
+ NOTREACHED() << "Unknown notification received:" << type; |
+ } |
+} |