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

Unified Diff: ui/views/cocoa/widget_owner_nswindow_adapter.mm

Issue 2056593002: Mac: Retain the child NSWindow in WidgetOwnerNSWindowAdapter before invoking close (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refine DCHECK Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/cocoa/native_widget_mac_nswindow.mm ('k') | ui/views/widget/native_widget_mac_unittest.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/cocoa/widget_owner_nswindow_adapter.mm
diff --git a/ui/views/cocoa/widget_owner_nswindow_adapter.mm b/ui/views/cocoa/widget_owner_nswindow_adapter.mm
index d85184ef5a445c422789135afb400eed06c1aed7..63cc4468d95449b86bbb6a2a2a8ab06cf9dd2c54 100644
--- a/ui/views/cocoa/widget_owner_nswindow_adapter.mm
+++ b/ui/views/cocoa/widget_owner_nswindow_adapter.mm
@@ -62,8 +62,22 @@ WidgetOwnerNSWindowAdapter::WidgetOwnerNSWindowAdapter(
}
void WidgetOwnerNSWindowAdapter::OnWindowWillClose() {
- [child_->ns_window() close];
+ // Retain the child window before closing it. If the last reference to the
+ // NSWindow goes away inside -[NSWindow close], then bad stuff can happen.
+ // See e.g. http://crbug.com/616701.
+ base::scoped_nsobject<NSWindow> child_window(child_->ns_window(),
+ base::scoped_policy::RETAIN);
+
+ // AppKit child window relationships break when the windows are not visible,
+ // so if the child is not visible, it won't currently be a child.
+ DCHECK(![child_window isVisible] || [child_window parentWindow]);
+ DCHECK([child_window delegate]);
+
+ [child_window close];
// Note: |this| will be deleted here.
+
+ DCHECK(![child_window parentWindow]);
+ DCHECK(![child_window delegate]);
}
NSWindow* WidgetOwnerNSWindowAdapter::GetNSWindow() {
« no previous file with comments | « ui/views/cocoa/native_widget_mac_nswindow.mm ('k') | ui/views/widget/native_widget_mac_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698