From 730eb8abbbbda465177d1c74952b761d6bad888c Mon Sep 17 00:00:00 2001 From: "mstoltz%netscape.com" Date: Wed, 9 Aug 2000 20:08:54 +0000 Subject: [PATCH] Fixed 37702 and 47670. r=vidur --- docshell/base/nsDocShell.cpp | 29 ++++++++++++++++----- dom/src/base/nsGlobalWindow.h | 3 ++- dom/src/base/nsLocation.cpp | 48 ++++++++++++++++++----------------- 3 files changed, 50 insertions(+), 30 deletions(-) diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index b8f6e7a006e4..3a8a9f0fd80f 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -2983,13 +2983,30 @@ NS_IMETHODIMP nsDocShell::GetCurrentDocumentOwner(nsISupports** aOwner) { nsresult rv; *aOwner = nsnull; - nsCOMPtr docv(do_QueryInterface(mContentViewer)); - if (!docv) return NS_ERROR_FAILURE; - nsCOMPtr doc; - rv = docv->GetDocument(*getter_AddRefs(doc)); - if (NS_FAILED(rv) || !doc) return NS_ERROR_FAILURE; + nsCOMPtr document; + //-- Get the current document + if (mContentViewer) + { + nsCOMPtr docViewer(do_QueryInterface(mContentViewer)); + if (!docViewer) return NS_ERROR_FAILURE; + rv = docViewer->GetDocument(*getter_AddRefs(document)); + } + else //-- If there's no document loaded yet, look at the parent (frameset) + { + nsCOMPtr parentItem; + rv = GetSameTypeParent(getter_AddRefs(parentItem)); + if (NS_FAILED(rv) || !parentItem) return rv; + nsCOMPtr parentWindow(do_GetInterface(parentItem)); + if (!parentWindow) return NS_OK; + nsCOMPtr parentDomDoc; + rv = parentWindow->GetDocument(getter_AddRefs(parentDomDoc)); + if (!parentDomDoc) return NS_OK; + document = do_QueryInterface(parentDomDoc); + } + + //-- Get the document's principal nsCOMPtr principal; - rv = doc->GetPrincipal(getter_AddRefs(principal)); + rv = document->GetPrincipal(getter_AddRefs(principal)); if (NS_FAILED(rv) || !principal) return NS_ERROR_FAILURE; rv = principal->QueryInterface(NS_GET_IID(nsISupports),(void**)aOwner); return rv; diff --git a/dom/src/base/nsGlobalWindow.h b/dom/src/base/nsGlobalWindow.h index 0b04c794b63b..2978e9c5ec5b 100644 --- a/dom/src/base/nsGlobalWindow.h +++ b/dom/src/base/nsGlobalWindow.h @@ -70,6 +70,7 @@ class LocationImpl; class NavigatorImpl; class ScreenImpl; class HistoryImpl; +class nsIDocShellLoadInfo; //***************************************************************************** // GlobalWindowImpl: Global Object for Scripting @@ -361,7 +362,7 @@ protected: PRBool aReplace); nsresult GetSourceURL(JSContext* cx, nsIURI** sourceURL); - nsresult CheckURL(nsIURI *url, nsIURI** aReferrer); + nsresult CheckURL(nsIURI *url, nsIDocShellLoadInfo** aLoadInfo); nsIDocShell *mDocShell; // Weak Reference void *mScriptObject; diff --git a/dom/src/base/nsLocation.cpp b/dom/src/base/nsLocation.cpp index 988a273f919e..940bb158634a 100644 --- a/dom/src/base/nsLocation.cpp +++ b/dom/src/base/nsLocation.cpp @@ -104,7 +104,7 @@ NS_IMETHODIMP_(void) LocationImpl::SetDocShell(nsIDocShell *aDocShell) } nsresult -LocationImpl::CheckURL(nsIURI* aURL, nsIURI** aReferrer) +LocationImpl::CheckURL(nsIURI* aURL, nsIDocShellLoadInfo** aLoadInfo) { nsresult result; // Get JSContext from stack. @@ -126,16 +126,29 @@ LocationImpl::CheckURL(nsIURI* aURL, nsIURI** aReferrer) if (NS_FAILED(result = secMan->CheckLoadURIFromScript(cx, aURL))) return result; - // Now get the referrer to use when loading the URI - nsCOMPtr principal; - if (NS_FAILED(secMan->GetSubjectPrincipal(getter_AddRefs(principal)))) - return NS_ERROR_FAILURE; - nsCOMPtr codebase = do_QueryInterface(principal); - if (codebase) { - if (NS_FAILED(result = codebase->GetURI(aReferrer))) - return result; - } + // Create load info + nsCOMPtr loadInfo; + mDocShell->CreateLoadInfo(getter_AddRefs(loadInfo)); + NS_ENSURE_TRUE(loadInfo, NS_ERROR_FAILURE); + + // Now get the principal and referrer to use when loading the URI + nsCOMPtr principal; + if (NS_FAILED(secMan->GetSubjectPrincipal(getter_AddRefs(principal))) || + !principal) + return NS_ERROR_FAILURE; + nsCOMPtr owner = do_QueryInterface(principal); + loadInfo->SetOwner(owner); + + nsCOMPtr codebase = do_QueryInterface(principal); + if (!codebase) return NS_ERROR_FAILURE; + nsCOMPtr referrer; + if (NS_FAILED(result = codebase->GetURI(getter_AddRefs(referrer)))) + return result; + loadInfo->SetReferrer(referrer); + + *aLoadInfo = loadInfo.get(); + NS_ADDREF(*aLoadInfo); return NS_OK; } @@ -146,15 +159,9 @@ LocationImpl::SetURL(nsIURI* aURL) if (mDocShell) { nsCOMPtr loadInfo; - mDocShell->CreateLoadInfo(getter_AddRefs(loadInfo)); - NS_ENSURE_TRUE(loadInfo, NS_ERROR_FAILURE); - - nsCOMPtr referrer; - if(NS_FAILED(CheckURL(aURL, getter_AddRefs(referrer)))) + if(NS_FAILED(CheckURL(aURL, getter_AddRefs(loadInfo)))) return NS_ERROR_FAILURE; - loadInfo->SetReferrer(referrer); - return mDocShell->LoadURI(aURL, loadInfo); } else { @@ -371,14 +378,9 @@ LocationImpl::SetHrefWithBase(const nsString& aHref, if ((NS_OK == result) && (mDocShell)) { nsCOMPtr loadInfo; - mDocShell->CreateLoadInfo(getter_AddRefs(loadInfo)); - NS_ENSURE_TRUE(loadInfo, NS_ERROR_FAILURE); - - nsCOMPtr referrer; - if(NS_FAILED(CheckURL(newUrl, getter_AddRefs(referrer)))) + if(NS_FAILED(CheckURL(newUrl, getter_AddRefs(loadInfo)))) return NS_ERROR_FAILURE; - loadInfo->SetReferrer(referrer); if (aReplace) loadInfo->SetLoadType(nsIDocShellLoadInfo::loadNormalReplace);