From dd01342a2405981ee10529565a0e0e35c69f4dfe Mon Sep 17 00:00:00 2001 From: "jst%netscape.com" Date: Thu, 29 May 2003 00:48:35 +0000 Subject: [PATCH] Fixing bug 205474. Making window.open() (and other ways to target things into existing windows) not reuse already closed windows. r=caillon@aillon.org, sr=bzbarsky@mit.edu --- docshell/base/nsDocShell.cpp | 23 ++++++++++++++++++++--- dom/src/base/nsGlobalWindow.cpp | 9 ++++++++- dom/src/base/nsGlobalWindow.h | 1 + 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 5da2b1092c0a..96cbad9f8ebb 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -1769,6 +1769,23 @@ nsDocShell::GetSameTypeRootTreeItem(nsIDocShellTreeItem ** aRootTreeItem) return NS_OK; } +static PRBool +ItemIsActive(nsIDocShellTreeItem *aItem) +{ + nsCOMPtr tmp(do_GetInterface(aItem)); + nsCOMPtr window(do_QueryInterface(tmp)); + + if (window) { + PRBool isClosed; + + if (NS_SUCCEEDED(window->GetClosed(&isClosed)) && !isClosed) { + return PR_TRUE; + } + } + + return PR_FALSE; +} + NS_IMETHODIMP nsDocShell::FindItemWithName(const PRUnichar * aName, nsISupports * aRequestor, @@ -1785,8 +1802,8 @@ nsDocShell::FindItemWithName(const PRUnichar * aName, reqAsTreeItem(do_QueryInterface(aRequestor)); // First we check our name. - if (mName.Equals(aName)) { - *_retval = NS_STATIC_CAST(nsIDocShellTreeItem *, this); + if (mName.Equals(aName) && ItemIsActive(this)) { + *_retval = this; NS_ADDREF(*_retval); return NS_OK; } @@ -2142,7 +2159,7 @@ nsDocShell::FindChildWithName(const PRUnichar * aName, PRBool childNameEquals = PR_FALSE; child->NameEquals(aName, &childNameEquals); - if (childNameEquals) { + if (childNameEquals && ItemIsActive(child)) { *_retval = child; NS_ADDREF(*_retval); break; diff --git a/dom/src/base/nsGlobalWindow.cpp b/dom/src/base/nsGlobalWindow.cpp index 453c2f4fa2f8..63aa59612e85 100644 --- a/dom/src/base/nsGlobalWindow.cpp +++ b/dom/src/base/nsGlobalWindow.cpp @@ -217,6 +217,7 @@ GlobalWindowImpl::GlobalWindowImpl() mIsScopeClear(PR_TRUE), mIsDocumentLoaded(PR_FALSE), mFullScreen(PR_FALSE), + mIsClosed(PR_FALSE), mLastMouseButtonAction(LL_ZERO), mGlobalObjectOwner(nsnull), mDocShell(nsnull), @@ -1294,7 +1295,10 @@ GlobalWindowImpl::GetDirectories(nsIDOMBarProp** aDirectories) NS_IMETHODIMP GlobalWindowImpl::GetClosed(PRBool* aClosed) { - *aClosed = !mDocShell; + // If someone called close(), or if we don't have a docshell, we're + // closed. + *aClosed = mIsClosed || !mDocShell; + return NS_OK; } @@ -3316,6 +3320,9 @@ GlobalWindowImpl::Close() } } + // Flag that we were closed. + mIsClosed = PR_TRUE; + nsCOMPtr stack = do_GetService(sJSStackContractID); diff --git a/dom/src/base/nsGlobalWindow.h b/dom/src/base/nsGlobalWindow.h index b6f0c0cd110a..ce212820e0ef 100644 --- a/dom/src/base/nsGlobalWindow.h +++ b/dom/src/base/nsGlobalWindow.h @@ -300,6 +300,7 @@ protected: PRPackedBool mIsScopeClear; PRPackedBool mIsDocumentLoaded; // true between onload and onunload events PRPackedBool mFullScreen; + PRPackedBool mIsClosed; PRTime mLastMouseButtonAction; nsString mStatus; nsString mDefaultStatus;