Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(545)

Side by Side Diff: chrome/browser/extensions/api/web_navigation/web_navigation_api.cc

Issue 2724433002: Remove the retargeting notification (Closed)
Patch Set: Remove comments in safe browsing tests Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 // Implements the Chrome Extensions WebNavigation API. 5 // Implements the Chrome Extensions WebNavigation API.
6 6
7 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h" 7 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h"
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "chrome/browser/chrome_notification_types.h" 10 #include "chrome/browser/chrome_notification_types.h"
11 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api_consta nts.h" 11 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api_consta nts.h"
12 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api_helper s.h" 12 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api_helper s.h"
13 #include "chrome/browser/extensions/extension_tab_util.h" 13 #include "chrome/browser/extensions/extension_tab_util.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/tab_contents/retargeting_details.h"
16 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/browser_list.h" 16 #include "chrome/browser/ui/browser_list.h"
18 #include "chrome/common/extensions/api/web_navigation.h" 17 #include "chrome/common/extensions/api/web_navigation.h"
19 #include "content/public/browser/navigation_details.h" 18 #include "content/public/browser/navigation_details.h"
20 #include "content/public/browser/navigation_handle.h" 19 #include "content/public/browser/navigation_handle.h"
21 #include "content/public/browser/notification_service.h" 20 #include "content/public/browser/notification_service.h"
22 #include "content/public/browser/notification_types.h" 21 #include "content/public/browser/notification_types.h"
23 #include "content/public/browser/render_frame_host.h" 22 #include "content/public/browser/render_frame_host.h"
24 #include "content/public/browser/render_process_host.h" 23 #include "content/public/browser/render_process_host.h"
25 #include "content/public/browser/resource_request_details.h" 24 #include "content/public/browser/resource_request_details.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 target_web_contents(target_web_contents), 68 target_web_contents(target_web_contents),
70 target_url(target_url) { 69 target_url(target_url) {
71 } 70 }
72 71
73 WebNavigationEventRouter::PendingWebContents::~PendingWebContents() {} 72 WebNavigationEventRouter::PendingWebContents::~PendingWebContents() {}
74 73
75 WebNavigationEventRouter::WebNavigationEventRouter(Profile* profile) 74 WebNavigationEventRouter::WebNavigationEventRouter(Profile* profile)
76 : profile_(profile), browser_tab_strip_tracker_(this, this, nullptr) { 75 : profile_(profile), browser_tab_strip_tracker_(this, this, nullptr) {
77 CHECK(registrar_.IsEmpty()); 76 CHECK(registrar_.IsEmpty());
78 registrar_.Add(this, 77 registrar_.Add(this,
79 chrome::NOTIFICATION_RETARGETING,
80 content::NotificationService::AllSources());
81 registrar_.Add(this,
82 chrome::NOTIFICATION_TAB_ADDED, 78 chrome::NOTIFICATION_TAB_ADDED,
83 content::NotificationService::AllSources()); 79 content::NotificationService::AllSources());
84 registrar_.Add(this, 80 registrar_.Add(this,
85 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 81 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
86 content::NotificationService::AllSources()); 82 content::NotificationService::AllSources());
87 83
88 browser_tab_strip_tracker_.Init( 84 browser_tab_strip_tracker_.Init(
89 BrowserTabStripTracker::InitWith::ALL_BROWERS); 85 BrowserTabStripTracker::InitWith::ALL_BROWERS);
90 } 86 }
91 87
(...skipping 22 matching lines...) Expand all
114 return; 110 return;
115 111
116 helpers::DispatchOnTabReplaced(old_contents, profile_, new_contents); 112 helpers::DispatchOnTabReplaced(old_contents, profile_, new_contents);
117 } 113 }
118 114
119 void WebNavigationEventRouter::Observe( 115 void WebNavigationEventRouter::Observe(
120 int type, 116 int type,
121 const content::NotificationSource& source, 117 const content::NotificationSource& source,
122 const content::NotificationDetails& details) { 118 const content::NotificationDetails& details) {
123 switch (type) { 119 switch (type) {
124 case chrome::NOTIFICATION_RETARGETING: {
125 Profile* profile = content::Source<Profile>(source).ptr();
126 if (profile->GetOriginalProfile() == profile_) {
127 Retargeting(
128 content::Details<const RetargetingDetails>(details).ptr());
129 }
130 break;
131 }
132 120
133 case chrome::NOTIFICATION_TAB_ADDED: 121 case chrome::NOTIFICATION_TAB_ADDED:
134 TabAdded(content::Details<content::WebContents>(details).ptr()); 122 TabAdded(content::Details<content::WebContents>(details).ptr());
135 break; 123 break;
136 124
137 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED: 125 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED:
138 TabDestroyed(content::Source<content::WebContents>(source).ptr()); 126 TabDestroyed(content::Source<content::WebContents>(source).ptr());
139 break; 127 break;
140 128
141 default: 129 default:
142 NOTREACHED(); 130 NOTREACHED();
143 } 131 }
144 } 132 }
145 133
146 void WebNavigationEventRouter::Retargeting(const RetargetingDetails* details) { 134 void WebNavigationEventRouter::RecordNewWebContents(
147 if (details->source_render_frame_id == 0) 135 content::WebContents* source_web_contents,
136 int source_render_process_id,
137 int source_render_frame_id,
138 GURL target_url,
139 content::WebContents* target_web_contents,
140 bool not_yet_in_tabstrip) {
141 if (source_render_frame_id == 0)
148 return; 142 return;
149 WebNavigationTabObserver* tab_observer = 143 WebNavigationTabObserver* tab_observer =
150 WebNavigationTabObserver::Get(details->source_web_contents); 144 WebNavigationTabObserver::Get(source_web_contents);
151 if (!tab_observer) { 145 if (!tab_observer) {
152 // If you hit this DCHECK(), please add reproduction steps to 146 // If you hit this DCHECK(), please add reproduction steps to
153 // http://crbug.com/109464. 147 // http://crbug.com/109464.
154 DCHECK(GetViewType(details->source_web_contents) != VIEW_TYPE_TAB_CONTENTS); 148 DCHECK(GetViewType(source_web_contents) != VIEW_TYPE_TAB_CONTENTS);
155 return; 149 return;
156 } 150 }
157 const FrameNavigationState& frame_navigation_state = 151 const FrameNavigationState& frame_navigation_state =
158 tab_observer->frame_navigation_state(); 152 tab_observer->frame_navigation_state();
159 153
160 content::RenderFrameHost* frame_host = content::RenderFrameHost::FromID( 154 content::RenderFrameHost* frame_host = content::RenderFrameHost::FromID(
161 details->source_render_process_id, details->source_render_frame_id); 155 source_render_process_id, source_render_frame_id);
162 if (!frame_navigation_state.CanSendEvents(frame_host)) 156 if (!frame_navigation_state.CanSendEvents(frame_host))
163 return; 157 return;
164 158
165 // If the WebContents isn't yet inserted into a tab strip, we need to delay 159 // If the WebContents isn't yet inserted into a tab strip, we need to delay
166 // the extension event until the WebContents is fully initialized. 160 // the extension event until the WebContents is fully initialized.
167 if (details->not_yet_in_tabstrip) { 161 if (not_yet_in_tabstrip) {
168 pending_web_contents_[details->target_web_contents] = 162 pending_web_contents_[target_web_contents] = PendingWebContents(
169 PendingWebContents(details->source_web_contents, 163 source_web_contents, frame_host, target_web_contents, target_url);
170 frame_host,
171 details->target_web_contents,
172 details->target_url);
173 } else { 164 } else {
174 helpers::DispatchOnCreatedNavigationTarget( 165 helpers::DispatchOnCreatedNavigationTarget(
175 details->source_web_contents, 166 source_web_contents, target_web_contents->GetBrowserContext(),
176 details->target_web_contents->GetBrowserContext(), 167 frame_host, target_web_contents, target_url);
177 frame_host,
178 details->target_web_contents,
179 details->target_url);
180 } 168 }
181 } 169 }
182 170
183 void WebNavigationEventRouter::TabAdded(content::WebContents* tab) { 171 void WebNavigationEventRouter::TabAdded(content::WebContents* tab) {
184 std::map<content::WebContents*, PendingWebContents>::iterator iter = 172 std::map<content::WebContents*, PendingWebContents>::iterator iter =
185 pending_web_contents_.find(tab); 173 pending_web_contents_.find(tab);
186 if (iter == pending_web_contents_.end()) 174 if (iter == pending_web_contents_.end())
187 return; 175 return;
188 176
189 WebNavigationTabObserver* tab_observer = 177 WebNavigationTabObserver* tab_observer =
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 navigation_state_.SetErrorOccurredInFrame(render_frame_host); 365 navigation_state_.SetErrorOccurredInFrame(render_frame_host);
378 } 366 }
379 367
380 void WebNavigationTabObserver::DidOpenRequestedURL( 368 void WebNavigationTabObserver::DidOpenRequestedURL(
381 content::WebContents* new_contents, 369 content::WebContents* new_contents,
382 content::RenderFrameHost* source_render_frame_host, 370 content::RenderFrameHost* source_render_frame_host,
383 const GURL& url, 371 const GURL& url,
384 const content::Referrer& referrer, 372 const content::Referrer& referrer,
385 WindowOpenDisposition disposition, 373 WindowOpenDisposition disposition,
386 ui::PageTransition transition, 374 ui::PageTransition transition,
387 bool started_from_context_menu) { 375 bool started_from_context_menu,
376 bool renderer_initiated) {
388 if (!navigation_state_.CanSendEvents(source_render_frame_host)) 377 if (!navigation_state_.CanSendEvents(source_render_frame_host))
389 return; 378 return;
390 379
391 // We only send the onCreatedNavigationTarget if we end up creating a new 380 // We only send the onCreatedNavigationTarget if we end up creating a new
392 // window. 381 // window.
393 if (disposition != WindowOpenDisposition::SINGLETON_TAB && 382 if (disposition != WindowOpenDisposition::SINGLETON_TAB &&
394 disposition != WindowOpenDisposition::NEW_FOREGROUND_TAB && 383 disposition != WindowOpenDisposition::NEW_FOREGROUND_TAB &&
395 disposition != WindowOpenDisposition::NEW_BACKGROUND_TAB && 384 disposition != WindowOpenDisposition::NEW_BACKGROUND_TAB &&
396 disposition != WindowOpenDisposition::NEW_POPUP && 385 disposition != WindowOpenDisposition::NEW_POPUP &&
397 disposition != WindowOpenDisposition::NEW_WINDOW && 386 disposition != WindowOpenDisposition::NEW_WINDOW &&
398 disposition != WindowOpenDisposition::OFF_THE_RECORD) 387 disposition != WindowOpenDisposition::OFF_THE_RECORD)
399 return; 388 return;
400 389
401 helpers::DispatchOnCreatedNavigationTarget(web_contents(), 390 WebNavigationAPI* api = WebNavigationAPI::GetFactoryInstance()->Get(
402 new_contents->GetBrowserContext(), 391 web_contents()->GetBrowserContext());
403 source_render_frame_host, 392 WebNavigationEventRouter* router = api->web_navigation_event_router_.get();
404 new_contents, 393 if (!router)
405 url); 394 return;
395
396 router->RecordNewWebContents(web_contents(),
397 source_render_frame_host->GetProcess()->GetID(),
398 source_render_frame_host->GetRoutingID(), url,
399 new_contents, renderer_initiated);
406 } 400 }
407 401
408 void WebNavigationTabObserver::WebContentsDestroyed() { 402 void WebNavigationTabObserver::WebContentsDestroyed() {
409 g_tab_observer.Get().erase(web_contents()); 403 g_tab_observer.Get().erase(web_contents());
410 registrar_.RemoveAll(); 404 registrar_.RemoveAll();
411 } 405 }
412 406
413 void WebNavigationTabObserver::DispatchCachedOnBeforeNavigate() { 407 void WebNavigationTabObserver::DispatchCachedOnBeforeNavigate() {
414 if (!pending_on_before_navigate_event_) 408 if (!pending_on_before_navigate_event_)
415 return; 409 return;
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 return g_factory.Pointer(); 582 return g_factory.Pointer();
589 } 583 }
590 584
591 void WebNavigationAPI::OnListenerAdded(const EventListenerInfo& details) { 585 void WebNavigationAPI::OnListenerAdded(const EventListenerInfo& details) {
592 web_navigation_event_router_.reset(new WebNavigationEventRouter( 586 web_navigation_event_router_.reset(new WebNavigationEventRouter(
593 Profile::FromBrowserContext(browser_context_))); 587 Profile::FromBrowserContext(browser_context_)));
594 EventRouter::Get(browser_context_)->UnregisterObserver(this); 588 EventRouter::Get(browser_context_)->UnregisterObserver(this);
595 } 589 }
596 590
597 } // namespace extensions 591 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698