From 301d13e7464932720554613443c79d2dea15f73f Mon Sep 17 00:00:00 2001 From: "shess@chromium.org" Date: Tue, 27 Oct 2009 22:35:51 +0000 Subject: [Mac] Prevent using tab context menu after tab closed. JavaScript can close windows while in the event loop processing a right-click menu. This change prevents sending messages to the tab controller after it has been closed. BUG=25462, 25465 TEST=See bug for test.html. TEST=Run test.html, right-click tab, after close all items should be grayed out. TEST=Run test.html, click tab's close button and hold until tab closes. Should not crash on release. Review URL: http://codereview.chromium.org/335048 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30269 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/cocoa/tab_controller.mm | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'chrome') diff --git a/chrome/browser/cocoa/tab_controller.mm b/chrome/browser/cocoa/tab_controller.mm index 94de7cfc..0d05c5c 100644 --- a/chrome/browser/cocoa/tab_controller.mm +++ b/chrome/browser/cocoa/tab_controller.mm @@ -47,6 +47,17 @@ } - (void)dealloc { + // Since the tab can be closed from JavaScript it is possible for + // |contextMenu_| to remain visible after the tab has closed, or for + // |closeButton_| to be tracking the mouse. Make sure neither sends + // us an action after -dealloc. + [closeButton_ setTarget:nil]; + [contextMenu_ setAutoenablesItems:NO]; + for (NSMenuItem* item in [contextMenu_ itemArray]) { + [item setTarget:nil]; + [item setEnabled:NO]; + } + [[NSNotificationCenter defaultCenter] removeObserver:self]; [super dealloc]; } -- cgit v1.1