Bug 868122 - Calculate the JS_SaveFrameChain optimization by directly examining the principal of the default compartment. r=mrbkap,gabor

This commit is contained in:
Bobby Holley 2013-05-06 16:53:10 -07:00
parent 2fcf1ab53b
commit c9228b2c97
3 changed files with 23 additions and 12 deletions

View File

@ -16,6 +16,8 @@
#include "mozilla/dom/BindingUtils.h"
using namespace mozilla;
using namespace JS;
using namespace xpc;
using mozilla::dom::DestroyProtoAndIfaceCache;
/***************************************************************************/
@ -75,18 +77,20 @@ XPCJSContextStack::Push(JSContext *cx)
XPCJSContextInfo &e = mStack[mStack.Length() - 1];
if (e.cx) {
if (e.cx == cx) {
nsIScriptSecurityManager* ssm = XPCWrapper::GetSecurityManager();
if (ssm) {
if (nsIPrincipal* globalObjectPrincipal = GetPrincipalFromCx(cx)) {
nsIPrincipal* subjectPrincipal = ssm->GetCxSubjectPrincipal(cx);
bool equals = false;
globalObjectPrincipal->Equals(subjectPrincipal, &equals);
if (equals) {
mStack.AppendElement(cx);
return true;
}
}
// The cx we're pushing is also stack-top. In general we still need to
// call JS_SaveFrameChain here. But if that would put us in a
// compartment that's same-origin with the current one, we can skip it.
nsIScriptSecurityManager* ssm = XPCWrapper::GetSecurityManager();
if ((e.cx == cx) && ssm) {
RootedObject defaultGlobal(cx, JS_GetGlobalObject(cx));
nsIPrincipal *currentPrincipal =
GetCompartmentPrincipal(js::GetContextCompartment(cx));
nsIPrincipal *defaultPrincipal = GetObjectPrincipal(defaultGlobal);
bool equal = false;
currentPrincipal->Equals(defaultPrincipal, &equal);
if (equal) {
mStack.AppendElement(cx);
return true;
}
}

View File

@ -363,6 +363,7 @@ bool StringToJsval(JSContext* cx, mozilla::dom::DOMString& str,
}
nsIPrincipal *GetCompartmentPrincipal(JSCompartment *compartment);
nsIPrincipal *GetObjectPrincipal(JSObject *obj);
bool IsXBLScope(JSCompartment *compartment);

View File

@ -35,6 +35,12 @@ GetCompartmentPrincipal(JSCompartment *compartment)
return nsJSPrincipals::get(JS_GetCompartmentPrincipals(compartment));
}
nsIPrincipal *
GetObjectPrincipal(JSObject *obj)
{
return GetCompartmentPrincipal(js::GetObjectCompartment(obj));
}
// Does the principal of compartment a subsume the principal of compartment b?
bool
AccessCheck::subsumes(JSCompartment *a, JSCompartment *b)