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

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_navigation_observer.cc

Issue 2538483002: Add management related code to SafeBrowsingNavigationObserverManager (Closed)
Patch Set: rebase-update Created 4 years 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/safe_browsing/safe_browsing_navigation_observer.h" 5 #include "chrome/browser/safe_browsing/safe_browsing_navigation_observer.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/time/time.h" 8 #include "base/time/time.h"
9 #include "chrome/browser/safe_browsing/safe_browsing_navigation_observer_manager .h" 9 #include "chrome/browser/safe_browsing/safe_browsing_navigation_observer_manager .h"
10 #include "chrome/browser/sessions/session_tab_helper.h" 10 #include "chrome/browser/sessions/session_tab_helper.h"
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 // set it as the source url of this navigation. Otherwise, this is the 130 // set it as the source url of this navigation. Otherwise, this is the
131 // first url going to commit in this frame. We set navigation_handle's URL as 131 // first url going to commit in this frame. We set navigation_handle's URL as
132 // the source url. 132 // the source url.
133 // TODO(jialiul): source_url, source_tab_id, and source_main_frame_url may be 133 // TODO(jialiul): source_url, source_tab_id, and source_main_frame_url may be
134 // incorrect when another frame is targeting this frame. Need to refine this 134 // incorrect when another frame is targeting this frame. Need to refine this
135 // logic after the true initiator details are added to NavigationHandle 135 // logic after the true initiator details are added to NavigationHandle
136 // (https://crbug.com/651895). 136 // (https://crbug.com/651895).
137 content::RenderFrameHost* current_frame_host = 137 content::RenderFrameHost* current_frame_host =
138 navigation_handle->GetWebContents()->FindFrameByFrameTreeNodeId( 138 navigation_handle->GetWebContents()->FindFrameByFrameTreeNodeId(
139 nav_event.frame_id); 139 nav_event.frame_id);
140 if (current_frame_host && 140 // For browser initiated navigation (e.g. from address bar or bookmark), we
Charlie Reis 2016/12/09 22:00:24 Sounds right.
Jialiu Lin 2016/12/12 23:43:37 thanks for confirming.
141 // don't fill the source_url to prevent attributing navigation to the last
142 // committed navigation.
143 if (navigation_handle->IsRendererInitiated() && current_frame_host &&
141 current_frame_host->GetLastCommittedURL().is_valid()) { 144 current_frame_host->GetLastCommittedURL().is_valid()) {
142 nav_event.source_url = SafeBrowsingNavigationObserverManager::ClearEmptyRef( 145 nav_event.source_url = SafeBrowsingNavigationObserverManager::ClearEmptyRef(
143 current_frame_host->GetLastCommittedURL()); 146 current_frame_host->GetLastCommittedURL());
144 } 147 }
145 nav_event.original_request_url = 148 nav_event.original_request_url =
146 SafeBrowsingNavigationObserverManager::ClearEmptyRef( 149 SafeBrowsingNavigationObserverManager::ClearEmptyRef(
147 navigation_handle->GetURL()); 150 navigation_handle->GetURL());
148 nav_event.destination_url = nav_event.original_request_url; 151 nav_event.destination_url = nav_event.original_request_url;
149 152
150 nav_event.source_tab_id = 153 nav_event.source_tab_id =
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 206
204 void SafeBrowsingNavigationObserver::DidGetResourceResponseStart( 207 void SafeBrowsingNavigationObserver::DidGetResourceResponseStart(
205 const content::ResourceRequestDetails& details) { 208 const content::ResourceRequestDetails& details) {
206 // We only care about main frame and sub frame. 209 // We only care about main frame and sub frame.
207 if (details.resource_type != content::RESOURCE_TYPE_MAIN_FRAME && 210 if (details.resource_type != content::RESOURCE_TYPE_MAIN_FRAME &&
208 details.resource_type != content::RESOURCE_TYPE_SUB_FRAME) { 211 details.resource_type != content::RESOURCE_TYPE_SUB_FRAME) {
209 return; 212 return;
210 } 213 }
211 if (!details.url.is_valid() || details.socket_address.IsEmpty()) 214 if (!details.url.is_valid() || details.socket_address.IsEmpty())
212 return; 215 return;
213 216 if (!details.url.host().empty())
Charlie Reis 2016/12/09 22:00:24 Style nit: Needs braces, since body is more than o
Jialiu Lin 2016/12/12 23:43:37 Thanks for catching this.
214 manager_->RecordHostToIpMapping(details.url.host(), 217 manager_->RecordHostToIpMapping(details.url.host(),
215 details.socket_address.host()); 218 details.socket_address.host());
216 } 219 }
217 220
218 void SafeBrowsingNavigationObserver::DidGetUserInteraction( 221 void SafeBrowsingNavigationObserver::DidGetUserInteraction(
219 const blink::WebInputEvent::Type type) { 222 const blink::WebInputEvent::Type type) {
220 last_user_gesture_timestamp_ = base::Time::Now(); 223 last_user_gesture_timestamp_ = base::Time::Now();
221 has_user_gesture_ = true; 224 has_user_gesture_ = true;
222 // TODO (jialiul): Refine user gesture logic when DidOpenRequestedURL
223 // covers all retargetting cases.
224 manager_->RecordUserGestureForWebContents(web_contents(), 225 manager_->RecordUserGestureForWebContents(web_contents(),
225 last_user_gesture_timestamp_); 226 last_user_gesture_timestamp_);
226 } 227 }
227 228
228 void SafeBrowsingNavigationObserver::WebContentsDestroyed() { 229 void SafeBrowsingNavigationObserver::WebContentsDestroyed() {
229 manager_->OnWebContentDestroyed(web_contents()); 230 manager_->OnWebContentDestroyed(web_contents());
230 web_contents()->RemoveUserData(kWebContentsUserDataKey); 231 web_contents()->RemoveUserData(kWebContentsUserDataKey);
231 // web_contents is null after this function. 232 // web_contents is null after this function.
232 } 233 }
233 234
234 } // namespace safe_browsing 235 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698