From 7ff9289c013ef68ec25dc8f133632fa78ebcaabb Mon Sep 17 00:00:00 2001 From: "darin%netscape.com" Date: Tue, 8 May 2001 21:34:02 +0000 Subject: [PATCH] merged with tip git-svn-id: svn://10.0.0.236/branches/HttpConnectionMagic_20010415_BRANCH@94274 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/docshell/base/nsDocShell.cpp | 27 ++++++++++++++++++++++----- mozilla/docshell/base/nsWebShell.cpp | 15 +++++---------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/mozilla/docshell/base/nsDocShell.cpp b/mozilla/docshell/base/nsDocShell.cpp index f4e2dde0792..fb8c7d8ea8a 100644 --- a/mozilla/docshell/base/nsDocShell.cpp +++ b/mozilla/docshell/base/nsDocShell.cpp @@ -33,6 +33,8 @@ #include "nsIPluginHost.h" #include "nsCURILoader.h" #include "nsLayoutCID.h" +#include "nsDOMCID.h" +#include "nsIDOMScriptObjectFactory.h" #include "nsNetUtil.h" #include "nsRect.h" #include "prprf.h" @@ -114,6 +116,8 @@ static NS_DEFINE_CID(kSimpleURICID, NS_SIMPLEURI_CID); static NS_DEFINE_CID(kDocumentCharsetInfoCID, NS_DOCUMENTCHARSETINFO_CID); static NS_DEFINE_CID(kPluginManagerCID, NS_PLUGINMANAGER_CID); static NS_DEFINE_CID(kSecurityManagerCID, NS_SCRIPTSECURITYMANAGER_CID); +static NS_DEFINE_CID(kDOMScriptObjectFactoryCID, + NS_DOM_SCRIPT_OBJECT_FACTORY_CID); // // Local function prototypes @@ -158,6 +162,7 @@ nsDocShell::nsDocShell(): mURIResultedInDocument(PR_FALSE), mUseExternalProtocolHandler(PR_FALSE), mDisallowPopupWindows(PR_FALSE), + mIsBeingDestroyed(PR_FALSE), mParent(nsnull), mTreeOwner(nsnull), mChromeEventHandler(nsnull) @@ -1333,7 +1338,6 @@ NS_IMETHODIMP nsDocShell::GetChildAt(PRInt32 aIndex, nsIDocShellTreeItem ** aChild) { NS_ENSURE_ARG_POINTER(aChild); - NS_ENSURE_ARG_RANGE(aIndex, 0, mChildren.Count() - 1); *aChild = (nsIDocShellTreeItem *) mChildren.ElementAt(aIndex); NS_IF_ADDREF(*aChild); @@ -1842,6 +1846,8 @@ nsDocShell::Create() NS_IMETHODIMP nsDocShell::Destroy() { + mIsBeingDestroyed = PR_TRUE; + // Stop any URLs that are currently being loaded... Stop(); if (mDocLoader) { @@ -2646,6 +2652,10 @@ nsDocShell::ScrollByPages(PRInt32 numPages) NS_IMETHODIMP nsDocShell::GetScriptGlobalObject(nsIScriptGlobalObject ** aGlobal) { + if (mIsBeingDestroyed) { + return NS_ERROR_NOT_AVAILABLE; + } + NS_ENSURE_ARG_POINTER(aGlobal); NS_ENSURE_SUCCESS(EnsureScriptEnvironment(), NS_ERROR_FAILURE); @@ -4448,7 +4458,7 @@ nsDocShell::LoadHistoryEntry(nsISHEntry * aEntry, PRUint32 aLoadType) NS_ERROR_FAILURE); NS_ENSURE_SUCCESS(aEntry->GetPostData(getter_AddRefs(postData)), NS_ERROR_FAILURE); -#if 0 + /* If there is a valid postdata *and* the user pressed * shift-reload, take user's permission before we repost the * data to the server. @@ -4477,7 +4487,6 @@ nsDocShell::LoadHistoryEntry(nsISHEntry * aEntry, PRUint32 aLoadType) } } } -#endif /* 0 */ NS_ENSURE_SUCCESS(InternalLoad (uri, referrerURI, nsnull, PR_TRUE, PR_FALSE, nsnull, @@ -4813,7 +4822,15 @@ nsDocShell::EnsureScriptEnvironment() if (mScriptContext) return NS_OK; - NS_NewScriptGlobalObject(getter_AddRefs(mScriptGlobal)); + if (mIsBeingDestroyed) { + return NS_ERROR_NOT_AVAILABLE; + } + + nsCOMPtr factory = + do_GetService(kDOMScriptObjectFactoryCID); + NS_ENSURE_TRUE(factory, NS_ERROR_FAILURE); + + factory->NewScriptGlobalObject(getter_AddRefs(mScriptGlobal)); NS_ENSURE_TRUE(mScriptGlobal, NS_ERROR_FAILURE); mScriptGlobal->SetDocShell(NS_STATIC_CAST(nsIDocShell *, this)); @@ -4821,7 +4838,7 @@ nsDocShell::EnsureScriptEnvironment() SetGlobalObjectOwner(NS_STATIC_CAST (nsIScriptGlobalObjectOwner *, this)); - NS_CreateScriptContext(mScriptGlobal, getter_AddRefs(mScriptContext)); + factory->NewScriptContext(mScriptGlobal, getter_AddRefs(mScriptContext)); NS_ENSURE_TRUE(mScriptContext, NS_ERROR_FAILURE); return NS_OK; diff --git a/mozilla/docshell/base/nsWebShell.cpp b/mozilla/docshell/base/nsWebShell.cpp index eac83852870..378d970abcc 100644 --- a/mozilla/docshell/base/nsWebShell.cpp +++ b/mozilla/docshell/base/nsWebShell.cpp @@ -323,18 +323,13 @@ nsWebShell::GetInterface(const nsIID &aIID, void** aInstancePtr) NS_ADDREF((nsISupports*)*aInstancePtr); return NS_OK; } - else if(aIID.Equals(NS_GET_IID(nsIDOMWindowInternal))) + else if(aIID.Equals(NS_GET_IID(nsIDOMWindowInternal)) || + aIID.Equals(NS_GET_IID(nsIDOMWindow))) + { NS_ENSURE_SUCCESS(EnsureScriptEnvironment(), NS_ERROR_FAILURE); - NS_ENSURE_SUCCESS(mScriptGlobal->QueryInterface(NS_GET_IID(nsIDOMWindowInternal), - aInstancePtr), NS_ERROR_FAILURE); - return NS_OK; - } - else if(aIID.Equals(NS_GET_IID(nsIDOMWindow))) - { - NS_ENSURE_SUCCESS(EnsureScriptEnvironment(), NS_ERROR_FAILURE); - NS_ENSURE_SUCCESS(mScriptGlobal->QueryInterface(NS_GET_IID(nsIDOMWindow), - aInstancePtr), NS_ERROR_FAILURE); + NS_ENSURE_SUCCESS(mScriptGlobal->QueryInterface(aIID, aInstancePtr), + NS_ERROR_FAILURE); return NS_OK; }