diff --git a/js/src/xpconnect/src/XPCCrossOriginWrapper.cpp b/js/src/xpconnect/src/XPCCrossOriginWrapper.cpp index 74c60482fe38..dfaf8e7f1220 100644 --- a/js/src/xpconnect/src/XPCCrossOriginWrapper.cpp +++ b/js/src/xpconnect/src/XPCCrossOriginWrapper.cpp @@ -177,19 +177,11 @@ GetWrappedObject(JSContext *cx, JSObject *wrapper) static inline nsIScriptSecurityManager * -GetSecurityManager(JSContext *cx) +GetSecurityManager() { - XPCCallContext ccx(JS_CALLER, cx); - NS_ENSURE_TRUE(ccx.IsValid(), nsnull); + extern nsIScriptSecurityManager *gScriptSecurityManager; - // XXX HOOK_CALL_METHOD seems wrong. - nsCOMPtr sm = ccx.GetXPCContext()-> - GetAppropriateSecurityManager(nsIXPCSecurityManager::HOOK_CALL_METHOD); - - nsCOMPtr ssm(do_QueryInterface(sm)); - - // This Releases, but that's OK, since XPConnect holds a reference to it. - return ssm; + return gScriptSecurityManager; } static JSBool @@ -234,7 +226,7 @@ IsWrapperSameOrigin(JSContext *cx, JSObject *wrappedObj) nsCOMPtr subjectPrin, objectPrin; // Get the subject principal from the execution stack. - nsIScriptSecurityManager *ssm = GetSecurityManager(cx); + nsIScriptSecurityManager *ssm = GetSecurityManager(); if (!ssm) { ThrowException(NS_ERROR_NOT_INITIALIZED, cx); return NS_ERROR_NOT_INITIALIZED; @@ -626,7 +618,7 @@ XPC_XOW_GetOrSetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp, XPCWrappedNative::GetWrappedNativeOfJSObject(cx, wrappedObj); NS_ASSERTION(wn, "How did we wrap a non-WrappedNative?"); if (!IsValFrame(cx, wrappedObj, id, wn)) { - nsIScriptSecurityManager *ssm = GetSecurityManager(cx); + nsIScriptSecurityManager *ssm = GetSecurityManager(); if (!ssm) { return ThrowException(NS_ERROR_NOT_INITIALIZED, cx); } @@ -772,7 +764,7 @@ XPC_XOW_NewResolve(JSContext *cx, JSObject *obj, jsval id, uintN flags, XPCWrappedNative::GetWrappedNativeOfJSObject(cx, wrappedObj); NS_ASSERTION(wn, "How did we wrap a non-WrappedNative?"); if (!IsValFrame(cx, wrappedObj, id, wn)) { - nsIScriptSecurityManager *ssm = GetSecurityManager(cx); + nsIScriptSecurityManager *ssm = GetSecurityManager(); if (!ssm) { return ThrowException(NS_ERROR_NOT_INITIALIZED, cx); } @@ -1146,7 +1138,7 @@ XPC_XOW_toString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, nsresult rv = IsWrapperSameOrigin(cx, wrappedObj); if (rv == NS_ERROR_DOM_PROP_ACCESS_DENIED) { - nsIScriptSecurityManager *ssm = GetSecurityManager(cx); + nsIScriptSecurityManager *ssm = GetSecurityManager(); if (!ssm) { return ThrowException(NS_ERROR_NOT_INITIALIZED, cx); } diff --git a/js/src/xpconnect/src/nsXPConnect.cpp b/js/src/xpconnect/src/nsXPConnect.cpp index 97a39839097a..7e6a554eb37d 100644 --- a/js/src/xpconnect/src/nsXPConnect.cpp +++ b/js/src/xpconnect/src/nsXPConnect.cpp @@ -60,6 +60,10 @@ NS_IMPL_THREADSAFE_ISUPPORTS3(nsXPConnect, nsXPConnect* nsXPConnect::gSelf = nsnull; JSBool nsXPConnect::gOnceAliveNowDead = JS_FALSE; +// Global cache of the default script security manager (QI'd to +// nsIScriptSecurityManager) +nsIScriptSecurityManager *gScriptSecurityManager = nsnull; + const char XPC_CONTEXT_STACK_CONTRACTID[] = "@mozilla.org/js/xpc/ContextStack;1"; const char XPC_RUNTIME_CONTRACTID[] = "@mozilla.org/js/xpc/RuntimeService;1"; const char XPC_EXCEPTION_CONTRACTID[] = "@mozilla.org/js/xpc/Exception;1"; @@ -151,6 +155,8 @@ nsXPConnect::~nsXPConnect() NS_IF_RELEASE(mContextStack); NS_IF_RELEASE(mDefaultSecurityManager); + gScriptSecurityManager = nsnull; + // shutdown the logging system XPC_LOG_FINISH(); @@ -1511,6 +1517,14 @@ nsXPConnect::SetDefaultSecurityManager(nsIXPCSecurityManager *aManager, NS_IF_RELEASE(mDefaultSecurityManager); mDefaultSecurityManager = aManager; mDefaultSecurityManagerFlags = flags; + + nsCOMPtr ssm = + do_QueryInterface(mDefaultSecurityManager); + + // Remember the result of the above QI for fast access to the + // script securityt manager. + gScriptSecurityManager = ssm; + return NS_OK; }