Bug 797204 - Use JS_GetScriptedCaller instead of JSStackFrames in nsLocation. r=bz

This commit is contained in:
Bobby Holley 2012-10-10 11:01:26 +02:00
parent e755bb3521
commit 28ec67ce73

View File

@ -138,14 +138,14 @@ nsLocation::GetDocShell()
return docshell;
}
// Try to get the the document corresponding to the given JSStackFrame.
// Try to get the the document corresponding to the given JSScript.
static already_AddRefed<nsIDocument>
GetFrameDocument(JSContext *cx, JSStackFrame *fp)
GetScriptDocument(JSContext *cx, JSScript *script)
{
if (!cx || !fp)
if (!cx || !script)
return nullptr;
JSObject* scope = JS_GetGlobalForFrame(fp);
JSObject* scope = JS_GetGlobalFromScript(script);
if (!scope)
return nullptr;
@ -206,12 +206,6 @@ nsLocation::CheckURL(nsIURI* aURI, nsIDocShellLoadInfo** aLoadInfo)
rv = secMan->CheckLoadURIFromScript(cx, aURI);
NS_ENSURE_SUCCESS(rv, rv);
// Now get the principal to use when loading the URI
// First, get the principal and frame.
JSStackFrame *fp;
nsIPrincipal* principal = secMan->GetCxSubjectPrincipalAndFrame(cx, &fp);
NS_ENSURE_TRUE(principal, NS_ERROR_FAILURE);
// Make the load's referrer reflect changes to the document's URI caused by
// push/replaceState, if possible. First, get the document corresponding to
// fp. If the document's original URI (i.e. its URI before
@ -219,7 +213,10 @@ nsLocation::CheckURL(nsIURI* aURI, nsIDocShellLoadInfo** aLoadInfo)
// current URI as the referrer. If they don't match, use the principal's
// URI.
nsCOMPtr<nsIDocument> doc = GetFrameDocument(cx, fp);
JSScript* script = nullptr;
if (!JS_DescribeScriptedCaller(cx, &script, nullptr))
return NS_ERROR_FAILURE;
nsCOMPtr<nsIDocument> doc = GetScriptDocument(cx, script);
nsCOMPtr<nsIURI> docOriginalURI, docCurrentURI, principalURI;
if (doc) {
docOriginalURI = doc->GetOriginalURI();