OLD | NEW |
---|---|
(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 "crypto/crypto_module_blocking_password_delegate.h" | |
12 #include "content/browser/browser_thread.h" | |
13 #include "googleurl/src/gurl.h" | |
14 #include "grit/generated_resources.h" | |
15 #include "ui/base/l10n/l10n_util.h" | |
16 | |
17 #if defined(OS_WIN) || defined(TOOLKIT_VIEWS) | |
Greg Spencer (Chromium)
2011/10/05 23:41:16
It seems to me that you don't need the "defined(OS
alicet1
2011/10/06 22:04:08
Done.
| |
18 #include "chrome/browser/ui/crypto_module_password_dialog_view.h" | |
19 #include "views/widget/widget.h" | |
20 #endif | |
21 | |
22 namespace { | |
23 | |
24 class CryptoModuleBlockingDialogDelegate | |
25 : public crypto::CryptoModuleBlockingPasswordDelegate { | |
26 public: | |
27 CryptoModuleBlockingDialogDelegate(browser::CryptoModulePasswordReason reason, | |
28 const std::string& server) | |
29 : event_(false, false), | |
30 reason_(reason), | |
31 server_(server), | |
32 password_(), | |
Greg Spencer (Chromium)
2011/10/05 23:41:16
No need for this: it'll get initialized regardless
alicet1
2011/10/06 22:04:08
Done.
| |
33 cancelled_(false) { | |
34 } | |
35 | |
36 ~CryptoModuleBlockingDialogDelegate() { | |
37 password_.replace(0, password_.size(), password_.size(), 0); | |
38 } | |
39 | |
40 // crypto::CryptoModuleBlockingDialogDelegate implementation. | |
41 virtual std::string RequestPassword(const std::string& slot_name, bool retry, | |
42 bool* cancelled) { | |
43 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
44 DCHECK(!event_.IsSignaled()); | |
45 event_.Reset(); | |
46 | |
47 if (BrowserThread::PostTask( | |
48 BrowserThread::UI, FROM_HERE, | |
49 base::Bind(&CryptoModuleBlockingDialogDelegate::ShowDialog, | |
50 // We block on event_ until the task completes, so | |
51 // there's no need to ref-count. | |
52 base::Unretained(this), | |
53 slot_name, | |
54 retry))) { | |
55 event_.Wait(); | |
56 } | |
57 *cancelled = cancelled_; | |
58 return password_; | |
59 } | |
60 | |
61 private: | |
62 void ShowDialog(const std::string& slot_name, bool retry) { | |
63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
64 ShowCryptoModulePasswordDialog( | |
65 slot_name, retry, reason_, server_, | |
66 base::Bind(&CryptoModuleBlockingDialogDelegate::GotPassword, | |
67 base::Unretained(this))); | |
Greg Spencer (Chromium)
2011/10/05 23:41:16
Maybe a similar comment here about why it doesn't
alicet1
2011/10/06 22:04:08
Done.
| |
68 } | |
69 void GotPassword(const char* password) { | |
70 if (password) | |
71 password_ = password; | |
72 else | |
73 cancelled_ = true; | |
74 event_.Signal(); | |
75 } | |
76 base::WaitableEvent event_; | |
77 browser::CryptoModulePasswordReason reason_; | |
78 std::string server_; | |
79 std::string password_; | |
80 bool cancelled_; | |
81 | |
82 DISALLOW_COPY_AND_ASSIGN(CryptoModuleBlockingDialogDelegate); | |
83 }; | |
84 } // namespace | |
85 | |
86 namespace browser { | |
87 | |
88 void ShowCryptoModulePasswordDialog( | |
89 const std::string& slot_name, | |
90 bool retry, | |
91 CryptoModulePasswordReason reason, | |
92 const std::string& server, | |
93 const CryptoModulePasswordCallback& callback) { | |
94 #if defined(OS_WIN) || defined(TOOLKIT_VIEWS) | |
Greg Spencer (Chromium)
2011/10/05 23:41:16
Again, I don't think you need OS_WIN here.
alicet1
2011/10/06 22:04:08
Done.
| |
95 (new CryptoModulePasswordDialogView( | |
96 slot_name, reason, server, callback))->GetWidget()->Show(); | |
97 #endif | |
98 } | |
99 | |
100 crypto::CryptoModuleBlockingPasswordDelegate* | |
101 NewCryptoModuleBlockingDialogDelegate( | |
102 CryptoModulePasswordReason reason, | |
103 const std::string& server) { | |
104 return new CryptoModuleBlockingDialogDelegate(reason, server); | |
105 } | |
106 } // namespace browser | |
OLD | NEW |