Chromium Code Reviews| 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" |
| 11 #include "base/callback_helpers.h" | 11 #include "base/callback_helpers.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
| 14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/interstitials/chrome_controller_client.h" | 17 #include "chrome/browser/interstitials/chrome_controller_client.h" |
| 18 #include "chrome/browser/interstitials/chrome_metrics_helper.h" | 18 #include "chrome/browser/interstitials/chrome_metrics_helper.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/renderer_preferences_util.h" | 20 #include "chrome/browser/renderer_preferences_util.h" |
| 21 #include "chrome/browser/ssl/cert_report_helper.h" | 21 #include "chrome/browser/ssl/cert_report_helper.h" |
| 22 #include "chrome/browser/ssl/ssl_cert_reporter.h" | 22 #include "chrome/browser/ssl/ssl_cert_reporter.h" |
| 23 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
| 24 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
| 25 #include "components/prefs/pref_service.h" | 25 #include "components/prefs/pref_service.h" |
| 26 #include "components/safe_browsing/common/safe_browsing_prefs.h" | 26 #include "components/safe_browsing/common/safe_browsing_prefs.h" |
| 27 #include "components/security_interstitials/core/controller_client.h" | 27 #include "components/security_interstitials/core/controller_client.h" |
| 28 #include "components/security_interstitials/core/metrics_helper.h" | 28 #include "components/security_interstitials/core/metrics_helper.h" |
| 29 #include "components/security_interstitials/core/ssl_error_ui.h" | 29 #include "components/security_interstitials/core/ssl_error_ui.h" |
| 30 #include "components/security_interstitials/core/superfish_error_ui.h" | |
| 30 #include "content/public/browser/interstitial_page.h" | 31 #include "content/public/browser/interstitial_page.h" |
| 31 #include "content/public/browser/interstitial_page_delegate.h" | 32 #include "content/public/browser/interstitial_page_delegate.h" |
| 32 #include "content/public/browser/navigation_entry.h" | 33 #include "content/public/browser/navigation_entry.h" |
| 33 #include "content/public/browser/render_process_host.h" | 34 #include "content/public/browser/render_process_host.h" |
| 34 #include "content/public/browser/ssl_status.h" | 35 #include "content/public/browser/ssl_status.h" |
| 35 #include "content/public/browser/web_contents.h" | 36 #include "content/public/browser/web_contents.h" |
| 36 #include "content/public/common/renderer_preferences.h" | 37 #include "content/public/common/renderer_preferences.h" |
| 37 #include "net/base/net_errors.h" | 38 #include "net/base/net_errors.h" |
| 38 | 39 |
| 39 using base::TimeTicks; | 40 using base::TimeTicks; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 event, | 93 event, |
| 93 END_OF_SSL_EXPIRATION_AND_DECISION); | 94 END_OF_SSL_EXPIRATION_AND_DECISION); |
| 94 } | 95 } |
| 95 } | 96 } |
| 96 | 97 |
| 97 std::unique_ptr<ChromeMetricsHelper> CreateMetricsHelper( | 98 std::unique_ptr<ChromeMetricsHelper> CreateMetricsHelper( |
| 98 content::WebContents* web_contents, | 99 content::WebContents* web_contents, |
| 99 int cert_error, | 100 int cert_error, |
| 100 const GURL& request_url, | 101 const GURL& request_url, |
| 101 bool overridable) { | 102 bool overridable) { |
| 102 // Set up the metrics helper for the SSLErrorUI. | |
| 103 security_interstitials::MetricsHelper::ReportDetails reporting_info; | 103 security_interstitials::MetricsHelper::ReportDetails reporting_info; |
| 104 reporting_info.metric_prefix = | 104 reporting_info.metric_prefix = |
| 105 overridable ? "ssl_overridable" : "ssl_nonoverridable"; | 105 overridable ? "ssl_overridable" : "ssl_nonoverridable"; |
| 106 return base::MakeUnique<ChromeMetricsHelper>( | 106 return base::MakeUnique<ChromeMetricsHelper>( |
| 107 web_contents, request_url, reporting_info, | 107 web_contents, request_url, reporting_info, |
| 108 GetSamplingEventName(overridable, cert_error)); | 108 GetSamplingEventName(overridable, cert_error)); |
| 109 } | 109 } |
| 110 | 110 |
| 111 } // namespace | 111 } // namespace |
| 112 | 112 |
| 113 // static | 113 // static |
| 114 InterstitialPageDelegate::TypeID SSLBlockingPage::kTypeForTesting = | 114 InterstitialPageDelegate::TypeID SSLBlockingPage::kTypeForTesting = |
| 115 &SSLBlockingPage::kTypeForTesting; | 115 &SSLBlockingPage::kTypeForTesting; |
| 116 | 116 |
| 117 // static | 117 // static |
| 118 SSLBlockingPage* SSLBlockingPage::Create( | 118 SSLBlockingPage* SSLBlockingPage::Create( |
| 119 content::WebContents* web_contents, | 119 content::WebContents* web_contents, |
| 120 int cert_error, | 120 int cert_error, |
| 121 const net::SSLInfo& ssl_info, | 121 const net::SSLInfo& ssl_info, |
| 122 const GURL& request_url, | 122 const GURL& request_url, |
| 123 int options_mask, | 123 int options_mask, |
| 124 const base::Time& time_triggered, | 124 const base::Time& time_triggered, |
| 125 std::unique_ptr<SSLCertReporter> ssl_cert_reporter, | 125 std::unique_ptr<SSLCertReporter> ssl_cert_reporter, |
| 126 bool is_superfish, | |
| 126 const base::Callback<void(content::CertificateRequestResultType)>& | 127 const base::Callback<void(content::CertificateRequestResultType)>& |
| 127 callback) { | 128 callback) { |
| 128 // Override prefs for the SSLErrorUI. | 129 // Override prefs for the SSLErrorUI. |
| 129 Profile* profile = | 130 Profile* profile = |
| 130 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 131 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 131 if (profile && | 132 if (profile && |
| 132 !profile->GetPrefs()->GetBoolean(prefs::kSSLErrorOverrideAllowed)) { | 133 !profile->GetPrefs()->GetBoolean(prefs::kSSLErrorOverrideAllowed)) { |
| 133 options_mask |= SSLErrorUI::HARD_OVERRIDE_DISABLED; | 134 options_mask |= SSLErrorUI::HARD_OVERRIDE_DISABLED; |
| 134 } | 135 } |
| 135 bool overridable = IsOverridable( | 136 bool overridable = |
|
meacer
2017/06/22 22:35:37
nit: const bool
estark
2017/06/22 23:17:48
Done.
| |
| 136 options_mask, | 137 is_superfish |
| 137 Profile::FromBrowserContext(web_contents->GetBrowserContext())); | 138 ? false |
| 139 : IsOverridable(options_mask, Profile::FromBrowserContext( | |
| 140 web_contents->GetBrowserContext())); | |
| 138 if (overridable) | 141 if (overridable) |
| 139 options_mask |= SSLErrorUI::SOFT_OVERRIDE_ENABLED; | 142 options_mask |= SSLErrorUI::SOFT_OVERRIDE_ENABLED; |
| 140 else | 143 else |
| 141 options_mask &= ~SSLErrorUI::SOFT_OVERRIDE_ENABLED; | 144 options_mask &= ~SSLErrorUI::SOFT_OVERRIDE_ENABLED; |
| 142 | 145 |
| 143 std::unique_ptr<ChromeMetricsHelper> metrics_helper( | 146 std::unique_ptr<ChromeMetricsHelper> metrics_helper( |
| 144 CreateMetricsHelper(web_contents, cert_error, request_url, overridable)); | 147 CreateMetricsHelper(web_contents, cert_error, request_url, overridable)); |
| 145 metrics_helper.get()->StartRecordingCaptivePortalMetrics(overridable); | 148 metrics_helper.get()->StartRecordingCaptivePortalMetrics(overridable); |
| 146 | 149 |
| 147 return new SSLBlockingPage(web_contents, cert_error, ssl_info, request_url, | 150 return new SSLBlockingPage(web_contents, cert_error, ssl_info, request_url, |
| 148 options_mask, time_triggered, | 151 options_mask, time_triggered, |
| 149 std::move(ssl_cert_reporter), overridable, | 152 std::move(ssl_cert_reporter), overridable, |
| 150 std::move(metrics_helper), callback); | 153 std::move(metrics_helper), is_superfish, callback); |
| 151 } | 154 } |
| 152 | 155 |
| 153 bool SSLBlockingPage::ShouldCreateNewNavigation() const { | 156 bool SSLBlockingPage::ShouldCreateNewNavigation() const { |
| 154 return true; | 157 return true; |
| 155 } | 158 } |
| 156 | 159 |
| 157 InterstitialPageDelegate::TypeID SSLBlockingPage::GetTypeForTesting() const { | 160 InterstitialPageDelegate::TypeID SSLBlockingPage::GetTypeForTesting() const { |
| 158 return SSLBlockingPage::kTypeForTesting; | 161 return SSLBlockingPage::kTypeForTesting; |
| 159 } | 162 } |
| 160 | 163 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 179 SSLBlockingPage::SSLBlockingPage( | 182 SSLBlockingPage::SSLBlockingPage( |
| 180 content::WebContents* web_contents, | 183 content::WebContents* web_contents, |
| 181 int cert_error, | 184 int cert_error, |
| 182 const net::SSLInfo& ssl_info, | 185 const net::SSLInfo& ssl_info, |
| 183 const GURL& request_url, | 186 const GURL& request_url, |
| 184 int options_mask, | 187 int options_mask, |
| 185 const base::Time& time_triggered, | 188 const base::Time& time_triggered, |
| 186 std::unique_ptr<SSLCertReporter> ssl_cert_reporter, | 189 std::unique_ptr<SSLCertReporter> ssl_cert_reporter, |
| 187 bool overridable, | 190 bool overridable, |
| 188 std::unique_ptr<ChromeMetricsHelper> metrics_helper, | 191 std::unique_ptr<ChromeMetricsHelper> metrics_helper, |
| 192 bool is_superfish, | |
| 189 const base::Callback<void(content::CertificateRequestResultType)>& callback) | 193 const base::Callback<void(content::CertificateRequestResultType)>& callback) |
| 190 : SecurityInterstitialPage( | 194 : SecurityInterstitialPage( |
| 191 web_contents, | 195 web_contents, |
| 192 request_url, | 196 request_url, |
| 193 base::MakeUnique<ChromeControllerClient>( | 197 base::MakeUnique<ChromeControllerClient>(web_contents, |
| 194 web_contents, std::move(metrics_helper))), | 198 std::move(metrics_helper))), |
| 195 callback_(callback), | 199 callback_(callback), |
| 196 ssl_info_(ssl_info), | 200 ssl_info_(ssl_info), |
| 197 overridable_(overridable), | 201 overridable_(overridable), |
| 198 expired_but_previously_allowed_( | 202 expired_but_previously_allowed_( |
| 199 (options_mask & SSLErrorUI::EXPIRED_BUT_PREVIOUSLY_ALLOWED) != 0), | 203 (options_mask & SSLErrorUI::EXPIRED_BUT_PREVIOUSLY_ALLOWED) != 0), |
| 200 cert_report_helper_(new CertReportHelper( | 204 cert_report_helper_(new CertReportHelper( |
| 201 std::move(ssl_cert_reporter), | 205 std::move(ssl_cert_reporter), |
| 202 web_contents, | 206 web_contents, |
| 203 request_url, | 207 request_url, |
| 204 ssl_info, | 208 ssl_info, |
| 205 certificate_reporting::ErrorReport::INTERSTITIAL_SSL, | 209 certificate_reporting::ErrorReport::INTERSTITIAL_SSL, |
| 206 overridable_, | 210 overridable_, |
| 207 time_triggered, | 211 time_triggered, |
| 208 controller()->metrics_helper())), | 212 controller()->metrics_helper())), |
| 209 ssl_error_ui_(new SSLErrorUI(request_url, | 213 ssl_error_ui_( |
| 210 cert_error, | 214 is_superfish |
| 211 ssl_info, | 215 ? base::MakeUnique<security_interstitials::SuperfishErrorUI>( |
| 212 options_mask, | 216 request_url, |
| 213 time_triggered, | 217 cert_error, |
| 214 controller())) { | 218 ssl_info, |
| 219 options_mask, | |
| 220 time_triggered, | |
| 221 controller()) | |
| 222 : base::MakeUnique<SSLErrorUI>(request_url, | |
| 223 cert_error, | |
| 224 ssl_info, | |
| 225 options_mask, | |
| 226 time_triggered, | |
| 227 controller())) { | |
| 215 // Creating an interstitial without showing (e.g. from chrome://interstitials) | 228 // Creating an interstitial without showing (e.g. from chrome://interstitials) |
| 216 // it leaks memory, so don't create it here. | 229 // it leaks memory, so don't create it here. |
| 217 } | 230 } |
| 218 | 231 |
| 219 void SSLBlockingPage::OverrideEntry(NavigationEntry* entry) { | 232 void SSLBlockingPage::OverrideEntry(NavigationEntry* entry) { |
| 220 entry->GetSSL() = content::SSLStatus(ssl_info_); | 233 entry->GetSSL() = content::SSLStatus(ssl_info_); |
| 221 } | 234 } |
| 222 | 235 |
| 223 void SSLBlockingPage::SetSSLCertReporterForTesting( | 236 void SSLBlockingPage::SetSSLCertReporterForTesting( |
| 224 std::unique_ptr<SSLCertReporter> ssl_cert_reporter) { | 237 std::unique_ptr<SSLCertReporter> ssl_cert_reporter) { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 306 | 319 |
| 307 // static | 320 // static |
| 308 bool SSLBlockingPage::IsOverridable(int options_mask, | 321 bool SSLBlockingPage::IsOverridable(int options_mask, |
| 309 const Profile* const profile) { | 322 const Profile* const profile) { |
| 310 const bool is_overridable = | 323 const bool is_overridable = |
| 311 (options_mask & SSLErrorUI::SOFT_OVERRIDE_ENABLED) && | 324 (options_mask & SSLErrorUI::SOFT_OVERRIDE_ENABLED) && |
| 312 !(options_mask & SSLErrorUI::STRICT_ENFORCEMENT) && | 325 !(options_mask & SSLErrorUI::STRICT_ENFORCEMENT) && |
| 313 profile->GetPrefs()->GetBoolean(prefs::kSSLErrorOverrideAllowed); | 326 profile->GetPrefs()->GetBoolean(prefs::kSSLErrorOverrideAllowed); |
| 314 return is_overridable; | 327 return is_overridable; |
| 315 } | 328 } |
| OLD | NEW |