OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "components/safe_browsing/base_blocking_page.h" | 5 #include "components/safe_browsing/base_blocking_page.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
12 #include "components/safe_browsing_db/safe_browsing_prefs.h" | 12 #include "components/safe_browsing_db/safe_browsing_prefs.h" |
13 #include "components/security_interstitials/content/security_interstitial_contro
ller_client.h" | 13 #include "components/security_interstitials/content/security_interstitial_contro
ller_client.h" |
14 #include "components/security_interstitials/core/metrics_helper.h" | 14 #include "components/security_interstitials/core/metrics_helper.h" |
15 #include "content/public/browser/interstitial_page.h" | 15 #include "content/public/browser/interstitial_page.h" |
16 #include "content/public/browser/navigation_entry.h" | 16 #include "content/public/browser/navigation_entry.h" |
17 #include "content/public/browser/user_metrics.h" | 17 #include "content/public/browser/user_metrics.h" |
18 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
19 | 19 |
20 using base::UserMetricsAction; | 20 using base::UserMetricsAction; |
21 using content::InterstitialPage; | 21 using content::InterstitialPage; |
22 using content::WebContents; | 22 using content::WebContents; |
23 using security_interstitials::SafeBrowsingErrorUI; | 23 using security_interstitials::SafeBrowsingErrorUI; |
24 using security_interstitials::SecurityInterstitialControllerClient; | 24 using security_interstitials::SecurityInterstitialControllerClient; |
25 | 25 |
26 namespace safe_browsing { | 26 namespace safe_browsing { |
27 | 27 |
28 namespace { | 28 namespace { |
29 | 29 |
| 30 // After a safe browsing interstitial where the user opted-in to the report |
| 31 // but clicked "proceed anyway", we delay the call to |
| 32 // ThreatDetails::FinishCollection() by this much time (in |
| 33 // milliseconds). |
| 34 const int64_t kThreatDetailsProceedDelayMilliSeconds = 3000; |
| 35 |
30 base::LazyInstance<BaseBlockingPage::UnsafeResourceMap>::Leaky | 36 base::LazyInstance<BaseBlockingPage::UnsafeResourceMap>::Leaky |
31 g_unsafe_resource_map = LAZY_INSTANCE_INITIALIZER; | 37 g_unsafe_resource_map = LAZY_INSTANCE_INITIALIZER; |
32 | 38 |
33 } // namespace | 39 } // namespace |
34 | 40 |
35 BaseBlockingPage::BaseBlockingPage( | 41 BaseBlockingPage::BaseBlockingPage( |
36 BaseUIManager* ui_manager, | 42 BaseUIManager* ui_manager, |
37 WebContents* web_contents, | 43 WebContents* web_contents, |
38 const GURL& main_frame_url, | 44 const GURL& main_frame_url, |
39 const UnsafeResourceList& unsafe_resources, | 45 const UnsafeResourceList& unsafe_resources, |
40 std::unique_ptr<SecurityInterstitialControllerClient> controller_client, | 46 std::unique_ptr<SecurityInterstitialControllerClient> controller_client, |
41 const SafeBrowsingErrorUI::SBErrorDisplayOptions& display_options) | 47 const SafeBrowsingErrorUI::SBErrorDisplayOptions& display_options) |
42 : SecurityInterstitialPage(web_contents, | 48 : SecurityInterstitialPage(web_contents, |
43 unsafe_resources[0].url, | 49 unsafe_resources[0].url, |
44 std::move(controller_client)), | 50 std::move(controller_client)), |
45 ui_manager_(ui_manager), | 51 ui_manager_(ui_manager), |
46 main_frame_url_(main_frame_url), | 52 main_frame_url_(main_frame_url), |
47 navigation_entry_index_to_remove_( | 53 navigation_entry_index_to_remove_( |
48 IsMainPageLoadBlocked(unsafe_resources) ? | 54 IsMainPageLoadBlocked(unsafe_resources) |
49 -1 : | 55 ? -1 |
50 web_contents->GetController().GetLastCommittedEntryIndex()), | 56 : web_contents->GetController().GetLastCommittedEntryIndex()), |
51 unsafe_resources_(unsafe_resources), | 57 unsafe_resources_(unsafe_resources), |
52 sb_error_ui_(base::MakeUnique<SafeBrowsingErrorUI>( | 58 sb_error_ui_(base::MakeUnique<SafeBrowsingErrorUI>( |
53 unsafe_resources_[0].url, main_frame_url_, | 59 unsafe_resources_[0].url, |
54 GetInterstitialReason(unsafe_resources_), | 60 main_frame_url_, |
55 display_options, | 61 GetInterstitialReason(unsafe_resources_), |
56 ui_manager->app_locale(), | 62 display_options, |
57 base::Time::NowFromSystemTime(), | 63 ui_manager->app_locale(), |
58 controller())), | 64 base::Time::NowFromSystemTime(), |
59 proceeded_(false) {} | 65 controller())), |
| 66 proceeded_(false), |
| 67 threat_details_proceed_delay_ms_(kThreatDetailsProceedDelayMilliSeconds) { |
| 68 } |
60 | 69 |
61 BaseBlockingPage::~BaseBlockingPage() {} | 70 BaseBlockingPage::~BaseBlockingPage() {} |
62 | 71 |
63 // static | 72 // static |
64 const SafeBrowsingErrorUI::SBErrorDisplayOptions | 73 const SafeBrowsingErrorUI::SBErrorDisplayOptions |
65 BaseBlockingPage::CreateDefaultDisplayOptions() { | 74 BaseBlockingPage::CreateDefaultDisplayOptions() { |
66 return SafeBrowsingErrorUI::SBErrorDisplayOptions( | 75 return SafeBrowsingErrorUI::SBErrorDisplayOptions( |
67 true, // IsMainPageLoadBlocked() | 76 true, // IsMainPageLoadBlocked() |
68 false, // kSafeBrowsingExtendedReportingOptInAllowed | 77 false, // kSafeBrowsingExtendedReportingOptInAllowed |
69 false, // is_off_the_record | 78 false, // is_off_the_record |
70 false, // is_extended_reporting | 79 false, // is_extended_reporting |
71 false, // is_scout | 80 false, // is_scout |
72 false); // kSafeBrowsingProceedAnywayDisabled | 81 false); // kSafeBrowsingProceedAnywayDisabled |
73 } | 82 } |
74 | 83 |
75 // static | 84 // static |
76 void BaseBlockingPage::ShowBlockingPage( | 85 void BaseBlockingPage::ShowBlockingPage( |
77 BaseUIManager* ui_manager, | 86 BaseUIManager* ui_manager, |
78 const UnsafeResource& unsafe_resource) { | 87 const UnsafeResource& unsafe_resource) { |
79 WebContents* web_contents = unsafe_resource.web_contents_getter.Run(); | 88 WebContents* web_contents = unsafe_resource.web_contents_getter.Run(); |
80 | 89 |
81 if (!InterstitialPage::GetInterstitialPage(web_contents) || | 90 if (InterstitialPage::GetInterstitialPage(web_contents) && |
82 !unsafe_resource.is_subresource) { | 91 unsafe_resource.is_subresource) { |
| 92 // This is an interstitial for a page's resource, let's queue it. |
| 93 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); |
| 94 (*unsafe_resource_map)[web_contents].push_back(unsafe_resource); |
| 95 } else { |
83 // There is no interstitial currently showing in that tab, or we are about | 96 // There is no interstitial currently showing in that tab, or we are about |
84 // to display a new one for the main frame. If there is already an | 97 // to display a new one for the main frame. If there is already an |
85 // interstitial, showing the new one will automatically hide the old one. | 98 // interstitial, showing the new one will automatically hide the old one. |
86 content::NavigationEntry* entry = | 99 content::NavigationEntry* entry = |
87 unsafe_resource.GetNavigationEntryForResource(); | 100 unsafe_resource.GetNavigationEntryForResource(); |
88 const UnsafeResourceList resources{unsafe_resource}; | 101 const UnsafeResourceList unsafe_resources{unsafe_resource}; |
89 BaseBlockingPage* blocking_page = | 102 BaseBlockingPage* blocking_page = new BaseBlockingPage( |
90 new BaseBlockingPage( | 103 ui_manager, web_contents, entry ? entry->GetURL() : GURL(), |
91 ui_manager, web_contents, | 104 unsafe_resources, |
92 entry ? entry->GetURL() : GURL(), | 105 CreateControllerClient(web_contents, unsafe_resources, ui_manager), |
93 resources, | 106 CreateDefaultDisplayOptions()); |
94 CreateControllerClient( | |
95 web_contents, resources, | |
96 ui_manager->history_service(web_contents), | |
97 ui_manager->app_locale(), | |
98 ui_manager->default_safe_page()), | |
99 CreateDefaultDisplayOptions()); | |
100 blocking_page->Show(); | 107 blocking_page->Show(); |
101 return; | |
102 } | 108 } |
103 | |
104 // This is an interstitial for a page's resource, let's queue it. | |
105 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); | |
106 (*unsafe_resource_map)[web_contents].push_back(unsafe_resource); | |
107 } | 109 } |
108 | 110 |
109 // static | 111 // static |
110 bool BaseBlockingPage::IsMainPageLoadBlocked( | 112 bool BaseBlockingPage::IsMainPageLoadBlocked( |
111 const UnsafeResourceList& unsafe_resources) { | 113 const UnsafeResourceList& unsafe_resources) { |
112 // If there is more than one unsafe resource, the main page load must not be | 114 // If there is more than one unsafe resource, the main page load must not be |
113 // blocked. Otherwise, check if the one resource is. | 115 // blocked. Otherwise, check if the one resource is. |
114 return unsafe_resources.size() == 1 && | 116 return unsafe_resources.size() == 1 && |
115 unsafe_resources[0].IsMainPageLoadBlocked(); | 117 unsafe_resources[0].IsMainPageLoadBlocked(); |
116 } | 118 } |
117 | 119 |
118 void BaseBlockingPage::OnProceed() { | 120 void BaseBlockingPage::OnProceed() { |
119 proceeded_ = true; | 121 set_proceeded(true); |
| 122 UpdateMetricsAfterSecurityInterstitial(); |
| 123 |
| 124 // Send the threat details, if we opted to. |
| 125 FinishThreatDetails( |
| 126 base::TimeDelta::FromMilliseconds(threat_details_proceed_delay_ms_), |
| 127 true, /* did_proceed */ |
| 128 controller()->metrics_helper()->NumVisits()); |
120 | 129 |
121 ui_manager_->OnBlockingPageDone(unsafe_resources_, true /* proceed */, | 130 ui_manager_->OnBlockingPageDone(unsafe_resources_, true /* proceed */, |
122 web_contents(), main_frame_url_); | 131 web_contents(), main_frame_url_); |
| 132 |
| 133 HandleSubresourcesAfterProceed(); |
| 134 } |
| 135 |
| 136 void BaseBlockingPage::HandleSubresourcesAfterProceed() {} |
| 137 |
| 138 void BaseBlockingPage::SetThreatDetailsProceedDelayForTesting(int64_t delay) { |
| 139 threat_details_proceed_delay_ms_ = delay; |
123 } | 140 } |
124 | 141 |
125 void BaseBlockingPage::OnDontProceed() { | 142 void BaseBlockingPage::OnDontProceed() { |
126 // We could have already called Proceed(), in which case we must not notify | 143 // We could have already called Proceed(), in which case we must not notify |
127 // the SafeBrowsingUIManager again, as the client has been deleted. | 144 // the SafeBrowsingUIManager again, as the client has been deleted. |
128 if (proceeded_) | 145 if (proceeded_) |
129 return; | 146 return; |
130 | 147 |
131 UpdateMetricsAfterSecurityInterstitial(); | 148 UpdateMetricsAfterSecurityInterstitial(); |
132 if (!sb_error_ui_->is_proceed_anyway_disabled()) { | 149 if (!sb_error_ui_->is_proceed_anyway_disabled()) { |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 | 310 |
294 SafeBrowsingErrorUI* BaseBlockingPage::sb_error_ui() const { | 311 SafeBrowsingErrorUI* BaseBlockingPage::sb_error_ui() const { |
295 return sb_error_ui_.get(); | 312 return sb_error_ui_.get(); |
296 } | 313 } |
297 | 314 |
298 void BaseBlockingPage::set_proceeded(bool proceeded) { | 315 void BaseBlockingPage::set_proceeded(bool proceeded) { |
299 proceeded_ = proceeded; | 316 proceeded_ = proceeded; |
300 } | 317 } |
301 | 318 |
302 // static | 319 // static |
| 320 security_interstitials::MetricsHelper::ReportDetails |
| 321 BaseBlockingPage::GetReportingInfo(const UnsafeResourceList& unsafe_resources) { |
| 322 SafeBrowsingErrorUI::SBInterstitialReason interstitial_reason = |
| 323 GetInterstitialReason(unsafe_resources); |
| 324 |
| 325 security_interstitials::MetricsHelper::ReportDetails reporting_info; |
| 326 reporting_info.metric_prefix = |
| 327 GetMetricPrefix(unsafe_resources, interstitial_reason); |
| 328 reporting_info.extra_suffix = GetExtraMetricsSuffix(unsafe_resources); |
| 329 return reporting_info; |
| 330 } |
| 331 |
| 332 // static |
303 std::unique_ptr<SecurityInterstitialControllerClient> | 333 std::unique_ptr<SecurityInterstitialControllerClient> |
304 BaseBlockingPage::CreateControllerClient( | 334 BaseBlockingPage::CreateControllerClient( |
305 content::WebContents* web_contents, | 335 content::WebContents* web_contents, |
306 const UnsafeResourceList& unsafe_resources, | 336 const UnsafeResourceList& unsafe_resources, |
307 history::HistoryService* history_service, | 337 BaseUIManager* ui_manager) { |
308 const std::string& app_locale, | 338 history::HistoryService* history_service = |
309 const GURL& default_safe_page) { | 339 ui_manager->history_service(web_contents); |
310 SafeBrowsingErrorUI::SBInterstitialReason interstitial_reason = | |
311 GetInterstitialReason(unsafe_resources); | |
312 security_interstitials::MetricsHelper::ReportDetails reporting_info; | |
313 reporting_info.metric_prefix = | |
314 GetMetricPrefix(unsafe_resources, interstitial_reason); | |
315 reporting_info.extra_suffix = GetExtraMetricsSuffix(unsafe_resources); | |
316 | 340 |
317 std::unique_ptr<security_interstitials::MetricsHelper> metrics_helper = | 341 std::unique_ptr<security_interstitials::MetricsHelper> metrics_helper = |
318 base::MakeUnique<security_interstitials::MetricsHelper>( | 342 base::MakeUnique<security_interstitials::MetricsHelper>( |
319 unsafe_resources[0].url, reporting_info, history_service); | 343 unsafe_resources[0].url, GetReportingInfo(unsafe_resources), |
| 344 history_service); |
320 | 345 |
321 return base::MakeUnique<SecurityInterstitialControllerClient>( | 346 return base::MakeUnique<SecurityInterstitialControllerClient>( |
322 web_contents, std::move(metrics_helper), nullptr, app_locale, | 347 web_contents, std::move(metrics_helper), nullptr, /* prefs */ |
323 default_safe_page); | 348 ui_manager->app_locale(), ui_manager->default_safe_page()); |
324 } | 349 } |
325 | 350 |
326 } // namespace safe_browsing | 351 } // namespace safe_browsing |
OLD | NEW |