| OLD | NEW |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 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 #include "chrome/browser/interstitials/security_interstitial_page.h" | 5 #include "chrome/browser/interstitials/security_interstitial_page.h" |
| 6 | 6 |
| 7 #include "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
| 8 |
| 9 #include "base/metrics/histogram.h" |
| 8 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/values.h" | 12 #include "base/values.h" |
| 11 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/interstitials/security_interstitial_metrics_helper.h" |
| 15 #include "chrome/browser/net/referrer.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 14 #include "chrome/grit/browser_resources.h" | 18 #include "chrome/grit/browser_resources.h" |
| 19 #include "chrome/grit/generated_resources.h" |
| 20 #include "components/google/core/browser/google_util.h" |
| 15 #include "content/public/browser/interstitial_page.h" | 21 #include "content/public/browser/interstitial_page.h" |
| 22 #include "content/public/browser/page_navigator.h" |
| 16 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
| 17 #include "net/base/net_util.h" | 24 #include "net/base/net_util.h" |
| 25 #include "ui/base/l10n/l10n_util.h" |
| 18 #include "ui/base/resource/resource_bundle.h" | 26 #include "ui/base/resource/resource_bundle.h" |
| 19 #include "ui/base/webui/jstemplate_builder.h" | 27 #include "ui/base/webui/jstemplate_builder.h" |
| 20 #include "ui/base/webui/web_ui_util.h" | 28 #include "ui/base/webui/web_ui_util.h" |
| 21 | 29 |
| 30 namespace interstitials { |
| 31 const char kBoxChecked[] = "boxchecked"; |
| 32 const char kDisplayCheckBox[] = "displaycheckbox"; |
| 33 const char kOptInLink[] = "optInLink"; |
| 34 const char kPrivacyLinkHtml[] = |
| 35 "<a id=\"privacy-link\" href=\"\" onclick=\"sendCommand(%d); " |
| 36 "return false;\" onmousedown=\"return false;\">%s</a>"; |
| 37 } |
| 38 |
| 39 using content::OpenURLParams; |
| 40 using content::Referrer; |
| 41 |
| 22 SecurityInterstitialPage::SecurityInterstitialPage( | 42 SecurityInterstitialPage::SecurityInterstitialPage( |
| 23 content::WebContents* web_contents, | 43 content::WebContents* web_contents, |
| 24 const GURL& request_url) | 44 const GURL& request_url) |
| 25 : web_contents_(web_contents), | 45 : web_contents_(web_contents), |
| 26 request_url_(request_url), | 46 request_url_(request_url), |
| 27 interstitial_page_(NULL), | 47 interstitial_page_(NULL), |
| 28 create_view_(true) { | 48 create_view_(true) { |
| 29 // Creating interstitial_page_ without showing it leaks memory, so don't | 49 // Creating interstitial_page_ without showing it leaks memory, so don't |
| 30 // create it here. | 50 // create it here. |
| 31 } | 51 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 51 | 71 |
| 52 void SecurityInterstitialPage::Show() { | 72 void SecurityInterstitialPage::Show() { |
| 53 DCHECK(!interstitial_page_); | 73 DCHECK(!interstitial_page_); |
| 54 interstitial_page_ = content::InterstitialPage::Create( | 74 interstitial_page_ = content::InterstitialPage::Create( |
| 55 web_contents_, ShouldCreateNewNavigation(), request_url_, this); | 75 web_contents_, ShouldCreateNewNavigation(), request_url_, this); |
| 56 if (!create_view_) | 76 if (!create_view_) |
| 57 interstitial_page_->DontCreateViewForTesting(); | 77 interstitial_page_->DontCreateViewForTesting(); |
| 58 interstitial_page_->Show(); | 78 interstitial_page_->Show(); |
| 59 } | 79 } |
| 60 | 80 |
| 81 void SecurityInterstitialPage::SetReportingPreference(bool report) { |
| 82 Profile* profile = |
| 83 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| 84 PrefService* pref = profile->GetPrefs(); |
| 85 pref->SetBoolean(prefs::kSafeBrowsingExtendedReportingEnabled, report); |
| 86 metrics_helper()->RecordUserInteraction( |
| 87 report |
| 88 ? SecurityInterstitialMetricsHelper::SET_EXTENDED_REPORTING_ENABLED |
| 89 : SecurityInterstitialMetricsHelper::SET_EXTENDED_REPORTING_DISABLED); |
| 90 } |
| 91 |
| 92 bool SecurityInterstitialPage::IsPrefEnabled(const char* pref) { |
| 93 Profile* profile = |
| 94 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| 95 return profile->GetPrefs()->GetBoolean(pref); |
| 96 } |
| 97 |
| 98 void SecurityInterstitialPage::OpenExtendedReportingPrivacyPolicy() { |
| 99 metrics_helper()->RecordUserInteraction( |
| 100 SecurityInterstitialMetricsHelper::SHOW_PRIVACY_POLICY); |
| 101 GURL privacy_url( |
| 102 l10n_util::GetStringUTF8(IDS_SAFE_BROWSING_PRIVACY_POLICY_URL)); |
| 103 privacy_url = google_util::AppendGoogleLocaleParam( |
| 104 privacy_url, g_browser_process->GetApplicationLocale()); |
| 105 OpenURLParams params(privacy_url, Referrer(), CURRENT_TAB, |
| 106 ui::PAGE_TRANSITION_LINK, false); |
| 107 web_contents()->OpenURL(params); |
| 108 } |
| 109 |
| 110 SecurityInterstitialMetricsHelper* SecurityInterstitialPage::metrics_helper() { |
| 111 return metrics_helper_.get(); |
| 112 } |
| 113 |
| 114 void SecurityInterstitialPage::set_metrics_helper( |
| 115 SecurityInterstitialMetricsHelper* metrics_helper) { |
| 116 metrics_helper_.reset(metrics_helper); |
| 117 } |
| 118 |
| 61 base::string16 SecurityInterstitialPage::GetFormattedHostName() const { | 119 base::string16 SecurityInterstitialPage::GetFormattedHostName() const { |
| 62 std::string languages; | 120 std::string languages; |
| 63 Profile* profile = | 121 Profile* profile = |
| 64 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 122 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| 65 if (profile) | 123 if (profile) |
| 66 languages = profile->GetPrefs()->GetString(prefs::kAcceptLanguages); | 124 languages = profile->GetPrefs()->GetString(prefs::kAcceptLanguages); |
| 67 base::string16 host = net::IDNToUnicode(request_url_.host(), languages); | 125 base::string16 host = net::IDNToUnicode(request_url_.host(), languages); |
| 68 if (base::i18n::IsRTL()) | 126 if (base::i18n::IsRTL()) |
| 69 base::i18n::WrapStringWithLTRFormatting(&host); | 127 base::i18n::WrapStringWithLTRFormatting(&host); |
| 70 return host; | 128 return host; |
| 71 } | 129 } |
| 72 | 130 |
| 73 std::string SecurityInterstitialPage::GetHTMLContents() { | 131 std::string SecurityInterstitialPage::GetHTMLContents() { |
| 74 base::DictionaryValue load_time_data; | 132 base::DictionaryValue load_time_data; |
| 75 PopulateInterstitialStrings(&load_time_data); | 133 PopulateInterstitialStrings(&load_time_data); |
| 76 const std::string& app_locale = g_browser_process->GetApplicationLocale(); | 134 const std::string& app_locale = g_browser_process->GetApplicationLocale(); |
| 77 webui::SetLoadTimeDataDefaults(app_locale, &load_time_data); | 135 webui::SetLoadTimeDataDefaults(app_locale, &load_time_data); |
| 78 std::string html = ResourceBundle::GetSharedInstance() | 136 std::string html = ResourceBundle::GetSharedInstance() |
| 79 .GetRawDataResource(IDR_SECURITY_INTERSTITIAL_HTML) | 137 .GetRawDataResource(IDR_SECURITY_INTERSTITIAL_HTML) |
| 80 .as_string(); | 138 .as_string(); |
| 81 webui::AppendWebUiCssTextDefaults(&html); | 139 webui::AppendWebUiCssTextDefaults(&html); |
| 82 return webui::GetI18nTemplateHtml(html, &load_time_data); | 140 return webui::GetI18nTemplateHtml(html, &load_time_data); |
| 83 } | 141 } |
| OLD | NEW |