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

This commit is contained in:
jst%netscape.com 2003-05-29 00:48:35 +00:00
parent 724dfc9b3c
commit dd01342a24
3 changed files with 29 additions and 4 deletions

View File

@ -1769,6 +1769,23 @@ nsDocShell::GetSameTypeRootTreeItem(nsIDocShellTreeItem ** aRootTreeItem)
return NS_OK;
}
static PRBool
ItemIsActive(nsIDocShellTreeItem *aItem)
{
nsCOMPtr<nsIDOMWindow> tmp(do_GetInterface(aItem));
nsCOMPtr<nsIDOMWindowInternal> 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;

View File

@ -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<nsIJSContextStack> stack =
do_GetService(sJSStackContractID);

View File

@ -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;