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

Side by Side 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 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/ui/gtk/crypto_module_password_dialog.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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 #include "chrome/browser/ui/crypto_module_password_dialog.h"
6
7 #include "base/basictypes.h"
8 #include "base/bind.h"
9 #include "base/synchronization/waitable_event.h"
10 #include "base/utf_string_conversions.h"
11 #include "chrome/browser/ui/views/window.h"
12 #include "crypto/crypto_module_blocking_password_delegate.h"
13 #include "content/public/browser/browser_thread.h"
14 #include "googleurl/src/gurl.h"
15 #include "grit/generated_resources.h"
16 #include "ui/base/l10n/l10n_util.h"
17
18 #if defined(TOOLKIT_VIEWS)
19 #include "chrome/browser/ui/views/crypto_module_password_dialog_view.h"
20 #include "ui/views/widget/widget.h"
21 #endif
22
23 using content::BrowserThread;
24
25 namespace {
26
27 class CryptoModuleBlockingDialogDelegate
28 : public crypto::CryptoModuleBlockingPasswordDelegate {
29 public:
30 CryptoModuleBlockingDialogDelegate(browser::CryptoModulePasswordReason reason,
31 const std::string& server)
32 : event_(false, false),
33 reason_(reason),
34 server_(server),
35 cancelled_(false) {
36 }
37
38 ~CryptoModuleBlockingDialogDelegate() {
sky 2011/11/29 00:51:28 virtual
alicet1 2011/11/29 19:04:27 Done.
39 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.
40 }
41
42 // crypto::CryptoModuleBlockingDialogDelegate implementation.
43 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.
44 bool* cancelled) {
45 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI));
46 DCHECK(!event_.IsSignaled());
47 event_.Reset();
48
49 if (BrowserThread::PostTask(
50 BrowserThread::UI, FROM_HERE,
51 base::Bind(&CryptoModuleBlockingDialogDelegate::ShowDialog,
52 // We block on event_ until the task completes, so
53 // there's no need to ref-count.
54 base::Unretained(this),
55 slot_name,
56 retry))) {
57 event_.Wait();
58 }
59 *cancelled = cancelled_;
60 return password_;
61 }
62
63 private:
64 void ShowDialog(const std::string& slot_name, bool retry) {
65 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
66 ShowCryptoModulePasswordDialog(
67 slot_name, retry, reason_, server_,
68 base::Bind(&CryptoModuleBlockingDialogDelegate::GotPassword,
69 // We block on event_ until the task completes, so
70 // there's no need to ref-count.
71 base::Unretained(this)));
72 }
73 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.
74 if (password)
75 password_ = password;
76 else
77 cancelled_ = true;
78 event_.Signal();
79 }
80 base::WaitableEvent event_;
sky 2011/11/29 00:51:28 nit: newline between 79 and 80
alicet1 2011/11/29 19:04:27 Done.
81 browser::CryptoModulePasswordReason reason_;
82 std::string server_;
83 std::string password_;
84 bool cancelled_;
85
86 DISALLOW_COPY_AND_ASSIGN(CryptoModuleBlockingDialogDelegate);
87 };
88 } // namespace
89
90 namespace browser {
91
92 void ShowCryptoModulePasswordDialog(
93 const std::string& slot_name,
94 bool retry,
95 CryptoModulePasswordReason reason,
96 const std::string& server,
97 const CryptoModulePasswordCallback& callback) {
98 #if defined(TOOLKIT_VIEWS)
99 CryptoModulePasswordDialogView* dialog =
100 new CryptoModulePasswordDialogView(
101 slot_name, reason, server, callback);
102 views::Widget* widget = CreateViewsWindow(NULL, dialog);
103 widget->Show();
104 #endif
105 }
106
107 crypto::CryptoModuleBlockingPasswordDelegate*
108 NewCryptoModuleBlockingDialogDelegate(
109 CryptoModulePasswordReason reason,
110 const std::string& server) {
111 return new CryptoModuleBlockingDialogDelegate(reason, server);
112 }
113 } // namespace browser
OLDNEW
« 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