Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4889)

Unified Diff: chrome/browser/ui/crypto_module_password_dialog.cc

Issue 8115020: add crypto module password dialog view and test. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: update Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/ui/gtk/crypto_module_password_dialog.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/crypto_module_password_dialog.cc
diff --git a/chrome/browser/ui/crypto_module_password_dialog.cc b/chrome/browser/ui/crypto_module_password_dialog.cc
new file mode 100644
index 0000000000000000000000000000000000000000..504c7ab98598d7a5c1afc88f28f19342fc9493f7
--- /dev/null
+++ b/chrome/browser/ui/crypto_module_password_dialog.cc
@@ -0,0 +1,113 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// 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 "base/basictypes.h"
+#include "base/bind.h"
+#include "base/synchronization/waitable_event.h"
+#include "base/utf_string_conversions.h"
+#include "chrome/browser/ui/views/window.h"
+#include "crypto/crypto_module_blocking_password_delegate.h"
+#include "content/public/browser/browser_thread.h"
+#include "googleurl/src/gurl.h"
+#include "grit/generated_resources.h"
+#include "ui/base/l10n/l10n_util.h"
+
+#if defined(TOOLKIT_VIEWS)
+#include "chrome/browser/ui/views/crypto_module_password_dialog_view.h"
+#include "ui/views/widget/widget.h"
+#endif
+
+using content::BrowserThread;
+
+namespace {
+
+class CryptoModuleBlockingDialogDelegate
+ : public crypto::CryptoModuleBlockingPasswordDelegate {
+ public:
+ CryptoModuleBlockingDialogDelegate(browser::CryptoModulePasswordReason reason,
+ const std::string& server)
+ : event_(false, false),
+ reason_(reason),
+ server_(server),
+ cancelled_(false) {
+ }
+
+ ~CryptoModuleBlockingDialogDelegate() {
sky 2011/11/29 00:51:28 virtual
alicet1 2011/11/29 19:04:27 Done.
+ password_.replace(0, password_.size(), password_.size(), 0);
sky 2011/11/29 00:51:28 This is a bit obscure. How about a comment as to w
alicet1 2011/11/29 19:04:27 Done.
+ }
+
+ // crypto::CryptoModuleBlockingDialogDelegate implementation.
+ virtual std::string RequestPassword(const std::string& slot_name, bool retry,
sky 2011/11/29 00:51:28 OVERRIDE and each param on its own line.
alicet1 2011/11/29 19:04:27 Done.
+ bool* cancelled) {
+ DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(!event_.IsSignaled());
+ event_.Reset();
+
+ if (BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&CryptoModuleBlockingDialogDelegate::ShowDialog,
+ // We block on event_ until the task completes, so
+ // there's no need to ref-count.
+ base::Unretained(this),
+ slot_name,
+ retry))) {
+ event_.Wait();
+ }
+ *cancelled = cancelled_;
+ return password_;
+ }
+
+ private:
+ void ShowDialog(const std::string& slot_name, bool retry) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ ShowCryptoModulePasswordDialog(
+ slot_name, retry, reason_, server_,
+ base::Bind(&CryptoModuleBlockingDialogDelegate::GotPassword,
+ // We block on event_ until the task completes, so
+ // there's no need to ref-count.
+ base::Unretained(this)));
+ }
+ void GotPassword(const char* password) {
sky 2011/11/29 00:51:28 nit: newline between 72 and 73.
alicet1 2011/11/29 19:04:27 Done.
+ if (password)
+ password_ = password;
+ else
+ cancelled_ = true;
+ event_.Signal();
+ }
+ base::WaitableEvent event_;
sky 2011/11/29 00:51:28 nit: newline between 79 and 80
alicet1 2011/11/29 19:04:27 Done.
+ browser::CryptoModulePasswordReason reason_;
+ std::string server_;
+ std::string password_;
+ bool cancelled_;
+
+ DISALLOW_COPY_AND_ASSIGN(CryptoModuleBlockingDialogDelegate);
+};
+} // namespace
+
+namespace browser {
+
+void ShowCryptoModulePasswordDialog(
+ const std::string& slot_name,
+ bool retry,
+ CryptoModulePasswordReason reason,
+ const std::string& server,
+ const CryptoModulePasswordCallback& callback) {
+#if defined(TOOLKIT_VIEWS)
+ CryptoModulePasswordDialogView* dialog =
+ new CryptoModulePasswordDialogView(
+ slot_name, reason, server, callback);
+ views::Widget* widget = CreateViewsWindow(NULL, dialog);
+ widget->Show();
+#endif
+}
+
+crypto::CryptoModuleBlockingPasswordDelegate*
+ NewCryptoModuleBlockingDialogDelegate(
+ CryptoModulePasswordReason reason,
+ const std::string& server) {
+ return new CryptoModuleBlockingDialogDelegate(reason, server);
+}
+} // namespace browser
« no previous file with comments | « no previous file | chrome/browser/ui/gtk/crypto_module_password_dialog.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698