OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 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_DELEGATE_NSS_H_ |
| 6 #define CHROME_BROWSER_UI_CRYPTO_MODULE_DELEGATE_NSS_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/compiler_specific.h" |
| 11 #include "base/synchronization/waitable_event.h" |
| 12 #include "chrome/browser/ui/crypto_module_password_dialog.h" |
| 13 #include "crypto/nss_crypto_module_delegate.h" |
| 14 |
| 15 namespace content { |
| 16 class ResourceContext; |
| 17 } |
| 18 |
| 19 // Delegate to handle unlocking a slot or indicating which slot to store a key |
| 20 // in. When passing to NSS functions which take a wincx argument, use the value |
| 21 // returned from the wincx() method. |
| 22 class ChromeNSSCryptoModuleDelegate |
| 23 : public crypto::NSSCryptoModuleDelegate { |
| 24 public: |
| 25 // Create a ChromeNSSCryptoModuleDelegate. |reason| is used to select what |
| 26 // string to show the user, |server| is displayed to indicate which connection |
| 27 // is causing the dialog to appear. |
| 28 ChromeNSSCryptoModuleDelegate(chrome::CryptoModulePasswordReason reason, |
| 29 const std::string& server); |
| 30 |
| 31 virtual ~ChromeNSSCryptoModuleDelegate(); |
| 32 |
| 33 // Must be called on IO thread. Returns true if the delegate is ready for use. |
| 34 // Otherwise, if |initialization_complete_callback| is non-null, the |
| 35 // initialization will proceed asynchronously and the callback will be run |
| 36 // once the delegate is ready to use. In that case, the caller must ensure the |
| 37 // delegate remains alive until the callback is run. |
| 38 bool InitializeSlot(content::ResourceContext* context, |
| 39 const base::Closure& initialization_complete_callback) |
| 40 WARN_UNUSED_RESULT; |
| 41 |
| 42 // crypto::NSSCryptoModuleDelegate implementation. |
| 43 virtual crypto::ScopedPK11Slot RequestSlot() OVERRIDE; |
| 44 |
| 45 // crypto::CryptoModuleBlockingPasswordDelegate implementation. |
| 46 virtual std::string RequestPassword(const std::string& slot_name, |
| 47 bool retry, |
| 48 bool* cancelled) OVERRIDE; |
| 49 |
| 50 private: |
| 51 void ShowDialog(const std::string& slot_name, bool retry); |
| 52 |
| 53 void GotPassword(const std::string& password); |
| 54 |
| 55 void DidGetSlot(const base::Closure& callback, crypto::ScopedPK11Slot slot); |
| 56 |
| 57 // Parameters displayed in the dialog. |
| 58 const chrome::CryptoModulePasswordReason reason_; |
| 59 const std::string server_; |
| 60 |
| 61 // Event to block worker thread while waiting for dialog on UI thread. |
| 62 base::WaitableEvent event_; |
| 63 |
| 64 // Stores the results from the dialog for access on worker thread. |
| 65 std::string password_; |
| 66 bool cancelled_; |
| 67 |
| 68 // The slot which will be returned by RequestSlot. |
| 69 crypto::ScopedPK11Slot slot_; |
| 70 |
| 71 DISALLOW_COPY_AND_ASSIGN(ChromeNSSCryptoModuleDelegate); |
| 72 }; |
| 73 |
| 74 // Create a delegate which only handles unlocking slots. |
| 75 crypto::CryptoModuleBlockingPasswordDelegate* |
| 76 CreateCryptoModuleBlockingPasswordDelegate( |
| 77 chrome::CryptoModulePasswordReason reason, |
| 78 const std::string& server); |
| 79 |
| 80 #endif // CHROME_BROWSER_UI_CRYPTO_MODULE_DELEGATE_NSS_H_ |
OLD | NEW |