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

Side by Side Diff: chrome/browser/ui/views/crypto_module_password_dialog_view.cc

Issue 9956157: views: Make everything in crypto module password dialog private except the ctor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: peter view Created 8 years, 8 months 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
OLDNEW
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 void CryptoModulePasswordDialogView::ContentsChanged(
74 views::Textfield* sender,
75 const string16& new_contents) {
76 }
77
78 bool CryptoModulePasswordDialogView::HandleKeyEvent(
79 views::Textfield* sender,
80 const views::KeyEvent& keystroke) {
81 return false;
82 }
83
84 void CryptoModulePasswordDialogView::Init(const std::string& server,
85 const std::string& slot_name,
86 CryptoModulePasswordReason reason) {
41 // Select an appropriate text for the reason. 87 // Select an appropriate text for the reason.
42 std::string text; 88 std::string text;
43 const string16& server16 = UTF8ToUTF16(server); 89 const string16& server16 = UTF8ToUTF16(server);
44 const string16& slot16 = UTF8ToUTF16(slot_name); 90 const string16& slot16 = UTF8ToUTF16(slot_name);
45 switch (reason) { 91 switch (reason) {
46 case browser::kCryptoModulePasswordKeygen: 92 case browser::kCryptoModulePasswordKeygen:
47 text = l10n_util::GetStringFUTF8( 93 text = l10n_util::GetStringFUTF8(
48 IDS_CRYPTO_MODULE_AUTH_DIALOG_TEXT_KEYGEN, slot16, server16); 94 IDS_CRYPTO_MODULE_AUTH_DIALOG_TEXT_KEYGEN, slot16, server16);
49 break; 95 break;
50 case browser::kCryptoModulePasswordCertEnrollment: 96 case browser::kCryptoModulePasswordCertEnrollment:
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 144
99 layout->StartRow(0, 0); 145 layout->StartRow(0, 0);
100 layout->AddView(reason_label_); 146 layout->AddView(reason_label_);
101 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); 147 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing);
102 148
103 layout->StartRow(0, 1); 149 layout->StartRow(0, 1);
104 layout->AddView(password_label_); 150 layout->AddView(password_label_);
105 layout->AddView(password_entry_); 151 layout->AddView(password_entry_);
106 } 152 }
107 153
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( 154 void ShowCryptoModulePasswordDialog(
156 const std::string& slot_name, 155 const std::string& slot_name,
157 bool retry, 156 bool retry,
158 CryptoModulePasswordReason reason, 157 CryptoModulePasswordReason reason,
159 const std::string& server, 158 const std::string& server,
160 const CryptoModulePasswordCallback& callback) { 159 const CryptoModulePasswordCallback& callback) {
161 CryptoModulePasswordDialogView* dialog = 160 CryptoModulePasswordDialogView* dialog =
162 new CryptoModulePasswordDialogView(slot_name, reason, server, callback); 161 new CryptoModulePasswordDialogView(slot_name, reason, server, callback);
163 views::Widget::CreateWindow(dialog)->Show(); 162 views::Widget::CreateWindow(dialog)->Show();
164 } 163 }
165 164
166 } // namespace browser 165 } // namespace browser
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698