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:: | |
16 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.
| |
17 } | |
18 | |
19 ChromeGoogleURLTrackerClient:: | |
20 ~ChromeGoogleURLTrackerClient() { | |
Peter Kasting
2014/05/14 23:30:28
Nit: Linebreak not necessary
blundell
2014/05/15 07:58:03
Done.
| |
21 } | |
22 | |
23 void ChromeGoogleURLTrackerClient::SetGoogleURLTracker( | |
24 GoogleURLTracker* tracker) { | |
25 DCHECK(tracker); | |
26 tracker_ = tracker; | |
27 } | |
28 | |
29 void ChromeGoogleURLTrackerClient::SetListeningForNavigationStart( | |
30 bool listen) { | |
31 if (listen) { | |
32 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_PENDING, | |
33 content::NotificationService::AllBrowserContextsAndSources()); | |
34 } else { | |
35 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_PENDING, | |
36 content::NotificationService::AllBrowserContextsAndSources()); | |
37 } | |
38 } | |
39 | |
40 bool ChromeGoogleURLTrackerClient::IsListeningForNavigationStart() { | |
41 return registrar_.IsRegistered(this, content::NOTIFICATION_NAV_ENTRY_PENDING, | |
42 content::NotificationService::AllBrowserContextsAndSources()); | |
43 } | |
44 | |
45 void ChromeGoogleURLTrackerClient::Observe( | |
46 int type, | |
47 const content::NotificationSource& source, | |
48 const content::NotificationDetails& details) { | |
49 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.
| |
50 case content::NOTIFICATION_NAV_ENTRY_PENDING: { | |
51 content::NavigationController* controller = | |
52 content::Source<content::NavigationController>(source).ptr(); | |
53 content::WebContents* web_contents = controller->GetWebContents(); | |
54 InfoBarService* infobar_service = | |
55 InfoBarService::FromWebContents(web_contents); | |
56 // Because we're listening to all sources, there may be no | |
57 // InfoBarService for some notifications, e.g. navigations in | |
58 // bubbles/balloons etc. | |
59 if (infobar_service) { | |
60 tracker_->OnNavigationPending( | |
61 controller, infobar_service, | |
62 controller->GetPendingEntry()->GetUniqueID()); | |
63 } | |
64 break; | |
65 } | |
66 | |
67 default: | |
68 NOTREACHED() << "Unknown notification received:" << type; | |
69 } | |
70 } | |
OLD | NEW |