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