Fix for bug 560199 (Link XPConnect and caps into layout). r=jst.

--HG--
extra : rebase_source : 5141822e9d560019ffc1e0cb0264782aa8aa7a99
This commit is contained in:
Peter Van der Beken 2010-04-11 15:55:24 +02:00
Родитель 29ae1a0599
Коммит df91a46a76
15 изменённых файлов: 605 добавлений и 300 удалений

Просмотреть файл

@ -57,6 +57,7 @@
#include "nsIObserver.h"
#include "pldhash.h"
#include "plstr.h"
#include "nsIScriptExternalNameSet.h"
class nsIDocShell;
class nsString;
@ -650,4 +651,20 @@ private:
static JSRuntime *sRuntime;
};
#define NS_SECURITYNAMESET_CID \
{ 0x7c02eadc, 0x76, 0x4d03, \
{ 0x99, 0x8d, 0x80, 0xd7, 0x79, 0xc4, 0x85, 0x89 } }
#define NS_SECURITYNAMESET_CONTRACTID "@mozilla.org/security/script/nameset;1"
class nsSecurityNameSet : public nsIScriptExternalNameSet
{
public:
nsSecurityNameSet();
virtual ~nsSecurityNameSet();
NS_DECL_ISUPPORTS
NS_IMETHOD InitializeNameSet(nsIScriptContext* aScriptContext);
};
#endif // nsScriptSecurityManager_h__

Просмотреть файл

@ -43,11 +43,8 @@ VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = caps
LIBRARY_NAME = caps
EXPORT_LIBRARY = 1
IS_COMPONENT = 1
MODULE_NAME = nsSecurityManagerModule
GRE_MODULE = 1
LIBRARY_NAME = caps_s
FORCE_STATIC_LIB = 1
LIBXUL_LIBRARY = 1
@ -65,14 +62,8 @@ ifdef XPC_IDISPATCH_SUPPORT
DEFINES += -DXPC_IDISPATCH_SUPPORT
endif
EXTRA_DSO_LDOPTS = \
$(LIBS_DIR) \
$(ZLIB_LIBS) \
$(MOZ_JS_LIBS) \
$(MOZ_COMPONENT_LIBS) \
$(NULL)
include $(topsrcdir)/config/rules.mk
INCLUDES += -I$(srcdir)/../include
INCLUDES += -I$(srcdir)/../include \
-I$(topsrcdir)/js/src/xpconnect/src

Просмотреть файл

