| 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" |
| 11 #include "base/timer/timer.h" | 11 #include "base/timer/timer.h" |
| 12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/chrome_notification_types.h" | |
| 14 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/safe_browsing/safe_browsing_navigation_observer.h" | 14 #include "chrome/browser/safe_browsing/safe_browsing_navigation_observer.h" |
| 16 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 15 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 17 #include "chrome/browser/sessions/session_tab_helper.h" | 16 #include "chrome/browser/sessions/session_tab_helper.h" |
| 18 #include "chrome/browser/tab_contents/retargeting_details.h" | |
| 19 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 20 #include "components/prefs/pref_service.h" | 18 #include "components/prefs/pref_service.h" |
| 21 #include "content/public/browser/navigation_details.h" | 19 #include "content/public/browser/navigation_details.h" |
| 22 #include "content/public/browser/notification_service.h" | |
| 23 #include "content/public/browser/notification_types.h" | |
| 24 #include "content/public/browser/render_frame_host.h" | 20 #include "content/public/browser/render_frame_host.h" |
| 25 #include "content/public/browser/render_process_host.h" | 21 #include "content/public/browser/render_process_host.h" |
| 26 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
| 27 | 23 |
| 28 using content::WebContents; | 24 using content::WebContents; |
| 29 | 25 |
| 30 namespace safe_browsing { | 26 namespace safe_browsing { |
| 31 | 27 |
| 32 namespace { | 28 namespace { |
| 33 | 29 |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 Profile* profile) { | 216 Profile* profile) { |
| 221 return base::FeatureList::IsEnabled( | 217 return base::FeatureList::IsEnabled( |
| 222 SafeBrowsingNavigationObserverManager::kDownloadAttribution) && | 218 SafeBrowsingNavigationObserverManager::kDownloadAttribution) && |
| 223 profile->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled) && | 219 profile->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled) && |
| 224 g_browser_process->safe_browsing_service() && | 220 g_browser_process->safe_browsing_service() && |
| 225 g_browser_process->safe_browsing_service()->navigation_observer_manager(); | 221 g_browser_process->safe_browsing_service()->navigation_observer_manager(); |
| 226 } | 222 } |
| 227 | 223 |
| 228 SafeBrowsingNavigationObserverManager::SafeBrowsingNavigationObserverManager() | 224 SafeBrowsingNavigationObserverManager::SafeBrowsingNavigationObserverManager() |
| 229 : navigation_event_list_(kNavigationRecordMaxSize) { | 225 : navigation_event_list_(kNavigationRecordMaxSize) { |
| 230 registrar_.Add(this, chrome::NOTIFICATION_RETARGETING, | |
| 231 content::NotificationService::AllSources()); | |
| 232 | 226 |
| 233 // Schedule clean up in 2 minutes. | 227 // Schedule clean up in 2 minutes. |
| 234 ScheduleNextCleanUpAfterInterval( | 228 ScheduleNextCleanUpAfterInterval( |
| 235 base::TimeDelta::FromSecondsD(kNavigationFootprintTTLInSecond)); | 229 base::TimeDelta::FromSecondsD(kNavigationFootprintTTLInSecond)); |
| 236 } | 230 } |
| 237 | 231 |
| 238 void SafeBrowsingNavigationObserverManager::RecordNavigationEvent( | 232 void SafeBrowsingNavigationObserverManager::RecordNavigationEvent( |
| 239 std::unique_ptr<NavigationEvent> nav_event) { | 233 std::unique_ptr<NavigationEvent> nav_event) { |
| 240 navigation_event_list_.RecordNavigationEvent(std::move(nav_event)); | 234 navigation_event_list_.RecordNavigationEvent(std::move(nav_event)); |
| 241 } | 235 } |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 user_gesture_count, | 383 user_gesture_count, |
| 390 user_gesture_count_limit, | 384 user_gesture_count_limit, |
| 391 out_referrer_chain, | 385 out_referrer_chain, |
| 392 &result); | 386 &result); |
| 393 return result; | 387 return result; |
| 394 } | 388 } |
| 395 | 389 |
| 396 SafeBrowsingNavigationObserverManager:: | 390 SafeBrowsingNavigationObserverManager:: |
| 397 ~SafeBrowsingNavigationObserverManager() {} | 391 ~SafeBrowsingNavigationObserverManager() {} |
| 398 | 392 |
| 399 void SafeBrowsingNavigationObserverManager::Observe( | 393 void SafeBrowsingNavigationObserverManager::RecordNewWebContents( |
| 400 int type, | 394 content::WebContents* source_web_contents, |
| 401 const content::NotificationSource& source, | 395 int source_render_process_id, |
| 402 const content::NotificationDetails& details) { | 396 int source_render_frame_id, |
| 403 if (type == chrome::NOTIFICATION_RETARGETING) | 397 GURL target_url, |
| 404 RecordRetargeting(details); | 398 content::WebContents* target_web_contents, |
| 405 } | 399 bool not_yet_in_tabstrip) { |
| 406 | 400 DCHECK(source_web_contents); |
| 407 void SafeBrowsingNavigationObserverManager::RecordRetargeting( | 401 DCHECK(target_web_contents); |
| 408 const content::NotificationDetails& details) { | |
| 409 const RetargetingDetails* retargeting_detail = | |
| 410 content::Details<const RetargetingDetails>(details).ptr(); | |
| 411 DCHECK(retargeting_detail); | |
| 412 content::WebContents* source_contents = | |
| 413 retargeting_detail->source_web_contents; | |
| 414 content::WebContents* target_contents = | |
| 415 retargeting_detail->target_web_contents; | |
| 416 DCHECK(source_contents); | |
| 417 DCHECK(target_contents); | |
| 418 | 402 |
| 419 content::RenderFrameHost* rfh = content::RenderFrameHost::FromID( | 403 content::RenderFrameHost* rfh = content::RenderFrameHost::FromID( |
| 420 retargeting_detail->source_render_process_id, | 404 source_render_process_id, source_render_frame_id); |
| 421 retargeting_detail->source_render_frame_id); | |
| 422 // Remove the "#" at the end of URL, since it does not point to any actual | 405 // Remove the "#" at the end of URL, since it does not point to any actual |
| 423 // page fragment ID. | 406 // page fragment ID. |
| 424 GURL target_url = SafeBrowsingNavigationObserverManager::ClearEmptyRef( | 407 GURL cleaned_target_url = |
| 425 retargeting_detail->target_url); | 408 SafeBrowsingNavigationObserverManager::ClearEmptyRef(target_url); |
| 426 | 409 |
| 427 std::unique_ptr<NavigationEvent> nav_event = | 410 std::unique_ptr<NavigationEvent> nav_event = |
| 428 base::MakeUnique<NavigationEvent>(); | 411 base::MakeUnique<NavigationEvent>(); |
| 429 if (rfh) { | 412 if (rfh) { |
| 430 nav_event->source_url = | 413 nav_event->source_url = |
| 431 SafeBrowsingNavigationObserverManager::ClearEmptyRef( | 414 SafeBrowsingNavigationObserverManager::ClearEmptyRef( |
| 432 rfh->GetLastCommittedURL()); | 415 rfh->GetLastCommittedURL()); |
| 433 } | 416 } |
| 434 nav_event->source_tab_id = SessionTabHelper::IdForTab(source_contents); | 417 nav_event->source_tab_id = SessionTabHelper::IdForTab(source_web_contents); |
| 435 nav_event->source_main_frame_url = | 418 nav_event->source_main_frame_url = |
| 436 SafeBrowsingNavigationObserverManager::ClearEmptyRef( | 419 SafeBrowsingNavigationObserverManager::ClearEmptyRef( |
| 437 source_contents->GetLastCommittedURL()); | 420 source_web_contents->GetLastCommittedURL()); |
| 438 nav_event->original_request_url = target_url; | 421 nav_event->original_request_url = cleaned_target_url; |
| 439 nav_event->target_tab_id = SessionTabHelper::IdForTab(target_contents); | 422 nav_event->target_tab_id = SessionTabHelper::IdForTab(target_web_contents); |
| 440 nav_event->frame_id = rfh ? rfh->GetFrameTreeNodeId() : -1; | 423 nav_event->frame_id = rfh ? rfh->GetFrameTreeNodeId() : -1; |
| 441 auto it = user_gesture_map_.find(source_contents); | 424 auto it = user_gesture_map_.find(source_web_contents); |
| 442 if (it != user_gesture_map_.end() && | 425 if (it != user_gesture_map_.end() && |
| 443 !SafeBrowsingNavigationObserverManager::IsUserGestureExpired( | 426 !SafeBrowsingNavigationObserverManager::IsUserGestureExpired( |
| 444 it->second)) { | 427 it->second)) { |
| 445 nav_event->is_user_initiated = true; | 428 nav_event->is_user_initiated = true; |
| 446 OnUserGestureConsumed(it->first, it->second); | 429 OnUserGestureConsumed(it->first, it->second); |
| 447 } else { | 430 } else { |
| 448 nav_event->is_user_initiated = false; | 431 nav_event->is_user_initiated = false; |
| 449 } | 432 } |
| 450 | 433 |
| 451 navigation_event_list_.RecordNavigationEvent(std::move(nav_event)); | 434 navigation_event_list_.RecordNavigationEvent(std::move(nav_event)); |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 out_result)); | 587 out_result)); |
| 605 // Stop searching if the size of out_referrer_chain already reached its | 588 // Stop searching if the size of out_referrer_chain already reached its |
| 606 // limit. | 589 // limit. |
| 607 if (out_referrer_chain->size() == kReferrerChainMaxLength) | 590 if (out_referrer_chain->size() == kReferrerChainMaxLength) |
| 608 return; | 591 return; |
| 609 last_main_frame_url_traced = last_nav_event_traced->source_main_frame_url; | 592 last_main_frame_url_traced = last_nav_event_traced->source_main_frame_url; |
| 610 } | 593 } |
| 611 } | 594 } |
| 612 | 595 |
| 613 } // namespace safe_browsing | 596 } // namespace safe_browsing |
| OLD | NEW |