| 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 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "chrome/browser/renderer_preferences_util.h" | 26 #include "chrome/browser/renderer_preferences_util.h" |
| 27 #include "chrome/browser/safe_browsing/threat_details.h" | 27 #include "chrome/browser/safe_browsing/threat_details.h" |
| 28 #include "chrome/browser/safe_browsing/ui_manager.h" | 28 #include "chrome/browser/safe_browsing/ui_manager.h" |
| 29 #include "chrome/browser/tab_contents/tab_util.h" | 29 #include "chrome/browser/tab_contents/tab_util.h" |
| 30 #include "chrome/common/chrome_switches.h" | 30 #include "chrome/common/chrome_switches.h" |
| 31 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
| 32 #include "chrome/common/url_constants.h" | 32 #include "chrome/common/url_constants.h" |
| 33 #include "chrome/grit/generated_resources.h" | 33 #include "chrome/grit/generated_resources.h" |
| 34 #include "chrome/grit/locale_settings.h" | 34 #include "chrome/grit/locale_settings.h" |
| 35 #include "components/google/core/browser/google_util.h" | 35 #include "components/google/core/browser/google_util.h" |
| 36 #include "components/security_interstitials/core/controller_client.h" |
| 36 #include "content/public/browser/browser_thread.h" | 37 #include "content/public/browser/browser_thread.h" |
| 37 #include "content/public/browser/interstitial_page.h" | 38 #include "content/public/browser/interstitial_page.h" |
| 38 #include "content/public/browser/navigation_controller.h" | 39 #include "content/public/browser/navigation_controller.h" |
| 39 #include "content/public/browser/user_metrics.h" | 40 #include "content/public/browser/user_metrics.h" |
| 40 #include "content/public/browser/web_contents.h" | 41 #include "content/public/browser/web_contents.h" |
| 41 #include "content/public/common/renderer_preferences.h" | 42 #include "content/public/common/renderer_preferences.h" |
| 42 #include "grit/browser_resources.h" | 43 #include "grit/browser_resources.h" |
| 43 #include "net/base/escape.h" | 44 #include "net/base/escape.h" |
| 44 #include "ui/base/l10n/l10n_util.h" | 45 #include "ui/base/l10n/l10n_util.h" |
| 45 | 46 |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 // content::WaitForRenderFrameReady sends this message when the page | 232 // content::WaitForRenderFrameReady sends this message when the page |
| 232 // load completes. Ignore it. | 233 // load completes. Ignore it. |
| 233 return; | 234 return; |
| 234 } | 235 } |
| 235 | 236 |
| 236 int command = 0; | 237 int command = 0; |
| 237 bool retval = base::StringToInt(page_cmd, &command); | 238 bool retval = base::StringToInt(page_cmd, &command); |
| 238 DCHECK(retval) << page_cmd; | 239 DCHECK(retval) << page_cmd; |
| 239 | 240 |
| 240 switch (command) { | 241 switch (command) { |
| 241 case CMD_DO_REPORT: { | 242 case security_interstitials::CMD_DO_REPORT: { |
| 242 // User enabled SB Extended Reporting via the checkbox. | 243 // User enabled SB Extended Reporting via the checkbox. |
| 243 SetReportingPreference(true); | 244 SetReportingPreference(true); |
| 244 break; | 245 break; |
| 245 } | 246 } |
| 246 case CMD_DONT_REPORT: { | 247 case security_interstitials::CMD_DONT_REPORT: { |
| 247 // User disabled SB Extended Reporting via the checkbox. | 248 // User disabled SB Extended Reporting via the checkbox. |
| 248 SetReportingPreference(false); | 249 SetReportingPreference(false); |
| 249 break; | 250 break; |
| 250 } | 251 } |
| 251 case CMD_OPEN_HELP_CENTER: { | 252 case security_interstitials::CMD_OPEN_HELP_CENTER: { |
| 252 // User pressed "Learn more". | 253 // User pressed "Learn more". |
| 253 metrics_helper()->RecordUserInteraction( | 254 metrics_helper()->RecordUserInteraction( |
| 254 security_interstitials::MetricsHelper::SHOW_LEARN_MORE); | 255 security_interstitials::MetricsHelper::SHOW_LEARN_MORE); |
| 255 GURL learn_more_url( | 256 GURL learn_more_url( |
| 256 interstitial_reason_ == SB_REASON_PHISHING ? | 257 interstitial_reason_ == SB_REASON_PHISHING ? |
| 257 kLearnMorePhishingUrlV2 : kLearnMoreMalwareUrlV2); | 258 kLearnMorePhishingUrlV2 : kLearnMoreMalwareUrlV2); |
| 258 learn_more_url = google_util::AppendGoogleLocaleParam( | 259 learn_more_url = google_util::AppendGoogleLocaleParam( |
| 259 learn_more_url, g_browser_process->GetApplicationLocale()); | 260 learn_more_url, g_browser_process->GetApplicationLocale()); |
| 260 OpenURLParams params(learn_more_url, | 261 OpenURLParams params(learn_more_url, |
| 261 Referrer(), | 262 Referrer(), |
| 262 CURRENT_TAB, | 263 CURRENT_TAB, |
| 263 ui::PAGE_TRANSITION_LINK, | 264 ui::PAGE_TRANSITION_LINK, |
| 264 false); | 265 false); |
| 265 web_contents()->OpenURL(params); | 266 web_contents()->OpenURL(params); |
| 266 break; | 267 break; |
| 267 } | 268 } |
| 268 case CMD_OPEN_REPORTING_PRIVACY: { | 269 case security_interstitials::CMD_OPEN_REPORTING_PRIVACY: { |
| 269 // User pressed on the SB Extended Reporting "privacy policy" link. | 270 // User pressed on the SB Extended Reporting "privacy policy" link. |
| 270 OpenExtendedReportingPrivacyPolicy(); | 271 OpenExtendedReportingPrivacyPolicy(); |
| 271 break; | 272 break; |
| 272 } | 273 } |
| 273 case CMD_PROCEED: { | 274 case security_interstitials::CMD_PROCEED: { |
| 274 // User pressed on the button to proceed. | 275 // User pressed on the button to proceed. |
| 275 if (!IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)) { | 276 if (!IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)) { |
| 276 metrics_helper()->RecordUserDecision( | 277 metrics_helper()->RecordUserDecision( |
| 277 security_interstitials::MetricsHelper::PROCEED); | 278 security_interstitials::MetricsHelper::PROCEED); |
| 278 interstitial_page()->Proceed(); | 279 interstitial_page()->Proceed(); |
| 279 // |this| has been deleted after Proceed() returns. | 280 // |this| has been deleted after Proceed() returns. |
| 280 break; | 281 break; |
| 281 } | 282 } |
| 282 // If the user can't proceed, fall through to CMD_DONT_PROCEED. | 283 // If the user can't proceed, fall through to CMD_DONT_PROCEED. |
| 283 } | 284 } |
| 284 case CMD_DONT_PROCEED: { | 285 case security_interstitials::CMD_DONT_PROCEED: { |
| 285 // User pressed on the button to return to safety. | 286 // User pressed on the button to return to safety. |
| 286 // Don't record the user action here because there are other ways of | 287 // Don't record the user action here because there are other ways of |
| 287 // triggering DontProceed, like clicking the back button. | 288 // triggering DontProceed, like clicking the back button. |
| 288 if (is_main_frame_load_blocked_) { | 289 if (is_main_frame_load_blocked_) { |
| 289 // If the load is blocked, we want to close the interstitial and discard | 290 // If the load is blocked, we want to close the interstitial and discard |
| 290 // the pending entry. | 291 // the pending entry. |
| 291 interstitial_page()->DontProceed(); | 292 interstitial_page()->DontProceed(); |
| 292 // |this| has been deleted after DontProceed() returns. | 293 // |this| has been deleted after DontProceed() returns. |
| 293 break; | 294 break; |
| 294 } | 295 } |
| 295 | 296 |
| 296 // Otherwise the offending entry has committed, and we need to go back or | 297 // Otherwise the offending entry has committed, and we need to go back or |
| 297 // to a safe page. We will close the interstitial when that page commits. | 298 // to a safe page. We will close the interstitial when that page commits. |
| 298 if (web_contents()->GetController().CanGoBack()) { | 299 if (web_contents()->GetController().CanGoBack()) { |
| 299 web_contents()->GetController().GoBack(); | 300 web_contents()->GetController().GoBack(); |
| 300 } else { | 301 } else { |
| 301 web_contents()->GetController().LoadURL( | 302 web_contents()->GetController().LoadURL( |
| 302 GURL(chrome::kChromeUINewTabURL), | 303 GURL(chrome::kChromeUINewTabURL), |
| 303 content::Referrer(), | 304 content::Referrer(), |
| 304 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | 305 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
| 305 std::string()); | 306 std::string()); |
| 306 } | 307 } |
| 307 break; | 308 break; |
| 308 } | 309 } |
| 309 case CMD_OPEN_DIAGNOSTIC: { | 310 case security_interstitials::CMD_OPEN_DIAGNOSTIC: { |
| 310 // User wants to see why this page is blocked. | 311 // User wants to see why this page is blocked. |
| 311 const UnsafeResource& unsafe_resource = unsafe_resources_[0]; | 312 const UnsafeResource& unsafe_resource = unsafe_resources_[0]; |
| 312 std::string bad_url_spec = unsafe_resource.url.spec(); | 313 std::string bad_url_spec = unsafe_resource.url.spec(); |
| 313 metrics_helper()->RecordUserInteraction( | 314 metrics_helper()->RecordUserInteraction( |
| 314 security_interstitials::MetricsHelper::SHOW_DIAGNOSTIC); | 315 security_interstitials::MetricsHelper::SHOW_DIAGNOSTIC); |
| 315 std::string diagnostic = | 316 std::string diagnostic = |
| 316 base::StringPrintf(kSbDiagnosticUrl, | 317 base::StringPrintf(kSbDiagnosticUrl, |
| 317 net::EscapeQueryParamValue(bad_url_spec, true).c_str()); | 318 net::EscapeQueryParamValue(bad_url_spec, true).c_str()); |
| 318 GURL diagnostic_url(diagnostic); | 319 GURL diagnostic_url(diagnostic); |
| 319 diagnostic_url = google_util::AppendGoogleLocaleParam( | 320 diagnostic_url = google_util::AppendGoogleLocaleParam( |
| 320 diagnostic_url, g_browser_process->GetApplicationLocale()); | 321 diagnostic_url, g_browser_process->GetApplicationLocale()); |
| 321 DCHECK(unsafe_resource.threat_type == SB_THREAT_TYPE_URL_MALWARE || | 322 DCHECK(unsafe_resource.threat_type == SB_THREAT_TYPE_URL_MALWARE || |
| 322 unsafe_resource.threat_type == | 323 unsafe_resource.threat_type == |
| 323 SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL || | 324 SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL || |
| 324 unsafe_resource.threat_type == SB_THREAT_TYPE_URL_UNWANTED); | 325 unsafe_resource.threat_type == SB_THREAT_TYPE_URL_UNWANTED); |
| 325 OpenURLParams params( | 326 OpenURLParams params( |
| 326 diagnostic_url, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_LINK, | 327 diagnostic_url, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_LINK, |
| 327 false); | 328 false); |
| 328 web_contents()->OpenURL(params); | 329 web_contents()->OpenURL(params); |
| 329 break; | 330 break; |
| 330 } | 331 } |
| 331 case CMD_SHOW_MORE_SECTION: { | 332 case security_interstitials::CMD_SHOW_MORE_SECTION: { |
| 332 // User has opened up the hidden text. | 333 // User has opened up the hidden text. |
| 333 metrics_helper()->RecordUserInteraction( | 334 metrics_helper()->RecordUserInteraction( |
| 334 security_interstitials::MetricsHelper::SHOW_ADVANCED); | 335 security_interstitials::MetricsHelper::SHOW_ADVANCED); |
| 335 break; | 336 break; |
| 336 } | 337 } |
| 337 case CMD_REPORT_PHISHING_ERROR: { | 338 case security_interstitials::CMD_REPORT_PHISHING_ERROR: { |
| 338 // User wants to report a phishing error. | 339 // User wants to report a phishing error. |
| 339 metrics_helper()->RecordUserInteraction( | 340 metrics_helper()->RecordUserInteraction( |
| 340 security_interstitials::MetricsHelper::REPORT_PHISHING_ERROR); | 341 security_interstitials::MetricsHelper::REPORT_PHISHING_ERROR); |
| 341 GURL phishing_error_url(kReportPhishingErrorUrl); | 342 GURL phishing_error_url(kReportPhishingErrorUrl); |
| 342 phishing_error_url = google_util::AppendGoogleLocaleParam( | 343 phishing_error_url = google_util::AppendGoogleLocaleParam( |
| 343 phishing_error_url, g_browser_process->GetApplicationLocale()); | 344 phishing_error_url, g_browser_process->GetApplicationLocale()); |
| 344 OpenURLParams params(phishing_error_url, Referrer(), CURRENT_TAB, | 345 OpenURLParams params(phishing_error_url, Referrer(), CURRENT_TAB, |
| 345 ui::PAGE_TRANSITION_LINK, false); | 346 ui::PAGE_TRANSITION_LINK, false); |
| 346 web_contents()->OpenURL(params); | 347 web_contents()->OpenURL(params); |
| 347 break; | 348 break; |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 case SB_REASON_PHISHING: | 626 case SB_REASON_PHISHING: |
| 626 PopulatePhishingLoadTimeData(load_time_data); | 627 PopulatePhishingLoadTimeData(load_time_data); |
| 627 break; | 628 break; |
| 628 } | 629 } |
| 629 } | 630 } |
| 630 | 631 |
| 631 void SafeBrowsingBlockingPage::PopulateExtendedReportingOption( | 632 void SafeBrowsingBlockingPage::PopulateExtendedReportingOption( |
| 632 base::DictionaryValue* load_time_data) { | 633 base::DictionaryValue* load_time_data) { |
| 633 // Only show checkbox if !(HTTPS || incognito-mode). | 634 // Only show checkbox if !(HTTPS || incognito-mode). |
| 634 const bool show = CanShowThreatDetailsOption(); | 635 const bool show = CanShowThreatDetailsOption(); |
| 635 load_time_data->SetBoolean(interstitials::kDisplayCheckBox, show); | 636 load_time_data->SetBoolean(security_interstitials::kDisplayCheckBox, show); |
| 636 if (!show) | 637 if (!show) |
| 637 return; | 638 return; |
| 638 | 639 |
| 639 const std::string privacy_link = base::StringPrintf( | 640 const std::string privacy_link = base::StringPrintf( |
| 640 interstitials::kPrivacyLinkHtml, CMD_OPEN_REPORTING_PRIVACY, | 641 security_interstitials::kPrivacyLinkHtml, |
| 642 security_interstitials::CMD_OPEN_REPORTING_PRIVACY, |
| 641 l10n_util::GetStringUTF8(IDS_SAFE_BROWSING_PRIVACY_POLICY_PAGE).c_str()); | 643 l10n_util::GetStringUTF8(IDS_SAFE_BROWSING_PRIVACY_POLICY_PAGE).c_str()); |
| 642 load_time_data->SetString( | 644 load_time_data->SetString( |
| 643 interstitials::kOptInLink, | 645 security_interstitials::kOptInLink, |
| 644 l10n_util::GetStringFUTF16(IDS_SAFE_BROWSING_MALWARE_REPORTING_AGREE, | 646 l10n_util::GetStringFUTF16(IDS_SAFE_BROWSING_MALWARE_REPORTING_AGREE, |
| 645 base::UTF8ToUTF16(privacy_link))); | 647 base::UTF8ToUTF16(privacy_link))); |
| 646 load_time_data->SetBoolean( | 648 load_time_data->SetBoolean( |
| 647 interstitials::kBoxChecked, | 649 security_interstitials::kBoxChecked, |
| 648 IsPrefEnabled(prefs::kSafeBrowsingExtendedReportingEnabled)); | 650 IsPrefEnabled(prefs::kSafeBrowsingExtendedReportingEnabled)); |
| 649 } | 651 } |
| 650 | 652 |
| 651 void SafeBrowsingBlockingPage::PopulateMalwareLoadTimeData( | 653 void SafeBrowsingBlockingPage::PopulateMalwareLoadTimeData( |
| 652 base::DictionaryValue* load_time_data) { | 654 base::DictionaryValue* load_time_data) { |
| 653 load_time_data->SetBoolean("phishing", false); | 655 load_time_data->SetBoolean("phishing", false); |
| 654 load_time_data->SetString( | 656 load_time_data->SetString( |
| 655 "heading", l10n_util::GetStringUTF16(IDS_MALWARE_V3_HEADING)); | 657 "heading", l10n_util::GetStringUTF16(IDS_MALWARE_V3_HEADING)); |
| 656 load_time_data->SetString( | 658 load_time_data->SetString( |
| 657 "primaryParagraph", | 659 "primaryParagraph", |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 } else { | 728 } else { |
| 727 load_time_data->SetString( | 729 load_time_data->SetString( |
| 728 "finalParagraph", | 730 "finalParagraph", |
| 729 l10n_util::GetStringUTF16(IDS_PHISHING_V3_PROCEED_PARAGRAPH)); | 731 l10n_util::GetStringUTF16(IDS_PHISHING_V3_PROCEED_PARAGRAPH)); |
| 730 } | 732 } |
| 731 | 733 |
| 732 PopulateExtendedReportingOption(load_time_data); | 734 PopulateExtendedReportingOption(load_time_data); |
| 733 } | 735 } |
| 734 | 736 |
| 735 } // namespace safe_browsing | 737 } // namespace safe_browsing |
| OLD | NEW |