1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #ifndef nsComponentManager_h__
39 #define nsComponentManager_h__
43 #include "xpcom-private.h"
44 #include "nsIComponentManager.h"
45 #include "nsIComponentRegistrar.h"
46 #include "nsIServiceManager.h"
47 #include "nsILocalFile.h"
48 #include "mozilla/Module.h"
49 #include "mozilla/ModuleLoader.h"
50 #include "nsXULAppAPI.h"
51 #include "nsNativeComponentLoader.h"
52 #include "nsIFactory.h"
53 #include "nsIInterfaceRequestor.h"
54 #include "nsIInterfaceRequestorUtils.h"
59 #include "nsAutoPtr.h"
60 #include "nsWeakReference.h"
63 #include "nsCOMArray.h"
64 #include "nsDataHashtable.h"
65 #include "nsInterfaceHashtable.h"
66 #include "nsClassHashtable.h"
70 #include "mozilla/Omnijar.h"
71 #include "nsManifestZIPLoader.h"
74 struct nsFactoryEntry
;
75 class nsIServiceManager
;
78 #define NS_COMPONENTMANAGER_CID \
79 { /* 91775d60-d5dc-11d2-92fb-00e09805570f */ \
83 {0x92, 0xfb, 0x00, 0xe0, 0x98, 0x05, 0x57, 0x0f} \
86 /* keys for registry use */
87 extern const char xpcomKeyName
[];
88 extern const char xpcomComponentsKeyName
[];
89 extern const char lastModValueName
[];
90 extern const char fileSizeValueName
[];
91 extern const char nativeComponentType
[];
92 extern const char staticComponentType
[];
94 typedef int LoaderType
;
96 // Predefined loader types.
97 #define NS_LOADER_TYPE_NATIVE -1
98 #define NS_LOADER_TYPE_STATIC -2
99 #define NS_LOADER_TYPE_JAR -3
100 #define NS_LOADER_TYPE_INVALID -4
103 #define XPCOM_CHECK_PENDING_CIDS
105 ////////////////////////////////////////////////////////////////////////////////
107 extern const mozilla::Module kXPCOMModule
;
109 // Array of Loaders and their type strings
110 struct nsLoaderdata
{
111 nsCOMPtr
<mozilla::ModuleLoader
> loader
;
115 class nsComponentManagerImpl
116 : public nsIComponentManager
117 , public nsIServiceManager
118 , public nsSupportsWeakReference
119 , public nsIComponentRegistrar
120 , public nsIInterfaceRequestor
124 NS_DECL_NSIINTERFACEREQUESTOR
125 NS_DECL_NSICOMPONENTMANAGER
126 NS_DECL_NSICOMPONENTREGISTRAR
128 static nsresult
Create(nsISupports
* aOuter
, REFNSIID aIID
, void** aResult
);
130 nsresult
RegistryLocationForFile(nsIFile
* aFile
,
132 nsresult
FileForRegistryLocation(const nsCString
&aLocation
,
133 nsILocalFile
**aSpec
);
135 NS_DECL_NSISERVICEMANAGER
137 // nsComponentManagerImpl methods:
138 nsComponentManagerImpl();
140 static nsComponentManagerImpl
* gComponentManager
;
143 nsresult
Shutdown(void);
145 nsresult
FreeServices();
147 already_AddRefed
<mozilla::ModuleLoader
> LoaderForExtension(const nsACString
& aExt
);
148 nsInterfaceHashtable
<nsCStringHashKey
, mozilla::ModuleLoader
> mLoaderMap
;
150 already_AddRefed
<nsIFactory
> FindFactory(const nsCID
& aClass
);
151 already_AddRefed
<nsIFactory
> FindFactory(const char *contractID
,
152 PRUint32 aContractIDLen
);
154 already_AddRefed
<nsIFactory
> LoadFactory(nsFactoryEntry
*aEntry
);
156 nsFactoryEntry
*GetFactoryEntry(const char *aContractID
,
157 PRUint32 aContractIDLen
);
158 nsFactoryEntry
*GetFactoryEntry(const nsCID
&aClass
);
160 nsDataHashtable
<nsIDHashKey
, nsFactoryEntry
*> mFactories
;
161 nsDataHashtable
<nsCStringHashKey
, nsFactoryEntry
*> mContractIDs
;
165 static void InitializeStaticModules();
166 static void InitializeModuleLocations();
168 struct ComponentLocation
171 nsCOMPtr
<nsILocalFile
> location
;
174 static nsTArray
<const mozilla::Module
*>* sStaticModules
;
175 static nsTArray
<ComponentLocation
>* sModuleLocations
;
177 nsNativeModuleLoader mNativeModuleLoader
;
183 * Static or binary module.
185 KnownModule(const mozilla::Module
* aModule
, nsILocalFile
* aFile
)
192 KnownModule(nsILocalFile
* aFile
)
201 KnownModule(const nsACString
& aPath
)
213 if (mLoaded
&& mModule
->unloadProc
)
214 mModule
->unloadProc();
220 const mozilla::Module
* Module() const
226 * For error logging, get a description of this module, either the
227 * file path, or <static module>.
229 nsCString
Description() const;
232 const mozilla::Module
* mModule
;
233 nsCOMPtr
<nsILocalFile
> mFile
;
237 nsCOMPtr
<mozilla::ModuleLoader
> mLoader
;
242 // The KnownModule is kept alive by these members, it is
243 // referenced by pointer from the factory entries.
244 nsTArray
< nsAutoPtr
<KnownModule
> > mKnownStaticModules
;
245 nsClassHashtable
<nsHashableHashKey
, KnownModule
> mKnownFileModules
;
247 nsClassHashtable
<nsCStringHashKey
, KnownModule
> mKnownJARModules
;
250 void RegisterModule(const mozilla::Module
* aModule
,
251 nsILocalFile
* aFile
);
252 void RegisterCIDEntry(const mozilla::Module::CIDEntry
* aEntry
,
253 KnownModule
* aModule
);
254 void RegisterContractID(const mozilla::Module::ContractIDEntry
* aEntry
);
257 void RegisterOmnijar(const char* aPath
, bool aChromeOnly
);
260 void RegisterManifestFile(NSLocationType aType
, nsILocalFile
* aFile
,
263 struct ManifestProcessingContext
265 ManifestProcessingContext(NSLocationType aType
, nsILocalFile
* aFile
, bool aChromeOnly
)
269 , mChromeOnly(aChromeOnly
)
273 ManifestProcessingContext(NSLocationType aType
, const char* aPath
, bool aChromeOnly
)
275 , mFile(mozilla::OmnijarPath())
277 , mChromeOnly(aChromeOnly
)
281 ~ManifestProcessingContext() { }
283 NSLocationType mType
;
289 void ManifestManifest(ManifestProcessingContext
& cx
, int lineno
, char *const * argv
);
290 void ManifestBinaryComponent(ManifestProcessingContext
& cx
, int lineno
, char *const * argv
);
291 void ManifestXPT(ManifestProcessingContext
& cx
, int lineno
, char *const * argv
);
292 void ManifestComponent(ManifestProcessingContext
& cx
, int lineno
, char *const * argv
);
293 void ManifestContract(ManifestProcessingContext
& cx
, int lineno
, char* const * argv
);
294 void ManifestCategory(ManifestProcessingContext
& cx
, int lineno
, char* const * argv
);
296 void RereadChromeManifests();
302 SHUTDOWN_IN_PROGRESS
,
306 nsTArray
<nsLoaderdata
> mLoaderData
;
310 struct PendingServiceInfo
{
315 inline PendingServiceInfo
* AddPendingService(const nsCID
& aServiceCID
,
317 inline void RemovePendingService(const nsCID
& aServiceCID
);
318 inline PRThread
* GetPendingServiceThread(const nsCID
& aServiceCID
) const;
320 nsTArray
<PendingServiceInfo
> mPendingServices
;
323 ~nsComponentManagerImpl();
326 nsAutoPtr
<nsManifestZIPLoader
> mManifestLoader
;
331 #define NS_MAX_FILENAME_LEN 1024
333 #define NS_ERROR_IS_DIR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_XPCOM, 24)
335 struct nsFactoryEntry
337 nsFactoryEntry(const mozilla::Module::CIDEntry
* entry
,
338 nsComponentManagerImpl::KnownModule
* module
);
340 // nsIComponentRegistrar.registerFactory support
341 nsFactoryEntry(const nsCID
& aClass
, nsIFactory
* factory
);
345 already_AddRefed
<nsIFactory
> GetFactory();
347 const mozilla::Module::CIDEntry
* mCIDEntry
;
348 nsComponentManagerImpl::KnownModule
* mModule
;
350 nsCOMPtr
<nsIFactory
> mFactory
;
351 nsCOMPtr
<nsISupports
> mServiceObject
;
354 #endif // nsComponentManager_h__