| 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 int display_options = 0; |
| 147 security_interstitials::MetricsHelper::SHOW); | 112 bool is_main_frame_load_blocked = IsMainPageLoadBlocked(unsafe_resources); |
| 148 controller()->metrics_helper()->RecordUserInteraction( | 113 bool can_show_threat_details_option = CanShowThreatDetailsOption(); |
| 149 security_interstitials::MetricsHelper::TOTAL_VISITS); | 114 if (is_main_frame_load_blocked) |
| 150 if (IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)) { | 115 display_options |= SafeBrowsingErrorUI::MAIN_FRAME_LOAD_BLOCKED; |
| 151 controller()->metrics_helper()->RecordUserDecision( | 116 if (can_show_threat_details_option) |
| 152 security_interstitials::MetricsHelper::PROCEEDING_DISABLED); | 117 display_options |= SafeBrowsingErrorUI::CAN_SHOW_THREAT_DETAILS_OPTION; |
| 153 } | 118 if (IsExtendedReportingEnabled(*profile()->GetPrefs())) |
| 119 display_options |= SafeBrowsingErrorUI::EXTENDED_REPORTING_ENABLED; |
| 120 if (IsScout(*profile()->GetPrefs())) |
| 121 display_options |= SafeBrowsingErrorUI::SCOUT_REPORTING_ENABLED; |
| 122 if (IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)) |
| 123 display_options |= SafeBrowsingErrorUI::PROCEED_ANYWAY_DISABLED; |
| 124 sb_error_ui_.reset(new SafeBrowsingErrorUI( |
| 125 unsafe_resources[0].url, main_frame_url_, |
| 126 GetInterstitialReason(unsafe_resources), display_options, |
| 127 g_browser_process->GetApplicationLocale(), |
| 128 base::Time::NowFromSystemTime(), controller())); |
| 154 | 129 |
| 155 if (!is_main_frame_load_blocked_) { | 130 if (!is_main_frame_load_blocked) { |
| 156 navigation_entry_index_to_remove_ = | 131 navigation_entry_index_to_remove_ = |
| 157 web_contents->GetController().GetLastCommittedEntryIndex(); | 132 web_contents->GetController().GetLastCommittedEntryIndex(); |
| 158 } else { | 133 } else { |
| 159 navigation_entry_index_to_remove_ = -1; | 134 navigation_entry_index_to_remove_ = -1; |
| 160 } | 135 } |
| 161 | 136 |
| 162 // Start computing threat details. They will be sent only | 137 // Start computing threat details. They will be sent only |
| 163 // if the user opts-in on the blocking page later. | 138 // if the user opts-in on the blocking page later. |
| 164 // If there's more than one malicious resources, it means the user | 139 // If there's more than one malicious resources, it means the user |
| 165 // clicked through the first warning, so we don't prepare additional | 140 // clicked through the first warning, so we don't prepare additional |
| 166 // reports. | 141 // reports. |
| 167 if (unsafe_resources.size() == 1 && | 142 if (unsafe_resources.size() == 1 && |
| 168 ShouldReportThreatDetails(unsafe_resources[0].threat_type) && | 143 ShouldReportThreatDetails(unsafe_resources[0].threat_type) && |
| 169 threat_details_.get() == NULL && CanShowThreatDetailsOption()) { | 144 threat_details_.get() == NULL && can_show_threat_details_option) { |
| 170 threat_details_ = ThreatDetails::NewThreatDetails(ui_manager_, web_contents, | 145 threat_details_ = ThreatDetails::NewThreatDetails(ui_manager_, web_contents, |
| 171 unsafe_resources[0]); | 146 unsafe_resources[0]); |
| 172 } | 147 } |
| 173 } | 148 } |
| 174 | 149 |
| 175 bool SafeBrowsingBlockingPage::ShouldReportThreatDetails( | 150 bool SafeBrowsingBlockingPage::ShouldReportThreatDetails( |
| 176 SBThreatType threat_type) { | 151 SBThreatType threat_type) { |
| 177 return threat_type == SB_THREAT_TYPE_URL_PHISHING || | 152 return threat_type == SB_THREAT_TYPE_URL_PHISHING || |
| 178 threat_type == SB_THREAT_TYPE_URL_MALWARE || | 153 threat_type == SB_THREAT_TYPE_URL_MALWARE || |
| 179 threat_type == SB_THREAT_TYPE_URL_UNWANTED || | 154 threat_type == SB_THREAT_TYPE_URL_UNWANTED || |
| (...skipping 14 matching lines...) Expand all Loading... |
| 194 if (page_cmd == "\"pageLoadComplete\"") { | 169 if (page_cmd == "\"pageLoadComplete\"") { |
| 195 // content::WaitForRenderFrameReady sends this message when the page | 170 // content::WaitForRenderFrameReady sends this message when the page |
| 196 // load completes. Ignore it. | 171 // load completes. Ignore it. |
| 197 return; | 172 return; |
| 198 } | 173 } |
| 199 | 174 |
| 200 int command = 0; | 175 int command = 0; |
| 201 bool retval = base::StringToInt(page_cmd, &command); | 176 bool retval = base::StringToInt(page_cmd, &command); |
| 202 DCHECK(retval) << page_cmd; | 177 DCHECK(retval) << page_cmd; |
| 203 | 178 |
| 204 switch (command) { | 179 sb_error_ui_->HandleCommand( |
| 205 case security_interstitials::CMD_DO_REPORT: { | 180 static_cast<security_interstitials::SecurityInterstitialCommands>( |
| 206 // User enabled SB Extended Reporting via the checkbox. | 181 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 } | 182 } |
| 322 | 183 |
| 323 void SafeBrowsingBlockingPage::OverrideRendererPrefs( | 184 void SafeBrowsingBlockingPage::OverrideRendererPrefs( |
| 324 content::RendererPreferences* prefs) { | 185 content::RendererPreferences* prefs) { |
| 325 Profile* profile = Profile::FromBrowserContext( | 186 Profile* profile = Profile::FromBrowserContext( |
| 326 web_contents()->GetBrowserContext()); | 187 web_contents()->GetBrowserContext()); |
| 327 renderer_preferences_util::UpdateFromSystemSettings( | 188 renderer_preferences_util::UpdateFromSystemSettings( |
| 328 prefs, profile, web_contents()); | 189 prefs, profile, web_contents()); |
| 329 } | 190 } |
| 330 | 191 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 359 if (blocking_page) | 220 if (blocking_page) |
| 360 blocking_page->Show(); | 221 blocking_page->Show(); |
| 361 } | 222 } |
| 362 | 223 |
| 363 content::InterstitialPageDelegate::TypeID | 224 content::InterstitialPageDelegate::TypeID |
| 364 SafeBrowsingBlockingPage::GetTypeForTesting() const { | 225 SafeBrowsingBlockingPage::GetTypeForTesting() const { |
| 365 return SafeBrowsingBlockingPage::kTypeForTesting; | 226 return SafeBrowsingBlockingPage::kTypeForTesting; |
| 366 } | 227 } |
| 367 | 228 |
| 368 bool SafeBrowsingBlockingPage::ShouldCreateNewNavigation() const { | 229 bool SafeBrowsingBlockingPage::ShouldCreateNewNavigation() const { |
| 369 return is_main_frame_load_blocked_; | 230 return sb_error_ui_->is_main_frame_load_blocked(); |
| 370 } | 231 } |
| 371 | 232 |
| 372 void SafeBrowsingBlockingPage::OnDontProceed() { | 233 void SafeBrowsingBlockingPage::OnDontProceed() { |
| 373 // We could have already called Proceed(), in which case we must not notify | 234 // We could have already called Proceed(), in which case we must not notify |
| 374 // the SafeBrowsingUIManager again, as the client has been deleted. | 235 // the SafeBrowsingUIManager again, as the client has been deleted. |
| 375 if (proceeded_) | 236 if (proceeded_) |
| 376 return; | 237 return; |
| 377 | 238 |
| 378 if (!IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)) { | 239 if (!IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)) { |
| 379 controller()->metrics_helper()->RecordUserDecision( | 240 controller()->metrics_helper()->RecordUserDecision( |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 const UnsafeResourceList& unsafe_resources) { | 349 const UnsafeResourceList& unsafe_resources) { |
| 489 // If there is more than one unsafe resource, the main page load must not be | 350 // If there is more than one unsafe resource, the main page load must not be |
| 490 // blocked. Otherwise, check if the one resource is. | 351 // blocked. Otherwise, check if the one resource is. |
| 491 return unsafe_resources.size() == 1 && | 352 return unsafe_resources.size() == 1 && |
| 492 unsafe_resources[0].IsMainPageLoadBlocked(); | 353 unsafe_resources[0].IsMainPageLoadBlocked(); |
| 493 } | 354 } |
| 494 | 355 |
| 495 // static | 356 // static |
| 496 std::string SafeBrowsingBlockingPage::GetMetricPrefix( | 357 std::string SafeBrowsingBlockingPage::GetMetricPrefix( |
| 497 const UnsafeResourceList& unsafe_resources, | 358 const UnsafeResourceList& unsafe_resources, |
| 498 SBInterstitialReason interstitial_reason) { | 359 SafeBrowsingErrorUI::SBInterstitialReason interstitial_reason) { |
| 499 bool primary_subresource = unsafe_resources[0].is_subresource; | 360 bool primary_subresource = unsafe_resources[0].is_subresource; |
| 500 switch (interstitial_reason) { | 361 switch (interstitial_reason) { |
| 501 case SB_REASON_MALWARE: | 362 case SafeBrowsingErrorUI::SB_REASON_MALWARE: |
| 502 return primary_subresource ? "malware_subresource" : "malware"; | 363 return primary_subresource ? "malware_subresource" : "malware"; |
| 503 case SB_REASON_HARMFUL: | 364 case SafeBrowsingErrorUI::SB_REASON_HARMFUL: |
| 504 return primary_subresource ? "harmful_subresource" : "harmful"; | 365 return primary_subresource ? "harmful_subresource" : "harmful"; |
| 505 case SB_REASON_PHISHING: | 366 case SafeBrowsingErrorUI::SB_REASON_PHISHING: |
| 506 ThreatPatternType threat_pattern_type = | 367 ThreatPatternType threat_pattern_type = |
| 507 unsafe_resources[0].threat_metadata.threat_pattern_type; | 368 unsafe_resources[0].threat_metadata.threat_pattern_type; |
| 508 if (threat_pattern_type == ThreatPatternType::PHISHING || | 369 if (threat_pattern_type == ThreatPatternType::PHISHING || |
| 509 threat_pattern_type == ThreatPatternType::NONE) | 370 threat_pattern_type == ThreatPatternType::NONE) |
| 510 return primary_subresource ? "phishing_subresource" : "phishing"; | 371 return primary_subresource ? "phishing_subresource" : "phishing"; |
| 511 else if (threat_pattern_type == ThreatPatternType::SOCIAL_ENGINEERING_ADS) | 372 else if (threat_pattern_type == ThreatPatternType::SOCIAL_ENGINEERING_ADS) |
| 512 return primary_subresource ? "social_engineering_ads_subresource" | 373 return primary_subresource ? "social_engineering_ads_subresource" |
| 513 : "social_engineering_ads"; | 374 : "social_engineering_ads"; |
| 514 else if (threat_pattern_type == | 375 else if (threat_pattern_type == |
| 515 ThreatPatternType::SOCIAL_ENGINEERING_LANDING) | 376 ThreatPatternType::SOCIAL_ENGINEERING_LANDING) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 537 case safe_browsing::ThreatSource::CLIENT_SIDE_DETECTION: | 398 case safe_browsing::ThreatSource::CLIENT_SIDE_DETECTION: |
| 538 return "from_client_side_detection"; | 399 return "from_client_side_detection"; |
| 539 case safe_browsing::ThreatSource::UNKNOWN: | 400 case safe_browsing::ThreatSource::UNKNOWN: |
| 540 break; | 401 break; |
| 541 } | 402 } |
| 542 NOTREACHED(); | 403 NOTREACHED(); |
| 543 return std::string(); | 404 return std::string(); |
| 544 } | 405 } |
| 545 | 406 |
| 546 // static | 407 // 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( | 408 std::string SafeBrowsingBlockingPage::GetSamplingEventName( |
| 578 SBInterstitialReason interstitial_reason) { | 409 SafeBrowsingErrorUI::SBInterstitialReason interstitial_reason) { |
| 579 switch (interstitial_reason) { | 410 switch (interstitial_reason) { |
| 580 case SB_REASON_MALWARE: | 411 case SafeBrowsingErrorUI::SB_REASON_MALWARE: |
| 581 return kEventNameMalware; | 412 return kEventNameMalware; |
| 582 case SB_REASON_HARMFUL: | 413 case SafeBrowsingErrorUI::SB_REASON_HARMFUL: |
| 583 return kEventNameHarmful; | 414 return kEventNameHarmful; |
| 584 case SB_REASON_PHISHING: | 415 case SafeBrowsingErrorUI::SB_REASON_PHISHING: |
| 585 return kEventNamePhishing; | 416 return kEventNamePhishing; |
| 586 default: | 417 default: |
| 587 return kEventNameOther; | 418 return kEventNameOther; |
| 588 } | 419 } |
| 589 } | 420 } |
| 590 | 421 |
| 591 // static | 422 // static |
| 592 SafeBrowsingBlockingPage::SBInterstitialReason | 423 SafeBrowsingErrorUI::SBInterstitialReason |
| 593 SafeBrowsingBlockingPage::GetInterstitialReason( | 424 SafeBrowsingBlockingPage::GetInterstitialReason( |
| 594 const UnsafeResourceList& unsafe_resources) { | 425 const UnsafeResourceList& unsafe_resources) { |
| 595 bool malware = false; | 426 bool malware = false; |
| 596 bool harmful = false; | 427 bool harmful = false; |
| 597 bool phishing = false; | 428 bool phishing = false; |
| 598 for (UnsafeResourceList::const_iterator iter = unsafe_resources.begin(); | 429 for (UnsafeResourceList::const_iterator iter = unsafe_resources.begin(); |
| 599 iter != unsafe_resources.end(); ++iter) { | 430 iter != unsafe_resources.end(); ++iter) { |
| 600 const SafeBrowsingUIManager::UnsafeResource& resource = *iter; | 431 const SafeBrowsingUIManager::UnsafeResource& resource = *iter; |
| 601 safe_browsing::SBThreatType threat_type = resource.threat_type; | 432 safe_browsing::SBThreatType threat_type = resource.threat_type; |
| 602 if (threat_type == SB_THREAT_TYPE_URL_MALWARE || | 433 if (threat_type == SB_THREAT_TYPE_URL_MALWARE || |
| 603 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL) { | 434 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL) { |
| 604 malware = true; | 435 malware = true; |
| 605 } else if (threat_type == SB_THREAT_TYPE_URL_UNWANTED) { | 436 } else if (threat_type == SB_THREAT_TYPE_URL_UNWANTED) { |
| 606 harmful = true; | 437 harmful = true; |
| 607 } else { | 438 } else { |
| 608 DCHECK(threat_type == SB_THREAT_TYPE_URL_PHISHING || | 439 DCHECK(threat_type == SB_THREAT_TYPE_URL_PHISHING || |
| 609 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL); | 440 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL); |
| 610 phishing = true; | 441 phishing = true; |
| 611 } | 442 } |
| 612 } | 443 } |
| 613 DCHECK(phishing || malware || harmful); | 444 DCHECK(phishing || malware || harmful); |
| 614 if (malware) | 445 if (malware) |
| 615 return SB_REASON_MALWARE; | 446 return SafeBrowsingErrorUI::SB_REASON_MALWARE; |
| 616 else if (harmful) | 447 else if (harmful) |
| 617 return SB_REASON_HARMFUL; | 448 return SafeBrowsingErrorUI::SB_REASON_HARMFUL; |
| 618 return SB_REASON_PHISHING; | 449 return SafeBrowsingErrorUI::SB_REASON_PHISHING; |
| 619 } | 450 } |
| 620 | 451 |
| 621 // static | 452 // static |
| 622 std::unique_ptr<ChromeMetricsHelper> | 453 std::unique_ptr<ChromeMetricsHelper> |
| 623 SafeBrowsingBlockingPage::CreateMetricsHelper( | 454 SafeBrowsingBlockingPage::CreateMetricsHelper( |
| 624 WebContents* web_contents, | 455 WebContents* web_contents, |
| 625 const UnsafeResourceList& unsafe_resources) { | 456 const UnsafeResourceList& unsafe_resources) { |
| 626 SBInterstitialReason interstitial_reason = | 457 SafeBrowsingErrorUI::SBInterstitialReason interstitial_reason = |
| 627 GetInterstitialReason(unsafe_resources); | 458 GetInterstitialReason(unsafe_resources); |
| 628 GURL request_url(unsafe_resources[0].url); | 459 GURL request_url(unsafe_resources[0].url); |
| 629 security_interstitials::MetricsHelper::ReportDetails reporting_info; | 460 security_interstitials::MetricsHelper::ReportDetails reporting_info; |
| 630 reporting_info.metric_prefix = | 461 reporting_info.metric_prefix = |
| 631 GetMetricPrefix(unsafe_resources, interstitial_reason); | 462 GetMetricPrefix(unsafe_resources, interstitial_reason); |
| 632 reporting_info.extra_suffix = GetExtraMetricsSuffix(unsafe_resources); | 463 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>( | 464 return std::unique_ptr<ChromeMetricsHelper>( |
| 641 new ChromeMetricsHelper(web_contents, request_url, reporting_info, | 465 new ChromeMetricsHelper(web_contents, request_url, reporting_info, |
| 642 GetSamplingEventName(interstitial_reason))); | 466 GetSamplingEventName(interstitial_reason))); |
| 643 } | 467 } |
| 644 | 468 |
| 645 void SafeBrowsingBlockingPage::PopulateInterstitialStrings( | 469 void SafeBrowsingBlockingPage::PopulateInterstitialStrings( |
| 646 base::DictionaryValue* load_time_data) { | 470 base::DictionaryValue* load_time_data) { |
| 647 CHECK(load_time_data); | 471 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 } | 472 } |
| 773 | 473 |
| 774 } // namespace safe_browsing | 474 } // namespace safe_browsing |
| OLD | NEW |