@ -35,6 +35,7 @@
*
* ***** END LICENSE BLOCK ***** */
#include "xpcprivate.h"
#include "nsString.h"
#include "nsIObjectOutputStream.h"
#include "nsIObjectInputStream.h"
@ -170,8 +171,7 @@ nsTranscodeJSPrincipals(JSXDRState *xdr, JSPrincipals **jsprinp)
nsresult
nsJSPrincipals::Startup()
{
static const char rtsvc_id[] = "@mozilla.org/js/xpc/RuntimeService;1";
nsCOMPtr<nsIJSRuntimeService> rtsvc(do_GetService(rtsvc_id));
nsCOMPtr<nsIJSRuntimeService> rtsvc = nsXPConnect::GetXPConnect();
if (!rtsvc)
return NS_ERROR_FAILURE;

Просмотреть файл

@ -40,6 +40,7 @@
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "xpcprivate.h"
#include "nsScriptSecurityManager.h"
#include "nsIServiceManager.h"
#include "nsIScriptObjectPrincipal.h"
@ -3367,11 +3368,12 @@ nsScriptSecurityManager::nsScriptSecurityManager(void)
nsresult nsScriptSecurityManager::Init()
{
nsresult rv = CallGetService(nsIXPConnect::GetCID(), &sXPConnect);
NS_ENSURE_SUCCESS(rv, rv);
nsXPConnect* xpconnect = nsXPConnect::GetXPConnect();
if (!xpconnect)
return NS_ERROR_FAILURE;
rv = CallGetService("@mozilla.org/js/xpc/ContextStack;1", &sJSContextStack);
NS_ENSURE_SUCCESS(rv, rv);
NS_ADDREF(sXPConnect = xpconnect);
NS_ADDREF(sJSContextStack = xpconnect);
JSContext* cx = GetSafeJSContext();
if (!cx) return NS_ERROR_FAILURE; // this can happen of xpt loading fails
@ -3383,7 +3385,7 @@ nsresult nsScriptSecurityManager::Init()
InitPrefs();
rv = CallGetService(NS_IOSERVICE_CONTRACTID, &sIOService);
nsresult rv = CallGetService(NS_IOSERVICE_CONTRACTID, &sIOService);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIStringBundleService> bundleService = do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
@ -3404,7 +3406,7 @@ nsresult nsScriptSecurityManager::Init()
//-- Register security check callback in the JS engine
// Currently this is used to control access to function.caller
nsCOMPtr<nsIJSRuntimeService> runtimeService =
do_GetService("@mozilla.org/js/xpc/RuntimeService;1", &rv);
do_QueryInterface(sXPConnect, &rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = runtimeService->GetRuntime(&sRuntime);

Просмотреть файл

@ -46,7 +46,6 @@
#include "nsSystemPrincipal.h"
#include "nsNullPrincipal.h"
#include "nsIScriptNameSpaceManager.h"
#include "nsIScriptExternalNameSet.h"
#include "nsIScriptContext.h"
#include "nsICategoryManager.h"
#include "nsXPIDLString.h"
@ -61,22 +60,6 @@
// nsSecurityNameSet //
///////////////////////
#define NS_SECURITYNAMESET_CID \
{ 0x7c02eadc, 0x76, 0x4d03, \
{ 0x99, 0x8d, 0x80, 0xd7, 0x79, 0xc4, 0x85, 0x89 } }
#define NS_SECURITYNAMESET_CONTRACTID "@mozilla.org/security/script/nameset;1"
class nsSecurityNameSet : public nsIScriptExternalNameSet
{
public:
nsSecurityNameSet();
virtual ~nsSecurityNameSet();
NS_DECL_ISUPPORTS
NS_IMETHOD InitializeNameSet(nsIScriptContext* aScriptContext);
};
nsSecurityNameSet::nsSecurityNameSet()
{
}
@ -337,171 +320,3 @@ nsSecurityNameSet::InitializeNameSet(nsIScriptContext* aScriptContext)
? NS_OK
: NS_ERROR_FAILURE;
}
NS_GENERIC_FACTORY_CONSTRUCTOR(nsPrincipal)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSecurityNameSet)
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsSystemPrincipal,
nsScriptSecurityManager::SystemPrincipalSingletonConstructor)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsNullPrincipal, Init)
NS_DECL_CLASSINFO(nsPrincipal)
NS_DECL_CLASSINFO(nsSystemPrincipal)
NS_DECL_CLASSINFO(nsNullPrincipal)
static NS_IMETHODIMP
Construct_nsIScriptSecurityManager(nsISupports *aOuter, REFNSIID aIID,
void **aResult)
{
if (!aResult)
return NS_ERROR_NULL_POINTER;
*aResult = nsnull;
if (aOuter)
return NS_ERROR_NO_AGGREGATION;
nsScriptSecurityManager *obj = nsScriptSecurityManager::GetScriptSecurityManager();
if (!obj)
return NS_ERROR_OUT_OF_MEMORY;
if (NS_FAILED(obj->QueryInterface(aIID, aResult)))
return NS_ERROR_FAILURE;
return NS_OK;
}
static NS_METHOD
RegisterSecurityNameSet(nsIComponentManager *aCompMgr,
nsIFile *aPath,
const char *registryLocation,
const char *componentType,
const nsModuleComponentInfo *info)
{
nsresult rv = NS_OK;
nsCOMPtr<nsICategoryManager> catman =
do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
if (NS_FAILED(rv))
return rv;
nsXPIDLCString previous;
rv = catman->AddCategoryEntry(JAVASCRIPT_GLOBAL_STATIC_NAMESET_CATEGORY,
"PrivilegeManager",
NS_SECURITYNAMESET_CONTRACTID,
PR_TRUE, PR_TRUE, getter_Copies(previous));
NS_ENSURE_SUCCESS(rv, rv);
rv = catman->AddCategoryEntry("app-startup", "Script Security Manager",
"service," NS_SCRIPTSECURITYMANAGER_CONTRACTID,
PR_TRUE, PR_TRUE,
getter_Copies(previous));
NS_ENSURE_SUCCESS(rv, rv);
return rv;
}
static const nsModuleComponentInfo capsComponentInfo[] =
{
{ NS_SCRIPTSECURITYMANAGER_CLASSNAME,
NS_SCRIPTSECURITYMANAGER_CID,
NS_SCRIPTSECURITYMANAGER_CONTRACTID,
Construct_nsIScriptSecurityManager,
RegisterSecurityNameSet,
nsnull,
nsnull,
nsnull,
nsnull,
nsnull,
nsIClassInfo::MAIN_THREAD_ONLY
},
{ NS_SCRIPTSECURITYMANAGER_CLASSNAME,
NS_SCRIPTSECURITYMANAGER_CID,
NS_GLOBAL_PREF_SECURITY_CHECK,
Construct_nsIScriptSecurityManager,
RegisterSecurityNameSet,
nsnull,
nsnull,
nsnull,
nsnull,
nsnull,
nsIClassInfo::MAIN_THREAD_ONLY
},
{ NS_SCRIPTSECURITYMANAGER_CLASSNAME,
NS_SCRIPTSECURITYMANAGER_CID,
NS_GLOBAL_CHANNELEVENTSINK_CONTRACTID,
Construct_nsIScriptSecurityManager,
RegisterSecurityNameSet,
nsnull,
nsnull,
nsnull,
nsnull,
nsnull,
nsIClassInfo::MAIN_THREAD_ONLY
},
{ NS_PRINCIPAL_CLASSNAME,
NS_PRINCIPAL_CID,
NS_PRINCIPAL_CONTRACTID,
nsPrincipalConstructor,
nsnull,
nsnull,
nsnull,
NS_CI_INTERFACE_GETTER_NAME(nsPrincipal),
nsnull,
&NS_CLASSINFO_NAME(nsPrincipal),
nsIClassInfo::MAIN_THREAD_ONLY | nsIClassInfo::EAGER_CLASSINFO
},
{ NS_SYSTEMPRINCIPAL_CLASSNAME,
NS_SYSTEMPRINCIPAL_CID,
NS_SYSTEMPRINCIPAL_CONTRACTID,
nsSystemPrincipalConstructor,
nsnull,
nsnull,
nsnull,
NS_CI_INTERFACE_GETTER_NAME(nsSystemPrincipal),
nsnull,
&NS_CLASSINFO_NAME(nsSystemPrincipal),
nsIClassInfo::SINGLETON | nsIClassInfo::MAIN_THREAD_ONLY |
nsIClassInfo::EAGER_CLASSINFO
},
{ NS_NULLPRINCIPAL_CLASSNAME,
NS_NULLPRINCIPAL_CID,
NS_NULLPRINCIPAL_CONTRACTID,
nsNullPrincipalConstructor,
nsnull,
nsnull,
nsnull,
NS_CI_INTERFACE_GETTER_NAME(nsNullPrincipal),
nsnull,
&NS_CLASSINFO_NAME(nsNullPrincipal),
nsIClassInfo::MAIN_THREAD_ONLY | nsIClassInfo::EAGER_CLASSINFO
},
{ "Security Script Name Set",
NS_SECURITYNAMESET_CID,
NS_SECURITYNAMESET_CONTRACTID,
nsSecurityNameSetConstructor,
nsnull,
nsnull,
nsnull,
nsnull,
nsnull,
nsnull,
nsIClassInfo::MAIN_THREAD_ONLY
}
};
void
CapsModuleDtor(nsIModule* thisModules)
{
nsScriptSecurityManager::Shutdown();
}
NS_IMPL_NSGETMODULE_WITH_DTOR(nsSecurityManagerModule, capsComponentInfo,
CapsModuleDtor)

