mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-17 15:25:52 +00:00
Bug 604368 - Share some code so that bug fixes fix both parts. r=peterv a=blocking beta7
This commit is contained in:
parent
d748fe33ff
commit
e444f80e5c
@ -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()
|
||||||
|
@ -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);
|
||||||
|
|
||||||
|
@ -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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user