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"
69 #include "mozilla/Omnijar.h"
70 #include "nsIZipReader.h"
72 struct nsFactoryEntry
;
73 class nsIServiceManager
;
76 #define NS_COMPONENTMANAGER_CID \
77 { /* 91775d60-d5dc-11d2-92fb-00e09805570f */ \
81 {0x92, 0xfb, 0x00, 0xe0, 0x98, 0x05, 0x57, 0x0f} \
84 /* keys for registry use */
85 extern const char xpcomKeyName
[];
86 extern const char xpcomComponentsKeyName
[];
87 extern const char lastModValueName
[];
88 extern const char fileSizeValueName
[];
89 extern const char nativeComponentType
[];
90 extern const char staticComponentType
[];
93 #define XPCOM_CHECK_PENDING_CIDS
95 ////////////////////////////////////////////////////////////////////////////////
97 extern const mozilla::Module kXPCOMModule
;
99 // Array of Loaders and their type strings
100 struct nsLoaderdata
{
101 nsCOMPtr
<mozilla::ModuleLoader
> loader
;
105 class nsComponentManagerImpl
106 : public nsIComponentManager
107 , public nsIServiceManager
108 , public nsSupportsWeakReference
109 , public nsIComponentRegistrar
110 , public nsIInterfaceRequestor
114 NS_DECL_NSIINTERFACEREQUESTOR
115 NS_DECL_NSICOMPONENTMANAGER
116 NS_DECL_NSICOMPONENTREGISTRAR
118 static nsresult
Create(nsISupports
* aOuter
, REFNSIID aIID
, void** aResult
);
120 nsresult
RegistryLocationForFile(nsIFile
* aFile
,
122 nsresult
FileForRegistryLocation(const nsCString
&aLocation
,
123 nsILocalFile
**aSpec
);
125 NS_DECL_NSISERVICEMANAGER
127 // nsComponentManagerImpl methods:
128 nsComponentManagerImpl();
130 static nsComponentManagerImpl
* gComponentManager
;
133 nsresult
Shutdown(void);
135 nsresult
FreeServices();
137 already_AddRefed
<mozilla::ModuleLoader
> LoaderForExtension(const nsACString
& aExt
);
138 nsInterfaceHashtable
<nsCStringHashKey
, mozilla::ModuleLoader
> mLoaderMap
;
140 already_AddRefed
<nsIFactory
> FindFactory(const nsCID
& aClass
);
141 already_AddRefed
<nsIFactory
> FindFactory(const char *contractID
,
142 PRUint32 aContractIDLen
);
144 already_AddRefed
<nsIFactory
> LoadFactory(nsFactoryEntry
*aEntry
);
146 nsFactoryEntry
*GetFactoryEntry(const char *aContractID
,
147 PRUint32 aContractIDLen
);
148 nsFactoryEntry
*GetFactoryEntry(const nsCID
&aClass
);
150 nsDataHashtable
<nsIDHashKey
, nsFactoryEntry
*> mFactories
;
151 nsDataHashtable
<nsCStringHashKey
, nsFactoryEntry
*> mContractIDs
;
155 static void InitializeStaticModules();
156 static void InitializeModuleLocations();
158 struct ComponentLocation
161 nsCOMPtr
<nsILocalFile
> location
;
165 static nsTArray
<const mozilla::Module
*>* sStaticModules
;
166 static nsTArray
<ComponentLocation
>* sModuleLocations
;
167 static nsTArray
<ComponentLocation
>* sJarModuleLocations
;
169 nsNativeModuleLoader mNativeModuleLoader
;
175 * Static or binary module.
177 KnownModule(const mozilla::Module
* aModule
, nsILocalFile
* aFile
)
184 KnownModule(nsILocalFile
* aFile
)
192 KnownModule(nsILocalFile
* aFile
, const nsACString
& aPath
)
203 if (mLoaded
&& mModule
->unloadProc
)
204 mModule
->unloadProc();
210 const mozilla::Module
* Module() const
216 * For error logging, get a description of this module, either the
217 * file path, or <static module>.
219 nsCString
Description() const;
222 const mozilla::Module
* mModule
;
223 nsCOMPtr
<nsILocalFile
> mFile
;
225 nsCOMPtr
<mozilla::ModuleLoader
> mLoader
;
230 // The KnownModule is kept alive by these members, it is
231 // referenced by pointer from the factory entries.
232 nsTArray
< nsAutoPtr
<KnownModule
> > mKnownStaticModules
;
233 nsClassHashtable
<nsHashableHashKey
, KnownModule
> mKnownFileModules
;
234 // The key is a string in this format "<jar path>|<path within jar>"
235 nsClassHashtable
<nsCStringHashKey
, KnownModule
> mKnownJARModules
;
237 void RegisterModule(const mozilla::Module
* aModule
,
238 nsILocalFile
* aFile
);
239 void RegisterCIDEntry(const mozilla::Module::CIDEntry
* aEntry
,
240 KnownModule
* aModule
);
241 void RegisterContractID(const mozilla::Module::ContractIDEntry
* aEntry
);
243 void RegisterJarManifest(nsIZipReader
* aReader
,
244 const char* aPath
, bool aChromeOnly
);
246 void RegisterManifestFile(NSLocationType aType
, nsILocalFile
* aFile
,
249 struct ManifestProcessingContext
251 ManifestProcessingContext(NSLocationType aType
, nsILocalFile
* aFile
, bool aChromeOnly
)
255 , mChromeOnly(aChromeOnly
)
258 ManifestProcessingContext(NSLocationType aType
, nsIZipReader
* aReader
, const char* aPath
, bool aChromeOnly
)
262 , mChromeOnly(aChromeOnly
)
264 nsCOMPtr
<nsIFile
> file
;
265 aReader
->GetFile(getter_AddRefs(file
));
266 nsCOMPtr
<nsILocalFile
> localfile
= do_QueryInterface(file
);
270 ~ManifestProcessingContext() { }
272 NSLocationType mType
;
274 nsIZipReader
* mReader
;
279 void ManifestManifest(ManifestProcessingContext
& cx
, int lineno
, char *const * argv
);
280 void ManifestBinaryComponent(ManifestProcessingContext
& cx
, int lineno
, char *const * argv
);
281 void ManifestXPT(ManifestProcessingContext
& cx
, int lineno
, char *const * argv
);
282 void ManifestComponent(ManifestProcessingContext
& cx
, int lineno
, char *const * argv
);
283 void ManifestContract(ManifestProcessingContext
& cx
, int lineno
, char* const * argv
);
284 void ManifestCategory(ManifestProcessingContext
& cx
, int lineno
, char* const * argv
);
286 void RereadChromeManifests();
292 SHUTDOWN_IN_PROGRESS
,
296 nsTArray
<nsLoaderdata
> mLoaderData
;
300 struct PendingServiceInfo
{
305 inline PendingServiceInfo
* AddPendingService(const nsCID
& aServiceCID
,
307 inline void RemovePendingService(const nsCID
& aServiceCID
);
308 inline PRThread
* GetPendingServiceThread(const nsCID
& aServiceCID
) const;
310 nsTArray
<PendingServiceInfo
> mPendingServices
;
313 ~nsComponentManagerImpl();
317 #define NS_MAX_FILENAME_LEN 1024
319 #define NS_ERROR_IS_DIR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_XPCOM, 24)
321 struct nsFactoryEntry
323 nsFactoryEntry(const mozilla::Module::CIDEntry
* entry
,
324 nsComponentManagerImpl::KnownModule
* module
);
326 // nsIComponentRegistrar.registerFactory support
327 nsFactoryEntry(const nsCID
& aClass
, nsIFactory
* factory
);
331 already_AddRefed
<nsIFactory
> GetFactory();
333 const mozilla::Module::CIDEntry
* mCIDEntry
;
334 nsComponentManagerImpl::KnownModule
* mModule
;
336 nsCOMPtr
<nsIFactory
> mFactory
;
337 nsCOMPtr
<nsISupports
> mServiceObject
;
340 #endif // nsComponentManager_h__