Chromium Code Reviews| Index: chrome/browser/safe_browsing/safe_browsing_blocking_page.cc |
| diff --git a/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc b/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc |
| index c5b4c449b0d539b87804e0550ea47bfb989e208e..5361ed8b2f109c2b6398e1ea66bf09eb53a4f027 100644 |
| --- a/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc |
| +++ b/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc |
| @@ -9,6 +9,7 @@ |
| #include <string> |
| #include "base/bind.h" |
| +#include "base/command_line.h" |
| #include "base/i18n/rtl.h" |
| #include "base/lazy_instance.h" |
| #include "base/metrics/field_trial.h" |
| @@ -28,6 +29,7 @@ |
| #include "chrome/browser/safe_browsing/malware_details.h" |
| #include "chrome/browser/safe_browsing/ui_manager.h" |
| #include "chrome/browser/tab_contents/tab_util.h" |
| +#include "chrome/common/chrome_switches.h" |
| #include "chrome/common/pref_names.h" |
| #include "chrome/common/url_constants.h" |
| #include "content/public/browser/browser_thread.h" |
| @@ -93,23 +95,25 @@ const char kPrivacyLinkHtml[] = |
| const int64 kMalwareDetailsProceedDelayMilliSeconds = 3000; |
| // The commands returned by the page when the user performs an action. |
| -const char kShowDiagnosticCommand[] = "showDiagnostic"; |
| -const char kReportErrorCommand[] = "reportError"; |
| +const char kDoReportCommand[] = "doReport"; |
| +const char kDontReportCommand[] = "dontReport"; |
| +const char kExpandedSeeMoreCommand[] = "expandedSeeMore"; |
| const char kLearnMoreCommand[] = "learnMore"; |
| const char kLearnMoreCommandV2[] = "learnMore2"; |
| -const char kShowPrivacyCommand[] = "showPrivacy"; |
| const char kProceedCommand[] = "proceed"; |
| +const char kReportErrorCommand[] = "reportError"; |
| +const char kShowDiagnosticCommand[] = "showDiagnostic"; |
| +const char kShowPrivacyCommand[] = "showPrivacy"; |
| const char kTakeMeBackCommand[] = "takeMeBack"; |
| -const char kDoReportCommand[] = "doReport"; |
| -const char kDontReportCommand[] = "dontReport"; |
| -const char kDisplayCheckBox[] = "displaycheckbox"; |
| -const char kBoxChecked[] = "boxchecked"; |
| -const char kExpandedSeeMore[] = "expandedSeeMore"; |
| // Special command that we use when the user navigated away from the |
| // page. E.g., closed the tab or the window. This is only used by |
| // RecordUserReactionTime. |
| const char kNavigatedAwayMetaCommand[] = "closed"; |
| +// Other constants used to communicate with the JavaScript. |
| +const char kBoxChecked[] = "boxchecked"; |
| +const char kDisplayCheckBox[] = "displaycheckbox"; |
| + |
| base::LazyInstance<SafeBrowsingBlockingPage::UnsafeResourceMap> |
| g_unsafe_resource_map = LAZY_INSTANCE_INITIALIZER; |
| @@ -126,6 +130,10 @@ const char kCond12PhishingQuestion[] = "cond12PhishingQuestion"; |
| const char kCond13MalwareGoBack[] = "cond13MalwareGoBack"; |
| const char kCond14PhishingGoBack[] = "cond14PhishingGoBack"; |
| +// These are the constants for the M37 Finch trial. |
| +const char kV3StudyName[] = "MalwareInterstitialVersion"; |
| +const char kCondUseV3[] = "V3"; |
| + |
| // This enum is used for a histogram. Don't reorder, delete, or insert |
| // elements. New elements should be added before MAX_ACTION only. |
| enum DetailedDecision { |
| @@ -146,6 +154,34 @@ void RecordDetailedUserAction(DetailedDecision decision) { |
| MAX_DETAILED_ACTION); |
| } |
| +bool Version3Enabled() { |
| + if (CommandLine::ForCurrentProcess()->HasSwitch( |
| + switches::kMalwareInterstitialVersionV3)) { |
| + return true; |
| + } |
| + if (base::FieldTrialList::FindFullName(kV3StudyName) == kCondUseV3) |
| + return true; |
|
mattm
2014/06/11 02:11:45
It might be better not to honor the field trial un
felt
2014/06/11 02:23:29
Good idea, removing the field trial.
|
| + return false; |
| +} |
| + |
| +class SafeBrowsingBlockingPageV3 : public SafeBrowsingBlockingPage { |
| + public: |
| + SafeBrowsingBlockingPageV3(SafeBrowsingUIManager* ui_manager, |
| + content::WebContents* web_contents, |
| + const UnsafeResourceList& unsafe_resources); |
| + |
| + // InterstitialPageDelegate method: |
| + virtual std::string GetHTMLContents() OVERRIDE; |
| + |
| + private: |
| + // Fills the passed dictionary with the values to be passed to the template |
| + // when creating the HTML. |
| + void PopulateMalwareLoadTimeData(base::DictionaryValue* load_time_data); |
| + void PopulatePhishingLoadTimeData(base::DictionaryValue* load_time_data); |
| + |
| + DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPageV3); |
| +}; |
| + |
| } // namespace |
| // static |
| @@ -171,8 +207,13 @@ class SafeBrowsingBlockingPageFactoryImpl |
| unsafe_resources[0].threat_type == SB_THREAT_TYPE_URL_PHISHING || |
| unsafe_resources[0].threat_type == |
| SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL)) { |
| - return new SafeBrowsingBlockingPageV2(ui_manager, web_contents, |
| - unsafe_resources); |
| + if (Version3Enabled()) { |
| + return new SafeBrowsingBlockingPageV3(ui_manager, web_contents, |
| + unsafe_resources); |
| + } else { |
| + return new SafeBrowsingBlockingPageV2(ui_manager, web_contents, |
| + unsafe_resources); |
| + } |
| } |
| return new SafeBrowsingBlockingPageV1(ui_manager, web_contents, |
| unsafe_resources); |
| @@ -430,7 +471,7 @@ void SafeBrowsingBlockingPage::CommandReceived(const std::string& cmd) { |
| return; |
| } |
| - if (command == kExpandedSeeMore) { |
| + if (command == kExpandedSeeMoreCommand) { |
| // User expanded the "see more info" section of the page. We don't actually |
| // do any action based on this, it's just so that RecordUserReactionTime can |
| // track it. |
| @@ -713,7 +754,7 @@ void SafeBrowsingBlockingPage::RecordUserReactionTime( |
| dt); |
| } else if (command == kNavigatedAwayMetaCommand) { |
| UMA_HISTOGRAM_MEDIUM_TIMES("SB2.MalwareInterstitialTimeClosed", dt); |
| - } else if (command == kExpandedSeeMore) { |
| + } else if (command == kExpandedSeeMoreCommand) { |
| // Only record the expanded histogram once per display of the |
| // interstitial. |
| if (has_expanded_see_more_section_) |
| @@ -740,7 +781,7 @@ void SafeBrowsingBlockingPage::RecordUserReactionTime( |
| UMA_HISTOGRAM_MEDIUM_TIMES("SB2.PhishingInterstitialTimeLearnMore", dt); |
| } else if (command == kNavigatedAwayMetaCommand) { |
| UMA_HISTOGRAM_MEDIUM_TIMES("SB2.PhishingInterstitialTimeClosed", dt); |
| - } else if (command == kExpandedSeeMore) { |
| + } else if (command == kExpandedSeeMoreCommand) { |
| // Only record the expanded histogram once per display of the |
| // interstitial. |
| if (has_expanded_see_more_section_) |
| @@ -1192,3 +1233,126 @@ void SafeBrowsingBlockingPageV2::PopulatePhishingStringDictionary( |
| strings->SetString("learnMore", |
| l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_V2_LEARN_MORE)); |
| } |
| + |
| +SafeBrowsingBlockingPageV3::SafeBrowsingBlockingPageV3( |
| + SafeBrowsingUIManager* ui_manager, |
| + WebContents* web_contents, |
| + const UnsafeResourceList& unsafe_resources) |
| + : SafeBrowsingBlockingPage(ui_manager, web_contents, unsafe_resources) { |
| +} |
| + |
| +std::string SafeBrowsingBlockingPageV3::GetHTMLContents() { |
| + if (unsafe_resources_.empty() || unsafe_resources_.size() > 1) { |
| + // TODO(felt): Implement new multi-threat interstitial. crbug.com/160336 |
| + NOTIMPLEMENTED(); |
| + return std::string(); |
| + } |
| + |
| + // Fill in the shared values. |
| + base::DictionaryValue load_time_data; |
| + webui::SetFontAndTextDirection(&load_time_data); |
| + load_time_data.SetBoolean("ssl", false); |
| + load_time_data.SetString( |
| + "openDetails", |
| + l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_V2_SEE_MORE)); |
| + load_time_data.SetString( |
| + "closeDetails", |
| + l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_V2_SEE_MORE)); |
| + load_time_data.SetString( |
| + "primaryButtonText", |
| + l10n_util::GetStringUTF16(IDS_SSL_OVERRIDABLE_SAFETY_BUTTON)); |
| + load_time_data.SetString( |
| + "proceedText", |
| + l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_V2_PROCEED_LINK)); |
| + load_time_data.SetBoolean( |
| + "overridable", |
| + !IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)); |
| + |
| + // Fill in the values that are specific to malware or phishing. |
| + SBThreatType threat_type = unsafe_resources_[0].threat_type; |
| + switch (threat_type) { |
| + case SB_THREAT_TYPE_URL_MALWARE: |
| + case SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL: |
| + PopulateMalwareLoadTimeData(&load_time_data); |
| + break; |
| + case SB_THREAT_TYPE_URL_PHISHING: |
| + case SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL: |
| + PopulatePhishingLoadTimeData(&load_time_data); |
| + break; |
| + case SB_THREAT_TYPE_SAFE: |
| + case SB_THREAT_TYPE_BINARY_MALWARE_URL: |
| + case SB_THREAT_TYPE_EXTENSION: |
| + NOTREACHED(); |
| + } |
| + |
| + interstitial_show_time_ = base::TimeTicks::Now(); |
| + |
| + base::StringPiece html( |
| + ResourceBundle::GetSharedInstance().GetRawDataResource( |
| + IRD_SSL_INTERSTITIAL_V2_HTML)); |
| + webui::UseVersion2 version; |
| + return webui::GetI18nTemplateHtml(html, &load_time_data); |
| +} |
| + |
| +void SafeBrowsingBlockingPageV3::PopulateMalwareLoadTimeData( |
| + base::DictionaryValue* load_time_data) { |
| + load_time_data->SetBoolean("phishing", false); |
| + load_time_data->SetString( |
| + "tabTitle", |
| + l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_V2_TITLE)); |
| + load_time_data->SetString( |
| + "heading", |
| + l10n_util::GetStringUTF16(is_main_frame_load_blocked_ ? |
| + IDS_SAFE_BROWSING_MALWARE_V2_HEADLINE : |
| + IDS_SAFE_BROWSING_MALWARE_V2_HEADLINE_SUBRESOURCE)); |
| + load_time_data->SetString( |
| + "primaryParagraph", |
| + l10n_util::GetStringFUTF16( |
| + is_main_frame_load_blocked_ ? |
| + IDS_SAFE_BROWSING_MALWARE_V2_DESCRIPTION1 : |
| + IDS_SAFE_BROWSING_MALWARE_V2_DESCRIPTION1_SUBRESOURCE, |
| + l10n_util::GetStringUTF16(IDS_PRODUCT_NAME), |
| + base::UTF8ToUTF16(is_main_frame_load_blocked_ ? |
| + url_.host() : web_contents_->GetURL().host()))); |
| + load_time_data->SetString( |
| + "secondParagraph", |
| + is_main_frame_load_blocked_ ? |
| + l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_V2_DESCRIPTION2) : |
| + l10n_util::GetStringFUTF16( |
| + IDS_SAFE_BROWSING_MALWARE_V2_DESCRIPTION2_SUBRESOURCE, |
| + l10n_util::GetStringUTF16(IDS_PRODUCT_NAME), |
| + base::UTF8ToUTF16(url_.host()))); |
| + load_time_data->SetString( |
| + "thirdParagraph", |
| + l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_V2_DESCRIPTION3)); |
| + load_time_data->SetString( |
| + "detailsText", |
| + is_main_frame_load_blocked_ ? |
| + l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_V2_DETAILS) : |
| + l10n_util::GetStringFUTF16( |
| + IDS_SAFE_BROWSING_MALWARE_V2_DETAILS_SUBRESOURCE, |
| + base::UTF8ToUTF16(url_.host()))); |
| +} |
| + |
| +void SafeBrowsingBlockingPageV3::PopulatePhishingLoadTimeData( |
| + base::DictionaryValue* load_time_data) { |
| + load_time_data->SetBoolean("phishing", true); |
| + load_time_data->SetString( |
| + "tabTitle", |
| + l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_V2_TITLE)); |
| + load_time_data->SetString( |
| + "heading", |
| + l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_V2_HEADLINE)); |
| + load_time_data->SetString( |
| + "primaryParagraph", |
| + l10n_util::GetStringFUTF16( |
| + IDS_SAFE_BROWSING_PHISHING_V2_DESCRIPTION1, |
| + l10n_util::GetStringUTF16(IDS_PRODUCT_NAME), |
| + base::UTF8ToUTF16(url_.host()))); |
| + load_time_data->SetString( |
| + "secondParagraph", |
| + l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_V2_DESCRIPTION2)); |
| + load_time_data->SetString( |
| + "detailsText", |
| + l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_V2_REPORT_ERROR)); |
| +} |