This source file includes following definitions.
- client_cert_store_
- OnRequestCancelled
- SelectCertificate
- CertificateSelected
- DidGetClientCerts
- DoCertificateSelected
- DoSelectCertificate
#include "content/browser/ssl/ssl_client_auth_handler.h"
#include "base/bind.h"
#include "content/browser/loader/resource_dispatcher_host_impl.h"
#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 "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(
scoped_ptr<net::ClientCertStore> client_cert_store,
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),
client_cert_store_(client_cert_store.Pass()) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
}
SSLClientAuthHandler::~SSLClientAuthHandler() {
DoCertificateSelected(NULL);
}
void SSLClientAuthHandler::OnRequestCancelled() {
request_ = NULL;
}
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::DidGetClientCerts, this));
} else {
DidGetClientCerts();
}
}
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::DidGetClientCerts() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
if (!request_)
return;
if (client_cert_store_ && cert_request_info_->client_certs.empty()) {
DoCertificateSelected(NULL);
return;
}
int render_process_host_id;
int render_frame_host_id;
if (!ResourceRequestInfo::ForRequest(request_)->GetAssociatedRenderFrame(
&render_process_host_id,
&render_frame_host_id))
NOTREACHED();
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(
&SSLClientAuthHandler::DoSelectCertificate, this,
render_process_host_id, render_frame_host_id));
}
void SSLClientAuthHandler::DoCertificateSelected(net::X509Certificate* cert) {
VLOG(1) << this << " DoCertificateSelected " << cert;
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
if (request_) {
request_->ContinueWithCertificate(cert);
ResourceDispatcherHostImpl::Get()->
ClearSSLClientAuthHandlerForRequest(request_);
request_ = NULL;
}
}
void SSLClientAuthHandler::DoSelectCertificate(
int render_process_host_id, int render_frame_host_id) {
GetContentClient()->browser()->SelectClientCertificate(
render_process_host_id,
render_frame_host_id,
http_network_session_,
cert_request_info_.get(),
base::Bind(&SSLClientAuthHandler::CertificateSelected, this));
}
}