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
This commit is contained in:
dveditz%cruzio.com
2007-11-14 11:59:00 +00:00
parent 6268c0884c
commit dca29c7be3
2 changed files with 17 additions and 6 deletions

View File

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

View File

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