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