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 #import "chrome/browser/ui/cocoa/ssl_client_certificate_selector_cocoa.h" | 5 #import "chrome/browser/ui/cocoa/ssl_client_certificate_selector_cocoa.h" |
6 | 6 |
7 #import <SecurityInterface/SFChooseIdentityPanel.h> | 7 #import <SecurityInterface/SFChooseIdentityPanel.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <utility> | 10 #include <utility> |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 | 74 |
75 private: | 75 private: |
76 SSLClientCertificateSelectorCocoa* controller_; // weak | 76 SSLClientCertificateSelectorCocoa* controller_; // weak |
77 }; | 77 }; |
78 | 78 |
79 namespace chrome { | 79 namespace chrome { |
80 | 80 |
81 void ShowSSLClientCertificateSelector( | 81 void ShowSSLClientCertificateSelector( |
82 content::WebContents* contents, | 82 content::WebContents* contents, |
83 net::SSLCertRequestInfo* cert_request_info, | 83 net::SSLCertRequestInfo* cert_request_info, |
84 net::CertificateList client_certs, | |
85 std::unique_ptr<content::ClientCertificateDelegate> delegate) { | 84 std::unique_ptr<content::ClientCertificateDelegate> delegate) { |
86 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 85 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
87 | 86 |
88 // Not all WebContentses can show modal dialogs. | 87 // Not all WebContentses can show modal dialogs. |
89 // | 88 // |
90 // Use the top-level embedder if |contents| is a guest. | 89 // Use the top-level embedder if |contents| is a guest. |
91 // GetTopLevelWebContents() will return |contents| otherwise. | 90 // GetTopLevelWebContents() will return |contents| otherwise. |
92 // TODO(davidben): Move this hook to the WebContentsDelegate and only try to | 91 // TODO(davidben): Move this hook to the WebContentsDelegate and only try to |
93 // show a dialog in Browser's implementation. https://crbug.com/456255 | 92 // show a dialog in Browser's implementation. https://crbug.com/456255 |
94 if (web_modal::WebContentsModalDialogManager::FromWebContents( | 93 if (web_modal::WebContentsModalDialogManager::FromWebContents( |
95 guest_view::GuestViewBase::GetTopLevelWebContents(contents)) == | 94 guest_view::GuestViewBase::GetTopLevelWebContents(contents)) == |
96 nullptr) | 95 nullptr) |
97 return; | 96 return; |
98 | 97 |
99 // The dialog manages its own lifetime. | 98 // The dialog manages its own lifetime. |
100 SSLClientCertificateSelectorCocoa* selector = | 99 SSLClientCertificateSelectorCocoa* selector = |
101 [[SSLClientCertificateSelectorCocoa alloc] | 100 [[SSLClientCertificateSelectorCocoa alloc] |
102 initWithBrowserContext:contents->GetBrowserContext() | 101 initWithBrowserContext:contents->GetBrowserContext() |
103 certRequestInfo:cert_request_info | 102 certRequestInfo:cert_request_info |
104 delegate:std::move(delegate)]; | 103 delegate:std::move(delegate)]; |
105 [selector displayForWebContents:contents clientCerts:std::move(client_certs)]; | 104 [selector displayForWebContents:contents]; |
106 } | 105 } |
107 | 106 |
108 } // namespace chrome | 107 } // namespace chrome |
109 | 108 |
110 namespace { | 109 namespace { |
111 | 110 |
112 // These ClearTableViewDataSources... functions help work around a bug in macOS | 111 // These ClearTableViewDataSources... functions help work around a bug in macOS |
113 // 10.12 where SFChooseIdentityPanel leaks a window and some views, including | 112 // 10.12 where SFChooseIdentityPanel leaks a window and some views, including |
114 // an NSTableView. Future events may make cause the table view to query its | 113 // an NSTableView. Future events may make cause the table view to query its |
115 // dataSource, which will have been deallocated. | 114 // dataSource, which will have been deallocated. |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 // already to cancel the selection rather than continue with no | 195 // already to cancel the selection rather than continue with no |
197 // certificate. Otherwise, tell the backend which identity (or none) the | 196 // certificate. Otherwise, tell the backend which identity (or none) the |
198 // user selected. | 197 // user selected. |
199 userResponded_ = YES; | 198 userResponded_ = YES; |
200 observer_->CertificateSelected(cert); | 199 observer_->CertificateSelected(cert); |
201 | 200 |
202 constrainedWindow_->CloseWebContentsModalDialog(); | 201 constrainedWindow_->CloseWebContentsModalDialog(); |
203 } | 202 } |
204 } | 203 } |
205 | 204 |
206 - (void)displayForWebContents:(content::WebContents*)webContents | 205 - (void)displayForWebContents:(content::WebContents*)webContents { |
207 clientCerts:(net::CertificateList)inputClientCerts { | |
208 // Create an array of CFIdentityRefs for the certificates: | 206 // Create an array of CFIdentityRefs for the certificates: |
209 size_t numCerts = inputClientCerts.size(); | 207 size_t numCerts = observer_->cert_request_info()->client_certs.size(); |
210 identities_.reset(CFArrayCreateMutable( | 208 identities_.reset(CFArrayCreateMutable( |
211 kCFAllocatorDefault, numCerts, &kCFTypeArrayCallBacks)); | 209 kCFAllocatorDefault, numCerts, &kCFTypeArrayCallBacks)); |
212 for (size_t i = 0; i < numCerts; ++i) { | 210 for (size_t i = 0; i < numCerts; ++i) { |
213 base::ScopedCFTypeRef<SecCertificateRef> cert( | 211 base::ScopedCFTypeRef<SecCertificateRef> cert( |
214 net::x509_util::CreateSecCertificateFromX509Certificate( | 212 net::x509_util::CreateSecCertificateFromX509Certificate( |
215 inputClientCerts[i].get())); | 213 observer_->cert_request_info()->client_certs[i].get())); |
216 if (!cert) | 214 if (!cert) |
217 continue; | 215 continue; |
218 SecIdentityRef identity; | 216 SecIdentityRef identity; |
219 if (SecIdentityCreateWithCertificate(NULL, cert, &identity) == noErr) { | 217 if (SecIdentityCreateWithCertificate(NULL, cert, &identity) == noErr) { |
220 CFArrayAppendValue(identities_, identity); | 218 CFArrayAppendValue(identities_, identity); |
221 CFRelease(identity); | 219 CFRelease(identity); |
222 certificates_.push_back(inputClientCerts[i]); | 220 certificates_.push_back(observer_->cert_request_info()->client_certs[i]); |
223 } | 221 } |
224 } | 222 } |
225 | 223 |
226 // Get the message to display: | 224 // Get the message to display: |
227 NSString* message = l10n_util::GetNSStringF( | 225 NSString* message = l10n_util::GetNSStringF( |
228 IDS_CLIENT_CERT_DIALOG_TEXT, | 226 IDS_CLIENT_CERT_DIALOG_TEXT, |
229 base::ASCIIToUTF16( | 227 base::ASCIIToUTF16( |
230 observer_->cert_request_info()->host_and_port.ToString())); | 228 observer_->cert_request_info()->host_and_port.ToString())); |
231 | 229 |
232 // Create and set up a system choose-identity panel. | 230 // Create and set up a system choose-identity panel. |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 } | 320 } |
323 | 321 |
324 - (void)onConstrainedWindowClosed { | 322 - (void)onConstrainedWindowClosed { |
325 observer_->StopObserving(); | 323 observer_->StopObserving(); |
326 panel_.reset(); | 324 panel_.reset(); |
327 constrainedWindow_.reset(); | 325 constrainedWindow_.reset(); |
328 [self release]; | 326 [self release]; |
329 } | 327 } |
330 | 328 |
331 @end | 329 @end |
OLD | NEW |