Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Side by Side Diff: chrome/browser/ssl/ssl_client_auth_handler.cc

Issue 2823038: Refactor SSLClientAuthHandler and certificate selection (Closed)
Patch Set: Rebase the patch Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "app/l10n_util.h"
8 #include "base/string_util.h"
9 #include "chrome/browser/browser_list.h"
10 #include "chrome/browser/browser.h"
11 #include "chrome/browser/browser_window.h"
12 #include "chrome/browser/chrome_thread.h" 7 #include "chrome/browser/chrome_thread.h"
13 #include "grit/generated_resources.h" 8 #include "chrome/browser/renderer_host/render_view_host_delegate.h"
9 #include "chrome/browser/renderer_host/render_view_host_notification_task.h"
10 #include "chrome/browser/renderer_host/resource_dispatcher_host.h"
14 #include "net/url_request/url_request.h" 11 #include "net/url_request/url_request.h"
15 12
16 SSLClientAuthHandler::SSLClientAuthHandler( 13 SSLClientAuthHandler::SSLClientAuthHandler(
17 URLRequest* request, 14 URLRequest* request,
18 net::SSLCertRequestInfo* cert_request_info) 15 net::SSLCertRequestInfo* cert_request_info)
19 : request_(request), 16 : request_(request),
20 cert_request_info_(cert_request_info) { 17 cert_request_info_(cert_request_info) {
21 // Keep us alive until a cert is selected.
22 AddRef();
23 } 18 }
24 19
25 SSLClientAuthHandler::~SSLClientAuthHandler() { 20 SSLClientAuthHandler::~SSLClientAuthHandler() {
21 // If we were simply dropped, then act as if we selected no certificate.
22 DoCertificateSelected(NULL);
26 } 23 }
27 24
28 void SSLClientAuthHandler::OnRequestCancelled() { 25 void SSLClientAuthHandler::OnRequestCancelled() {
29 request_ = NULL; 26 request_ = NULL;
30 } 27 }
31 28
32 void SSLClientAuthHandler::SelectCertificate() { 29 void SSLClientAuthHandler::SelectCertificate() {
33 // Let's move the request to the UI thread. 30 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
34 ChromeThread::PostTask( 31
35 ChromeThread::UI, FROM_HERE, 32 int render_process_host_id;
36 NewRunnableMethod(this, &SSLClientAuthHandler::DoSelectCertificate)); 33 int render_view_host_id;
34 if (!ResourceDispatcherHost::RenderViewForRequest(request_,
35 &render_process_host_id,
36 &render_view_host_id))
37 NOTREACHED();
38
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
41 // away, so we do not leak anything. The destructor takes care of ensuring
42 // the URLRequest always gets a response.
43 CallRenderViewHostSSLDelegate(
44 render_process_host_id, render_view_host_id,
45 &RenderViewHostDelegate::SSL::ShowClientCertificateRequestDialog,
46 scoped_refptr<SSLClientAuthHandler>(this));
37 } 47 }
38 48
39 // Looking for DoSelectCertificate()?
40 // It's implemented in a separate source file for each platform.
41
42 // Notify the IO thread that we have selected a cert. 49 // Notify the IO thread that we have selected a cert.
43 void SSLClientAuthHandler::CertificateSelected(net::X509Certificate* cert) { 50 void SSLClientAuthHandler::CertificateSelected(net::X509Certificate* cert) {
44 ChromeThread::PostTask( 51 ChromeThread::PostTask(
45 ChromeThread::IO, FROM_HERE, 52 ChromeThread::IO, FROM_HERE,
46 NewRunnableMethod( 53 NewRunnableMethod(
47 this, &SSLClientAuthHandler::DoCertificateSelected, cert)); 54 this, &SSLClientAuthHandler::DoCertificateSelected, cert));
48 } 55 }
49 56
50 void SSLClientAuthHandler::DoCertificateSelected(net::X509Certificate* cert) { 57 void SSLClientAuthHandler::DoCertificateSelected(net::X509Certificate* cert) {
51 // request_ could have been NULLed if the request was cancelled while the user 58 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
52 // was choosing a cert. 59 // request_ could have been NULLed if the request was cancelled while the
53 if (request_) 60 // user was choosing a cert, or because we have already responded to the
61 // certificate.
62 if (request_) {
54 request_->ContinueWithCertificate(cert); 63 request_->ContinueWithCertificate(cert);
55 64 request_ = NULL;
56 // We are done. 65 }
57 Release();
58 } 66 }
OLDNEW
« no previous file with comments | « chrome/browser/ssl/ssl_client_auth_handler.h ('k') | chrome/browser/ssl/ssl_client_auth_handler_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698