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

Side by Side Diff: chrome/browser/gtk/crypto_module_password_dialog.cc

Issue 6303004: Cleanup: replace usage of "pk11" with "pkcs11" or "crypto module", as appropriate. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 11 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/pk11_password_dialog.h" 5 #include "chrome/browser/ui/crypto_module_password_dialog.h"
6 6
7 #include <gtk/gtk.h> 7 #include <gtk/gtk.h>
8 8
9 #include "app/gtk_signal.h" 9 #include "app/gtk_signal.h"
10 #include "app/l10n_util.h" 10 #include "app/l10n_util.h"
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/crypto/pk11_blocking_password_delegate.h" 12 #include "base/crypto/crypto_module_blocking_password_delegate.h"
13 #include "base/synchronization/waitable_event.h" 13 #include "base/synchronization/waitable_event.h"
14 #include "base/task.h" 14 #include "base/task.h"
15 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
16 #include "chrome/browser/browser_thread.h" 16 #include "chrome/browser/browser_thread.h"
17 #include "chrome/browser/gtk/gtk_util.h" 17 #include "chrome/browser/gtk/gtk_util.h"
18 #include "googleurl/src/gurl.h" 18 #include "googleurl/src/gurl.h"
19 #include "grit/generated_resources.h" 19 #include "grit/generated_resources.h"
20 20
21 namespace { 21 namespace {
22 22
23 class PK11BlockingDialogDelegate : public base::PK11BlockingPasswordDelegate { 23 class CryptoModuleBlockingDialogDelegate
24 : public base::CryptoModuleBlockingPasswordDelegate {
24 public: 25 public:
25 PK11BlockingDialogDelegate(browser::PK11PasswordReason reason, 26 CryptoModuleBlockingDialogDelegate(browser::CryptoModulePasswordReason reason,
26 const std::string& server) 27 const std::string& server)
tfarina 2011/01/13 23:52:27 wrong indentation.
mattm 2011/01/19 00:59:34 Done.
27 : event_(false, false), 28 : event_(false, false),
28 reason_(reason), 29 reason_(reason),
29 server_(server), 30 server_(server),
30 password_(), 31 password_(),
31 cancelled_(false) { 32 cancelled_(false) {
32 } 33 }
33 34
34 ~PK11BlockingDialogDelegate() { 35 ~CryptoModuleBlockingDialogDelegate() {
35 password_.replace(0, password_.size(), password_.size(), 0); 36 password_.replace(0, password_.size(), password_.size(), 0);
36 } 37 }
37 38
38 // base::PK11BlockingDialogDelegate implementation. 39 // base::CryptoModuleBlockingDialogDelegate implementation.
39 virtual std::string RequestPassword(const std::string& slot_name, bool retry, 40 virtual std::string RequestPassword(const std::string& slot_name, bool retry,
40 bool* cancelled) { 41 bool* cancelled) {
41 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); 42 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI));
42 DCHECK(!event_.IsSignaled()); 43 DCHECK(!event_.IsSignaled());
43 event_.Reset(); 44 event_.Reset();
44 if (BrowserThread::PostTask( 45 if (BrowserThread::PostTask(
45 BrowserThread::UI, FROM_HERE, 46 BrowserThread::UI, FROM_HERE,
46 NewRunnableMethod(this, &PK11BlockingDialogDelegate::ShowDialog, 47 NewRunnableMethod(this,
47 slot_name, retry))) { 48 &CryptoModuleBlockingDialogDelegate::ShowDialog,
49 slot_name,
50 retry))) {
48 event_.Wait(); 51 event_.Wait();
49 } 52 }
50 *cancelled = cancelled_; 53 *cancelled = cancelled_;
51 return password_; 54 return password_;
52 } 55 }
53 56
54 private: 57 private:
55 void ShowDialog(const std::string& slot_name, bool retry) { 58 void ShowDialog(const std::string& slot_name, bool retry) {
56 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
57 ShowPK11PasswordDialog( 60 ShowCryptoModulePasswordDialog(
58 slot_name, retry, reason_, server_, 61 slot_name, retry, reason_, server_,
59 NewCallback(this, &PK11BlockingDialogDelegate::GotPassword)); 62 NewCallback(this, &CryptoModuleBlockingDialogDelegate::GotPassword));
60 } 63 }
61 void GotPassword(const char* password) { 64 void GotPassword(const char* password) {
62 if (password) 65 if (password)
63 password_ = password; 66 password_ = password;
64 else 67 else
65 cancelled_ = true; 68 cancelled_ = true;
66 event_.Signal(); 69 event_.Signal();
67 } 70 }
68 base::WaitableEvent event_; 71 base::WaitableEvent event_;
69 browser::PK11PasswordReason reason_; 72 browser::CryptoModulePasswordReason reason_;
70 std::string server_; 73 std::string server_;
71 std::string password_; 74 std::string password_;
72 bool cancelled_; 75 bool cancelled_;
73 76
74 DISALLOW_COPY_AND_ASSIGN(PK11BlockingDialogDelegate); 77 DISALLOW_COPY_AND_ASSIGN(CryptoModuleBlockingDialogDelegate);
75 }; 78 };
76 79
77 // TODO(mattm): change into a constrained dialog. 80 // TODO(mattm): change into a constrained dialog.
78 class PK11PasswordDialog { 81 class CryptoModulePasswordDialog {
79 public: 82 public:
80 PK11PasswordDialog(const std::string& slot_name, 83 CryptoModulePasswordDialog(const std::string& slot_name,
81 bool retry, 84 bool retry,
tfarina 2011/01/13 23:52:27 wrong indentation.
mattm 2011/01/19 00:59:34 Done.
82 browser::PK11PasswordReason reason, 85 browser::CryptoModulePasswordReason reason,
83 const std::string& server, 86 const std::string& server,
84 browser::PK11PasswordCallback* callback); 87 browser::CryptoModulePasswordCallback* callback);
85 88
86 void Show(); 89 void Show();
87 90
88 private: 91 private:
89 CHROMEGTK_CALLBACK_1(PK11PasswordDialog, void, OnResponse, int); 92 CHROMEGTK_CALLBACK_1(CryptoModulePasswordDialog, void, OnResponse, int);
90 CHROMEGTK_CALLBACK_0(PK11PasswordDialog, void, OnWindowDestroy); 93 CHROMEGTK_CALLBACK_0(CryptoModulePasswordDialog, void, OnWindowDestroy);
91 94
92 scoped_ptr<browser::PK11PasswordCallback> callback_; 95 scoped_ptr<browser::CryptoModulePasswordCallback> callback_;
93 96
94 GtkWidget* dialog_; 97 GtkWidget* dialog_;
95 GtkWidget* password_entry_; 98 GtkWidget* password_entry_;
96 99
97 DISALLOW_COPY_AND_ASSIGN(PK11PasswordDialog); 100 DISALLOW_COPY_AND_ASSIGN(CryptoModulePasswordDialog);
98 }; 101 };
99 102
100 PK11PasswordDialog::PK11PasswordDialog(const std::string& slot_name, 103 CryptoModulePasswordDialog::CryptoModulePasswordDialog(
101 bool retry, 104 const std::string& slot_name,
102 browser::PK11PasswordReason reason, 105 bool retry,
103 const std::string& server, 106 browser::CryptoModulePasswordReason reason,
104 browser::PK11PasswordCallback* callback) 107 const std::string& server,
108 browser::CryptoModulePasswordCallback* callback)
105 : callback_(callback) { 109 : callback_(callback) {
106 dialog_ = gtk_dialog_new_with_buttons( 110 dialog_ = gtk_dialog_new_with_buttons(
107 l10n_util::GetStringUTF8(IDS_PK11_AUTH_DIALOG_TITLE).c_str(), 111 l10n_util::GetStringUTF8(IDS_CRYPTO_MODULE_AUTH_DIALOG_TITLE).c_str(),
108 NULL, 112 NULL,
109 GTK_DIALOG_NO_SEPARATOR, 113 GTK_DIALOG_NO_SEPARATOR,
110 NULL); // Populate the buttons later, for control over the OK button. 114 NULL); // Populate the buttons later, for control over the OK button.
111 gtk_dialog_add_button(GTK_DIALOG(dialog_), 115 gtk_dialog_add_button(GTK_DIALOG(dialog_),
112 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT); 116 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT);
113 GtkWidget* ok_button = gtk_util::AddButtonToDialog( 117 GtkWidget* ok_button = gtk_util::AddButtonToDialog(
114 dialog_, 118 dialog_,
115 l10n_util::GetStringUTF8(IDS_PK11_AUTH_DIALOG_OK_BUTTON_LABEL).c_str(), 119 l10n_util::GetStringUTF8(
120 IDS_CRYPTO_MODULE_AUTH_DIALOG_OK_BUTTON_LABEL).c_str(),
116 GTK_STOCK_OK, 121 GTK_STOCK_OK,
117 GTK_RESPONSE_ACCEPT); 122 GTK_RESPONSE_ACCEPT);
118 GTK_WIDGET_SET_FLAGS(ok_button, GTK_CAN_DEFAULT); 123 GTK_WIDGET_SET_FLAGS(ok_button, GTK_CAN_DEFAULT);
119 gtk_dialog_set_default_response(GTK_DIALOG(dialog_), GTK_RESPONSE_ACCEPT); 124 gtk_dialog_set_default_response(GTK_DIALOG(dialog_), GTK_RESPONSE_ACCEPT);
120 125
121 // Select an appropriate text for the reason. 126 // Select an appropriate text for the reason.
122 std::string text; 127 std::string text;
123 const string16& server16 = UTF8ToUTF16(server); 128 const string16& server16 = UTF8ToUTF16(server);
124 const string16& slot16 = UTF8ToUTF16(slot_name); 129 const string16& slot16 = UTF8ToUTF16(slot_name);
125 switch (reason) { 130 switch (reason) {
126 case browser::kPK11PasswordKeygen: 131 case browser::kCryptoModulePasswordKeygen:
127 text = l10n_util::GetStringFUTF8(IDS_PK11_AUTH_DIALOG_TEXT_KEYGEN, 132 text = l10n_util::GetStringFUTF8(
128 slot16, server16); 133 IDS_CRYPTO_MODULE_AUTH_DIALOG_TEXT_KEYGEN, slot16, server16);
129 break; 134 break;
130 case browser::kPK11PasswordCertEnrollment: 135 case browser::kCryptoModulePasswordCertEnrollment:
131 text = l10n_util::GetStringFUTF8( 136 text = l10n_util::GetStringFUTF8(
132 IDS_PK11_AUTH_DIALOG_TEXT_CERT_ENROLLMENT, slot16, server16); 137 IDS_CRYPTO_MODULE_AUTH_DIALOG_TEXT_CERT_ENROLLMENT, slot16, server16);
133 break; 138 break;
134 case browser::kPK11PasswordClientAuth: 139 case browser::kCryptoModulePasswordClientAuth:
135 text = l10n_util::GetStringFUTF8(IDS_PK11_AUTH_DIALOG_TEXT_CLIENT_AUTH, 140 text = l10n_util::GetStringFUTF8(
136 slot16, server16); 141 IDS_CRYPTO_MODULE_AUTH_DIALOG_TEXT_CLIENT_AUTH, slot16, server16);
137 break; 142 break;
138 case browser::kPK11PasswordCertImport: 143 case browser::kCryptoModulePasswordCertImport:
139 text = l10n_util::GetStringFUTF8(IDS_PK11_AUTH_DIALOG_TEXT_CERT_IMPORT, 144 text = l10n_util::GetStringFUTF8(
140 slot16); 145 IDS_CRYPTO_MODULE_AUTH_DIALOG_TEXT_CERT_IMPORT, slot16);
141 break; 146 break;
142 case browser::kPK11PasswordCertExport: 147 case browser::kCryptoModulePasswordCertExport:
143 text = l10n_util::GetStringFUTF8(IDS_PK11_AUTH_DIALOG_TEXT_CERT_EXPORT, 148 text = l10n_util::GetStringFUTF8(
144 slot16); 149 IDS_CRYPTO_MODULE_AUTH_DIALOG_TEXT_CERT_EXPORT, slot16);
145 break; 150 break;
146 default: 151 default:
147 NOTREACHED(); 152 NOTREACHED();
148 } 153 }
149 GtkWidget* label = gtk_label_new(text.c_str()); 154 GtkWidget* label = gtk_label_new(text.c_str());
150 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); 155 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
151 gtk_util::LeftAlignMisc(label); 156 gtk_util::LeftAlignMisc(label);
152 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog_)->vbox), label, 157 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog_)->vbox), label,
153 FALSE, FALSE, 0); 158 FALSE, FALSE, 0);
154 159
155 password_entry_ = gtk_entry_new(); 160 password_entry_ = gtk_entry_new();
156 gtk_entry_set_activates_default(GTK_ENTRY(password_entry_), TRUE); 161 gtk_entry_set_activates_default(GTK_ENTRY(password_entry_), TRUE);
157 gtk_entry_set_visibility(GTK_ENTRY(password_entry_), FALSE); 162 gtk_entry_set_visibility(GTK_ENTRY(password_entry_), FALSE);
158 163
159 GtkWidget* password_box = gtk_hbox_new(FALSE, gtk_util::kLabelSpacing); 164 GtkWidget* password_box = gtk_hbox_new(FALSE, gtk_util::kLabelSpacing);
160 gtk_box_pack_start(GTK_BOX(password_box), 165 gtk_box_pack_start(GTK_BOX(password_box),
161 gtk_label_new(l10n_util::GetStringUTF8( 166 gtk_label_new(l10n_util::GetStringUTF8(
162 IDS_PK11_AUTH_DIALOG_PASSWORD_FIELD).c_str()), 167 IDS_CRYPTO_MODULE_AUTH_DIALOG_PASSWORD_FIELD).c_str()),
163 FALSE, FALSE, 0); 168 FALSE, FALSE, 0);
164 gtk_box_pack_start(GTK_BOX(password_box), password_entry_, 169 gtk_box_pack_start(GTK_BOX(password_box), password_entry_,
165 TRUE, TRUE, 0); 170 TRUE, TRUE, 0);
166 171
167 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog_)->vbox), password_box, 172 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog_)->vbox), password_box,
168 FALSE, FALSE, 0); 173 FALSE, FALSE, 0);
169 174
170 g_signal_connect(dialog_, "response", 175 g_signal_connect(dialog_, "response",
171 G_CALLBACK(OnResponseThunk), this); 176 G_CALLBACK(OnResponseThunk), this);
172 g_signal_connect(dialog_, "destroy", 177 g_signal_connect(dialog_, "destroy",
173 G_CALLBACK(OnWindowDestroyThunk), this); 178 G_CALLBACK(OnWindowDestroyThunk), this);
174 } 179 }
175 180
176 void PK11PasswordDialog::Show() { 181 void CryptoModulePasswordDialog::Show() {
177 gtk_util::ShowDialog(dialog_); 182 gtk_util::ShowDialog(dialog_);
178 } 183 }
179 184
180 void PK11PasswordDialog::OnResponse(GtkWidget* dialog, int response_id) { 185 void CryptoModulePasswordDialog::OnResponse(GtkWidget* dialog,
186 int response_id) {
181 if (response_id == GTK_RESPONSE_ACCEPT) 187 if (response_id == GTK_RESPONSE_ACCEPT)
182 callback_->Run(gtk_entry_get_text(GTK_ENTRY(password_entry_))); 188 callback_->Run(gtk_entry_get_text(GTK_ENTRY(password_entry_)));
183 else 189 else
184 callback_->Run(static_cast<const char*>(NULL)); 190 callback_->Run(static_cast<const char*>(NULL));
185 191
186 // This will cause gtk to zero out the buffer. (see 192 // This will cause gtk to zero out the buffer. (see
187 // gtk_entry_buffer_normal_delete_text: 193 // gtk_entry_buffer_normal_delete_text:
188 // http://git.gnome.org/browse/gtk+/tree/gtk/gtkentrybuffer.c#n187) 194 // http://git.gnome.org/browse/gtk+/tree/gtk/gtkentrybuffer.c#n187)
189 gtk_editable_delete_text(GTK_EDITABLE(password_entry_), 0, -1); 195 gtk_editable_delete_text(GTK_EDITABLE(password_entry_), 0, -1);
190 gtk_widget_destroy(GTK_WIDGET(dialog_)); 196 gtk_widget_destroy(GTK_WIDGET(dialog_));
191 } 197 }
192 198
193 void PK11PasswordDialog::OnWindowDestroy(GtkWidget* widget) { 199 void CryptoModulePasswordDialog::OnWindowDestroy(GtkWidget* widget) {
194 delete this; 200 delete this;
195 } 201 }
196 202
197 } // namespace 203 } // namespace
198 204
199 // Every post-task we do blocks, so there's no need to ref-count. 205 // Every post-task we do blocks, so there's no need to ref-count.
200 DISABLE_RUNNABLE_METHOD_REFCOUNT(PK11BlockingDialogDelegate); 206 DISABLE_RUNNABLE_METHOD_REFCOUNT(CryptoModuleBlockingDialogDelegate);
201 207
202 namespace browser { 208 namespace browser {
203 209
204 void ShowPK11PasswordDialog(const std::string& slot_name, 210 void ShowCryptoModulePasswordDialog(const std::string& slot_name,
205 bool retry, 211 bool retry,
tfarina 2011/01/13 23:52:27 wrong indentation.
206 PK11PasswordReason reason, 212 CryptoModulePasswordReason reason,
207 const std::string& server, 213 const std::string& server,
208 PK11PasswordCallback* callback) { 214 CryptoModulePasswordCallback* callback) {
209 (new PK11PasswordDialog(slot_name, retry, reason, server, callback))->Show(); 215 (new CryptoModulePasswordDialog(slot_name, retry, reason, server,
216 callback))->Show();
210 } 217 }
211 218
212 base::PK11BlockingPasswordDelegate* NewPK11BlockingDialogDelegate( 219 base::CryptoModuleBlockingPasswordDelegate*
213 PK11PasswordReason reason, 220 NewCryptoModuleBlockingDialogDelegate(
214 const std::string& server) { 221 CryptoModulePasswordReason reason,
215 return new PK11BlockingDialogDelegate(reason, server); 222 const std::string& server) {
223 return new CryptoModuleBlockingDialogDelegate(reason, server);
216 } 224 }
217 225
218 } // namespace browser 226 } // namespace browser
OLDNEW
« no previous file with comments | « chrome/browser/dom_ui/options/certificate_manager_handler.cc ('k') | chrome/browser/gtk/ssl_client_certificate_selector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698