From 7c0d9cb3bae28fb0c91a25076b4aec4413ea4c44 Mon Sep 17 00:00:00 2001 From: "feldstein@chromium.org" Date: Fri, 22 Jan 2010 22:08:51 +0000 Subject: Fix js alert crasher when window is closed by js There was a problem with pages that call window.close() then immediately open a js alert. The problem was that the TabContents would get destroyed, but the alert would stick around, and when you closed the alert, it would try to call back to the tab contents' js, crashing chrome. The other OSs got around this by closing the alert immediately, but mac didn't implement the CloseModalDialog method. This CL implements that. BUG=29580 TEST=Run the html attached to the bug Review URL: http://codereview.chromium.org/549126 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@36908 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/app_modal_dialog_mac.mm | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'chrome/browser/app_modal_dialog_mac.mm') diff --git a/chrome/browser/app_modal_dialog_mac.mm b/chrome/browser/app_modal_dialog_mac.mm index c0343be..3b64a87 100644 --- a/chrome/browser/app_modal_dialog_mac.mm +++ b/chrome/browser/app_modal_dialog_mac.mm @@ -70,6 +70,13 @@ bridge->OnCancel(); break; } + case NSRunStoppedResponse: { // Window was closed underneath us + // Need to call OnCancel() because there is some cleanup that needs + // to be done. It won't call back to the javascript since the + // AppModalDialog knows that the TabContents was destroyed. + bridge->OnCancel(); + break; + } default: { NOTREACHED(); } @@ -117,6 +124,7 @@ void AppModalDialog::CreateAndShowDialog() { // Show the modal dialog. NSAlert* alert = [helper alert]; + dialog_ = alert; NSTextField* field = nil; if (text_field) { field = [helper textField]; @@ -149,7 +157,10 @@ void AppModalDialog::ActivateModalDialog() { } void AppModalDialog::CloseModalDialog() { - NOTIMPLEMENTED(); + NSAlert* alert = dialog_; + DCHECK([alert isKindOfClass:[NSAlert class]]); + [NSApp endSheet:[alert window]]; + dialog_ = nil; } int AppModalDialog::GetDialogButtons() { -- cgit v1.1