Bug 956382 - Add AccessCheck::subsumesConsideringDomain and clean up other implementations. r=mrbkap

We now assert that we have a principal when we enter the wrap callback, and we
now have a convenient overload defined in nsIPrincipal.idl.
This commit is contained in:
Bobby Holley
2014-02-13 18:57:34 -08:00
parent 171cb8c80a
commit 9cbbe11542
2 changed files with 11 additions and 20 deletions

View File

@@ -42,18 +42,7 @@ AccessCheck::subsumes(JSCompartment *a, JSCompartment *b)
{ {
nsIPrincipal *aprin = GetCompartmentPrincipal(a); nsIPrincipal *aprin = GetCompartmentPrincipal(a);
nsIPrincipal *bprin = GetCompartmentPrincipal(b); nsIPrincipal *bprin = GetCompartmentPrincipal(b);
return aprin->Subsumes(bprin);
// If either a or b doesn't have principals, we don't have enough
// information to tell. Seeing as how this is Gecko, we are default-unsafe
// in this case.
if (!aprin || !bprin)
return true;
bool subsumes;
nsresult rv = aprin->Subsumes(bprin, &subsumes);
NS_ENSURE_SUCCESS(rv, false);
return subsumes;
} }
bool bool
@@ -68,15 +57,16 @@ AccessCheck::subsumesIgnoringDomain(JSCompartment *a, JSCompartment *b)
{ {
nsIPrincipal *aprin = GetCompartmentPrincipal(a); nsIPrincipal *aprin = GetCompartmentPrincipal(a);
nsIPrincipal *bprin = GetCompartmentPrincipal(b); nsIPrincipal *bprin = GetCompartmentPrincipal(b);
return aprin->SubsumesIgnoringDomain(bprin);
}
if (!aprin || !bprin) // Same as above, but considering document.domain.
return false; bool
AccessCheck::subsumesConsideringDomain(JSCompartment *a, JSCompartment *b)
bool subsumes; {
nsresult rv = aprin->SubsumesIgnoringDomain(bprin, &subsumes); nsIPrincipal *aprin = GetCompartmentPrincipal(a);
NS_ENSURE_SUCCESS(rv, false); nsIPrincipal *bprin = GetCompartmentPrincipal(b);
return aprin->SubsumesConsideringDomain(bprin);
return subsumes;
} }
// Does the compartment of the wrapper subsumes the compartment of the wrappee? // Does the compartment of the wrapper subsumes the compartment of the wrappee?

View File

@@ -21,6 +21,7 @@ class AccessCheck {
static bool subsumes(JSObject *a, JSObject *b); static bool subsumes(JSObject *a, JSObject *b);
static bool wrapperSubsumes(JSObject *wrapper); static bool wrapperSubsumes(JSObject *wrapper);
static bool subsumesIgnoringDomain(JSCompartment *a, JSCompartment *b); static bool subsumesIgnoringDomain(JSCompartment *a, JSCompartment *b);
static bool subsumesConsideringDomain(JSCompartment *a, JSCompartment *b);
static bool isChrome(JSCompartment *compartment); static bool isChrome(JSCompartment *compartment);
static bool isChrome(JSObject *obj); static bool isChrome(JSObject *obj);
static bool callerIsChrome(); static bool callerIsChrome();