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[] = | |
| 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. |
| 40 | |
| 41 certificate_report_callback_for_testing_ = base::Bind(&base::DoNothing); | |
| 27 } | 42 } |
| 28 | 43 |
| 29 SecurityInterstitialPage::~SecurityInterstitialPage() { | 44 SecurityInterstitialPage::~SecurityInterstitialPage() { |
| 30 } | 45 } |
| 31 | 46 |
| 32 content::InterstitialPage* SecurityInterstitialPage::interstitial_page() const { | 47 content::InterstitialPage* SecurityInterstitialPage::interstitial_page() const { |
| 33 return interstitial_page_; | 48 return interstitial_page_; |
| 34 } | 49 } |
| 35 | 50 |
| 36 content::WebContents* SecurityInterstitialPage::web_contents() const { | 51 content::WebContents* SecurityInterstitialPage::web_contents() const { |
| 37 return web_contents_; | 52 return web_contents_; |
| 38 } | 53 } |
| 39 | 54 |
| 40 GURL SecurityInterstitialPage::request_url() const { | 55 GURL SecurityInterstitialPage::request_url() const { |
| 41 return request_url_; | 56 return request_url_; |
| 42 } | 57 } |
| 43 | 58 |
| 44 void SecurityInterstitialPage::DontCreateViewForTesting() { | 59 void SecurityInterstitialPage::DontCreateViewForTesting() { |
| 45 create_view_ = false; | 60 create_view_ = false; |
| 46 } | 61 } |
| 47 | 62 |
| 63 void SecurityInterstitialPage::SetCertificateReportCallbackForTesting( | |
| 64 base::Callback<void()>& callback) { | |
| 65 certificate_report_callback_for_testing_ = callback; | |
| 66 } | |
| 67 | |
| 48 void SecurityInterstitialPage::Show() { | 68 void SecurityInterstitialPage::Show() { |
| 49 DCHECK(!interstitial_page_); | 69 DCHECK(!interstitial_page_); |
| 50 interstitial_page_ = content::InterstitialPage::Create( | 70 interstitial_page_ = content::InterstitialPage::Create( |
| 51 web_contents_, ShouldCreateNewNavigation(), request_url_, this); | 71 web_contents_, ShouldCreateNewNavigation(), request_url_, this); |
| 52 if (!create_view_) | 72 if (!create_view_) |
| 53 interstitial_page_->DontCreateViewForTesting(); | 73 interstitial_page_->DontCreateViewForTesting(); |
| 54 interstitial_page_->Show(); | 74 interstitial_page_->Show(); |
| 55 } | 75 } |
| 56 | 76 |
| 57 base::string16 SecurityInterstitialPage::GetFormattedHostName() const { | 77 base::string16 SecurityInterstitialPage::GetFormattedHostName() const { |
| 58 base::string16 host(base::UTF8ToUTF16(request_url_.host())); | 78 base::string16 host(base::UTF8ToUTF16(request_url_.host())); |
| 59 if (base::i18n::IsRTL()) | 79 if (base::i18n::IsRTL()) |
| 60 base::i18n::WrapStringWithLTRFormatting(&host); | 80 base::i18n::WrapStringWithLTRFormatting(&host); |
| 61 return host; | 81 return host; |
| 62 } | 82 } |
| 63 | 83 |
| 64 std::string SecurityInterstitialPage::GetHTMLContents() { | 84 std::string SecurityInterstitialPage::GetHTMLContents() { |
| 65 base::DictionaryValue load_time_data; | 85 base::DictionaryValue load_time_data; |
| 66 PopulateInterstitialStrings(&load_time_data); | 86 PopulateInterstitialStrings(&load_time_data); |
| 67 const std::string& app_locale = g_browser_process->GetApplicationLocale(); | 87 const std::string& app_locale = g_browser_process->GetApplicationLocale(); |
| 68 webui::SetLoadTimeDataDefaults(app_locale, &load_time_data); | 88 webui::SetLoadTimeDataDefaults(app_locale, &load_time_data); |
| 69 std::string html = ResourceBundle::GetSharedInstance() | 89 std::string html = ResourceBundle::GetSharedInstance() |
| 70 .GetRawDataResource(IDR_SECURITY_INTERSTITIAL_HTML) | 90 .GetRawDataResource(IDR_SECURITY_INTERSTITIAL_HTML) |
| 71 .as_string(); | 91 .as_string(); |
| 72 webui::AppendWebUiCssTextDefaults(&html); | 92 webui::AppendWebUiCssTextDefaults(&html); |
| 73 return webui::GetI18nTemplateHtml(html, &load_time_data); | 93 return webui::GetI18nTemplateHtml(html, &load_time_data); |
| 74 } | 94 } |
| 95 | |
| 96 void SecurityInterstitialPage::SetReportingPreference(bool report) { | |
| 97 Profile* profile = | |
| 98 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | |
| 99 PrefService* pref = profile->GetPrefs(); | |
| 100 pref->SetBoolean(prefs::kSafeBrowsingExtendedReportingEnabled, report); | |
|
mattm
2015/03/04 02:58:41
Should kSafeBrowsingExtendedReportingEnabled be re
felt
2015/03/04 03:05:08
The feature is still referred to as Safe Browsing
| |
| 101 UMA_HISTOGRAM_BOOLEAN("SB2.SetExtendedReportingEnabled", report); | |
|
mattm
2015/03/04 02:58:41
Similar comment as above. Should we make a new his
felt
2015/03/13 18:52:37
Yes. Now that this is shared code, perhaps we can
| |
| 102 } | |
| 103 | |
| 104 bool SecurityInterstitialPage::IsPrefEnabled(const char* pref) { | |
| 105 Profile* profile = | |
| 106 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | |
| 107 return profile->GetPrefs()->GetBoolean(pref); | |
| 108 } | |
| OLD | NEW |