2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* 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/
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* 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
|
|
|
|
* 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"),
|
|
|
|
* 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
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* 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
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#ifndef nsComponentManager_h__
|
|
|
|
#define nsComponentManager_h__
|
|
|
|
|
|
|
|
#include "nsXPCOM.h"
|
|
|
|
|
|
|
|
#include "xpcom-private.h"
|
|
|
|
#include "nsIComponentManager.h"
|
|
|
|
#include "nsIComponentRegistrar.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsILocalFile.h"
|
2010-06-10 11:11:11 -07:00
|
|
|
#include "mozilla/Module.h"
|
|
|
|
#include "mozilla/ModuleLoader.h"
|
2011-04-29 12:21:57 -07:00
|
|
|
#include "mozilla/ReentrantMonitor.h"
|
2010-06-11 13:13:26 -07:00
|
|
|
#include "nsXULAppAPI.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsNativeComponentLoader.h"
|
|
|
|
#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 "nsIFile.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"
|
2010-09-08 20:37:11 -07:00
|
|
|
#include "nsIZipReader.h"
|
2010-07-02 06:53:19 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
struct nsFactoryEntry;
|
|
|
|
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;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Array of Loaders and their type strings
|
|
|
|
struct nsLoaderdata {
|
2010-06-10 11:11:11 -07:00
|
|
|
nsCOMPtr<mozilla::ModuleLoader> loader;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCString type;
|
|
|
|
};
|
|
|
|
|
|
|
|
class nsComponentManagerImpl
|
2010-07-02 06:53:19 -07:00
|
|
|
: public nsIComponentManager
|
|
|
|
, public nsIServiceManager
|
|
|
|
, public nsSupportsWeakReference
|
|
|
|
, public nsIComponentRegistrar
|
|
|
|
, public nsIInterfaceRequestor
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIINTERFACEREQUESTOR
|
2010-06-10 11:11:11 -07:00
|
|
|
NS_DECL_NSICOMPONENTMANAGER
|
|
|
|
NS_DECL_NSICOMPONENTREGISTRAR
|
|
|
|
|
|
|
|
static nsresult Create(nsISupports* aOuter, REFNSIID aIID, void** aResult);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult RegistryLocationForFile(nsIFile* aFile,
|
|
|
|
nsCString& aResult);
|
|
|
|
nsresult FileForRegistryLocation(const nsCString &aLocation,
|
|
|
|
nsILocalFile **aSpec);
|
|
|
|
|
|
|
|
NS_DECL_NSISERVICEMANAGER
|
|
|
|
|
|
|
|
// nsComponentManagerImpl methods:
|
|
|
|
nsComponentManagerImpl();
|
|
|
|
|
|
|
|
static nsComponentManagerImpl* gComponentManager;
|
2010-06-10 11:11:11 -07:00
|
|
|
nsresult Init();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult Shutdown(void);
|
|
|
|
|
|
|
|
nsresult FreeServices();
|
|
|
|
|
2010-06-10 11:11:11 -07: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);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsFactoryEntry *GetFactoryEntry(const char *aContractID,
|
|
|
|
PRUint32 aContractIDLen);
|
|
|
|
nsFactoryEntry *GetFactoryEntry(const nsCID &aClass);
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
nsDataHashtable<nsIDHashKey, nsFactoryEntry*> mFactories;
|
|
|
|
nsDataHashtable<nsCStringHashKey, nsFactoryEntry*> mContractIDs;
|
|
|
|
|
2011-04-29 12:21:57 -07:00
|
|
|
mozilla::ReentrantMonitor mMon;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
static void InitializeStaticModules();
|
|
|
|
static void InitializeModuleLocations();
|
|
|
|
|
2010-06-11 13:13:26 -07:00
|
|
|
struct ComponentLocation
|
|
|
|
{
|
|
|
|
NSLocationType type;
|
|
|
|
nsCOMPtr<nsILocalFile> location;
|
2010-09-08 20:37:11 -07:00
|
|
|
bool jar;
|
2010-06-11 13:13:26 -07:00
|
|
|
};
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
static nsTArray<const mozilla::Module*>* sStaticModules;
|
2010-06-11 13:13:26 -07:00
|
|
|
static nsTArray<ComponentLocation>* sModuleLocations;
|
2010-09-08 20:37:11 -07:00
|
|
|
static nsTArray<ComponentLocation>* sJarModuleLocations;
|
2010-06-10 11:11:11 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsNativeModuleLoader mNativeModuleLoader;
|
|
|
|
|
2010-06-10 11:11:11 -07: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-11 13:13:26 -07:00
|
|
|
KnownModule(nsILocalFile* aFile)
|
2010-06-10 11:11:11 -07:00
|
|
|
: mModule(NULL)
|
|
|
|
, mFile(aFile)
|
2010-06-11 13:13:26 -07:00
|
|
|
, mLoader(NULL)
|
2010-06-10 11:11:11 -07:00
|
|
|
, mLoaded(false)
|
|
|
|
, mFailed(false)
|
|
|
|
{ }
|
|
|
|
|
2010-09-08 20:37:11 -07:00
|
|
|
KnownModule(nsILocalFile* aFile, const nsACString& aPath)
|
2010-07-02 06:53:19 -07:00
|
|
|
: mModule(NULL)
|
2010-09-08 20:37:11 -07:00
|
|
|
, mFile(aFile)
|
2010-07-02 06:53:19 -07:00
|
|
|
, mPath(aPath)
|
|
|
|
, mLoader(NULL)
|
|
|
|
, mLoaded(false)
|
|
|
|
, mFailed(false)
|
|
|
|
{ }
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
~KnownModule()
|
|
|
|
{
|
2010-06-21 09:46:26 -07:00
|
|
|
if (mLoaded && mModule->unloadProc)
|
|
|
|
mModule->unloadProc();
|
2010-06-10 11:11:11 -07:00
|
|
|
}
|
|
|
|
|
2010-06-11 13:13:26 -07:00
|
|
|
bool EnsureLoader();
|
2010-06-10 11:11:11 -07:00
|
|
|
bool Load();
|
|
|
|
|
|
|
|
const mozilla::Module* Module() const
|
|
|
|
{
|
|
|
|
return mModule;
|
|
|
|
}
|
|
|
|
|
2010-06-28 10:55:57 -07:00
|
|
|
/**
|
|
|
|
* For error logging, get a description of this module, either the
|
|
|
|
* file path, or <static module>.
|
|
|
|
*/
|
|
|
|
nsCString Description() const;
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
private:
|
|
|
|
const mozilla::Module* mModule;
|
|
|
|
nsCOMPtr<nsILocalFile> mFile;
|
2010-07-02 06:53:19 -07:00
|
|
|
nsCString mPath;
|
2010-06-10 11:11:11 -07:00
|
|
|
nsCOMPtr<mozilla::ModuleLoader> mLoader;
|
|
|
|
bool mLoaded;
|
|
|
|
bool mFailed;
|
|
|
|
};
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-07-02 06:53:19 -07:00
|
|
|
// The KnownModule is kept alive by these members, it is
|
|
|
|
// referenced by pointer from the factory entries.
|
2010-06-11 13:13:26 -07:00
|
|
|
nsTArray< nsAutoPtr<KnownModule> > mKnownStaticModules;
|
|
|
|
nsClassHashtable<nsHashableHashKey, KnownModule> mKnownFileModules;
|
2010-09-08 20:37:11 -07:00
|
|
|
// The key is a string in this format "<jar path>|<path within jar>"
|
2010-07-02 06:53:19 -07:00
|
|
|
nsClassHashtable<nsCStringHashKey, KnownModule> mKnownJARModules;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07: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);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-09-08 20:37:11 -07:00
|
|
|
void RegisterJarManifest(nsIZipReader* aReader,
|
|
|
|
const char* aPath, bool aChromeOnly);
|
2010-07-02 06:53:19 -07:00
|
|
|
|
2010-06-22 13:24:01 -07:00
|
|
|
void RegisterManifestFile(NSLocationType aType, nsILocalFile* aFile,
|
|
|
|
bool aChromeOnly);
|
2010-06-11 13:13:26 -07:00
|
|
|
|
|
|
|
struct ManifestProcessingContext
|
|
|
|
{
|
2010-07-22 07:31:29 -07:00
|
|
|
ManifestProcessingContext(NSLocationType aType, nsILocalFile* aFile, bool aChromeOnly)
|
2010-06-11 13:13:26 -07:00
|
|
|
: mType(aType)
|
|
|
|
, mFile(aFile)
|
2010-07-02 06:53:19 -07:00
|
|
|
, mPath(NULL)
|
2010-07-22 07:31:29 -07:00
|
|
|
, mChromeOnly(aChromeOnly)
|
2010-07-02 06:53:19 -07:00
|
|
|
{ }
|
|
|
|
|
2010-09-08 20:37:11 -07:00
|
|
|
ManifestProcessingContext(NSLocationType aType, nsIZipReader* aReader, const char* aPath, bool aChromeOnly)
|
2010-07-02 06:53:19 -07:00
|
|
|
: mType(aType)
|
2010-09-08 20:37:11 -07:00
|
|
|
, mReader(aReader)
|
2010-07-02 06:53:19 -07:00
|
|
|
, mPath(aPath)
|
2010-07-22 07:31:29 -07:00
|
|
|
, mChromeOnly(aChromeOnly)
|
2010-09-08 20:37:11 -07:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIFile> file;
|
|
|
|
aReader->GetFile(getter_AddRefs(file));
|
|
|
|
nsCOMPtr<nsILocalFile> localfile = do_QueryInterface(file);
|
|
|
|
mFile = localfile;
|
|
|
|
}
|
2010-07-02 06:53:19 -07:00
|
|
|
|
2010-06-11 13:13:26 -07:00
|
|
|
~ManifestProcessingContext() { }
|
|
|
|
|
|
|
|
NSLocationType mType;
|
2010-07-02 06:53:19 -07:00
|
|
|
nsILocalFile* mFile;
|
2010-09-08 20:37:11 -07:00
|
|
|
nsIZipReader* mReader;
|
2010-07-02 06:53:19 -07:00
|
|
|
const char* mPath;
|
2010-07-22 07:31:29 -07:00
|
|
|
bool mChromeOnly;
|
2010-06-11 13:13:26 -07:00
|
|
|
};
|
|
|
|
|
2010-07-22 07:31:29 -07:00
|
|
|
void ManifestManifest(ManifestProcessingContext& cx, int lineno, char *const * argv);
|
2010-06-11 13:13:26 -07:00
|
|
|
void ManifestBinaryComponent(ManifestProcessingContext& cx, int lineno, char *const * argv);
|
2010-06-25 10:55:46 -07:00
|
|
|
void ManifestXPT(ManifestProcessingContext& cx, int lineno, char *const * argv);
|
2010-06-11 13:13:26 -07: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);
|
|
|
|
|
|
|
|
void RereadChromeManifests();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
// Shutdown
|
|
|
|
enum {
|
|
|
|
NOT_INITIALIZED,
|
|
|
|
NORMAL,
|
|
|
|
SHUTDOWN_IN_PROGRESS,
|
|
|
|
SHUTDOWN_COMPLETE
|
|
|
|
} mStatus;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
nsTArray<nsLoaderdata> mLoaderData;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
PLArenaPool mArena;
|
|
|
|
|
2008-09-04 15:44:41 -07:00
|
|
|
struct PendingServiceInfo {
|
|
|
|
const nsCID* cid;
|
|
|
|
PRThread* thread;
|
|
|
|
};
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-09-04 15:44:41 -07: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;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
private:
|
|
|
|
~nsComponentManagerImpl();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
nsFactoryEntry(const mozilla::Module::CIDEntry* entry,
|
|
|
|
nsComponentManagerImpl::KnownModule* module);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
// nsIComponentRegistrar.registerFactory support
|
2010-06-25 07:44:35 -07:00
|
|
|
nsFactoryEntry(const nsCID& aClass, nsIFactory* factory);
|
|
|
|
|
|
|
|
~nsFactoryEntry();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
already_AddRefed<nsIFactory> GetFactory();
|
|
|
|
|
|
|
|
const mozilla::Module::CIDEntry* mCIDEntry;
|
|
|
|
nsComponentManagerImpl::KnownModule* mModule;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
nsCOMPtr<nsIFactory> mFactory;
|
|
|
|
nsCOMPtr<nsISupports> mServiceObject;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsComponentManager_h__
|