ssl_add_cert_handler.h revision c407dc5cd9bdc5668497f21b26b09d988ab439de
1// Copyright (c) 2010 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 CHROME_BROWSER_SSL_SSL_ADD_CERT_HANDLER_H_
6#define CHROME_BROWSER_SSL_SSL_ADD_CERT_HANDLER_H_
7
8#include "base/basictypes.h"
9#include "base/ref_counted.h"
10#include "base/string16.h"
11
12namespace net {
13class X509Certificate;
14}
15class URLRequest;
16
17// This class handles adding a newly-generated client cert. It ensures there's a
18// private key for the cert, displays the cert to the user, and adds it upon
19// user approval.
20// It is self-owned and deletes itself when finished.
21class SSLAddCertHandler : public base::RefCountedThreadSafe<SSLAddCertHandler> {
22 public:
23  SSLAddCertHandler(URLRequest* request, net::X509Certificate* cert);
24
25  net::X509Certificate* cert()  { return cert_; }
26
27  // The platform-specific code calls this when it's done, to clean up.
28  // If |addCert| is true, the cert will be added to the CertDatabase.
29  void Finished(bool add_cert);
30
31 private:
32  friend class base::RefCountedThreadSafe<SSLAddCertHandler>;
33
34  // Runs the user interface. Called on the UI thread. Calls AskToAddCert.
35  void RunUI();
36
37  // Platform-specific code that asks the user whether to add the cert.
38  // Called on the UI thread.
39  void AskToAddCert();
40
41  // Utility to display an error message in a dialog box.
42  void ShowError(const string16& error);
43
44  // The cert to add.
45  scoped_refptr<net::X509Certificate> cert_;
46
47  DISALLOW_COPY_AND_ASSIGN(SSLAddCertHandler);
48};
49
50#endif  // CHROME_BROWSER_SSL_SSL_ADD_CERT_HANDLER_H_
51