Bug 809290 - Fix nsLocation::CheckURL. r=bz

This commit is contained in:
Bobby Holley 2012-11-08 08:26:49 -08:00
parent 6f4c5d25ef
commit bcd798914e
2 changed files with 13 additions and 32 deletions

View File

@ -108,31 +108,6 @@ nsLocation::GetDocShell()
return docshell;
}
// Try to get the the document corresponding to the given JSScript.
static already_AddRefed<nsIDocument>
GetScriptDocument(JSContext *cx, JSScript *script)
{
if (!cx || !script)
return nullptr;
JSObject* scope = JS_GetGlobalFromScript(script);
if (!scope)
return nullptr;
JSAutoCompartment ac(cx, scope);
nsCOMPtr<nsIDOMWindow> window =
do_QueryInterface(nsJSUtils::GetStaticScriptGlobal(cx, scope));
if (!window)
return nullptr;
// If it's a window, get its document.
nsCOMPtr<nsIDOMDocument> domDoc;
window->GetDocument(getter_AddRefs(domDoc));
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
return doc.forget();
}
nsresult
nsLocation::CheckURL(nsIURI* aURI, nsIDocShellLoadInfo** aLoadInfo)
{
@ -166,13 +141,12 @@ nsLocation::CheckURL(nsIURI* aURI, nsIDocShellLoadInfo** aLoadInfo)
// current URI as the referrer. If they don't match, use the principal's
// URI.
JSScript* script = nullptr;
nsCOMPtr<nsIDocument> doc;
nsCOMPtr<nsIURI> docOriginalURI, docCurrentURI, principalURI;
// NB: A false return value from JS_DescribeScriptedCaller means no caller
// was found. It does not signal that an exception was thrown.
if (JS_DescribeScriptedCaller(cx, &script, nullptr)) {
doc = GetScriptDocument(cx, script);
nsCOMPtr<nsPIDOMWindow> entryPoint =
do_QueryInterface(nsJSUtils::GetDynamicScriptGlobal(cx));
if (entryPoint) {
doc = entryPoint->GetDoc();
}
if (doc) {
docOriginalURI = doc->GetOriginalURI();

View File

@ -56,8 +56,15 @@ function iframeLoaded(identifier) {
is(iframeCw.getInnerIframeReferrer(), iframeCw.location, 'inner iframe referrer');
// Now do the test again, this time with a popup.
//
// NB: in this situation, we're actually getting called in an event handler from
// the iframe, meaning that it serves as the script entry point. But that's a detail,
// and we want to pretend like this window is doing the call. So let's use setTimeout
// to forget about the iframe.
window.setTimeout(function() {
popup = window.open('file_bug593174_1.html');
popup.onload = iframeLoaded('popup/outer');
}, 0);
}
else if (loadCount == 4) {
history.replaceState('', '', Math.random());