Back to index

lightning-sunbird  0.9+nobinonly
xpcmodule.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is Mozilla Communicator client code, released
00017  * March 31, 1998.
00018  *
00019  * The Initial Developer of the Original Code is
00020  * Netscape Communications Corporation.
00021  * Portions created by the Initial Developer are Copyright (C) 1998
00022  * the Initial Developer. All Rights Reserved.
00023  *
00024  * Contributor(s):
00025  *   John Bandhauer <jband@netscape.com> (original author)
00026  *
00027  * Alternatively, the contents of this file may be used under the terms of
00028  * either of the GNU General Public License Version 2 or later (the "GPL"),
00029  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00030  * in which case the provisions of the GPL or the LGPL are applicable instead
00031  * of those above. If you wish to allow use of your version of this file only
00032  * under the terms of either the GPL or the LGPL, and not to allow others to
00033  * use your version of this file under the terms of the MPL, indicate your
00034  * decision by deleting the provisions above and replace them with the notice
00035  * and other provisions required by the GPL or the LGPL. If you do not delete
00036  * the provisions above, a recipient may use your version of this file under
00037  * the terms of any one of the MPL, the GPL or the LGPL.
00038  *
00039  * ***** END LICENSE BLOCK ***** */
00040 
00041 /* Module level methods. */
00042 
00043 #include "xpcprivate.h"
00044 #include "nsXPCOMCID.h"
00045 #ifdef MOZ_JSLOADER
00046 #include "mozJSLoaderConstructors.h"
00047 #endif
00048 
00049 /* Module implementation for the xpconnect library. */
00050 
00051 NS_DECL_CLASSINFO(XPCVariant)
00052 
00053 // {DC524540-487E-4501-9AC7-AAA784B17C1C}
00054 #define XPCVARIANT_CID \
00055     {0xdc524540, 0x487e, 0x4501, \
00056       { 0x9a, 0xc7, 0xaa, 0xa7, 0x84, 0xb1, 0x7c, 0x1c } }
00057 
00058 #define XPCVARIANT_CONTRACTID "@mozilla.org/xpcvariant;1"
00059 #define XPC_JSCONTEXT_STACK_ITERATOR_CONTRACTID "@mozilla.org/js/xpc/ContextStackIterator;1"
00060 
00061 // {FE4F7592-C1FC-4662-AC83-538841318803}
00062 #define SCRIPTABLE_INTERFACES_CID \
00063     {0xfe4f7592, 0xc1fc, 0x4662, \
00064       { 0xac, 0x83, 0x53, 0x88, 0x41, 0x31, 0x88, 0x3 } }
00065 
00066 NS_GENERIC_FACTORY_CONSTRUCTOR(nsJSID)
00067 NS_GENERIC_FACTORY_CONSTRUCTOR(nsXPCException)
00068 NS_GENERIC_FACTORY_CONSTRUCTOR(nsXPCJSContextStackIterator)
00069 NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIXPConnect, nsXPConnect::GetSingleton)
00070 NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIJSContextStack, nsXPCThreadJSContextStackImpl::GetSingleton)
00071 NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIJSRuntimeService, nsJSRuntimeServiceImpl::GetSingleton)
00072 NS_GENERIC_FACTORY_CONSTRUCTOR(nsScriptError)
00073 NS_GENERIC_FACTORY_CONSTRUCTOR(nsXPCComponents_Interfaces)
00074 
00075 #ifdef XPC_IDISPATCH_SUPPORT
00076 NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIDispatchSupport, nsDispatchSupport::GetSingleton)
00077 #endif
00078 
00079 NS_DECL_CLASSINFO(nsXPCException)
00080 
00081 #ifdef XPCONNECT_STANDALONE
00082 #define NO_SUBSCRIPT_LOADER
00083 #endif
00084 
00085 static const nsModuleComponentInfo components[] = {
00086   {nsnull, NS_JS_ID_CID,                         XPC_ID_CONTRACTID,            nsJSIDConstructor             },
00087   {nsnull, NS_XPCONNECT_CID,                     XPC_XPCONNECT_CONTRACTID,     nsIXPConnectConstructor       },
00088   {nsnull, NS_XPC_THREAD_JSCONTEXT_STACK_CID,    XPC_CONTEXT_STACK_CONTRACTID, nsIJSContextStackConstructor  },
00089   {nsnull, NS_XPCEXCEPTION_CID,                  XPC_EXCEPTION_CONTRACTID,     nsXPCExceptionConstructor, nsnull, nsnull, nsnull, NS_CI_INTERFACE_GETTER_NAME(nsXPCException), nsnull, &NS_CLASSINFO_NAME(nsXPCException)},
00090   {nsnull, NS_JS_RUNTIME_SERVICE_CID,            XPC_RUNTIME_CONTRACTID,       nsIJSRuntimeServiceConstructor},
00091   {NS_SCRIPTERROR_CLASSNAME, NS_SCRIPTERROR_CID, NS_SCRIPTERROR_CONTRACTID,    nsScriptErrorConstructor      },
00092   {nsnull, SCRIPTABLE_INTERFACES_CID,            NS_SCRIPTABLE_INTERFACES_CONTRACTID,        nsXPCComponents_InterfacesConstructor },
00093   {nsnull, XPCVARIANT_CID,                       XPCVARIANT_CONTRACTID,        nsnull, nsnull, nsnull, nsnull, NS_CI_INTERFACE_GETTER_NAME(XPCVariant), nsnull, &NS_CLASSINFO_NAME(XPCVariant)},
00094   {nsnull, NS_XPC_JSCONTEXT_STACK_ITERATOR_CID,  XPC_JSCONTEXT_STACK_ITERATOR_CONTRACTID, nsXPCJSContextStackIteratorConstructor },
00095   {nsnull, NS_XPCONNECT_CID,                     NS_EVENT_QUEUE_LISTENER_CONTRACTID,     nsIXPConnectConstructor       }
00096 
00097 #ifdef MOZ_JSLOADER
00098   // jsloader stuff
00099  ,{ "JS component loader", MOZJSCOMPONENTLOADER_CID,
00100     MOZJSCOMPONENTLOADER_CONTRACTID, mozJSComponentLoaderConstructor,
00101     RegisterJSLoader, UnregisterJSLoader }
00102 #ifndef NO_SUBSCRIPT_LOADER
00103  ,{ "JS subscript loader", MOZ_JSSUBSCRIPTLOADER_CID,
00104     mozJSSubScriptLoadContractID, mozJSSubScriptLoaderConstructor }
00105 #endif
00106 #endif
00107 #ifdef XPC_IDISPATCH_SUPPORT
00108  ,{ nsnull, NS_IDISPATCH_SUPPORT_CID,            NS_IDISPATCH_SUPPORT_CONTRACTID,
00109     nsIDispatchSupportConstructor }
00110 #endif
00111 };
00112 
00113 PR_STATIC_CALLBACK(nsresult)
00114 xpcModuleCtor(nsIModule* self)
00115 {
00116     nsXPConnect::InitStatics();
00117     nsXPCException::InitStatics();
00118     XPCWrappedNativeScope::InitStatics();
00119     XPCPerThreadData::InitStatics();
00120     nsJSRuntimeServiceImpl::InitStatics();
00121     nsXPCThreadJSContextStackImpl::InitStatics();
00122 
00123 #ifdef XPC_IDISPATCH_SUPPORT
00124     XPCIDispatchExtension::InitStatics();
00125 #endif
00126 
00127     return NS_OK;
00128 }
00129 
00130 PR_STATIC_CALLBACK(void)
00131 xpcModuleDtor(nsIModule* self)
00132 {
00133     // Release our singletons
00134     nsXPConnect::ReleaseXPConnectSingleton();
00135     nsXPCThreadJSContextStackImpl::FreeSingleton();
00136     nsJSRuntimeServiceImpl::FreeSingleton();
00137     xpc_DestroyJSxIDClassObjects();
00138 #ifdef XPC_IDISPATCH_SUPPORT
00139     nsDispatchSupport::FreeSingleton();
00140     XPCIDispatchClassInfo::FreeSingleton();
00141 #endif
00142 }
00143 
00144 NS_IMPL_NSGETMODULE_WITH_CTOR_DTOR(xpconnect, components, xpcModuleCtor, xpcModuleDtor)