Chromium Code Reviews| 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 8e47513350dc150013b5a19023ea9e969f42d8e1..64310109fb4bc60b134e91c702c3856b6e0889f1 100644 |
| --- a/ui/views/cocoa/bridged_native_widget.mm |
| +++ b/ui/views/cocoa/bridged_native_widget.mm |
| @@ -353,42 +353,15 @@ BridgedNativeWidget::BridgedNativeWidget(NativeWidgetMac* parent) |
| } |
| 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; |
| - } |
| + // The delegate should be cleared already. Note this enforces the precondition |
| + // that the hosted NSWindow is closed before the destructor is called. |
|
karandeepb
2016/10/18 10:00:29
Technically, the window hasn't closed yet right? W
tapted
2016/10/19 06:20:25
Done.
|
| + DCHECK(![window_ delegate]); |
| RemoveOrDestroyChildren(); |
| DCHECK(child_windows_.empty()); |
| SetFocusManager(nullptr); |
| SetRootView(nullptr); |
| DestroyCompositor(); |
| - |
| - if (close_window) { |
| - OnWindowWillClose(); |
| - [window_ close]; |
| - } |
| } |
| void BridgedNativeWidget::Init(base::scoped_nsobject<NSWindow> window, |
| @@ -706,6 +679,8 @@ void BridgedNativeWidget::SetCursor(NSCursor* cursor) { |
| } |
| void BridgedNativeWidget::OnWindowWillClose() { |
| + native_widget_mac_->GetWidget()->OnNativeWidgetDestroying(); |
| + |
| // Ensure BridgedNativeWidget does not have capture, otherwise |
| // OnMouseCaptureLost() may reference a deleted |native_widget_mac_| when |
| // called via ~CocoaMouseCapture() upon the destruction of |mouse_capture_|. |
| @@ -719,10 +694,9 @@ void BridgedNativeWidget::OnWindowWillClose() { |
| parent_ = nullptr; |
| } |
| [[NSNotificationCenter defaultCenter] removeObserver:window_delegate_]; |
| - // Note this also clears the NSWindow delegate, after informing Widget |
| - // delegates about the closure. NativeWidgetMac then deletes |this| before |
| - // returning. |
| - native_widget_mac_->OnWindowWillClose(); |
| + [window_ setDelegate:nil]; |
| + native_widget_mac_->OnWindowDestroyed(); |
| + // Note: |this| is deleted here. |
| } |
| void BridgedNativeWidget::OnFullscreenTransitionStart( |