OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/google/chrome_google_url_tracker_client.h" |
| 6 |
| 7 #include "chrome/browser/chrome_notification_types.h" |
| 8 #include "chrome/browser/google/google_url_tracker.h" |
| 9 #include "chrome/browser/infobars/infobar_service.h" |
| 10 #include "content/public/browser/navigation_controller.h" |
| 11 #include "content/public/browser/navigation_entry.h" |
| 12 #include "content/public/browser/notification_service.h" |
| 13 #include "content/public/browser/web_contents.h" |
| 14 |
| 15 ChromeGoogleURLTrackerClient::ChromeGoogleURLTrackerClient() { |
| 16 } |
| 17 |
| 18 ChromeGoogleURLTrackerClient::~ChromeGoogleURLTrackerClient() { |
| 19 } |
| 20 |
| 21 void ChromeGoogleURLTrackerClient::SetListeningForNavigationStart( |
| 22 bool listen) { |
| 23 if (listen) { |
| 24 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_PENDING, |
| 25 content::NotificationService::AllBrowserContextsAndSources()); |
| 26 } else { |
| 27 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_PENDING, |
| 28 content::NotificationService::AllBrowserContextsAndSources()); |
| 29 } |
| 30 } |
| 31 |
| 32 bool ChromeGoogleURLTrackerClient::IsListeningForNavigationStart() { |
| 33 return registrar_.IsRegistered(this, content::NOTIFICATION_NAV_ENTRY_PENDING, |
| 34 content::NotificationService::AllBrowserContextsAndSources()); |
| 35 } |
| 36 |
| 37 void ChromeGoogleURLTrackerClient::Observe( |
| 38 int type, |
| 39 const content::NotificationSource& source, |
| 40 const content::NotificationDetails& details) { |
| 41 DCHECK_EQ(content::NOTIFICATION_NAV_ENTRY_PENDING, type); |
| 42 content::NavigationController* controller = |
| 43 content::Source<content::NavigationController>(source).ptr(); |
| 44 InfoBarService* infobar_service = |
| 45 InfoBarService::FromWebContents(controller->GetWebContents()); |
| 46 // Because we're listening to all sources, there may be no |
| 47 // InfoBarService for some notifications, e.g. navigations in |
| 48 // bubbles/balloons etc. |
| 49 if (infobar_service) { |
| 50 google_url_tracker()->OnNavigationPending( |
| 51 controller, |
| 52 infobar_service, |
| 53 controller->GetPendingEntry()->GetUniqueID()); |
| 54 } |
| 55 } |
OLD | NEW |