Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(868)

Side by Side Diff: chrome/browser/interstitials/security_interstitial_page.cc

Issue 935663004: Add checkbox for reporting invalid TLS/SSL cert chains (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: use SecurityInterstitialMetricsHelper for extended reporting events Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/interstitials/security_interstitial_metrics_helper.h"
14 #include "chrome/browser/net/referrer.h"
15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/common/pref_names.h"
11 #include "chrome/grit/browser_resources.h" 17 #include "chrome/grit/browser_resources.h"
18 #include "chrome/grit/generated_resources.h"
19 #include "components/google/core/browser/google_util.h"
12 #include "content/public/browser/interstitial_page.h" 20 #include "content/public/browser/interstitial_page.h"
21 #include "content/public/browser/page_navigator.h"
13 #include "content/public/browser/web_contents.h" 22 #include "content/public/browser/web_contents.h"
23 #include "ui/base/l10n/l10n_util.h"
14 #include "ui/base/resource/resource_bundle.h" 24 #include "ui/base/resource/resource_bundle.h"
15 #include "ui/base/webui/jstemplate_builder.h" 25 #include "ui/base/webui/jstemplate_builder.h"
16 #include "ui/base/webui/web_ui_util.h" 26 #include "ui/base/webui/web_ui_util.h"
17 27
28 namespace interstitials {
29 const char kBoxChecked[] = "boxchecked";
30 const char kDisplayCheckBox[] = "displaycheckbox";
31 const char kOptInLink[] = "optInLink";
32 const char kPrivacyLinkHtml[] =
33 "<a id=\"privacy-link\" href=\"\" onclick=\"sendCommand(%d); "
34 "return false;\" onmousedown=\"return false;\">%s</a>";
35 }
36
37 using content::OpenURLParams;
38 using content::Referrer;
39
18 SecurityInterstitialPage::SecurityInterstitialPage( 40 SecurityInterstitialPage::SecurityInterstitialPage(
19 content::WebContents* web_contents, 41 content::WebContents* web_contents,
20 const GURL& request_url) 42 const GURL& request_url)
21 : web_contents_(web_contents), 43 : web_contents_(web_contents),
22 request_url_(request_url), 44 request_url_(request_url),
23 interstitial_page_(NULL), 45 interstitial_page_(NULL),
24 create_view_(true) { 46 create_view_(true) {
25 // Creating interstitial_page_ without showing it leaks memory, so don't 47 // Creating interstitial_page_ without showing it leaks memory, so don't
26 // create it here. 48 // create it here.
27 } 49 }
(...skipping 10 matching lines...) Expand all
38 } 60 }
39 61
40 GURL SecurityInterstitialPage::request_url() const { 62 GURL SecurityInterstitialPage::request_url() const {
41 return request_url_; 63 return request_url_;
42 } 64 }
43 65
44 void SecurityInterstitialPage::DontCreateViewForTesting() { 66 void SecurityInterstitialPage::DontCreateViewForTesting() {
45 create_view_ = false; 67 create_view_ = false;
46 } 68 }
47 69
70 void SecurityInterstitialPage::SetCertificateReportCallbackForTesting(
71 const base::Closure& callback) {
72 certificate_report_callback_for_testing_ = callback;
73 }
74
48 void SecurityInterstitialPage::Show() { 75 void SecurityInterstitialPage::Show() {
49 DCHECK(!interstitial_page_); 76 DCHECK(!interstitial_page_);
50 interstitial_page_ = content::InterstitialPage::Create( 77 interstitial_page_ = content::InterstitialPage::Create(
51 web_contents_, ShouldCreateNewNavigation(), request_url_, this); 78 web_contents_, ShouldCreateNewNavigation(), request_url_, this);
52 if (!create_view_) 79 if (!create_view_)
53 interstitial_page_->DontCreateViewForTesting(); 80 interstitial_page_->DontCreateViewForTesting();
54 interstitial_page_->Show(); 81 interstitial_page_->Show();
55 } 82 }
56 83
84 void SecurityInterstitialPage::SetReportingPreference(bool report) {
85 Profile* profile =
86 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
87 PrefService* pref = profile->GetPrefs();
88 pref->SetBoolean(prefs::kSafeBrowsingExtendedReportingEnabled, report);
89 UMA_HISTOGRAM_BOOLEAN("SB2.SetExtendedReportingEnabled", report);
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
57 base::string16 SecurityInterstitialPage::GetFormattedHostName() const { 110 base::string16 SecurityInterstitialPage::GetFormattedHostName() const {
58 base::string16 host(base::UTF8ToUTF16(request_url_.host())); 111 base::string16 host(base::UTF8ToUTF16(request_url_.host()));
59 if (base::i18n::IsRTL()) 112 if (base::i18n::IsRTL())
60 base::i18n::WrapStringWithLTRFormatting(&host); 113 base::i18n::WrapStringWithLTRFormatting(&host);
61 return host; 114 return host;
62 } 115 }
63 116
64 std::string SecurityInterstitialPage::GetHTMLContents() { 117 std::string SecurityInterstitialPage::GetHTMLContents() {
65 base::DictionaryValue load_time_data; 118 base::DictionaryValue load_time_data;
66 PopulateInterstitialStrings(&load_time_data); 119 PopulateInterstitialStrings(&load_time_data);
67 const std::string& app_locale = g_browser_process->GetApplicationLocale(); 120 const std::string& app_locale = g_browser_process->GetApplicationLocale();
68 webui::SetLoadTimeDataDefaults(app_locale, &load_time_data); 121 webui::SetLoadTimeDataDefaults(app_locale, &load_time_data);
69 std::string html = ResourceBundle::GetSharedInstance() 122 std::string html = ResourceBundle::GetSharedInstance()
70 .GetRawDataResource(IDR_SECURITY_INTERSTITIAL_HTML) 123 .GetRawDataResource(IDR_SECURITY_INTERSTITIAL_HTML)
71 .as_string(); 124 .as_string();
72 webui::AppendWebUiCssTextDefaults(&html); 125 webui::AppendWebUiCssTextDefaults(&html);
73 return webui::GetI18nTemplateHtml(html, &load_time_data); 126 return webui::GetI18nTemplateHtml(html, &load_time_data);
74 } 127 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698