OLD | NEW |
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/ssl_client_certificate_selector.h" | 5 #include "chrome/browser/ssl_client_certificate_selector.h" |
6 | 6 |
7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "app/gtk_signal.h" | 12 #include "app/gtk_signal.h" |
13 #include "app/l10n_util.h" | 13 #include "app/l10n_util.h" |
14 #include "base/i18n/time_formatting.h" | 14 #include "base/i18n/time_formatting.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/nss_util.h" | 16 #include "base/nss_util.h" |
17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
18 #include "chrome/browser/certificate_viewer.h" | 18 #include "chrome/browser/certificate_viewer.h" |
19 #include "chrome/browser/gtk/constrained_window_gtk.h" | 19 #include "chrome/browser/gtk/constrained_window_gtk.h" |
20 #include "chrome/browser/gtk/gtk_util.h" | 20 #include "chrome/browser/gtk/gtk_util.h" |
21 #include "chrome/browser/gtk/owned_widget_gtk.h" | 21 #include "chrome/browser/gtk/owned_widget_gtk.h" |
22 #include "chrome/browser/ssl/ssl_client_auth_handler.h" | 22 #include "chrome/browser/ssl/ssl_client_auth_handler.h" |
23 #include "chrome/browser/tab_contents/tab_contents.h" | 23 #include "chrome/browser/tab_contents/tab_contents.h" |
| 24 #include "chrome/browser/ui/pk11_password_dialog.h" |
24 #include "chrome/common/net/x509_certificate_model.h" | 25 #include "chrome/common/net/x509_certificate_model.h" |
25 #include "gfx/native_widget_types.h" | 26 #include "gfx/native_widget_types.h" |
26 #include "grit/generated_resources.h" | 27 #include "grit/generated_resources.h" |
27 #include "net/base/x509_certificate.h" | 28 #include "net/base/x509_certificate.h" |
28 | 29 |
29 namespace { | 30 namespace { |
30 | 31 |
31 enum { | 32 enum { |
32 RESPONSE_SHOW_CERT_INFO = 1, | 33 RESPONSE_SHOW_CERT_INFO = 1, |
33 }; | 34 }; |
(...skipping 19 matching lines...) Expand all Loading... |
53 void PopulateCerts(); | 54 void PopulateCerts(); |
54 | 55 |
55 net::X509Certificate* GetSelectedCert(); | 56 net::X509Certificate* GetSelectedCert(); |
56 | 57 |
57 static std::string FormatComboBoxText( | 58 static std::string FormatComboBoxText( |
58 net::X509Certificate::OSCertHandle cert, | 59 net::X509Certificate::OSCertHandle cert, |
59 const std::string& nickname); | 60 const std::string& nickname); |
60 static std::string FormatDetailsText( | 61 static std::string FormatDetailsText( |
61 net::X509Certificate::OSCertHandle cert); | 62 net::X509Certificate::OSCertHandle cert); |
62 | 63 |
| 64 // Callback after unlocking certificate slot. |
| 65 void Unlocked(); |
| 66 |
63 CHROMEGTK_CALLBACK_0(SSLClientCertificateSelector, void, OnComboBoxChanged); | 67 CHROMEGTK_CALLBACK_0(SSLClientCertificateSelector, void, OnComboBoxChanged); |
64 CHROMEGTK_CALLBACK_0(SSLClientCertificateSelector, void, OnViewClicked); | 68 CHROMEGTK_CALLBACK_0(SSLClientCertificateSelector, void, OnViewClicked); |
65 CHROMEGTK_CALLBACK_0(SSLClientCertificateSelector, void, OnCancelClicked); | 69 CHROMEGTK_CALLBACK_0(SSLClientCertificateSelector, void, OnCancelClicked); |
66 CHROMEGTK_CALLBACK_0(SSLClientCertificateSelector, void, OnOkClicked); | 70 CHROMEGTK_CALLBACK_0(SSLClientCertificateSelector, void, OnOkClicked); |
67 CHROMEGTK_CALLBACK_1(SSLClientCertificateSelector, void, OnPromptShown, | 71 CHROMEGTK_CALLBACK_1(SSLClientCertificateSelector, void, OnPromptShown, |
68 GtkWidget*); | 72 GtkWidget*); |
69 | 73 |
70 scoped_refptr<net::SSLCertRequestInfo> cert_request_info_; | 74 scoped_refptr<net::SSLCertRequestInfo> cert_request_info_; |
71 | 75 |
72 std::vector<std::string> details_strings_; | 76 std::vector<std::string> details_strings_; |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 | 298 |
295 string16 token(UTF8ToUTF16(x509_certificate_model::GetTokenName(cert))); | 299 string16 token(UTF8ToUTF16(x509_certificate_model::GetTokenName(cert))); |
296 if (!token.empty()) { | 300 if (!token.empty()) { |
297 rv += '\n'; | 301 rv += '\n'; |
298 rv += l10n_util::GetStringFUTF8(IDS_CERT_TOKEN_FORMAT, token); | 302 rv += l10n_util::GetStringFUTF8(IDS_CERT_TOKEN_FORMAT, token); |
299 } | 303 } |
300 | 304 |
301 return rv; | 305 return rv; |
302 } | 306 } |
303 | 307 |
| 308 void SSLClientCertificateSelector::Unlocked() { |
| 309 // TODO(mattm): refactor so we don't need to call GetSelectedCert again. |
| 310 net::X509Certificate* cert = GetSelectedCert(); |
| 311 delegate_->CertificateSelected(cert); |
| 312 delegate_ = NULL; |
| 313 DCHECK(window_); |
| 314 window_->CloseConstrainedWindow(); |
| 315 } |
| 316 |
304 void SSLClientCertificateSelector::OnComboBoxChanged(GtkWidget* combo_box) { | 317 void SSLClientCertificateSelector::OnComboBoxChanged(GtkWidget* combo_box) { |
305 int selected = gtk_combo_box_get_active( | 318 int selected = gtk_combo_box_get_active( |
306 GTK_COMBO_BOX(cert_combo_box_)); | 319 GTK_COMBO_BOX(cert_combo_box_)); |
307 if (selected < 0) | 320 if (selected < 0) |
308 return; | 321 return; |
309 gtk_text_buffer_set_text(cert_details_buffer_, | 322 gtk_text_buffer_set_text(cert_details_buffer_, |
310 details_strings_[selected].c_str(), | 323 details_strings_[selected].c_str(), |
311 details_strings_[selected].size()); | 324 details_strings_[selected].size()); |
312 } | 325 } |
313 | 326 |
314 void SSLClientCertificateSelector::OnViewClicked(GtkWidget* button) { | 327 void SSLClientCertificateSelector::OnViewClicked(GtkWidget* button) { |
315 net::X509Certificate* cert = GetSelectedCert(); | 328 net::X509Certificate* cert = GetSelectedCert(); |
316 if (cert) { | 329 if (cert) { |
317 GtkWidget* toplevel = gtk_widget_get_toplevel(root_widget_.get()); | 330 GtkWidget* toplevel = gtk_widget_get_toplevel(root_widget_.get()); |
318 ShowCertificateViewer(GTK_WINDOW(toplevel), cert); | 331 ShowCertificateViewer(GTK_WINDOW(toplevel), cert); |
319 } | 332 } |
320 } | 333 } |
321 | 334 |
322 void SSLClientCertificateSelector::OnCancelClicked(GtkWidget* button) { | 335 void SSLClientCertificateSelector::OnCancelClicked(GtkWidget* button) { |
323 delegate_->CertificateSelected(NULL); | 336 delegate_->CertificateSelected(NULL); |
324 delegate_ = NULL; | 337 delegate_ = NULL; |
325 DCHECK(window_); | 338 DCHECK(window_); |
326 window_->CloseConstrainedWindow(); | 339 window_->CloseConstrainedWindow(); |
327 } | 340 } |
328 | 341 |
329 void SSLClientCertificateSelector::OnOkClicked(GtkWidget* button) { | 342 void SSLClientCertificateSelector::OnOkClicked(GtkWidget* button) { |
330 net::X509Certificate* cert = GetSelectedCert(); | 343 net::X509Certificate* cert = GetSelectedCert(); |
331 delegate_->CertificateSelected(cert); | 344 |
332 delegate_ = NULL; | 345 browser::UnlockCertSlotIfNecessary( |
333 DCHECK(window_); | 346 cert, |
334 window_->CloseConstrainedWindow(); | 347 browser::kPK11PasswordClientAuth, |
| 348 cert_request_info_->host_and_port, |
| 349 NewCallback(this, &SSLClientCertificateSelector::Unlocked)); |
335 } | 350 } |
336 | 351 |
337 void SSLClientCertificateSelector::OnPromptShown(GtkWidget* widget, | 352 void SSLClientCertificateSelector::OnPromptShown(GtkWidget* widget, |
338 GtkWidget* previous_toplevel) { | 353 GtkWidget* previous_toplevel) { |
339 if (!root_widget_.get() || | 354 if (!root_widget_.get() || |
340 !GTK_WIDGET_TOPLEVEL(gtk_widget_get_toplevel(root_widget_.get()))) | 355 !GTK_WIDGET_TOPLEVEL(gtk_widget_get_toplevel(root_widget_.get()))) |
341 return; | 356 return; |
342 GTK_WIDGET_SET_FLAGS(select_button_, GTK_CAN_DEFAULT); | 357 GTK_WIDGET_SET_FLAGS(select_button_, GTK_CAN_DEFAULT); |
343 gtk_widget_grab_default(select_button_); | 358 gtk_widget_grab_default(select_button_); |
344 gtk_widget_grab_focus(select_button_); | 359 gtk_widget_grab_focus(select_button_); |
345 } | 360 } |
346 | 361 |
347 } // namespace | 362 } // namespace |
348 | 363 |
349 /////////////////////////////////////////////////////////////////////////////// | 364 /////////////////////////////////////////////////////////////////////////////// |
350 // SSLClientAuthHandler platform specific implementation: | 365 // SSLClientAuthHandler platform specific implementation: |
351 | 366 |
352 namespace browser { | 367 namespace browser { |
353 | 368 |
354 void ShowSSLClientCertificateSelector( | 369 void ShowSSLClientCertificateSelector( |
355 TabContents* parent, | 370 TabContents* parent, |
356 net::SSLCertRequestInfo* cert_request_info, | 371 net::SSLCertRequestInfo* cert_request_info, |
357 SSLClientAuthHandler* delegate) { | 372 SSLClientAuthHandler* delegate) { |
358 (new SSLClientCertificateSelector(parent, | 373 (new SSLClientCertificateSelector(parent, |
359 cert_request_info, | 374 cert_request_info, |
360 delegate))->Show(); | 375 delegate))->Show(); |
361 } | 376 } |
362 | 377 |
363 } // namespace browser | 378 } // namespace browser |
OLD | NEW |