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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "ui/views/cocoa/widget_owner_nswindow_adapter.h" 5 #import "ui/views/cocoa/widget_owner_nswindow_adapter.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/mac/sdk_forward_declarations.h" 10 #include "base/mac/sdk_forward_declarations.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 DCHECK(anchor_window_); 55 DCHECK(anchor_window_);
56 56
57 [[NSNotificationCenter defaultCenter] 57 [[NSNotificationCenter defaultCenter]
58 addObserver:observer_bridge_ 58 addObserver:observer_bridge_
59 selector:@selector(windowWillClose:) 59 selector:@selector(windowWillClose:)
60 name:NSWindowWillCloseNotification 60 name:NSWindowWillCloseNotification
61 object:anchor_window_]; 61 object:anchor_window_];
62 } 62 }
63 63
64 void WidgetOwnerNSWindowAdapter::OnWindowWillClose() { 64 void WidgetOwnerNSWindowAdapter::OnWindowWillClose() {
65 [child_->ns_window() close]; 65 // Retain the child window before closing it. If the last reference to the
66 // NSWindow goes away inside -[NSWindow close], then bad stuff can happen.
67 // See e.g. http://crbug.com/616701.
68 base::scoped_nsobject<NSWindow> child_window(child_->ns_window(),
69 base::scoped_policy::RETAIN);
70
71 // AppKit child window relationships break when the windows are not visible,
72 // so if the child is not visible, it won't currently be a child.
73 DCHECK(![child_window isVisible] || [child_window parentWindow]);
74 DCHECK([child_window delegate]);
75
76 [child_window close];
66 // Note: |this| will be deleted here. 77 // Note: |this| will be deleted here.
78
79 DCHECK(![child_window parentWindow]);
80 DCHECK(![child_window delegate]);
67 } 81 }
68 82
69 NSWindow* WidgetOwnerNSWindowAdapter::GetNSWindow() { 83 NSWindow* WidgetOwnerNSWindowAdapter::GetNSWindow() {
70 return anchor_window_; 84 return anchor_window_;
71 } 85 }
72 86
73 gfx::Vector2d WidgetOwnerNSWindowAdapter::GetChildWindowOffset() const { 87 gfx::Vector2d WidgetOwnerNSWindowAdapter::GetChildWindowOffset() const {
74 NSRect rect_in_window = 88 NSRect rect_in_window =
75 [anchor_view_ convertRect:[anchor_view_ bounds] toView:nil]; 89 [anchor_view_ convertRect:[anchor_view_ bounds] toView:nil];
76 NSRect rect_in_screen = [anchor_window_ convertRectToScreen:rect_in_window]; 90 NSRect rect_in_screen = [anchor_window_ convertRectToScreen:rect_in_window];
(...skipping 12 matching lines...) Expand all
89 DCHECK_EQ(child, child_); 103 DCHECK_EQ(child, child_);
90 [GetNSWindow() removeChildWindow:child->ns_window()]; 104 [GetNSWindow() removeChildWindow:child->ns_window()];
91 delete this; 105 delete this;
92 } 106 }
93 107
94 WidgetOwnerNSWindowAdapter::~WidgetOwnerNSWindowAdapter() { 108 WidgetOwnerNSWindowAdapter::~WidgetOwnerNSWindowAdapter() {
95 [[NSNotificationCenter defaultCenter] removeObserver:observer_bridge_]; 109 [[NSNotificationCenter defaultCenter] removeObserver:observer_bridge_];
96 } 110 }
97 111
98 } // namespace views 112 } // namespace views
OLDNEW
« 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