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

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

Issue 1978883002: In dialogs & dialog-like bubbles, make the escape button just close the prompt. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2704
Patch Set: Created 4 years, 7 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
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/ssl_client_certificate_selector.h" 5 #include "chrome/browser/ui/views/ssl_client_certificate_selector.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 13 matching lines...) Expand all
24 #include "chrome/browser/ui/crypto_module_password_dialog_nss.h" 24 #include "chrome/browser/ui/crypto_module_password_dialog_nss.h"
25 #endif 25 #endif
26 26
27 SSLClientCertificateSelector::SSLClientCertificateSelector( 27 SSLClientCertificateSelector::SSLClientCertificateSelector(
28 content::WebContents* web_contents, 28 content::WebContents* web_contents,
29 const scoped_refptr<net::SSLCertRequestInfo>& cert_request_info, 29 const scoped_refptr<net::SSLCertRequestInfo>& cert_request_info,
30 std::unique_ptr<content::ClientCertificateDelegate> delegate) 30 std::unique_ptr<content::ClientCertificateDelegate> delegate)
31 : CertificateSelector(cert_request_info->client_certs, web_contents), 31 : CertificateSelector(cert_request_info->client_certs, web_contents),
32 SSLClientAuthObserver(web_contents->GetBrowserContext(), 32 SSLClientAuthObserver(web_contents->GetBrowserContext(),
33 cert_request_info, 33 cert_request_info,
34 std::move(delegate)) {} 34 std::move(delegate)),
35 WebContentsObserver(web_contents) {}
35 36
36 SSLClientCertificateSelector::~SSLClientCertificateSelector() { 37 SSLClientCertificateSelector::~SSLClientCertificateSelector() {}
37 }
38 38
39 void SSLClientCertificateSelector::Init() { 39 void SSLClientCertificateSelector::Init() {
40 StartObserving(); 40 StartObserving();
41 std::unique_ptr<views::Label> text_label( 41 std::unique_ptr<views::Label> text_label(
42 new views::Label(l10n_util::GetStringFUTF16( 42 new views::Label(l10n_util::GetStringFUTF16(
43 IDS_CLIENT_CERT_DIALOG_TEXT, 43 IDS_CLIENT_CERT_DIALOG_TEXT,
44 base::ASCIIToUTF16(cert_request_info()->host_and_port.ToString())))); 44 base::ASCIIToUTF16(cert_request_info()->host_and_port.ToString()))));
45 text_label->SetMultiLine(true); 45 text_label->SetMultiLine(true);
46 text_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 46 text_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
47 text_label->SetAllowCharacterBreak(true); 47 text_label->SetAllowCharacterBreak(true);
48 text_label->SizeToFit(kTableViewWidth); 48 text_label->SizeToFit(kTableViewWidth);
49 InitWithText(std::move(text_label)); 49 InitWithText(std::move(text_label));
50 } 50 }
51 51
52 void SSLClientCertificateSelector::OnCertSelectedByNotification() { 52 void SSLClientCertificateSelector::OnCertSelectedByNotification() {
53 GetWidget()->Close(); 53 GetWidget()->Close();
54 } 54 }
55 55
56 bool SSLClientCertificateSelector::Cancel() { 56 void SSLClientCertificateSelector::DeleteDelegate() {
57 // This is here and not in Cancel() to give WebContentsDestroyed a chance
58 // to abort instead of proceeding with a null certificate. (This will be
59 // ignored if there was a previous call to CertificateSelected or
60 // CancelCertificateSelection.)
57 CertificateSelected(nullptr); 61 CertificateSelected(nullptr);
58 return true; 62 chrome::CertificateSelector::DeleteDelegate();
59 } 63 }
60 64
61 bool SSLClientCertificateSelector::Accept() { 65 bool SSLClientCertificateSelector::Accept() {
62 scoped_refptr<net::X509Certificate> cert = GetSelectedCert(); 66 scoped_refptr<net::X509Certificate> cert = GetSelectedCert();
63 if (cert.get()) { 67 if (cert.get()) {
64 // Remove the observer before we try unlocking, otherwise we might act on a 68 // Remove the observer before we try unlocking, otherwise we might act on a
65 // notification while waiting for the unlock dialog, causing us to delete 69 // notification while waiting for the unlock dialog, causing us to delete
66 // ourself before the Unlocked callback gets called. 70 // ourself before the Unlocked callback gets called.
67 StopObserving(); 71 StopObserving();
68 #if defined(USE_NSS_CERTS) && !defined(OS_CHROMEOS) 72 #if defined(USE_NSS_CERTS) && !defined(OS_CHROMEOS)
69 chrome::UnlockCertSlotIfNecessary( 73 chrome::UnlockCertSlotIfNecessary(
70 cert.get(), chrome::kCryptoModulePasswordClientAuth, 74 cert.get(), chrome::kCryptoModulePasswordClientAuth,
71 cert_request_info()->host_and_port, GetWidget()->GetNativeView(), 75 cert_request_info()->host_and_port, GetWidget()->GetNativeView(),
72 base::Bind(&SSLClientCertificateSelector::Unlocked, 76 base::Bind(&SSLClientCertificateSelector::Unlocked,
73 base::Unretained(this), base::RetainedRef(cert))); 77 base::Unretained(this), base::RetainedRef(cert)));
74 #else 78 #else
75 Unlocked(cert.get()); 79 Unlocked(cert.get());
76 #endif 80 #endif
77 return false; // Unlocked() will close the dialog. 81 return false; // Unlocked() will close the dialog.
78 } 82 }
79 83
80 return false; 84 return false;
81 } 85 }
82 86
83 bool SSLClientCertificateSelector::Close() { 87 void SSLClientCertificateSelector::WebContentsDestroyed() {
84 // By default, closing the dialog calls the Cancel method. However, selecting 88 // If the dialog is closed by closing the containing tab, abort the request.
85 // cancel in the UI currently continues the request with no certificate,
86 // remembering the selection. If the dialog is closed by closing the
87 // containing tab, the request should abort.
88 CancelCertificateSelection(); 89 CancelCertificateSelection();
89 return true;
90 } 90 }
91 91
92 void SSLClientCertificateSelector::Unlocked(net::X509Certificate* cert) { 92 void SSLClientCertificateSelector::Unlocked(net::X509Certificate* cert) {
93 CertificateSelected(cert); 93 CertificateSelected(cert);
94 GetWidget()->Close(); 94 GetWidget()->Close();
95 } 95 }
96 96
97 namespace chrome { 97 namespace chrome {
98 98
99 void ShowSSLClientCertificateSelector( 99 void ShowSSLClientCertificateSelector(
100 content::WebContents* contents, 100 content::WebContents* contents,
101 net::SSLCertRequestInfo* cert_request_info, 101 net::SSLCertRequestInfo* cert_request_info,
102 std::unique_ptr<content::ClientCertificateDelegate> delegate) { 102 std::unique_ptr<content::ClientCertificateDelegate> delegate) {
103 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 103 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
104 104
105 // Not all WebContentses can show modal dialogs. 105 // Not all WebContentses can show modal dialogs.
106 // 106 //
107 // TODO(davidben): Move this hook to the WebContentsDelegate and only try to 107 // TODO(davidben): Move this hook to the WebContentsDelegate and only try to
108 // show a dialog in Browser's implementation. https://crbug.com/456255 108 // show a dialog in Browser's implementation. https://crbug.com/456255
109 if (!SSLClientCertificateSelector::CanShow(contents)) 109 if (!SSLClientCertificateSelector::CanShow(contents))
110 return; 110 return;
111 111
112 SSLClientCertificateSelector* selector = new SSLClientCertificateSelector( 112 SSLClientCertificateSelector* selector = new SSLClientCertificateSelector(
113 contents, cert_request_info, std::move(delegate)); 113 contents, cert_request_info, std::move(delegate));
114 selector->Init(); 114 selector->Init();
115 selector->Show(); 115 selector->Show();
116 } 116 }
117 117
118 } // namespace chrome 118 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698