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

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

Issue 2375903002: Emit OnNativeWidgetDestroying() before clearing the NSWindowDelegate. (Closed)
Patch Set: Created 4 years, 3 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
Index: ui/views/cocoa/bridged_native_widget.mm
diff --git a/ui/views/cocoa/bridged_native_widget.mm b/ui/views/cocoa/bridged_native_widget.mm
index b0ab01429cdce334feb89a25766c3dd61b38532a..f2ed000a4b5cec36f6f3552a06262888752be29c 100644
--- a/ui/views/cocoa/bridged_native_widget.mm
+++ b/ui/views/cocoa/bridged_native_widget.mm
@@ -342,39 +342,23 @@ NSComparisonResult SubviewSorter(NSViewComparatorValue lhs,
}
BridgedNativeWidget::~BridgedNativeWidget() {
- bool close_window = false;
- if ([window_ delegate]) {
- // If the delegate is still set on a modal dialog, it means it was not
- // closed via [NSApplication endSheet:]. This is probably OK if the widget
- // was never shown. But Cocoa ignores close() calls on open sheets. Calling
- // endSheet: here would work, but it messes up assumptions elsewhere. E.g.
- // DialogClientView assumes its delegate is alive when closing, which isn't
- // true after endSheet: synchronously calls OnNativeWidgetDestroyed().
- // So ban it. Modal dialogs should be closed via Widget::Close().
- DCHECK(!native_widget_mac_->IsWindowModalSheet());
-
- // If the delegate is still set, it means OnWindowWillClose() has not been
- // called and the window is still open. Usually, -[NSWindow close] would
- // synchronously call OnWindowWillClose() which removes the delegate and
- // notifies NativeWidgetMac, which then calls this with a nil delegate.
- // For other teardown flows (e.g. Widget::WIDGET_OWNS_NATIVE_WIDGET or
- // Widget::CloseNow()) the delegate must first be cleared to avoid AppKit
- // calling back into the bridge. This means OnWindowWillClose() needs to be
- // invoked manually, which is done below.
- // Note that if the window has children it can't be closed until the
- // children are gone, but removing child windows calls into AppKit for the
- // parent window, so the delegate must be cleared first.
- [window_ setDelegate:nil];
- close_window = true;
- }
+ // If the delegate is still set on a modal dialog, it means it was not
+ // closed via [NSApplication endSheet:]. This is probably OK if the widget
+ // was never shown. But Cocoa ignores close() calls on open sheets. Calling
+ // endSheet: here would work, but it messes up assumptions elsewhere. E.g.
+ // DialogClientView assumes its delegate is alive when closing, which isn't
+ // true after endSheet: synchronously calls OnNativeWidgetDestroyed().
+ // So ban it. Modal dialogs should be closed via Widget::Close().
+ DCHECK(!close_window_ || !native_widget_mac_->IsWindowModalSheet());
+ [window_ setDelegate:nil];
RemoveOrDestroyChildren();
DCHECK(child_windows_.empty());
SetFocusManager(nullptr);
SetRootView(nullptr);
DestroyCompositor();
- if (close_window) {
+ if (close_window_) {
OnWindowWillClose();
[window_ close];
}
@@ -707,7 +691,7 @@ NSComparisonResult SubviewSorter(NSViewComparatorValue lhs,
parent_->RemoveChildWindow(this);
parent_ = nullptr;
}
- [window_ setDelegate:nil];
+ close_window_ = false;
[[NSNotificationCenter defaultCenter] removeObserver:window_delegate_];
native_widget_mac_->OnWindowWillClose();
tapted 2016/10/05 08:38:18 Is the problem just that NativeWidgetMac::OnWindow
}

Powered by Google App Engine
This is Rietveld 408576698