1999-03-10 12:53:25 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2001-09-29 00:14:13 +04:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 18:21:17 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1999-03-09 12:44:27 +03:00
|
|
|
*
|
2004-04-18 18:21:17 +04:00
|
|
|
* 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/
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* 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.
|
1999-03-09 12:44:27 +03:00
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 18:21:17 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-29 00:14:13 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 18:21:17 +04:00
|
|
|
* 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"),
|
2001-09-29 00:14:13 +04:00
|
|
|
* 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
|
2004-04-18 18:21:17 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-29 00:14:13 +04:00
|
|
|
* 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
|
2004-04-18 18:21:17 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
1999-11-06 06:43:54 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-03-09 12:44:27 +03:00
|
|
|
|
|
|
|
#ifndef nsComponentManager_h__
|
|
|
|
#define nsComponentManager_h__
|
|
|
|
|
2001-10-16 07:35:52 +04:00
|
|
|
#include "nsXPCOM.h"
|
|
|
|
|
2003-10-31 23:50:22 +03:00
|
|
|
#include "xpcom-private.h"
|
1999-03-09 12:44:27 +03:00
|
|
|
#include "nsIComponentManager.h"
|
2002-01-30 00:22:13 +03:00
|
|
|
#include "nsIComponentRegistrar.h"
|
2001-09-07 01:13:11 +04:00
|
|
|
#include "nsIServiceManager.h"
|
2005-12-13 20:55:43 +03:00
|
|
|
#include "nsILocalFile.h"
|
2010-06-10 22:11:11 +04:00
|
|
|
#include "mozilla/Module.h"
|
|
|
|
#include "mozilla/ModuleLoader.h"
|
2010-06-12 00:13:26 +04:00
|
|
|
#include "nsXULAppAPI.h"
|
2005-12-13 20:55:43 +03:00
|
|
|
#include "nsNativeComponentLoader.h"
|
1999-09-01 01:40:21 +04:00
|
|
|
#include "nsIFactory.h"
|
2000-01-12 01:54:46 +03:00
|
|
|
#include "nsIInterfaceRequestor.h"
|
2001-09-06 01:28:38 +04:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
2001-10-23 06:28:12 +04:00
|
|
|
#include "pldhash.h"
|
1999-03-09 12:44:27 +03:00
|
|
|
#include "prtime.h"
|
1999-03-09 13:15:54 +03:00
|
|
|
#include "prmon.h"
|
1999-09-01 01:40:21 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2010-06-10 22:11:11 +04:00
|
|
|
#include "nsAutoPtr.h"
|
1999-10-16 01:14:43 +04:00
|
|
|
#include "nsWeakReference.h"
|
2000-01-25 00:28:28 +03:00
|
|
|
#include "nsIFile.h"
|
2002-05-03 01:25:08 +04:00
|
|
|
#include "plarena.h"
|
2005-12-13 20:55:43 +03:00
|
|
|
#include "nsCOMArray.h"
|
|
|
|
#include "nsDataHashtable.h"
|
2010-06-10 22:11:11 +04:00
|
|
|
#include "nsInterfaceHashtable.h"
|
2010-06-12 00:13:26 +04:00
|
|
|
#include "nsClassHashtable.h"
|
2005-12-13 20:55:43 +03:00
|
|
|
#include "nsTArray.h"
|
1999-03-09 12:44:27 +03:00
|
|
|
|
2005-12-13 20:55:43 +03:00
|
|
|
struct nsFactoryEntry;
|
1999-07-31 09:55:26 +04:00
|
|
|
class nsIServiceManager;
|
2008-09-05 02:44:41 +04:00
|
|
|
struct PRThread;
|
1999-03-09 12:44:27 +03:00
|
|
|
|
2004-11-23 23:53:38 +03:00
|
|
|
#define NS_COMPONENTMANAGER_CID \
|
|
|
|
{ /* 91775d60-d5dc-11d2-92fb-00e09805570f */ \
|
|
|
|
0x91775d60, \
|
|
|
|
0xd5dc, \
|
|
|
|
0x11d2, \
|
|
|
|
{0x92, 0xfb, 0x00, 0xe0, 0x98, 0x05, 0x57, 0x0f} \
|
|
|
|
}
|
|
|
|
|
|
|
|
/* keys for registry use */
|
|
|
|
extern const char xpcomKeyName[];
|
|
|
|
extern const char xpcomComponentsKeyName[];
|
|
|
|
extern const char lastModValueName[];
|
|
|
|
extern const char fileSizeValueName[];
|
|
|
|
extern const char nativeComponentType[];
|
|
|
|
extern const char staticComponentType[];
|
1999-03-09 12:44:27 +03:00
|
|
|
|
2005-12-13 20:55:43 +03:00
|
|
|
typedef int LoaderType;
|
2001-08-30 18:10:41 +04:00
|
|
|
|
2005-12-13 20:55:43 +03:00
|
|
|
// Predefined loader types.
|
|
|
|
#define NS_LOADER_TYPE_NATIVE -1
|
|
|
|
#define NS_LOADER_TYPE_STATIC -2
|
2010-06-15 23:38:46 +04:00
|
|
|
#define NS_LOADER_TYPE_JAR -3
|
|
|
|
#define NS_LOADER_TYPE_INVALID -4
|
2003-03-12 06:58:33 +03:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
#define XPCOM_CHECK_PENDING_CIDS
|
|
|
|
#endif
|
1999-03-09 12:44:27 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2010-06-10 22:11:11 +04:00
|
|
|
extern const mozilla::Module kXPCOMModule;
|
|
|
|
|
2002-06-15 01:33:05 +04:00
|
|
|
// Array of Loaders and their type strings
|
|
|
|
struct nsLoaderdata {
|
2010-06-10 22:11:11 +04:00
|
|
|
nsCOMPtr<mozilla::ModuleLoader> loader;
|
2005-12-13 20:55:43 +03:00
|
|
|
nsCString type;
|
|
|
|
};
|
|
|
|
|
2000-01-12 01:54:46 +03:00
|
|
|
class nsComponentManagerImpl
|
2001-09-07 01:13:11 +04:00
|
|
|
: public nsIComponentManager,
|
|
|
|
public nsIServiceManager,
|
|
|
|
public nsSupportsWeakReference,
|
2010-06-10 22:11:11 +04:00
|
|
|
public nsIComponentRegistrar,
|
|
|
|
public nsIInterfaceRequestor
|
2001-10-17 03:39:20 +04:00
|
|
|
{
|
1999-03-09 12:44:27 +03:00
|
|
|
public:
|
1999-03-10 12:53:25 +03:00
|
|
|
NS_DECL_ISUPPORTS
|
2000-01-12 01:54:46 +03:00
|
|
|
NS_DECL_NSIINTERFACEREQUESTOR
|
2010-06-10 22:11:11 +04:00
|
|
|
NS_DECL_NSICOMPONENTMANAGER
|
|
|
|
NS_DECL_NSICOMPONENTREGISTRAR
|
|
|
|
|
|
|
|
static nsresult Create(nsISupports* aOuter, REFNSIID aIID, void** aResult);
|
|
|
|
|
2005-12-13 20:55:43 +03:00
|
|
|
nsresult RegistryLocationForFile(nsIFile* aFile,
|
|
|
|
nsCString& aResult);
|
|
|
|
nsresult FileForRegistryLocation(const nsCString &aLocation,
|
|
|
|
nsILocalFile **aSpec);
|
|
|
|
|
2002-01-30 00:22:13 +03:00
|
|
|
NS_DECL_NSISERVICEMANAGER
|
2001-09-07 01:13:11 +04:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
// nsComponentManagerImpl methods:
|
|
|
|
nsComponentManagerImpl();
|
|
|
|
|
|
|
|
static nsComponentManagerImpl* gComponentManager;
|
2010-06-10 22:11:11 +04:00
|
|
|
nsresult Init();
|
2002-06-15 01:33:05 +04:00
|
|
|
|
1999-10-22 01:34:39 +04:00
|
|
|
nsresult Shutdown(void);
|
1999-03-09 12:44:27 +03:00
|
|
|
|
2001-10-16 07:35:52 +04:00
|
|
|
nsresult FreeServices();
|
|
|
|
|
2010-06-10 22:11:11 +04:00
|
|
|
already_AddRefed<mozilla::ModuleLoader> LoaderForExtension(const nsACString& aExt);
|
|
|
|
nsInterfaceHashtable<nsCStringHashKey, mozilla::ModuleLoader> mLoaderMap;
|
|
|
|
|
|
|
|
already_AddRefed<nsIFactory> FindFactory(const nsCID& aClass);
|
|
|
|
already_AddRefed<nsIFactory> FindFactory(const char *contractID,
|
|
|
|
PRUint32 aContractIDLen);
|
|
|
|
|
|
|
|
already_AddRefed<nsIFactory> LoadFactory(nsFactoryEntry *aEntry);
|
2001-08-22 02:42:35 +04:00
|
|
|
|
2003-03-14 08:07:24 +03:00
|
|
|
nsFactoryEntry *GetFactoryEntry(const char *aContractID,
|
|
|
|
PRUint32 aContractIDLen);
|
2002-06-15 01:33:05 +04:00
|
|
|
nsFactoryEntry *GetFactoryEntry(const nsCID &aClass);
|
1999-04-03 00:28:22 +04:00
|
|
|
|
2010-06-10 22:11:11 +04:00
|
|
|
nsDataHashtable<nsIDHashKey, nsFactoryEntry*> mFactories;
|
|
|
|
nsDataHashtable<nsCStringHashKey, nsFactoryEntry*> mContractIDs;
|
|
|
|
|
1999-07-28 12:01:03 +04:00
|
|
|
PRMonitor* mMon;
|
2001-12-19 03:12:41 +03:00
|
|
|
|
2010-06-10 22:11:11 +04:00
|
|
|
static void InitializeStaticModules();
|
|
|
|
static void InitializeModuleLocations();
|
|
|
|
|
2010-06-12 00:13:26 +04:00
|
|
|
struct ComponentLocation
|
|
|
|
{
|
|
|
|
NSLocationType type;
|
|
|
|
nsCOMPtr<nsILocalFile> location;
|
|
|
|
};
|
|
|
|
|
2010-06-10 22:11:11 +04:00
|
|
|
static nsTArray<const mozilla::Module*>* sStaticModules;
|
2010-06-12 00:13:26 +04:00
|
|
|
static nsTArray<ComponentLocation>* sModuleLocations;
|
2010-06-10 22:11:11 +04:00
|
|
|
|
2005-12-13 20:55:43 +03:00
|
|
|
nsNativeModuleLoader mNativeModuleLoader;
|
2000-02-01 10:54:46 +03:00
|
|
|
|
2010-06-10 22:11:11 +04:00
|
|
|
class KnownModule
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Static or binary module.
|
|
|
|
*/
|
|
|
|
KnownModule(const mozilla::Module* aModule, nsILocalFile* aFile)
|
|
|
|
: mModule(aModule)
|
|
|
|
, mFile(aFile)
|
|
|
|
, mLoaded(false)
|
|
|
|
, mFailed(false)
|
|
|
|
{ }
|
|
|
|
|
2010-06-12 00:13:26 +04:00
|
|
|
KnownModule(nsILocalFile* aFile)
|
2010-06-10 22:11:11 +04:00
|
|
|
: mModule(NULL)
|
|
|
|
, mFile(aFile)
|
2010-06-12 00:13:26 +04:00
|
|
|
, mLoader(NULL)
|
2010-06-10 22:11:11 +04:00
|
|
|
, mLoaded(false)
|
|
|
|
, mFailed(false)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
~KnownModule()
|
|
|
|
{
|
2010-06-21 20:46:26 +04:00
|
|
|
if (mLoaded && mModule->unloadProc)
|
|
|
|
mModule->unloadProc();
|
2010-06-10 22:11:11 +04:00
|
|
|
}
|
|
|
|
|
2010-06-12 00:13:26 +04:00
|
|
|
bool EnsureLoader();
|
2010-06-10 22:11:11 +04:00
|
|
|
bool Load();
|
|
|
|
|
|
|
|
const mozilla::Module* Module() const
|
|
|
|
{
|
|
|
|
return mModule;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const mozilla::Module* mModule;
|
|
|
|
nsCOMPtr<nsILocalFile> mFile;
|
|
|
|
nsCOMPtr<mozilla::ModuleLoader> mLoader;
|
|
|
|
bool mLoaded;
|
|
|
|
bool mFailed;
|
|
|
|
};
|
2003-03-05 06:22:12 +03:00
|
|
|
|
2010-06-12 00:13:26 +04:00
|
|
|
// The KnownModule is kept alive by these members, it is referenced by pointer
|
|
|
|
// from the factory entries.
|
|
|
|
nsTArray< nsAutoPtr<KnownModule> > mKnownStaticModules;
|
|
|
|
nsClassHashtable<nsHashableHashKey, KnownModule> mKnownFileModules;
|
2003-03-12 00:36:59 +03:00
|
|
|
|
2010-06-10 22:11:11 +04:00
|
|
|
void RegisterModule(const mozilla::Module* aModule,
|
|
|
|
nsILocalFile* aFile);
|
|
|
|
void RegisterCIDEntry(const mozilla::Module::CIDEntry* aEntry,
|
|
|
|
KnownModule* aModule);
|
|
|
|
void RegisterContractID(const mozilla::Module::ContractIDEntry* aEntry);
|
2001-08-30 18:10:41 +04:00
|
|
|
|
2010-06-23 00:24:01 +04:00
|
|
|
void RegisterLocation(NSLocationType aType, nsILocalFile* aLocation,
|
|
|
|
bool aChromeOnly);
|
2010-06-12 00:13:26 +04:00
|
|
|
|
|
|
|
// Register XPT/XPTJAR files, and fills aManifests with .manifest
|
|
|
|
// files, which must be registered after all DLLs so that networking is
|
|
|
|
// registered.
|
|
|
|
void RegisterDirectory(NSLocationType aType, nsILocalFile* aDirectory,
|
2010-06-23 00:24:01 +04:00
|
|
|
nsCOMArray<nsILocalFile>& aManifests,
|
|
|
|
bool aChromeOnly);
|
2010-06-12 00:13:26 +04:00
|
|
|
void RegisterFile(NSLocationType aType, nsILocalFile* aFile,
|
2010-06-23 00:24:01 +04:00
|
|
|
nsCOMArray<nsILocalFile>& aManifests,
|
|
|
|
bool aChromeOnly);
|
2010-06-12 00:13:26 +04:00
|
|
|
|
2010-06-23 00:24:01 +04:00
|
|
|
void RegisterManifestFile(NSLocationType aType, nsILocalFile* aFile,
|
|
|
|
bool aChromeOnly);
|
2010-06-12 00:13:26 +04:00
|
|
|
|
|
|
|
struct ManifestProcessingContext
|
|
|
|
{
|
|
|
|
ManifestProcessingContext(NSLocationType aType, nsILocalFile* aFile)
|
|
|
|
: mType(aType)
|
|
|
|
, mFile(aFile)
|
|
|
|
{ }
|
|
|
|
~ManifestProcessingContext() { }
|
|
|
|
|
|
|
|
NSLocationType mType;
|
|
|
|
nsCOMPtr<nsILocalFile> mFile;
|
|
|
|
};
|
|
|
|
|
|
|
|
void ManifestBinaryComponent(ManifestProcessingContext& cx, int lineno, char *const * argv);
|
|
|
|
void ManifestComponent(ManifestProcessingContext& cx, int lineno, char *const * argv);
|
|
|
|
void ManifestContract(ManifestProcessingContext& cx, int lineno, char* const * argv);
|
|
|
|
void ManifestCategory(ManifestProcessingContext& cx, int lineno, char* const * argv);
|
|
|
|
|
|
|
|
void RereadChromeManifests();
|
2005-12-13 20:55:43 +03:00
|
|
|
|
2010-06-10 22:11:11 +04:00
|
|
|
// Shutdown
|
|
|
|
enum {
|
|
|
|
NOT_INITIALIZED,
|
|
|
|
NORMAL,
|
|
|
|
SHUTDOWN_IN_PROGRESS,
|
|
|
|
SHUTDOWN_COMPLETE
|
|
|
|
} mStatus;
|
2002-05-03 01:25:08 +04:00
|
|
|
|
2010-06-10 22:11:11 +04:00
|
|
|
nsTArray<nsLoaderdata> mLoaderData;
|
2002-06-15 01:33:05 +04:00
|
|
|
|
2002-05-03 01:25:08 +04:00
|
|
|
PLArenaPool mArena;
|
2003-03-12 06:58:33 +03:00
|
|
|
|
2008-09-05 02:44:41 +04:00
|
|
|
struct PendingServiceInfo {
|
|
|
|
const nsCID* cid;
|
|
|
|
PRThread* thread;
|
|
|
|
};
|
2003-03-12 06:58:33 +03:00
|
|
|
|
2008-09-05 02:44:41 +04:00
|
|
|
inline PendingServiceInfo* AddPendingService(const nsCID& aServiceCID,
|
|
|
|
PRThread* aThread);
|
|
|
|
inline void RemovePendingService(const nsCID& aServiceCID);
|
|
|
|
inline PRThread* GetPendingServiceThread(const nsCID& aServiceCID) const;
|
|
|
|
|
|
|
|
nsTArray<PendingServiceInfo> mPendingServices;
|
2003-03-12 06:58:33 +03:00
|
|
|
|
2004-01-15 09:14:18 +03:00
|
|
|
private:
|
|
|
|
~nsComponentManagerImpl();
|
1999-03-09 12:44:27 +03:00
|
|
|
};
|
|
|
|
|
2001-09-07 01:13:11 +04:00
|
|
|
|
2010-06-23 21:36:53 +04:00
|
|
|
#define NS_MAX_FILENAME_LEN 1024
|
1999-03-09 12:44:27 +03:00
|
|
|
|
|
|
|
#define NS_ERROR_IS_DIR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_XPCOM, 24)
|
|
|
|
|
2010-06-10 22:11:11 +04:00
|
|
|
struct nsFactoryEntry
|
|
|
|
{
|
|
|
|
nsFactoryEntry(const mozilla::Module::CIDEntry* entry,
|
|
|
|
nsComponentManagerImpl::KnownModule* module);
|
1999-03-09 12:44:27 +03:00
|
|
|
|
2010-06-10 22:11:11 +04:00
|
|
|
// nsIComponentRegistrar.registerFactory support
|
|
|
|
nsFactoryEntry(nsIFactory* factory);
|
1999-03-09 12:44:27 +03:00
|
|
|
|
2010-06-10 22:11:11 +04:00
|
|
|
already_AddRefed<nsIFactory> GetFactory();
|
|
|
|
|
|
|
|
const mozilla::Module::CIDEntry* mCIDEntry;
|
|
|
|
nsComponentManagerImpl::KnownModule* mModule;
|
2001-10-23 06:28:12 +04:00
|
|
|
|
2010-06-10 22:11:11 +04:00
|
|
|
nsCOMPtr<nsIFactory> mFactory;
|
|
|
|
nsCOMPtr<nsISupports> mServiceObject;
|
2001-10-23 06:28:12 +04:00
|
|
|
};
|
2003-03-12 06:58:33 +03:00
|
|
|
|
1999-03-09 12:44:27 +03:00
|
|
|
#endif // nsComponentManager_h__
|