| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_UI_CRYPTO_MODULE_DELEGATE_NSS_H_ | 5 #ifndef CHROME_BROWSER_UI_CRYPTO_MODULE_DELEGATE_NSS_H_ |
| 6 #define CHROME_BROWSER_UI_CRYPTO_MODULE_DELEGATE_NSS_H_ | 6 #define CHROME_BROWSER_UI_CRYPTO_MODULE_DELEGATE_NSS_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/synchronization/waitable_event.h" | 11 #include "base/synchronization/waitable_event.h" |
| 12 #include "chrome/browser/ui/crypto_module_password_dialog.h" | 12 #include "chrome/browser/ui/crypto_module_password_dialog.h" |
| 13 #include "crypto/nss_crypto_module_delegate.h" | 13 #include "crypto/nss_crypto_module_delegate.h" |
| 14 #include "net/base/host_port_pair.h" | 14 #include "net/base/host_port_pair.h" |
| 15 | 15 |
| 16 // Delegate to handle unlocking a slot or indicating which slot to store a key | 16 // Delegate to handle unlocking a slot or indicating which slot to store a key |
| 17 // in. When passing to NSS functions which take a wincx argument, use the value | 17 // in. When passing to NSS functions which take a wincx argument, use the value |
| 18 // returned from the wincx() method. | 18 // returned from the wincx() method. |
| 19 class ChromeNSSCryptoModuleDelegate | 19 class ChromeNSSCryptoModuleDelegate |
| 20 : public crypto::CryptoModuleBlockingPasswordDelegate { | 20 : public crypto::CryptoModuleBlockingPasswordDelegate { |
| 21 public: | 21 public: |
| 22 // Create a ChromeNSSCryptoModuleDelegate. |reason| is used to select what | 22 // Create a ChromeNSSCryptoModuleDelegate. |reason| is used to select what |
| 23 // string to show the user, |server| is displayed to indicate which connection | 23 // string to show the user, |server| is displayed to indicate which connection |
| 24 // is causing the dialog to appear. |slot| can be NULL. | 24 // is causing the dialog to appear. |slot| can be NULL. |
| 25 ChromeNSSCryptoModuleDelegate(chrome::CryptoModulePasswordReason reason, | 25 ChromeNSSCryptoModuleDelegate(chrome::CryptoModulePasswordReason reason, |
| 26 const net::HostPortPair& server); | 26 const net::HostPortPair& server); |
| 27 | 27 |
| 28 ~ChromeNSSCryptoModuleDelegate() override; | |
| 29 | |
| 30 // crypto::CryptoModuleBlockingPasswordDelegate implementation. | 28 // crypto::CryptoModuleBlockingPasswordDelegate implementation. |
| 31 std::string RequestPassword(const std::string& slot_name, | 29 std::string RequestPassword(const std::string& slot_name, |
| 32 bool retry, | 30 bool retry, |
| 33 bool* cancelled) override; | 31 bool* cancelled) override; |
| 34 | 32 |
| 35 private: | 33 private: |
| 34 friend class base::RefCountedThreadSafe<ChromeNSSCryptoModuleDelegate>; |
| 35 |
| 36 ~ChromeNSSCryptoModuleDelegate() override; |
| 37 |
| 36 void ShowDialog(const std::string& slot_name, bool retry); | 38 void ShowDialog(const std::string& slot_name, bool retry); |
| 37 | 39 |
| 38 void GotPassword(const std::string& password); | 40 void GotPassword(const std::string& password); |
| 39 | 41 |
| 40 // Parameters displayed in the dialog. | 42 // Parameters displayed in the dialog. |
| 41 const chrome::CryptoModulePasswordReason reason_; | 43 const chrome::CryptoModulePasswordReason reason_; |
| 42 net::HostPortPair server_; | 44 net::HostPortPair server_; |
| 43 | 45 |
| 44 // Event to block worker thread while waiting for dialog on UI thread. | 46 // Event to block worker thread while waiting for dialog on UI thread. |
| 45 base::WaitableEvent event_; | 47 base::WaitableEvent event_; |
| 46 | 48 |
| 47 // Stores the results from the dialog for access on worker thread. | 49 // Stores the results from the dialog for access on worker thread. |
| 48 std::string password_; | 50 std::string password_; |
| 49 bool cancelled_; | 51 bool cancelled_; |
| 50 | 52 |
| 51 DISALLOW_COPY_AND_ASSIGN(ChromeNSSCryptoModuleDelegate); | 53 DISALLOW_COPY_AND_ASSIGN(ChromeNSSCryptoModuleDelegate); |
| 52 }; | 54 }; |
| 53 | 55 |
| 54 // Create a delegate which only handles unlocking slots. | 56 // Create a delegate which only handles unlocking slots. |
| 55 crypto::CryptoModuleBlockingPasswordDelegate* | 57 crypto::CryptoModuleBlockingPasswordDelegate* |
| 56 CreateCryptoModuleBlockingPasswordDelegate( | 58 CreateCryptoModuleBlockingPasswordDelegate( |
| 57 chrome::CryptoModulePasswordReason reason, | 59 chrome::CryptoModulePasswordReason reason, |
| 58 const net::HostPortPair& server); | 60 const net::HostPortPair& server); |
| 59 | 61 |
| 60 #endif // CHROME_BROWSER_UI_CRYPTO_MODULE_DELEGATE_NSS_H_ | 62 #endif // CHROME_BROWSER_UI_CRYPTO_MODULE_DELEGATE_NSS_H_ |
| OLD | NEW |