Bug 747607 - Remove GetContextFromStack. r=bz

This commit is contained in:
Bobby Holley 2012-10-19 23:26:17 +02:00
parent fdb9000352
commit 1847a73fea

View File

@ -38,36 +38,6 @@
#include "nsContentUtils.h"
#include "nsEventStateManager.h"
static nsresult
GetContextFromStack(nsIJSContextStack *aStack, JSContext **aContext)
{
nsCOMPtr<nsIJSContextStackIterator>
iterator(do_CreateInstance("@mozilla.org/js/xpc/ContextStackIterator;1"));
NS_ENSURE_TRUE(iterator, NS_ERROR_FAILURE);
nsresult rv = iterator->Reset(aStack);
NS_ENSURE_SUCCESS(rv, rv);
bool done;
while (NS_SUCCEEDED(iterator->Done(&done)) && !done) {
rv = iterator->Prev(aContext);
NS_ASSERTION(NS_SUCCEEDED(rv), "Broken iterator implementation");
// Consider a null context the end of the line.
if (!*aContext) {
break;
}
if (nsJSUtils::GetDynamicScriptContext(*aContext)) {
return NS_OK;
}
}
*aContext = nullptr;
return NS_OK;
}
static nsresult
GetDocumentCharacterSetForURI(const nsAString& aHref, nsACString& aCharset)
{
@ -78,11 +48,7 @@ GetDocumentCharacterSetForURI(const nsAString& aHref, nsACString& aCharset)
nsCOMPtr<nsIJSContextStack> stack(do_GetService("@mozilla.org/js/xpc/ContextStack;1", &rv));
NS_ENSURE_SUCCESS(rv, rv);
JSContext *cx;
rv = GetContextFromStack(stack, &cx);
NS_ENSURE_SUCCESS(rv, rv);
JSContext *cx = nsContentUtils::GetCurrentJSContext();
if (cx) {
nsCOMPtr<nsIDOMWindow> window =
do_QueryInterface(nsJSUtils::GetDynamicScriptGlobal(cx));
@ -168,30 +134,14 @@ nsresult
nsLocation::CheckURL(nsIURI* aURI, nsIDocShellLoadInfo** aLoadInfo)
{
*aLoadInfo = nullptr;
JSContext* cx;
if ((cx = nsContentUtils::GetCurrentJSContext())) {
nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager();
NS_ENSURE_STATE(ssm);
// Check to see if URI is allowed.
nsresult rv = ssm->CheckLoadURIFromScript(cx, aURI);
NS_ENSURE_SUCCESS(rv, rv);
}
nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mDocShell));
NS_ENSURE_TRUE(docShell, NS_ERROR_NOT_AVAILABLE);
nsresult rv;
// Get JSContext from stack.
nsCOMPtr<nsIJSContextStack>
stack(do_GetService("@mozilla.org/js/xpc/ContextStack;1", &rv));
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_SUCCESS(GetContextFromStack(stack, &cx), NS_ERROR_FAILURE);
nsCOMPtr<nsISupports> owner;
nsCOMPtr<nsIURI> sourceURI;
if (cx) {
if (JSContext *cx = nsContentUtils::GetCurrentJSContext()) {
// No cx means that there's no JS running, or at least no JS that
// was run through code that properly pushed a context onto the
// context stack (as all code that runs JS off of web pages
@ -199,12 +149,11 @@ nsLocation::CheckURL(nsIURI* aURI, nsIDocShellLoadInfo** aLoadInfo)
// we need to create the loadinfo etc.
// Get security manager.
nsCOMPtr<nsIScriptSecurityManager>
secMan(do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv));
NS_ENSURE_SUCCESS(rv, rv);
nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager();
NS_ENSURE_STATE(ssm);
// Check to see if URI is allowed.
rv = secMan->CheckLoadURIFromScript(cx, aURI);
nsresult rv = ssm->CheckLoadURIFromScript(cx, aURI);
NS_ENSURE_SUCCESS(rv, rv);
// Make the load's referrer reflect changes to the document's URI caused by
@ -241,7 +190,7 @@ nsLocation::CheckURL(nsIURI* aURI, nsIDocShellLoadInfo** aLoadInfo)
sourceURI = principalURI;
}
owner = do_QueryInterface(secMan->GetCxSubjectPrincipal(cx));
owner = do_QueryInterface(ssm->GetCxSubjectPrincipal(cx));
}
// Create load info
@ -534,17 +483,7 @@ nsLocation::SetHref(const nsAString& aHref)
nsAutoString oldHref;
nsresult rv = NS_OK;
// Get JSContext from stack.
nsCOMPtr<nsIJSContextStack>
stack(do_GetService("@mozilla.org/js/xpc/ContextStack;1", &rv));
if (NS_FAILED(rv))
return NS_ERROR_FAILURE;
JSContext *cx;
if (NS_FAILED(GetContextFromStack(stack, &cx)))
return NS_ERROR_FAILURE;
JSContext *cx = nsContentUtils::GetCurrentJSContext();
// According to HTML5 spec, |location.href = ...| must act as if
// it were |location.replace(...)| before the page load finishes.
@ -923,19 +862,8 @@ NS_IMETHODIMP
nsLocation::Replace(const nsAString& aUrl)
{
nsresult rv = NS_OK;
// Get JSContext from stack.
nsCOMPtr<nsIJSContextStack>
stack(do_GetService("@mozilla.org/js/xpc/ContextStack;1"));
if (stack) {
JSContext *cx;
rv = GetContextFromStack(stack, &cx);
NS_ENSURE_SUCCESS(rv, rv);
if (cx) {
return SetHrefWithContext(cx, aUrl, true);
}
if (JSContext *cx = nsContentUtils::GetCurrentJSContext()) {
return SetHrefWithContext(cx, aUrl, true);
}
nsAutoString oldHref;