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/grit/components_resources.h" | |
12 #include "components/safe_browsing/common/safe_browsing_prefs.h" | 13 #include "components/safe_browsing/common/safe_browsing_prefs.h" |
13 #include "components/security_interstitials/content/security_interstitial_contro ller_client.h" | 14 #include "components/security_interstitials/content/security_interstitial_contro ller_client.h" |
14 #include "components/security_interstitials/core/metrics_helper.h" | 15 #include "components/security_interstitials/core/metrics_helper.h" |
15 #include "components/security_interstitials/core/safe_browsing_loud_error_ui.h" | 16 #include "components/security_interstitials/core/safe_browsing_loud_error_ui.h" |
17 #include "components/security_interstitials/core/safe_browsing_quiet_error_ui.h" | |
16 #include "content/public/browser/interstitial_page.h" | 18 #include "content/public/browser/interstitial_page.h" |
17 #include "content/public/browser/navigation_entry.h" | 19 #include "content/public/browser/navigation_entry.h" |
18 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
19 | 21 |
20 using content::InterstitialPage; | 22 using content::InterstitialPage; |
21 using content::WebContents; | 23 using content::WebContents; |
22 using security_interstitials::BaseSafeBrowsingErrorUI; | 24 using security_interstitials::BaseSafeBrowsingErrorUI; |
23 using security_interstitials::SafeBrowsingLoudErrorUI; | 25 using security_interstitials::SafeBrowsingLoudErrorUI; |
26 using security_interstitials::SafeBrowsingQuietErrorUI; | |
24 using security_interstitials::SecurityInterstitialControllerClient; | 27 using security_interstitials::SecurityInterstitialControllerClient; |
25 | 28 |
26 namespace safe_browsing { | 29 namespace safe_browsing { |
27 | 30 |
28 namespace { | 31 namespace { |
29 | 32 |
30 // After a safe browsing interstitial where the user opted-in to the report | 33 // After a safe browsing interstitial where the user opted-in to the report |
31 // but clicked "proceed anyway", we delay the call to | 34 // but clicked "proceed anyway", we delay the call to |
32 // ThreatDetails::FinishCollection() by this much time (in | 35 // ThreatDetails::FinishCollection() by this much time (in |
33 // milliseconds). | 36 // milliseconds). |
34 const int64_t kThreatDetailsProceedDelayMilliSeconds = 3000; | 37 const int64_t kThreatDetailsProceedDelayMilliSeconds = 3000; |
35 | 38 |
36 base::LazyInstance<BaseBlockingPage::UnsafeResourceMap>::Leaky | 39 base::LazyInstance<BaseBlockingPage::UnsafeResourceMap>::Leaky |
37 g_unsafe_resource_map = LAZY_INSTANCE_INITIALIZER; | 40 g_unsafe_resource_map = LAZY_INSTANCE_INITIALIZER; |
38 | 41 |
39 } // namespace | 42 } // namespace |
40 | 43 |
41 BaseBlockingPage::BaseBlockingPage( | 44 BaseBlockingPage::BaseBlockingPage( |
42 BaseUIManager* ui_manager, | 45 BaseUIManager* ui_manager, |
43 WebContents* web_contents, | 46 WebContents* web_contents, |
44 const GURL& main_frame_url, | 47 const GURL& main_frame_url, |
45 const UnsafeResourceList& unsafe_resources, | 48 const UnsafeResourceList& unsafe_resources, |
46 std::unique_ptr<SecurityInterstitialControllerClient> controller_client, | 49 std::unique_ptr<SecurityInterstitialControllerClient> controller_client, |
47 const BaseSafeBrowsingErrorUI::SBErrorDisplayOptions& display_options) | 50 const BaseSafeBrowsingErrorUI::SBErrorDisplayOptions& display_options, |
51 ErrorUiType error_type) | |
48 : SecurityInterstitialPage(web_contents, | 52 : SecurityInterstitialPage(web_contents, |
49 unsafe_resources[0].url, | 53 unsafe_resources[0].url, |
50 std::move(controller_client)), | 54 std::move(controller_client)), |
51 ui_manager_(ui_manager), | 55 ui_manager_(ui_manager), |
52 main_frame_url_(main_frame_url), | 56 main_frame_url_(main_frame_url), |
53 navigation_entry_index_to_remove_( | 57 navigation_entry_index_to_remove_( |
54 IsMainPageLoadBlocked(unsafe_resources) | 58 IsMainPageLoadBlocked(unsafe_resources) |
55 ? -1 | 59 ? -1 |
56 : web_contents->GetController().GetLastCommittedEntryIndex()), | 60 : web_contents->GetController().GetLastCommittedEntryIndex()), |
57 unsafe_resources_(unsafe_resources), | 61 unsafe_resources_(unsafe_resources), |
58 sb_error_ui_(base::MakeUnique<SafeBrowsingLoudErrorUI>( | 62 sb_error_ui_(error_type == ErrorUiType::LOUD |
Jialiu Lin
2017/05/22 17:06:00
nit: construction list is supposed to be simple. H
Nate Fischer
2017/05/22 23:13:46
Done.
| |
59 unsafe_resources_[0].url, | 63 ? static_cast<std::unique_ptr<BaseSafeBrowsingErrorUI>>( |
60 main_frame_url_, | 64 base::MakeUnique<SafeBrowsingLoudErrorUI>( |
61 GetInterstitialReason(unsafe_resources_), | 65 unsafe_resources_[0].url, |
62 display_options, | 66 main_frame_url_, |
63 ui_manager->app_locale(), | 67 GetInterstitialReason(unsafe_resources_), |
64 base::Time::NowFromSystemTime(), | 68 display_options, |
65 controller())), | 69 ui_manager->app_locale(), |
70 base::Time::NowFromSystemTime(), | |
71 controller())) | |
72 : static_cast<std::unique_ptr<BaseSafeBrowsingErrorUI>>( | |
73 base::MakeUnique<SafeBrowsingQuietErrorUI>( | |
74 unsafe_resources_[0].url, | |
75 main_frame_url_, | |
76 GetInterstitialReason(unsafe_resources_), | |
77 display_options, | |
78 ui_manager->app_locale(), | |
79 base::Time::NowFromSystemTime(), | |
80 controller(), | |
81 error_type == ErrorUiType::QUIET_GIANT))), | |
66 proceeded_(false), | 82 proceeded_(false), |
67 threat_details_proceed_delay_ms_(kThreatDetailsProceedDelayMilliSeconds) { | 83 threat_details_proceed_delay_ms_(kThreatDetailsProceedDelayMilliSeconds), |
68 } | 84 error_type_(error_type) {} |
69 | 85 |
70 BaseBlockingPage::~BaseBlockingPage() {} | 86 BaseBlockingPage::~BaseBlockingPage() {} |
71 | 87 |
72 // static | 88 // static |
73 const security_interstitials::BaseSafeBrowsingErrorUI::SBErrorDisplayOptions | 89 const security_interstitials::BaseSafeBrowsingErrorUI::SBErrorDisplayOptions |
74 BaseBlockingPage::CreateDefaultDisplayOptions( | 90 BaseBlockingPage::CreateDefaultDisplayOptions( |
75 const UnsafeResourceList& unsafe_resources) { | 91 const UnsafeResourceList& unsafe_resources) { |
76 return BaseSafeBrowsingErrorUI::SBErrorDisplayOptions( | 92 return BaseSafeBrowsingErrorUI::SBErrorDisplayOptions( |
77 IsMainPageLoadBlocked(unsafe_resources), | 93 IsMainPageLoadBlocked(unsafe_resources), |
78 false, // kSafeBrowsingExtendedReportingOptInAllowed | 94 false, // kSafeBrowsingExtendedReportingOptInAllowed |
(...skipping 19 matching lines...) Expand all Loading... | |
98 // There is no interstitial currently showing in that tab, or we are about | 114 // There is no interstitial currently showing in that tab, or we are about |
99 // to display a new one for the main frame. If there is already an | 115 // to display a new one for the main frame. If there is already an |
100 // interstitial, showing the new one will automatically hide the old one. | 116 // interstitial, showing the new one will automatically hide the old one. |
101 content::NavigationEntry* entry = | 117 content::NavigationEntry* entry = |
102 unsafe_resource.GetNavigationEntryForResource(); | 118 unsafe_resource.GetNavigationEntryForResource(); |
103 const UnsafeResourceList unsafe_resources{unsafe_resource}; | 119 const UnsafeResourceList unsafe_resources{unsafe_resource}; |
104 BaseBlockingPage* blocking_page = new BaseBlockingPage( | 120 BaseBlockingPage* blocking_page = new BaseBlockingPage( |
105 ui_manager, web_contents, entry ? entry->GetURL() : GURL(), | 121 ui_manager, web_contents, entry ? entry->GetURL() : GURL(), |
106 unsafe_resources, | 122 unsafe_resources, |
107 CreateControllerClient(web_contents, unsafe_resources, ui_manager), | 123 CreateControllerClient(web_contents, unsafe_resources, ui_manager), |
108 CreateDefaultDisplayOptions(unsafe_resources)); | 124 CreateDefaultDisplayOptions(unsafe_resources), ErrorUiType::LOUD); |
109 blocking_page->Show(); | 125 blocking_page->Show(); |
110 } | 126 } |
111 } | 127 } |
112 | 128 |
113 // static | 129 // static |
114 bool BaseBlockingPage::IsMainPageLoadBlocked( | 130 bool BaseBlockingPage::IsMainPageLoadBlocked( |
115 const UnsafeResourceList& unsafe_resources) { | 131 const UnsafeResourceList& unsafe_resources) { |
116 // If there is more than one unsafe resource, the main page load must not be | 132 // If there is more than one unsafe resource, the main page load must not be |
117 // blocked. Otherwise, check if the one resource is. | 133 // blocked. Otherwise, check if the one resource is. |
118 return unsafe_resources.size() == 1 && | 134 return unsafe_resources.size() == 1 && |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
343 std::unique_ptr<security_interstitials::MetricsHelper> metrics_helper = | 359 std::unique_ptr<security_interstitials::MetricsHelper> metrics_helper = |
344 base::MakeUnique<security_interstitials::MetricsHelper>( | 360 base::MakeUnique<security_interstitials::MetricsHelper>( |
345 unsafe_resources[0].url, GetReportingInfo(unsafe_resources), | 361 unsafe_resources[0].url, GetReportingInfo(unsafe_resources), |
346 history_service); | 362 history_service); |
347 | 363 |
348 return base::MakeUnique<SecurityInterstitialControllerClient>( | 364 return base::MakeUnique<SecurityInterstitialControllerClient>( |
349 web_contents, std::move(metrics_helper), nullptr, /* prefs */ | 365 web_contents, std::move(metrics_helper), nullptr, /* prefs */ |
350 ui_manager->app_locale(), ui_manager->default_safe_page()); | 366 ui_manager->app_locale(), ui_manager->default_safe_page()); |
351 } | 367 } |
352 | 368 |
369 int BaseBlockingPage::GetHTMLTemplateId() { | |
370 return error_type_ == ErrorUiType::LOUD | |
371 ? IDR_SECURITY_INTERSTITIAL_HTML | |
372 : IDR_SECURITY_INTERSTITIAL_QUIET_HTML; | |
373 } | |
374 | |
353 } // namespace safe_browsing | 375 } // namespace safe_browsing |
OLD | NEW |