Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
|
alicet1
2011/11/29 19:04:27
I tried re-uploading, but that doesn't show the di
| |
| 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 virtual ~CryptoModuleBlockingDialogDelegate() { | |
| 39 // Make sure we clear the password in memory. | |
| 40 password_.replace(0, password_.size(), password_.size(), 0); | |
| 41 } | |
| 42 | |
| 43 // crypto::CryptoModuleBlockingDialogDelegate implementation. | |
| 44 virtual std::string RequestPassword(const std::string& slot_name, | |
| 45 bool retry, | |
| 46 bool* cancelled) OVERRIDE { | |
| 47 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 48 DCHECK(!event_.IsSignaled()); | |
| 49 event_.Reset(); | |
| 50 | |
| 51 if (BrowserThread::PostTask( | |
| 52 BrowserThread::UI, FROM_HERE, | |
| 53 base::Bind(&CryptoModuleBlockingDialogDelegate::ShowDialog, | |
| 54 // We block on event_ until the task completes, so | |
| 55 // there's no need to ref-count. | |
| 56 base::Unretained(this), | |
| 57 slot_name, | |
| 58 retry))) { | |
| 59 event_.Wait(); | |
| 60 } | |
| 61 *cancelled = cancelled_; | |
| 62 return password_; | |
| 63 } | |
| 64 | |
| 65 private: | |
| 66 void ShowDialog(const std::string& slot_name, | |
| 67 bool retry) { | |
| 68 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 69 ShowCryptoModulePasswordDialog( | |
| 70 slot_name, retry, reason_, server_, | |
| 71 base::Bind(&CryptoModuleBlockingDialogDelegate::GotPassword, | |
| 72 // We block on event_ until the task completes, so | |
| 73 // there's no need to ref-count. | |
| 74 base::Unretained(this))); | |
| 75 } | |
| 76 | |
| 77 void GotPassword(const char* password) { | |
| 78 if (password) | |
| 79 password_ = password; | |
| 80 else | |
| 81 cancelled_ = true; | |
| 82 event_.Signal(); | |
| 83 } | |
| 84 | |
| 85 base::WaitableEvent event_; | |
| 86 browser::CryptoModulePasswordReason reason_; | |
| 87 std::string server_; | |
| 88 std::string password_; | |
| 89 bool cancelled_; | |
| 90 | |
| 91 DISALLOW_COPY_AND_ASSIGN(CryptoModuleBlockingDialogDelegate); | |
| 92 }; | |
| 93 } // namespace | |
| 94 | |
| 95 namespace browser { | |
| 96 | |
| 97 void ShowCryptoModulePasswordDialog( | |
| 98 const std::string& slot_name, | |
| 99 bool retry, | |
| 100 CryptoModulePasswordReason reason, | |
| 101 const std::string& server, | |
| 102 const CryptoModulePasswordCallback& callback) { | |
| 103 #if defined(TOOLKIT_VIEWS) | |
| 104 CryptoModulePasswordDialogView* dialog = | |
| 105 new CryptoModulePasswordDialogView( | |
| 106 slot_name, reason, server, callback); | |
| 107 views::Widget* widget = CreateViewsWindow(NULL, dialog); | |
| 108 widget->Show(); | |
| 109 #endif | |
| 110 } | |
| 111 | |
| 112 crypto::CryptoModuleBlockingPasswordDelegate* | |
| 113 NewCryptoModuleBlockingDialogDelegate( | |
| 114 CryptoModulePasswordReason reason, | |
| 115 const std::string& server) { | |
| 116 return new CryptoModuleBlockingDialogDelegate(reason, server); | |
| 117 } | |
| 118 } // namespace browser | |
| OLD | NEW |