| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 const char kSbDiagnosticUrl[] = | 61 const char kSbDiagnosticUrl[] = |
| 62 "http://safebrowsing.clients.google.com/safebrowsing/diagnostic?site=%s&clie
nt=chromium"; | 62 "http://safebrowsing.clients.google.com/safebrowsing/diagnostic?site=%s&clie
nt=chromium"; |
| 63 #endif | 63 #endif |
| 64 | 64 |
| 65 // URL for malware and phishing, V2. | 65 // URL for malware and phishing, V2. |
| 66 const char kLearnMoreMalwareUrlV2[] = | 66 const char kLearnMoreMalwareUrlV2[] = |
| 67 "https://www.google.com/transparencyreport/safebrowsing/"; | 67 "https://www.google.com/transparencyreport/safebrowsing/"; |
| 68 const char kLearnMorePhishingUrlV2[] = | 68 const char kLearnMorePhishingUrlV2[] = |
| 69 "https://www.google.com/transparencyreport/safebrowsing/"; | 69 "https://www.google.com/transparencyreport/safebrowsing/"; |
| 70 | 70 |
| 71 const char kPrivacyLinkHtml[] = | |
| 72 "<a id=\"privacy-link\" href=\"\" onclick=\"sendCommand(%d); " | |
| 73 "return false;\" onmousedown=\"return false;\">%s</a>"; | |
| 74 | |
| 75 // After a malware interstitial where the user opted-in to the report | 71 // After a malware interstitial where the user opted-in to the report |
| 76 // but clicked "proceed anyway", we delay the call to | 72 // but clicked "proceed anyway", we delay the call to |
| 77 // MalwareDetails::FinishCollection() by this much time (in | 73 // MalwareDetails::FinishCollection() by this much time (in |
| 78 // milliseconds). | 74 // milliseconds). |
| 79 const int64 kMalwareDetailsProceedDelayMilliSeconds = 3000; | 75 const int64 kMalwareDetailsProceedDelayMilliSeconds = 3000; |
| 80 | 76 |
| 81 // Other constants used to communicate with the JavaScript. | |
| 82 const char kBoxChecked[] = "boxchecked"; | |
| 83 const char kDisplayCheckBox[] = "displaycheckbox"; | |
| 84 | |
| 85 // Constants for the Experience Sampling instrumentation. | 77 // Constants for the Experience Sampling instrumentation. |
| 86 const char kEventNameMalware[] = "safebrowsing_interstitial_"; | 78 const char kEventNameMalware[] = "safebrowsing_interstitial_"; |
| 87 const char kEventNameHarmful[] = "harmful_interstitial_"; | 79 const char kEventNameHarmful[] = "harmful_interstitial_"; |
| 88 const char kEventNamePhishing[] = "phishing_interstitial_"; | 80 const char kEventNamePhishing[] = "phishing_interstitial_"; |
| 89 const char kEventNameOther[] = "safebrowsing_other_interstitial_"; | 81 const char kEventNameOther[] = "safebrowsing_other_interstitial_"; |
| 90 | 82 |
| 91 base::LazyInstance<SafeBrowsingBlockingPage::UnsafeResourceMap> | 83 base::LazyInstance<SafeBrowsingBlockingPage::UnsafeResourceMap> |
| 92 g_unsafe_resource_map = LAZY_INSTANCE_INITIALIZER; | 84 g_unsafe_resource_map = LAZY_INSTANCE_INITIALIZER; |
| 93 | 85 |
| 94 } // namespace | 86 } // namespace |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 OpenURLParams params(learn_more_url, | 233 OpenURLParams params(learn_more_url, |
| 242 Referrer(), | 234 Referrer(), |
| 243 CURRENT_TAB, | 235 CURRENT_TAB, |
| 244 ui::PAGE_TRANSITION_LINK, | 236 ui::PAGE_TRANSITION_LINK, |
| 245 false); | 237 false); |
| 246 web_contents()->OpenURL(params); | 238 web_contents()->OpenURL(params); |
| 247 break; | 239 break; |
| 248 } | 240 } |
| 249 case CMD_OPEN_REPORTING_PRIVACY: { | 241 case CMD_OPEN_REPORTING_PRIVACY: { |
| 250 // User pressed on the SB Extended Reporting "privacy policy" link. | 242 // User pressed on the SB Extended Reporting "privacy policy" link. |
| 251 metrics_helper_->RecordUserInteraction( | 243 OpenExtendedReportingPrivacyPolicy(); |
| 252 SecurityInterstitialMetricsHelper::SHOW_PRIVACY_POLICY); | |
| 253 GURL privacy_url( | |
| 254 l10n_util::GetStringUTF8(IDS_SAFE_BROWSING_PRIVACY_POLICY_URL)); | |
| 255 privacy_url = google_util::AppendGoogleLocaleParam( | |
| 256 privacy_url, g_browser_process->GetApplicationLocale()); | |
| 257 OpenURLParams params(privacy_url, | |
| 258 Referrer(), | |
| 259 CURRENT_TAB, | |
| 260 ui::PAGE_TRANSITION_LINK, | |
| 261 false); | |
| 262 web_contents()->OpenURL(params); | |
| 263 break; | 244 break; |
| 264 } | 245 } |
| 265 case CMD_PROCEED: { | 246 case CMD_PROCEED: { |
| 266 // User pressed on the button to proceed. | 247 // User pressed on the button to proceed. |
| 267 if (!IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)) { | 248 if (!IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)) { |
| 268 metrics_helper_->RecordUserDecision( | 249 metrics_helper_->RecordUserDecision( |
| 269 SecurityInterstitialMetricsHelper::PROCEED); | 250 SecurityInterstitialMetricsHelper::PROCEED); |
| 270 interstitial_page()->Proceed(); | 251 interstitial_page()->Proceed(); |
| 271 // |this| has been deleted after Proceed() returns. | 252 // |this| has been deleted after Proceed() returns. |
| 272 break; | 253 break; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 } | 313 } |
| 333 | 314 |
| 334 void SafeBrowsingBlockingPage::OverrideRendererPrefs( | 315 void SafeBrowsingBlockingPage::OverrideRendererPrefs( |
| 335 content::RendererPreferences* prefs) { | 316 content::RendererPreferences* prefs) { |
| 336 Profile* profile = Profile::FromBrowserContext( | 317 Profile* profile = Profile::FromBrowserContext( |
| 337 web_contents()->GetBrowserContext()); | 318 web_contents()->GetBrowserContext()); |
| 338 renderer_preferences_util::UpdateFromSystemSettings( | 319 renderer_preferences_util::UpdateFromSystemSettings( |
| 339 prefs, profile, web_contents()); | 320 prefs, profile, web_contents()); |
| 340 } | 321 } |
| 341 | 322 |
| 342 void SafeBrowsingBlockingPage::SetReportingPreference(bool report) { | |
| 343 Profile* profile = Profile::FromBrowserContext( | |
| 344 web_contents()->GetBrowserContext()); | |
| 345 PrefService* pref = profile->GetPrefs(); | |
| 346 pref->SetBoolean(prefs::kSafeBrowsingExtendedReportingEnabled, report); | |
| 347 UMA_HISTOGRAM_BOOLEAN("SB2.SetExtendedReportingEnabled", report); | |
| 348 } | |
| 349 | |
| 350 void SafeBrowsingBlockingPage::OnProceed() { | 323 void SafeBrowsingBlockingPage::OnProceed() { |
| 351 proceeded_ = true; | 324 proceeded_ = true; |
| 352 // Send the malware details, if we opted to. | 325 // Send the malware details, if we opted to. |
| 353 FinishMalwareDetails(malware_details_proceed_delay_ms_); | 326 FinishMalwareDetails(malware_details_proceed_delay_ms_); |
| 354 | 327 |
| 355 NotifySafeBrowsingUIManager(ui_manager_, unsafe_resources_, true); | 328 NotifySafeBrowsingUIManager(ui_manager_, unsafe_resources_, true); |
| 356 | 329 |
| 357 // Check to see if some new notifications of unsafe resources have been | 330 // Check to see if some new notifications of unsafe resources have been |
| 358 // received while we were showing the interstitial. | 331 // received while we were showing the interstitial. |
| 359 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); | 332 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 } | 397 } |
| 425 } | 398 } |
| 426 | 399 |
| 427 void SafeBrowsingBlockingPage::FinishMalwareDetails(int64 delay_ms) { | 400 void SafeBrowsingBlockingPage::FinishMalwareDetails(int64 delay_ms) { |
| 428 if (malware_details_.get() == NULL) | 401 if (malware_details_.get() == NULL) |
| 429 return; // Not all interstitials have malware details (eg phishing). | 402 return; // Not all interstitials have malware details (eg phishing). |
| 430 DCHECK_EQ(interstitial_reason_, SB_REASON_MALWARE); | 403 DCHECK_EQ(interstitial_reason_, SB_REASON_MALWARE); |
| 431 | 404 |
| 432 const bool enabled = | 405 const bool enabled = |
| 433 IsPrefEnabled(prefs::kSafeBrowsingExtendedReportingEnabled); | 406 IsPrefEnabled(prefs::kSafeBrowsingExtendedReportingEnabled); |
| 434 UMA_HISTOGRAM_BOOLEAN("SB2.ExtendedReportingIsEnabled", enabled); | 407 if (!enabled) |
| 435 if (enabled) { | 408 return; |
| 436 // Finish the malware details collection, send it over. | |
| 437 BrowserThread::PostDelayedTask( | |
| 438 BrowserThread::IO, FROM_HERE, | |
| 439 base::Bind(&MalwareDetails::FinishCollection, malware_details_.get()), | |
| 440 base::TimeDelta::FromMilliseconds(delay_ms)); | |
| 441 } | |
| 442 } | |
| 443 | 409 |
| 444 bool SafeBrowsingBlockingPage::IsPrefEnabled(const char* pref) { | 410 metrics_helper_->RecordUserInteraction( |
| 445 Profile* profile = | 411 SecurityInterstitialMetricsHelper:: |
| 446 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 412 EXTENDED_REPORTING_IS_ENABLED_SAFE_BROWSING); |
| 447 return profile->GetPrefs()->GetBoolean(pref); | 413 // Finish the malware details collection, send it over. |
| 414 BrowserThread::PostDelayedTask( |
| 415 BrowserThread::IO, FROM_HERE, |
| 416 base::Bind(&MalwareDetails::FinishCollection, malware_details_.get()), |
| 417 base::TimeDelta::FromMilliseconds(delay_ms)); |
| 448 } | 418 } |
| 449 | 419 |
| 450 // static | 420 // static |
| 451 void SafeBrowsingBlockingPage::NotifySafeBrowsingUIManager( | 421 void SafeBrowsingBlockingPage::NotifySafeBrowsingUIManager( |
| 452 SafeBrowsingUIManager* ui_manager, | 422 SafeBrowsingUIManager* ui_manager, |
| 453 const UnsafeResourceList& unsafe_resources, | 423 const UnsafeResourceList& unsafe_resources, |
| 454 bool proceed) { | 424 bool proceed) { |
| 455 BrowserThread::PostTask( | 425 BrowserThread::PostTask( |
| 456 BrowserThread::IO, FROM_HERE, | 426 BrowserThread::IO, FROM_HERE, |
| 457 base::Bind(&SafeBrowsingUIManager::OnBlockingPageDone, | 427 base::Bind(&SafeBrowsingUIManager::OnBlockingPageDone, |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 case SB_REASON_PHISHING: | 551 case SB_REASON_PHISHING: |
| 582 PopulatePhishingLoadTimeData(load_time_data); | 552 PopulatePhishingLoadTimeData(load_time_data); |
| 583 break; | 553 break; |
| 584 } | 554 } |
| 585 } | 555 } |
| 586 | 556 |
| 587 void SafeBrowsingBlockingPage::PopulateExtendedReportingOption( | 557 void SafeBrowsingBlockingPage::PopulateExtendedReportingOption( |
| 588 base::DictionaryValue* load_time_data) { | 558 base::DictionaryValue* load_time_data) { |
| 589 // Only show checkbox if !(HTTPS || incognito-mode). | 559 // Only show checkbox if !(HTTPS || incognito-mode). |
| 590 const bool show = CanShowMalwareDetailsOption(); | 560 const bool show = CanShowMalwareDetailsOption(); |
| 591 load_time_data->SetBoolean(kDisplayCheckBox, show); | 561 load_time_data->SetBoolean(interstitials::kDisplayCheckBox, show); |
| 592 if (!show) | 562 if (!show) |
| 593 return; | 563 return; |
| 594 | 564 |
| 595 const std::string privacy_link = base::StringPrintf( | 565 const std::string privacy_link = base::StringPrintf( |
| 596 kPrivacyLinkHtml, | 566 interstitials::kPrivacyLinkHtml, CMD_OPEN_REPORTING_PRIVACY, |
| 597 CMD_OPEN_REPORTING_PRIVACY, | 567 l10n_util::GetStringUTF8(IDS_SAFE_BROWSING_PRIVACY_POLICY_PAGE).c_str()); |
| 598 l10n_util::GetStringUTF8( | |
| 599 IDS_SAFE_BROWSING_PRIVACY_POLICY_PAGE).c_str()); | |
| 600 load_time_data->SetString( | 568 load_time_data->SetString( |
| 601 "optInLink", | 569 interstitials::kOptInLink, |
| 602 l10n_util::GetStringFUTF16(IDS_SAFE_BROWSING_MALWARE_REPORTING_AGREE, | 570 l10n_util::GetStringFUTF16(IDS_SAFE_BROWSING_MALWARE_REPORTING_AGREE, |
| 603 base::UTF8ToUTF16(privacy_link))); | 571 base::UTF8ToUTF16(privacy_link))); |
| 604 load_time_data->SetBoolean( | 572 load_time_data->SetBoolean( |
| 605 kBoxChecked, | 573 interstitials::kBoxChecked, |
| 606 IsPrefEnabled(prefs::kSafeBrowsingExtendedReportingEnabled)); | 574 IsPrefEnabled(prefs::kSafeBrowsingExtendedReportingEnabled)); |
| 607 } | 575 } |
| 608 | 576 |
| 609 void SafeBrowsingBlockingPage::PopulateMalwareLoadTimeData( | 577 void SafeBrowsingBlockingPage::PopulateMalwareLoadTimeData( |
| 610 base::DictionaryValue* load_time_data) { | 578 base::DictionaryValue* load_time_data) { |
| 611 load_time_data->SetBoolean("phishing", false); | 579 load_time_data->SetBoolean("phishing", false); |
| 612 load_time_data->SetString( | 580 load_time_data->SetString( |
| 613 "heading", l10n_util::GetStringUTF16(IDS_MALWARE_V3_HEADING)); | 581 "heading", l10n_util::GetStringUTF16(IDS_MALWARE_V3_HEADING)); |
| 614 load_time_data->SetString( | 582 load_time_data->SetString( |
| 615 "primaryParagraph", | 583 "primaryParagraph", |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 load_time_data->SetString( | 637 load_time_data->SetString( |
| 670 "explanationParagraph", | 638 "explanationParagraph", |
| 671 l10n_util::GetStringFUTF16(IDS_PHISHING_V3_EXPLANATION_PARAGRAPH, | 639 l10n_util::GetStringFUTF16(IDS_PHISHING_V3_EXPLANATION_PARAGRAPH, |
| 672 GetFormattedHostName())); | 640 GetFormattedHostName())); |
| 673 load_time_data->SetString( | 641 load_time_data->SetString( |
| 674 "finalParagraph", | 642 "finalParagraph", |
| 675 l10n_util::GetStringUTF16(IDS_PHISHING_V3_PROCEED_PARAGRAPH)); | 643 l10n_util::GetStringUTF16(IDS_PHISHING_V3_PROCEED_PARAGRAPH)); |
| 676 | 644 |
| 677 PopulateExtendedReportingOption(load_time_data); | 645 PopulateExtendedReportingOption(load_time_data); |
| 678 } | 646 } |
| OLD | NEW |