Просмотреть файл

@ -177,6 +177,8 @@ INCLUDES += \
-I$(srcdir)/../../../dom/base \
-I$(srcdir)/../../xml/document/src \
-I$(topsrcdir)/xpcom/io \
-I$(topsrcdir)/js/src/xpconnect/src \
-I$(topsrcdir)/caps/include \
$(NULL)
DEFINES += -D_IMPL_NS_LAYOUT

Просмотреть файл

@ -193,6 +193,8 @@ static NS_DEFINE_CID(kXTFServiceCID, NS_XTFSERVICE_CID);
#include "jsdate.h"
#include "jsregexp.h"
#include "jstypedarray.h"
#include "xpcprivate.h"
#include "nsScriptSecurityManager.h"
using namespace mozilla::dom;
@ -357,21 +359,22 @@ nsContentUtils::Init()
sPrefCacheData = new nsTArray<nsAutoPtr<PrefCacheData> >();
nsresult rv = CallGetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID,
&sSecurityManager);
NS_ENSURE_SUCCESS(rv, rv);
// It's ok to not have a pref service.
CallGetService(NS_PREFSERVICE_CONTRACTID, &sPrefBranch);
rv = NS_GetNameSpaceManager(&sNameSpaceManager);
nsresult rv = NS_GetNameSpaceManager(&sNameSpaceManager);
NS_ENSURE_SUCCESS(rv, rv);
rv = CallGetService(nsIXPConnect::GetCID(), &sXPConnect);
NS_ENSURE_SUCCESS(rv, rv);
nsXPConnect* xpconnect = nsXPConnect::GetXPConnect();
NS_ENSURE_TRUE(xpconnect, NS_ERROR_FAILURE);
rv = CallGetService(kJSStackContractID, &sThreadJSContextStack);
NS_ENSURE_SUCCESS(rv, rv);
sXPConnect = xpconnect;
sThreadJSContextStack = xpconnect;
sSecurityManager = nsScriptSecurityManager::GetScriptSecurityManager();
if(!sSecurityManager)
return NS_ERROR_FAILURE;
NS_ADDREF(sSecurityManager);
rv = CallGetService(NS_IOSERVICE_CONTRACTID, &sIOService);
if (NS_FAILED(rv)) {
@ -976,10 +979,9 @@ nsContentUtils::Shutdown()
NS_IF_RELEASE(sStringBundleService);
NS_IF_RELEASE(sConsoleService);
NS_IF_RELEASE(sDOMScriptObjectFactory);
if (sJSGCThingRootCount == 0 && sXPConnect)
NS_RELEASE(sXPConnect);
sXPConnect = nsnull;
sThreadJSContextStack = nsnull;
NS_IF_RELEASE(sSecurityManager);
NS_IF_RELEASE(sThreadJSContextStack);
NS_IF_RELEASE(sNameSpaceManager);
NS_IF_RELEASE(sParserService);
NS_IF_RELEASE(sIOService);
@ -4178,10 +4180,14 @@ nsresult
nsContentUtils::HoldJSObjects(void* aScriptObjectHolder,
nsScriptObjectTracer* aTracer)
{
NS_ENSURE_TRUE(sXPConnect, NS_ERROR_UNEXPECTED);
nsresult rv = sXPConnect->AddJSHolder(aScriptObjectHolder, aTracer);
NS_ENSURE_SUCCESS(rv, rv);
++sJSGCThingRootCount;
if (sJSGCThingRootCount++ == 0) {
nsLayoutStatics::AddRef();
}
NS_LOG_ADDREF(sXPConnect, sJSGCThingRootCount, "HoldJSObjects",
sizeof(void*));
@ -4194,8 +4200,8 @@ nsContentUtils::DropJSObjects(void* aScriptObjectHolder)
{
NS_LOG_RELEASE(sXPConnect, sJSGCThingRootCount - 1, "HoldJSObjects");
nsresult rv = sXPConnect->RemoveJSHolder(aScriptObjectHolder);
if (--sJSGCThingRootCount == 0 && !sInitialized) {
NS_RELEASE(sXPConnect);
if (--sJSGCThingRootCount == 0) {
nsLayoutStatics::Release();
}
return rv;
}

Просмотреть файл

@ -45,6 +45,8 @@ VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = xpconnect
ifeq (xpconnect, $(findstring xpconnect, $(BUILD_MODULES)))
LIBRARY_NAME = xpconnect
EXPORT_LIBRARY = 1
SHORT_LIBNAME = xpconect
@ -55,13 +57,12 @@ ifeq ($(OS_ARCH)$(MOZ_ENABLE_LIBXUL),WINNT)
LIBRARY_NAME = xpc32$(VERSION_NUMBER)
SHORT_LIBNAME = xpc32$(VERSION_NUMBER)
endif
else
LIBRARY_NAME = xpconnect_s
FORCE_STATIC_LIB = 1
endif
LIBXUL_LIBRARY = 1
# These modules are required because the auto-generated file
# dom_quickstubs.cpp #includes header files from many places.
CPPSRCS = \
nsScriptError.cpp \
nsXPConnect.cpp \
@ -118,6 +119,7 @@ LOCAL_INCLUDES = \
-I$(srcdir)/../loader \
-I$(topsrcdir)/js/src \
-I$(topsrcdir)/js/src/nanojit \
-I$(topsrcdir)/caps/include \
$(NULL)
EXTRA_DSO_LDOPTS += \

Просмотреть файл

@ -40,73 +40,13 @@
/* Module level methods. */
#include "xpcprivate.h"
#ifdef MOZ_JSLOADER
#include "mozJSLoaderConstructors.h"
#endif
/* Module implementation for the xpconnect library. */
NS_DECL_CLASSINFO(XPCVariant)
// {DC524540-487E-4501-9AC7-AAA784B17C1C}
#define XPCVARIANT_CID \
{0xdc524540, 0x487e, 0x4501, \
{ 0x9a, 0xc7, 0xaa, 0xa7, 0x84, 0xb1, 0x7c, 0x1c } }
#define XPCVARIANT_CONTRACTID "@mozilla.org/xpcvariant;1"
#define XPC_JSCONTEXT_STACK_ITERATOR_CONTRACTID "@mozilla.org/js/xpc/ContextStackIterator;1"
// {FE4F7592-C1FC-4662-AC83-538841318803}
#define SCRIPTABLE_INTERFACES_CID \
{0xfe4f7592, 0xc1fc, 0x4662, \
{ 0xac, 0x83, 0x53, 0x88, 0x41, 0x31, 0x88, 0x3 } }
NS_GENERIC_FACTORY_CONSTRUCTOR(nsJSID)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsXPCException)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsXPCJSContextStackIterator)
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIXPConnect, nsXPConnect::GetSingleton)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsScriptError)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsXPCComponents_Interfaces)
#ifdef XPC_IDISPATCH_SUPPORT
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIDispatchSupport, nsDispatchSupport::GetSingleton)
#endif
NS_DECL_CLASSINFO(nsXPCException)
#ifdef XPCONNECT_STANDALONE
#define NO_SUBSCRIPT_LOADER
#endif
static const nsModuleComponentInfo components[] = {
{nsnull, NS_JS_ID_CID, XPC_ID_CONTRACTID, nsJSIDConstructor },
{nsnull, NS_XPCONNECT_CID, XPC_XPCONNECT_CONTRACTID, nsIXPConnectConstructor },
{nsnull, NS_XPC_THREAD_JSCONTEXT_STACK_CID, XPC_CONTEXT_STACK_CONTRACTID, nsIXPConnectConstructor },
{nsnull, NS_XPCEXCEPTION_CID, XPC_EXCEPTION_CONTRACTID, nsXPCExceptionConstructor, nsnull, nsnull, nsnull, NS_CI_INTERFACE_GETTER_NAME(nsXPCException), nsnull, &NS_CLASSINFO_NAME(nsXPCException), nsIClassInfo::DOM_OBJECT },
{nsnull, NS_JS_RUNTIME_SERVICE_CID, XPC_RUNTIME_CONTRACTID, nsIXPConnectConstructor},
{NS_SCRIPTERROR_CLASSNAME, NS_SCRIPTERROR_CID, NS_SCRIPTERROR_CONTRACTID, nsScriptErrorConstructor },
{nsnull, SCRIPTABLE_INTERFACES_CID, NS_SCRIPTABLE_INTERFACES_CONTRACTID, nsXPCComponents_InterfacesConstructor, 0, 0, 0, 0, 0, 0, nsIClassInfo::THREADSAFE },
{nsnull, XPCVARIANT_CID, XPCVARIANT_CONTRACTID, nsnull, nsnull, nsnull, nsnull, NS_CI_INTERFACE_GETTER_NAME(XPCVariant), nsnull, &NS_CLASSINFO_NAME(XPCVariant)},
{nsnull, NS_XPC_JSCONTEXT_STACK_ITERATOR_CID, XPC_JSCONTEXT_STACK_ITERATOR_CONTRACTID, nsXPCJSContextStackIteratorConstructor }
#include "xpcmodule.h"
#ifdef MOZ_JSLOADER
// jsloader stuff
,{ "JS component loader", MOZJSCOMPONENTLOADER_CID,
MOZJSCOMPONENTLOADER_CONTRACTID, mozJSComponentLoaderConstructor,
RegisterJSLoader, UnregisterJSLoader }
#ifndef NO_SUBSCRIPT_LOADER
,{ "JS subscript loader", MOZ_JSSUBSCRIPTLOADER_CID,
mozJSSubScriptLoadContractID, mozJSSubScriptLoaderConstructor }
#endif
#endif
#ifdef XPC_IDISPATCH_SUPPORT
,{ nsnull, NS_IDISPATCH_SUPPORT_CID, NS_IDISPATCH_SUPPORT_CONTRACTID,
nsIDispatchSupportConstructor }
#endif
};
static nsresult
nsresult
xpcModuleCtor(nsIModule* self)
{
nsXPConnect::InitStatics();
@ -121,8 +61,8 @@ xpcModuleCtor(nsIModule* self)
return NS_OK;
}
static void
xpcModuleDtor(nsIModule* self)
void
xpcModuleDtor(nsIModule*)
{
// Release our singletons
nsXPConnect::ReleaseXPConnectSingleton();
@ -133,4 +73,15 @@ xpcModuleDtor(nsIModule* self)
#endif
}
#ifdef XPCONNECT_STANDALONE
/* Module implementation for the xpconnect library. */
XPCONNECT_FACTORIES
static const nsModuleComponentInfo components[] = {
XPCONNECT_COMPONENTS
};
NS_IMPL_NSGETMODULE_WITH_CTOR_DTOR(xpconnect, components, xpcModuleCtor, xpcModuleDtor)
#endif

