From 1a86b2d55dd1c11146b28fdfa895293df75fa819 Mon Sep 17 00:00:00 2001 From: "jst%mozilla.jstenback.com" Date: Tue, 14 Sep 2004 06:03:34 +0000 Subject: [PATCH] Fixing bug 259117. Prevent popups when closing a window even if the close came from a user action that would normally enable popups. r=bzbarsky@mit.edu, sr=brendan@mozilla.org --- docshell/base/nsDocShell.cpp | 8 ++------ dom/src/base/nsGlobalWindow.cpp | 20 ++++++++++++++++++-- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 3734ef6e4099..8be60bcf3e5f 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -3129,11 +3129,11 @@ nsDocShell::Create() NS_IMETHODIMP nsDocShell::Destroy() { + mIsBeingDestroyed = PR_TRUE; + //Fire unload event before we blow anything away. (void) FireUnloadNotification(); - mIsBeingDestroyed = PR_TRUE; - // Stop any URLs that are currently being loaded... Stop(nsIWebNavigation::STOP_ALL); if (mDocLoader) { @@ -3771,10 +3771,6 @@ nsDocShell::ScrollByPages(PRInt32 numPages) nsIScriptGlobalObject* nsDocShell::GetScriptGlobalObject() { - if (mIsBeingDestroyed) { - return nsnull; - } - NS_ENSURE_SUCCESS(EnsureScriptEnvironment(), nsnull); return mScriptGlobal; diff --git a/dom/src/base/nsGlobalWindow.cpp b/dom/src/base/nsGlobalWindow.cpp index c36278401baf..ce2e878dd375 100644 --- a/dom/src/base/nsGlobalWindow.cpp +++ b/dom/src/base/nsGlobalWindow.cpp @@ -2958,6 +2958,7 @@ PopupControlState GlobalWindowImpl::CheckForAbusePoint() { nsCOMPtr item(do_QueryInterface(mDocShell)); + PRBool isBeingDestroyed = PR_FALSE; if (item) { PRInt32 type = nsIDocShellTreeItem::typeChrome; @@ -2965,11 +2966,26 @@ GlobalWindowImpl::CheckForAbusePoint() item->GetItemType(&type); if (type != nsIDocShellTreeItem::typeContent) return openAllowed; + + while (item) { + nsCOMPtr docShell(do_QueryInterface(item)); + + docShell->IsBeingDestroyed(&isBeingDestroyed); + + if (isBeingDestroyed) { + break; + } + + nsIDocShellTreeItem *tmp = item; + tmp->GetParent(getter_AddRefs(item)); + } } // level of abuse we've detected, initialized to the current popup - // state - PopupControlState abuse = gPopupControlState; + // state, except in the case where this window is being destroyed + // since then we override the current state and prevent popups + // alltogether. + PopupControlState abuse = isBeingDestroyed ? openAbused : gPopupControlState; // limit the number of simultaneously open popups if (abuse == openAbused || abuse == openControlled) {