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

Side by Side Diff: chrome/browser/ssl/ssl_blocking_page.cc

Issue 2303413002: Simplify security_interstitials::ControllerClient and other related classes (Closed)
Patch Set: Rebase 2 Created 4 years, 2 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ssl/ssl_blocking_page.h" 5 #include "chrome/browser/ssl/ssl_blocking_page.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 event, 91 event,
92 END_OF_SSL_EXPIRATION_AND_DECISION); 92 END_OF_SSL_EXPIRATION_AND_DECISION);
93 } else { 93 } else {
94 UMA_HISTOGRAM_ENUMERATION( 94 UMA_HISTOGRAM_ENUMERATION(
95 "interstitial.ssl.expiration_and_decision.nonoverridable", 95 "interstitial.ssl.expiration_and_decision.nonoverridable",
96 event, 96 event,
97 END_OF_SSL_EXPIRATION_AND_DECISION); 97 END_OF_SSL_EXPIRATION_AND_DECISION);
98 } 98 }
99 } 99 }
100 100
101 std::unique_ptr<ChromeMetricsHelper> CreateMetricsHelper(
102 content::WebContents* web_contents,
103 int cert_error,
104 const GURL& request_url,
105 bool overridable) {
106 // Set up the metrics helper for the SSLErrorUI.
107 security_interstitials::MetricsHelper::ReportDetails reporting_info;
108 reporting_info.metric_prefix =
109 overridable ? "ssl_overridable" : "ssl_nonoverridable";
110 reporting_info.rappor_prefix = kSSLRapporPrefix;
111 reporting_info.deprecated_rappor_prefix = kDeprecatedSSLRapporPrefix;
112 reporting_info.rappor_report_type = rappor::LOW_FREQUENCY_UMA_RAPPOR_TYPE;
113 reporting_info.deprecated_rappor_report_type = rappor::UMA_RAPPOR_TYPE;
114 return base::MakeUnique<ChromeMetricsHelper>(
115 web_contents, request_url, reporting_info,
116 GetSamplingEventName(overridable, cert_error));
117 }
118
101 } // namespace 119 } // namespace
102 120
103 // static 121 // static
104 InterstitialPageDelegate::TypeID SSLBlockingPage::kTypeForTesting = 122 InterstitialPageDelegate::TypeID SSLBlockingPage::kTypeForTesting =
105 &SSLBlockingPage::kTypeForTesting; 123 &SSLBlockingPage::kTypeForTesting;
106 124
125 // static
126 SSLBlockingPage* SSLBlockingPage::Create(
127 content::WebContents* web_contents,
128 int cert_error,
129 const net::SSLInfo& ssl_info,
130 const GURL& request_url,
131 int options_mask,
132 const base::Time& time_triggered,
133 std::unique_ptr<SSLCertReporter> ssl_cert_reporter,
134 const base::Callback<void(content::CertificateRequestResultType)>&
135 callback) {
136 bool overridable = IsOverridable(
137 options_mask,
138 Profile::FromBrowserContext(web_contents->GetBrowserContext()));
139 std::unique_ptr<ChromeMetricsHelper> metrics_helper(
140 CreateMetricsHelper(web_contents, cert_error, request_url, overridable));
141 metrics_helper.get()->StartRecordingCaptivePortalMetrics(overridable);
142 return new SSLBlockingPage(web_contents, cert_error, ssl_info, request_url,
143 options_mask, time_triggered,
144 std::move(ssl_cert_reporter), overridable,
145 std::move(metrics_helper), callback);
146 }
147
148 bool SSLBlockingPage::ShouldCreateNewNavigation() const {
149 return true;
150 }
151
152 InterstitialPageDelegate::TypeID SSLBlockingPage::GetTypeForTesting() const {
153 return SSLBlockingPage::kTypeForTesting;
154 }
155
156 SSLBlockingPage::~SSLBlockingPage() {
157 if (!callback_.is_null()) {
158 // The page is closed without the user having chosen what to do, default to
159 // deny.
160 RecordSSLExpirationPageEventState(expired_but_previously_allowed_, false,
161 overridable_);
162 NotifyDenyCertificate();
163 }
164 }
165
166 void SSLBlockingPage::PopulateInterstitialStrings(
167 base::DictionaryValue* load_time_data) {
168 ssl_error_ui_->PopulateStringsForHTML(load_time_data);
169 cert_report_helper_->PopulateExtendedReportingOption(load_time_data);
170 }
171
107 // Note that we always create a navigation entry with SSL errors. 172 // Note that we always create a navigation entry with SSL errors.
108 // No error happening loading a sub-resource triggers an interstitial so far. 173 // No error happening loading a sub-resource triggers an interstitial so far.
109 SSLBlockingPage::SSLBlockingPage( 174 SSLBlockingPage::SSLBlockingPage(
110 content::WebContents* web_contents, 175 content::WebContents* web_contents,
111 int cert_error, 176 int cert_error,
112 const net::SSLInfo& ssl_info, 177 const net::SSLInfo& ssl_info,
113 const GURL& request_url, 178 const GURL& request_url,
114 int options_mask, 179 int options_mask,
115 const base::Time& time_triggered, 180 const base::Time& time_triggered,
116 std::unique_ptr<SSLCertReporter> ssl_cert_reporter, 181 std::unique_ptr<SSLCertReporter> ssl_cert_reporter,
182 bool overridable,
183 std::unique_ptr<ChromeMetricsHelper> metrics_helper,
117 const base::Callback<void(content::CertificateRequestResultType)>& callback) 184 const base::Callback<void(content::CertificateRequestResultType)>& callback)
118 : SecurityInterstitialPage(web_contents, request_url), 185 : SecurityInterstitialPage(web_contents,
186 request_url,
187 std::move(metrics_helper)),
119 callback_(callback), 188 callback_(callback),
120 ssl_info_(ssl_info), 189 ssl_info_(ssl_info),
121 overridable_(IsOverridable( 190 overridable_(overridable),
122 options_mask,
123 Profile::FromBrowserContext(web_contents->GetBrowserContext()))),
124 expired_but_previously_allowed_( 191 expired_but_previously_allowed_(
125 (options_mask & SSLErrorUI::EXPIRED_BUT_PREVIOUSLY_ALLOWED) != 0) { 192 (options_mask & SSLErrorUI::EXPIRED_BUT_PREVIOUSLY_ALLOWED) != 0) {
126 // Override prefs for the SSLErrorUI. 193 // Override prefs for the SSLErrorUI.
127 Profile* profile = 194 Profile* profile =
128 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 195 Profile::FromBrowserContext(web_contents->GetBrowserContext());
129 if (profile && 196 if (profile &&
130 !profile->GetPrefs()->GetBoolean(prefs::kSSLErrorOverrideAllowed)) { 197 !profile->GetPrefs()->GetBoolean(prefs::kSSLErrorOverrideAllowed)) {
131 options_mask |= SSLErrorUI::HARD_OVERRIDE_DISABLED; 198 options_mask |= SSLErrorUI::HARD_OVERRIDE_DISABLED;
132 } 199 }
133 if (overridable_) 200 if (overridable_)
134 options_mask |= SSLErrorUI::SOFT_OVERRIDE_ENABLED; 201 options_mask |= SSLErrorUI::SOFT_OVERRIDE_ENABLED;
135 else 202 else
136 options_mask &= ~SSLErrorUI::SOFT_OVERRIDE_ENABLED; 203 options_mask &= ~SSLErrorUI::SOFT_OVERRIDE_ENABLED;
137 204
138 // Set up the metrics helper for the SSLErrorUI.
139 security_interstitials::MetricsHelper::ReportDetails reporting_info;
140 reporting_info.metric_prefix =
141 overridable_ ? "ssl_overridable" : "ssl_nonoverridable";
142 reporting_info.rappor_prefix = kSSLRapporPrefix;
143 reporting_info.deprecated_rappor_prefix = kDeprecatedSSLRapporPrefix;
144 reporting_info.rappor_report_type = rappor::LOW_FREQUENCY_UMA_RAPPOR_TYPE;
145 reporting_info.deprecated_rappor_report_type = rappor::UMA_RAPPOR_TYPE;
146 ChromeMetricsHelper* chrome_metrics_helper =
147 new ChromeMetricsHelper(web_contents, request_url, reporting_info,
148 GetSamplingEventName(overridable_, cert_error));
149 chrome_metrics_helper->StartRecordingCaptivePortalMetrics(overridable_);
150 controller()->set_metrics_helper(base::WrapUnique(chrome_metrics_helper));
151
152 cert_report_helper_.reset(new CertReportHelper( 205 cert_report_helper_.reset(new CertReportHelper(
153 std::move(ssl_cert_reporter), web_contents, request_url, ssl_info, 206 std::move(ssl_cert_reporter), web_contents, request_url, ssl_info,
154 certificate_reporting::ErrorReport::INTERSTITIAL_SSL, overridable_, 207 certificate_reporting::ErrorReport::INTERSTITIAL_SSL, overridable_,
155 controller()->metrics_helper())); 208 controller()->metrics_helper()));
156 209
157 ssl_error_ui_.reset(new SSLErrorUI(request_url, cert_error, ssl_info, 210 ssl_error_ui_.reset(new SSLErrorUI(request_url, cert_error, ssl_info,
158 options_mask, time_triggered, 211 options_mask, time_triggered,
159 controller())); 212 controller()));
160
161 // Creating an interstitial without showing (e.g. from chrome://interstitials) 213 // Creating an interstitial without showing (e.g. from chrome://interstitials)
162 // it leaks memory, so don't create it here. 214 // it leaks memory, so don't create it here.
163 } 215 }
164 216
165 bool SSLBlockingPage::ShouldCreateNewNavigation() const {
166 return true;
167 }
168
169 InterstitialPageDelegate::TypeID SSLBlockingPage::GetTypeForTesting() const {
170 return SSLBlockingPage::kTypeForTesting;
171 }
172
173 SSLBlockingPage::~SSLBlockingPage() {
174 if (!callback_.is_null()) {
175 // The page is closed without the user having chosen what to do, default to
176 // deny.
177 RecordSSLExpirationPageEventState(
178 expired_but_previously_allowed_, false, overridable_);
179 NotifyDenyCertificate();
180 }
181 }
182
183 void SSLBlockingPage::PopulateInterstitialStrings(
184 base::DictionaryValue* load_time_data) {
185 ssl_error_ui_->PopulateStringsForHTML(load_time_data);
186 cert_report_helper_->PopulateExtendedReportingOption(load_time_data);
187 }
188
189 void SSLBlockingPage::OverrideEntry(NavigationEntry* entry) { 217 void SSLBlockingPage::OverrideEntry(NavigationEntry* entry) {
190 entry->GetSSL() = content::SSLStatus( 218 entry->GetSSL() = content::SSLStatus(
191 content::SECURITY_STYLE_AUTHENTICATION_BROKEN, ssl_info_.cert, ssl_info_); 219 content::SECURITY_STYLE_AUTHENTICATION_BROKEN, ssl_info_.cert, ssl_info_);
192 } 220 }
193 221
194 void SSLBlockingPage::SetSSLCertReporterForTesting( 222 void SSLBlockingPage::SetSSLCertReporterForTesting(
195 std::unique_ptr<SSLCertReporter> ssl_cert_reporter) { 223 std::unique_ptr<SSLCertReporter> ssl_cert_reporter) {
196 cert_report_helper_->SetSSLCertReporterForTesting( 224 cert_report_helper_->SetSSLCertReporterForTesting(
197 std::move(ssl_cert_reporter)); 225 std::move(ssl_cert_reporter));
198 } 226 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 284
257 // static 285 // static
258 bool SSLBlockingPage::IsOverridable(int options_mask, 286 bool SSLBlockingPage::IsOverridable(int options_mask,
259 const Profile* const profile) { 287 const Profile* const profile) {
260 const bool is_overridable = 288 const bool is_overridable =
261 (options_mask & SSLErrorUI::SOFT_OVERRIDE_ENABLED) && 289 (options_mask & SSLErrorUI::SOFT_OVERRIDE_ENABLED) &&
262 !(options_mask & SSLErrorUI::STRICT_ENFORCEMENT) && 290 !(options_mask & SSLErrorUI::STRICT_ENFORCEMENT) &&
263 profile->GetPrefs()->GetBoolean(prefs::kSSLErrorOverrideAllowed); 291 profile->GetPrefs()->GetBoolean(prefs::kSSLErrorOverrideAllowed);
264 return is_overridable; 292 return is_overridable;
265 } 293 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698