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 6771e71f15
commit 7a8e0ba5b9
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 *bprin = GetCompartmentPrincipal(b);
// 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;
return aprin->Subsumes(bprin);
}
bool
@ -68,15 +57,16 @@ AccessCheck::subsumesIgnoringDomain(JSCompartment *a, JSCompartment *b)
{
nsIPrincipal *aprin = GetCompartmentPrincipal(a);
nsIPrincipal *bprin = GetCompartmentPrincipal(b);
return aprin->SubsumesIgnoringDomain(bprin);
}
if (!aprin || !bprin)
return false;
bool subsumes;
nsresult rv = aprin->SubsumesIgnoringDomain(bprin, &subsumes);
NS_ENSURE_SUCCESS(rv, false);
return subsumes;
// Same as above, but considering document.domain.
bool
AccessCheck::subsumesConsideringDomain(JSCompartment *a, JSCompartment *b)
{
nsIPrincipal *aprin = GetCompartmentPrincipal(a);
nsIPrincipal *bprin = GetCompartmentPrincipal(b);
return aprin->SubsumesConsideringDomain(bprin);
}
// 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 wrapperSubsumes(JSObject *wrapper);
static bool subsumesIgnoringDomain(JSCompartment *a, JSCompartment *b);
static bool subsumesConsideringDomain(JSCompartment *a, JSCompartment *b);
static bool isChrome(JSCompartment *compartment);
static bool isChrome(JSObject *obj);
static bool callerIsChrome();