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

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_navigation_observer_manager.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_manager .h" 5 #include "chrome/browser/safe_browsing/safe_browsing_navigation_observer_manager .h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/metrics/histogram_macros.h" 8 #include "base/metrics/histogram_macros.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 158
159 void SafeBrowsingNavigationObserverManager::RecordHostToIpMapping( 159 void SafeBrowsingNavigationObserverManager::RecordHostToIpMapping(
160 const std::string& host, 160 const std::string& host,
161 const std::string& ip) { 161 const std::string& ip) {
162 auto insert_result = host_to_ip_map_.insert( 162 auto insert_result = host_to_ip_map_.insert(
163 std::make_pair(host, std::vector<ResolvedIPAddress>())); 163 std::make_pair(host, std::vector<ResolvedIPAddress>()));
164 if (!insert_result.second) { 164 if (!insert_result.second) {
165 // host_to_ip_map already contains this key. 165 // host_to_ip_map already contains this key.
166 // If this IP is already in the vector, we update its timestamp. 166 // If this IP is already in the vector, we update its timestamp.
167 for (auto& vector_entry : insert_result.first->second) { 167 for (auto& vector_entry : insert_result.first->second) {
168 if (vector_entry.ip == host) { 168 if (vector_entry.ip == ip) {
169 vector_entry.timestamp = base::Time::Now(); 169 vector_entry.timestamp = base::Time::Now();
170 return; 170 return;
171 } 171 }
172 } 172 }
173 } 173 }
174 // If this is a new IP of this host, and we added to the end of the vector. 174 // If this is a new IP of this host, and we added to the end of the vector.
175 insert_result.first->second.push_back( 175 insert_result.first->second.push_back(
176 ResolvedIPAddress(base::Time::Now(), ip)); 176 ResolvedIPAddress(base::Time::Now(), ip));
177 } 177 }
178 178
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 NavigationEvent nav_event; 297 NavigationEvent nav_event;
298 if (rfh) { 298 if (rfh) {
299 nav_event.source_url = SafeBrowsingNavigationObserverManager::ClearEmptyRef( 299 nav_event.source_url = SafeBrowsingNavigationObserverManager::ClearEmptyRef(
300 rfh->GetLastCommittedURL()); 300 rfh->GetLastCommittedURL());
301 } 301 }
302 nav_event.source_tab_id = SessionTabHelper::IdForTab(source_contents); 302 nav_event.source_tab_id = SessionTabHelper::IdForTab(source_contents);
303 nav_event.source_main_frame_url = 303 nav_event.source_main_frame_url =
304 SafeBrowsingNavigationObserverManager::ClearEmptyRef( 304 SafeBrowsingNavigationObserverManager::ClearEmptyRef(
305 source_contents->GetLastCommittedURL()); 305 source_contents->GetLastCommittedURL());
306 nav_event.original_request_url = target_url; 306 nav_event.original_request_url = target_url;
307 nav_event.destination_url = target_url;
308 nav_event.target_tab_id = SessionTabHelper::IdForTab(target_contents); 307 nav_event.target_tab_id = SessionTabHelper::IdForTab(target_contents);
309 nav_event.frame_id = rfh ? rfh->GetFrameTreeNodeId() : -1; 308 nav_event.frame_id = rfh ? rfh->GetFrameTreeNodeId() : -1;
310 auto it = user_gesture_map_.find(source_contents); 309 auto it = user_gesture_map_.find(source_contents);
311 if (it != user_gesture_map_.end() && 310 if (it != user_gesture_map_.end() &&
312 !SafeBrowsingNavigationObserverManager::IsUserGestureExpired( 311 !SafeBrowsingNavigationObserverManager::IsUserGestureExpired(
313 it->second)) { 312 it->second)) {
314 nav_event.is_user_initiated = true; 313 nav_event.is_user_initiated = true;
315 OnUserGestureConsumed(it->first, it->second); 314 OnUserGestureConsumed(it->first, it->second);
316 } else { 315 } else {
317 nav_event.is_user_initiated = false; 316 nav_event.is_user_initiated = false;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 GURL search_url = 389 GURL search_url =
391 target_url.is_empty() ? target_main_frame_url : target_url; 390 target_url.is_empty() ? target_main_frame_url : target_url;
392 auto it = navigation_map_.find(search_url); 391 auto it = navigation_map_.find(search_url);
393 if (it == navigation_map_.end()) 392 if (it == navigation_map_.end())
394 return nullptr; 393 return nullptr;
395 394
396 // Since navigation events are recorded in chronological order, we traverse 395 // Since navigation events are recorded in chronological order, we traverse
397 // the vector in reverse order to get the latest match. 396 // the vector in reverse order to get the latest match.
398 for (auto rit = it->second.rbegin(); rit != it->second.rend(); ++rit) { 397 for (auto rit = it->second.rbegin(); rit != it->second.rend(); ++rit) {
399 // If tab id is not valid, we only compare url, otherwise we compare both. 398 // If tab id is not valid, we only compare url, otherwise we compare both.
400 if (rit->destination_url == search_url && 399 if (rit->GetDestinationUrl() == search_url &&
401 (target_tab_id == -1 || rit->target_tab_id == target_tab_id)) { 400 (target_tab_id == -1 || rit->target_tab_id == target_tab_id)) {
402 // If both source_url and source_main_frame_url are empty, and this 401 // If both source_url and source_main_frame_url are empty, and this
403 // navigation is not triggered by user, a retargeting navigation probably 402 // navigation is not triggered by user, a retargeting navigation probably
404 // causes this navigation. In this case, we skip this navigation event and 403 // causes this navigation. In this case, we skip this navigation event and
405 // looks for the retargeting navigation event. 404 // looks for the retargeting navigation event.
406 if (rit->source_url.is_empty() && rit->source_main_frame_url.is_empty() && 405 if (rit->source_url.is_empty() && rit->source_main_frame_url.is_empty() &&
407 !rit->is_user_initiated) { 406 !rit->is_user_initiated) {
408 // If there is a server redirection immediately after retargeting, we 407 // If there is a server redirection immediately after retargeting, we
409 // need to adjust our search url to the original request. 408 // need to adjust our search url to the original request.
410 if (rit->has_server_redirect){ 409 if (rit->has_server_redirect){
411 NavigationEvent* retargeting_nav_event = 410 NavigationEvent* retargeting_nav_event =
412 FindNavigationEvent(rit->original_request_url, 411 FindNavigationEvent(rit->original_request_url,
413 GURL(), 412 GURL(),
414 rit->target_tab_id); 413 rit->target_tab_id);
415 if (!retargeting_nav_event) 414 if (!retargeting_nav_event)
416 return nullptr; 415 return nullptr;
417 // Adjust retargeting navigation event's attributes. 416 // Adjust retargeting navigation event's attributes.
418 retargeting_nav_event->has_server_redirect = true; 417 retargeting_nav_event->has_server_redirect = true;
419 retargeting_nav_event->destination_url = search_url; 418 retargeting_nav_event->server_redirect_urls.push_back(
419 std::move(search_url));
420 return retargeting_nav_event; 420 return retargeting_nav_event;
421 } else { 421 } else {
422 continue; 422 continue;
423 } 423 }
424 } else { 424 } else {
425 return &*rit; 425 return &*rit;
426 } 426 }
427 } 427 }
428 } 428 }
429 return nullptr; 429 return nullptr;
430 } 430 }
431 431
432 void SafeBrowsingNavigationObserverManager::AddToReferrerChain( 432 void SafeBrowsingNavigationObserverManager::AddToReferrerChain(
433 ReferrerChain* referrer_chain, 433 ReferrerChain* referrer_chain,
434 NavigationEvent* nav_event, 434 NavigationEvent* nav_event,
435 ReferrerChainEntry::URLType type) { 435 ReferrerChainEntry::URLType type) {
436 std::unique_ptr<ReferrerChainEntry> referrer_chain_entry = 436 std::unique_ptr<ReferrerChainEntry> referrer_chain_entry =
437 base::MakeUnique<ReferrerChainEntry>(); 437 base::MakeUnique<ReferrerChainEntry>();
438 referrer_chain_entry->set_url(nav_event->destination_url.spec()); 438 const GURL destination_url = nav_event->GetDestinationUrl();
439 referrer_chain_entry->set_url(destination_url.spec());
439 referrer_chain_entry->set_type(type); 440 referrer_chain_entry->set_type(type);
440 auto ip_it = host_to_ip_map_.find(nav_event->destination_url.host()); 441 auto ip_it = host_to_ip_map_.find(destination_url.host());
441 if (ip_it != host_to_ip_map_.end()) { 442 if (ip_it != host_to_ip_map_.end()) {
442 for (ResolvedIPAddress entry : ip_it->second) { 443 for (ResolvedIPAddress entry : ip_it->second) {
443 referrer_chain_entry->add_ip_addresses(entry.ip); 444 referrer_chain_entry->add_ip_addresses(entry.ip);
444 } 445 }
445 } 446 }
446 // Since we only track navigation to landing referrer, we will not log the 447 // Since we only track navigation to landing referrer, we will not log the
447 // referrer of the landing referrer page. 448 // referrer of the landing referrer page.
448 if (type != ReferrerChainEntry::LANDING_REFERRER) { 449 if (type != ReferrerChainEntry::LANDING_REFERRER) {
449 referrer_chain_entry->set_referrer_url(nav_event->source_url.spec()); 450 referrer_chain_entry->set_referrer_url(nav_event->source_url.spec());
450 referrer_chain_entry->set_referrer_main_frame_url( 451 referrer_chain_entry->set_referrer_main_frame_url(
451 nav_event->source_main_frame_url.spec()); 452 nav_event->source_main_frame_url.spec());
452 } 453 }
453 referrer_chain_entry->set_is_retargeting(nav_event->source_tab_id != 454 referrer_chain_entry->set_is_retargeting(nav_event->source_tab_id !=
454 nav_event->target_tab_id); 455 nav_event->target_tab_id);
455 referrer_chain_entry->set_navigation_time_msec( 456 referrer_chain_entry->set_navigation_time_msec(
456 nav_event->last_updated.ToJavaTime()); 457 nav_event->last_updated.ToJavaTime());
458 if (nav_event->has_server_redirect) {
459 referrer_chain_entry->add_server_redirect_chain(
460 nav_event->original_request_url.spec());
461 for (const GURL& redirect: nav_event->server_redirect_urls)
462 referrer_chain_entry->add_server_redirect_chain(redirect.spec());
463 }
457 referrer_chain->push_back(std::move(referrer_chain_entry)); 464 referrer_chain->push_back(std::move(referrer_chain_entry));
458 } 465 }
459 466
460 void SafeBrowsingNavigationObserverManager::GetRemainingReferrerChain( 467 void SafeBrowsingNavigationObserverManager::GetRemainingReferrerChain(
461 NavigationEvent* last_nav_event_traced, 468 NavigationEvent* last_nav_event_traced,
462 int current_user_gesture_count, 469 int current_user_gesture_count,
463 int user_gesture_count_limit, 470 int user_gesture_count_limit,
464 ReferrerChain* out_referrer_chain, 471 ReferrerChain* out_referrer_chain,
465 SafeBrowsingNavigationObserverManager::AttributionResult* out_result) { 472 SafeBrowsingNavigationObserverManager::AttributionResult* out_result) {
466 473
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 508
502 AddToReferrerChain(out_referrer_chain, last_nav_event_traced, 509 AddToReferrerChain(out_referrer_chain, last_nav_event_traced,
503 GetURLTypeAndAdjustAttributionResult( 510 GetURLTypeAndAdjustAttributionResult(
504 current_user_gesture_count == 511 current_user_gesture_count ==
505 user_gesture_count_limit, 512 user_gesture_count_limit,
506 out_result)); 513 out_result));
507 } 514 }
508 } 515 }
509 516
510 } // namespace safe_browsing 517 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698