Просмотреть файл

@ -0,0 +1,237 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* John Bandhauer <jband@netscape.com> (original author)
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef xpcmodule_h___
#define xpcmodule_h___
#include "xpcprivate.h"
#ifdef MOZ_JSLOADER
#include "mozJSLoaderConstructors.h"
#endif
/* Module implementation for the xpconnect library. */
// {DC524540-487E-4501-9AC7-AAA784B17C1C}
#define XPCVARIANT_CID \
{0xdc524540, 0x487e, 0x4501, \
{ 0x9a, 0xc7, 0xaa, 0xa7, 0x84, 0xb1, 0x7c, 0x1c } }
#define XPCVARIANT_CONTRACTID "@mozilla.org/xpcvariant;1"
#define XPC_JSCONTEXT_STACK_ITERATOR_CONTRACTID \
"@mozilla.org/js/xpc/ContextStackIterator;1"
// {FE4F7592-C1FC-4662-AC83-538841318803}
#define SCRIPTABLE_INTERFACES_CID \
{0xfe4f7592, 0xc1fc, 0x4662, \
{ 0xac, 0x83, 0x53, 0x88, 0x41, 0x31, 0x88, 0x3 } }
#define XPCONNECT_GENERAL_FACTORIES \
NS_DECL_CLASSINFO(XPCVariant) \
NS_DECL_CLASSINFO(nsXPCException) \
\
NS_GENERIC_FACTORY_CONSTRUCTOR(nsJSID) \
NS_GENERIC_FACTORY_CONSTRUCTOR(nsXPCException) \
NS_GENERIC_FACTORY_CONSTRUCTOR(nsXPCJSContextStackIterator) \
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIXPConnect, \
nsXPConnect::GetSingleton) \
NS_GENERIC_FACTORY_CONSTRUCTOR(nsScriptError) \
NS_GENERIC_FACTORY_CONSTRUCTOR(nsXPCComponents_Interfaces)
#ifdef XPC_IDISPATCH_SUPPORT
#define XPCONNECT_FACTORIES \
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIDispatchSupport, \
nsDispatchSupport::GetSingleton) \
XPCONNECT_GENERAL_FACTORIES
#else
#define XPCONNECT_FACTORIES XPCONNECT_GENERAL_FACTORIES
#endif // XPC_IDISPATCH_SUPPORT
#ifdef XPCONNECT_STANDALONE
#define NO_SUBSCRIPT_LOADER
#endif
#define XPCONNECT_GENERAL_COMPONENTS \
{ \
nsnull, \
NS_JS_ID_CID, \
XPC_ID_CONTRACTID, \
nsJSIDConstructor \
}, \
{ \
nsnull, \
NS_XPCONNECT_CID, \
XPC_XPCONNECT_CONTRACTID, \
nsIXPConnectConstructor \
}, \
{ \
nsnull, \
NS_XPC_THREAD_JSCONTEXT_STACK_CID, \
XPC_CONTEXT_STACK_CONTRACTID, \
nsIXPConnectConstructor \
}, \
{ \
nsnull, \
NS_XPCEXCEPTION_CID, \
XPC_EXCEPTION_CONTRACTID, \
nsXPCExceptionConstructor, \
nsnull, \
nsnull, \
nsnull, \
NS_CI_INTERFACE_GETTER_NAME(nsXPCException), \
nsnull, \
&NS_CLASSINFO_NAME(nsXPCException), \
nsIClassInfo::DOM_OBJECT \
}, \
{ \
nsnull, \
NS_JS_RUNTIME_SERVICE_CID, \
XPC_RUNTIME_CONTRACTID, \
nsIXPConnectConstructor \
}, \
{ \
NS_SCRIPTERROR_CLASSNAME, \
NS_SCRIPTERROR_CID, \
NS_SCRIPTERROR_CONTRACTID, \
nsScriptErrorConstructor \
}, \
{ \
nsnull, \
SCRIPTABLE_INTERFACES_CID, \
NS_SCRIPTABLE_INTERFACES_CONTRACTID, \
nsXPCComponents_InterfacesConstructor, \
nsnull, \
nsnull, \
nsnull, \
nsnull, \
nsnull, \
nsnull, \
nsIClassInfo::THREADSAFE \
}, \
{ \
nsnull, \
XPCVARIANT_CID, \
XPCVARIANT_CONTRACTID, \
nsnull, \
nsnull, \
nsnull, \
nsnull, \
NS_CI_INTERFACE_GETTER_NAME(XPCVariant), \
nsnull, \
&NS_CLASSINFO_NAME(XPCVariant) \
}, \
{ \
nsnull, \
NS_XPC_JSCONTEXT_STACK_ITERATOR_CID, \
XPC_JSCONTEXT_STACK_ITERATOR_CONTRACTID, \
nsXPCJSContextStackIteratorConstructor \
}
// jsloader stuff
#ifdef MOZ_JSLOADER
#define XPCONNECT_LOADER_COMPONENTS \
{ \
"JS component loader", \
MOZJSCOMPONENTLOADER_CID, \
MOZJSCOMPONENTLOADER_CONTRACTID, \
mozJSComponentLoaderConstructor, \
RegisterJSLoader, \
UnregisterJSLoader \
}, \
XPCONNECT_SUBSCRIPT_LOADER_COMPONENTS
#ifdef NO_SUBSCRIPT_LOADER
#define XPCONNECT_SUBSCRIPT_LOADER_COMPONENTS
#else
#define XPCONNECT_SUBSCRIPT_LOADER_COMPONENTS \
{ \
"JS subscript loader", \
MOZ_JSSUBSCRIPTLOADER_CID, \
mozJSSubScriptLoadContractID, \
mozJSSubScriptLoaderConstructor \
},
#endif // NO_SUBSCRIPT_LOADER
#else
#define XPCONNECT_LOADER_COMPONENTS
#endif // MOZ_JSLOADER
#ifdef XPC_IDISPATCH_SUPPORT
#define XPCONNECT_IDISPATCH_COMPONENTS \
{ \
nsnull, \
NS_IDISPATCH_SUPPORT_CID, \
NS_IDISPATCH_SUPPORT_CONTRACTID, \
nsIDispatchSupportConstructor \
},
#else
#define XPCONNECT_IDISPATCH_COMPONENTS
#endif // XPC_IDISPATCH_SUPPORT
#define XPCONNECT_COMPONENTS \
XPCONNECT_LOADER_COMPONENTS \
XPCONNECT_IDISPATCH_COMPONENTS \
XPCONNECT_GENERAL_COMPONENTS
extern nsresult xpcModuleCtor(nsIModule* self);
extern void xpcModuleDtor(nsIModule*);
#endif /* xpcmodule_h___ */

