Index: chrome/browser/ui/crypto_module_delegate_nss.cc |
diff --git a/chrome/browser/ui/crypto_module_password_dialog.cc b/chrome/browser/ui/crypto_module_delegate_nss.cc |
similarity index 50% |
rename from chrome/browser/ui/crypto_module_password_dialog.cc |
rename to chrome/browser/ui/crypto_module_delegate_nss.cc |
index c8b1d0d4776deeb1a08ec04dba5418c1779e6de1..0315362f1d10fa1012946dbcaa22f04c95571e2b 100644 |
--- a/chrome/browser/ui/crypto_module_password_dialog.cc |
+++ b/chrome/browser/ui/crypto_module_delegate_nss.cc |
@@ -2,17 +2,14 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "chrome/browser/ui/crypto_module_password_dialog.h" |
+#include "chrome/browser/ui/crypto_module_delegate_nss.h" |
#include "base/basictypes.h" |
#include "base/bind.h" |
-#include "base/strings/utf_string_conversions.h" |
#include "base/synchronization/waitable_event.h" |
+#include "chrome/browser/net/nss_context.h" |
#include "content/public/browser/browser_thread.h" |
-#include "crypto/crypto_module_blocking_password_delegate.h" |
-#include "grit/generated_resources.h" |
-#include "ui/base/l10n/l10n_util.h" |
-#include "url/gurl.h" |
+#include "crypto/nss_crypto_module_delegate.h" |
using content::BrowserThread; |
@@ -20,23 +17,41 @@ namespace chrome { |
namespace { |
-class CryptoModuleBlockingDialogDelegate |
- : public crypto::CryptoModuleBlockingPasswordDelegate { |
+class ChromeNSSCryptoModuleDelegate |
+ : public crypto::NSSCryptoModuleDelegate { |
public: |
- CryptoModuleBlockingDialogDelegate(CryptoModulePasswordReason reason, |
- const std::string& server) |
+ ChromeNSSCryptoModuleDelegate(content::ResourceContext* context, |
+ CryptoModulePasswordReason reason, |
+ const std::string& server) |
: event_(false, false), |
+ context_(context), |
reason_(reason), |
server_(server), |
- cancelled_(false) { |
+ cancelled_(false) {} |
+ |
+ virtual ~ChromeNSSCryptoModuleDelegate() {} |
+ |
+ // crypto::NSSCryptoModuleDelegate implementation. |
+ virtual void Initialize(const base::Closure& callback) OVERRIDE { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
+ |
+ content::ResourceContext* context = context_; |
+ context_ = NULL; |
+ OnPrivateNSSKeySlotForResourceContextReady( |
+ context, |
+ base::Bind(&ChromeNSSCryptoModuleDelegate::DidGetSlot, |
+ // Caller is responsible for keeping us alive until we run |
+ // the callback. |
+ base::Unretained(this), |
+ callback)); |
} |
- virtual ~CryptoModuleBlockingDialogDelegate() { |
- // Make sure we clear the password in memory. |
- password_.replace(0, password_.size(), password_.size(), 0); |
+ // TODO(mattm): allow choosing which slot to generate and store the key. |
+ virtual crypto::ScopedPK11Slot RequestSlot() OVERRIDE { |
+ return slot_.Pass(); |
} |
- // crypto::CryptoModuleBlockingDialogDelegate implementation. |
+ // crypto::CryptoModuleBlockingPasswordDelegate implementation. |
virtual std::string RequestPassword(const std::string& slot_name, |
bool retry, |
bool* cancelled) OVERRIDE { |
@@ -46,7 +61,7 @@ class CryptoModuleBlockingDialogDelegate |
if (BrowserThread::PostTask( |
BrowserThread::UI, FROM_HERE, |
- base::Bind(&CryptoModuleBlockingDialogDelegate::ShowDialog, |
+ base::Bind(&ChromeNSSCryptoModuleDelegate::ShowDialog, |
// We block on event_ until the task completes, so |
// there's no need to ref-count. |
base::Unretained(this), |
@@ -68,7 +83,7 @@ class CryptoModuleBlockingDialogDelegate |
reason_, |
server_, |
NULL, // TODO(mattm): Supply parent window. |
- base::Bind(&CryptoModuleBlockingDialogDelegate::GotPassword, |
+ base::Bind(&ChromeNSSCryptoModuleDelegate::GotPassword, |
// We block on event_ until the task completes, so |
// there's no need to ref-count. |
base::Unretained(this))); |
@@ -82,21 +97,30 @@ class CryptoModuleBlockingDialogDelegate |
event_.Signal(); |
} |
+ void DidGetSlot(const base::Closure& callback, crypto::ScopedPK11Slot slot) { |
+ slot_ = slot.Pass(); |
+ callback.Run(); |
+ } |
+ |
base::WaitableEvent event_; |
+ content::ResourceContext* context_; |
CryptoModulePasswordReason reason_; |
std::string server_; |
std::string password_; |
+ crypto::ScopedPK11Slot slot_; |
bool cancelled_; |
- DISALLOW_COPY_AND_ASSIGN(CryptoModuleBlockingDialogDelegate); |
+ DISALLOW_COPY_AND_ASSIGN(ChromeNSSCryptoModuleDelegate); |
}; |
} // namespace |
-crypto::CryptoModuleBlockingPasswordDelegate* |
- NewCryptoModuleBlockingDialogDelegate(CryptoModulePasswordReason reason, |
- const std::string& server) { |
- return new CryptoModuleBlockingDialogDelegate(reason, server); |
+crypto::NSSCryptoModuleDelegate* CreateNSSCryptoModuleDelegate( |
+ content::ResourceContext* context, |
+ CryptoModulePasswordReason reason, |
+ const std::string& server) { |
+ return new ChromeNSSCryptoModuleDelegate(context, reason, server); |
} |
+ |
} // namespace chrome |