Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / content / browser / ssl / ssl_client_auth_handler.h
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
3 // found in the LICENSE file.
4
5 #ifndef CONTENT_BROWSER_SSL_SSL_CLIENT_AUTH_HANDLER_H_
6 #define CONTENT_BROWSER_SSL_SSL_CLIENT_AUTH_HANDLER_H_
7
8 #include "base/basictypes.h"
9 #include "base/callback.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/weak_ptr.h"
12 #include "content/public/browser/browser_thread.h"
13 #include "net/ssl/ssl_cert_request_info.h"
14
15 namespace net {
16 class ClientCertStore;
17 class URLRequest;
18 class X509Certificate;
19 }  // namespace net
20
21 namespace content {
22
23 // This class handles the approval and selection of a certificate for SSL client
24 // authentication by the user. Should only be used on the IO thread. If the
25 // SSLClientAuthHandler is destroyed before the certificate is selected, the
26 // selection is canceled and the callback never called.
27 class SSLClientAuthHandler {
28  public:
29   typedef base::Callback<void(net::X509Certificate*)> CertificateCallback;
30
31   SSLClientAuthHandler(scoped_ptr<net::ClientCertStore> client_cert_store,
32                        net::URLRequest* request,
33                        net::SSLCertRequestInfo* cert_request_info,
34                        const CertificateCallback& callback);
35   ~SSLClientAuthHandler();
36
37   // Selects a certificate and resumes the URL request with that certificate.
38   void SelectCertificate();
39
40  private:
41   // Called when ClientCertStore is done retrieving the cert list.
42   void DidGetClientCerts();
43
44   // Called when the user has selected a cert.
45   void CertificateSelected(net::X509Certificate* cert);
46
47   // The net::URLRequest that triggered this client auth.
48   net::URLRequest* request_;
49
50   // The certs to choose from.
51   scoped_refptr<net::SSLCertRequestInfo> cert_request_info_;
52
53   scoped_ptr<net::ClientCertStore> client_cert_store_;
54
55   // The callback to call when the certificate is selected.
56   CertificateCallback callback_;
57
58   base::WeakPtrFactory<SSLClientAuthHandler> weak_factory_;
59
60   DISALLOW_COPY_AND_ASSIGN(SSLClientAuthHandler);
61 };
62
63 }  // namespace content
64
65 #endif  // CONTENT_BROWSER_SSL_SSL_CLIENT_AUTH_HANDLER_H_