Home | History | Annotate | Download | only in ui
      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
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROME_BROWSER_UI_CRYPTO_MODULE_PASSWORD_DIALOG_H_
      6 #define CHROME_BROWSER_UI_CRYPTO_MODULE_PASSWORD_DIALOG_H_
      7 #pragma once
      8 
      9 #include <string>
     10 #include <vector>
     11 
     12 #include "base/callback.h"
     13 #include "base/memory/ref_counted.h"
     14 
     15 namespace crypto {
     16 class CryptoModuleBlockingPasswordDelegate;
     17 }
     18 
     19 namespace net {
     20 class CryptoModule;
     21 typedef std::vector<scoped_refptr<CryptoModule> > CryptoModuleList;
     22 class X509Certificate;
     23 }
     24 
     25 namespace browser {
     26 
     27 // An enum to describe the reason for the password request.
     28 enum CryptoModulePasswordReason {
     29   kCryptoModulePasswordKeygen,
     30   kCryptoModulePasswordCertEnrollment,
     31   kCryptoModulePasswordClientAuth,
     32   kCryptoModulePasswordListCerts,
     33   kCryptoModulePasswordCertImport,
     34   kCryptoModulePasswordCertExport,
     35 };
     36 
     37 typedef Callback1<const char*>::Type CryptoModulePasswordCallback;
     38 
     39 // Display a dialog, prompting the user to authenticate to unlock
     40 // |module|. |reason| describes the purpose of the authentication and
     41 // affects the message displayed in the dialog. |server| is the name
     42 // of the server which requested the access.
     43 void ShowCryptoModulePasswordDialog(const std::string& module_name,
     44                             bool retry,
     45                             CryptoModulePasswordReason reason,
     46                             const std::string& server,
     47                             CryptoModulePasswordCallback* callback);
     48 
     49 // Returns a CryptoModuleBlockingPasswordDelegate to open a dialog and block
     50 // until returning. Should only be used on a worker thread.
     51 crypto::CryptoModuleBlockingPasswordDelegate*
     52     NewCryptoModuleBlockingDialogDelegate(
     53         CryptoModulePasswordReason reason,
     54         const std::string& server);
     55 
     56 // Asynchronously unlock |modules|, if necessary.  |callback| is called when
     57 // done (regardless if any modules were successfully unlocked or not).  Should
     58 // only be called on UI thread.
     59 void UnlockSlotsIfNecessary(const net::CryptoModuleList& modules,
     60                             browser::CryptoModulePasswordReason reason,
     61                             const std::string& server,
     62                             Callback0::Type* callback);
     63 
     64 // Asynchronously unlock the |cert|'s module, if necessary.  |callback| is
     65 // called when done (regardless if module was successfully unlocked or not).
     66 // Should only be called on UI thread.
     67 void UnlockCertSlotIfNecessary(net::X509Certificate* cert,
     68                                browser::CryptoModulePasswordReason reason,
     69                                const std::string& server,
     70                                Callback0::Type* callback);
     71 
     72 }  // namespace browser
     73 
     74 #endif  // CHROME_BROWSER_UI_CRYPTO_MODULE_PASSWORD_DIALOG_H_
     75