| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/views/crypto_module_password_dialog_view.h" | 5 #include "chrome/browser/ui/views/crypto_module_password_dialog_view.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | |
| 8 #include "base/bind.h" | |
| 9 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/ui/views/window.h" | |
| 11 #include "googleurl/src/gurl.h" | |
| 12 #include "grit/generated_resources.h" | 8 #include "grit/generated_resources.h" |
| 13 #include "ui/base/l10n/l10n_util.h" | 9 #include "ui/base/l10n/l10n_util.h" |
| 14 #include "ui/views/controls/button/text_button.h" | 10 #include "ui/views/controls/button/text_button.h" |
| 15 #include "ui/views/controls/label.h" | 11 #include "ui/views/controls/label.h" |
| 16 #include "ui/views/controls/textfield/textfield.h" | 12 #include "ui/views/controls/textfield/textfield.h" |
| 17 #include "ui/views/layout/grid_layout.h" | 13 #include "ui/views/layout/grid_layout.h" |
| 18 #include "ui/views/layout/layout_constants.h" | 14 #include "ui/views/layout/layout_constants.h" |
| 19 #include "ui/views/widget/widget.h" | 15 #include "ui/views/widget/widget.h" |
| 20 | 16 |
| 21 namespace browser { | 17 namespace browser { |
| 22 | 18 |
| 23 // CryptoModulePasswordDialogView | |
| 24 //////////////////////////////////////////////////////////////////////////////// | 19 //////////////////////////////////////////////////////////////////////////////// |
| 20 // CryptoModulePasswordDialogView, public: |
| 21 |
| 25 CryptoModulePasswordDialogView::CryptoModulePasswordDialogView( | 22 CryptoModulePasswordDialogView::CryptoModulePasswordDialogView( |
| 26 const std::string& slot_name, | 23 const std::string& slot_name, |
| 27 browser::CryptoModulePasswordReason reason, | 24 CryptoModulePasswordReason reason, |
| 28 const std::string& server, | 25 const std::string& server, |
| 29 const base::Callback<void(const char*)>& callback) | 26 const CryptoModulePasswordCallback& callback) |
| 30 : callback_(callback) { | 27 : callback_(callback) { |
| 31 Init(server, slot_name, reason); | 28 Init(server, slot_name, reason); |
| 32 } | 29 } |
| 33 | 30 |
| 34 CryptoModulePasswordDialogView::~CryptoModulePasswordDialogView() { | 31 CryptoModulePasswordDialogView::~CryptoModulePasswordDialogView() { |
| 35 } | 32 } |
| 36 | 33 |
| 37 void CryptoModulePasswordDialogView::Init( | 34 //////////////////////////////////////////////////////////////////////////////// |
| 38 const std::string& server, | 35 // CryptoModulePasswordDialogView, private: |
| 39 const std::string& slot_name, | 36 |
| 40 browser::CryptoModulePasswordReason reason) { | 37 views::View* CryptoModulePasswordDialogView::GetInitiallyFocusedView() { |
| 38 return password_entry_; |
| 39 } |
| 40 |
| 41 ui::ModalType CryptoModulePasswordDialogView::GetModalType() const { |
| 42 return ui::MODAL_TYPE_WINDOW; |
| 43 } |
| 44 |
| 45 string16 CryptoModulePasswordDialogView::GetWindowTitle() const { |
| 46 return l10n_util::GetStringUTF16(IDS_CRYPTO_MODULE_AUTH_DIALOG_TITLE); |
| 47 } |
| 48 |
| 49 views::View* CryptoModulePasswordDialogView::GetContentsView() { |
| 50 return this; |
| 51 } |
| 52 |
| 53 string16 CryptoModulePasswordDialogView::GetDialogButtonLabel( |
| 54 ui::DialogButton button) const { |
| 55 return l10n_util::GetStringUTF16(button == ui::DIALOG_BUTTON_OK ? |
| 56 IDS_CRYPTO_MODULE_AUTH_DIALOG_OK_BUTTON_LABEL : IDS_CANCEL); |
| 57 } |
| 58 |
| 59 bool CryptoModulePasswordDialogView::Cancel() { |
| 60 callback_.Run(static_cast<const char*>(NULL)); |
| 61 const string16 empty; |
| 62 password_entry_->SetText(empty); |
| 63 return true; |
| 64 } |
| 65 |
| 66 bool CryptoModulePasswordDialogView::Accept() { |
| 67 callback_.Run(UTF16ToUTF8(password_entry_->text()).c_str()); |
| 68 const string16 empty; |
| 69 password_entry_->SetText(empty); |
| 70 return true; |
| 71 } |
| 72 |
| 73 |
| 74 void CryptoModulePasswordDialogView::ContentsChanged( |
| 75 views::Textfield* sender, |
| 76 const string16& new_contents) { |
| 77 } |
| 78 |
| 79 bool CryptoModulePasswordDialogView::HandleKeyEvent( |
| 80 views::Textfield* sender, |
| 81 const views::KeyEvent& keystroke) { |
| 82 return false; |
| 83 } |
| 84 |
| 85 void CryptoModulePasswordDialogView::Init(const std::string& server, |
| 86 const std::string& slot_name, |
| 87 CryptoModulePasswordReason reason) { |
| 41 // Select an appropriate text for the reason. | 88 // Select an appropriate text for the reason. |
| 42 std::string text; | 89 std::string text; |
| 43 const string16& server16 = UTF8ToUTF16(server); | 90 const string16& server16 = UTF8ToUTF16(server); |
| 44 const string16& slot16 = UTF8ToUTF16(slot_name); | 91 const string16& slot16 = UTF8ToUTF16(slot_name); |
| 45 switch (reason) { | 92 switch (reason) { |
| 46 case browser::kCryptoModulePasswordKeygen: | 93 case browser::kCryptoModulePasswordKeygen: |
| 47 text = l10n_util::GetStringFUTF8( | 94 text = l10n_util::GetStringFUTF8( |
| 48 IDS_CRYPTO_MODULE_AUTH_DIALOG_TEXT_KEYGEN, slot16, server16); | 95 IDS_CRYPTO_MODULE_AUTH_DIALOG_TEXT_KEYGEN, slot16, server16); |
| 49 break; | 96 break; |
| 50 case browser::kCryptoModulePasswordCertEnrollment: | 97 case browser::kCryptoModulePasswordCertEnrollment: |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 | 145 |
| 99 layout->StartRow(0, 0); | 146 layout->StartRow(0, 0); |
| 100 layout->AddView(reason_label_); | 147 layout->AddView(reason_label_); |
| 101 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); | 148 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); |
| 102 | 149 |
| 103 layout->StartRow(0, 1); | 150 layout->StartRow(0, 1); |
| 104 layout->AddView(password_label_); | 151 layout->AddView(password_label_); |
| 105 layout->AddView(password_entry_); | 152 layout->AddView(password_entry_); |
| 106 } | 153 } |
| 107 | 154 |
| 108 views::View* CryptoModulePasswordDialogView::GetInitiallyFocusedView() { | |
| 109 return password_entry_; | |
| 110 } | |
| 111 | |
| 112 ui::ModalType CryptoModulePasswordDialogView::GetModalType() const { | |
| 113 return ui::MODAL_TYPE_WINDOW; | |
| 114 } | |
| 115 | |
| 116 views::View* CryptoModulePasswordDialogView::GetContentsView() { | |
| 117 return this; | |
| 118 } | |
| 119 | |
| 120 string16 CryptoModulePasswordDialogView::GetDialogButtonLabel( | |
| 121 ui::DialogButton button) const { | |
| 122 return l10n_util::GetStringUTF16(button == ui::DIALOG_BUTTON_OK ? | |
| 123 IDS_CRYPTO_MODULE_AUTH_DIALOG_OK_BUTTON_LABEL : IDS_CANCEL); | |
| 124 } | |
| 125 | |
| 126 bool CryptoModulePasswordDialogView::Accept() { | |
| 127 callback_.Run(UTF16ToUTF8(password_entry_->text()).c_str()); | |
| 128 const string16 empty; | |
| 129 password_entry_->SetText(empty); | |
| 130 return true; | |
| 131 } | |
| 132 | |
| 133 bool CryptoModulePasswordDialogView::Cancel() { | |
| 134 callback_.Run(static_cast<const char*>(NULL)); | |
| 135 const string16 empty; | |
| 136 password_entry_->SetText(empty); | |
| 137 return true; | |
| 138 } | |
| 139 | |
| 140 bool CryptoModulePasswordDialogView::HandleKeyEvent( | |
| 141 views::Textfield* sender, | |
| 142 const views::KeyEvent& keystroke) { | |
| 143 return false; | |
| 144 } | |
| 145 | |
| 146 void CryptoModulePasswordDialogView::ContentsChanged( | |
| 147 views::Textfield* sender, | |
| 148 const string16& new_contents) { | |
| 149 } | |
| 150 | |
| 151 string16 CryptoModulePasswordDialogView::GetWindowTitle() const { | |
| 152 return l10n_util::GetStringUTF16(IDS_CRYPTO_MODULE_AUTH_DIALOG_TITLE); | |
| 153 } | |
| 154 | |
| 155 void ShowCryptoModulePasswordDialog( | 155 void ShowCryptoModulePasswordDialog( |
| 156 const std::string& slot_name, | 156 const std::string& slot_name, |
| 157 bool retry, | 157 bool retry, |
| 158 CryptoModulePasswordReason reason, | 158 CryptoModulePasswordReason reason, |
| 159 const std::string& server, | 159 const std::string& server, |
| 160 const CryptoModulePasswordCallback& callback) { | 160 const CryptoModulePasswordCallback& callback) { |
| 161 CryptoModulePasswordDialogView* dialog = | 161 CryptoModulePasswordDialogView* dialog = |
| 162 new CryptoModulePasswordDialogView(slot_name, reason, server, callback); | 162 new CryptoModulePasswordDialogView(slot_name, reason, server, callback); |
| 163 views::Widget::CreateWindow(dialog)->Show(); | 163 views::Widget::CreateWindow(dialog)->Show(); |
| 164 } | 164 } |
| 165 | 165 |
| 166 } // namespace browser | 166 } // namespace browser |
| OLD | NEW |