mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-29 07:42:04 +00:00
Bug 820170 - Turning BackstagePass into non-singleton. r=bholley
This commit is contained in:
parent
716156d923
commit
2edb19076f
@ -1355,6 +1355,11 @@ public:
|
||||
*/
|
||||
static bool IsSystemPrincipal(nsIPrincipal* aPrincipal);
|
||||
|
||||
/**
|
||||
* Gets the system principal from the security manager.
|
||||
*/
|
||||
static nsIPrincipal* GetSystemPrincipal();
|
||||
|
||||
/**
|
||||
* *aResourcePrincipal is a principal describing who may access the contents
|
||||
* of a resource. The resource can only be consumed by a principal that
|
||||
|
@ -4698,6 +4698,15 @@ nsContentUtils::IsSystemPrincipal(nsIPrincipal* aPrincipal)
|
||||
return NS_SUCCEEDED(rv) && isSystem;
|
||||
}
|
||||
|
||||
nsIPrincipal*
|
||||
nsContentUtils::GetSystemPrincipal()
|
||||
{
|
||||
nsCOMPtr<nsIPrincipal> sysPrin;
|
||||
nsresult rv = sSecurityManager->GetSystemPrincipal(getter_AddRefs(sysPrin));
|
||||
MOZ_ASSERT(NS_SUCCEEDED(rv) && sysPrin);
|
||||
return sysPrin;
|
||||
}
|
||||
|
||||
bool
|
||||
nsContentUtils::CombineResourcePrincipals(nsCOMPtr<nsIPrincipal>* aResourcePrincipal,
|
||||
nsIPrincipal* aExtraPrincipal)
|
||||
|
@ -39,6 +39,8 @@
|
||||
#include "nsThreadUtils.h"
|
||||
#include "nsXULAppAPI.h"
|
||||
|
||||
#include "BackstagePass.h"
|
||||
|
||||
#include "TestShellChild.h"
|
||||
#include "TestShellParent.h"
|
||||
|
||||
@ -1035,15 +1037,16 @@ XPCShellEnvironment::Init()
|
||||
|
||||
AutoContextPusher pusher(this);
|
||||
|
||||
nsCOMPtr<nsIXPCScriptable> backstagePass;
|
||||
rv = rtsvc->GetBackstagePass(getter_AddRefs(backstagePass));
|
||||
nsRefPtr<BackstagePass> backstagePass;
|
||||
rv = NS_NewBackstagePass(getter_AddRefs(backstagePass));
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_ERROR("Failed to get backstage pass from rtsvc!");
|
||||
NS_ERROR("Failed to create backstage pass!");
|
||||
return false;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||
rv = xpc->InitClassesWithNewWrappedGlobal(cx, backstagePass,
|
||||
rv = xpc->InitClassesWithNewWrappedGlobal(cx,
|
||||
static_cast<nsIGlobalObject *>(backstagePass),
|
||||
principal, 0,
|
||||
JS::SystemZone,
|
||||
getter_AddRefs(holder));
|
||||
@ -1059,6 +1062,7 @@ XPCShellEnvironment::Init()
|
||||
return false;
|
||||
}
|
||||
|
||||
backstagePass->SetGlobalObject(globalObj);
|
||||
|
||||
{
|
||||
JSAutoRequest ar(cx);
|
||||
|
@ -9,13 +9,12 @@
|
||||
[ptr] native JSRuntime(JSRuntime);
|
||||
native JSGCCallback(JSGCCallback);
|
||||
|
||||
interface nsIXPCScriptable;
|
||||
interface nsIBackstagePass;
|
||||
|
||||
[uuid(364bcec3-7034-4a4e-bff5-b3f796ca9771)]
|
||||
[uuid(991c0749-a22e-476b-9428-a373df037455)]
|
||||
interface nsIJSRuntimeService : nsISupports
|
||||
{
|
||||
readonly attribute JSRuntime runtime;
|
||||
readonly attribute nsIXPCScriptable backstagePass;
|
||||
|
||||
/**
|
||||
* Register additional GC callback which will run after the
|
||||
|
@ -736,11 +736,12 @@ mozJSComponentLoader::PrepareObjectForLocation(JSCLContextHelper& aCx,
|
||||
NS_ENSURE_SUCCESS(rv, nullptr);
|
||||
|
||||
if (!mLoaderGlobal) {
|
||||
nsCOMPtr<nsIXPCScriptable> backstagePass;
|
||||
rv = mRuntimeService->GetBackstagePass(getter_AddRefs(backstagePass));
|
||||
nsRefPtr<BackstagePass> backstagePass;
|
||||
rv = NS_NewBackstagePass(getter_AddRefs(backstagePass));
|
||||
NS_ENSURE_SUCCESS(rv, nullptr);
|
||||
|
||||
rv = xpc->InitClassesWithNewWrappedGlobal(aCx, backstagePass,
|
||||
rv = xpc->InitClassesWithNewWrappedGlobal(aCx,
|
||||
static_cast<nsIGlobalObject *>(backstagePass),
|
||||
mSystemPrincipal,
|
||||
0,
|
||||
JS::SystemZone,
|
||||
@ -751,6 +752,8 @@ mozJSComponentLoader::PrepareObjectForLocation(JSCLContextHelper& aCx,
|
||||
rv = holder->GetJSObject(&global);
|
||||
NS_ENSURE_SUCCESS(rv, nullptr);
|
||||
|
||||
backstagePass->SetGlobalObject(global);
|
||||
|
||||
JSAutoCompartment ac(aCx, global);
|
||||
if (!JS_DefineFunctions(aCx, global, gGlobalFun) ||
|
||||
!JS_DefineProfilingFunctions(aCx, global)) {
|
||||
|
@ -45,6 +45,7 @@
|
||||
#include "nsJSPrincipals.h"
|
||||
#include "xpcpublic.h"
|
||||
#include "nsXULAppAPI.h"
|
||||
#include "BackstagePass.h"
|
||||
#ifdef XP_MACOSX
|
||||
#include "xpcshellMacUtils.h"
|
||||
#endif
|
||||
@ -1882,16 +1883,17 @@ main(int argc, char **argv, char **envp)
|
||||
return 1;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIXPCScriptable> backstagePass;
|
||||
nsresult rv = rtsvc->GetBackstagePass(getter_AddRefs(backstagePass));
|
||||
nsRefPtr<BackstagePass> backstagePass;
|
||||
rv = NS_NewBackstagePass(getter_AddRefs(backstagePass));
|
||||
if (NS_FAILED(rv)) {
|
||||
fprintf(gErrFile, "+++ Failed to get backstage pass from rtsvc: %8x\n",
|
||||
fprintf(gErrFile, "+++ Failed to create BackstagePass: %8x\n",
|
||||
static_cast<uint32_t>(rv));
|
||||
return 1;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||
rv = xpc->InitClassesWithNewWrappedGlobal(cx, backstagePass,
|
||||
rv = xpc->InitClassesWithNewWrappedGlobal(cx,
|
||||
static_cast<nsIGlobalObject *>(backstagePass),
|
||||
systemprincipal,
|
||||
0,
|
||||
JS::SystemZone,
|
||||
@ -1905,6 +1907,8 @@ main(int argc, char **argv, char **envp)
|
||||
return 1;
|
||||
}
|
||||
|
||||
backstagePass->SetGlobalObject(glob);
|
||||
|
||||
JS_BeginRequest(cx);
|
||||
{
|
||||
JSAutoCompartment ac(cx, glob);
|
||||
|
52
js/xpconnect/src/BackstagePass.h
Normal file
52
js/xpconnect/src/BackstagePass.h
Normal file
@ -0,0 +1,52 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef BackstagePass_h__
|
||||
#define BackstagePass_h__
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nsIGlobalObject.h"
|
||||
|
||||
class BackstagePass : public nsIGlobalObject,
|
||||
public nsIXPCScriptable,
|
||||
public nsIClassInfo
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIXPCSCRIPTABLE
|
||||
NS_DECL_NSICLASSINFO
|
||||
|
||||
virtual nsIPrincipal* GetPrincipal() {
|
||||
return mPrincipal;
|
||||
}
|
||||
|
||||
virtual JSObject* GetGlobalJSObject() {
|
||||
return mGlobal;
|
||||
}
|
||||
|
||||
virtual void ForgetGlobalObject() {
|
||||
mGlobal = NULL;
|
||||
}
|
||||
|
||||
virtual void SetGlobalObject(JSObject* global) {
|
||||
mGlobal = global;
|
||||
}
|
||||
|
||||
BackstagePass(nsIPrincipal *prin) :
|
||||
mPrincipal(prin)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~BackstagePass() { }
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsIPrincipal> mPrincipal;
|
||||
JSObject *mGlobal;
|
||||
};
|
||||
|
||||
NS_EXPORT nsresult
|
||||
NS_NewBackstagePass(BackstagePass** ret);
|
||||
|
||||
#endif // BackstagePass_h__
|
@ -18,7 +18,9 @@ EXPORTS = \
|
||||
xpcObjectHelper.h \
|
||||
xpcpublic.h \
|
||||
XPCJSMemoryReporter.h \
|
||||
GeneratedEvents.h
|
||||
GeneratedEvents.h \
|
||||
BackstagePass.h \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
nsScriptError.cpp \
|
||||
|
@ -7,9 +7,13 @@
|
||||
#include "xpcprivate.h"
|
||||
|
||||
#include "mozilla/dom/workers/Workers.h"
|
||||
#include "nsIScriptSecurityManager.h"
|
||||
#include "nsContentUtils.h"
|
||||
|
||||
using mozilla::dom::workers::ResolveWorkerClasses;
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN(BackstagePass)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIGlobalObject)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIXPCScriptable)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIClassInfo)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIScriptObjectPrincipal)
|
||||
@ -23,6 +27,8 @@ NS_IMPL_THREADSAFE_RELEASE(BackstagePass)
|
||||
#define XPC_MAP_CLASSNAME BackstagePass
|
||||
#define XPC_MAP_QUOTED_CLASSNAME "BackstagePass"
|
||||
#define XPC_MAP_WANT_NEWRESOLVE
|
||||
#define XPC_MAP_WANT_FINALIZE
|
||||
|
||||
#define XPC_MAP_FLAGS nsIXPCScriptable::USE_JSSTUB_FOR_ADDPROPERTY | \
|
||||
nsIXPCScriptable::USE_JSSTUB_FOR_DELPROPERTY | \
|
||||
nsIXPCScriptable::USE_JSSTUB_FOR_SETPROPERTY | \
|
||||
@ -152,3 +158,21 @@ BackstagePass::GetClassIDNoAlloc(nsCID *aClassIDNoAlloc)
|
||||
{
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
BackstagePass::Finalize(nsIXPConnectWrappedNative *wrapper, JSFreeOp * fop, JSObject * obj)
|
||||
{
|
||||
nsCOMPtr<nsIGlobalObject> bsp(do_QueryWrappedNative(wrapper));
|
||||
MOZ_ASSERT(bsp);
|
||||
static_cast<BackstagePass*>(bsp.get())->ForgetGlobalObject();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
NS_NewBackstagePass(BackstagePass** ret)
|
||||
{
|
||||
nsRefPtr<BackstagePass> bsp = new BackstagePass(
|
||||
nsContentUtils::GetSystemPrincipal());
|
||||
bsp.forget(ret);
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -1983,27 +1983,6 @@ nsXPConnect::GetRuntime(JSRuntime **runtime)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* attribute nsIXPCScriptable backstagePass; */
|
||||
NS_IMETHODIMP
|
||||
nsXPConnect::GetBackstagePass(nsIXPCScriptable **bsp)
|
||||
{
|
||||
if (!mBackstagePass) {
|
||||
nsCOMPtr<nsIPrincipal> sysprin;
|
||||
nsCOMPtr<nsIScriptSecurityManager> secman =
|
||||
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID);
|
||||
if (!secman)
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
if (NS_FAILED(secman->GetSystemPrincipal(getter_AddRefs(sysprin))))
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
mBackstagePass = new BackstagePass(sysprin);
|
||||
if (!mBackstagePass)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
NS_ADDREF(*bsp = mBackstagePass);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* [noscript, notxpcom] void registerGCCallback(in JSGCCallback func); */
|
||||
NS_IMETHODIMP_(void)
|
||||
nsXPConnect::RegisterGCCallback(JSGCCallback func)
|
||||
|
@ -179,6 +179,7 @@
|
||||
#include "nsIThreadInternal.h"
|
||||
|
||||
#include "SandboxPrivate.h"
|
||||
#include "BackstagePass.h"
|
||||
|
||||
#ifdef XP_WIN
|
||||
// Nasty MS defines
|
||||
@ -579,8 +580,6 @@ private:
|
||||
// watch out for this, we'll do an unmatched |pop| on the context stack.
|
||||
uint16_t mEventDepth;
|
||||
|
||||
nsCOMPtr<nsIXPCScriptable> mBackstagePass;
|
||||
|
||||
static uint32_t gReportAllJSExceptions;
|
||||
static JSBool gDebugMode;
|
||||
static JSBool gDesiredDebugMode;
|
||||
@ -3685,31 +3684,6 @@ private:
|
||||
};
|
||||
|
||||
/***************************************************************************/
|
||||
#include "nsIScriptSecurityManager.h"
|
||||
|
||||
class BackstagePass : public nsIScriptObjectPrincipal,
|
||||
public nsIXPCScriptable,
|
||||
public nsIClassInfo
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIXPCSCRIPTABLE
|
||||
NS_DECL_NSICLASSINFO
|
||||
|
||||
virtual nsIPrincipal* GetPrincipal() {
|
||||
return mPrincipal;
|
||||
}
|
||||
|
||||
BackstagePass(nsIPrincipal *prin) :
|
||||
mPrincipal(prin)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~BackstagePass() { }
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsIPrincipal> mPrincipal;
|
||||
};
|
||||
// 'Components' object
|
||||
|
||||
class nsXPCComponents : public nsIXPCComponents,
|
||||
|
Loading…
Reference in New Issue
Block a user