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

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

Issue 9384014: Remove knowledge about SSLClientAuthHandler from chrome. Instead a callback is given to the embed... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: review comments+sync Created 8 years, 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "content/browser/ssl/ssl_client_auth_handler.h" 5 #include "content/browser/ssl/ssl_client_auth_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "content/browser/renderer_host/resource_dispatcher_host.h" 8 #include "content/browser/renderer_host/resource_dispatcher_host.h"
9 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" 9 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h"
10 #include "content/browser/ssl/ssl_client_auth_notification_details.h"
11 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
12 #include "content/public/browser/content_browser_client.h" 11 #include "content/public/browser/content_browser_client.h"
13 #include "content/public/browser/notification_service.h"
14 #include "net/base/x509_certificate.h" 12 #include "net/base/x509_certificate.h"
15 #include "net/http/http_transaction_factory.h" 13 #include "net/http/http_transaction_factory.h"
16 #include "net/url_request/url_request.h" 14 #include "net/url_request/url_request.h"
17 #include "net/url_request/url_request_context.h" 15 #include "net/url_request/url_request_context.h"
18 16
19 using content::BrowserThread; 17 using content::BrowserThread;
20 18
21 SSLClientAuthHandler::SSLClientAuthHandler( 19 SSLClientAuthHandler::SSLClientAuthHandler(
22 net::URLRequest* request, 20 net::URLRequest* request,
23 net::SSLCertRequestInfo* cert_request_info) 21 net::SSLCertRequestInfo* cert_request_info)
(...skipping 27 matching lines...) Expand all
51 // will be dropped and the scoped_refptr to SSLClientAuthHandler will go 49 // will be dropped and the scoped_refptr to SSLClientAuthHandler will go
52 // away, so we do not leak anything. The destructor takes care of ensuring 50 // away, so we do not leak anything. The destructor takes care of ensuring
53 // the net::URLRequest always gets a response. 51 // the net::URLRequest always gets a response.
54 BrowserThread::PostTask( 52 BrowserThread::PostTask(
55 BrowserThread::UI, FROM_HERE, 53 BrowserThread::UI, FROM_HERE,
56 base::Bind( 54 base::Bind(
57 &SSLClientAuthHandler::DoSelectCertificate, this, 55 &SSLClientAuthHandler::DoSelectCertificate, this,
58 render_process_host_id, render_view_host_id)); 56 render_process_host_id, render_view_host_id));
59 } 57 }
60 58
61 // Sends an SSL_CLIENT_AUTH_CERT_SELECTED notification and notifies the IO
62 // thread that we have selected a cert.
63 void SSLClientAuthHandler::CertificateSelected(net::X509Certificate* cert) { 59 void SSLClientAuthHandler::CertificateSelected(net::X509Certificate* cert) {
64 VLOG(1) << this << " CertificateSelected " << cert;
65 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 60 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
66 61
67 SSLClientAuthNotificationDetails details(cert_request_info_, this, cert); 62 VLOG(1) << this << " CertificateSelected " << cert;
68 content::NotificationService* service =
69 content::NotificationService::current();
70 service->Notify(content::NOTIFICATION_SSL_CLIENT_AUTH_CERT_SELECTED,
71 content::Source<net::HttpNetworkSession>(
72 http_network_session()),
73 content::Details<SSLClientAuthNotificationDetails>(&details));
74
75 CertificateSelectedNoNotify(cert);
76 }
77
78 // Notifies the IO thread that we have selected a cert.
79 void SSLClientAuthHandler::CertificateSelectedNoNotify(
80 net::X509Certificate* cert) {
81 VLOG(1) << this << " CertificateSelectedNoNotify " << cert;
82 BrowserThread::PostTask( 63 BrowserThread::PostTask(
83 BrowserThread::IO, FROM_HERE, 64 BrowserThread::IO, FROM_HERE,
84 base::Bind( 65 base::Bind(
85 &SSLClientAuthHandler::DoCertificateSelected, this, 66 &SSLClientAuthHandler::DoCertificateSelected, this,
86 make_scoped_refptr(cert))); 67 make_scoped_refptr(cert)));
87 } 68 }
88 69
89 void SSLClientAuthHandler::DoCertificateSelected(net::X509Certificate* cert) { 70 void SSLClientAuthHandler::DoCertificateSelected(net::X509Certificate* cert) {
90 VLOG(1) << this << " DoCertificateSelected " << cert; 71 VLOG(1) << this << " DoCertificateSelected " << cert;
91 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
92 // request_ could have been NULLed if the request was cancelled while the 73 // request_ could have been NULLed if the request was cancelled while the
93 // user was choosing a cert, or because we have already responded to the 74 // user was choosing a cert, or because we have already responded to the
94 // certificate. 75 // certificate.
95 if (request_) { 76 if (request_) {
96 request_->ContinueWithCertificate(cert); 77 request_->ContinueWithCertificate(cert);
97 78
98 ResourceDispatcherHostRequestInfo* info = 79 ResourceDispatcherHostRequestInfo* info =
99 ResourceDispatcherHost::InfoForRequest(request_); 80 ResourceDispatcherHost::InfoForRequest(request_);
100 if (info) 81 if (info)
101 info->set_ssl_client_auth_handler(NULL); 82 info->set_ssl_client_auth_handler(NULL);
102 83
103 request_ = NULL; 84 request_ = NULL;
104 } 85 }
105 } 86 }
106 87
107 void SSLClientAuthHandler::DoSelectCertificate( 88 void SSLClientAuthHandler::DoSelectCertificate(
108 int render_process_host_id, int render_view_host_id) { 89 int render_process_host_id, int render_view_host_id) {
109 content::GetContentClient()->browser()->SelectClientCertificate( 90 content::GetContentClient()->browser()->SelectClientCertificate(
110 render_process_host_id, render_view_host_id, this); 91 render_process_host_id, render_view_host_id, http_network_session_,
92 cert_request_info_,
93 base::Bind(&SSLClientAuthHandler::CertificateSelected, this));
111 } 94 }
112
113 SSLClientAuthObserver::SSLClientAuthObserver(
114 net::SSLCertRequestInfo* cert_request_info,
115 SSLClientAuthHandler* handler)
116 : cert_request_info_(cert_request_info), handler_(handler) {
117 }
118
119 SSLClientAuthObserver::~SSLClientAuthObserver() {
120 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
121 }
122
123 void SSLClientAuthObserver::Observe(
124 int type,
125 const content::NotificationSource& source,
126 const content::NotificationDetails& details) {
127 VLOG(1) << "SSLClientAuthObserver::Observe " << this << " " << handler_.get();
128 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
129 DCHECK(type == content::NOTIFICATION_SSL_CLIENT_AUTH_CERT_SELECTED);
130
131 SSLClientAuthNotificationDetails* auth_details =
132 content::Details<SSLClientAuthNotificationDetails>(details).ptr();
133
134 if (auth_details->IsSameHandler(handler_.get())) {
135 VLOG(1) << "got notification from ourself " << handler_.get();
136 return;
137 }
138
139 if (!auth_details->IsSameHost(cert_request_info_))
140 return;
141
142 VLOG(1) << this << " got matching notification for "
143 << handler_.get() << ", selecting cert "
144 << auth_details->selected_cert();
145 StopObserving();
146 handler_->CertificateSelectedNoNotify(auth_details->selected_cert());
147 OnCertSelectedByNotification();
148 }
149
150 void SSLClientAuthObserver::StartObserving() {
151 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
152 notification_registrar_.Add(
153 this, content::NOTIFICATION_SSL_CLIENT_AUTH_CERT_SELECTED,
154 content::Source<net::HttpNetworkSession>(
155 handler_->http_network_session()));
156 }
157
158 void SSLClientAuthObserver::StopObserving() {
159 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
160 notification_registrar_.RemoveAll();
161 }
OLDNEW
« no previous file with comments | « content/browser/ssl/ssl_client_auth_handler.h ('k') | content/browser/ssl/ssl_client_auth_handler_mock.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698