| 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 | 8 |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 | 72 |
| 73 void SecurityInterstitialPage::Show() { | 73 void SecurityInterstitialPage::Show() { |
| 74 DCHECK(!interstitial_page_); | 74 DCHECK(!interstitial_page_); |
| 75 interstitial_page_ = content::InterstitialPage::Create( | 75 interstitial_page_ = content::InterstitialPage::Create( |
| 76 web_contents_, ShouldCreateNewNavigation(), request_url_, this); | 76 web_contents_, ShouldCreateNewNavigation(), request_url_, this); |
| 77 if (!create_view_) | 77 if (!create_view_) |
| 78 interstitial_page_->DontCreateViewForTesting(); | 78 interstitial_page_->DontCreateViewForTesting(); |
| 79 interstitial_page_->Show(); | 79 interstitial_page_->Show(); |
| 80 } | 80 } |
| 81 | 81 |
| 82 void SecurityInterstitialPage::SetReportingPreference(bool report) { | |
| 83 Profile* profile = | |
| 84 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | |
| 85 PrefService* pref = profile->GetPrefs(); | |
| 86 pref->SetBoolean(prefs::kSafeBrowsingExtendedReportingEnabled, report); | |
| 87 metrics_helper()->RecordUserInteraction( | |
| 88 report ? security_interstitials::MetricsHelper:: | |
| 89 SET_EXTENDED_REPORTING_ENABLED | |
| 90 : security_interstitials::MetricsHelper:: | |
| 91 SET_EXTENDED_REPORTING_DISABLED); | |
| 92 } | |
| 93 | |
| 94 bool SecurityInterstitialPage::IsPrefEnabled(const char* pref) { | 82 bool SecurityInterstitialPage::IsPrefEnabled(const char* pref) { |
| 95 Profile* profile = | 83 Profile* profile = |
| 96 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 84 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| 97 return profile->GetPrefs()->GetBoolean(pref); | 85 return profile->GetPrefs()->GetBoolean(pref); |
| 98 } | 86 } |
| 99 | 87 |
| 100 void SecurityInterstitialPage::OpenExtendedReportingPrivacyPolicy() { | |
| 101 metrics_helper()->RecordUserInteraction( | |
| 102 security_interstitials::MetricsHelper::SHOW_PRIVACY_POLICY); | |
| 103 GURL privacy_url( | |
| 104 l10n_util::GetStringUTF8(IDS_SAFE_BROWSING_PRIVACY_POLICY_URL)); | |
| 105 privacy_url = google_util::AppendGoogleLocaleParam( | |
| 106 privacy_url, g_browser_process->GetApplicationLocale()); | |
| 107 OpenURLParams params(privacy_url, Referrer(), CURRENT_TAB, | |
| 108 ui::PAGE_TRANSITION_LINK, false); | |
| 109 web_contents()->OpenURL(params); | |
| 110 } | |
| 111 | |
| 112 security_interstitials::MetricsHelper* | |
| 113 SecurityInterstitialPage::metrics_helper() const { | |
| 114 return metrics_helper_.get(); | |
| 115 } | |
| 116 | |
| 117 void SecurityInterstitialPage::set_metrics_helper( | |
| 118 scoped_ptr<security_interstitials::MetricsHelper> metrics_helper) { | |
| 119 metrics_helper_ = metrics_helper.Pass(); | |
| 120 } | |
| 121 | |
| 122 base::string16 SecurityInterstitialPage::GetFormattedHostName() const { | 88 base::string16 SecurityInterstitialPage::GetFormattedHostName() const { |
| 123 std::string languages; | 89 std::string languages; |
| 124 Profile* profile = | 90 Profile* profile = |
| 125 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 91 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| 126 if (profile) | 92 if (profile) |
| 127 languages = profile->GetPrefs()->GetString(prefs::kAcceptLanguages); | 93 languages = profile->GetPrefs()->GetString(prefs::kAcceptLanguages); |
| 128 base::string16 host = | 94 base::string16 host = |
| 129 url_formatter::IDNToUnicode(request_url_.host(), languages); | 95 url_formatter::IDNToUnicode(request_url_.host(), languages); |
| 130 if (base::i18n::IsRTL()) | 96 if (base::i18n::IsRTL()) |
| 131 base::i18n::WrapStringWithLTRFormatting(&host); | 97 base::i18n::WrapStringWithLTRFormatting(&host); |
| 132 return host; | 98 return host; |
| 133 } | 99 } |
| 134 | 100 |
| 135 std::string SecurityInterstitialPage::GetHTMLContents() { | 101 std::string SecurityInterstitialPage::GetHTMLContents() { |
| 136 base::DictionaryValue load_time_data; | 102 base::DictionaryValue load_time_data; |
| 137 PopulateInterstitialStrings(&load_time_data); | 103 PopulateInterstitialStrings(&load_time_data); |
| 138 const std::string& app_locale = g_browser_process->GetApplicationLocale(); | 104 const std::string& app_locale = g_browser_process->GetApplicationLocale(); |
| 139 webui::SetLoadTimeDataDefaults(app_locale, &load_time_data); | 105 webui::SetLoadTimeDataDefaults(app_locale, &load_time_data); |
| 140 std::string html = ResourceBundle::GetSharedInstance() | 106 std::string html = ResourceBundle::GetSharedInstance() |
| 141 .GetRawDataResource(IDR_SECURITY_INTERSTITIAL_HTML) | 107 .GetRawDataResource(IDR_SECURITY_INTERSTITIAL_HTML) |
| 142 .as_string(); | 108 .as_string(); |
| 143 webui::AppendWebUiCssTextDefaults(&html); | 109 webui::AppendWebUiCssTextDefaults(&html); |
| 144 return webui::GetI18nTemplateHtml(html, &load_time_data); | 110 return webui::GetI18nTemplateHtml(html, &load_time_data); |
| 145 } | 111 } |
| 112 |
| 113 void SecurityInterstitialPage::OpenUrlInCurrentTab(const GURL& url) { |
| 114 OpenURLParams params(url, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_LINK, |
| 115 false); |
| 116 web_contents()->OpenURL(params); |
| 117 } |
| 118 |
| 119 const std::string& SecurityInterstitialPage::GetApplicationLocale() { |
| 120 return g_browser_process->GetApplicationLocale(); |
| 121 } |
| 122 |
| 123 PrefService* SecurityInterstitialPage::GetPrefService() { |
| 124 Profile* profile = |
| 125 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| 126 return profile->GetPrefs(); |
| 127 } |
| 128 |
| 129 const std::string SecurityInterstitialPage::GetExtendedReportingPrefName() { |
| 130 return prefs::kSafeBrowsingExtendedReportingEnabled; |
| 131 } |
| OLD | NEW |