| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 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/ssl/ssl_error_handler.h" | 5 #include "chrome/browser/ssl/ssl_error_handler.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SSLErrorHandler); | 148 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SSLErrorHandler); |
| 149 DEFINE_WEB_CONTENTS_USER_DATA_KEY(CommonNameMismatchRedirectObserver); | 149 DEFINE_WEB_CONTENTS_USER_DATA_KEY(CommonNameMismatchRedirectObserver); |
| 150 | 150 |
| 151 void SSLErrorHandler::HandleSSLError( | 151 void SSLErrorHandler::HandleSSLError( |
| 152 content::WebContents* web_contents, | 152 content::WebContents* web_contents, |
| 153 int cert_error, | 153 int cert_error, |
| 154 const net::SSLInfo& ssl_info, | 154 const net::SSLInfo& ssl_info, |
| 155 const GURL& request_url, | 155 const GURL& request_url, |
| 156 int options_mask, | 156 int options_mask, |
| 157 std::unique_ptr<SSLCertReporter> ssl_cert_reporter, | 157 std::unique_ptr<SSLCertReporter> ssl_cert_reporter, |
| 158 const base::Callback<void(bool)>& callback) { | 158 const base::Callback<void(content::CertificateRequestResultType)>& |
| 159 callback) { |
| 159 DCHECK(!FromWebContents(web_contents)); | 160 DCHECK(!FromWebContents(web_contents)); |
| 160 SSLErrorHandler* error_handler = | 161 SSLErrorHandler* error_handler = |
| 161 new SSLErrorHandler(web_contents, cert_error, ssl_info, request_url, | 162 new SSLErrorHandler(web_contents, cert_error, ssl_info, request_url, |
| 162 options_mask, std::move(ssl_cert_reporter), callback); | 163 options_mask, std::move(ssl_cert_reporter), callback); |
| 163 web_contents->SetUserData(UserDataKey(), error_handler); | 164 web_contents->SetUserData(UserDataKey(), error_handler); |
| 164 error_handler->StartHandlingError(); | 165 error_handler->StartHandlingError(); |
| 165 } | 166 } |
| 166 | 167 |
| 167 // static | 168 // static |
| 168 void SSLErrorHandler::SetInterstitialDelayForTest(base::TimeDelta delay) { | 169 void SSLErrorHandler::SetInterstitialDelayForTest(base::TimeDelta delay) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 181 g_testing_clock = testing_clock; | 182 g_testing_clock = testing_clock; |
| 182 } | 183 } |
| 183 | 184 |
| 184 SSLErrorHandler::SSLErrorHandler( | 185 SSLErrorHandler::SSLErrorHandler( |
| 185 content::WebContents* web_contents, | 186 content::WebContents* web_contents, |
| 186 int cert_error, | 187 int cert_error, |
| 187 const net::SSLInfo& ssl_info, | 188 const net::SSLInfo& ssl_info, |
| 188 const GURL& request_url, | 189 const GURL& request_url, |
| 189 int options_mask, | 190 int options_mask, |
| 190 std::unique_ptr<SSLCertReporter> ssl_cert_reporter, | 191 std::unique_ptr<SSLCertReporter> ssl_cert_reporter, |
| 191 const base::Callback<void(bool)>& callback) | 192 const base::Callback<void(content::CertificateRequestResultType)>& callback) |
| 192 : content::WebContentsObserver(web_contents), | 193 : content::WebContentsObserver(web_contents), |
| 193 web_contents_(web_contents), | 194 web_contents_(web_contents), |
| 194 cert_error_(cert_error), | 195 cert_error_(cert_error), |
| 195 ssl_info_(ssl_info), | 196 ssl_info_(ssl_info), |
| 196 request_url_(request_url), | 197 request_url_(request_url), |
| 197 options_mask_(options_mask), | 198 options_mask_(options_mask), |
| 198 callback_(callback), | 199 callback_(callback), |
| 199 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), | 200 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), |
| 200 ssl_cert_reporter_(std::move(ssl_cert_reporter)) {} | 201 ssl_cert_reporter_(std::move(ssl_cert_reporter)) {} |
| 201 | 202 |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 | 403 |
| 403 void SSLErrorHandler::NavigationStopped() { | 404 void SSLErrorHandler::NavigationStopped() { |
| 404 // Destroy the error handler when the page load is stopped. | 405 // Destroy the error handler when the page load is stopped. |
| 405 DeleteSSLErrorHandler(); | 406 DeleteSSLErrorHandler(); |
| 406 } | 407 } |
| 407 | 408 |
| 408 void SSLErrorHandler::DeleteSSLErrorHandler() { | 409 void SSLErrorHandler::DeleteSSLErrorHandler() { |
| 409 // Need to explicity deny the certificate via the callback, otherwise memory | 410 // Need to explicity deny the certificate via the callback, otherwise memory |
| 410 // is leaked. | 411 // is leaked. |
| 411 if (!callback_.is_null()) { | 412 if (!callback_.is_null()) { |
| 412 base::ResetAndReturn(&callback_).Run(false); | 413 base::ResetAndReturn(&callback_) |
| 414 .Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY); |
| 413 } | 415 } |
| 414 if (common_name_mismatch_handler_) { | 416 if (common_name_mismatch_handler_) { |
| 415 common_name_mismatch_handler_->Cancel(); | 417 common_name_mismatch_handler_->Cancel(); |
| 416 common_name_mismatch_handler_.reset(); | 418 common_name_mismatch_handler_.reset(); |
| 417 } | 419 } |
| 418 // Deletes |this| and also destroys the timer. | 420 // Deletes |this| and also destroys the timer. |
| 419 web_contents_->RemoveUserData(UserDataKey()); | 421 web_contents_->RemoveUserData(UserDataKey()); |
| 420 } | 422 } |
| OLD | NEW |