Bug 604368 - Share some code so that bug fixes fix both parts. r=peterv a=blocking beta7

This commit is contained in:
Blake Kaplan 2010-10-16 15:26:14 -07:00
parent d748fe33ff
commit e444f80e5c
3 changed files with 48 additions and 85 deletions

View File

@ -216,6 +216,50 @@ GetPrincipal(JSObject *obj)
return xpc->GetPrincipal(obj, PR_TRUE); return xpc->GetPrincipal(obj, PR_TRUE);
} }
bool
AccessCheck::documentDomainMakesSameOrigin(JSContext *cx, JSObject *obj)
{
JSObject *scope = nsnull;
JSStackFrame *fp = nsnull;
JS_FrameIterator(cx, &fp);
if (fp) {
while (fp->isDummyFrame()) {
if (!JS_FrameIterator(cx, &fp))
break;
}
if (fp)
scope = &fp->scopeChain();
}
if (!scope)
scope = JS_GetScopeChain(cx);
nsIPrincipal *subject;
nsIPrincipal *object;
{
JSAutoEnterCompartment ac;
if (!ac.enter(cx, scope))
return false;
subject = GetPrincipal(JS_GetGlobalForObject(cx, scope));
}
{
JSAutoEnterCompartment ac;
if (!ac.enter(cx, obj))
return false;
object = GetPrincipal(JS_GetGlobalForObject(cx, obj));
}
PRBool subsumes;
return NS_SUCCEEDED(subject->Subsumes(object, &subsumes)) && subsumes;
}
bool bool
AccessCheck::isCrossOriginAccessPermitted(JSContext *cx, JSObject *wrapper, jsid id, AccessCheck::isCrossOriginAccessPermitted(JSContext *cx, JSObject *wrapper, jsid id,
JSWrapper::Action act) JSWrapper::Action act)
@ -248,48 +292,8 @@ AccessCheck::isCrossOriginAccessPermitted(JSContext *cx, JSObject *wrapper, jsid
// We only reach this point for cross origin location objects (see // We only reach this point for cross origin location objects (see
// SameOriginOrCrossOriginAccessiblePropertiesOnly::check). // SameOriginOrCrossOriginAccessiblePropertiesOnly::check).
if (!IsLocation(name)) { if (!IsLocation(name) && documentDomainMakesSameOrigin(cx, obj))
JSObject *scope = nsnull; return true;
JSStackFrame *fp = nsnull;
JS_FrameIterator(cx, &fp);
if (fp) {
while (fp->isDummyFrame()) {
if (!JS_FrameIterator(cx, &fp))
break;
}
if (fp)
scope = &fp->scopeChain();
}
if (!scope)
scope = JS_GetScopeChain(cx);
nsIPrincipal *subject;
nsIPrincipal *object;
{
JSAutoEnterCompartment ac;
if (!ac.enter(cx, scope))
return false;
subject = GetPrincipal(JS_GetGlobalForObject(cx, scope));
}
{
JSAutoEnterCompartment ac;
if (!ac.enter(cx, obj))
return false;
object = GetPrincipal(JS_GetGlobalForObject(cx, obj));
}
PRBool subsumes;
if (NS_SUCCEEDED(subject->Subsumes(object, &subsumes)) && subsumes)
return true;
}
return (act == JSWrapper::SET) return (act == JSWrapper::SET)
? nsContentUtils::IsCallerTrustedForWrite() ? nsContentUtils::IsCallerTrustedForWrite()

View File

@ -53,6 +53,7 @@ class AccessCheck {
JSWrapper::Action act); JSWrapper::Action act);
static bool isSystemOnlyAccessPermitted(JSContext *cx); static bool isSystemOnlyAccessPermitted(JSContext *cx);
static bool isLocationObjectSameOrigin(JSContext *cx, JSObject *wrapper); static bool isLocationObjectSameOrigin(JSContext *cx, JSObject *wrapper);
static bool documentDomainMakesSameOrigin(JSContext *cx, JSObject *obj);
static bool needsSystemOnlyWrapper(JSObject *obj); static bool needsSystemOnlyWrapper(JSObject *obj);

View File

@ -415,49 +415,7 @@ Transparent(JSContext *cx, JSObject *wrapper)
return true; return true;
} }
JSObject *scope = nsnull; return AccessCheck::documentDomainMakesSameOrigin(cx, wrapper->unwrap());
JSStackFrame *fp = nsnull;
JS_FrameIterator(cx, &fp);
if (fp) {
while (fp->isDummyFrame()) {
if (!JS_FrameIterator(cx, &fp))
break;
}
if (fp)
scope = &fp->scopeChain();
}
if (!scope)
scope = JS_GetScopeChain(cx);
nsIPrincipal *subject;
nsIPrincipal *object;
nsIXPConnect *xpc = nsXPConnect::GetXPConnect();
{
JSAutoEnterCompartment ac;
if (!ac.enter(cx, scope))
return false;
subject = xpc->GetPrincipal(JS_GetGlobalForObject(cx, scope), PR_TRUE);
}
{
JSAutoEnterCompartment ac;
JSObject *obj = wrapper->unwrap();
if (!ac.enter(cx, obj))
return false;
object = xpc->GetPrincipal(JS_GetGlobalForObject(cx, obj), PR_TRUE);
}
PRBool subsumes;
if (NS_SUCCEEDED(subject->Subsumes(object, &subsumes)) && subsumes)
return true;
return false;
} }
namespace XrayUtils { namespace XrayUtils {