OLD | NEW |
---|---|
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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
87 event, | 87 event, |
88 END_OF_SSL_EXPIRATION_AND_DECISION); | 88 END_OF_SSL_EXPIRATION_AND_DECISION); |
89 } else { | 89 } else { |
90 UMA_HISTOGRAM_ENUMERATION( | 90 UMA_HISTOGRAM_ENUMERATION( |
91 "interstitial.ssl.expiration_and_decision.nonoverridable", | 91 "interstitial.ssl.expiration_and_decision.nonoverridable", |
92 event, | 92 event, |
93 END_OF_SSL_EXPIRATION_AND_DECISION); | 93 END_OF_SSL_EXPIRATION_AND_DECISION); |
94 } | 94 } |
95 } | 95 } |
96 | 96 |
97 std::unique_ptr<ChromeMetricsHelper> CreateMetricsHelper( | |
98 content::WebContents* web_contents, | |
99 int cert_error, | |
100 const GURL& request_url, | |
101 bool overridable) { | |
102 // Set up the metrics helper for the SSLErrorUI. | |
103 security_interstitials::MetricsHelper::ReportDetails reporting_info; | |
104 reporting_info.metric_prefix = | |
105 overridable ? "ssl_overridable" : "ssl_nonoverridable"; | |
106 return base::MakeUnique<ChromeMetricsHelper>( | |
107 web_contents, request_url, reporting_info, | |
108 GetSamplingEventName(overridable, cert_error)); | |
109 } | |
110 | |
111 } // namespace | 97 } // namespace |
112 | 98 |
113 // static | 99 // static |
114 InterstitialPageDelegate::TypeID SSLBlockingPage::kTypeForTesting = | 100 InterstitialPageDelegate::TypeID SSLBlockingPage::kTypeForTesting = |
115 &SSLBlockingPage::kTypeForTesting; | 101 &SSLBlockingPage::kTypeForTesting; |
116 | 102 |
117 // static | 103 // static |
118 SSLBlockingPage* SSLBlockingPage::Create( | 104 SSLBlockingPage* SSLBlockingPage::Create( |
119 content::WebContents* web_contents, | 105 content::WebContents* web_contents, |
120 int cert_error, | 106 int cert_error, |
(...skipping 16 matching lines...) Expand all Loading... | |
137 Profile::FromBrowserContext(web_contents->GetBrowserContext())); | 123 Profile::FromBrowserContext(web_contents->GetBrowserContext())); |
138 if (overridable) | 124 if (overridable) |
139 options_mask |= SSLErrorUI::SOFT_OVERRIDE_ENABLED; | 125 options_mask |= SSLErrorUI::SOFT_OVERRIDE_ENABLED; |
140 else | 126 else |
141 options_mask &= ~SSLErrorUI::SOFT_OVERRIDE_ENABLED; | 127 options_mask &= ~SSLErrorUI::SOFT_OVERRIDE_ENABLED; |
142 | 128 |
143 std::unique_ptr<ChromeMetricsHelper> metrics_helper( | 129 std::unique_ptr<ChromeMetricsHelper> metrics_helper( |
144 CreateMetricsHelper(web_contents, cert_error, request_url, overridable)); | 130 CreateMetricsHelper(web_contents, cert_error, request_url, overridable)); |
145 metrics_helper.get()->StartRecordingCaptivePortalMetrics(overridable); | 131 metrics_helper.get()->StartRecordingCaptivePortalMetrics(overridable); |
146 | 132 |
147 return new SSLBlockingPage(web_contents, cert_error, ssl_info, request_url, | 133 SSLBlockingPage* page = |
148 options_mask, time_triggered, | 134 new SSLBlockingPage(web_contents, ssl_info, request_url, options_mask, |
149 std::move(ssl_cert_reporter), overridable, | 135 time_triggered, std::move(ssl_cert_reporter), |
150 std::move(metrics_helper), callback); | 136 overridable, std::move(metrics_helper), callback); |
137 page->SetErrorUI(base::MakeUnique<SSLErrorUI>( | |
138 request_url, cert_error, ssl_info, options_mask, time_triggered, | |
139 page->controller())); | |
140 return page; | |
151 } | 141 } |
152 | 142 |
153 bool SSLBlockingPage::ShouldCreateNewNavigation() const { | 143 bool SSLBlockingPage::ShouldCreateNewNavigation() const { |
154 return true; | 144 return true; |
155 } | 145 } |
156 | 146 |
157 InterstitialPageDelegate::TypeID SSLBlockingPage::GetTypeForTesting() const { | 147 InterstitialPageDelegate::TypeID SSLBlockingPage::GetTypeForTesting() const { |
158 return SSLBlockingPage::kTypeForTesting; | 148 return SSLBlockingPage::kTypeForTesting; |
159 } | 149 } |
160 | 150 |
161 SSLBlockingPage::~SSLBlockingPage() { | 151 SSLBlockingPage::~SSLBlockingPage() { |
162 if (!callback_.is_null()) { | 152 if (!callback_.is_null()) { |
163 // The page is closed without the user having chosen what to do, default to | 153 // The page is closed without the user having chosen what to do, default to |
164 // deny. | 154 // deny. |
165 RecordSSLExpirationPageEventState(expired_but_previously_allowed_, false, | 155 RecordSSLExpirationPageEventState(expired_but_previously_allowed_, false, |
166 overridable_); | 156 overridable_); |
167 NotifyDenyCertificate(); | 157 NotifyDenyCertificate(); |
168 } | 158 } |
169 } | 159 } |
170 | 160 |
171 void SSLBlockingPage::PopulateInterstitialStrings( | 161 void SSLBlockingPage::PopulateInterstitialStrings( |
172 base::DictionaryValue* load_time_data) { | 162 base::DictionaryValue* load_time_data) { |
173 ssl_error_ui_->PopulateStringsForHTML(load_time_data); | 163 ssl_error_ui_->PopulateStringsForHTML(load_time_data); |
174 cert_report_helper_->PopulateExtendedReportingOption(load_time_data); | 164 cert_report_helper_->PopulateExtendedReportingOption(load_time_data); |
175 } | 165 } |
176 | 166 |
167 void SSLBlockingPage::SetErrorUI(std::unique_ptr<SSLErrorUI> error_ui) { | |
168 ssl_error_ui_ = std::move(error_ui); | |
169 } | |
170 | |
171 // static | |
172 std::unique_ptr<ChromeMetricsHelper> SSLBlockingPage::CreateMetricsHelper( | |
173 content::WebContents* web_contents, | |
174 int cert_error, | |
175 const GURL& request_url, | |
176 bool overridable) { | |
177 // Set up the metrics helper for the SSLErrorUI. | |
meacer
2017/06/22 19:06:18
nit: Comment seems a bit redundant.
estark
2017/06/22 22:01:05
Done.
| |
178 security_interstitials::MetricsHelper::ReportDetails reporting_info; | |
179 reporting_info.metric_prefix = | |
180 overridable ? "ssl_overridable" : "ssl_nonoverridable"; | |
181 return base::MakeUnique<ChromeMetricsHelper>( | |
182 web_contents, request_url, reporting_info, | |
183 GetSamplingEventName(overridable, cert_error)); | |
184 } | |
185 | |
177 // Note that we always create a navigation entry with SSL errors. | 186 // Note that we always create a navigation entry with SSL errors. |
178 // No error happening loading a sub-resource triggers an interstitial so far. | 187 // No error happening loading a sub-resource triggers an interstitial so far. |
179 SSLBlockingPage::SSLBlockingPage( | 188 SSLBlockingPage::SSLBlockingPage( |
180 content::WebContents* web_contents, | 189 content::WebContents* web_contents, |
181 int cert_error, | |
182 const net::SSLInfo& ssl_info, | 190 const net::SSLInfo& ssl_info, |
183 const GURL& request_url, | 191 const GURL& request_url, |
184 int options_mask, | 192 int options_mask, |
185 const base::Time& time_triggered, | 193 const base::Time& time_triggered, |
186 std::unique_ptr<SSLCertReporter> ssl_cert_reporter, | 194 std::unique_ptr<SSLCertReporter> ssl_cert_reporter, |
187 bool overridable, | 195 bool overridable, |
188 std::unique_ptr<ChromeMetricsHelper> metrics_helper, | 196 std::unique_ptr<ChromeMetricsHelper> metrics_helper, |
189 const base::Callback<void(content::CertificateRequestResultType)>& callback) | 197 const base::Callback<void(content::CertificateRequestResultType)>& callback) |
190 : SecurityInterstitialPage( | 198 : SecurityInterstitialPage( |
191 web_contents, | 199 web_contents, |
192 request_url, | 200 request_url, |
193 base::MakeUnique<ChromeControllerClient>( | 201 base::MakeUnique<ChromeControllerClient>(web_contents, |
194 web_contents, std::move(metrics_helper))), | 202 std::move(metrics_helper))), |
195 callback_(callback), | 203 callback_(callback), |
196 ssl_info_(ssl_info), | 204 ssl_info_(ssl_info), |
197 overridable_(overridable), | 205 overridable_(overridable), |
198 expired_but_previously_allowed_( | 206 expired_but_previously_allowed_( |
199 (options_mask & SSLErrorUI::EXPIRED_BUT_PREVIOUSLY_ALLOWED) != 0), | 207 (options_mask & SSLErrorUI::EXPIRED_BUT_PREVIOUSLY_ALLOWED) != 0), |
200 cert_report_helper_(new CertReportHelper( | 208 cert_report_helper_(new CertReportHelper( |
201 std::move(ssl_cert_reporter), | 209 std::move(ssl_cert_reporter), |
202 web_contents, | 210 web_contents, |
203 request_url, | 211 request_url, |
204 ssl_info, | 212 ssl_info, |
205 certificate_reporting::ErrorReport::INTERSTITIAL_SSL, | 213 certificate_reporting::ErrorReport::INTERSTITIAL_SSL, |
206 overridable_, | 214 overridable_, |
207 time_triggered, | 215 time_triggered, |
208 controller()->metrics_helper())), | 216 controller()->metrics_helper())) { |
209 ssl_error_ui_(new SSLErrorUI(request_url, | |
210 cert_error, | |
211 ssl_info, | |
212 options_mask, | |
213 time_triggered, | |
214 controller())) { | |
215 // Creating an interstitial without showing (e.g. from chrome://interstitials) | 217 // Creating an interstitial without showing (e.g. from chrome://interstitials) |
216 // it leaks memory, so don't create it here. | 218 // it leaks memory, so don't create it here. |
217 } | 219 } |
218 | 220 |
219 void SSLBlockingPage::OverrideEntry(NavigationEntry* entry) { | 221 void SSLBlockingPage::OverrideEntry(NavigationEntry* entry) { |
220 entry->GetSSL() = content::SSLStatus(ssl_info_); | 222 entry->GetSSL() = content::SSLStatus(ssl_info_); |
221 } | 223 } |
222 | 224 |
223 void SSLBlockingPage::SetSSLCertReporterForTesting( | 225 void SSLBlockingPage::SetSSLCertReporterForTesting( |
224 std::unique_ptr<SSLCertReporter> ssl_cert_reporter) { | 226 std::unique_ptr<SSLCertReporter> ssl_cert_reporter) { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
306 | 308 |
307 // static | 309 // static |
308 bool SSLBlockingPage::IsOverridable(int options_mask, | 310 bool SSLBlockingPage::IsOverridable(int options_mask, |
309 const Profile* const profile) { | 311 const Profile* const profile) { |
310 const bool is_overridable = | 312 const bool is_overridable = |
311 (options_mask & SSLErrorUI::SOFT_OVERRIDE_ENABLED) && | 313 (options_mask & SSLErrorUI::SOFT_OVERRIDE_ENABLED) && |
312 !(options_mask & SSLErrorUI::STRICT_ENFORCEMENT) && | 314 !(options_mask & SSLErrorUI::STRICT_ENFORCEMENT) && |
313 profile->GetPrefs()->GetBoolean(prefs::kSSLErrorOverrideAllowed); | 315 profile->GetPrefs()->GetBoolean(prefs::kSSLErrorOverrideAllowed); |
314 return is_overridable; | 316 return is_overridable; |
315 } | 317 } |
OLD | NEW |