Chromium Code Reviews| Index: content/browser/ssl/ssl_client_auth_handler.cc |
| diff --git a/content/browser/ssl/ssl_client_auth_handler.cc b/content/browser/ssl/ssl_client_auth_handler.cc |
| index 3340334f18376ef1bff346b2c21b9eebc105051d..b76542d899dd912441106b3a182a3281933c997d 100644 |
| --- a/content/browser/ssl/ssl_client_auth_handler.cc |
| +++ b/content/browser/ssl/ssl_client_auth_handler.cc |
| @@ -9,20 +9,24 @@ |
| #include "content/browser/loader/resource_request_info_impl.h" |
| #include "content/public/browser/browser_thread.h" |
| #include "content/public/browser/content_browser_client.h" |
| +#include "content/public/browser/resource_context.h" |
| #include "net/cert/x509_certificate.h" |
| #include "net/http/http_transaction_factory.h" |
| +#include "net/ssl/client_cert_store.h" |
| #include "net/url_request/url_request.h" |
| #include "net/url_request/url_request_context.h" |
| namespace content { |
| SSLClientAuthHandler::SSLClientAuthHandler( |
| + ResourceContext* context, |
| net::URLRequest* request, |
| net::SSLCertRequestInfo* cert_request_info) |
| : request_(request), |
| http_network_session_( |
| request_->context()->http_transaction_factory()->GetSession()), |
| - cert_request_info_(cert_request_info) { |
| + cert_request_info_(cert_request_info), |
| + client_cert_store_(context->GetClientCertStore()) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| } |
| @@ -39,6 +43,38 @@ void SSLClientAuthHandler::SelectCertificate() { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| DCHECK(request_); |
| + if (client_cert_store_) |
| + client_cert_store_->GetClientCerts( |
| + *cert_request_info_, |
| + &cert_request_info_->client_certs, |
| + base::Bind(&SSLClientAuthHandler::GotClientCerts, this)); |
| + else |
| + GotClientCerts(); |
|
wtc
2013/10/28 19:41:12
Nit: I recommend curly braces because the body of
mattm
2013/10/28 23:56:16
Done.
|
| +} |
| + |
| +void SSLClientAuthHandler::CertificateSelected(net::X509Certificate* cert) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + |
| + VLOG(1) << this << " CertificateSelected " << cert; |
| + BrowserThread::PostTask( |
| + BrowserThread::IO, FROM_HERE, |
| + base::Bind( |
| + &SSLClientAuthHandler::DoCertificateSelected, this, |
| + make_scoped_refptr(cert))); |
| +} |
| + |
| +void SSLClientAuthHandler::GotClientCerts() { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| + // Request may have cancelled while we were getting client certs. |
| + if (!request_) |
| + return; |
| + |
| + if (client_cert_store_ && cert_request_info_->client_certs.empty()) { |
|
wtc
2013/10/28 19:41:12
IMPORTANT: if client_cert_store_ is NULL, does not
mattm
2013/10/28 23:56:16
This fallthrough is for android, where there isn't
|
| + // No need to query the user if there are no certs to choose from. |
| + DoCertificateSelected(NULL); |
| + return; |
| + } |
| + |
| int render_process_host_id; |
| int render_view_host_id; |
| if (!ResourceRequestInfo::ForRequest(request_)->GetAssociatedRenderView( |
| @@ -57,17 +93,6 @@ void SSLClientAuthHandler::SelectCertificate() { |
| render_process_host_id, render_view_host_id)); |
| } |
| -void SSLClientAuthHandler::CertificateSelected(net::X509Certificate* cert) { |
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| - |
| - VLOG(1) << this << " CertificateSelected " << cert; |
| - BrowserThread::PostTask( |
| - BrowserThread::IO, FROM_HERE, |
| - base::Bind( |
| - &SSLClientAuthHandler::DoCertificateSelected, this, |
| - make_scoped_refptr(cert))); |
| -} |
| - |
| void SSLClientAuthHandler::DoCertificateSelected(net::X509Certificate* cert) { |
| VLOG(1) << this << " DoCertificateSelected " << cert; |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |