OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Implementation of the SafeBrowsingBlockingPage class. | 5 // Implementation of the SafeBrowsingBlockingPage class. |
6 | 6 |
7 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" | 7 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "chrome/browser/history/history_service_factory.h" | 10 #include "chrome/browser/history/history_service_factory.h" |
11 #include "chrome/browser/interstitials/chrome_controller_client.h" | 11 #include "chrome/browser/interstitials/chrome_controller_client.h" |
12 #include "chrome/browser/interstitials/chrome_metrics_helper.h" | 12 #include "chrome/browser/interstitials/chrome_metrics_helper.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/renderer_preferences_util.h" | 14 #include "chrome/browser/renderer_preferences_util.h" |
15 #include "chrome/browser/safe_browsing/threat_details.h" | 15 #include "chrome/browser/safe_browsing/threat_details.h" |
16 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
17 #include "components/prefs/pref_service.h" | 17 #include "components/prefs/pref_service.h" |
18 #include "components/safe_browsing_db/safe_browsing_prefs.h" | 18 #include "components/safe_browsing_db/safe_browsing_prefs.h" |
19 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
20 #include "content/public/browser/interstitial_page.h" | 20 #include "content/public/browser/interstitial_page.h" |
21 #include "content/public/browser/navigation_entry.h" | 21 #include "content/public/browser/navigation_entry.h" |
22 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
23 | 23 |
24 using content::BrowserThread; | 24 using content::BrowserThread; |
25 using content::InterstitialPage; | 25 using content::InterstitialPage; |
26 using content::WebContents; | 26 using content::WebContents; |
27 using security_interstitials::SafeBrowsingErrorUI; | 27 using security_interstitials::BaseSafeBrowsingErrorUI; |
28 using security_interstitials::SecurityInterstitialControllerClient; | 28 using security_interstitials::SecurityInterstitialControllerClient; |
29 | 29 |
30 namespace safe_browsing { | 30 namespace safe_browsing { |
31 | 31 |
32 namespace { | 32 namespace { |
33 | 33 |
34 // Constants for the Experience Sampling instrumentation. | 34 // Constants for the Experience Sampling instrumentation. |
35 const char kEventNameMalware[] = "safebrowsing_interstitial_"; | 35 const char kEventNameMalware[] = "safebrowsing_interstitial_"; |
36 const char kEventNameHarmful[] = "harmful_interstitial_"; | 36 const char kEventNameHarmful[] = "harmful_interstitial_"; |
37 const char kEventNamePhishing[] = "phishing_interstitial_"; | 37 const char kEventNamePhishing[] = "phishing_interstitial_"; |
(...skipping 22 matching lines...) Expand all Loading... |
60 bool is_extended_reporting_opt_in_allowed = | 60 bool is_extended_reporting_opt_in_allowed = |
61 prefs->GetBoolean(prefs::kSafeBrowsingExtendedReportingOptInAllowed); | 61 prefs->GetBoolean(prefs::kSafeBrowsingExtendedReportingOptInAllowed); |
62 bool is_proceed_anyway_disabled = | 62 bool is_proceed_anyway_disabled = |
63 prefs->GetBoolean(prefs::kSafeBrowsingProceedAnywayDisabled); | 63 prefs->GetBoolean(prefs::kSafeBrowsingProceedAnywayDisabled); |
64 | 64 |
65 // Determine if any prefs need to be updated prior to showing the security | 65 // Determine if any prefs need to be updated prior to showing the security |
66 // interstitial. This must happen before querying IsScout to populate the | 66 // interstitial. This must happen before querying IsScout to populate the |
67 // Display Options below. | 67 // Display Options below. |
68 safe_browsing::UpdatePrefsBeforeSecurityInterstitial(prefs); | 68 safe_browsing::UpdatePrefsBeforeSecurityInterstitial(prefs); |
69 | 69 |
70 SafeBrowsingErrorUI::SBErrorDisplayOptions display_options( | 70 BaseSafeBrowsingErrorUI::SBErrorDisplayOptions display_options( |
71 BaseBlockingPage::IsMainPageLoadBlocked(unsafe_resources), | 71 BaseBlockingPage::IsMainPageLoadBlocked(unsafe_resources), |
72 is_extended_reporting_opt_in_allowed, | 72 is_extended_reporting_opt_in_allowed, |
73 web_contents->GetBrowserContext()->IsOffTheRecord(), | 73 web_contents->GetBrowserContext()->IsOffTheRecord(), |
74 IsExtendedReportingEnabled(*prefs), IsScout(*prefs), | 74 IsExtendedReportingEnabled(*prefs), IsScout(*prefs), |
75 is_proceed_anyway_disabled, | 75 is_proceed_anyway_disabled, |
76 BaseBlockingPage::IsMainPageLoadBlocked(unsafe_resources)); | 76 BaseBlockingPage::IsMainPageLoadBlocked(unsafe_resources)); |
77 | 77 |
78 return new SafeBrowsingBlockingPage(ui_manager, web_contents, | 78 return new SafeBrowsingBlockingPage(ui_manager, web_contents, |
79 main_frame_url, unsafe_resources, | 79 main_frame_url, unsafe_resources, |
80 display_options); | 80 display_options); |
(...skipping 14 matching lines...) Expand all Loading... |
95 // static | 95 // static |
96 content::InterstitialPageDelegate::TypeID | 96 content::InterstitialPageDelegate::TypeID |
97 SafeBrowsingBlockingPage::kTypeForTesting = | 97 SafeBrowsingBlockingPage::kTypeForTesting = |
98 &SafeBrowsingBlockingPage::kTypeForTesting; | 98 &SafeBrowsingBlockingPage::kTypeForTesting; |
99 | 99 |
100 SafeBrowsingBlockingPage::SafeBrowsingBlockingPage( | 100 SafeBrowsingBlockingPage::SafeBrowsingBlockingPage( |
101 BaseUIManager* ui_manager, | 101 BaseUIManager* ui_manager, |
102 WebContents* web_contents, | 102 WebContents* web_contents, |
103 const GURL& main_frame_url, | 103 const GURL& main_frame_url, |
104 const UnsafeResourceList& unsafe_resources, | 104 const UnsafeResourceList& unsafe_resources, |
105 const SafeBrowsingErrorUI::SBErrorDisplayOptions& display_options) | 105 const BaseSafeBrowsingErrorUI::SBErrorDisplayOptions& display_options) |
106 : BaseBlockingPage( | 106 : BaseBlockingPage( |
107 ui_manager, | 107 ui_manager, |
108 web_contents, | 108 web_contents, |
109 main_frame_url, | 109 main_frame_url, |
110 unsafe_resources, | 110 unsafe_resources, |
111 CreateControllerClient(web_contents, unsafe_resources, ui_manager), | 111 CreateControllerClient(web_contents, unsafe_resources, ui_manager), |
112 display_options) { | 112 display_options) { |
113 // Start computing threat details. They will be sent only | 113 // Start computing threat details. They will be sent only |
114 // if the user opts-in on the blocking page later. | 114 // if the user opts-in on the blocking page later. |
115 // If there's more than one malicious resources, it means the user | 115 // If there's more than one malicious resources, it means the user |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 SafeBrowsingBlockingPage::GetTypeForTesting() const { | 176 SafeBrowsingBlockingPage::GetTypeForTesting() const { |
177 return SafeBrowsingBlockingPage::kTypeForTesting; | 177 return SafeBrowsingBlockingPage::kTypeForTesting; |
178 } | 178 } |
179 | 179 |
180 void SafeBrowsingBlockingPage::FinishThreatDetails(const base::TimeDelta& delay, | 180 void SafeBrowsingBlockingPage::FinishThreatDetails(const base::TimeDelta& delay, |
181 bool did_proceed, | 181 bool did_proceed, |
182 int num_visits) { | 182 int num_visits) { |
183 if (threat_details_.get() == NULL) | 183 if (threat_details_.get() == NULL) |
184 return; // Not all interstitials have threat details (eg., incognito mode). | 184 return; // Not all interstitials have threat details (eg., incognito mode). |
185 | 185 |
186 const bool enabled = | 186 const bool enabled = sb_error_ui()->is_extended_reporting_enabled() && |
187 sb_error_ui()->is_extended_reporting_enabled() && | 187 sb_error_ui()->is_extended_reporting_opt_in_allowed(); |
188 sb_error_ui()->is_extended_reporting_opt_in_allowed(); | |
189 if (!enabled) | 188 if (!enabled) |
190 return; | 189 return; |
191 | 190 |
192 controller()->metrics_helper()->RecordUserInteraction( | 191 controller()->metrics_helper()->RecordUserInteraction( |
193 security_interstitials::MetricsHelper::EXTENDED_REPORTING_IS_ENABLED); | 192 security_interstitials::MetricsHelper::EXTENDED_REPORTING_IS_ENABLED); |
194 // Finish the malware details collection, send it over. | 193 // Finish the malware details collection, send it over. |
195 BrowserThread::PostDelayedTask( | 194 BrowserThread::PostDelayedTask( |
196 BrowserThread::IO, FROM_HERE, | 195 BrowserThread::IO, FROM_HERE, |
197 base::BindOnce(&ThreatDetails::FinishCollection, threat_details_, | 196 base::BindOnce(&ThreatDetails::FinishCollection, threat_details_, |
198 did_proceed, num_visits), | 197 did_proceed, num_visits), |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 unsafe_resource.GetNavigationEntryForResource(); | 233 unsafe_resource.GetNavigationEntryForResource(); |
235 SafeBrowsingBlockingPage* blocking_page = | 234 SafeBrowsingBlockingPage* blocking_page = |
236 CreateBlockingPage(ui_manager, web_contents, | 235 CreateBlockingPage(ui_manager, web_contents, |
237 entry ? entry->GetURL() : GURL(), unsafe_resource); | 236 entry ? entry->GetURL() : GURL(), unsafe_resource); |
238 blocking_page->Show(); | 237 blocking_page->Show(); |
239 } | 238 } |
240 } | 239 } |
241 | 240 |
242 // static | 241 // static |
243 std::string SafeBrowsingBlockingPage::GetSamplingEventName( | 242 std::string SafeBrowsingBlockingPage::GetSamplingEventName( |
244 SafeBrowsingErrorUI::SBInterstitialReason interstitial_reason) { | 243 BaseSafeBrowsingErrorUI::SBInterstitialReason interstitial_reason) { |
245 switch (interstitial_reason) { | 244 switch (interstitial_reason) { |
246 case SafeBrowsingErrorUI::SB_REASON_MALWARE: | 245 case BaseSafeBrowsingErrorUI::SB_REASON_MALWARE: |
247 return kEventNameMalware; | 246 return kEventNameMalware; |
248 case SafeBrowsingErrorUI::SB_REASON_HARMFUL: | 247 case BaseSafeBrowsingErrorUI::SB_REASON_HARMFUL: |
249 return kEventNameHarmful; | 248 return kEventNameHarmful; |
250 case SafeBrowsingErrorUI::SB_REASON_PHISHING: | 249 case BaseSafeBrowsingErrorUI::SB_REASON_PHISHING: |
251 return kEventNamePhishing; | 250 return kEventNamePhishing; |
252 default: | 251 default: |
253 return kEventNameOther; | 252 return kEventNameOther; |
254 } | 253 } |
255 } | 254 } |
256 | 255 |
257 // static | 256 // static |
258 std::unique_ptr<SecurityInterstitialControllerClient> | 257 std::unique_ptr<SecurityInterstitialControllerClient> |
259 SafeBrowsingBlockingPage::CreateControllerClient( | 258 SafeBrowsingBlockingPage::CreateControllerClient( |
260 WebContents* web_contents, | 259 WebContents* web_contents, |
261 const UnsafeResourceList& unsafe_resources, | 260 const UnsafeResourceList& unsafe_resources, |
262 const BaseUIManager* ui_manager) { | 261 const BaseUIManager* ui_manager) { |
263 Profile* profile = Profile::FromBrowserContext( | 262 Profile* profile = Profile::FromBrowserContext( |
264 web_contents->GetBrowserContext()); | 263 web_contents->GetBrowserContext()); |
265 DCHECK(profile); | 264 DCHECK(profile); |
266 | 265 |
267 std::unique_ptr<ChromeMetricsHelper> metrics_helper = | 266 std::unique_ptr<ChromeMetricsHelper> metrics_helper = |
268 base::MakeUnique<ChromeMetricsHelper>( | 267 base::MakeUnique<ChromeMetricsHelper>( |
269 web_contents, unsafe_resources[0].url, | 268 web_contents, unsafe_resources[0].url, |
270 GetReportingInfo(unsafe_resources), | 269 GetReportingInfo(unsafe_resources), |
271 GetSamplingEventName(GetInterstitialReason(unsafe_resources))); | 270 GetSamplingEventName(GetInterstitialReason(unsafe_resources))); |
272 | 271 |
273 return base::MakeUnique<SecurityInterstitialControllerClient>( | 272 return base::MakeUnique<SecurityInterstitialControllerClient>( |
274 web_contents, std::move(metrics_helper), profile->GetPrefs(), | 273 web_contents, std::move(metrics_helper), profile->GetPrefs(), |
275 ui_manager->app_locale(), ui_manager->default_safe_page()); | 274 ui_manager->app_locale(), ui_manager->default_safe_page()); |
276 } | 275 } |
277 | 276 |
278 } // namespace safe_browsing | 277 } // namespace safe_browsing |
OLD | NEW |