From c4c9f9e982778d84bbc41dbda91aa3269ddff2d3 Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Tue, 17 Sep 2013 15:29:11 -0700 Subject: [PATCH] Bug 917009 - Remove old-style object principal calculation. r=bz --- caps/include/nsScriptSecurityManager.h | 5 -- caps/src/nsScriptSecurityManager.cpp | 111 +------------------------ 2 files changed, 1 insertion(+), 115 deletions(-) diff --git a/caps/include/nsScriptSecurityManager.h b/caps/include/nsScriptSecurityManager.h index 782aa434e845..43c57c5ce5a2 100644 --- a/caps/include/nsScriptSecurityManager.h +++ b/caps/include/nsScriptSecurityManager.h @@ -382,11 +382,6 @@ private: // Returns null if a principal cannot be found; generally callers // should error out at that point. static nsIPrincipal* doGetObjectPrincipal(JS::Handle obj); -#ifdef DEBUG - static nsIPrincipal* - old_doGetObjectPrincipal(JS::Handle obj, - bool aAllowShortCircuit = true); -#endif // Returns null if a principal cannot be found. Note that rv can be NS_OK // when this happens -- this means that there was no JS running. diff --git a/caps/src/nsScriptSecurityManager.cpp b/caps/src/nsScriptSecurityManager.cpp index b43d6b390991..f76b22565025 100644 --- a/caps/src/nsScriptSecurityManager.cpp +++ b/caps/src/nsScriptSecurityManager.cpp @@ -1957,118 +1957,9 @@ nsScriptSecurityManager::doGetObjectPrincipal(JS::Handle aObj) { JSCompartment *compartment = js::GetObjectCompartment(aObj); JSPrincipals *principals = JS_GetCompartmentPrincipals(compartment); - nsIPrincipal *principal = nsJSPrincipals::get(principals); - - // We leave the old code in for a little while to make sure that pulling - // object principals directly off the compartment always gives an equivalent - // result (from a security perspective). -#ifdef DEBUG - nsIPrincipal *old = old_doGetObjectPrincipal(aObj); - MOZ_ASSERT(NS_SUCCEEDED(CheckSameOriginPrincipal(principal, old))); -#endif - - return principal; + return nsJSPrincipals::get(principals); } -#ifdef DEBUG -// static -nsIPrincipal* -nsScriptSecurityManager::old_doGetObjectPrincipal(JS::Handle aObj, - bool aAllowShortCircuit) -{ - NS_ASSERTION(aObj, "Bad call to doGetObjectPrincipal()!"); - nsIPrincipal* result = nullptr; - - JSContext* cx = nsXPConnect::XPConnect()->GetCurrentJSContext(); - JS::RootedObject obj(cx, aObj); - JS::RootedObject origObj(cx, obj); - - // A common case seen in this code is that we enter this function - // with obj being a Function object, whose parent is a Call - // object. Neither of those have object principals, so we can skip - // those objects here before we enter the below loop. That way we - // avoid wasting time checking properties of their classes etc in - // the loop. - - if (js::IsFunctionObject(obj)) { - obj = js::GetObjectParent(obj); - - if (!obj) - return nullptr; - - if (js::IsCallObject(obj)) { - obj = js::GetObjectParentMaybeScope(obj); - - if (!obj) - return nullptr; - } - } - - const js::Class *jsClass = js::GetObjectClass(obj); - - do { - // Note: jsClass is set before this loop, and also at the - // *end* of this loop. - - if (IS_WN_CLASS(jsClass)) { - result = nsXPConnect::XPConnect()->GetPrincipal(obj, - aAllowShortCircuit); - if (result) { - break; - } - } else { - nsISupports *priv; - if (!(~jsClass->flags & (JSCLASS_HAS_PRIVATE | - JSCLASS_PRIVATE_IS_NSISUPPORTS))) { - priv = (nsISupports *) js::GetObjectPrivate(obj); - } else { - priv = UnwrapDOMObjectToISupports(obj); - } - - if (aAllowShortCircuit) { - nsCOMPtr xpcWrapper = - do_QueryInterface(priv); - - NS_ASSERTION(!xpcWrapper || - !strcmp(jsClass->name, "XPCNativeWrapper"), - "Uh, an nsIXPConnectWrappedNative with the " - "wrong JSClass or getObjectOps hooks!"); - } - - nsCOMPtr objPrin = - do_QueryInterface(priv); - - if (objPrin) { - result = objPrin->GetPrincipal(); - - if (result) { - break; - } - } - } - - obj = js::GetObjectParentMaybeScope(obj); - - if (!obj) - break; - - jsClass = js::GetObjectClass(obj); - } while (1); - - if (aAllowShortCircuit) { - nsIPrincipal *principal = old_doGetObjectPrincipal(origObj, false); - - // Because of inner window reuse, we can have objects with one principal - // living in a scope with a different (but same-origin) principal. So - // just check same-origin here. - NS_ASSERTION(NS_SUCCEEDED(CheckSameOriginPrincipal(result, principal)), - "Principal mismatch. Not good"); - } - - return result; -} -#endif /* DEBUG */ - //////////////////////////////////////////////// // Methods implementing nsIXPCSecurityManager // ////////////////////////////////////////////////