2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifndef nsComponentManager_h__
|
|
|
|
#define nsComponentManager_h__
|
|
|
|
|
|
|
|
#include "nsXPCOM.h"
|
|
|
|
|
|
|
|
#include "xpcom-private.h"
|
|
|
|
#include "nsIComponentManager.h"
|
|
|
|
#include "nsIComponentRegistrar.h"
|
2013-11-06 21:35:30 -08:00
|
|
|
#include "nsIMemoryReporter.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIServiceManager.h"
|
2012-06-05 19:08:30 -07:00
|
|
|
#include "nsIFile.h"
|
2013-06-23 05:03:39 -07:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2010-06-10 11:11:11 -07:00
|
|
|
#include "mozilla/Module.h"
|
|
|
|
#include "mozilla/ModuleLoader.h"
|
2013-03-13 13:39:28 -07:00
|
|
|
#include "mozilla/Mutex.h"
|
2010-06-11 13:13:26 -07:00
|
|
|
#include "nsXULAppAPI.h"
|
2014-07-28 10:15:57 -07:00
|
|
|
#include "nsNativeModuleLoader.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIFactory.h"
|
|
|
|
#include "nsIInterfaceRequestor.h"
|
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
|
|
|
#include "pldhash.h"
|
|
|
|
#include "prtime.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2010-06-10 11:11:11 -07:00
|
|
|
#include "nsAutoPtr.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsWeakReference.h"
|
|
|
|
#include "plarena.h"
|
|
|
|
#include "nsCOMArray.h"
|
|
|
|
#include "nsDataHashtable.h"
|
2010-06-10 11:11:11 -07:00
|
|
|
#include "nsInterfaceHashtable.h"
|
2010-06-11 13:13:26 -07:00
|
|
|
#include "nsClassHashtable.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsTArray.h"
|
|
|
|
|
2010-07-02 06:53:19 -07:00
|
|
|
#include "mozilla/Omnijar.h"
|
2012-06-05 16:51:58 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2010-07-02 06:53:19 -07:00
|
|
|
|
2014-07-25 17:52:00 -07:00
|
|
|
#ifdef MOZ_B2G_LOADER
|
|
|
|
#include "mozilla/FileLocation.h"
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
struct nsFactoryEntry;
|
2013-01-17 21:43:21 -08:00
|
|
|
class nsIServiceManager;
|
2008-09-04 15:44:41 -07:00
|
|
|
struct PRThread;
|
2007-03-22 10:30:00 -07: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[];
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
#define XPCOM_CHECK_PENDING_CIDS
|
|
|
|
#endif
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
extern const mozilla::Module kXPCOMModule;
|
|
|
|
|
2013-03-13 13:39:53 -07:00
|
|
|
/**
|
|
|
|
* This is a wrapper around mozilla::Mutex which provides runtime
|
|
|
|
* checking for a deadlock where the same thread tries to lock a mutex while
|
|
|
|
* it is already locked. This checking is present in both debug and release
|
|
|
|
* builds.
|
|
|
|
*/
|
|
|
|
class SafeMutex
|
|
|
|
{
|
|
|
|
public:
|
2014-08-05 06:21:27 -07:00
|
|
|
explicit SafeMutex(const char* aName)
|
2014-08-02 13:44:06 -07:00
|
|
|
: mMutex(aName)
|
|
|
|
, mOwnerThread(nullptr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~SafeMutex() {}
|
|
|
|
|
|
|
|
void Lock()
|
|
|
|
{
|
|
|
|
AssertNotCurrentThreadOwns();
|
|
|
|
mMutex.Lock();
|
|
|
|
MOZ_ASSERT(mOwnerThread == nullptr);
|
|
|
|
mOwnerThread = PR_GetCurrentThread();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Unlock()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mOwnerThread == PR_GetCurrentThread());
|
|
|
|
mOwnerThread = nullptr;
|
|
|
|
mMutex.Unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AssertCurrentThreadOwns() const
|
|
|
|
{
|
|
|
|
// This method is a debug-only check
|
|
|
|
MOZ_ASSERT(mOwnerThread == PR_GetCurrentThread());
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_NEVER_INLINE void AssertNotCurrentThreadOwns() const
|
|
|
|
{
|
|
|
|
// This method is a release-mode check
|
|
|
|
if (PR_GetCurrentThread() == mOwnerThread) {
|
|
|
|
MOZ_CRASH();
|
2013-03-13 13:39:53 -07:00
|
|
|
}
|
2014-08-02 13:44:06 -07:00
|
|
|
}
|
2013-03-13 13:39:53 -07:00
|
|
|
|
|
|
|
private:
|
2014-08-02 13:44:06 -07:00
|
|
|
mozilla::Mutex mMutex;
|
|
|
|
volatile PRThread* mOwnerThread;
|
2013-03-13 13:39:53 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef mozilla::BaseAutoLock<SafeMutex> SafeMutexAutoLock;
|
|
|
|
typedef mozilla::BaseAutoUnlock<SafeMutex> SafeMutexAutoUnlock;
|
|
|
|
|
2012-06-05 16:51:58 -07:00
|
|
|
class nsComponentManagerImpl MOZ_FINAL
|
2014-08-02 13:44:06 -07:00
|
|
|
: public nsIComponentManager
|
|
|
|
, public nsIServiceManager
|
|
|
|
, public nsSupportsWeakReference
|
|
|
|
, public nsIComponentRegistrar
|
|
|
|
, public nsIInterfaceRequestor
|
|
|
|
, public nsIMemoryReporter
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
2014-08-02 13:44:06 -07:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
|
|
|
NS_DECL_NSIINTERFACEREQUESTOR
|
|
|
|
NS_DECL_NSICOMPONENTMANAGER
|
|
|
|
NS_DECL_NSICOMPONENTREGISTRAR
|
|
|
|
NS_DECL_NSIMEMORYREPORTER
|
2010-06-10 11:11:11 -07:00
|
|
|
|
2014-08-02 13:44:06 -07:00
|
|
|
static nsresult Create(nsISupports* aOuter, REFNSIID aIID, void** aResult);
|
2010-06-10 11:11:11 -07:00
|
|
|
|
2014-08-02 13:44:06 -07:00
|
|
|
nsresult RegistryLocationForFile(nsIFile* aFile,
|
|
|
|
nsCString& aResult);
|
|
|
|
nsresult FileForRegistryLocation(const nsCString& aLocation,
|
|
|
|
nsIFile** aSpec);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-08-02 13:44:06 -07:00
|
|
|
NS_DECL_NSISERVICEMANAGER
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-08-02 13:44:06 -07:00
|
|
|
// nsComponentManagerImpl methods:
|
|
|
|
nsComponentManagerImpl();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-08-02 13:44:06 -07:00
|
|
|
static nsComponentManagerImpl* gComponentManager;
|
|
|
|
nsresult Init();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-08-02 13:44:06 -07:00
|
|
|
nsresult Shutdown(void);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-08-02 13:44:06 -07:00
|
|
|
nsresult FreeServices();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-08-02 13:44:06 -07:00
|
|
|
already_AddRefed<mozilla::ModuleLoader> LoaderForExtension(const nsACString& aExt);
|
|
|
|
nsInterfaceHashtable<nsCStringHashKey, mozilla::ModuleLoader> mLoaderMap;
|
2010-06-10 11:11:11 -07:00
|
|
|
|
2014-08-02 13:44:06 -07:00
|
|
|
already_AddRefed<nsIFactory> FindFactory(const nsCID& aClass);
|
|
|
|
already_AddRefed<nsIFactory> FindFactory(const char* aContractID,
|
|
|
|
uint32_t aContractIDLen);
|
2010-06-10 11:11:11 -07:00
|
|
|
|
2014-08-02 13:44:06 -07:00
|
|
|
already_AddRefed<nsIFactory> LoadFactory(nsFactoryEntry* aEntry);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-08-02 13:44:06 -07:00
|
|
|
nsFactoryEntry* GetFactoryEntry(const char* aContractID,
|
|
|
|
uint32_t aContractIDLen);
|
|
|
|
nsFactoryEntry* GetFactoryEntry(const nsCID& aClass);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-08-02 13:44:06 -07:00
|
|
|
nsDataHashtable<nsIDHashKey, nsFactoryEntry*> mFactories;
|
|
|
|
nsDataHashtable<nsCStringHashKey, nsFactoryEntry*> mContractIDs;
|
2010-06-10 11:11:11 -07:00
|
|
|
|
2014-08-02 13:44:06 -07:00
|
|
|
SafeMutex mLock;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-08-02 13:44:06 -07:00
|
|
|
static void InitializeStaticModules();
|
|
|
|
static void InitializeModuleLocations();
|
2010-06-10 11:11:11 -07:00
|
|
|
|
2014-08-02 13:44:06 -07:00
|
|
|
struct ComponentLocation
|
|
|
|
{
|
|
|
|
NSLocationType type;
|
|
|
|
mozilla::FileLocation location;
|
|
|
|
};
|
2010-06-11 13:13:26 -07:00
|
|
|
|
2014-08-02 13:44:06 -07:00
|
|
|
class ComponentLocationComparator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool Equals(const ComponentLocation& aA, const ComponentLocation& aB) const
|
2011-07-29 02:20:47 -07:00
|
|
|
{
|
2014-08-02 13:44:06 -07:00
|
|
|
return (aA.type == aB.type && aA.location.Equals(aB.location));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static nsTArray<const mozilla::Module*>* sStaticModules;
|
|
|
|
static nsTArray<ComponentLocation>* sModuleLocations;
|
|
|
|
|
|
|
|
nsNativeModuleLoader mNativeModuleLoader;
|
|
|
|
|
|
|
|
class KnownModule
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Static or binary module.
|
|
|
|
*/
|
|
|
|
KnownModule(const mozilla::Module* aModule, mozilla::FileLocation& aFile)
|
|
|
|
: mModule(aModule)
|
|
|
|
, mFile(aFile)
|
|
|
|
, mLoaded(false)
|
|
|
|
, mFailed(false)
|
2010-06-11 13:13:26 -07:00
|
|
|
{
|
2014-08-02 13:44:06 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-08-05 06:21:27 -07:00
|
|
|
explicit KnownModule(const mozilla::Module* aModule)
|
2014-08-02 13:44:06 -07:00
|
|
|
: mModule(aModule)
|
|
|
|
, mLoaded(false)
|
|
|
|
, mFailed(false)
|
|
|
|
{
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-08-05 06:21:27 -07:00
|
|
|
explicit KnownModule(mozilla::FileLocation& aFile)
|
2014-08-02 13:44:06 -07:00
|
|
|
: mModule(nullptr)
|
|
|
|
, mFile(aFile)
|
|
|
|
, mLoader(nullptr)
|
|
|
|
, mLoaded(false)
|
|
|
|
, mFailed(false)
|
|
|
|
{
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-08-02 13:44:06 -07:00
|
|
|
~KnownModule()
|
|
|
|
{
|
|
|
|
if (mLoaded && mModule->unloadProc) {
|
|
|
|
mModule->unloadProc();
|
|
|
|
}
|
|
|
|
}
|
2008-09-04 15:44:41 -07:00
|
|
|
|
2014-08-02 13:44:06 -07:00
|
|
|
bool EnsureLoader();
|
|
|
|
bool Load();
|
|
|
|
|
|
|
|
const mozilla::Module* Module() const { return mModule; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* For error logging, get a description of this module, either the
|
|
|
|
* file path, or <static module>.
|
|
|
|
*/
|
|
|
|
nsCString Description() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
const mozilla::Module* mModule;
|
|
|
|
mozilla::FileLocation mFile;
|
|
|
|
nsCOMPtr<mozilla::ModuleLoader> mLoader;
|
|
|
|
bool mLoaded;
|
|
|
|
bool mFailed;
|
|
|
|
};
|
|
|
|
|
|
|
|
// The KnownModule is kept alive by these members, it is
|
|
|
|
// referenced by pointer from the factory entries.
|
|
|
|
nsTArray<nsAutoPtr<KnownModule>> mKnownStaticModules;
|
|
|
|
// The key is the URI string of the module
|
|
|
|
nsClassHashtable<nsCStringHashKey, KnownModule> mKnownModules;
|
|
|
|
|
|
|
|
// Mutex not held
|
|
|
|
void RegisterModule(const mozilla::Module* aModule,
|
|
|
|
mozilla::FileLocation* aFile);
|
|
|
|
|
|
|
|
|
|
|
|
// Mutex held
|
|
|
|
void RegisterCIDEntryLocked(const mozilla::Module::CIDEntry* aEntry,
|
|
|
|
KnownModule* aModule);
|
|
|
|
void RegisterContractIDLocked(const mozilla::Module::ContractIDEntry* aEntry);
|
|
|
|
|
|
|
|
// Mutex not held
|
|
|
|
void RegisterManifest(NSLocationType aType, mozilla::FileLocation& aFile,
|
|
|
|
bool aChromeOnly);
|
|
|
|
|
|
|
|
struct ManifestProcessingContext
|
|
|
|
{
|
|
|
|
ManifestProcessingContext(NSLocationType aType,
|
|
|
|
mozilla::FileLocation& aFile, bool aChromeOnly)
|
|
|
|
: mType(aType)
|
|
|
|
, mFile(aFile)
|
|
|
|
, mChromeOnly(aChromeOnly)
|
|
|
|
{
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-08-02 13:44:06 -07:00
|
|
|
~ManifestProcessingContext() {}
|
|
|
|
|
|
|
|
NSLocationType mType;
|
|
|
|
mozilla::FileLocation mFile;
|
|
|
|
bool mChromeOnly;
|
|
|
|
};
|
|
|
|
|
|
|
|
void ManifestManifest(ManifestProcessingContext& aCx, int aLineNo,
|
|
|
|
char* const* aArgv);
|
|
|
|
void ManifestBinaryComponent(ManifestProcessingContext& aCx, int aLineNo,
|
|
|
|
char* const* aArgv);
|
|
|
|
void ManifestXPT(ManifestProcessingContext& aCx, int aLineNo,
|
|
|
|
char* const* aArgv);
|
|
|
|
void ManifestComponent(ManifestProcessingContext& aCx, int aLineNo,
|
|
|
|
char* const* aArgv);
|
|
|
|
void ManifestContract(ManifestProcessingContext& aCx, int aLineNo,
|
|
|
|
char* const* aArgv);
|
|
|
|
void ManifestCategory(ManifestProcessingContext& aCx, int aLineNo,
|
|
|
|
char* const* aArgv);
|
|
|
|
|
|
|
|
void RereadChromeManifests(bool aChromeOnly = true);
|
|
|
|
|
|
|
|
// Shutdown
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
NOT_INITIALIZED,
|
|
|
|
NORMAL,
|
|
|
|
SHUTDOWN_IN_PROGRESS,
|
|
|
|
SHUTDOWN_COMPLETE
|
|
|
|
} mStatus;
|
|
|
|
|
|
|
|
PLArenaPool mArena;
|
|
|
|
|
|
|
|
struct PendingServiceInfo
|
|
|
|
{
|
|
|
|
const nsCID* cid;
|
|
|
|
PRThread* thread;
|
|
|
|
};
|
|
|
|
|
|
|
|
inline PendingServiceInfo* AddPendingService(const nsCID& aServiceCID,
|
|
|
|
PRThread* aThread);
|
|
|
|
inline void RemovePendingService(const nsCID& aServiceCID);
|
|
|
|
inline PRThread* GetPendingServiceThread(const nsCID& aServiceCID) const;
|
|
|
|
|
|
|
|
nsTArray<PendingServiceInfo> mPendingServices;
|
|
|
|
|
|
|
|
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf);
|
2012-10-19 05:07:36 -07:00
|
|
|
|
2014-07-25 17:52:00 -07:00
|
|
|
#ifdef MOZ_B2G_LOADER
|
2014-08-02 13:44:06 -07:00
|
|
|
// Preload XPT interface info for B2G loader.
|
|
|
|
// This function is called before XPCOM has been initialized.
|
|
|
|
static void PreloadXPT(nsIFile* aFile);
|
2014-07-25 17:52:00 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef MOZ_B2G_LOADER
|
2014-08-02 13:44:06 -07:00
|
|
|
// Parsing functions of directives of manifest for XPT only parsing.
|
|
|
|
struct XPTOnlyManifestProcessingContext
|
|
|
|
{
|
|
|
|
XPTOnlyManifestProcessingContext(mozilla::FileLocation& aFile)
|
|
|
|
: mFile(aFile)
|
2014-07-25 17:52:00 -07:00
|
|
|
{
|
2014-08-02 13:44:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
~XPTOnlyManifestProcessingContext() {}
|
|
|
|
|
|
|
|
mozilla::FileLocation mFile;
|
|
|
|
};
|
|
|
|
static void XPTOnlyManifestManifest(XPTOnlyManifestProcessingContext& aCx,
|
|
|
|
int aLineNo, char* const* aArgv);
|
|
|
|
static void XPTOnlyManifestXPT(XPTOnlyManifestProcessingContext& aCx,
|
|
|
|
int aLineNo, char* const* aArgv);
|
2014-07-25 17:52:00 -07:00
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
private:
|
2014-08-02 13:44:06 -07:00
|
|
|
~nsComponentManagerImpl();
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-06-23 10:36:53 -07:00
|
|
|
#define NS_MAX_FILENAME_LEN 1024
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#define NS_ERROR_IS_DIR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_XPCOM, 24)
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
struct nsFactoryEntry
|
|
|
|
{
|
2014-08-02 13:44:06 -07:00
|
|
|
nsFactoryEntry(const mozilla::Module::CIDEntry* aEntry,
|
|
|
|
nsComponentManagerImpl::KnownModule* aModule);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-08-02 13:44:06 -07:00
|
|
|
// nsIComponentRegistrar.registerFactory support
|
|
|
|
nsFactoryEntry(const nsCID& aClass, nsIFactory* aFactory);
|
2010-06-25 07:44:35 -07:00
|
|
|
|
2014-08-02 13:44:06 -07:00
|
|
|
~nsFactoryEntry();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-08-02 13:44:06 -07:00
|
|
|
already_AddRefed<nsIFactory> GetFactory();
|
2010-06-10 11:11:11 -07:00
|
|
|
|
2014-08-02 13:44:06 -07:00
|
|
|
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf);
|
2012-10-19 05:07:36 -07:00
|
|
|
|
2014-08-02 13:44:06 -07:00
|
|
|
const mozilla::Module::CIDEntry* mCIDEntry;
|
|
|
|
nsComponentManagerImpl::KnownModule* mModule;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-08-02 13:44:06 -07:00
|
|
|
nsCOMPtr<nsIFactory> mFactory;
|
|
|
|
nsCOMPtr<nsISupports> mServiceObject;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsComponentManager_h__
|