OLD | NEW |
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 25 matching lines...) Expand all Loading... |
36 if (current_time_in_second <= event_time_in_second) | 36 if (current_time_in_second <= event_time_in_second) |
37 return true; | 37 return true; |
38 return current_time_in_second - event_time_in_second > ttl_in_second; | 38 return current_time_in_second - event_time_in_second > ttl_in_second; |
39 } | 39 } |
40 | 40 |
41 // Helper function to determine if the URL type should be LANDING_REFERRER or | 41 // Helper function to determine if the URL type should be LANDING_REFERRER or |
42 // LANDING_PAGE, and modify AttributionResult accordingly. | 42 // LANDING_PAGE, and modify AttributionResult accordingly. |
43 ReferrerChainEntry::URLType GetURLTypeAndAdjustAttributionResult( | 43 ReferrerChainEntry::URLType GetURLTypeAndAdjustAttributionResult( |
44 bool at_user_gesture_limit, | 44 bool at_user_gesture_limit, |
45 SafeBrowsingNavigationObserverManager::AttributionResult* out_result) { | 45 SafeBrowsingNavigationObserverManager::AttributionResult* out_result) { |
46 // Landing page of a download refers to the page user directly interacts | 46 // Landing page refers to the page user directly interacts with to trigger |
47 // with to trigger this download (e.g. clicking on download button). Landing | 47 // this event (e.g. clicking on download button). Landing referrer page is the |
48 // referrer page is the one user interacts with right before navigating to | 48 // one user interacts with right before navigating to the landing page. |
49 // the landing page. | |
50 // Since we are tracing navigations backwards, if we've reached | 49 // Since we are tracing navigations backwards, if we've reached |
51 // user gesture limit before this navigation event, this is a navigation | 50 // user gesture limit before this navigation event, this is a navigation |
52 // leading to the landing referrer page, otherwise it leads to landing page. | 51 // leading to the landing referrer page, otherwise it leads to landing page. |
53 if (at_user_gesture_limit) { | 52 if (at_user_gesture_limit) { |
54 *out_result = | 53 *out_result = |
55 SafeBrowsingNavigationObserverManager::SUCCESS_LANDING_REFERRER; | 54 SafeBrowsingNavigationObserverManager::SUCCESS_LANDING_REFERRER; |
56 return ReferrerChainEntry::LANDING_REFERRER; | 55 return ReferrerChainEntry::LANDING_REFERRER; |
57 } else { | 56 } else { |
58 *out_result = SafeBrowsingNavigationObserverManager::SUCCESS_LANDING_PAGE; | 57 *out_result = SafeBrowsingNavigationObserverManager::SUCCESS_LANDING_PAGE; |
59 return ReferrerChainEntry::LANDING_PAGE; | 58 return ReferrerChainEntry::LANDING_PAGE; |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 | 297 |
299 void SafeBrowsingNavigationObserverManager::CleanUpStaleNavigationFootprints() { | 298 void SafeBrowsingNavigationObserverManager::CleanUpStaleNavigationFootprints() { |
300 CleanUpNavigationEvents(); | 299 CleanUpNavigationEvents(); |
301 CleanUpUserGestures(); | 300 CleanUpUserGestures(); |
302 CleanUpIpAddresses(); | 301 CleanUpIpAddresses(); |
303 ScheduleNextCleanUpAfterInterval( | 302 ScheduleNextCleanUpAfterInterval( |
304 base::TimeDelta::FromSecondsD(kNavigationFootprintTTLInSecond)); | 303 base::TimeDelta::FromSecondsD(kNavigationFootprintTTLInSecond)); |
305 } | 304 } |
306 | 305 |
307 SafeBrowsingNavigationObserverManager::AttributionResult | 306 SafeBrowsingNavigationObserverManager::AttributionResult |
308 SafeBrowsingNavigationObserverManager::IdentifyReferrerChainForDownload( | 307 SafeBrowsingNavigationObserverManager::IdentifyReferrerChainByEventURL( |
309 const GURL& target_url, | 308 const GURL& event_url, |
310 int target_tab_id, | 309 int event_tab_id, |
311 int user_gesture_count_limit, | 310 int user_gesture_count_limit, |
312 ReferrerChain* out_referrer_chain) { | 311 ReferrerChain* out_referrer_chain) { |
313 if (!target_url.is_valid()) | 312 if (!event_url.is_valid()) |
314 return INVALID_URL; | 313 return INVALID_URL; |
315 | 314 |
316 NavigationEvent* nav_event = navigation_event_list_.FindNavigationEvent( | 315 NavigationEvent* nav_event = navigation_event_list_.FindNavigationEvent( |
317 target_url, GURL(), target_tab_id); | 316 event_url, GURL(), event_tab_id); |
318 if (!nav_event) { | 317 if (!nav_event) { |
319 // We cannot find a single navigation event related to this download. | 318 // We cannot find a single navigation event related to this event. |
320 return NAVIGATION_EVENT_NOT_FOUND; | 319 return NAVIGATION_EVENT_NOT_FOUND; |
321 } | 320 } |
322 AttributionResult result = SUCCESS; | 321 AttributionResult result = SUCCESS; |
323 AddToReferrerChain(out_referrer_chain, nav_event, GURL(), | 322 AddToReferrerChain(out_referrer_chain, nav_event, GURL(), |
324 ReferrerChainEntry::DOWNLOAD_URL); | 323 ReferrerChainEntry::EVENT_URL); |
325 int user_gesture_count = 0; | 324 int user_gesture_count = 0; |
326 GetRemainingReferrerChain( | 325 GetRemainingReferrerChain( |
327 nav_event, | 326 nav_event, |
328 user_gesture_count, | 327 user_gesture_count, |
329 user_gesture_count_limit, | 328 user_gesture_count_limit, |
330 out_referrer_chain, | 329 out_referrer_chain, |
331 &result); | 330 &result); |
332 return result; | 331 return result; |
333 } | 332 } |
334 | 333 |
335 SafeBrowsingNavigationObserverManager::AttributionResult | 334 SafeBrowsingNavigationObserverManager::AttributionResult |
336 SafeBrowsingNavigationObserverManager:: | 335 SafeBrowsingNavigationObserverManager::IdentifyReferrerChainByWebContent( |
337 IdentifyReferrerChainByDownloadWebContent( | 336 content::WebContents* web_contents, |
338 content::WebContents* web_contents, | 337 int user_gesture_count_limit, |
339 int user_gesture_count_limit, | 338 ReferrerChain* out_referrer_chain) { |
340 ReferrerChain* out_referrer_chain) { | |
341 if (!web_contents || !web_contents->GetLastCommittedURL().is_valid()) | 339 if (!web_contents || !web_contents->GetLastCommittedURL().is_valid()) |
342 return INVALID_URL; | 340 return INVALID_URL; |
343 bool has_user_gesture = HasUserGesture(web_contents); | 341 bool has_user_gesture = HasUserGesture(web_contents); |
344 int tab_id = SessionTabHelper::IdForTab(web_contents); | 342 int tab_id = SessionTabHelper::IdForTab(web_contents); |
345 return IdentifyReferrerChainForDownloadHostingPage( | 343 return IdentifyReferrerChainByHostingPage( |
346 web_contents->GetLastCommittedURL(), GURL(), tab_id, has_user_gesture, | 344 web_contents->GetLastCommittedURL(), GURL(), tab_id, has_user_gesture, |
347 user_gesture_count_limit, out_referrer_chain); | 345 user_gesture_count_limit, out_referrer_chain); |
348 } | 346 } |
349 | 347 |
350 SafeBrowsingNavigationObserverManager::AttributionResult | 348 SafeBrowsingNavigationObserverManager::AttributionResult |
351 SafeBrowsingNavigationObserverManager:: | 349 SafeBrowsingNavigationObserverManager::IdentifyReferrerChainByHostingPage( |
352 IdentifyReferrerChainForDownloadHostingPage( | 350 const GURL& initiating_frame_url, |
353 const GURL& initiating_frame_url, | 351 const GURL& initiating_main_frame_url, |
354 const GURL& initiating_main_frame_url, | 352 int tab_id, |
355 int tab_id, | 353 bool has_user_gesture, |
356 bool has_user_gesture, | 354 int user_gesture_count_limit, |
357 int user_gesture_count_limit, | 355 ReferrerChain* out_referrer_chain) { |
358 ReferrerChain* out_referrer_chain) { | |
359 if (!initiating_frame_url.is_valid()) | 356 if (!initiating_frame_url.is_valid()) |
360 return INVALID_URL; | 357 return INVALID_URL; |
361 | 358 |
362 NavigationEvent* nav_event = navigation_event_list_.FindNavigationEvent( | 359 NavigationEvent* nav_event = navigation_event_list_.FindNavigationEvent( |
363 initiating_frame_url, initiating_main_frame_url, tab_id); | 360 initiating_frame_url, initiating_main_frame_url, tab_id); |
364 if (!nav_event) { | 361 if (!nav_event) { |
365 // We cannot find a single navigation event related to this download hosting | 362 // We cannot find a single navigation event related to this hosting page. |
366 // page. | |
367 return NAVIGATION_EVENT_NOT_FOUND; | 363 return NAVIGATION_EVENT_NOT_FOUND; |
368 } | 364 } |
369 | 365 |
370 AttributionResult result = SUCCESS; | 366 AttributionResult result = SUCCESS; |
371 | 367 |
372 int user_gesture_count = 0; | 368 int user_gesture_count = 0; |
373 // If this initiating_frame has user gesture, we consider this as the landing | 369 // If this initiating_frame has user gesture, we consider this as the landing |
374 // page of the PPAPI download. | 370 // page of this event. |
375 if (has_user_gesture) { | 371 if (has_user_gesture) { |
376 user_gesture_count = 1; | 372 user_gesture_count = 1; |
377 AddToReferrerChain( | 373 AddToReferrerChain( |
378 out_referrer_chain, nav_event, initiating_main_frame_url, | 374 out_referrer_chain, nav_event, initiating_main_frame_url, |
379 GetURLTypeAndAdjustAttributionResult( | 375 GetURLTypeAndAdjustAttributionResult( |
380 user_gesture_count == user_gesture_count_limit, &result)); | 376 user_gesture_count == user_gesture_count_limit, &result)); |
381 } else { | 377 } else { |
382 AddToReferrerChain(out_referrer_chain, nav_event, initiating_main_frame_url, | 378 AddToReferrerChain(out_referrer_chain, nav_event, initiating_main_frame_url, |
383 ReferrerChainEntry::CLIENT_REDIRECT); | 379 ReferrerChainEntry::CLIENT_REDIRECT); |
384 } | 380 } |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 out_result)); | 588 out_result)); |
593 // Stop searching if the size of out_referrer_chain already reached its | 589 // Stop searching if the size of out_referrer_chain already reached its |
594 // limit. | 590 // limit. |
595 if (out_referrer_chain->size() == kReferrerChainMaxLength) | 591 if (out_referrer_chain->size() == kReferrerChainMaxLength) |
596 return; | 592 return; |
597 last_main_frame_url_traced = last_nav_event_traced->source_main_frame_url; | 593 last_main_frame_url_traced = last_nav_event_traced->source_main_frame_url; |
598 } | 594 } |
599 } | 595 } |
600 | 596 |
601 } // namespace safe_browsing | 597 } // namespace safe_browsing |
OLD | NEW |