Bug 917009 - Remove old-style object principal calculation. r=bz

This commit is contained in:
Bobby Holley 2013-09-17 15:29:11 -07:00
parent 93e8d15780
commit c4c9f9e982
2 changed files with 1 additions and 115 deletions

View File

@ -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<JSObject*> obj);
#ifdef DEBUG
static nsIPrincipal*
old_doGetObjectPrincipal(JS::Handle<JSObject*> 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.

View File

@ -1957,118 +1957,9 @@ nsScriptSecurityManager::doGetObjectPrincipal(JS::Handle<JSObject*> 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<JSObject*> 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<nsIXPConnectWrappedNative> xpcWrapper =
do_QueryInterface(priv);
NS_ASSERTION(!xpcWrapper ||
!strcmp(jsClass->name, "XPCNativeWrapper"),
"Uh, an nsIXPConnectWrappedNative with the "
"wrong JSClass or getObjectOps hooks!");
}
nsCOMPtr<nsIScriptObjectPrincipal> 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 //
////////////////////////////////////////////////