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

Unified Diff: chrome/browser/ui/cocoa/ssl_client_certificate_selector_cocoa.mm

Issue 2532203005: Work around an AppKit bug that can crash Chrome after using the client certificate prompt. (Closed)
Patch Set: Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/cocoa/ssl_client_certificate_selector_cocoa.mm
diff --git a/chrome/browser/ui/cocoa/ssl_client_certificate_selector_cocoa.mm b/chrome/browser/ui/cocoa/ssl_client_certificate_selector_cocoa.mm
index f16a443928269edbd24b319ef9babfb8ae166dbd..07440ae2d370b0d45568fabc9cfcff11b62675fa 100644
--- a/chrome/browser/ui/cocoa/ssl_client_certificate_selector_cocoa.mm
+++ b/chrome/browser/ui/cocoa/ssl_client_certificate_selector_cocoa.mm
@@ -105,6 +105,43 @@ void ShowSSLClientCertificateSelector(
} // namespace chrome
+namespace {
+
+// These ClearTableViewDataSources... functions help work around a bug in macOS
+// 10.12 where SFChooseIdentityPanel leaks a window and some views, including
+// an NSTableView. Future events may make cause the table view to query its
+// dataSource, which will have been deallocated.
+//
+// NSTableView.dataSource becomes a zeroing weak reference starting in 10.11,
Robert Sesek 2016/11/29 21:31:36 Use the availability macros to only do this work i
Sidney San Martín 2016/11/29 22:55:07 Done.
+// so this workaround can be removed once we're on the 10.11 SDK.
+//
+// rdar://29409207
+// BUG=653093
Robert Sesek 2016/11/29 21:31:35 Make this a https://crbug.com/ URL please. (Could
Sidney San Martín 2016/11/29 22:55:07 Done.
+
+void ClearTableViewDataSources(NSView* view){
+ if (auto tableView = base::mac::ObjCCast<NSTableView>(view)) {
Robert Sesek 2016/11/29 21:31:35 naming: table_view
Sidney San Martín 2016/11/29 22:55:07 Done.
+ tableView.dataSource = nil;
+ } else {
+ for (NSView* subview in view.subviews) {
+ ClearTableViewDataSources(subview);
+ }
+ }
+}
+
+void ClearTableViewDataSourcesIfWindowStillAround(
+ __unsafe_unretained NSWindow* leakedWindow) {
Robert Sesek 2016/11/29 21:31:35 naming: leaked_window
Robert Sesek 2016/11/29 21:31:35 Is the __unsafe_unretained so the block doesn't gr
Sidney San Martín 2016/11/29 22:55:07 Done.
Sidney San Martín 2016/11/29 22:55:07 That's the idea. Without ARC it's a noop, but I th
Robert Sesek 2016/11/30 00:23:32 I don't think this is a practice we currently foll
Sidney San Martín 2016/11/30 04:19:50 That's fair — and base::Unretained also gets that
+ dispatch_async(dispatch_get_main_queue(), ^{
Robert Sesek 2016/11/29 21:31:35 Why does this need to be done in dispatch_async()?
Sidney San Martín 2016/11/29 22:55:07 At the call site, the window is still in an autore
Robert Sesek 2016/11/30 00:23:32 It's Chrome's task posting system. You can use it
Sidney San Martín 2016/11/30 04:19:50 Done (mostly). If I get what you're saying, then m
Robert Sesek 2016/11/30 16:24:48 It is, but what you did is fine as well.
+ for (NSWindow* window : [NSApp windows]) {
+ if (window == leakedWindow) {
+ ClearTableViewDataSources(window.contentView);
+ break;
+ }
+ }
+ });
+}
+
+} // namespace
+
@implementation SSLClientCertificateSelectorCocoa
- (id)initWithBrowserContext:(const content::BrowserContext*)browserContext
@@ -121,7 +158,7 @@ void ShowSSLClientCertificateSelector(
return self;
}
-- (void)sheetDidEnd:(NSWindow*)parent
+- (void)sheetDidEnd:(NSWindow*)sheet
returnCode:(NSInteger)returnCode
context:(void*)context {
net::X509Certificate* cert = NULL;
@@ -135,6 +172,9 @@ void ShowSSLClientCertificateSelector(
NOTREACHED();
}
+ // See comment at definition; this works around a 10.12 bug.
+ ClearTableViewDataSourcesIfWindowStillAround(sheet);
+
if (!closePending_) {
// If |closePending_| is already set, |closeSheetWithAnimation:| was called
// already to cancel the selection rather than continue with no
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698