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 "components/security_interstitials/core/safe_browsing_loud_error_ui.h" | |
felt
2017/05/05 00:28:29
include?
edwardjung
2017/05/08 20:43:00
I need to include it as I'm using it below
| |
15 #include "content/public/browser/interstitial_page.h" | 16 #include "content/public/browser/interstitial_page.h" |
16 #include "content/public/browser/navigation_entry.h" | 17 #include "content/public/browser/navigation_entry.h" |
17 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
18 | 19 |
19 using content::InterstitialPage; | 20 using content::InterstitialPage; |
20 using content::WebContents; | 21 using content::WebContents; |
21 using security_interstitials::SafeBrowsingErrorUI; | 22 using security_interstitials::BaseSafeBrowsingErrorUI; |
23 using security_interstitials::SafeBrowsingLoudErrorUI; | |
22 using security_interstitials::SecurityInterstitialControllerClient; | 24 using security_interstitials::SecurityInterstitialControllerClient; |
23 | 25 |
24 namespace safe_browsing { | 26 namespace safe_browsing { |
25 | 27 |
26 namespace { | 28 namespace { |
27 | 29 |
28 // After a safe browsing interstitial where the user opted-in to the report | 30 // After a safe browsing interstitial where the user opted-in to the report |
29 // but clicked "proceed anyway", we delay the call to | 31 // but clicked "proceed anyway", we delay the call to |
30 // ThreatDetails::FinishCollection() by this much time (in | 32 // ThreatDetails::FinishCollection() by this much time (in |
31 // milliseconds). | 33 // milliseconds). |
32 const int64_t kThreatDetailsProceedDelayMilliSeconds = 3000; | 34 const int64_t kThreatDetailsProceedDelayMilliSeconds = 3000; |
33 | 35 |
34 base::LazyInstance<BaseBlockingPage::UnsafeResourceMap>::Leaky | 36 base::LazyInstance<BaseBlockingPage::UnsafeResourceMap>::Leaky |
35 g_unsafe_resource_map = LAZY_INSTANCE_INITIALIZER; | 37 g_unsafe_resource_map = LAZY_INSTANCE_INITIALIZER; |
36 | 38 |
37 } // namespace | 39 } // namespace |
38 | 40 |
39 BaseBlockingPage::BaseBlockingPage( | 41 BaseBlockingPage::BaseBlockingPage( |
40 BaseUIManager* ui_manager, | 42 BaseUIManager* ui_manager, |
41 WebContents* web_contents, | 43 WebContents* web_contents, |
42 const GURL& main_frame_url, | 44 const GURL& main_frame_url, |
43 const UnsafeResourceList& unsafe_resources, | 45 const UnsafeResourceList& unsafe_resources, |
44 std::unique_ptr<SecurityInterstitialControllerClient> controller_client, | 46 std::unique_ptr<SecurityInterstitialControllerClient> controller_client, |
45 const SafeBrowsingErrorUI::SBErrorDisplayOptions& display_options) | 47 const BaseSafeBrowsingErrorUI::SBErrorDisplayOptions& display_options) |
46 : SecurityInterstitialPage(web_contents, | 48 : SecurityInterstitialPage(web_contents, |
47 unsafe_resources[0].url, | 49 unsafe_resources[0].url, |
48 std::move(controller_client)), | 50 std::move(controller_client)), |
49 ui_manager_(ui_manager), | 51 ui_manager_(ui_manager), |
50 main_frame_url_(main_frame_url), | 52 main_frame_url_(main_frame_url), |
51 navigation_entry_index_to_remove_( | 53 navigation_entry_index_to_remove_( |
52 IsMainPageLoadBlocked(unsafe_resources) | 54 IsMainPageLoadBlocked(unsafe_resources) |
53 ? -1 | 55 ? -1 |
54 : web_contents->GetController().GetLastCommittedEntryIndex()), | 56 : web_contents->GetController().GetLastCommittedEntryIndex()), |
55 unsafe_resources_(unsafe_resources), | 57 unsafe_resources_(unsafe_resources), |
56 sb_error_ui_(base::MakeUnique<SafeBrowsingErrorUI>( | 58 sb_error_ui_(base::MakeUnique<SafeBrowsingLoudErrorUI>( |
felt
2017/05/05 00:28:29
Is this where it's crashing?
| |
57 unsafe_resources_[0].url, | 59 unsafe_resources_[0].url, |
58 main_frame_url_, | 60 main_frame_url_, |
59 GetInterstitialReason(unsafe_resources_), | 61 GetInterstitialReason(unsafe_resources_), |
60 display_options, | 62 display_options, |
61 ui_manager->app_locale(), | 63 ui_manager->app_locale(), |
62 base::Time::NowFromSystemTime(), | 64 base::Time::NowFromSystemTime(), |
63 controller())), | 65 controller())), |
64 proceeded_(false), | 66 proceeded_(false), |
65 threat_details_proceed_delay_ms_(kThreatDetailsProceedDelayMilliSeconds) { | 67 threat_details_proceed_delay_ms_(kThreatDetailsProceedDelayMilliSeconds) { |
66 } | 68 } |
67 | 69 |
68 BaseBlockingPage::~BaseBlockingPage() {} | 70 BaseBlockingPage::~BaseBlockingPage() {} |
69 | 71 |
70 // static | 72 // static |
71 const SafeBrowsingErrorUI::SBErrorDisplayOptions | 73 const security_interstitials::BaseSafeBrowsingErrorUI::SBErrorDisplayOptions |
72 BaseBlockingPage::CreateDefaultDisplayOptions( | 74 BaseBlockingPage::CreateDefaultDisplayOptions( |
73 const UnsafeResourceList& unsafe_resources) { | 75 const UnsafeResourceList& unsafe_resources) { |
74 return SafeBrowsingErrorUI::SBErrorDisplayOptions( | 76 return BaseSafeBrowsingErrorUI::SBErrorDisplayOptions( |
75 IsMainPageLoadBlocked(unsafe_resources), | 77 IsMainPageLoadBlocked(unsafe_resources), |
76 false, // kSafeBrowsingExtendedReportingOptInAllowed | 78 false, // kSafeBrowsingExtendedReportingOptInAllowed |
77 false, // is_off_the_record | 79 false, // is_off_the_record |
78 false, // is_extended_reporting | 80 false, // is_extended_reporting |
79 false, // is_scout | 81 false, // is_scout |
80 false, // kSafeBrowsingProceedAnywayDisabled | 82 false, // kSafeBrowsingProceedAnywayDisabled |
81 true); // is_resource_cancellable | 83 true); // is_resource_cancellable |
82 } | 84 } |
83 | 85 |
84 // static | 86 // static |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
215 | 217 |
216 // static | 218 // static |
217 BaseBlockingPage::UnsafeResourceMap* | 219 BaseBlockingPage::UnsafeResourceMap* |
218 BaseBlockingPage::GetUnsafeResourcesMap() { | 220 BaseBlockingPage::GetUnsafeResourcesMap() { |
219 return g_unsafe_resource_map.Pointer(); | 221 return g_unsafe_resource_map.Pointer(); |
220 } | 222 } |
221 | 223 |
222 // static | 224 // static |
223 std::string BaseBlockingPage::GetMetricPrefix( | 225 std::string BaseBlockingPage::GetMetricPrefix( |
224 const UnsafeResourceList& unsafe_resources, | 226 const UnsafeResourceList& unsafe_resources, |
225 SafeBrowsingErrorUI::SBInterstitialReason interstitial_reason) { | 227 BaseSafeBrowsingErrorUI::SBInterstitialReason interstitial_reason) { |
226 bool primary_subresource = unsafe_resources[0].is_subresource; | 228 bool primary_subresource = unsafe_resources[0].is_subresource; |
227 switch (interstitial_reason) { | 229 switch (interstitial_reason) { |
228 case SafeBrowsingErrorUI::SB_REASON_MALWARE: | 230 case BaseSafeBrowsingErrorUI::SB_REASON_MALWARE: |
229 return primary_subresource ? "malware_subresource" : "malware"; | 231 return primary_subresource ? "malware_subresource" : "malware"; |
230 case SafeBrowsingErrorUI::SB_REASON_HARMFUL: | 232 case BaseSafeBrowsingErrorUI::SB_REASON_HARMFUL: |
231 return primary_subresource ? "harmful_subresource" : "harmful"; | 233 return primary_subresource ? "harmful_subresource" : "harmful"; |
232 case SafeBrowsingErrorUI::SB_REASON_PHISHING: | 234 case BaseSafeBrowsingErrorUI::SB_REASON_PHISHING: |
233 ThreatPatternType threat_pattern_type = | 235 ThreatPatternType threat_pattern_type = |
234 unsafe_resources[0].threat_metadata.threat_pattern_type; | 236 unsafe_resources[0].threat_metadata.threat_pattern_type; |
235 if (threat_pattern_type == ThreatPatternType::PHISHING || | 237 if (threat_pattern_type == ThreatPatternType::PHISHING || |
236 threat_pattern_type == ThreatPatternType::NONE) | 238 threat_pattern_type == ThreatPatternType::NONE) |
237 return primary_subresource ? "phishing_subresource" : "phishing"; | 239 return primary_subresource ? "phishing_subresource" : "phishing"; |
238 else if (threat_pattern_type == ThreatPatternType::SOCIAL_ENGINEERING_ADS) | 240 else if (threat_pattern_type == ThreatPatternType::SOCIAL_ENGINEERING_ADS) |
239 return primary_subresource ? "social_engineering_ads_subresource" | 241 return primary_subresource ? "social_engineering_ads_subresource" |
240 : "social_engineering_ads"; | 242 : "social_engineering_ads"; |
241 else if (threat_pattern_type == | 243 else if (threat_pattern_type == |
242 ThreatPatternType::SOCIAL_ENGINEERING_LANDING) | 244 ThreatPatternType::SOCIAL_ENGINEERING_LANDING) |
(...skipping 21 matching lines...) Expand all Loading... | |
264 case safe_browsing::ThreatSource::CLIENT_SIDE_DETECTION: | 266 case safe_browsing::ThreatSource::CLIENT_SIDE_DETECTION: |
265 return "from_client_side_detection"; | 267 return "from_client_side_detection"; |
266 case safe_browsing::ThreatSource::UNKNOWN: | 268 case safe_browsing::ThreatSource::UNKNOWN: |
267 break; | 269 break; |
268 } | 270 } |
269 NOTREACHED(); | 271 NOTREACHED(); |
270 return std::string(); | 272 return std::string(); |
271 } | 273 } |
272 | 274 |
273 // static | 275 // static |
274 SafeBrowsingErrorUI::SBInterstitialReason | 276 security_interstitials::BaseSafeBrowsingErrorUI::SBInterstitialReason |
275 BaseBlockingPage::GetInterstitialReason( | 277 BaseBlockingPage::GetInterstitialReason( |
276 const UnsafeResourceList& unsafe_resources) { | 278 const UnsafeResourceList& unsafe_resources) { |
277 bool harmful = false; | 279 bool harmful = false; |
278 for (UnsafeResourceList::const_iterator iter = unsafe_resources.begin(); | 280 for (UnsafeResourceList::const_iterator iter = unsafe_resources.begin(); |
279 iter != unsafe_resources.end(); ++iter) { | 281 iter != unsafe_resources.end(); ++iter) { |
280 const BaseUIManager::UnsafeResource& resource = *iter; | 282 const BaseUIManager::UnsafeResource& resource = *iter; |
281 safe_browsing::SBThreatType threat_type = resource.threat_type; | 283 safe_browsing::SBThreatType threat_type = resource.threat_type; |
282 if (threat_type == SB_THREAT_TYPE_URL_MALWARE || | 284 if (threat_type == SB_THREAT_TYPE_URL_MALWARE || |
283 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL) { | 285 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL) { |
284 return SafeBrowsingErrorUI::SB_REASON_MALWARE; | 286 return BaseSafeBrowsingErrorUI::SB_REASON_MALWARE; |
285 } else if (threat_type == SB_THREAT_TYPE_URL_UNWANTED) { | 287 } else if (threat_type == SB_THREAT_TYPE_URL_UNWANTED) { |
286 harmful = true; | 288 harmful = true; |
287 } else { | 289 } else { |
288 DCHECK(threat_type == SB_THREAT_TYPE_URL_PHISHING || | 290 DCHECK(threat_type == SB_THREAT_TYPE_URL_PHISHING || |
289 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL); | 291 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL); |
290 } | 292 } |
291 } | 293 } |
292 | 294 |
293 if (harmful) | 295 if (harmful) |
294 return SafeBrowsingErrorUI::SB_REASON_HARMFUL; | 296 return BaseSafeBrowsingErrorUI::SB_REASON_HARMFUL; |
295 return SafeBrowsingErrorUI::SB_REASON_PHISHING; | 297 return BaseSafeBrowsingErrorUI::SB_REASON_PHISHING; |
296 } | 298 } |
297 | 299 |
298 BaseUIManager* BaseBlockingPage::ui_manager() const { | 300 BaseUIManager* BaseBlockingPage::ui_manager() const { |
299 return ui_manager_; | 301 return ui_manager_; |
300 } | 302 } |
301 | 303 |
302 const GURL BaseBlockingPage::main_frame_url() const { | 304 const GURL BaseBlockingPage::main_frame_url() const { |
303 return main_frame_url_; | 305 return main_frame_url_; |
304 } | 306 } |
305 | 307 |
306 BaseBlockingPage::UnsafeResourceList | 308 BaseBlockingPage::UnsafeResourceList |
307 BaseBlockingPage::unsafe_resources() const { | 309 BaseBlockingPage::unsafe_resources() const { |
308 return unsafe_resources_; | 310 return unsafe_resources_; |
309 } | 311 } |
310 | 312 |
311 SafeBrowsingErrorUI* BaseBlockingPage::sb_error_ui() const { | 313 BaseSafeBrowsingErrorUI* BaseBlockingPage::sb_error_ui() const { |
312 return sb_error_ui_.get(); | 314 return sb_error_ui_.get(); |
313 } | 315 } |
314 | 316 |
315 void BaseBlockingPage::set_proceeded(bool proceeded) { | 317 void BaseBlockingPage::set_proceeded(bool proceeded) { |
316 proceeded_ = proceeded; | 318 proceeded_ = proceeded; |
317 } | 319 } |
318 | 320 |
319 // static | 321 // static |
320 security_interstitials::MetricsHelper::ReportDetails | 322 security_interstitials::MetricsHelper::ReportDetails |
321 BaseBlockingPage::GetReportingInfo(const UnsafeResourceList& unsafe_resources) { | 323 BaseBlockingPage::GetReportingInfo(const UnsafeResourceList& unsafe_resources) { |
322 SafeBrowsingErrorUI::SBInterstitialReason interstitial_reason = | 324 BaseSafeBrowsingErrorUI::SBInterstitialReason interstitial_reason = |
323 GetInterstitialReason(unsafe_resources); | 325 GetInterstitialReason(unsafe_resources); |
324 | 326 |
325 security_interstitials::MetricsHelper::ReportDetails reporting_info; | 327 security_interstitials::MetricsHelper::ReportDetails reporting_info; |
326 reporting_info.metric_prefix = | 328 reporting_info.metric_prefix = |
327 GetMetricPrefix(unsafe_resources, interstitial_reason); | 329 GetMetricPrefix(unsafe_resources, interstitial_reason); |
328 reporting_info.extra_suffix = GetExtraMetricsSuffix(unsafe_resources); | 330 reporting_info.extra_suffix = GetExtraMetricsSuffix(unsafe_resources); |
329 return reporting_info; | 331 return reporting_info; |
330 } | 332 } |
331 | 333 |
332 // static | 334 // static |
333 std::unique_ptr<SecurityInterstitialControllerClient> | 335 std::unique_ptr<SecurityInterstitialControllerClient> |
334 BaseBlockingPage::CreateControllerClient( | 336 BaseBlockingPage::CreateControllerClient( |
335 content::WebContents* web_contents, | 337 content::WebContents* web_contents, |
336 const UnsafeResourceList& unsafe_resources, | 338 const UnsafeResourceList& unsafe_resources, |
337 BaseUIManager* ui_manager) { | 339 BaseUIManager* ui_manager) { |
338 history::HistoryService* history_service = | 340 history::HistoryService* history_service = |
339 ui_manager->history_service(web_contents); | 341 ui_manager->history_service(web_contents); |
340 | 342 |
341 std::unique_ptr<security_interstitials::MetricsHelper> metrics_helper = | 343 std::unique_ptr<security_interstitials::MetricsHelper> metrics_helper = |
342 base::MakeUnique<security_interstitials::MetricsHelper>( | 344 base::MakeUnique<security_interstitials::MetricsHelper>( |
343 unsafe_resources[0].url, GetReportingInfo(unsafe_resources), | 345 unsafe_resources[0].url, GetReportingInfo(unsafe_resources), |
344 history_service); | 346 history_service); |
345 | 347 |
346 return base::MakeUnique<SecurityInterstitialControllerClient>( | 348 return base::MakeUnique<SecurityInterstitialControllerClient>( |
347 web_contents, std::move(metrics_helper), nullptr, /* prefs */ | 349 web_contents, std::move(metrics_helper), nullptr, /* prefs */ |
348 ui_manager->app_locale(), ui_manager->default_safe_page()); | 350 ui_manager->app_locale(), ui_manager->default_safe_page()); |
349 } | 351 } |
350 | 352 |
351 } // namespace safe_browsing | 353 } // namespace safe_browsing |
OLD | NEW |