| 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/ssl_client_certificate_selector.h" | 5 #include "chrome/browser/ui/views/ssl_client_certificate_selector.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/logging.h" | |
| 10 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 11 #include "chrome/grit/generated_resources.h" | 10 #include "chrome/grit/generated_resources.h" |
| 12 #include "components/web_modal/popup_manager.h" | 11 #include "components/web_modal/popup_manager.h" |
| 13 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
| 14 #include "content/public/browser/client_certificate_delegate.h" | 13 #include "content/public/browser/client_certificate_delegate.h" |
| 15 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
| 16 #include "net/cert/x509_certificate.h" | 15 #include "net/cert/x509_certificate.h" |
| 17 #include "net/ssl/ssl_cert_request_info.h" | 16 #include "net/ssl/ssl_cert_request_info.h" |
| 18 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
| 19 #include "ui/views/widget/widget.h" | 18 #include "ui/views/widget/widget.h" |
| 20 | 19 |
| 21 #if defined(USE_NSS) | 20 #if defined(USE_NSS) |
| 22 #include "chrome/browser/ui/crypto_module_password_dialog_nss.h" | 21 #include "chrome/browser/ui/crypto_module_password_dialog_nss.h" |
| 23 #endif | 22 #endif |
| 24 | 23 |
| 25 SSLClientCertificateSelector::SSLClientCertificateSelector( | 24 SSLClientCertificateSelector::SSLClientCertificateSelector( |
| 26 content::WebContents* web_contents, | 25 content::WebContents* web_contents, |
| 27 const scoped_refptr<net::SSLCertRequestInfo>& cert_request_info, | 26 const scoped_refptr<net::SSLCertRequestInfo>& cert_request_info, |
| 28 scoped_ptr<content::ClientCertificateDelegate> delegate) | 27 scoped_ptr<content::ClientCertificateDelegate> delegate) |
| 29 : CertificateSelector(cert_request_info->client_certs, web_contents), | 28 : CertificateSelector(cert_request_info->client_certs, web_contents), |
| 30 SSLClientAuthObserver(web_contents->GetBrowserContext(), | 29 SSLClientAuthObserver(web_contents->GetBrowserContext(), |
| 31 cert_request_info, | 30 cert_request_info, |
| 32 delegate.Pass()) { | 31 delegate.Pass()) { |
| 33 DVLOG(1) << __FUNCTION__; | |
| 34 } | 32 } |
| 35 | 33 |
| 36 SSLClientCertificateSelector::~SSLClientCertificateSelector() { | 34 SSLClientCertificateSelector::~SSLClientCertificateSelector() { |
| 37 } | 35 } |
| 38 | 36 |
| 39 void SSLClientCertificateSelector::Init() { | 37 void SSLClientCertificateSelector::Init() { |
| 40 StartObserving(); | 38 StartObserving(); |
| 41 InitWithText(l10n_util::GetStringFUTF16( | 39 InitWithText(l10n_util::GetStringFUTF16( |
| 42 IDS_CLIENT_CERT_DIALOG_TEXT, | 40 IDS_CLIENT_CERT_DIALOG_TEXT, |
| 43 base::ASCIIToUTF16(cert_request_info()->host_and_port.ToString()))); | 41 base::ASCIIToUTF16(cert_request_info()->host_and_port.ToString()))); |
| 44 } | 42 } |
| 45 | 43 |
| 46 void SSLClientCertificateSelector::OnCertSelectedByNotification() { | 44 void SSLClientCertificateSelector::OnCertSelectedByNotification() { |
| 47 DVLOG(1) << __FUNCTION__; | |
| 48 GetWidget()->Close(); | 45 GetWidget()->Close(); |
| 49 } | 46 } |
| 50 | 47 |
| 51 bool SSLClientCertificateSelector::Cancel() { | 48 bool SSLClientCertificateSelector::Cancel() { |
| 52 DVLOG(1) << __FUNCTION__; | |
| 53 StopObserving(); | |
| 54 CertificateSelected(nullptr); | 49 CertificateSelected(nullptr); |
| 55 return true; | 50 return true; |
| 56 } | 51 } |
| 57 | 52 |
| 58 bool SSLClientCertificateSelector::Accept() { | 53 bool SSLClientCertificateSelector::Accept() { |
| 59 DVLOG(1) << __FUNCTION__; | |
| 60 scoped_refptr<net::X509Certificate> cert = GetSelectedCert(); | 54 scoped_refptr<net::X509Certificate> cert = GetSelectedCert(); |
| 61 if (cert.get()) { | 55 if (cert.get()) { |
| 62 // Remove the observer before we try unlocking, otherwise we might act on a | 56 // Remove the observer before we try unlocking, otherwise we might act on a |
| 63 // notification while waiting for the unlock dialog, causing us to delete | 57 // notification while waiting for the unlock dialog, causing us to delete |
| 64 // ourself before the Unlocked callback gets called. | 58 // ourself before the Unlocked callback gets called. |
| 65 StopObserving(); | 59 StopObserving(); |
| 66 #if defined(USE_NSS) | 60 #if defined(USE_NSS) |
| 67 chrome::UnlockCertSlotIfNecessary( | 61 chrome::UnlockCertSlotIfNecessary( |
| 68 cert.get(), chrome::kCryptoModulePasswordClientAuth, | 62 cert.get(), chrome::kCryptoModulePasswordClientAuth, |
| 69 cert_request_info()->host_and_port, GetWidget()->GetNativeView(), | 63 cert_request_info()->host_and_port, GetWidget()->GetNativeView(), |
| (...skipping 11 matching lines...) Expand all Loading... |
| 81 bool SSLClientCertificateSelector::Close() { | 75 bool SSLClientCertificateSelector::Close() { |
| 82 // By default, closing the dialog calls the Cancel method. However, selecting | 76 // By default, closing the dialog calls the Cancel method. However, selecting |
| 83 // cancel in the UI currently continues the request with no certificate, | 77 // cancel in the UI currently continues the request with no certificate, |
| 84 // remembering the selection. If the dialog is closed by closing the | 78 // remembering the selection. If the dialog is closed by closing the |
| 85 // containing tab, the request should abort. | 79 // containing tab, the request should abort. |
| 86 CancelCertificateSelection(); | 80 CancelCertificateSelection(); |
| 87 return true; | 81 return true; |
| 88 } | 82 } |
| 89 | 83 |
| 90 void SSLClientCertificateSelector::Unlocked(net::X509Certificate* cert) { | 84 void SSLClientCertificateSelector::Unlocked(net::X509Certificate* cert) { |
| 91 DVLOG(1) << __FUNCTION__; | |
| 92 CertificateSelected(cert); | 85 CertificateSelected(cert); |
| 93 GetWidget()->Close(); | 86 GetWidget()->Close(); |
| 94 } | 87 } |
| 95 | 88 |
| 96 namespace chrome { | 89 namespace chrome { |
| 97 | 90 |
| 98 void ShowSSLClientCertificateSelector( | 91 void ShowSSLClientCertificateSelector( |
| 99 content::WebContents* contents, | 92 content::WebContents* contents, |
| 100 net::SSLCertRequestInfo* cert_request_info, | 93 net::SSLCertRequestInfo* cert_request_info, |
| 101 scoped_ptr<content::ClientCertificateDelegate> delegate) { | 94 scoped_ptr<content::ClientCertificateDelegate> delegate) { |
| 102 DVLOG(1) << __FUNCTION__ << " " << contents; | |
| 103 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 95 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 104 | 96 |
| 105 // Not all WebContentses can show modal dialogs. | 97 // Not all WebContentses can show modal dialogs. |
| 106 // | 98 // |
| 107 // TODO(davidben): Move this hook to the WebContentsDelegate and only try to | 99 // TODO(davidben): Move this hook to the WebContentsDelegate and only try to |
| 108 // show a dialog in Browser's implementation. https://crbug.com/456255 | 100 // show a dialog in Browser's implementation. https://crbug.com/456255 |
| 109 if (web_modal::PopupManager::FromWebContents(contents) == nullptr) | 101 if (web_modal::PopupManager::FromWebContents(contents) == nullptr) |
| 110 return; | 102 return; |
| 111 | 103 |
| 112 SSLClientCertificateSelector* selector = new SSLClientCertificateSelector( | 104 SSLClientCertificateSelector* selector = new SSLClientCertificateSelector( |
| 113 contents, cert_request_info, delegate.Pass()); | 105 contents, cert_request_info, delegate.Pass()); |
| 114 selector->Init(); | 106 selector->Init(); |
| 115 selector->Show(); | 107 selector->Show(); |
| 116 } | 108 } |
| 117 | 109 |
| 118 } // namespace chrome | 110 } // namespace chrome |
| OLD | NEW |