| 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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 SSLClientCertificateSelectorCocoa* selector = | 98 SSLClientCertificateSelectorCocoa* selector = |
| 99 [[SSLClientCertificateSelectorCocoa alloc] | 99 [[SSLClientCertificateSelectorCocoa alloc] |
| 100 initWithBrowserContext:contents->GetBrowserContext() | 100 initWithBrowserContext:contents->GetBrowserContext() |
| 101 certRequestInfo:cert_request_info | 101 certRequestInfo:cert_request_info |
| 102 delegate:std::move(delegate)]; | 102 delegate:std::move(delegate)]; |
| 103 [selector displayForWebContents:contents]; | 103 [selector displayForWebContents:contents]; |
| 104 } | 104 } |
| 105 | 105 |
| 106 } // namespace chrome | 106 } // namespace chrome |
| 107 | 107 |
| 108 namespace { |
| 109 |
| 110 // These ClearTableViewDataSources... functions help work around a bug in macOS |
| 111 // 10.12 where SFChooseIdentityPanel leaks a window and some views, including |
| 112 // an NSTableView. Future events may make cause the table view to query its |
| 113 // dataSource, which will have been deallocated. |
| 114 // |
| 115 // NSTableView.dataSource becomes a zeroing weak reference starting in 10.11, |
| 116 // so this workaround can be removed once we're on the 10.11 SDK. |
| 117 // |
| 118 // See https://crbug.com/653093 and rdar://29409207 for more information. |
| 119 |
| 120 #if !defined(MAC_OS_X_VERSION_10_11) || \ |
| 121 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_11 |
| 122 |
| 123 void ClearTableViewDataSources(NSView* view) { |
| 124 if (auto table_view = base::mac::ObjCCast<NSTableView>(view)) { |
| 125 table_view.dataSource = nil; |
| 126 } else { |
| 127 for (NSView* subview in view.subviews) { |
| 128 ClearTableViewDataSources(subview); |
| 129 } |
| 130 } |
| 131 } |
| 132 |
| 133 void ClearTableViewDataSourcesIfWindowStillExists(NSWindow* leaked_window) { |
| 134 for (NSWindow* window in [NSApp windows]) { |
| 135 // If the window is still in the window list... |
| 136 if (window == leaked_window) { |
| 137 // ...search it for table views. |
| 138 ClearTableViewDataSources(window.contentView); |
| 139 break; |
| 140 } |
| 141 } |
| 142 } |
| 143 |
| 144 void ClearTableViewDataSourcesIfNeeded(NSWindow* leaked_window) { |
| 145 // Let the autorelease pool drain before deciding if the window was leaked. |
| 146 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 147 FROM_HERE, base::Bind(ClearTableViewDataSourcesIfWindowStillExists, |
| 148 base::Unretained(leaked_window))); |
| 149 } |
| 150 |
| 151 #else |
| 152 |
| 153 void ClearTableViewDataSourcesIfNeeded(NSWindow*) {} |
| 154 |
| 155 #endif // MAC_OS_X_VERSION_10_11 |
| 156 |
| 157 } // namespace |
| 158 |
| 108 @implementation SSLClientCertificateSelectorCocoa | 159 @implementation SSLClientCertificateSelectorCocoa |
| 109 | 160 |
| 110 - (id)initWithBrowserContext:(const content::BrowserContext*)browserContext | 161 - (id)initWithBrowserContext:(const content::BrowserContext*)browserContext |
| 111 certRequestInfo:(net::SSLCertRequestInfo*)certRequestInfo | 162 certRequestInfo:(net::SSLCertRequestInfo*)certRequestInfo |
| 112 delegate: | 163 delegate: |
| 113 (std::unique_ptr<content::ClientCertificateDelegate>) | 164 (std::unique_ptr<content::ClientCertificateDelegate>) |
| 114 delegate { | 165 delegate { |
| 115 DCHECK(browserContext); | 166 DCHECK(browserContext); |
| 116 DCHECK(certRequestInfo); | 167 DCHECK(certRequestInfo); |
| 117 if ((self = [super init])) { | 168 if ((self = [super init])) { |
| 118 observer_.reset(new SSLClientAuthObserverCocoaBridge( | 169 observer_.reset(new SSLClientAuthObserverCocoaBridge( |
| 119 browserContext, certRequestInfo, std::move(delegate), self)); | 170 browserContext, certRequestInfo, std::move(delegate), self)); |
| 120 } | 171 } |
| 121 return self; | 172 return self; |
| 122 } | 173 } |
| 123 | 174 |
| 124 - (void)sheetDidEnd:(NSWindow*)parent | 175 - (void)sheetDidEnd:(NSWindow*)sheet |
| 125 returnCode:(NSInteger)returnCode | 176 returnCode:(NSInteger)returnCode |
| 126 context:(void*)context { | 177 context:(void*)context { |
| 127 net::X509Certificate* cert = NULL; | 178 net::X509Certificate* cert = NULL; |
| 128 if (returnCode == NSFileHandlingPanelOKButton) { | 179 if (returnCode == NSFileHandlingPanelOKButton) { |
| 129 CFRange range = CFRangeMake(0, CFArrayGetCount(identities_)); | 180 CFRange range = CFRangeMake(0, CFArrayGetCount(identities_)); |
| 130 CFIndex index = | 181 CFIndex index = |
| 131 CFArrayGetFirstIndexOfValue(identities_, range, [panel_ identity]); | 182 CFArrayGetFirstIndexOfValue(identities_, range, [panel_ identity]); |
| 132 if (index != -1) | 183 if (index != -1) |
| 133 cert = certificates_[index].get(); | 184 cert = certificates_[index].get(); |
| 134 else | 185 else |
| 135 NOTREACHED(); | 186 NOTREACHED(); |
| 136 } | 187 } |
| 137 | 188 |
| 189 // See comment at definition; this works around a 10.12 bug. |
| 190 ClearTableViewDataSourcesIfNeeded(sheet); |
| 191 |
| 138 if (!closePending_) { | 192 if (!closePending_) { |
| 139 // If |closePending_| is already set, |closeSheetWithAnimation:| was called | 193 // If |closePending_| is already set, |closeSheetWithAnimation:| was called |
| 140 // already to cancel the selection rather than continue with no | 194 // already to cancel the selection rather than continue with no |
| 141 // certificate. Otherwise, tell the backend which identity (or none) the | 195 // certificate. Otherwise, tell the backend which identity (or none) the |
| 142 // user selected. | 196 // user selected. |
| 143 userResponded_ = YES; | 197 userResponded_ = YES; |
| 144 observer_->CertificateSelected(cert); | 198 observer_->CertificateSelected(cert); |
| 145 | 199 |
| 146 constrainedWindow_->CloseWebContentsModalDialog(); | 200 constrainedWindow_->CloseWebContentsModalDialog(); |
| 147 } | 201 } |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 } | 324 } |
| 271 | 325 |
| 272 - (void)onConstrainedWindowClosed { | 326 - (void)onConstrainedWindowClosed { |
| 273 observer_->StopObserving(); | 327 observer_->StopObserving(); |
| 274 panel_.reset(); | 328 panel_.reset(); |
| 275 constrainedWindow_.reset(); | 329 constrainedWindow_.reset(); |
| 276 [self release]; | 330 [self release]; |
| 277 } | 331 } |
| 278 | 332 |
| 279 @end | 333 @end |
| OLD | NEW |