Просмотреть файл

@ -45,6 +45,7 @@
#include "XPCWrapper.h"
#include "nsDOMJSUtils.h"
#include "nsIScriptGlobalObject.h"
#include "nsNullPrincipal.h"
/***************************************************************************/
@ -226,12 +227,13 @@ XPCJSContextStack::GetSafeJSContext(JSContext * *aSafeJSContext)
#ifndef XPCONNECT_STANDALONE
// Start by getting the principal holder and principal for this
// context. If we can't manage that, don't bother with the rest.
nsCOMPtr<nsIPrincipal> principal =
do_CreateInstance("@mozilla.org/nullprincipal;1");
nsRefPtr<nsNullPrincipal> principal = new nsNullPrincipal();
nsCOMPtr<nsIScriptObjectPrincipal> sop;
if(principal)
{
sop = new PrincipalHolder(principal);
nsresult rv = principal->Init();
if(NS_SUCCEEDED(rv))
sop = new PrincipalHolder(principal);
}
if(!sop)
{

Просмотреть файл

@ -108,6 +108,7 @@ SHARED_LIBRARY_LIBS = \
$(DEPTH)/editor/libeditor/text/$(LIB_PREFIX)texteditor_s.$(LIB_SUFFIX) \
$(DEPTH)/editor/libeditor/base/$(LIB_PREFIX)editorbase_s.$(LIB_SUFFIX) \
$(DEPTH)/parser/html/$(LIB_PREFIX)html5p_s.$(LIB_SUFFIX) \
$(DEPTH)/caps/src/$(LIB_PREFIX)caps_s.$(LIB_SUFFIX) \
$(NULL)
ifdef MOZ_MEDIA
@ -200,6 +201,9 @@ ifdef ENABLE_EDITOR_API_LOG
DEFINES += -DENABLE_EDITOR_API_LOG
endif
SHARED_LIBRARY_LIBS += \
$(DEPTH)/js/src/xpconnect/src/$(LIB_PREFIX)xpconnect_s.$(LIB_SUFFIX)
EXTRA_DSO_LDOPTS = \
$(LIBS_DIR) \
$(EXTRA_DSO_LIBS) \
@ -269,6 +273,9 @@ LOCAL_INCLUDES += -I$(srcdir)/../base \
-I$(topsrcdir)/editor/libeditor/html \
-I$(topsrcdir)/editor/txtsvc/src \
-I$(topsrcdir)/editor/composer/src \
-I$(topsrcdir)/js/src/xpconnect/src \
-I$(topsrcdir)/js/src/xpconnect/loader \
-I$(topsrcdir)/caps/include \
$(NULL)
ifdef MOZ_MATHML

Просмотреть файл

@ -36,6 +36,7 @@
*
* ***** END LICENSE BLOCK ***** */
#include "xpcmodule.h"
#include "nsLayoutStatics.h"
#include "nsContentCID.h"
#include "nsContentDLF.h"
@ -143,6 +144,13 @@
#include "nsTextServicesCID.h"
#endif
#include "nsScriptSecurityManager.h"
#include "nsPrincipal.h"
#include "nsSystemPrincipal.h"
#include "nsNullPrincipal.h"
#include "nsPrefsCID.h"
#include "nsNetCID.h"
#define NS_EDITORCOMMANDTABLE_CID \
{ 0x4f5e62b8, 0xd659, 0x4156, { 0x84, 0xfc, 0x2f, 0x60, 0x99, 0x40, 0x03, 0x69 }}
@ -261,7 +269,6 @@ NS_IMETHODIMP
NS_NewXULTreeBuilder(nsISupports* aOuter, REFNSIID aIID, void** aResult);
#endif
static nsresult Initialize(nsIModule* aSelf);
static void Shutdown();
#ifdef MOZ_XTF
@ -921,8 +928,68 @@ CSPServiceUnregistration(nsIComponentManager *aCompMgr,
NS_GENERIC_FACTORY_CONSTRUCTOR(CSPService)
XPCONNECT_FACTORIES
NS_GENERIC_FACTORY_CONSTRUCTOR(nsPrincipal)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSecurityNameSet)
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsSystemPrincipal,
nsScriptSecurityManager::SystemPrincipalSingletonConstructor)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsNullPrincipal, Init)
NS_DECL_CLASSINFO(nsPrincipal)
NS_DECL_CLASSINFO(nsSystemPrincipal)
NS_DECL_CLASSINFO(nsNullPrincipal)
static NS_IMETHODIMP
Construct_nsIScriptSecurityManager(nsISupports *aOuter, REFNSIID aIID,
void **aResult)
{
if (!aResult)
return NS_ERROR_NULL_POINTER;
*aResult = nsnull;
if (aOuter)
return NS_ERROR_NO_AGGREGATION;
nsScriptSecurityManager *obj = nsScriptSecurityManager::GetScriptSecurityManager();
if (!obj)
return NS_ERROR_OUT_OF_MEMORY;
if (NS_FAILED(obj->QueryInterface(aIID, aResult)))
return NS_ERROR_FAILURE;
return NS_OK;
}
static NS_METHOD
RegisterSecurityNameSet(nsIComponentManager *aCompMgr,
nsIFile *aPath,
const char *registryLocation,
const char *componentType,
const nsModuleComponentInfo *info)
{
nsresult rv = NS_OK;
nsCOMPtr<nsICategoryManager> catman =
do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
if (NS_FAILED(rv))
return rv;
nsXPIDLCString previous;
rv = catman->AddCategoryEntry(JAVASCRIPT_GLOBAL_STATIC_NAMESET_CATEGORY,
"PrivilegeManager",
NS_SECURITYNAMESET_CONTRACTID,
PR_TRUE, PR_TRUE, getter_Copies(previous));
NS_ENSURE_SUCCESS(rv, rv);
rv = catman->AddCategoryEntry("app-startup", "Script Security Manager",
"service," NS_SCRIPTSECURITYMANAGER_CONTRACTID,
PR_TRUE, PR_TRUE,
getter_Copies(previous));
NS_ENSURE_SUCCESS(rv, rv);
return rv;
}
// The list of components we register
static const nsModuleComponentInfo gComponents[] = {
static const nsModuleComponentInfo gLayoutComponents[] = {
#ifdef DEBUG
{ "Frame utility",
NS_FRAME_UTIL_CID,
@ -1544,4 +1611,214 @@ static const nsModuleComponentInfo gComponents[] = {
nsChannelPolicyConstructor }
};
NS_IMPL_NSGETMODULE_WITH_CTOR(nsLayoutModule, gComponents, Initialize)
static nsModuleInfo const kLayoutModuleInfo = {
NS_MODULEINFO_VERSION,
"nsLayoutModule",
gLayoutComponents,
(sizeof(gLayoutComponents) / sizeof(gLayoutComponents[0])),
Initialize,
nsnull
};
static const nsModuleComponentInfo gXPConnectComponents[] = {
XPCONNECT_COMPONENTS,
{ NS_SCRIPTSECURITYMANAGER_CLASSNAME,
NS_SCRIPTSECURITYMANAGER_CID,
NS_SCRIPTSECURITYMANAGER_CONTRACTID,
Construct_nsIScriptSecurityManager,
RegisterSecurityNameSet,
nsnull,
nsnull,
nsnull,
nsnull,
nsnull,
nsIClassInfo::MAIN_THREAD_ONLY
},
{ NS_SCRIPTSECURITYMANAGER_CLASSNAME,
NS_SCRIPTSECURITYMANAGER_CID,
NS_GLOBAL_PREF_SECURITY_CHECK,
Construct_nsIScriptSecurityManager,
RegisterSecurityNameSet,
nsnull,
nsnull,
nsnull,
nsnull,
nsnull,
nsIClassInfo::MAIN_THREAD_ONLY
},
{ NS_SCRIPTSECURITYMANAGER_CLASSNAME,
NS_SCRIPTSECURITYMANAGER_CID,
NS_GLOBAL_CHANNELEVENTSINK_CONTRACTID,
Construct_nsIScriptSecurityManager,
RegisterSecurityNameSet,
nsnull,
nsnull,
nsnull,
nsnull,
nsnull,
nsIClassInfo::MAIN_THREAD_ONLY
},
{ NS_PRINCIPAL_CLASSNAME,
NS_PRINCIPAL_CID,
NS_PRINCIPAL_CONTRACTID,
nsPrincipalConstructor,
nsnull,
nsnull,
nsnull,
NS_CI_INTERFACE_GETTER_NAME(nsPrincipal),
nsnull,
&NS_CLASSINFO_NAME(nsPrincipal),
nsIClassInfo::MAIN_THREAD_ONLY | nsIClassInfo::EAGER_CLASSINFO
},
{ NS_SYSTEMPRINCIPAL_CLASSNAME,
NS_SYSTEMPRINCIPAL_CID,
NS_SYSTEMPRINCIPAL_CONTRACTID,
nsSystemPrincipalConstructor,
nsnull,
nsnull,
nsnull,
NS_CI_INTERFACE_GETTER_NAME(nsSystemPrincipal),
nsnull,
&NS_CLASSINFO_NAME(nsSystemPrincipal),
nsIClassInfo::SINGLETON | nsIClassInfo::MAIN_THREAD_ONLY |
nsIClassInfo::EAGER_CLASSINFO
},
{ NS_NULLPRINCIPAL_CLASSNAME,
NS_NULLPRINCIPAL_CID,
NS_NULLPRINCIPAL_CONTRACTID,
nsNullPrincipalConstructor,
nsnull,
nsnull,
nsnull,
NS_CI_INTERFACE_GETTER_NAME(nsNullPrincipal),
nsnull,
&NS_CLASSINFO_NAME(nsNullPrincipal),
nsIClassInfo::MAIN_THREAD_ONLY | nsIClassInfo::EAGER_CLASSINFO
},
{ "Security Script Name Set",
NS_SECURITYNAMESET_CID,
NS_SECURITYNAMESET_CONTRACTID,
nsSecurityNameSetConstructor,
nsnull,
nsnull,
nsnull,
nsnull,
nsnull,
nsnull,
nsIClassInfo::MAIN_THREAD_ONLY
}
};
void
XPConnectModuleDtor(nsIModule *self)
{
xpcModuleDtor(self);
nsScriptSecurityManager::Shutdown();
}
static nsModuleInfo const kXPConnectModuleInfo = {
NS_MODULEINFO_VERSION,
"XPConnectModule",
gXPConnectComponents,
(sizeof(gXPConnectComponents) / sizeof(gXPConnectComponents[0])),
xpcModuleCtor,
XPConnectModuleDtor
};
// XPConnect is initialized early, because it has an XPCOM component loader.
// Initializing nsLayoutStatics at that point leads to recursive initialization,
// because it instantiates a bunch of other components. To get around that we
// use two nsGenericModules, each with their own initialiser. nsLayoutStatics is
// initialized for the module for layout components, but not for the module for
// XPConnect components. nsLayoutModule forwards to the two nsGenericModules.
class nsLayoutModule : public nsIModule
{
public:
nsLayoutModule(nsIModule *aXPConnectModule, nsIModule *aLayoutModule)
: mXPConnectModule(aXPConnectModule),
mLayoutModule(aLayoutModule)
{
}
NS_DECL_ISUPPORTS
// nsIModule
NS_SCRIPTABLE NS_IMETHOD GetClassObject(nsIComponentManager *aCompMgr,
const nsCID & aClass,
const nsIID & aIID,
void **aResult NS_OUTPARAM)
{
nsresult rv = mXPConnectModule->GetClassObject(aCompMgr, aClass, aIID,
aResult);
if (rv == NS_ERROR_FACTORY_NOT_REGISTERED) {
rv = mLayoutModule->GetClassObject(aCompMgr, aClass, aIID, aResult);
}
return rv;
}
NS_SCRIPTABLE NS_IMETHOD RegisterSelf(nsIComponentManager *aCompMgr,
nsIFile *aLocation,
const char *aLoaderStr,
const char *aType)
{
nsresult rv = mXPConnectModule->RegisterSelf(aCompMgr, aLocation,
aLoaderStr, aType);
if (NS_SUCCEEDED(rv)) {
rv = mLayoutModule->RegisterSelf(aCompMgr, aLocation, aLoaderStr, aType);
}
return rv;
}
NS_SCRIPTABLE NS_IMETHOD UnregisterSelf(nsIComponentManager *aCompMgr,
nsIFile *aLocation,
const char *aLoaderStr)
{
nsresult rv = mXPConnectModule->UnregisterSelf(aCompMgr, aLocation,
aLoaderStr);
if (NS_SUCCEEDED(rv)) {
rv = mLayoutModule->UnregisterSelf(aCompMgr, aLocation, aLoaderStr);
}
return rv;
}
NS_SCRIPTABLE NS_IMETHOD CanUnload(nsIComponentManager *aCompMgr,
PRBool *aResult NS_OUTPARAM)
{
nsresult rv = mXPConnectModule->CanUnload(aCompMgr, aResult);
if (NS_SUCCEEDED(rv)) {
rv = mLayoutModule->CanUnload(aCompMgr, aResult);
}
return rv;
}
private:
nsCOMPtr<nsIModule> mXPConnectModule;
nsCOMPtr<nsIModule> mLayoutModule;
};
NS_IMPL_ISUPPORTS1(nsLayoutModule, nsIModule)
NSGETMODULE_ENTRY_POINT(nsLayoutModule)(nsIComponentManager *aServMgr,
nsIFile *aLocation,
nsIModule **aResult)
{
nsCOMPtr<nsIModule> xpconnectModule;
nsresult rv = NS_NewGenericModule2(&kXPConnectModuleInfo,
getter_AddRefs(xpconnectModule));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIModule> layoutModule;
rv = NS_NewGenericModule2(&kLayoutModuleInfo, getter_AddRefs(layoutModule));
NS_ENSURE_SUCCESS(rv, rv);
NS_ADDREF(*aResult = new nsLayoutModule(xpconnectModule, layoutModule));
return NS_OK;
}

Просмотреть файл

@ -132,14 +132,12 @@ endif
# component libraries
COMPONENT_LIBS += \
xpconnect \
necko \
uconv \
i18n \
chardet \
jar$(VERSION_NUMBER) \
pref \
caps \
htmlpars \
imglib2 \
gklayout \

Просмотреть файл

@ -234,7 +234,6 @@
#endif
#define XUL_MODULES \
MODULE(xpconnect) \
MODULE(nsUConvModule) \
MODULE(nsI18nModule) \
MODULE(nsChardetModule) \
@ -245,7 +244,6 @@
MODULE(nsJarModule) \
ZIPWRITER_MODULE \
MODULE(nsPrefModule) \
MODULE(nsSecurityManagerModule) \
RDF_MODULES \
MODULE(nsParserModule) \
GFX_MODULES \