Chromium Code Reviews| 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_view.h" | |
| 6 | |
| 7 #include "base/basictypes.h" | |
| 8 #include "base/bind.h" | |
| 9 #include "base/utf_string_conversions.h" | |
| 10 #include "googleurl/src/gurl.h" | |
| 11 #include "grit/generated_resources.h" | |
| 12 #include "ui/base/l10n/l10n_util.h" | |
| 13 #include "views/controls/button/text_button.h" | |
| 14 #include "views/controls/label.h" | |
| 15 #include "views/controls/textfield/textfield.h" | |
| 16 #include "views/layout/grid_layout.h" | |
| 17 #include "views/layout/layout_constants.h" | |
| 18 | |
| 19 namespace browser { | |
| 20 // CryptoModulePasswordDialogView | |
| 21 //////////////////////////////////////////////////////////////////////////////// | |
| 22 CryptoModulePasswordDialogView::CryptoModulePasswordDialogView( | |
| 23 const std::string& slot_name, | |
| 24 browser::CryptoModulePasswordReason reason, | |
| 25 const std::string& server, | |
| 26 const base::Callback<void(const char*)>& callback) | |
| 27 : callback_(callback) { | |
| 28 Init(server, slot_name, reason); | |
| 29 } | |
| 30 | |
| 31 void CryptoModulePasswordDialogView::Init( | |
| 32 const std::string& server, | |
| 33 const std::string& slot_name, | |
| 34 browser::CryptoModulePasswordReason reason) { | |
| 35 | |
| 36 // Select an appropriate text for the reason. | |
| 37 std::string text; | |
| 38 const string16& server16 = UTF8ToUTF16(server); | |
| 39 const string16& slot16 = UTF8ToUTF16(slot_name); | |
| 40 switch (reason) { | |
| 41 case browser::kCryptoModulePasswordKeygen: | |
| 42 text = l10n_util::GetStringFUTF8( | |
| 43 IDS_CRYPTO_MODULE_AUTH_DIALOG_TEXT_KEYGEN, slot16, server16); | |
| 44 break; | |
| 45 case browser::kCryptoModulePasswordCertEnrollment: | |
| 46 text = l10n_util::GetStringFUTF8( | |
| 47 IDS_CRYPTO_MODULE_AUTH_DIALOG_TEXT_CERT_ENROLLMENT, slot16, server16); | |
| 48 break; | |
| 49 case browser::kCryptoModulePasswordClientAuth: | |
| 50 text = l10n_util::GetStringFUTF8( | |
| 51 IDS_CRYPTO_MODULE_AUTH_DIALOG_TEXT_CLIENT_AUTH, slot16, server16); | |
| 52 break; | |
| 53 case browser::kCryptoModulePasswordListCerts: | |
| 54 text = l10n_util::GetStringFUTF8( | |
| 55 IDS_CRYPTO_MODULE_AUTH_DIALOG_TEXT_LIST_CERTS, slot16); | |
| 56 break; | |
| 57 case browser::kCryptoModulePasswordCertImport: | |
| 58 text = l10n_util::GetStringFUTF8( | |
| 59 IDS_CRYPTO_MODULE_AUTH_DIALOG_TEXT_CERT_IMPORT, slot16); | |
| 60 break; | |
| 61 case browser::kCryptoModulePasswordCertExport: | |
| 62 text = l10n_util::GetStringFUTF8( | |
| 63 IDS_CRYPTO_MODULE_AUTH_DIALOG_TEXT_CERT_EXPORT, slot16); | |
| 64 break; | |
| 65 default: | |
| 66 NOTREACHED(); | |
| 67 } | |
| 68 reason_label_ = new views::Label(); | |
| 69 reason_label_->SetText(UTF8ToWide(text)); | |
| 70 reason_label_->SetMultiLine(true); | |
| 71 reason_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | |
| 72 | |
| 73 password_label_ = new views::Label(); | |
| 74 password_label_->SetText(UTF8ToWide( | |
| 75 l10n_util::GetStringUTF8( | |
| 76 IDS_CRYPTO_MODULE_AUTH_DIALOG_PASSWORD_FIELD))); | |
| 77 password_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | |
| 78 | |
| 79 password_entry_ = new views::Textfield(views::Textfield::STYLE_PASSWORD); | |
| 80 password_entry_->SetController(this); | |
| 81 | |
| 82 views::GridLayout* layout = views::GridLayout::CreatePanel(this); | |
| 83 SetLayoutManager(layout); | |
| 84 | |
| 85 views::ColumnSet* column_set = layout->AddColumnSet(0); | |
| 86 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1, | |
| 87 views::GridLayout::USE_PREF, 0, 0); | |
| 88 column_set->AddPaddingColumn( | |
| 89 0, views::kUnrelatedControlLargeHorizontalSpacing); | |
| 90 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1, | |
| 91 views::GridLayout::USE_PREF, 0, 0); | |
| 92 | |
| 93 layout->StartRow(0, 0); | |
| 94 layout->AddView(reason_label_); | |
| 95 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); | |
| 96 | |
| 97 layout->StartRow(0, 0); | |
| 98 layout->AddView(password_label_); | |
| 99 layout->AddView(password_entry_); | |
| 100 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); | |
| 101 } | |
| 102 | |
| 103 views::View* CryptoModulePasswordDialogView::GetInitiallyFocusedView() { | |
| 104 return password_entry_; | |
| 105 } | |
| 106 bool CryptoModulePasswordDialogView::IsModal() const { | |
| 107 return true; | |
| 108 } | |
| 109 views::View* CryptoModulePasswordDialogView::GetContentsView() { | |
| 110 return this; | |
| 111 } | |
| 112 | |
| 113 std::wstring CryptoModulePasswordDialogView::GetDialogButtonLabel( | |
| 114 ui::MessageBoxFlags::DialogButton button) const { | |
| 115 if (button == ui::MessageBoxFlags::DIALOGBUTTON_OK) | |
| 116 return UTF8ToWide(l10n_util::GetStringUTF8( | |
| 117 IDS_CRYPTO_MODULE_AUTH_DIALOG_OK_BUTTON_LABEL)); | |
| 118 else if (button == ui::MessageBoxFlags::DIALOGBUTTON_CANCEL) | |
|
Greg Spencer (Chromium)
2011/10/05 23:41:16
remove extra space after the "=="
alicet1
2011/10/06 22:04:08
Done.
| |
| 119 return UTF8ToWide(l10n_util::GetStringUTF8(IDS_CANCEL)); | |
| 120 return L""; | |
| 121 } | |
| 122 | |
| 123 bool CryptoModulePasswordDialogView::Accept() { | |
| 124 callback_.Run(UTF16ToUTF8(password_entry_->text()).c_str()); | |
| 125 string16 empty; | |
|
Greg Spencer (Chromium)
2011/10/05 23:41:16
probably can be const.
alicet1
2011/10/06 22:04:08
Done.
| |
| 126 password_entry_->SetText(empty); | |
| 127 return true; | |
| 128 } | |
| 129 | |
| 130 bool CryptoModulePasswordDialogView::Cancel() { | |
| 131 callback_.Run(static_cast<const char*>(NULL)); | |
| 132 string16 empty; | |
| 133 password_entry_->SetText(empty); | |
| 134 return true; | |
| 135 } | |
| 136 | |
| 137 bool CryptoModulePasswordDialogView::HandleKeyEvent( | |
| 138 views::Textfield* sender, | |
| 139 const views::KeyEvent& keystroke) { | |
| 140 return false; | |
| 141 } | |
| 142 | |
| 143 string16 CryptoModulePasswordDialogView::GetWindowTitle() const { | |
| 144 return UTF8ToUTF16(l10n_util::GetStringUTF8( | |
| 145 IDS_CRYPTO_MODULE_AUTH_DIALOG_TITLE)); | |
| 146 } | |
| 147 } // namespace browser | |
| OLD | NEW |