Chromium Code Reviews| 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('showPrivacy'); " | |
| 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 // The commands returned by the page when the user performs an action. | 77 // The commands returned by the page when the user performs an action. |
| 82 const char kDoReportCommand[] = "doReport"; | 78 const char kDoReportCommand[] = "doReport"; |
| 83 const char kDontReportCommand[] = "dontReport"; | 79 const char kDontReportCommand[] = "dontReport"; |
| 84 const char kExpandedSeeMoreCommand[] = "expandedSeeMore"; | 80 const char kExpandedSeeMoreCommand[] = "expandedSeeMore"; |
| 85 const char kLearnMoreCommand[] = "learnMore2"; | 81 const char kLearnMoreCommand[] = "learnMore2"; |
| 86 const char kProceedCommand[] = "proceed"; | 82 const char kProceedCommand[] = "proceed"; |
| 87 const char kShowDiagnosticCommand[] = "showDiagnostic"; | 83 const char kShowDiagnosticCommand[] = "showDiagnostic"; |
| 88 const char kShowPrivacyCommand[] = "showPrivacy"; | 84 const char kShowPrivacyCommand[] = "showPrivacy"; |
| 89 const char kTakeMeBackCommand[] = "takeMeBack"; | 85 const char kTakeMeBackCommand[] = "takeMeBack"; |
| 90 | 86 |
| 91 // Other constants used to communicate with the JavaScript. | |
| 92 const char kBoxChecked[] = "boxchecked"; | |
| 93 const char kDisplayCheckBox[] = "displaycheckbox"; | |
| 94 | |
| 95 // Constants for the Experience Sampling instrumentation. | 87 // Constants for the Experience Sampling instrumentation. |
| 96 const char kEventNameMalware[] = "safebrowsing_interstitial_"; | 88 const char kEventNameMalware[] = "safebrowsing_interstitial_"; |
| 97 const char kEventNameHarmful[] = "harmful_interstitial_"; | 89 const char kEventNameHarmful[] = "harmful_interstitial_"; |
| 98 const char kEventNamePhishing[] = "phishing_interstitial_"; | 90 const char kEventNamePhishing[] = "phishing_interstitial_"; |
| 99 const char kEventNameOther[] = "safebrowsing_other_interstitial_"; | 91 const char kEventNameOther[] = "safebrowsing_other_interstitial_"; |
| 100 | 92 |
| 101 base::LazyInstance<SafeBrowsingBlockingPage::UnsafeResourceMap> | 93 base::LazyInstance<SafeBrowsingBlockingPage::UnsafeResourceMap> |
| 102 g_unsafe_resource_map = LAZY_INSTANCE_INITIALIZER; | 94 g_unsafe_resource_map = LAZY_INSTANCE_INITIALIZER; |
| 103 | 95 |
| 104 } // namespace | 96 } // namespace |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 367 } | 359 } |
| 368 | 360 |
| 369 void SafeBrowsingBlockingPage::OverrideRendererPrefs( | 361 void SafeBrowsingBlockingPage::OverrideRendererPrefs( |
| 370 content::RendererPreferences* prefs) { | 362 content::RendererPreferences* prefs) { |
| 371 Profile* profile = Profile::FromBrowserContext( | 363 Profile* profile = Profile::FromBrowserContext( |
| 372 web_contents()->GetBrowserContext()); | 364 web_contents()->GetBrowserContext()); |
| 373 renderer_preferences_util::UpdateFromSystemSettings( | 365 renderer_preferences_util::UpdateFromSystemSettings( |
| 374 prefs, profile, web_contents()); | 366 prefs, profile, web_contents()); |
| 375 } | 367 } |
| 376 | 368 |
| 377 void SafeBrowsingBlockingPage::SetReportingPreference(bool report) { | |
| 378 Profile* profile = Profile::FromBrowserContext( | |
| 379 web_contents()->GetBrowserContext()); | |
| 380 PrefService* pref = profile->GetPrefs(); | |
| 381 pref->SetBoolean(prefs::kSafeBrowsingExtendedReportingEnabled, report); | |
| 382 UMA_HISTOGRAM_BOOLEAN("SB2.SetExtendedReportingEnabled", report); | |
| 383 } | |
| 384 | |
| 385 void SafeBrowsingBlockingPage::OnProceed() { | 369 void SafeBrowsingBlockingPage::OnProceed() { |
| 386 proceeded_ = true; | 370 proceeded_ = true; |
| 387 // Send the malware details, if we opted to. | 371 // Send the malware details, if we opted to. |
| 388 FinishMalwareDetails(malware_details_proceed_delay_ms_); | 372 FinishMalwareDetails(malware_details_proceed_delay_ms_); |
| 389 | 373 |
| 390 NotifySafeBrowsingUIManager(ui_manager_, unsafe_resources_, true); | 374 NotifySafeBrowsingUIManager(ui_manager_, unsafe_resources_, true); |
| 391 | 375 |
| 392 // Check to see if some new notifications of unsafe resources have been | 376 // Check to see if some new notifications of unsafe resources have been |
| 393 // received while we were showing the interstitial. | 377 // received while we were showing the interstitial. |
| 394 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); | 378 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 468 UMA_HISTOGRAM_BOOLEAN("SB2.ExtendedReportingIsEnabled", enabled); | 452 UMA_HISTOGRAM_BOOLEAN("SB2.ExtendedReportingIsEnabled", enabled); |
| 469 if (enabled) { | 453 if (enabled) { |
| 470 // Finish the malware details collection, send it over. | 454 // Finish the malware details collection, send it over. |
| 471 BrowserThread::PostDelayedTask( | 455 BrowserThread::PostDelayedTask( |
| 472 BrowserThread::IO, FROM_HERE, | 456 BrowserThread::IO, FROM_HERE, |
| 473 base::Bind(&MalwareDetails::FinishCollection, malware_details_.get()), | 457 base::Bind(&MalwareDetails::FinishCollection, malware_details_.get()), |
| 474 base::TimeDelta::FromMilliseconds(delay_ms)); | 458 base::TimeDelta::FromMilliseconds(delay_ms)); |
| 475 } | 459 } |
| 476 } | 460 } |
| 477 | 461 |
| 478 bool SafeBrowsingBlockingPage::IsPrefEnabled(const char* pref) { | |
| 479 Profile* profile = | |
| 480 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | |
| 481 return profile->GetPrefs()->GetBoolean(pref); | |
| 482 } | |
| 483 | |
| 484 // static | 462 // static |
| 485 void SafeBrowsingBlockingPage::NotifySafeBrowsingUIManager( | 463 void SafeBrowsingBlockingPage::NotifySafeBrowsingUIManager( |
| 486 SafeBrowsingUIManager* ui_manager, | 464 SafeBrowsingUIManager* ui_manager, |
| 487 const UnsafeResourceList& unsafe_resources, | 465 const UnsafeResourceList& unsafe_resources, |
| 488 bool proceed) { | 466 bool proceed) { |
| 489 BrowserThread::PostTask( | 467 BrowserThread::PostTask( |
| 490 BrowserThread::IO, FROM_HERE, | 468 BrowserThread::IO, FROM_HERE, |
| 491 base::Bind(&SafeBrowsingUIManager::OnBlockingPageDone, | 469 base::Bind(&SafeBrowsingUIManager::OnBlockingPageDone, |
| 492 ui_manager, unsafe_resources, proceed)); | 470 ui_manager, unsafe_resources, proceed)); |
| 493 } | 471 } |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 615 case SB_REASON_PHISHING: | 593 case SB_REASON_PHISHING: |
| 616 PopulatePhishingLoadTimeData(load_time_data); | 594 PopulatePhishingLoadTimeData(load_time_data); |
| 617 break; | 595 break; |
| 618 } | 596 } |
| 619 } | 597 } |
| 620 | 598 |
| 621 void SafeBrowsingBlockingPage::PopulateExtendedReportingOption( | 599 void SafeBrowsingBlockingPage::PopulateExtendedReportingOption( |
| 622 base::DictionaryValue* load_time_data) { | 600 base::DictionaryValue* load_time_data) { |
| 623 // Only show checkbox if !(HTTPS || incognito-mode). | 601 // Only show checkbox if !(HTTPS || incognito-mode). |
| 624 const bool show = CanShowMalwareDetailsOption(); | 602 const bool show = CanShowMalwareDetailsOption(); |
| 625 load_time_data->SetBoolean(kDisplayCheckBox, show); | 603 load_time_data->SetBoolean(interstitials::kDisplayCheckBox, show); |
| 626 if (!show) | 604 if (!show) |
| 627 return; | 605 return; |
| 628 | 606 |
| 629 const std::string privacy_link = base::StringPrintf( | 607 const std::string privacy_link = base::StringPrintf( |
| 630 kPrivacyLinkHtml, | 608 interstitials::kPrivacyLinkHtml, |
| 631 l10n_util::GetStringUTF8( | 609 l10n_util::GetStringUTF8(IDS_SAFE_BROWSING_PRIVACY_POLICY_PAGE).c_str()); |
| 632 IDS_SAFE_BROWSING_PRIVACY_POLICY_PAGE).c_str()); | |
| 633 load_time_data->SetString( | 610 load_time_data->SetString( |
| 634 "optInLink", | 611 "optInLink", |
|
Bernhard Bauer
2015/03/03 09:45:59
If you have constants for the other keys, you migh
estark
2015/03/03 15:36:24
Done.
| |
| 635 l10n_util::GetStringFUTF16(IDS_SAFE_BROWSING_MALWARE_REPORTING_AGREE, | 612 l10n_util::GetStringFUTF16(IDS_SAFE_BROWSING_MALWARE_REPORTING_AGREE, |
| 636 base::UTF8ToUTF16(privacy_link))); | 613 base::UTF8ToUTF16(privacy_link))); |
| 637 load_time_data->SetBoolean( | 614 load_time_data->SetBoolean( |
| 638 kBoxChecked, | 615 interstitials::kBoxChecked, |
| 639 IsPrefEnabled(prefs::kSafeBrowsingExtendedReportingEnabled)); | 616 IsPrefEnabled(prefs::kSafeBrowsingExtendedReportingEnabled)); |
| 640 } | 617 } |
| 641 | 618 |
| 642 void SafeBrowsingBlockingPage::PopulateMalwareLoadTimeData( | 619 void SafeBrowsingBlockingPage::PopulateMalwareLoadTimeData( |
| 643 base::DictionaryValue* load_time_data) { | 620 base::DictionaryValue* load_time_data) { |
| 644 load_time_data->SetBoolean("phishing", false); | 621 load_time_data->SetBoolean("phishing", false); |
| 645 load_time_data->SetString( | 622 load_time_data->SetString( |
| 646 "heading", l10n_util::GetStringUTF16(IDS_MALWARE_V3_HEADING)); | 623 "heading", l10n_util::GetStringUTF16(IDS_MALWARE_V3_HEADING)); |
| 647 load_time_data->SetString( | 624 load_time_data->SetString( |
| 648 "primaryParagraph", | 625 "primaryParagraph", |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 702 load_time_data->SetString( | 679 load_time_data->SetString( |
| 703 "explanationParagraph", | 680 "explanationParagraph", |
| 704 l10n_util::GetStringFUTF16(IDS_PHISHING_V3_EXPLANATION_PARAGRAPH, | 681 l10n_util::GetStringFUTF16(IDS_PHISHING_V3_EXPLANATION_PARAGRAPH, |
| 705 GetFormattedHostName())); | 682 GetFormattedHostName())); |
| 706 load_time_data->SetString( | 683 load_time_data->SetString( |
| 707 "finalParagraph", | 684 "finalParagraph", |
| 708 l10n_util::GetStringUTF16(IDS_PHISHING_V3_PROCEED_PARAGRAPH)); | 685 l10n_util::GetStringUTF16(IDS_PHISHING_V3_PROCEED_PARAGRAPH)); |
| 709 | 686 |
| 710 PopulateExtendedReportingOption(load_time_data); | 687 PopulateExtendedReportingOption(load_time_data); |
| 711 } | 688 } |
| OLD | NEW |