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

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

Issue 2644133005: Include all server redirects in referrer chain (Closed)
Patch Set: nit Created 3 years, 11 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 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/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
(...skipping 13 matching lines...) Expand all
24 "web_contents_safe_browsing_navigation_observer"; 24 "web_contents_safe_browsing_navigation_observer";
25 } // namespace 25 } // namespace
26 26
27 namespace safe_browsing { 27 namespace safe_browsing {
28 28
29 // SafeBrowsingNavigationObserver::NavigationEvent----------------------------- 29 // SafeBrowsingNavigationObserver::NavigationEvent-----------------------------
30 NavigationEvent::NavigationEvent() 30 NavigationEvent::NavigationEvent()
31 : source_url(), 31 : source_url(),
32 source_main_frame_url(), 32 source_main_frame_url(),
33 original_request_url(), 33 original_request_url(),
34 destination_url(),
35 source_tab_id(-1), 34 source_tab_id(-1),
36 target_tab_id(-1), 35 target_tab_id(-1),
37 frame_id(-1), 36 frame_id(-1),
38 last_updated(base::Time::Now()), 37 last_updated(base::Time::Now()),
39 is_user_initiated(false), 38 is_user_initiated(false),
40 has_committed(false), 39 has_committed(false),
41 has_server_redirect(false) {} 40 has_server_redirect(false) {}
42 41
43 NavigationEvent::NavigationEvent(NavigationEvent&& nav_event) 42 NavigationEvent::NavigationEvent(NavigationEvent&& nav_event)
44 : source_url(std::move(nav_event.source_url)), 43 : source_url(std::move(nav_event.source_url)),
45 source_main_frame_url(std::move(nav_event.source_main_frame_url)), 44 source_main_frame_url(std::move(nav_event.source_main_frame_url)),
46 original_request_url(std::move(nav_event.original_request_url)), 45 original_request_url(std::move(nav_event.original_request_url)),
47 destination_url(std::move(nav_event.destination_url)),
48 source_tab_id(std::move(nav_event.source_tab_id)), 46 source_tab_id(std::move(nav_event.source_tab_id)),
49 target_tab_id(std::move(nav_event.target_tab_id)), 47 target_tab_id(std::move(nav_event.target_tab_id)),
50 frame_id(nav_event.frame_id), 48 frame_id(nav_event.frame_id),
51 last_updated(nav_event.last_updated), 49 last_updated(nav_event.last_updated),
52 is_user_initiated(nav_event.is_user_initiated), 50 is_user_initiated(nav_event.is_user_initiated),
53 has_committed(nav_event.has_committed), 51 has_committed(nav_event.has_committed),
54 has_server_redirect(nav_event.has_server_redirect) {} 52 has_server_redirect(nav_event.has_server_redirect),
53 server_redirect_urls(std::move(nav_event.server_redirect_urls)) {}
55 54
56 NavigationEvent& NavigationEvent::operator=(NavigationEvent&& nav_event) { 55 NavigationEvent& NavigationEvent::operator=(NavigationEvent&& nav_event) {
57 source_url = std::move(nav_event.source_url); 56 source_url = std::move(nav_event.source_url);
58 source_main_frame_url = std::move(nav_event.source_main_frame_url); 57 source_main_frame_url = std::move(nav_event.source_main_frame_url);
59 original_request_url = std::move(nav_event.original_request_url); 58 original_request_url = std::move(nav_event.original_request_url);
60 destination_url = std::move(nav_event.destination_url);
61 source_tab_id = nav_event.source_tab_id; 59 source_tab_id = nav_event.source_tab_id;
62 target_tab_id = nav_event.target_tab_id; 60 target_tab_id = nav_event.target_tab_id;
63 frame_id = nav_event.frame_id; 61 frame_id = nav_event.frame_id;
64 last_updated = nav_event.last_updated; 62 last_updated = nav_event.last_updated;
65 is_user_initiated = nav_event.is_user_initiated; 63 is_user_initiated = nav_event.is_user_initiated;
66 has_committed = nav_event.has_committed; 64 has_committed = nav_event.has_committed;
67 has_server_redirect = nav_event.has_server_redirect; 65 has_server_redirect = nav_event.has_server_redirect;
66 server_redirect_urls = std::move(nav_event.server_redirect_urls);
68 return *this; 67 return *this;
69 } 68 }
70 69
71 NavigationEvent::~NavigationEvent() {} 70 NavigationEvent::~NavigationEvent() {}
72 71
73 // SafeBrowsingNavigationObserver -------------------------------------------- 72 // SafeBrowsingNavigationObserver --------------------------------------------
74 73
75 // static 74 // static
76 void SafeBrowsingNavigationObserver::MaybeCreateForWebContents( 75 void SafeBrowsingNavigationObserver::MaybeCreateForWebContents(
77 content::WebContents* web_contents) { 76 content::WebContents* web_contents) {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 // don't fill the source_url to prevent attributing navigation to the last 152 // don't fill the source_url to prevent attributing navigation to the last
154 // committed navigation. 153 // committed navigation.
155 if (navigation_handle->IsRendererInitiated() && current_frame_host && 154 if (navigation_handle->IsRendererInitiated() && current_frame_host &&
156 current_frame_host->GetLastCommittedURL().is_valid()) { 155 current_frame_host->GetLastCommittedURL().is_valid()) {
157 nav_event.source_url = SafeBrowsingNavigationObserverManager::ClearEmptyRef( 156 nav_event.source_url = SafeBrowsingNavigationObserverManager::ClearEmptyRef(
158 current_frame_host->GetLastCommittedURL()); 157 current_frame_host->GetLastCommittedURL());
159 } 158 }
160 nav_event.original_request_url = 159 nav_event.original_request_url =
161 SafeBrowsingNavigationObserverManager::ClearEmptyRef( 160 SafeBrowsingNavigationObserverManager::ClearEmptyRef(
162 navigation_handle->GetURL()); 161 navigation_handle->GetURL());
163 nav_event.destination_url = nav_event.original_request_url;
164 162
165 nav_event.source_tab_id = 163 nav_event.source_tab_id =
166 SessionTabHelper::IdForTab(navigation_handle->GetWebContents()); 164 SessionTabHelper::IdForTab(navigation_handle->GetWebContents());
167 165
168 if (navigation_handle->IsInMainFrame()) { 166 if (navigation_handle->IsInMainFrame()) {
169 nav_event.source_main_frame_url = nav_event.source_url; 167 nav_event.source_main_frame_url = nav_event.source_url;
170 } else { 168 } else {
171 nav_event.source_main_frame_url = 169 nav_event.source_main_frame_url =
172 SafeBrowsingNavigationObserverManager::ClearEmptyRef( 170 SafeBrowsingNavigationObserverManager::ClearEmptyRef(
173 navigation_handle->GetWebContents()->GetLastCommittedURL()); 171 navigation_handle->GetWebContents()->GetLastCommittedURL());
174 } 172 }
175 navigation_handle_map_[navigation_handle] = std::move(nav_event); 173 navigation_handle_map_[navigation_handle] = std::move(nav_event);
176 } 174 }
177 175
178 void SafeBrowsingNavigationObserver::DidRedirectNavigation( 176 void SafeBrowsingNavigationObserver::DidRedirectNavigation(
179 content::NavigationHandle* navigation_handle) { 177 content::NavigationHandle* navigation_handle) {
180 // We should have already seen this navigation_handle in DidStartNavigation. 178 // We should have already seen this navigation_handle in DidStartNavigation.
181 if (navigation_handle_map_.find(navigation_handle) == 179 if (navigation_handle_map_.find(navigation_handle) ==
182 navigation_handle_map_.end()) { 180 navigation_handle_map_.end()) {
183 NOTREACHED(); 181 NOTREACHED();
184 return; 182 return;
185 } 183 }
186 184
187 NavigationEvent* nav_event = &navigation_handle_map_[navigation_handle]; 185 NavigationEvent* nav_event = &navigation_handle_map_[navigation_handle];
188 nav_event->has_server_redirect = true; 186 nav_event->has_server_redirect = true;
189 nav_event->destination_url = 187 nav_event->server_redirect_urls.push_back(
190 SafeBrowsingNavigationObserverManager::ClearEmptyRef( 188 SafeBrowsingNavigationObserverManager::ClearEmptyRef(
191 navigation_handle->GetURL()); 189 navigation_handle->GetURL()));
192 nav_event->last_updated = base::Time::Now(); 190 nav_event->last_updated = base::Time::Now();
193 } 191 }
194 192
195 void SafeBrowsingNavigationObserver::DidFinishNavigation( 193 void SafeBrowsingNavigationObserver::DidFinishNavigation(
196 content::NavigationHandle* navigation_handle) { 194 content::NavigationHandle* navigation_handle) {
197 if (navigation_handle_map_.find(navigation_handle) == 195 if (navigation_handle_map_.find(navigation_handle) ==
198 navigation_handle_map_.end()) { 196 navigation_handle_map_.end()) {
199 NOTREACHED(); 197 NOTREACHED();
200 return; 198 return;
201 } 199 }
202 200
203 // If it is an error page, we ignore this navigation. 201 // If it is an error page, we ignore this navigation.
204 if (navigation_handle->IsErrorPage()) { 202 if (navigation_handle->IsErrorPage()) {
205 navigation_handle_map_.erase(navigation_handle); 203 navigation_handle_map_.erase(navigation_handle);
206 return; 204 return;
207 } 205 }
208 NavigationEvent* nav_event = &navigation_handle_map_[navigation_handle]; 206 NavigationEvent* nav_event = &navigation_handle_map_[navigation_handle];
209 207
210 nav_event->has_committed = navigation_handle->HasCommitted(); 208 nav_event->has_committed = navigation_handle->HasCommitted();
211 nav_event->target_tab_id = 209 nav_event->target_tab_id =
212 SessionTabHelper::IdForTab(navigation_handle->GetWebContents()); 210 SessionTabHelper::IdForTab(navigation_handle->GetWebContents());
213 nav_event->last_updated = base::Time::Now(); 211 nav_event->last_updated = base::Time::Now();
214 212
215 manager_->RecordNavigationEvent(nav_event->destination_url, nav_event); 213 manager_->RecordNavigationEvent(nav_event->GetDestinationUrl(), nav_event);
216 navigation_handle_map_.erase(navigation_handle); 214 navigation_handle_map_.erase(navigation_handle);
217 } 215 }
218 216
219 void SafeBrowsingNavigationObserver::DidGetResourceResponseStart( 217 void SafeBrowsingNavigationObserver::DidGetResourceResponseStart(
220 const content::ResourceRequestDetails& details) { 218 const content::ResourceRequestDetails& details) {
221 // We only care about main frame and sub frame. 219 // We only care about main frame and sub frame.
222 if (details.resource_type != content::RESOURCE_TYPE_MAIN_FRAME && 220 if (details.resource_type != content::RESOURCE_TYPE_MAIN_FRAME &&
223 details.resource_type != content::RESOURCE_TYPE_SUB_FRAME) { 221 details.resource_type != content::RESOURCE_TYPE_SUB_FRAME) {
224 return; 222 return;
225 } 223 }
(...skipping 13 matching lines...) Expand all
239 last_user_gesture_timestamp_); 237 last_user_gesture_timestamp_);
240 } 238 }
241 239
242 void SafeBrowsingNavigationObserver::WebContentsDestroyed() { 240 void SafeBrowsingNavigationObserver::WebContentsDestroyed() {
243 manager_->OnWebContentDestroyed(web_contents()); 241 manager_->OnWebContentDestroyed(web_contents());
244 web_contents()->RemoveUserData(kWebContentsUserDataKey); 242 web_contents()->RemoveUserData(kWebContentsUserDataKey);
245 // web_contents is null after this function. 243 // web_contents is null after this function.
246 } 244 }
247 245
248 } // namespace safe_browsing 246 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698