From 743cd886221847c3be1487cdcd541f39f003ec89 Mon Sep 17 00:00:00 2001 From: "mrbkap@gmail.com" Date: Sat, 29 Dec 2007 15:38:36 -0800 Subject: [PATCH] Allow chrome to use SJOWs. bug 409889, r+sr=jst --- js/src/xpconnect/src/XPCSafeJSObjectWrapper.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/js/src/xpconnect/src/XPCSafeJSObjectWrapper.cpp b/js/src/xpconnect/src/XPCSafeJSObjectWrapper.cpp index 118f1c52a2b..fe2f3845404 100644 --- a/js/src/xpconnect/src/XPCSafeJSObjectWrapper.cpp +++ b/js/src/xpconnect/src/XPCSafeJSObjectWrapper.cpp @@ -281,10 +281,11 @@ WrapJSValue(JSContext *cx, JSObject *obj, jsval val, jsval *rval) // force the new wrapper to use the principal of the unsafe // object we got the new object from. nsCOMPtr srcObjPrincipal; + nsCOMPtr subjPrincipal; nsCOMPtr valObjPrincipal; nsresult rv = FindPrincipals(cx, obj, getter_AddRefs(srcObjPrincipal), - nsnull, nsnull); + getter_AddRefs(subjPrincipal), nsnull); if (NS_FAILED(rv)) { return ThrowException(rv, cx); } @@ -301,6 +302,19 @@ WrapJSValue(JSContext *cx, JSObject *obj, jsval val, jsval *rval) return ThrowException(rv, cx); } + // If the subject can access both the source and object principals, then + // don't bother forcing the principal below. + if (!subsumes) { + PRBool subjSubsumes = PR_FALSE; + rv = subjPrincipal->Subsumes(srcObjPrincipal, &subjSubsumes); + if (NS_SUCCEEDED(rv) && subjSubsumes) { + rv = subjPrincipal->Subsumes(valObjPrincipal, &subjSubsumes); + if (NS_SUCCEEDED(rv) && subjSubsumes) { + subsumes = PR_TRUE; + } + } + } + if (!subsumes) { // The unsafe object we got the new object from can not access // the new object, force the wrapper we just created to use