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

Unified Diff: chrome/browser/safe_browsing/safe_browsing_navigation_observer_manager.cc

Issue 2612663002: Use main frame URL to identify referrer if sub-frame url is not available (Closed)
Patch Set: Created 3 years, 12 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/safe_browsing/safe_browsing_navigation_observer_manager.cc
diff --git a/chrome/browser/safe_browsing/safe_browsing_navigation_observer_manager.cc b/chrome/browser/safe_browsing/safe_browsing_navigation_observer_manager.cc
index 2ebc790a511a410e938f005d73fd73cf0619906c..520919173e529e176bdb79eb618fc29e137f60ce 100644
--- a/chrome/browser/safe_browsing/safe_browsing_navigation_observer_manager.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_navigation_observer_manager.cc
@@ -164,7 +164,10 @@ SafeBrowsingNavigationObserverManager::IdentifyReferrerChain(
if (!target_url.is_valid())
return INVALID_URL;
- NavigationEvent* nav_event = FindNavigationEvent(target_url, target_tab_id);
+ NavigationEvent* nav_event = FindNavigationEvent(
+ target_url,
+ GURL(),
+ target_tab_id);
if (!nav_event) {
// We cannot find a single navigation event related to this download.
return NAVIGATION_EVENT_NOT_FOUND;
@@ -178,7 +181,9 @@ SafeBrowsingNavigationObserverManager::IdentifyReferrerChain(
// Back trace to the next nav_event that was initiated by the user.
while (!nav_event->is_user_initiated) {
nav_event =
- FindNavigationEvent(nav_event->source_url, nav_event->source_tab_id);
+ FindNavigationEvent(nav_event->source_url,
+ nav_event->source_main_frame_url,
+ nav_event->source_tab_id);
if (!nav_event)
return result;
AddToReferrerChain(out_referrer_chain, nav_event,
@@ -200,7 +205,9 @@ SafeBrowsingNavigationObserverManager::IdentifyReferrerChain(
}
nav_event =
- FindNavigationEvent(nav_event->source_url, nav_event->source_tab_id);
+ FindNavigationEvent(nav_event->source_url,
+ nav_event->source_main_frame_url,
+ nav_event->source_tab_id);
if (!nav_event)
return result;
@@ -344,8 +351,16 @@ void SafeBrowsingNavigationObserverManager::ScheduleNextCleanUpAfterInterval(
NavigationEvent* SafeBrowsingNavigationObserverManager::FindNavigationEvent(
const GURL& target_url,
+ const GURL& target_main_frame_url,
int target_tab_id) {
- auto it = navigation_map_.find(target_url);
+ if (target_url.is_empty() && target_main_frame_url.is_empty())
+ return nullptr;
+
+ // If target_url is empty, we should back trace navigation based on its
+ // main frame URL instead.
+ GURL search_url = target_url.is_empty() ? target_main_frame_url : target_url;
Nathan Parker 2017/01/04 18:54:51 nit: could be const GURL& so you don't make a cop
Jialiu Lin 2017/01/04 21:47:01 Done.
+
+ auto it = navigation_map_.find(search_url);
if (it == navigation_map_.end()) {
return nullptr;
}
@@ -353,7 +368,7 @@ NavigationEvent* SafeBrowsingNavigationObserverManager::FindNavigationEvent(
// the vector in reverse order to get the latest match.
for (auto rit = it->second.rbegin(); rit != it->second.rend(); ++rit) {
// If tab id is not valid, we only compare url, otherwise we compare both.
- if (rit->destination_url == target_url &&
+ if (rit->destination_url == search_url &&
(target_tab_id == -1 || rit->target_tab_id == target_tab_id)) {
// If both source_url and source_main_frame_url are empty, and this
// navigation is not triggered by user, a retargeting navigation probably

Powered by Google App Engine
This is Rietveld 408576698