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.
5 #include "chrome/browser/google/chrome_google_url_tracker_client.h"
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"
15 ChromeGoogleURLTrackerClient::ChromeGoogleURLTrackerClient() {
18 ChromeGoogleURLTrackerClient::~ChromeGoogleURLTrackerClient() {
21 void ChromeGoogleURLTrackerClient::SetListeningForNavigationStart(bool listen
) {
25 content::NOTIFICATION_NAV_ENTRY_PENDING
,
26 content::NotificationService::AllBrowserContextsAndSources());
30 content::NOTIFICATION_NAV_ENTRY_PENDING
,
31 content::NotificationService::AllBrowserContextsAndSources());
35 bool ChromeGoogleURLTrackerClient::IsListeningForNavigationStart() {
36 return registrar_
.IsRegistered(
38 content::NOTIFICATION_NAV_ENTRY_PENDING
,
39 content::NotificationService::AllBrowserContextsAndSources());
42 void ChromeGoogleURLTrackerClient::Observe(
44 const content::NotificationSource
& source
,
45 const content::NotificationDetails
& details
) {
46 DCHECK_EQ(content::NOTIFICATION_NAV_ENTRY_PENDING
, type
);
47 content::NavigationController
* controller
=
48 content::Source
<content::NavigationController
>(source
).ptr();
49 InfoBarService
* infobar_service
=
50 InfoBarService::FromWebContents(controller
->GetWebContents());
51 // Because we're listening to all sources, there may be no
52 // InfoBarService for some notifications, e.g. navigations in
53 // bubbles/balloons etc.
54 if (infobar_service
) {
55 google_url_tracker()->OnNavigationPending(
58 controller
->GetPendingEntry()->GetUniqueID());