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/chrome_notification_types.h" | 7 #include "chrome/browser/chrome_notification_types.h" |
8 #include "chrome/browser/google/google_url_tracker.h" | 8 #include "chrome/browser/google/google_url_tracker.h" |
9 #include "chrome/browser/infobars/infobar_service.h" | 9 #include "chrome/browser/infobars/infobar_service.h" |
10 #include "content/public/browser/navigation_controller.h" | 10 #include "content/public/browser/navigation_controller.h" |
11 #include "content/public/browser/navigation_entry.h" | 11 #include "content/public/browser/navigation_entry.h" |
12 #include "content/public/browser/notification_service.h" | 12 #include "content/public/browser/notification_service.h" |
13 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
14 | 14 |
15 GoogleURLTrackerNavigationHelperImpl::GoogleURLTrackerNavigationHelperImpl( | 15 GoogleURLTrackerNavigationHelperImpl::GoogleURLTrackerNavigationHelperImpl( |
16 content::WebContents* web_contents, | 16 content::WebContents* web_contents, |
17 GoogleURLTracker* tracker) | 17 GoogleURLTracker* tracker) |
18 : GoogleURLTrackerNavigationHelper(tracker), | 18 : GoogleURLTrackerNavigationHelper(tracker), |
19 web_contents_(web_contents) { | 19 web_contents_(web_contents) { |
20 } | 20 } |
21 | 21 |
22 GoogleURLTrackerNavigationHelperImpl::~GoogleURLTrackerNavigationHelperImpl() { | 22 GoogleURLTrackerNavigationHelperImpl::~GoogleURLTrackerNavigationHelperImpl() { |
| 23 web_contents_ = NULL; |
23 } | 24 } |
24 | 25 |
25 void GoogleURLTrackerNavigationHelperImpl::SetListeningForNavigationCommit( | 26 void GoogleURLTrackerNavigationHelperImpl::SetListeningForNavigationCommit( |
26 bool listen) { | 27 bool listen) { |
27 content::NotificationSource navigation_controller_source = | 28 content::NotificationSource navigation_controller_source = |
28 content::Source<content::NavigationController>( | 29 content::Source<content::NavigationController>( |
29 &web_contents_->GetController()); | 30 &web_contents_->GetController()); |
30 if (listen) { | 31 if (listen) { |
31 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 32 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
32 navigation_controller_source); | 33 navigation_controller_source); |
(...skipping 27 matching lines...) Expand all Loading... |
60 } | 61 } |
61 } | 62 } |
62 | 63 |
63 bool GoogleURLTrackerNavigationHelperImpl::IsListeningForTabDestruction() { | 64 bool GoogleURLTrackerNavigationHelperImpl::IsListeningForTabDestruction() { |
64 return registrar_.IsRegistered( | 65 return registrar_.IsRegistered( |
65 this, | 66 this, |
66 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 67 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
67 content::Source<content::WebContents>(web_contents_)); | 68 content::Source<content::WebContents>(web_contents_)); |
68 } | 69 } |
69 | 70 |
| 71 void GoogleURLTrackerNavigationHelperImpl::OpenURL( |
| 72 GURL url, |
| 73 WindowOpenDisposition disposition, |
| 74 bool user_clicked_on_link) { |
| 75 content::PageTransition transition_type = user_clicked_on_link ? |
| 76 content::PAGE_TRANSITION_LINK : content::PAGE_TRANSITION_GENERATED; |
| 77 web_contents_->OpenURL(content::OpenURLParams( |
| 78 url, content::Referrer(), disposition, transition_type, false)); |
| 79 } |
| 80 |
70 void GoogleURLTrackerNavigationHelperImpl::Observe( | 81 void GoogleURLTrackerNavigationHelperImpl::Observe( |
71 int type, | 82 int type, |
72 const content::NotificationSource& source, | 83 const content::NotificationSource& source, |
73 const content::NotificationDetails& details) { | 84 const content::NotificationDetails& details) { |
74 switch (type) { | 85 switch (type) { |
75 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: { | 86 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: { |
76 content::NavigationController* controller = | 87 content::NavigationController* controller = |
77 content::Source<content::NavigationController>(source).ptr(); | 88 content::Source<content::NavigationController>(source).ptr(); |
78 DCHECK_EQ(web_contents_, controller->GetWebContents()); | 89 DCHECK_EQ(web_contents_, controller->GetWebContents()); |
79 | 90 |
(...skipping 13 matching lines...) Expand all Loading... |
93 DCHECK_EQ(web_contents_, | 104 DCHECK_EQ(web_contents_, |
94 content::Source<content::WebContents>(source).ptr()); | 105 content::Source<content::WebContents>(source).ptr()); |
95 google_url_tracker()->OnTabClosed(this); | 106 google_url_tracker()->OnTabClosed(this); |
96 break; | 107 break; |
97 } | 108 } |
98 | 109 |
99 default: | 110 default: |
100 NOTREACHED() << "Unknown notification received:" << type; | 111 NOTREACHED() << "Unknown notification received:" << type; |
101 } | 112 } |
102 } | 113 } |
OLD | NEW |