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