1999-03-10 09:53:25 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1999-03-09 09:44:27 +00:00
|
|
|
|
|
|
|
#ifndef nsComponentManager_h__
|
|
|
|
#define nsComponentManager_h__
|
|
|
|
|
2001-10-16 03:35:52 +00:00
|
|
|
#include "nsXPCOM.h"
|
|
|
|
|
2003-10-31 20:50:22 +00:00
|
|
|
#include "xpcom-private.h"
|
1999-03-09 09:44:27 +00:00
|
|
|
#include "nsIComponentManager.h"
|
2002-01-29 21:22:13 +00:00
|
|
|
#include "nsIComponentRegistrar.h"
|
2001-09-06 21:13:11 +00:00
|
|
|
#include "nsIServiceManager.h"
|
2005-12-13 17:55:43 +00:00
|
|
|
#include "nsILocalFile.h"
|
2010-06-10 18:11:11 +00:00
|
|
|
#include "mozilla/Module.h"
|
|
|
|
#include "mozilla/ModuleLoader.h"
|
2011-04-29 19:21:57 +00:00
|
|
|
#include "mozilla/ReentrantMonitor.h"
|
2010-06-11 20:13:26 +00:00
|
|
|
#include "nsXULAppAPI.h"
|
2005-12-13 17:55:43 +00:00
|
|
|
#include "nsNativeComponentLoader.h"
|
1999-08-31 21:40:21 +00:00
|
|
|
#include "nsIFactory.h"
|
2000-01-11 22:54:46 +00:00
|
|
|
#include "nsIInterfaceRequestor.h"
|
2001-09-05 21:28:38 +00:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
2001-10-23 02:28:12 +00:00
|
|
|
#include "pldhash.h"
|
1999-03-09 09:44:27 +00:00
|
|
|
#include "prtime.h"
|
1999-08-31 21:40:21 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2010-06-10 18:11:11 +00:00
|
|
|
#include "nsAutoPtr.h"
|
1999-10-15 21:14:43 +00:00
|
|
|
#include "nsWeakReference.h"
|
2000-01-24 21:28:28 +00:00
|
|
|
#include "nsIFile.h"
|
2002-05-02 21:25:08 +00:00
|
|
|
#include "plarena.h"
|
2005-12-13 17:55:43 +00:00
|
|
|
#include "nsCOMArray.h"
|
|
|
|
#include "nsDataHashtable.h"
|
2010-06-10 18:11:11 +00:00
|
|
|
#include "nsInterfaceHashtable.h"
|
2010-06-11 20:13:26 +00:00
|
|
|
#include "nsClassHashtable.h"
|
2005-12-13 17:55:43 +00:00
|
|
|
#include "nsTArray.h"
|
1999-03-09 09:44:27 +00:00
|
|
|
|
2010-07-02 13:53:19 +00:00
|
|
|
#include "mozilla/Omnijar.h"
|
|
|
|
|
2005-12-13 17:55:43 +00:00
|
|
|
struct nsFactoryEntry;
|
1999-07-31 05:55:26 +00:00
|
|
|
class nsIServiceManager;
|
2008-09-04 22:44:41 +00:00
|
|
|
struct PRThread;
|
1999-03-09 09:44:27 +00:00
|
|
|
|
2004-11-23 20:53:38 +00: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 09:44:27 +00:00
|
|
|
|
2003-03-12 03:58:33 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
#define XPCOM_CHECK_PENDING_CIDS
|
|
|
|
#endif
|
1999-03-09 09:44:27 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
extern const mozilla::Module kXPCOMModule;
|
|
|
|
|
2002-06-14 21:33:05 +00:00
|
|
|
// Array of Loaders and their type strings
|
|
|
|
struct nsLoaderdata {
|
2010-06-10 18:11:11 +00:00
|
|
|
nsCOMPtr<mozilla::ModuleLoader> loader;
|
2005-12-13 17:55:43 +00:00
|
|
|
nsCString type;
|
|
|
|
};
|
|
|
|
|
2000-01-11 22:54:46 +00:00
|
|
|
class nsComponentManagerImpl
|
2010-07-02 13:53:19 +00:00
|
|
|
: public nsIComponentManager
|
|
|
|
, public nsIServiceManager
|
|
|
|
, public nsSupportsWeakReference
|
|
|
|
, public nsIComponentRegistrar
|
|
|
|
, public nsIInterfaceRequestor
|
2001-10-16 23:39:20 +00:00
|
|
|
{
|
1999-03-09 09:44:27 +00:00
|
|
|
public:
|
1999-03-10 09:53:25 +00:00
|
|
|
NS_DECL_ISUPPORTS
|
2000-01-11 22:54:46 +00:00
|
|
|
NS_DECL_NSIINTERFACEREQUESTOR
|
2010-06-10 18:11:11 +00:00
|
|
|
NS_DECL_NSICOMPONENTMANAGER
|
|
|
|
NS_DECL_NSICOMPONENTREGISTRAR
|
|
|
|
|
|
|
|
static nsresult Create(nsISupports* aOuter, REFNSIID aIID, void** aResult);
|
|
|
|
|
2005-12-13 17:55:43 +00:00
|
|
|
nsresult RegistryLocationForFile(nsIFile* aFile,
|
|
|
|
nsCString& aResult);
|
|
|
|
nsresult FileForRegistryLocation(const nsCString &aLocation,
|
|
|
|
nsILocalFile **aSpec);
|
|
|
|
|
2002-01-29 21:22:13 +00:00
|
|
|
NS_DECL_NSISERVICEMANAGER
|
2001-09-06 21:13:11 +00:00
|
|
|
|
1999-03-10 09:53:25 +00:00
|
|
|
// nsComponentManagerImpl methods:
|
|
|
|
nsComponentManagerImpl();
|
|
|
|
|
|
|
|
static nsComponentManagerImpl* gComponentManager;
|
2010-06-10 18:11:11 +00:00
|
|
|
nsresult Init();
|
2002-06-14 21:33:05 +00:00
|
|
|
|
1999-10-21 21:34:39 +00:00
|
|
|
nsresult Shutdown(void);
|
1999-03-09 09:44:27 +00:00
|
|
|
|
2001-10-16 03:35:52 +00:00
|
|
|
nsresult FreeServices();
|
|
|
|
|
2010-06-10 18:11:11 +00: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-21 22:42:35 +00:00
|
|
|
|
2003-03-14 05:07:24 +00:00
|
|
|
nsFactoryEntry *GetFactoryEntry(const char *aContractID,
|
|
|
|
PRUint32 aContractIDLen);
|
2002-06-14 21:33:05 +00:00
|
|
|
nsFactoryEntry *GetFactoryEntry(const nsCID &aClass);
|
1999-04-02 20:28:22 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
nsDataHashtable<nsIDHashKey, nsFactoryEntry*> mFactories;
|
|
|
|
nsDataHashtable<nsCStringHashKey, nsFactoryEntry*> mContractIDs;
|
|
|
|
|
2011-04-29 19:21:57 +00:00
|
|
|
mozilla::ReentrantMonitor mMon;
|
2001-12-19 00:12:41 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
static void InitializeStaticModules();
|
|
|
|
static void InitializeModuleLocations();
|
|
|
|
|
2010-06-11 20:13:26 +00:00
|
|
|
struct ComponentLocation
|
|
|
|
{
|
|
|
|
NSLocationType type;
|
2011-11-08 17:10:51 +00:00
|
|
|
mozilla::FileLocation location;
|
2010-06-11 20:13:26 +00:00
|
|
|
};
|
|
|
|
|
2011-07-29 09:20:47 +00:00
|
|
|
class ComponentLocationComparator
|
|
|
|
{
|
|
|
|
public:
|
2011-09-29 06:19:26 +00:00
|
|
|
bool Equals(const ComponentLocation& a, const ComponentLocation& b) const
|
2011-07-29 09:20:47 +00:00
|
|
|
{
|
2011-11-08 17:10:51 +00:00
|
|
|
return (a.type == b.type && a.location.Equals(b.location));
|
2011-07-29 09:20:47 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
static nsTArray<const mozilla::Module*>* sStaticModules;
|
2010-06-11 20:13:26 +00:00
|
|
|
static nsTArray<ComponentLocation>* sModuleLocations;
|
2010-06-10 18:11:11 +00:00
|
|
|
|
2005-12-13 17:55:43 +00:00
|
|
|
nsNativeModuleLoader mNativeModuleLoader;
|
2000-02-01 07:54:46 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
class KnownModule
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Static or binary module.
|
|
|
|
*/
|
2011-11-08 17:10:51 +00:00
|
|
|
KnownModule(const mozilla::Module* aModule, mozilla::FileLocation &aFile)
|
2010-06-10 18:11:11 +00:00
|
|
|
: mModule(aModule)
|
|
|
|
, mFile(aFile)
|
|
|
|
, mLoaded(false)
|
|
|
|
, mFailed(false)
|
|
|
|
{ }
|
|
|
|
|
2011-11-08 17:10:51 +00:00
|
|
|
KnownModule(const mozilla::Module* aModule)
|
|
|
|
: mModule(aModule)
|
2010-06-10 18:11:11 +00:00
|
|
|
, mLoaded(false)
|
|
|
|
, mFailed(false)
|
|
|
|
{ }
|
|
|
|
|
2011-11-08 17:10:51 +00:00
|
|
|
KnownModule(mozilla::FileLocation &aFile)
|
2010-07-02 13:53:19 +00:00
|
|
|
: mModule(NULL)
|
2010-09-09 03:37:11 +00:00
|
|
|
, mFile(aFile)
|
2010-07-02 13:53:19 +00:00
|
|
|
, mLoader(NULL)
|
|
|
|
, mLoaded(false)
|
|
|
|
, mFailed(false)
|
|
|
|
{ }
|
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
~KnownModule()
|
|
|
|
{
|
2010-06-21 16:46:26 +00:00
|
|
|
if (mLoaded && mModule->unloadProc)
|
|
|
|
mModule->unloadProc();
|
2010-06-10 18:11:11 +00:00
|
|
|
}
|
|
|
|
|
2010-06-11 20:13:26 +00:00
|
|
|
bool EnsureLoader();
|
2010-06-10 18:11:11 +00:00
|
|
|
bool Load();
|
|
|
|
|
|
|
|
const mozilla::Module* Module() const
|
|
|
|
{
|
|
|
|
return mModule;
|
|
|
|
}
|
|
|
|
|
2010-06-28 17:55:57 +00:00
|
|
|
/**
|
|
|
|
* For error logging, get a description of this module, either the
|
|
|
|
* file path, or <static module>.
|
|
|
|
*/
|
|
|
|
nsCString Description() const;
|
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
private:
|
|
|
|
const mozilla::Module* mModule;
|
2011-11-08 17:10:51 +00:00
|
|
|
mozilla::FileLocation mFile;
|
2010-06-10 18:11:11 +00:00
|
|
|
nsCOMPtr<mozilla::ModuleLoader> mLoader;
|
|
|
|
bool mLoaded;
|
|
|
|
bool mFailed;
|
|
|
|
};
|
2003-03-05 03:22:12 +00:00
|
|
|
|
2010-07-02 13:53:19 +00:00
|
|
|
// The KnownModule is kept alive by these members, it is
|
|
|
|
// referenced by pointer from the factory entries.
|
2010-06-11 20:13:26 +00:00
|
|
|
nsTArray< nsAutoPtr<KnownModule> > mKnownStaticModules;
|
2011-11-08 17:18:12 +00:00
|
|
|
// The key is the URI string of the module
|
|
|
|
nsClassHashtable<nsCStringHashKey, KnownModule> mKnownModules;
|
2003-03-11 21:36:59 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
void RegisterModule(const mozilla::Module* aModule,
|
2011-11-08 17:10:51 +00:00
|
|
|
mozilla::FileLocation* aFile);
|
2010-06-10 18:11:11 +00:00
|
|
|
void RegisterCIDEntry(const mozilla::Module::CIDEntry* aEntry,
|
|
|
|
KnownModule* aModule);
|
|
|
|
void RegisterContractID(const mozilla::Module::ContractIDEntry* aEntry);
|
2001-08-30 14:10:41 +00:00
|
|
|
|
2011-11-08 17:10:51 +00:00
|
|
|
void RegisterManifest(NSLocationType aType, mozilla::FileLocation &aFile,
|
|
|
|
bool aChromeOnly);
|
2010-06-11 20:13:26 +00:00
|
|
|
|
|
|
|
struct ManifestProcessingContext
|
|
|
|
{
|
2011-11-08 17:10:51 +00:00
|
|
|
ManifestProcessingContext(NSLocationType aType, mozilla::FileLocation &aFile, bool aChromeOnly)
|
2010-06-11 20:13:26 +00:00
|
|
|
: mType(aType)
|
|
|
|
, mFile(aFile)
|
2010-07-22 14:31:29 +00:00
|
|
|
, mChromeOnly(aChromeOnly)
|
2010-07-02 13:53:19 +00:00
|
|
|
{ }
|
|
|
|
|
2010-06-11 20:13:26 +00:00
|
|
|
~ManifestProcessingContext() { }
|
|
|
|
|
|
|
|
NSLocationType mType;
|
2011-11-08 17:10:51 +00:00
|
|
|
mozilla::FileLocation mFile;
|
2010-07-22 14:31:29 +00:00
|
|
|
bool mChromeOnly;
|
2010-06-11 20:13:26 +00:00
|
|
|
};
|
|
|
|
|
2010-07-22 14:31:29 +00:00
|
|
|
void ManifestManifest(ManifestProcessingContext& cx, int lineno, char *const * argv);
|
2010-06-11 20:13:26 +00:00
|
|
|
void ManifestBinaryComponent(ManifestProcessingContext& cx, int lineno, char *const * argv);
|
2010-06-25 17:55:46 +00:00
|
|
|
void ManifestXPT(ManifestProcessingContext& cx, int lineno, char *const * argv);
|
2010-06-11 20:13:26 +00:00
|
|
|
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);
|
|
|
|
|
2011-12-08 10:03:36 +00:00
|
|
|
void RereadChromeManifests(bool aChromeOnly = true);
|
2005-12-13 17:55:43 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
// Shutdown
|
|
|
|
enum {
|
|
|
|
NOT_INITIALIZED,
|
|
|
|
NORMAL,
|
|
|
|
SHUTDOWN_IN_PROGRESS,
|
|
|
|
SHUTDOWN_COMPLETE
|
|
|
|
} mStatus;
|
2002-05-02 21:25:08 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
nsTArray<nsLoaderdata> mLoaderData;
|
2002-06-14 21:33:05 +00:00
|
|
|
|
2002-05-02 21:25:08 +00:00
|
|
|
PLArenaPool mArena;
|
2003-03-12 03:58:33 +00:00
|
|
|
|
2008-09-04 22:44:41 +00:00
|
|
|
struct PendingServiceInfo {
|
|
|
|
const nsCID* cid;
|
|
|
|
PRThread* thread;
|
|
|
|
};
|
2003-03-12 03:58:33 +00:00
|
|
|
|
2008-09-04 22:44:41 +00: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 03:58:33 +00:00
|
|
|
|
2004-01-15 06:14:18 +00:00
|
|
|
private:
|
|
|
|
~nsComponentManagerImpl();
|
1999-03-09 09:44:27 +00:00
|
|
|
};
|
|
|
|
|
2001-09-06 21:13:11 +00:00
|
|
|
|
2010-06-23 17:36:53 +00:00
|
|
|
#define NS_MAX_FILENAME_LEN 1024
|
1999-03-09 09:44:27 +00:00
|
|
|
|
|
|
|
#define NS_ERROR_IS_DIR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_XPCOM, 24)
|
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
struct nsFactoryEntry
|
|
|
|
{
|
|
|
|
nsFactoryEntry(const mozilla::Module::CIDEntry* entry,
|
|
|
|
nsComponentManagerImpl::KnownModule* module);
|
1999-03-09 09:44:27 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
// nsIComponentRegistrar.registerFactory support
|
2010-06-25 14:44:35 +00:00
|
|
|
nsFactoryEntry(const nsCID& aClass, nsIFactory* factory);
|
|
|
|
|
|
|
|
~nsFactoryEntry();
|
1999-03-09 09:44:27 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
already_AddRefed<nsIFactory> GetFactory();
|
|
|
|
|
|
|
|
const mozilla::Module::CIDEntry* mCIDEntry;
|
|
|
|
nsComponentManagerImpl::KnownModule* mModule;
|
2001-10-23 02:28:12 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
nsCOMPtr<nsIFactory> mFactory;
|
|
|
|
nsCOMPtr<nsISupports> mServiceObject;
|
2001-10-23 02:28:12 +00:00
|
|
|
};
|
2003-03-12 03:58:33 +00:00
|
|
|
|
1999-03-09 09:44:27 +00:00
|
|
|
#endif // nsComponentManager_h__
|