From dca29c7be3e375441017b0c0de9c0ac031ed0bbc Mon Sep 17 00:00:00 2001 From: "dveditz%cruzio.com" Date: Wed, 14 Nov 2007 11:59:00 +0000 Subject: [PATCH] bug 402649 Base our referrer on the URI of the principal executing the code, not on the URI of the document currently loaded in the window associated to the context we're running on. patch=bzbarsky, r+sr=jst, a=dveditz git-svn-id: svn://10.0.0.236/branches/MOZILLA_1_8_BRANCH@239383 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/dom/src/base/nsGlobalWindow.h | 3 ++- mozilla/dom/src/base/nsLocation.cpp | 20 +++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/mozilla/dom/src/base/nsGlobalWindow.h b/mozilla/dom/src/base/nsGlobalWindow.h index 4acba9be1d9..19a8a6f5e36 100644 --- a/mozilla/dom/src/base/nsGlobalWindow.h +++ b/mozilla/dom/src/base/nsGlobalWindow.h @@ -756,7 +756,8 @@ protected: nsresult SetHrefWithContext(JSContext* cx, const nsAString& aHref, PRBool aReplace); - nsresult GetSourceURL(JSContext* cx, nsIURI** sourceURL); + nsresult GetSourceURL(JSContext* cx, nsIPrincipal* callerPrincipal, + nsIURI** sourceURL); nsresult GetSourceBaseURL(JSContext* cx, nsIURI** sourceURL); nsresult GetSourceDocument(JSContext* cx, nsIDocument** aDocument); diff --git a/mozilla/dom/src/base/nsLocation.cpp b/mozilla/dom/src/base/nsLocation.cpp index dad92491d0d..8abba06fd74 100644 --- a/mozilla/dom/src/base/nsLocation.cpp +++ b/mozilla/dom/src/base/nsLocation.cpp @@ -220,7 +220,7 @@ nsLocation::CheckURL(nsIURI* aURI, nsIDocShellLoadInfo** aLoadInfo) return NS_ERROR_FAILURE; owner = do_QueryInterface(principal); - GetSourceURL(cx, getter_AddRefs(sourceURI)); + GetSourceURL(cx, principal, getter_AddRefs(sourceURI)); } // Create load info @@ -1026,14 +1026,24 @@ nsLocation::GetSourceBaseURL(JSContext* cx, nsIURI** sourceURL) } nsresult -nsLocation::GetSourceURL(JSContext* cx, nsIURI** sourceURL) +nsLocation::GetSourceURL(JSContext* cx, nsIPrincipal* callerPrincipal, + nsIURI** sourceURL) { + NS_PRECONDITION(callerPrincipal, "Must have caller principal here"); + + *sourceURL = nsnull; + nsCOMPtr doc; nsresult rv = GetSourceDocument(cx, getter_AddRefs(doc)); if (doc) { - NS_IF_ADDREF(*sourceURL = doc->GetDocumentURI()); - } else { - *sourceURL = nsnull; + nsIPrincipal* docPrincipal = doc->GetPrincipal(); + if (docPrincipal) { + PRBool subsumes; + rv = callerPrincipal->Subsumes(docPrincipal, &subsumes); + if (NS_SUCCEEDED(rv) && subsumes) { + NS_IF_ADDREF(*sourceURL = doc->GetDocumentURI()); + } + } } return rv;