diff options
author | panayiotis@google.com <panayiotis@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-07 18:51:38 +0000 |
---|---|---|
committer | panayiotis@google.com <panayiotis@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-07 18:51:38 +0000 |
commit | 674731cacddac05a7ddf1f333defe22bb5be8e1b (patch) | |
tree | e381e65e187b10ce5091b304fa3e6fc5840873a3 /chrome/browser/safe_browsing | |
parent | 39900b44ac1515cafacbe33d0578e52b9eafb25b (diff) | |
download | chromium_src-674731cacddac05a7ddf1f333defe22bb5be8e1b.zip chromium_src-674731cacddac05a7ddf1f333defe22bb5be8e1b.tar.gz chromium_src-674731cacddac05a7ddf1f333defe22bb5be8e1b.tar.bz2 |
Add a checkbox to the malware interstitial page, for user to opt-in to send malware report. The user's choice will be stored as preference in user's profile.
Landing original change by kewang: http://codereview.chromium.org/5102001/.
BUG=60831
TEST=Relevant unit_tests,browser_tests
Review URL: http://codereview.chromium.org/6066011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@70755 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/safe_browsing')
4 files changed, 80 insertions, 8 deletions
diff --git a/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc b/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc index 11dcfd8..95baed4 100644 --- a/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc +++ b/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc @@ -15,6 +15,7 @@ #include "base/string_number_conversions.h" #include "base/utf_string_conversions.h" #include "base/values.h" +#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_thread.h" #include "chrome/browser/dom_operation_notification_details.h" #include "chrome/browser/dom_ui/new_tab_ui.h" @@ -72,6 +73,10 @@ static const char* const kReportErrorCommand = "reportError"; static const char* const kLearnMoreCommand = "learnMore"; static const char* const kProceedCommand = "proceed"; static const char* const kTakeMeBackCommand = "takeMeBack"; +static const char* const kDoReportCommand = "doReport"; +static const char* const kDontReportCommand = "dontReport"; +static const char* const kDisplayCheckBox = "displaycheckbox"; +static const char* const kBoxChecked = "boxchecked"; // static SafeBrowsingBlockingPageFactory* SafeBrowsingBlockingPage::factory_ = NULL; @@ -316,6 +321,27 @@ void SafeBrowsingBlockingPage::PopulateMalwareStringDictionary( strings->SetString("proceed_link", l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_PROCEED_LINK)); strings->SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr"); + + if (!CanShowMalwareDetailsOption()) { + strings->SetBoolean(kDisplayCheckBox, false); + } else { + // Show the checkbox for sending malware details. + strings->SetBoolean(kDisplayCheckBox, true); + strings->SetString( + "confirm_text", + l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_REPORTING_AGREE)); + + const PrefService::Preference* pref = + tab()->profile()->GetPrefs()->FindPreference( + prefs::kSafeBrowsingReportingEnabled); + + bool value; + if (pref && pref->GetValue()->GetAsBoolean(&value) && value) { + strings->SetString(kBoxChecked, "yes"); + } else { + strings->SetString(kBoxChecked, ""); + } + } } void SafeBrowsingBlockingPage::PopulatePhishingStringDictionary( @@ -349,6 +375,16 @@ void SafeBrowsingBlockingPage::CommandReceived(const std::string& cmd) { command = command.substr(1, command.length() - 2); } + if (command == kDoReportCommand) { + SetReportingPreference(true); + return; + } + + if (command == kDontReportCommand) { + SetReportingPreference(false); + return; + } + if (command == kLearnMoreCommand) { // User pressed "Learn more". GURL url; @@ -424,6 +460,11 @@ void SafeBrowsingBlockingPage::CommandReceived(const std::string& cmd) { NOTREACHED() << "Unexpected command: " << command; } +void SafeBrowsingBlockingPage::SetReportingPreference(bool report) { + PrefService* pref = tab()->profile()->GetPrefs(); + pref->SetBoolean(prefs::kSafeBrowsingReportingEnabled, report); +} + void SafeBrowsingBlockingPage::Proceed() { RecordUserAction(PROCEED); FinishMalwareDetails(); // Send the malware details, if we opted to. diff --git a/chrome/browser/safe_browsing/safe_browsing_blocking_page.h b/chrome/browser/safe_browsing/safe_browsing_blocking_page.h index e06b23b..2cadfc1 100644 --- a/chrome/browser/safe_browsing/safe_browsing_blocking_page.h +++ b/chrome/browser/safe_browsing/safe_browsing_blocking_page.h @@ -66,6 +66,7 @@ class SafeBrowsingBlockingPage : public InterstitialPage { // InterstitialPage method: virtual std::string GetHTMLContents(); + virtual void SetReportingPreference(bool report); virtual void Proceed(); virtual void DontProceed(); @@ -106,7 +107,7 @@ class SafeBrowsingBlockingPage : public InterstitialPage { // SBInterstitial[Phishing|Malware|Multiple][Show|Proceed|DontProceed]. void RecordUserAction(BlockingPageEvent event); - // See if we should even show the malware details option. For example, we + // Checks if we should even show the malware details option. For example, we // don't show it in incognito mode. bool CanShowMalwareDetailsOption(); diff --git a/chrome/browser/safe_browsing/safe_browsing_blocking_page_test.cc b/chrome/browser/safe_browsing/safe_browsing_blocking_page_test.cc index 0c9f40c..318e6ac 100644 --- a/chrome/browser/safe_browsing/safe_browsing_blocking_page_test.cc +++ b/chrome/browser/safe_browsing/safe_browsing_blocking_page_test.cc @@ -297,19 +297,17 @@ IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, MalwareIframeReportDetails) { - // Enable reporting of malware details. - browser()->GetProfile()->GetPrefs()->SetBoolean( - prefs::kSafeBrowsingReportingEnabled, true); - EXPECT_TRUE(browser()->GetProfile()->GetPrefs()->GetBoolean( - prefs::kSafeBrowsingReportingEnabled)); - GURL url = test_server()->GetURL(kMalwarePage); GURL iframe_url = test_server()->GetURL(kMalwareIframe); AddURLResult(iframe_url, SafeBrowsingService::URL_MALWARE); ui_test_utils::NavigateToURL(browser(), url); - SendCommand("\"proceed\""); // Simulate the user clicking "back" + SendCommand("\"doReport\""); // Simulate the user checking the checkbox. + EXPECT_TRUE(browser()->GetProfile()->GetPrefs()->GetBoolean( + prefs::kSafeBrowsingReportingEnabled)); + + SendCommand("\"proceed\""); // Simulate the user clicking "back" AssertNoInterstitial(); // Assert the interstitial is gone EXPECT_EQ(url, browser()->GetSelectedTabContents()->GetURL()); diff --git a/chrome/browser/safe_browsing/safe_browsing_blocking_page_unittest.cc b/chrome/browser/safe_browsing/safe_browsing_blocking_page_unittest.cc index 195f5c0..5b8163b 100644 --- a/chrome/browser/safe_browsing/safe_browsing_blocking_page_unittest.cc +++ b/chrome/browser/safe_browsing/safe_browsing_blocking_page_unittest.cc @@ -548,3 +548,35 @@ TEST_F(SafeBrowsingBlockingPageTest, MalwareReportsDisabled) { EXPECT_EQ(0u, service_->GetDetails()->size()); service_->GetDetails()->clear(); } + +// Test setting the malware report preferance +TEST_F(SafeBrowsingBlockingPageTest, MalwareReports) { + // Disable malware reports. + contents()->profile()->GetPrefs()->SetBoolean( + prefs::kSafeBrowsingReportingEnabled, false); + + // Start a load. + controller().LoadURL(GURL(kBadURL), GURL(), PageTransition::TYPED); + + // Simulate the load causing a safe browsing interstitial to be shown. + ShowInterstitial(ResourceType::MAIN_FRAME, kBadURL); + SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); + ASSERT_TRUE(sb_interstitial); + + MessageLoop::current()->RunAllPending(); + + EXPECT_FALSE(contents()->profile()->GetPrefs()->GetBoolean( + prefs::kSafeBrowsingReportingEnabled)); + + // Simulate the user check the report agreement checkbox. + sb_interstitial->SetReportingPreference(true); + + EXPECT_TRUE(contents()->profile()->GetPrefs()->GetBoolean( + prefs::kSafeBrowsingReportingEnabled)); + + // Simulate the user uncheck the report agreement checkbox. + sb_interstitial->SetReportingPreference(false); + + EXPECT_FALSE(contents()->profile()->GetPrefs()->GetBoolean( + prefs::kSafeBrowsingReportingEnabled)); +} |