Bug 1052089 - Add a System Principal accessor to nsXPConnect and use it in Sandbox creation. r=billm

nsContentUtils isn't ready by this point.
This commit is contained in:
Bobby Holley 2014-08-18 10:57:29 -07:00
parent 335a978404
commit c135b0217a
3 changed files with 15 additions and 2 deletions

View File

@ -911,7 +911,7 @@ xpc::CreateSandboxObject(JSContext *cx, MutableHandleValue vp, nsISupports *prin
// Don't try to mirror the properties that are set below.
AutoSkipPropertyMirroring askip(CompartmentPrivate::Get(sandbox));
bool allowComponents = nsContentUtils::IsSystemPrincipal(principal) ||
bool allowComponents = principal == nsXPConnect::SystemPrincipal() ||
nsContentUtils::IsExpandedPrincipal(principal);
if (options.wantComponents && allowComponents &&
!ObjectScope(sandbox)->AttachComponentsObject(cx))

View File

@ -54,8 +54,9 @@ bool nsXPConnect::gOnceAliveNowDead = false;
uint32_t nsXPConnect::gReportAllJSExceptions = 0;
// Global cache of the default script security manager (QI'd to
// nsIScriptSecurityManager)
// nsIScriptSecurityManager) and the system principal.
nsIScriptSecurityManager *nsXPConnect::gScriptSecurityManager = nullptr;
nsIPrincipal *nsXPConnect::gSystemPrincipal = nullptr;
const char XPC_CONTEXT_STACK_CONTRACTID[] = "@mozilla.org/js/xpc/ContextStack;1";
const char XPC_RUNTIME_CONTRACTID[] = "@mozilla.org/js/xpc/RuntimeService;1";
@ -102,6 +103,7 @@ nsXPConnect::~nsXPConnect()
// maps that our finalize callback depends on.
JS_GC(mRuntime->Runtime());
NS_RELEASE(gSystemPrincipal);
gScriptSecurityManager = nullptr;
// shutdown the logging system
@ -135,6 +137,8 @@ nsXPConnect::InitStatics()
// Fire up the SSM.
nsScriptSecurityManager::InitStatics();
gScriptSecurityManager = nsScriptSecurityManager::GetScriptSecurityManager();
gScriptSecurityManager->GetSystemPrincipal(&gSystemPrincipal);
MOZ_RELEASE_ASSERT(gSystemPrincipal);
// Initialize the SafeJSContext.
gSelf->mRuntime->GetJSContextStack()->InitSafeJSContext();

View File

@ -283,9 +283,17 @@ public:
static nsIScriptSecurityManager* SecurityManager()
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(gScriptSecurityManager);
return gScriptSecurityManager;
}
static nsIPrincipal* SystemPrincipal()
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(gSystemPrincipal);
return gSystemPrincipal;
}
// This returns an AddRef'd pointer. It does not do this with an 'out' param
// only because this form is required by the generic module macro:
// NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR
@ -339,6 +347,7 @@ private:
public:
static nsIScriptSecurityManager *gScriptSecurityManager;
static nsIPrincipal *gSystemPrincipal;
};
/***************************************************************************/