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 <string> | 9 #include <string> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/i18n/rtl.h" | |
14 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
15 #include "base/macros.h" | 14 #include "base/macros.h" |
16 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
17 #include "base/metrics/field_trial.h" | |
18 #include "base/metrics/histogram_macros.h" | |
19 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
20 #include "base/strings/string_piece.h" | |
21 #include "base/strings/stringprintf.h" | |
22 #include "base/strings/utf_string_conversions.h" | |
23 #include "base/time/time.h" | 17 #include "base/time/time.h" |
24 #include "base/values.h" | 18 #include "base/values.h" |
25 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
26 #include "chrome/browser/interstitials/chrome_controller_client.h" | 20 #include "chrome/browser/interstitials/chrome_controller_client.h" |
27 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
28 #include "chrome/browser/renderer_preferences_util.h" | 22 #include "chrome/browser/renderer_preferences_util.h" |
29 #include "chrome/browser/safe_browsing/threat_details.h" | 23 #include "chrome/browser/safe_browsing/threat_details.h" |
30 #include "chrome/browser/safe_browsing/ui_manager.h" | 24 #include "chrome/browser/safe_browsing/ui_manager.h" |
31 #include "chrome/common/chrome_switches.h" | |
32 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
33 #include "chrome/common/url_constants.h" | |
34 #include "chrome/grit/generated_resources.h" | |
35 #include "components/google/core/browser/google_util.h" | |
36 #include "components/prefs/pref_service.h" | 26 #include "components/prefs/pref_service.h" |
37 #include "components/safe_browsing_db/safe_browsing_prefs.h" | 27 #include "components/safe_browsing_db/safe_browsing_prefs.h" |
38 #include "components/security_interstitials/core/common_string_util.h" | |
39 #include "components/security_interstitials/core/controller_client.h" | |
40 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
41 #include "content/public/browser/interstitial_page.h" | 29 #include "content/public/browser/interstitial_page.h" |
42 #include "content/public/browser/navigation_controller.h" | |
43 #include "content/public/browser/navigation_entry.h" | 30 #include "content/public/browser/navigation_entry.h" |
44 #include "content/public/browser/user_metrics.h" | 31 #include "content/public/browser/user_metrics.h" |
45 #include "content/public/browser/web_contents.h" | 32 #include "content/public/browser/web_contents.h" |
46 #include "content/public/common/renderer_preferences.h" | |
47 #include "net/base/escape.h" | |
48 #include "ui/base/l10n/l10n_util.h" | |
49 | 33 |
50 using base::UserMetricsAction; | 34 using base::UserMetricsAction; |
51 using content::BrowserThread; | 35 using content::BrowserThread; |
52 using content::InterstitialPage; | 36 using content::InterstitialPage; |
53 using content::OpenURLParams; | |
54 using content::Referrer; | |
55 using content::WebContents; | 37 using content::WebContents; |
| 38 using security_interstitials::SafeBrowsingErrorUI; |
56 | 39 |
57 namespace safe_browsing { | 40 namespace safe_browsing { |
58 | 41 |
59 namespace { | 42 namespace { |
60 | 43 |
61 // For malware interstitial pages, we link the problematic URL to Google's | |
62 // diagnostic page. | |
63 #if defined(GOOGLE_CHROME_BUILD) | |
64 const char kSbDiagnosticUrl[] = | |
65 "https://www.google.com/safebrowsing/diagnostic?site=%s&client=googlechrome"
; | |
66 #else | |
67 const char kSbDiagnosticUrl[] = | |
68 "https://www.google.com/safebrowsing/diagnostic?site=%s&client=chromium"; | |
69 #endif | |
70 | |
71 // URL for the Help Center article on Safe Browsing warnings. | |
72 const char kLearnMore[] = "https://support.google.com/chrome/answer/99020"; | |
73 | |
74 // After a safe browsing interstitial where the user opted-in to the report | 44 // After a safe browsing interstitial where the user opted-in to the report |
75 // but clicked "proceed anyway", we delay the call to | 45 // but clicked "proceed anyway", we delay the call to |
76 // ThreatDetails::FinishCollection() by this much time (in | 46 // ThreatDetails::FinishCollection() by this much time (in |
77 // milliseconds). | 47 // milliseconds). |
78 const int64_t kThreatDetailsProceedDelayMilliSeconds = 3000; | 48 const int64_t kThreatDetailsProceedDelayMilliSeconds = 3000; |
79 | 49 |
80 // Constants for the Experience Sampling instrumentation. | 50 // Constants for the Experience Sampling instrumentation. |
81 const char kEventNameMalware[] = "safebrowsing_interstitial_"; | 51 const char kEventNameMalware[] = "safebrowsing_interstitial_"; |
82 const char kEventNameHarmful[] = "harmful_interstitial_"; | 52 const char kEventNameHarmful[] = "harmful_interstitial_"; |
83 const char kEventNamePhishing[] = "phishing_interstitial_"; | 53 const char kEventNamePhishing[] = "phishing_interstitial_"; |
84 const char kEventNameOther[] = "safebrowsing_other_interstitial_"; | 54 const char kEventNameOther[] = "safebrowsing_other_interstitial_"; |
85 | 55 |
86 // Constants for the V4 phishing string upgrades. | |
87 const char kReportPhishingErrorUrl[] = | |
88 "https://www.google.com/safebrowsing/report_error/"; | |
89 | |
90 base::LazyInstance<SafeBrowsingBlockingPage::UnsafeResourceMap> | 56 base::LazyInstance<SafeBrowsingBlockingPage::UnsafeResourceMap> |
91 g_unsafe_resource_map = LAZY_INSTANCE_INITIALIZER; | 57 g_unsafe_resource_map = LAZY_INSTANCE_INITIALIZER; |
92 | 58 |
93 } // namespace | 59 } // namespace |
94 | 60 |
95 // static | 61 // static |
96 SafeBrowsingBlockingPageFactory* SafeBrowsingBlockingPage::factory_ = NULL; | 62 SafeBrowsingBlockingPageFactory* SafeBrowsingBlockingPage::factory_ = NULL; |
97 | 63 |
98 // The default SafeBrowsingBlockingPageFactory. Global, made a singleton so we | 64 // The default SafeBrowsingBlockingPageFactory. Global, made a singleton so we |
99 // don't leak it. | 65 // don't leak it. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 SafeBrowsingUIManager* ui_manager, | 97 SafeBrowsingUIManager* ui_manager, |
132 WebContents* web_contents, | 98 WebContents* web_contents, |
133 const GURL& main_frame_url, | 99 const GURL& main_frame_url, |
134 const UnsafeResourceList& unsafe_resources) | 100 const UnsafeResourceList& unsafe_resources) |
135 : SecurityInterstitialPage( | 101 : SecurityInterstitialPage( |
136 web_contents, | 102 web_contents, |
137 unsafe_resources[0].url, | 103 unsafe_resources[0].url, |
138 CreateMetricsHelper(web_contents, unsafe_resources)), | 104 CreateMetricsHelper(web_contents, unsafe_resources)), |
139 threat_details_proceed_delay_ms_(kThreatDetailsProceedDelayMilliSeconds), | 105 threat_details_proceed_delay_ms_(kThreatDetailsProceedDelayMilliSeconds), |
140 ui_manager_(ui_manager), | 106 ui_manager_(ui_manager), |
141 is_main_frame_load_blocked_(IsMainPageLoadBlocked(unsafe_resources)), | |
142 main_frame_url_(main_frame_url), | 107 main_frame_url_(main_frame_url), |
143 unsafe_resources_(unsafe_resources), | 108 unsafe_resources_(unsafe_resources), |
144 proceeded_(false), | 109 proceeded_(false) { |
145 interstitial_reason_(GetInterstitialReason(unsafe_resources)) { | 110 // Computes display options based on user profile and blocked resource. |
146 controller()->metrics_helper()->RecordUserDecision( | 111 bool is_main_frame_load_blocked = IsMainPageLoadBlocked(unsafe_resources); |
147 security_interstitials::MetricsHelper::SHOW); | 112 bool can_show_threat_details_option = CanShowThreatDetailsOption(); |
148 controller()->metrics_helper()->RecordUserInteraction( | 113 SafeBrowsingErrorUI::SBErrorDisplayOptions display_options( |
149 security_interstitials::MetricsHelper::TOTAL_VISITS); | 114 is_main_frame_load_blocked, can_show_threat_details_option, |
150 if (IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)) { | 115 IsExtendedReportingEnabled(*profile()->GetPrefs()), |
151 controller()->metrics_helper()->RecordUserDecision( | 116 IsScout(*profile()->GetPrefs()), |
152 security_interstitials::MetricsHelper::PROCEEDING_DISABLED); | 117 IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)); |
153 } | 118 sb_error_ui_ = base::MakeUnique<SafeBrowsingErrorUI>( |
| 119 unsafe_resources[0].url, main_frame_url_, |
| 120 GetInterstitialReason(unsafe_resources), display_options, |
| 121 g_browser_process->GetApplicationLocale(), |
| 122 base::Time::NowFromSystemTime(), controller()); |
154 | 123 |
155 if (!is_main_frame_load_blocked_) { | 124 if (!is_main_frame_load_blocked) { |
156 navigation_entry_index_to_remove_ = | 125 navigation_entry_index_to_remove_ = |
157 web_contents->GetController().GetLastCommittedEntryIndex(); | 126 web_contents->GetController().GetLastCommittedEntryIndex(); |
158 } else { | 127 } else { |
159 navigation_entry_index_to_remove_ = -1; | 128 navigation_entry_index_to_remove_ = -1; |
160 } | 129 } |
161 | 130 |
162 // Start computing threat details. They will be sent only | 131 // Start computing threat details. They will be sent only |
163 // if the user opts-in on the blocking page later. | 132 // if the user opts-in on the blocking page later. |
164 // If there's more than one malicious resources, it means the user | 133 // If there's more than one malicious resources, it means the user |
165 // clicked through the first warning, so we don't prepare additional | 134 // clicked through the first warning, so we don't prepare additional |
166 // reports. | 135 // reports. |
167 if (unsafe_resources.size() == 1 && | 136 if (unsafe_resources.size() == 1 && |
168 ShouldReportThreatDetails(unsafe_resources[0].threat_type) && | 137 ShouldReportThreatDetails(unsafe_resources[0].threat_type) && |
169 threat_details_.get() == NULL && CanShowThreatDetailsOption()) { | 138 threat_details_.get() == NULL && can_show_threat_details_option) { |
170 threat_details_ = ThreatDetails::NewThreatDetails(ui_manager_, web_contents, | 139 threat_details_ = ThreatDetails::NewThreatDetails(ui_manager_, web_contents, |
171 unsafe_resources[0]); | 140 unsafe_resources[0]); |
172 } | 141 } |
173 } | 142 } |
174 | 143 |
175 bool SafeBrowsingBlockingPage::ShouldReportThreatDetails( | 144 bool SafeBrowsingBlockingPage::ShouldReportThreatDetails( |
176 SBThreatType threat_type) { | 145 SBThreatType threat_type) { |
177 return threat_type == SB_THREAT_TYPE_URL_PHISHING || | 146 return threat_type == SB_THREAT_TYPE_URL_PHISHING || |
178 threat_type == SB_THREAT_TYPE_URL_MALWARE || | 147 threat_type == SB_THREAT_TYPE_URL_MALWARE || |
179 threat_type == SB_THREAT_TYPE_URL_UNWANTED || | 148 threat_type == SB_THREAT_TYPE_URL_UNWANTED || |
(...skipping 14 matching lines...) Expand all Loading... |
194 if (page_cmd == "\"pageLoadComplete\"") { | 163 if (page_cmd == "\"pageLoadComplete\"") { |
195 // content::WaitForRenderFrameReady sends this message when the page | 164 // content::WaitForRenderFrameReady sends this message when the page |
196 // load completes. Ignore it. | 165 // load completes. Ignore it. |
197 return; | 166 return; |
198 } | 167 } |
199 | 168 |
200 int command = 0; | 169 int command = 0; |
201 bool retval = base::StringToInt(page_cmd, &command); | 170 bool retval = base::StringToInt(page_cmd, &command); |
202 DCHECK(retval) << page_cmd; | 171 DCHECK(retval) << page_cmd; |
203 | 172 |
204 switch (command) { | 173 sb_error_ui_->HandleCommand( |
205 case security_interstitials::CMD_DO_REPORT: { | 174 static_cast<security_interstitials::SecurityInterstitialCommands>( |
206 // User enabled SB Extended Reporting via the checkbox. | 175 command)); |
207 controller()->SetReportingPreference(true); | |
208 safe_browsing::SetExtendedReportingPrefAndMetric( | |
209 controller()->GetPrefService(), true, | |
210 safe_browsing::SBER_OPTIN_SITE_SECURITY_INTERSTITIAL); | |
211 break; | |
212 } | |
213 case security_interstitials::CMD_DONT_REPORT: { | |
214 // User disabled SB Extended Reporting via the checkbox. | |
215 controller()->SetReportingPreference(false); | |
216 safe_browsing::SetExtendedReportingPrefAndMetric( | |
217 controller()->GetPrefService(), false, | |
218 safe_browsing::SBER_OPTIN_SITE_SECURITY_INTERSTITIAL); | |
219 break; | |
220 } | |
221 case security_interstitials::CMD_OPEN_HELP_CENTER: { | |
222 // User pressed "Learn more". | |
223 metrics_helper()->RecordUserInteraction( | |
224 security_interstitials::MetricsHelper::SHOW_LEARN_MORE); | |
225 GURL learn_more_url(kLearnMore); | |
226 learn_more_url = google_util::AppendGoogleLocaleParam( | |
227 learn_more_url, g_browser_process->GetApplicationLocale()); | |
228 OpenURLParams params(learn_more_url, Referrer(), | |
229 WindowOpenDisposition::CURRENT_TAB, | |
230 ui::PAGE_TRANSITION_LINK, false); | |
231 web_contents()->OpenURL(params); | |
232 break; | |
233 } | |
234 case security_interstitials::CMD_OPEN_REPORTING_PRIVACY: { | |
235 // User pressed on the SB Extended Reporting "privacy policy" link. | |
236 controller()->OpenExtendedReportingPrivacyPolicy(); | |
237 break; | |
238 } | |
239 case security_interstitials::CMD_PROCEED: { | |
240 // User pressed on the button to proceed. | |
241 if (!IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)) { | |
242 metrics_helper()->RecordUserDecision( | |
243 security_interstitials::MetricsHelper::PROCEED); | |
244 interstitial_page()->Proceed(); | |
245 // |this| has been deleted after Proceed() returns. | |
246 break; | |
247 } | |
248 // If the user can't proceed, fall through to CMD_DONT_PROCEED. | |
249 } | |
250 case security_interstitials::CMD_DONT_PROCEED: { | |
251 // User pressed on the button to return to safety. | |
252 // Don't record the user action here because there are other ways of | |
253 // triggering DontProceed, like clicking the back button. | |
254 if (is_main_frame_load_blocked_) { | |
255 // If the load is blocked, we want to close the interstitial and discard | |
256 // the pending entry. | |
257 interstitial_page()->DontProceed(); | |
258 // |this| has been deleted after DontProceed() returns. | |
259 break; | |
260 } | |
261 | |
262 // Otherwise the offending entry has committed, and we need to go back or | |
263 // to a safe page. We will close the interstitial when that page commits. | |
264 if (web_contents()->GetController().CanGoBack()) { | |
265 web_contents()->GetController().GoBack(); | |
266 } else { | |
267 web_contents()->GetController().LoadURL( | |
268 GURL(chrome::kChromeUINewTabURL), | |
269 content::Referrer(), | |
270 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | |
271 std::string()); | |
272 } | |
273 break; | |
274 } | |
275 case security_interstitials::CMD_OPEN_DIAGNOSTIC: { | |
276 // User wants to see why this page is blocked. | |
277 const UnsafeResource& unsafe_resource = unsafe_resources_[0]; | |
278 std::string bad_url_spec = unsafe_resource.url.spec(); | |
279 metrics_helper()->RecordUserInteraction( | |
280 security_interstitials::MetricsHelper::SHOW_DIAGNOSTIC); | |
281 std::string diagnostic = | |
282 base::StringPrintf(kSbDiagnosticUrl, | |
283 net::EscapeQueryParamValue(bad_url_spec, true).c_str()); | |
284 GURL diagnostic_url(diagnostic); | |
285 diagnostic_url = google_util::AppendGoogleLocaleParam( | |
286 diagnostic_url, g_browser_process->GetApplicationLocale()); | |
287 DCHECK(unsafe_resource.threat_type == SB_THREAT_TYPE_URL_MALWARE || | |
288 unsafe_resource.threat_type == | |
289 SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL || | |
290 unsafe_resource.threat_type == SB_THREAT_TYPE_URL_UNWANTED); | |
291 OpenURLParams params(diagnostic_url, Referrer(), | |
292 WindowOpenDisposition::CURRENT_TAB, | |
293 ui::PAGE_TRANSITION_LINK, false); | |
294 web_contents()->OpenURL(params); | |
295 break; | |
296 } | |
297 case security_interstitials::CMD_SHOW_MORE_SECTION: { | |
298 // User has opened up the hidden text. | |
299 metrics_helper()->RecordUserInteraction( | |
300 security_interstitials::MetricsHelper::SHOW_ADVANCED); | |
301 break; | |
302 } | |
303 case security_interstitials::CMD_REPORT_PHISHING_ERROR: { | |
304 // User wants to report a phishing error. | |
305 metrics_helper()->RecordUserInteraction( | |
306 security_interstitials::MetricsHelper::REPORT_PHISHING_ERROR); | |
307 GURL phishing_error_url(kReportPhishingErrorUrl); | |
308 phishing_error_url = google_util::AppendGoogleLocaleParam( | |
309 phishing_error_url, g_browser_process->GetApplicationLocale()); | |
310 OpenURLParams params(phishing_error_url, Referrer(), | |
311 WindowOpenDisposition::CURRENT_TAB, | |
312 ui::PAGE_TRANSITION_LINK, false); | |
313 web_contents()->OpenURL(params); | |
314 break; | |
315 } | |
316 case security_interstitials::CMD_OPEN_WHITEPAPER: { | |
317 controller()->OpenExtendedReportingWhitepaper(); | |
318 break; | |
319 } | |
320 } | |
321 } | 176 } |
322 | 177 |
323 void SafeBrowsingBlockingPage::OverrideRendererPrefs( | 178 void SafeBrowsingBlockingPage::OverrideRendererPrefs( |
324 content::RendererPreferences* prefs) { | 179 content::RendererPreferences* prefs) { |
325 Profile* profile = Profile::FromBrowserContext( | 180 Profile* profile = Profile::FromBrowserContext( |
326 web_contents()->GetBrowserContext()); | 181 web_contents()->GetBrowserContext()); |
327 renderer_preferences_util::UpdateFromSystemSettings( | 182 renderer_preferences_util::UpdateFromSystemSettings( |
328 prefs, profile, web_contents()); | 183 prefs, profile, web_contents()); |
329 } | 184 } |
330 | 185 |
(...skipping 28 matching lines...) Expand all Loading... |
359 if (blocking_page) | 214 if (blocking_page) |
360 blocking_page->Show(); | 215 blocking_page->Show(); |
361 } | 216 } |
362 | 217 |
363 content::InterstitialPageDelegate::TypeID | 218 content::InterstitialPageDelegate::TypeID |
364 SafeBrowsingBlockingPage::GetTypeForTesting() const { | 219 SafeBrowsingBlockingPage::GetTypeForTesting() const { |
365 return SafeBrowsingBlockingPage::kTypeForTesting; | 220 return SafeBrowsingBlockingPage::kTypeForTesting; |
366 } | 221 } |
367 | 222 |
368 bool SafeBrowsingBlockingPage::ShouldCreateNewNavigation() const { | 223 bool SafeBrowsingBlockingPage::ShouldCreateNewNavigation() const { |
369 return is_main_frame_load_blocked_; | 224 return sb_error_ui_->is_main_frame_load_blocked(); |
370 } | 225 } |
371 | 226 |
372 void SafeBrowsingBlockingPage::OnDontProceed() { | 227 void SafeBrowsingBlockingPage::OnDontProceed() { |
373 // We could have already called Proceed(), in which case we must not notify | 228 // We could have already called Proceed(), in which case we must not notify |
374 // the SafeBrowsingUIManager again, as the client has been deleted. | 229 // the SafeBrowsingUIManager again, as the client has been deleted. |
375 if (proceeded_) | 230 if (proceeded_) |
376 return; | 231 return; |
377 | 232 |
378 if (!IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)) { | 233 if (!IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)) { |
379 controller()->metrics_helper()->RecordUserDecision( | 234 controller()->metrics_helper()->RecordUserDecision( |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 const UnsafeResourceList& unsafe_resources) { | 343 const UnsafeResourceList& unsafe_resources) { |
489 // If there is more than one unsafe resource, the main page load must not be | 344 // If there is more than one unsafe resource, the main page load must not be |
490 // blocked. Otherwise, check if the one resource is. | 345 // blocked. Otherwise, check if the one resource is. |
491 return unsafe_resources.size() == 1 && | 346 return unsafe_resources.size() == 1 && |
492 unsafe_resources[0].IsMainPageLoadBlocked(); | 347 unsafe_resources[0].IsMainPageLoadBlocked(); |
493 } | 348 } |
494 | 349 |
495 // static | 350 // static |
496 std::string SafeBrowsingBlockingPage::GetMetricPrefix( | 351 std::string SafeBrowsingBlockingPage::GetMetricPrefix( |
497 const UnsafeResourceList& unsafe_resources, | 352 const UnsafeResourceList& unsafe_resources, |
498 SBInterstitialReason interstitial_reason) { | 353 SafeBrowsingErrorUI::SBInterstitialReason interstitial_reason) { |
499 bool primary_subresource = unsafe_resources[0].is_subresource; | 354 bool primary_subresource = unsafe_resources[0].is_subresource; |
500 switch (interstitial_reason) { | 355 switch (interstitial_reason) { |
501 case SB_REASON_MALWARE: | 356 case SafeBrowsingErrorUI::SB_REASON_MALWARE: |
502 return primary_subresource ? "malware_subresource" : "malware"; | 357 return primary_subresource ? "malware_subresource" : "malware"; |
503 case SB_REASON_HARMFUL: | 358 case SafeBrowsingErrorUI::SB_REASON_HARMFUL: |
504 return primary_subresource ? "harmful_subresource" : "harmful"; | 359 return primary_subresource ? "harmful_subresource" : "harmful"; |
505 case SB_REASON_PHISHING: | 360 case SafeBrowsingErrorUI::SB_REASON_PHISHING: |
506 ThreatPatternType threat_pattern_type = | 361 ThreatPatternType threat_pattern_type = |
507 unsafe_resources[0].threat_metadata.threat_pattern_type; | 362 unsafe_resources[0].threat_metadata.threat_pattern_type; |
508 if (threat_pattern_type == ThreatPatternType::PHISHING || | 363 if (threat_pattern_type == ThreatPatternType::PHISHING || |
509 threat_pattern_type == ThreatPatternType::NONE) | 364 threat_pattern_type == ThreatPatternType::NONE) |
510 return primary_subresource ? "phishing_subresource" : "phishing"; | 365 return primary_subresource ? "phishing_subresource" : "phishing"; |
511 else if (threat_pattern_type == ThreatPatternType::SOCIAL_ENGINEERING_ADS) | 366 else if (threat_pattern_type == ThreatPatternType::SOCIAL_ENGINEERING_ADS) |
512 return primary_subresource ? "social_engineering_ads_subresource" | 367 return primary_subresource ? "social_engineering_ads_subresource" |
513 : "social_engineering_ads"; | 368 : "social_engineering_ads"; |
514 else if (threat_pattern_type == | 369 else if (threat_pattern_type == |
515 ThreatPatternType::SOCIAL_ENGINEERING_LANDING) | 370 ThreatPatternType::SOCIAL_ENGINEERING_LANDING) |
(...skipping 21 matching lines...) Expand all Loading... |
537 case safe_browsing::ThreatSource::CLIENT_SIDE_DETECTION: | 392 case safe_browsing::ThreatSource::CLIENT_SIDE_DETECTION: |
538 return "from_client_side_detection"; | 393 return "from_client_side_detection"; |
539 case safe_browsing::ThreatSource::UNKNOWN: | 394 case safe_browsing::ThreatSource::UNKNOWN: |
540 break; | 395 break; |
541 } | 396 } |
542 NOTREACHED(); | 397 NOTREACHED(); |
543 return std::string(); | 398 return std::string(); |
544 } | 399 } |
545 | 400 |
546 // static | 401 // static |
547 std::string SafeBrowsingBlockingPage::GetRapporPrefix( | |
548 SBInterstitialReason interstitial_reason) { | |
549 switch (interstitial_reason) { | |
550 case SB_REASON_MALWARE: | |
551 return "malware2"; | |
552 case SB_REASON_HARMFUL: | |
553 return "harmful2"; | |
554 case SB_REASON_PHISHING: | |
555 return "phishing2"; | |
556 } | |
557 NOTREACHED(); | |
558 return std::string(); | |
559 } | |
560 | |
561 // static | |
562 std::string SafeBrowsingBlockingPage::GetDeprecatedRapporPrefix( | |
563 SBInterstitialReason interstitial_reason) { | |
564 switch (interstitial_reason) { | |
565 case SB_REASON_MALWARE: | |
566 return "malware"; | |
567 case SB_REASON_HARMFUL: | |
568 return "harmful"; | |
569 case SB_REASON_PHISHING: | |
570 return "phishing"; | |
571 } | |
572 NOTREACHED(); | |
573 return std::string(); | |
574 } | |
575 | |
576 // static | |
577 std::string SafeBrowsingBlockingPage::GetSamplingEventName( | 402 std::string SafeBrowsingBlockingPage::GetSamplingEventName( |
578 SBInterstitialReason interstitial_reason) { | 403 SafeBrowsingErrorUI::SBInterstitialReason interstitial_reason) { |
579 switch (interstitial_reason) { | 404 switch (interstitial_reason) { |
580 case SB_REASON_MALWARE: | 405 case SafeBrowsingErrorUI::SB_REASON_MALWARE: |
581 return kEventNameMalware; | 406 return kEventNameMalware; |
582 case SB_REASON_HARMFUL: | 407 case SafeBrowsingErrorUI::SB_REASON_HARMFUL: |
583 return kEventNameHarmful; | 408 return kEventNameHarmful; |
584 case SB_REASON_PHISHING: | 409 case SafeBrowsingErrorUI::SB_REASON_PHISHING: |
585 return kEventNamePhishing; | 410 return kEventNamePhishing; |
586 default: | 411 default: |
587 return kEventNameOther; | 412 return kEventNameOther; |
588 } | 413 } |
589 } | 414 } |
590 | 415 |
591 // static | 416 // static |
592 SafeBrowsingBlockingPage::SBInterstitialReason | 417 SafeBrowsingErrorUI::SBInterstitialReason |
593 SafeBrowsingBlockingPage::GetInterstitialReason( | 418 SafeBrowsingBlockingPage::GetInterstitialReason( |
594 const UnsafeResourceList& unsafe_resources) { | 419 const UnsafeResourceList& unsafe_resources) { |
595 bool malware = false; | 420 bool malware = false; |
596 bool harmful = false; | 421 bool harmful = false; |
597 bool phishing = false; | 422 bool phishing = false; |
598 for (UnsafeResourceList::const_iterator iter = unsafe_resources.begin(); | 423 for (UnsafeResourceList::const_iterator iter = unsafe_resources.begin(); |
599 iter != unsafe_resources.end(); ++iter) { | 424 iter != unsafe_resources.end(); ++iter) { |
600 const SafeBrowsingUIManager::UnsafeResource& resource = *iter; | 425 const SafeBrowsingUIManager::UnsafeResource& resource = *iter; |
601 safe_browsing::SBThreatType threat_type = resource.threat_type; | 426 safe_browsing::SBThreatType threat_type = resource.threat_type; |
602 if (threat_type == SB_THREAT_TYPE_URL_MALWARE || | 427 if (threat_type == SB_THREAT_TYPE_URL_MALWARE || |
603 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL) { | 428 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL) { |
604 malware = true; | 429 malware = true; |
605 } else if (threat_type == SB_THREAT_TYPE_URL_UNWANTED) { | 430 } else if (threat_type == SB_THREAT_TYPE_URL_UNWANTED) { |
606 harmful = true; | 431 harmful = true; |
607 } else { | 432 } else { |
608 DCHECK(threat_type == SB_THREAT_TYPE_URL_PHISHING || | 433 DCHECK(threat_type == SB_THREAT_TYPE_URL_PHISHING || |
609 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL); | 434 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL); |
610 phishing = true; | 435 phishing = true; |
611 } | 436 } |
612 } | 437 } |
613 DCHECK(phishing || malware || harmful); | 438 DCHECK(phishing || malware || harmful); |
614 if (malware) | 439 if (malware) |
615 return SB_REASON_MALWARE; | 440 return SafeBrowsingErrorUI::SB_REASON_MALWARE; |
616 else if (harmful) | 441 else if (harmful) |
617 return SB_REASON_HARMFUL; | 442 return SafeBrowsingErrorUI::SB_REASON_HARMFUL; |
618 return SB_REASON_PHISHING; | 443 return SafeBrowsingErrorUI::SB_REASON_PHISHING; |
619 } | 444 } |
620 | 445 |
621 // static | 446 // static |
622 std::unique_ptr<ChromeMetricsHelper> | 447 std::unique_ptr<ChromeMetricsHelper> |
623 SafeBrowsingBlockingPage::CreateMetricsHelper( | 448 SafeBrowsingBlockingPage::CreateMetricsHelper( |
624 WebContents* web_contents, | 449 WebContents* web_contents, |
625 const UnsafeResourceList& unsafe_resources) { | 450 const UnsafeResourceList& unsafe_resources) { |
626 SBInterstitialReason interstitial_reason = | 451 SafeBrowsingErrorUI::SBInterstitialReason interstitial_reason = |
627 GetInterstitialReason(unsafe_resources); | 452 GetInterstitialReason(unsafe_resources); |
628 GURL request_url(unsafe_resources[0].url); | 453 GURL request_url(unsafe_resources[0].url); |
629 security_interstitials::MetricsHelper::ReportDetails reporting_info; | 454 security_interstitials::MetricsHelper::ReportDetails reporting_info; |
630 reporting_info.metric_prefix = | 455 reporting_info.metric_prefix = |
631 GetMetricPrefix(unsafe_resources, interstitial_reason); | 456 GetMetricPrefix(unsafe_resources, interstitial_reason); |
632 reporting_info.extra_suffix = GetExtraMetricsSuffix(unsafe_resources); | 457 reporting_info.extra_suffix = GetExtraMetricsSuffix(unsafe_resources); |
633 reporting_info.rappor_prefix = GetRapporPrefix(interstitial_reason); | |
634 reporting_info.deprecated_rappor_prefix = | |
635 GetDeprecatedRapporPrefix(interstitial_reason); | |
636 reporting_info.rappor_report_type = | |
637 rappor::LOW_FREQUENCY_SAFEBROWSING_RAPPOR_TYPE; | |
638 reporting_info.deprecated_rappor_report_type = | |
639 rappor::SAFEBROWSING_RAPPOR_TYPE; | |
640 return std::unique_ptr<ChromeMetricsHelper>( | 458 return std::unique_ptr<ChromeMetricsHelper>( |
641 new ChromeMetricsHelper(web_contents, request_url, reporting_info, | 459 new ChromeMetricsHelper(web_contents, request_url, reporting_info, |
642 GetSamplingEventName(interstitial_reason))); | 460 GetSamplingEventName(interstitial_reason))); |
643 } | 461 } |
644 | 462 |
645 void SafeBrowsingBlockingPage::PopulateInterstitialStrings( | 463 void SafeBrowsingBlockingPage::PopulateInterstitialStrings( |
646 base::DictionaryValue* load_time_data) { | 464 base::DictionaryValue* load_time_data) { |
647 CHECK(load_time_data); | 465 sb_error_ui_->PopulateStringsForHTML(load_time_data); |
648 CHECK(!unsafe_resources_.empty()); | |
649 | |
650 load_time_data->SetString("type", "SAFEBROWSING"); | |
651 load_time_data->SetString( | |
652 "tabTitle", l10n_util::GetStringUTF16(IDS_SAFEBROWSING_V3_TITLE)); | |
653 load_time_data->SetString( | |
654 "openDetails", | |
655 l10n_util::GetStringUTF16(IDS_SAFEBROWSING_V3_OPEN_DETAILS_BUTTON)); | |
656 load_time_data->SetString( | |
657 "closeDetails", | |
658 l10n_util::GetStringUTF16(IDS_SAFEBROWSING_V3_CLOSE_DETAILS_BUTTON)); | |
659 load_time_data->SetString( | |
660 "primaryButtonText", | |
661 l10n_util::GetStringUTF16(IDS_SAFEBROWSING_OVERRIDABLE_SAFETY_BUTTON)); | |
662 load_time_data->SetBoolean( | |
663 "overridable", | |
664 !IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)); | |
665 security_interstitials::common_string_util::PopulateNewIconStrings( | |
666 load_time_data); | |
667 | |
668 switch (interstitial_reason_) { | |
669 case SB_REASON_MALWARE: | |
670 PopulateMalwareLoadTimeData(load_time_data); | |
671 break; | |
672 case SB_REASON_HARMFUL: | |
673 PopulateHarmfulLoadTimeData(load_time_data); | |
674 break; | |
675 case SB_REASON_PHISHING: | |
676 PopulatePhishingLoadTimeData(load_time_data); | |
677 break; | |
678 } | |
679 } | |
680 | |
681 void SafeBrowsingBlockingPage::PopulateExtendedReportingOption( | |
682 base::DictionaryValue* load_time_data) { | |
683 // Only show checkbox if !(HTTPS || incognito-mode). | |
684 const bool show = CanShowThreatDetailsOption(); | |
685 load_time_data->SetBoolean(security_interstitials::kDisplayCheckBox, show); | |
686 if (!show) | |
687 return; | |
688 | |
689 const std::string privacy_link = base::StringPrintf( | |
690 security_interstitials::kPrivacyLinkHtml, | |
691 security_interstitials::CMD_OPEN_REPORTING_PRIVACY, | |
692 l10n_util::GetStringUTF8(IDS_SAFE_BROWSING_PRIVACY_POLICY_PAGE).c_str()); | |
693 load_time_data->SetString( | |
694 security_interstitials::kOptInLink, | |
695 l10n_util::GetStringFUTF16( | |
696 ChooseOptInTextResource(*profile()->GetPrefs(), | |
697 IDS_SAFE_BROWSING_MALWARE_REPORTING_AGREE, | |
698 IDS_SAFE_BROWSING_SCOUT_REPORTING_AGREE), | |
699 base::UTF8ToUTF16(privacy_link))); | |
700 load_time_data->SetBoolean( | |
701 security_interstitials::kBoxChecked, | |
702 IsExtendedReportingEnabled(*profile()->GetPrefs())); | |
703 } | |
704 | |
705 void SafeBrowsingBlockingPage::PopulateMalwareLoadTimeData( | |
706 base::DictionaryValue* load_time_data) { | |
707 load_time_data->SetBoolean("phishing", false); | |
708 load_time_data->SetString( | |
709 "heading", l10n_util::GetStringUTF16(IDS_MALWARE_V3_HEADING)); | |
710 load_time_data->SetString( | |
711 "primaryParagraph", | |
712 l10n_util::GetStringFUTF16( | |
713 IDS_MALWARE_V3_PRIMARY_PARAGRAPH, | |
714 GetFormattedHostName())); | |
715 load_time_data->SetString( | |
716 "explanationParagraph", | |
717 is_main_frame_load_blocked_ ? | |
718 l10n_util::GetStringFUTF16( | |
719 IDS_MALWARE_V3_EXPLANATION_PARAGRAPH, | |
720 GetFormattedHostName()) : | |
721 l10n_util::GetStringFUTF16( | |
722 IDS_MALWARE_V3_EXPLANATION_PARAGRAPH_SUBRESOURCE, | |
723 base::UTF8ToUTF16(main_frame_url_.host()), | |
724 GetFormattedHostName())); | |
725 load_time_data->SetString( | |
726 "finalParagraph", | |
727 l10n_util::GetStringUTF16(IDS_MALWARE_V3_PROCEED_PARAGRAPH)); | |
728 | |
729 PopulateExtendedReportingOption(load_time_data); | |
730 } | |
731 | |
732 void SafeBrowsingBlockingPage::PopulateHarmfulLoadTimeData( | |
733 base::DictionaryValue* load_time_data) { | |
734 load_time_data->SetBoolean("phishing", false); | |
735 load_time_data->SetString( | |
736 "heading", l10n_util::GetStringUTF16(IDS_HARMFUL_V3_HEADING)); | |
737 load_time_data->SetString( | |
738 "primaryParagraph", | |
739 l10n_util::GetStringFUTF16( | |
740 IDS_HARMFUL_V3_PRIMARY_PARAGRAPH, | |
741 GetFormattedHostName())); | |
742 load_time_data->SetString( | |
743 "explanationParagraph", | |
744 l10n_util::GetStringFUTF16( | |
745 IDS_HARMFUL_V3_EXPLANATION_PARAGRAPH, | |
746 GetFormattedHostName())); | |
747 load_time_data->SetString( | |
748 "finalParagraph", | |
749 l10n_util::GetStringUTF16(IDS_HARMFUL_V3_PROCEED_PARAGRAPH)); | |
750 | |
751 PopulateExtendedReportingOption(load_time_data); | |
752 } | |
753 | |
754 void SafeBrowsingBlockingPage::PopulatePhishingLoadTimeData( | |
755 base::DictionaryValue* load_time_data) { | |
756 load_time_data->SetBoolean("phishing", true); | |
757 load_time_data->SetString("heading", | |
758 l10n_util::GetStringUTF16(IDS_PHISHING_V4_HEADING)); | |
759 load_time_data->SetString( | |
760 "primaryParagraph", | |
761 l10n_util::GetStringFUTF16(IDS_PHISHING_V4_PRIMARY_PARAGRAPH, | |
762 GetFormattedHostName())); | |
763 load_time_data->SetString( | |
764 "explanationParagraph", | |
765 l10n_util::GetStringFUTF16(IDS_PHISHING_V4_EXPLANATION_PARAGRAPH, | |
766 GetFormattedHostName())); | |
767 load_time_data->SetString( | |
768 "finalParagraph", | |
769 l10n_util::GetStringUTF16(IDS_PHISHING_V4_PROCEED_AND_REPORT_PARAGRAPH)); | |
770 | |
771 PopulateExtendedReportingOption(load_time_data); | |
772 } | 466 } |
773 | 467 |
774 } // namespace safe_browsing | 468 } // namespace safe_browsing |
OLD | NEW |