| 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 #ifndef CHROME_BROWSER_SSL_SSL_CLIENT_AUTH_OBSERVER_H_ | 5 #ifndef CHROME_BROWSER_SSL_SSL_CLIENT_AUTH_OBSERVER_H_ |
| 6 #define CHROME_BROWSER_SSL_SSL_CLIENT_AUTH_OBSERVER_H_ | 6 #define CHROME_BROWSER_SSL_SSL_CLIENT_AUTH_OBSERVER_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" |
| 10 #include "content/public/browser/notification_observer.h" | 11 #include "content/public/browser/notification_observer.h" |
| 11 #include "content/public/browser/notification_registrar.h" | 12 #include "content/public/browser/notification_registrar.h" |
| 12 | 13 |
| 13 namespace net { | 14 namespace net { |
| 14 class SSLCertRequestInfo; | 15 class SSLCertRequestInfo; |
| 15 class X509Certificate; | 16 class X509Certificate; |
| 16 } | 17 } |
| 17 | 18 |
| 18 namespace content { | 19 namespace content { |
| 19 class BrowserContext; | 20 class BrowserContext; |
| 21 class ClientCertificateDelegate; |
| 20 } | 22 } |
| 21 | 23 |
| 24 // SSLClientAuthObserver is a base class that wraps a |
| 25 // ClientCertificateDelegate. It links client certificate selection dialogs |
| 26 // attached to the same BrowserContext. When CertificateSelected is called via |
| 27 // one of them, the rest simulate the same action. |
| 22 class SSLClientAuthObserver : public content::NotificationObserver { | 28 class SSLClientAuthObserver : public content::NotificationObserver { |
| 23 public: | 29 public: |
| 24 SSLClientAuthObserver( | 30 SSLClientAuthObserver( |
| 25 const content::BrowserContext* browser_context, | 31 const content::BrowserContext* browser_context, |
| 26 const scoped_refptr<net::SSLCertRequestInfo>& cert_request_info, | 32 const scoped_refptr<net::SSLCertRequestInfo>& cert_request_info, |
| 27 const base::Callback<void(net::X509Certificate*)>& callback); | 33 scoped_ptr<content::ClientCertificateDelegate> delegate); |
| 28 ~SSLClientAuthObserver() override; | 34 ~SSLClientAuthObserver() override; |
| 29 | 35 |
| 30 // UI should implement this to close the dialog. | 36 // UI should implement this to close the dialog. |
| 31 virtual void OnCertSelectedByNotification() = 0; | 37 virtual void OnCertSelectedByNotification() = 0; |
| 32 | 38 |
| 33 // Send content the certificate. Can also call with NULL if the user | 39 // Continues the request with a certificate. Can also call with NULL to |
| 34 // cancelled. Derived classes must use this instead of caching the callback | 40 // continue with no certificate. Derived classes must use this instead of |
| 35 // and calling it directly. | 41 // caching the delegate and calling it directly. |
| 36 void CertificateSelected(net::X509Certificate* cert); | 42 void CertificateSelected(net::X509Certificate* cert); |
| 37 | 43 |
| 44 // Cancels the certificate selection and aborts the request. |
| 45 void CancelCertificateSelection(); |
| 46 |
| 38 // Begins observing notifications from other SSLClientAuthHandler instances. | 47 // Begins observing notifications from other SSLClientAuthHandler instances. |
| 39 // If another instance chooses a cert for a matching SSLCertRequestInfo, we | 48 // If another instance chooses a cert for a matching SSLCertRequestInfo, we |
| 40 // will also use the same cert and OnCertSelectedByNotification will be called | 49 // will also use the same cert and OnCertSelectedByNotification will be called |
| 41 // so that the cert selection UI can be closed. | 50 // so that the cert selection UI can be closed. |
| 42 void StartObserving(); | 51 void StartObserving(); |
| 43 | 52 |
| 44 // Stops observing notifications. We will no longer act on client auth | 53 // Stops observing notifications. We will no longer act on client auth |
| 45 // notifications. | 54 // notifications. |
| 46 void StopObserving(); | 55 void StopObserving(); |
| 47 | 56 |
| 48 net::SSLCertRequestInfo* cert_request_info() const { | 57 net::SSLCertRequestInfo* cert_request_info() const { |
| 49 return cert_request_info_.get(); | 58 return cert_request_info_.get(); |
| 50 } | 59 } |
| 51 | 60 |
| 52 private: | 61 private: |
| 53 // content::NotificationObserver implementation: | 62 // content::NotificationObserver implementation: |
| 54 void Observe(int type, | 63 void Observe(int type, |
| 55 const content::NotificationSource& source, | 64 const content::NotificationSource& source, |
| 56 const content::NotificationDetails& details) override; | 65 const content::NotificationDetails& details) override; |
| 57 | 66 |
| 58 const content::BrowserContext* browser_context_; | 67 const content::BrowserContext* browser_context_; |
| 59 scoped_refptr<net::SSLCertRequestInfo> cert_request_info_; | 68 scoped_refptr<net::SSLCertRequestInfo> cert_request_info_; |
| 60 base::Callback<void(net::X509Certificate*)> callback_; | 69 scoped_ptr<content::ClientCertificateDelegate> delegate_; |
| 61 content::NotificationRegistrar notification_registrar_; | 70 content::NotificationRegistrar notification_registrar_; |
| 62 | 71 |
| 63 DISALLOW_COPY_AND_ASSIGN(SSLClientAuthObserver); | 72 DISALLOW_COPY_AND_ASSIGN(SSLClientAuthObserver); |
| 64 }; | 73 }; |
| 65 | 74 |
| 66 #endif // CHROME_BROWSER_SSL_SSL_CLIENT_AUTH_OBSERVER_H_ | 75 #endif // CHROME_BROWSER_SSL_SSL_CLIENT_AUTH_OBSERVER_H_ |
| OLD | NEW |