OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_observer.h" | 5 #include "chrome/browser/ssl/ssl_client_auth_observer.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "chrome/browser/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
13 #include "content/public/browser/client_certificate_delegate.h" | |
13 #include "content/public/browser/notification_service.h" | 14 #include "content/public/browser/notification_service.h" |
14 #include "net/cert/x509_certificate.h" | 15 #include "net/cert/x509_certificate.h" |
15 #include "net/ssl/ssl_cert_request_info.h" | 16 #include "net/ssl/ssl_cert_request_info.h" |
16 | 17 |
17 using content::BrowserThread; | 18 using content::BrowserThread; |
18 | 19 |
19 typedef std::pair<net::SSLCertRequestInfo*, net::X509Certificate*> CertDetails; | 20 typedef std::pair<net::SSLCertRequestInfo*, net::X509Certificate*> CertDetails; |
20 | 21 |
21 SSLClientAuthObserver::SSLClientAuthObserver( | 22 SSLClientAuthObserver::SSLClientAuthObserver( |
22 const content::BrowserContext* browser_context, | 23 const content::BrowserContext* browser_context, |
23 const scoped_refptr<net::SSLCertRequestInfo>& cert_request_info, | 24 const scoped_refptr<net::SSLCertRequestInfo>& cert_request_info, |
24 const base::Callback<void(net::X509Certificate*)>& callback) | 25 scoped_ptr<content::ClientCertificateDelegate> delegate) |
25 : browser_context_(browser_context), | 26 : browser_context_(browser_context), |
26 cert_request_info_(cert_request_info), | 27 cert_request_info_(cert_request_info), |
27 callback_(callback) { | 28 delegate_(delegate.Pass()) { |
28 } | 29 } |
29 | 30 |
30 SSLClientAuthObserver::~SSLClientAuthObserver() { | 31 SSLClientAuthObserver::~SSLClientAuthObserver() { |
31 } | 32 } |
32 | 33 |
33 void SSLClientAuthObserver::CertificateSelected( | 34 void SSLClientAuthObserver::CertificateSelected( |
34 net::X509Certificate* certificate) { | 35 net::X509Certificate* certificate) { |
35 if (callback_.is_null()) | 36 if (!delegate_) |
36 return; | 37 return; |
37 | 38 |
38 // Stop listening right away so we don't get our own notification. | 39 // Stop listening right away so we don't get our own notification. |
39 StopObserving(); | 40 StopObserving(); |
40 | 41 |
41 CertDetails details; | 42 CertDetails details; |
42 details.first = cert_request_info_.get(); | 43 details.first = cert_request_info_.get(); |
43 details.second = certificate; | 44 details.second = certificate; |
44 content::NotificationService* service = | 45 content::NotificationService* service = |
45 content::NotificationService::current(); | 46 content::NotificationService::current(); |
46 service->Notify(chrome::NOTIFICATION_SSL_CLIENT_AUTH_CERT_SELECTED, | 47 service->Notify(chrome::NOTIFICATION_SSL_CLIENT_AUTH_CERT_SELECTED, |
47 content::Source<content::BrowserContext>(browser_context_), | 48 content::Source<content::BrowserContext>(browser_context_), |
48 content::Details<CertDetails>(&details)); | 49 content::Details<CertDetails>(&details)); |
49 | 50 |
50 callback_.Run(certificate); | 51 delegate_->ContinueWithCertificate(certificate); |
51 callback_.Reset(); | 52 delegate_.reset(); |
53 } | |
54 | |
55 void SSLClientAuthObserver::CancelCertificateSelection() { | |
56 if (!delegate_) | |
57 return; | |
58 | |
59 // Stop listening right away so we don't get our own notification. | |
mmenke
2015/02/13 19:35:53
I don't think there is a notification here. Shoul
davidben
2015/02/13 22:04:11
There shouldn't be. SSLClientAuthObserver is a (so
| |
60 StopObserving(); | |
61 | |
62 delegate_->CancelCertificateSelection(); | |
63 delegate_.reset(); | |
52 } | 64 } |
53 | 65 |
54 void SSLClientAuthObserver::Observe( | 66 void SSLClientAuthObserver::Observe( |
55 int type, | 67 int type, |
56 const content::NotificationSource& source, | 68 const content::NotificationSource& source, |
57 const content::NotificationDetails& details) { | 69 const content::NotificationDetails& details) { |
58 DVLOG(1) << "SSLClientAuthObserver::Observe " << this; | 70 DVLOG(1) << "SSLClientAuthObserver::Observe " << this; |
59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 71 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
60 DCHECK(type == chrome::NOTIFICATION_SSL_CLIENT_AUTH_CERT_SELECTED); | 72 DCHECK(type == chrome::NOTIFICATION_SSL_CLIENT_AUTH_CERT_SELECTED); |
61 | 73 |
62 CertDetails* cert_details = content::Details<CertDetails>(details).ptr(); | 74 CertDetails* cert_details = content::Details<CertDetails>(details).ptr(); |
63 if (!cert_details->first->host_and_port.Equals( | 75 if (!cert_details->first->host_and_port.Equals( |
64 cert_request_info_->host_and_port)) | 76 cert_request_info_->host_and_port)) |
65 return; | 77 return; |
66 | 78 |
67 DVLOG(1) << this << " got matching notification and selecting cert " | 79 DVLOG(1) << this << " got matching notification and selecting cert " |
68 << cert_details->second; | 80 << cert_details->second; |
69 StopObserving(); | 81 StopObserving(); |
70 callback_.Run(cert_details->second); | 82 delegate_->ContinueWithCertificate(cert_details->second); |
71 callback_.Reset(); | 83 delegate_.reset(); |
72 OnCertSelectedByNotification(); | 84 OnCertSelectedByNotification(); |
73 } | 85 } |
74 | 86 |
75 void SSLClientAuthObserver::StartObserving() { | 87 void SSLClientAuthObserver::StartObserving() { |
76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
77 notification_registrar_.Add( | 89 notification_registrar_.Add( |
78 this, chrome::NOTIFICATION_SSL_CLIENT_AUTH_CERT_SELECTED, | 90 this, chrome::NOTIFICATION_SSL_CLIENT_AUTH_CERT_SELECTED, |
79 content::Source<content::BrowserContext>(browser_context_)); | 91 content::Source<content::BrowserContext>(browser_context_)); |
80 } | 92 } |
81 | 93 |
82 void SSLClientAuthObserver::StopObserving() { | 94 void SSLClientAuthObserver::StopObserving() { |
83 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 95 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
84 notification_registrar_.RemoveAll(); | 96 notification_registrar_.RemoveAll(); |
85 } | 97 } |
OLD | NEW |