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" | 9 #include "base/logging.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "chrome/grit/generated_resources.h" | 11 #include "chrome/grit/generated_resources.h" |
12 #include "components/web_modal/popup_manager.h" | |
12 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
14 #include "content/public/browser/client_certificate_delegate.h" | |
13 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
14 #include "net/cert/x509_certificate.h" | 16 #include "net/cert/x509_certificate.h" |
15 #include "net/ssl/ssl_cert_request_info.h" | 17 #include "net/ssl/ssl_cert_request_info.h" |
16 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
17 #include "ui/views/widget/widget.h" | 19 #include "ui/views/widget/widget.h" |
18 | 20 |
19 #if defined(USE_NSS) | 21 #if defined(USE_NSS) |
20 #include "chrome/browser/ui/crypto_module_password_dialog_nss.h" | 22 #include "chrome/browser/ui/crypto_module_password_dialog_nss.h" |
21 #endif | 23 #endif |
22 | 24 |
23 SSLClientCertificateSelector::SSLClientCertificateSelector( | 25 SSLClientCertificateSelector::SSLClientCertificateSelector( |
24 content::WebContents* web_contents, | 26 content::WebContents* web_contents, |
25 const scoped_refptr<net::SSLCertRequestInfo>& cert_request_info, | 27 const scoped_refptr<net::SSLCertRequestInfo>& cert_request_info, |
26 const chrome::SelectCertificateCallback& callback) | 28 scoped_ptr<content::ClientCertificateDelegate> delegate) |
27 : CertificateSelector(cert_request_info->client_certs, web_contents), | 29 : CertificateSelector(cert_request_info->client_certs, web_contents), |
28 SSLClientAuthObserver(web_contents->GetBrowserContext(), | 30 SSLClientAuthObserver(web_contents->GetBrowserContext(), |
29 cert_request_info, | 31 cert_request_info, |
30 callback) { | 32 delegate.Pass()) { |
31 DVLOG(1) << __FUNCTION__; | 33 DVLOG(1) << __FUNCTION__; |
32 } | 34 } |
33 | 35 |
34 SSLClientCertificateSelector::~SSLClientCertificateSelector() { | 36 SSLClientCertificateSelector::~SSLClientCertificateSelector() { |
35 } | 37 } |
36 | 38 |
37 void SSLClientCertificateSelector::Init() { | 39 void SSLClientCertificateSelector::Init() { |
38 StartObserving(); | 40 StartObserving(); |
39 InitWithText(l10n_util::GetStringFUTF16( | 41 InitWithText(l10n_util::GetStringFUTF16( |
40 IDS_CLIENT_CERT_DIALOG_TEXT, | 42 IDS_CLIENT_CERT_DIALOG_TEXT, |
(...skipping 28 matching lines...) Expand all Loading... | |
69 base::Unretained(this), cert)); | 71 base::Unretained(this), cert)); |
70 #else | 72 #else |
71 Unlocked(cert.get()); | 73 Unlocked(cert.get()); |
72 #endif | 74 #endif |
73 return false; // Unlocked() will close the dialog. | 75 return false; // Unlocked() will close the dialog. |
74 } | 76 } |
75 | 77 |
76 return false; | 78 return false; |
77 } | 79 } |
78 | 80 |
81 bool SSLClientCertificateSelector::Close() { | |
82 DVLOG(1) << __FUNCTION__; | |
83 StopObserving(); | |
84 CancelCertificateSelection(); | |
85 return true; | |
86 } | |
87 | |
79 void SSLClientCertificateSelector::Unlocked(net::X509Certificate* cert) { | 88 void SSLClientCertificateSelector::Unlocked(net::X509Certificate* cert) { |
80 DVLOG(1) << __FUNCTION__; | 89 DVLOG(1) << __FUNCTION__; |
81 CertificateSelected(cert); | 90 CertificateSelected(cert); |
82 GetWidget()->Close(); | 91 GetWidget()->Close(); |
83 } | 92 } |
84 | 93 |
85 namespace chrome { | 94 namespace chrome { |
86 | 95 |
87 void ShowSSLClientCertificateSelector( | 96 void ShowSSLClientCertificateSelector( |
88 content::WebContents* contents, | 97 content::WebContents* contents, |
89 net::SSLCertRequestInfo* cert_request_info, | 98 net::SSLCertRequestInfo* cert_request_info, |
90 const chrome::SelectCertificateCallback& callback) { | 99 scoped_ptr<content::ClientCertificateDelegate> delegate) { |
91 DVLOG(1) << __FUNCTION__ << " " << contents; | 100 DVLOG(1) << __FUNCTION__ << " " << contents; |
92 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 101 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
93 SSLClientCertificateSelector* selector = | 102 |
94 new SSLClientCertificateSelector(contents, cert_request_info, callback); | 103 // Not all WebContentses can show modal dialogs. |
104 // | |
105 // TODO(davidben): Move this hook to the WebContentsDelegate and only try to | |
106 // show a dialog in Browser's implementation. https://crbug.com/456255 | |
107 if (web_modal::PopupManager::FromWebContents(contents) == nullptr) { | |
108 delegate->CancelCertificateSelection(); | |
sky
2015/02/20 21:32:29
Same comment about cancel here.
| |
109 return; | |
110 } | |
111 | |
112 SSLClientCertificateSelector* selector = new SSLClientCertificateSelector( | |
113 contents, cert_request_info, delegate.Pass()); | |
95 selector->Init(); | 114 selector->Init(); |
96 selector->Show(); | 115 selector->Show(); |
97 } | 116 } |
98 | 117 |
99 } // namespace chrome | 118 } // namespace chrome |
OLD | NEW |