Chromium Code Reviews| 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 #include "base/metrics/histogram.h" | |
| 9 #include "base/prefs/pref_service.h" | |
| 8 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 9 #include "base/values.h" | 11 #include "base/values.h" |
| 10 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/profiles/profile.h" | |
| 14 #include "chrome/common/pref_names.h" | |
| 11 #include "chrome/grit/browser_resources.h" | 15 #include "chrome/grit/browser_resources.h" |
| 12 #include "content/public/browser/interstitial_page.h" | 16 #include "content/public/browser/interstitial_page.h" |
| 13 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
| 14 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
| 15 #include "ui/base/webui/jstemplate_builder.h" | 19 #include "ui/base/webui/jstemplate_builder.h" |
| 16 #include "ui/base/webui/web_ui_util.h" | 20 #include "ui/base/webui/web_ui_util.h" |
| 17 | 21 |
| 22 namespace interstitials { | |
| 23 const char kBoxChecked[] = "boxchecked"; | |
| 24 const char kDisplayCheckBox[] = "displaycheckbox"; | |
| 25 const char kOptInLink[] = "optInLink"; | |
| 26 const char kPrivacyLinkHtml[] = | |
|
felt
2015/03/13 19:18:11
This needs to be updated, given that https://coder
estark
2015/03/16 23:40:52
Done.
| |
| 27 "<a id=\"privacy-link\" href=\"\" onclick=\"sendCommand('showPrivacy'); " | |
| 28 "return false;\" onmousedown=\"return false;\">%s</a>"; | |
| 29 } | |
| 30 | |
| 18 SecurityInterstitialPage::SecurityInterstitialPage( | 31 SecurityInterstitialPage::SecurityInterstitialPage( |
| 19 content::WebContents* web_contents, | 32 content::WebContents* web_contents, |
| 20 const GURL& request_url) | 33 const GURL& request_url) |
| 21 : web_contents_(web_contents), | 34 : web_contents_(web_contents), |
| 22 request_url_(request_url), | 35 request_url_(request_url), |
| 23 interstitial_page_(NULL), | 36 interstitial_page_(NULL), |
| 24 create_view_(true) { | 37 create_view_(true) { |
| 25 // Creating interstitial_page_ without showing it leaks memory, so don't | 38 // Creating interstitial_page_ without showing it leaks memory, so don't |
| 26 // create it here. | 39 // create it here. |
| 27 } | 40 } |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 38 } | 51 } |
| 39 | 52 |
| 40 GURL SecurityInterstitialPage::request_url() const { | 53 GURL SecurityInterstitialPage::request_url() const { |
| 41 return request_url_; | 54 return request_url_; |
| 42 } | 55 } |
| 43 | 56 |
| 44 void SecurityInterstitialPage::DontCreateViewForTesting() { | 57 void SecurityInterstitialPage::DontCreateViewForTesting() { |
| 45 create_view_ = false; | 58 create_view_ = false; |
| 46 } | 59 } |
| 47 | 60 |
| 61 void SecurityInterstitialPage::SetCertificateReportCallbackForTesting( | |
| 62 const base::Closure& callback) { | |
| 63 certificate_report_callback_for_testing_ = callback; | |
| 64 } | |
| 65 | |
| 48 void SecurityInterstitialPage::Show() { | 66 void SecurityInterstitialPage::Show() { |
| 49 DCHECK(!interstitial_page_); | 67 DCHECK(!interstitial_page_); |
| 50 interstitial_page_ = content::InterstitialPage::Create( | 68 interstitial_page_ = content::InterstitialPage::Create( |
| 51 web_contents_, ShouldCreateNewNavigation(), request_url_, this); | 69 web_contents_, ShouldCreateNewNavigation(), request_url_, this); |
| 52 if (!create_view_) | 70 if (!create_view_) |
| 53 interstitial_page_->DontCreateViewForTesting(); | 71 interstitial_page_->DontCreateViewForTesting(); |
| 54 interstitial_page_->Show(); | 72 interstitial_page_->Show(); |
| 55 } | 73 } |
| 56 | 74 |
| 57 base::string16 SecurityInterstitialPage::GetFormattedHostName() const { | 75 base::string16 SecurityInterstitialPage::GetFormattedHostName() const { |
| 58 base::string16 host(base::UTF8ToUTF16(request_url_.host())); | 76 base::string16 host(base::UTF8ToUTF16(request_url_.host())); |
| 59 if (base::i18n::IsRTL()) | 77 if (base::i18n::IsRTL()) |
| 60 base::i18n::WrapStringWithLTRFormatting(&host); | 78 base::i18n::WrapStringWithLTRFormatting(&host); |
| 61 return host; | 79 return host; |
| 62 } | 80 } |
| 63 | 81 |
| 64 std::string SecurityInterstitialPage::GetHTMLContents() { | 82 std::string SecurityInterstitialPage::GetHTMLContents() { |
| 65 base::DictionaryValue load_time_data; | 83 base::DictionaryValue load_time_data; |
| 66 PopulateInterstitialStrings(&load_time_data); | 84 PopulateInterstitialStrings(&load_time_data); |
| 67 const std::string& app_locale = g_browser_process->GetApplicationLocale(); | 85 const std::string& app_locale = g_browser_process->GetApplicationLocale(); |
| 68 webui::SetLoadTimeDataDefaults(app_locale, &load_time_data); | 86 webui::SetLoadTimeDataDefaults(app_locale, &load_time_data); |
| 69 std::string html = ResourceBundle::GetSharedInstance() | 87 std::string html = ResourceBundle::GetSharedInstance() |
| 70 .GetRawDataResource(IDR_SECURITY_INTERSTITIAL_HTML) | 88 .GetRawDataResource(IDR_SECURITY_INTERSTITIAL_HTML) |
| 71 .as_string(); | 89 .as_string(); |
| 72 webui::AppendWebUiCssTextDefaults(&html); | 90 webui::AppendWebUiCssTextDefaults(&html); |
| 73 return webui::GetI18nTemplateHtml(html, &load_time_data); | 91 return webui::GetI18nTemplateHtml(html, &load_time_data); |
| 74 } | 92 } |
| 93 | |
| 94 void SecurityInterstitialPage::SetReportingPreference(bool report) { | |
| 95 Profile* profile = | |
| 96 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | |
| 97 PrefService* pref = profile->GetPrefs(); | |
| 98 pref->SetBoolean(prefs::kSafeBrowsingExtendedReportingEnabled, report); | |
| 99 UMA_HISTOGRAM_BOOLEAN("SB2.SetExtendedReportingEnabled", report); | |
| 100 } | |
| 101 | |
| 102 bool SecurityInterstitialPage::IsPrefEnabled(const char* pref) { | |
| 103 Profile* profile = | |
| 104 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | |
| 105 return profile->GetPrefs()->GetBoolean(pref); | |
| 106 } | |
| OLD | NEW |