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