| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_client_auth_handler.h" | 5 #include "chrome/browser/ssl/ssl_client_auth_handler.h" |
| 6 | 6 |
| 7 #include "chrome/browser/browser_thread.h" | 7 #include "chrome/browser/browser_thread.h" |
| 8 #include "chrome/browser/renderer_host/render_view_host_delegate.h" | 8 #include "chrome/browser/renderer_host/render_view_host_delegate.h" |
| 9 #include "chrome/browser/renderer_host/render_view_host_notification_task.h" | 9 #include "chrome/browser/renderer_host/render_view_host_notification_task.h" |
| 10 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" | 10 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" |
| 11 #include "net/url_request/url_request.h" | 11 #include "net/url_request/url_request.h" |
| 12 | 12 |
| 13 SSLClientAuthHandler::SSLClientAuthHandler( | 13 SSLClientAuthHandler::SSLClientAuthHandler( |
| 14 URLRequest* request, | 14 net::URLRequest* request, |
| 15 net::SSLCertRequestInfo* cert_request_info) | 15 net::SSLCertRequestInfo* cert_request_info) |
| 16 : request_(request), | 16 : request_(request), |
| 17 cert_request_info_(cert_request_info) { | 17 cert_request_info_(cert_request_info) { |
| 18 } | 18 } |
| 19 | 19 |
| 20 SSLClientAuthHandler::~SSLClientAuthHandler() { | 20 SSLClientAuthHandler::~SSLClientAuthHandler() { |
| 21 // If we were simply dropped, then act as if we selected no certificate. | 21 // If we were simply dropped, then act as if we selected no certificate. |
| 22 DoCertificateSelected(NULL); | 22 DoCertificateSelected(NULL); |
| 23 } | 23 } |
| 24 | 24 |
| 25 void SSLClientAuthHandler::OnRequestCancelled() { | 25 void SSLClientAuthHandler::OnRequestCancelled() { |
| 26 request_ = NULL; | 26 request_ = NULL; |
| 27 } | 27 } |
| 28 | 28 |
| 29 void SSLClientAuthHandler::SelectCertificate() { | 29 void SSLClientAuthHandler::SelectCertificate() { |
| 30 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 30 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 31 | 31 |
| 32 int render_process_host_id; | 32 int render_process_host_id; |
| 33 int render_view_host_id; | 33 int render_view_host_id; |
| 34 if (!ResourceDispatcherHost::RenderViewForRequest(request_, | 34 if (!ResourceDispatcherHost::RenderViewForRequest(request_, |
| 35 &render_process_host_id, | 35 &render_process_host_id, |
| 36 &render_view_host_id)) | 36 &render_view_host_id)) |
| 37 NOTREACHED(); | 37 NOTREACHED(); |
| 38 | 38 |
| 39 // If the RVH does not exist by the time this task gets run, then the task | 39 // If the RVH does not exist by the time this task gets run, then the task |
| 40 // will be dropped and the scoped_refptr to SSLClientAuthHandler will go | 40 // will be dropped and the scoped_refptr to SSLClientAuthHandler will go |
| 41 // away, so we do not leak anything. The destructor takes care of ensuring | 41 // away, so we do not leak anything. The destructor takes care of ensuring |
| 42 // the URLRequest always gets a response. | 42 // the net::URLRequest always gets a response. |
| 43 CallRenderViewHostSSLDelegate( | 43 CallRenderViewHostSSLDelegate( |
| 44 render_process_host_id, render_view_host_id, | 44 render_process_host_id, render_view_host_id, |
| 45 &RenderViewHostDelegate::SSL::ShowClientCertificateRequestDialog, | 45 &RenderViewHostDelegate::SSL::ShowClientCertificateRequestDialog, |
| 46 scoped_refptr<SSLClientAuthHandler>(this)); | 46 scoped_refptr<SSLClientAuthHandler>(this)); |
| 47 } | 47 } |
| 48 | 48 |
| 49 // Notify the IO thread that we have selected a cert. | 49 // Notify the IO thread that we have selected a cert. |
| 50 void SSLClientAuthHandler::CertificateSelected(net::X509Certificate* cert) { | 50 void SSLClientAuthHandler::CertificateSelected(net::X509Certificate* cert) { |
| 51 BrowserThread::PostTask( | 51 BrowserThread::PostTask( |
| 52 BrowserThread::IO, FROM_HERE, | 52 BrowserThread::IO, FROM_HERE, |
| 53 NewRunnableMethod( | 53 NewRunnableMethod( |
| 54 this, &SSLClientAuthHandler::DoCertificateSelected, cert)); | 54 this, &SSLClientAuthHandler::DoCertificateSelected, cert)); |
| 55 } | 55 } |
| 56 | 56 |
| 57 void SSLClientAuthHandler::DoCertificateSelected(net::X509Certificate* cert) { | 57 void SSLClientAuthHandler::DoCertificateSelected(net::X509Certificate* cert) { |
| 58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 59 // request_ could have been NULLed if the request was cancelled while the | 59 // request_ could have been NULLed if the request was cancelled while the |
| 60 // user was choosing a cert, or because we have already responded to the | 60 // user was choosing a cert, or because we have already responded to the |
| 61 // certificate. | 61 // certificate. |
| 62 if (request_) { | 62 if (request_) { |
| 63 request_->ContinueWithCertificate(cert); | 63 request_->ContinueWithCertificate(cert); |
| 64 request_ = NULL; | 64 request_ = NULL; |
| 65 } | 65 } |
| 66 } | 66 } |
| OLD | NEW |