1999-03-10 12:53:25 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
1999-03-09 12:44:27 +03:00
|
|
|
/*
|
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
|
|
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
|
|
|
* http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* NPL.
|
|
|
|
*
|
|
|
|
* The Initial Developer of this code under the NPL is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
|
|
|
* Reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef nsComponentManager_h__
|
|
|
|
#define nsComponentManager_h__
|
|
|
|
|
1999-09-01 01:40:21 +04:00
|
|
|
#include "nsIComponentLoader.h"
|
|
|
|
#include "nsNativeComponentLoader.h"
|
1999-03-09 12:44:27 +03:00
|
|
|
#include "nsIComponentManager.h"
|
1999-09-01 01:40:21 +04:00
|
|
|
#include "nsIFactory.h"
|
1999-03-31 11:04:12 +04:00
|
|
|
#include "nsIRegistry.h"
|
1999-03-09 12:44:27 +03:00
|
|
|
#include "nsHashtable.h"
|
|
|
|
#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"
|
1999-03-09 12:44:27 +03:00
|
|
|
|
|
|
|
class nsFactoryEntry;
|
|
|
|
class nsDll;
|
1999-07-31 09:55:26 +04:00
|
|
|
class nsIServiceManager;
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-06-14 06:07:03 +04:00
|
|
|
// Registry Factory creation function defined in nsRegistry.cpp
|
|
|
|
// We hook into this function locally to create and register the registry
|
|
|
|
// Since noone outside xpcom needs to know about this and nsRegistry.cpp
|
|
|
|
// does not have a local include file, we are putting this definition
|
|
|
|
// here rather than in nsIRegistry.h
|
|
|
|
extern "C" NS_EXPORT nsresult NS_RegistryGetFactory(nsIFactory** aFactory);
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-09-01 01:40:21 +04:00
|
|
|
extern const char xpcomBaseName[];
|
|
|
|
extern const char xpcomKeyName[];
|
|
|
|
extern const char lastModValueName[];
|
|
|
|
extern const char fileSizeValueName[];
|
|
|
|
|
1999-03-09 12:44:27 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class nsComponentManagerImpl : public nsIComponentManager {
|
|
|
|
public:
|
1999-03-10 12:53:25 +03:00
|
|
|
NS_DECL_ISUPPORTS
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
// nsIComponentManager methods:
|
|
|
|
NS_IMETHOD FindFactory(const nsCID &aClass,
|
|
|
|
nsIFactory **aFactory);
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-08-19 18:54:12 +04:00
|
|
|
// nsIComponentManager methods:
|
|
|
|
NS_IMETHOD GetClassObject(const nsCID &aClass, const nsIID &aIID,
|
|
|
|
void **aResult);
|
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
// Finds a class ID for a specific Program ID
|
|
|
|
NS_IMETHOD ProgIDToCLSID(const char *aProgID,
|
|
|
|
nsCID *aClass);
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
// Finds a Program ID for a specific class ID
|
|
|
|
// caller frees the result with delete[]
|
|
|
|
NS_IMETHOD CLSIDToProgID(nsCID *aClass,
|
|
|
|
char* *aClassName,
|
|
|
|
char* *aProgID);
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
// Creates a class instance for a specific class ID
|
|
|
|
NS_IMETHOD CreateInstance(const nsCID &aClass,
|
|
|
|
nsISupports *aDelegate,
|
|
|
|
const nsIID &aIID,
|
|
|
|
void **aResult);
|
|
|
|
|
|
|
|
// Convenience routine, creates a class instance for a specific ProgID
|
|
|
|
NS_IMETHOD CreateInstance(const char *aProgID,
|
|
|
|
nsISupports *aDelegate,
|
|
|
|
const nsIID &aIID,
|
|
|
|
void **aResult);
|
|
|
|
|
|
|
|
// Manually registry a factory for a class
|
|
|
|
NS_IMETHOD RegisterFactory(const nsCID &aClass,
|
1999-03-09 12:44:27 +03:00
|
|
|
const char *aClassName,
|
|
|
|
const char *aProgID,
|
1999-03-10 12:53:25 +03:00
|
|
|
nsIFactory *aFactory,
|
|
|
|
PRBool aReplace);
|
|
|
|
|
1999-09-02 11:00:29 +04:00
|
|
|
// Register the component loader for a given type.
|
|
|
|
NS_IMETHOD RegisterComponentLoader(const char *aType,
|
|
|
|
const char *aProgID,
|
|
|
|
PRBool aReplace);
|
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
// Manually register a dynamically loaded component.
|
1999-06-22 18:02:58 +04:00
|
|
|
// The libraryPersistentDescriptor is what gets passed to the library
|
|
|
|
// self register function from ComponentManager. The format of this string
|
|
|
|
// is the same as nsIFileSpec::GetPersistentDescriptorString()
|
|
|
|
//
|
|
|
|
// This function will go away in favour of RegisterComponentSpec. In fact,
|
|
|
|
// it internally turns around and calls RegisterComponentSpec.
|
1999-03-10 12:53:25 +03:00
|
|
|
NS_IMETHOD RegisterComponent(const nsCID &aClass,
|
|
|
|
const char *aClassName,
|
|
|
|
const char *aProgID,
|
1999-06-22 18:02:58 +04:00
|
|
|
const char *aLibraryPersistentDescriptor,
|
1999-03-10 12:53:25 +03:00
|
|
|
PRBool aReplace,
|
|
|
|
PRBool aPersist);
|
|
|
|
|
1999-06-22 18:02:58 +04:00
|
|
|
// Register a component using its FileSpec as its identification
|
|
|
|
// This is the more prevalent use.
|
|
|
|
NS_IMETHOD RegisterComponentSpec(const nsCID &aClass,
|
|
|
|
const char *aClassName,
|
|
|
|
const char *aProgID,
|
|
|
|
nsIFileSpec *aLibrary,
|
|
|
|
PRBool aReplace,
|
|
|
|
PRBool aPersist);
|
|
|
|
|
|
|
|
// Register a component using its dllName. This could be a dll name with
|
|
|
|
// no path so that LD_LIBRARY_PATH on unix or PATH on win can load it. Or
|
|
|
|
// this could be a code fragment name on the Mac.
|
|
|
|
NS_IMETHOD RegisterComponentLib(const nsCID &aClass,
|
|
|
|
const char *aClassName,
|
|
|
|
const char *aProgID,
|
|
|
|
const char *adllName,
|
|
|
|
PRBool aReplace,
|
|
|
|
PRBool aPersist);
|
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
// Manually unregister a factory for a class
|
|
|
|
NS_IMETHOD UnregisterFactory(const nsCID &aClass,
|
|
|
|
nsIFactory *aFactory);
|
|
|
|
|
|
|
|
// Manually unregister a dynamically loaded component
|
|
|
|
NS_IMETHOD UnregisterComponent(const nsCID &aClass,
|
|
|
|
const char *aLibrary);
|
|
|
|
|
1999-08-13 23:30:13 +04:00
|
|
|
// Manually unregister a dynamically loaded component
|
|
|
|
NS_IMETHOD UnregisterComponentSpec(const nsCID &aClass,
|
|
|
|
nsIFileSpec *aLibrary);
|
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
// Unload dynamically loaded factories that are not in use
|
|
|
|
NS_IMETHOD FreeLibraries(void);
|
|
|
|
|
1999-08-09 09:02:25 +04:00
|
|
|
// Is the given CID currently registered?
|
|
|
|
NS_IMETHOD IsRegistered(const nsCID &aClass,
|
|
|
|
PRBool *aRegistered);
|
|
|
|
|
|
|
|
// Get an enumeration of all the CIDs
|
|
|
|
NS_IMETHOD EnumerateCLSIDs(nsIEnumerator** aEmumerator);
|
|
|
|
|
|
|
|
// Get an enumeration of all the ProgIDs
|
|
|
|
NS_IMETHOD EnumerateProgIDs(nsIEnumerator** aEmumerator);
|
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// DLL registration support
|
1999-04-03 00:28:22 +04:00
|
|
|
// Autoregistration will try only files with these extensions.
|
|
|
|
// All extensions are case insensitive.
|
|
|
|
// ".dll", // Windows
|
|
|
|
// ".dso", // Unix
|
|
|
|
// ".so", // Unix
|
|
|
|
// ".sl", // Unix: HP
|
1999-05-06 17:29:37 +04:00
|
|
|
// ".shlb", // Mac
|
1999-04-03 00:28:22 +04:00
|
|
|
// ".dlm", // new for all platforms
|
|
|
|
//
|
|
|
|
//
|
1999-06-22 18:02:58 +04:00
|
|
|
NS_IMETHOD AutoRegister(RegistrationTime when, nsIFileSpec *directory);
|
|
|
|
NS_IMETHOD AutoRegisterComponent(RegistrationTime when, nsIFileSpec *component);
|
1999-03-10 12:53:25 +03:00
|
|
|
|
|
|
|
// nsComponentManagerImpl methods:
|
|
|
|
nsComponentManagerImpl();
|
|
|
|
virtual ~nsComponentManagerImpl();
|
|
|
|
|
|
|
|
static nsComponentManagerImpl* gComponentManager;
|
|
|
|
nsresult Init(void);
|
1999-07-02 07:35:09 +04:00
|
|
|
nsresult PlatformPrePopulateRegistry();
|
1999-03-09 12:44:27 +03:00
|
|
|
|
|
|
|
protected:
|
1999-09-01 01:40:21 +04:00
|
|
|
nsresult RegisterComponentCommon(const nsCID &aClass,
|
|
|
|
const char *aClassName,
|
|
|
|
const char *aProgID, char *aRegistryName,
|
|
|
|
PRBool aReplace, PRBool aPersist,
|
|
|
|
const char *aType);
|
|
|
|
nsresult AddComponentToRegistry(const nsCID &aCID, const char *aClassName,
|
|
|
|
const char *aProgID,
|
|
|
|
const char *aRegistryName,
|
|
|
|
const char *aType);
|
|
|
|
nsresult GetLoaderForType(const char *aType,
|
|
|
|
nsIComponentLoader **aLoader);
|
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
nsresult LoadFactory(nsFactoryEntry *aEntry, nsIFactory **aFactory);
|
1999-07-07 11:47:14 +04:00
|
|
|
nsFactoryEntry *GetFactoryEntry(const nsCID &aClass, PRBool checkRegistry);
|
1999-04-03 00:28:22 +04:00
|
|
|
|
1999-06-22 18:02:58 +04:00
|
|
|
nsresult SyncComponentsInDir(RegistrationTime when, nsIFileSpec *dirSpec);
|
1999-03-10 12:53:25 +03:00
|
|
|
nsresult SelfRegisterDll(nsDll *dll);
|
|
|
|
nsresult SelfUnregisterDll(nsDll *dll);
|
1999-04-12 16:32:24 +04:00
|
|
|
nsresult HashProgID(const char *aprogID, const nsCID &aClass);
|
1999-07-31 09:55:26 +04:00
|
|
|
nsresult UnloadLibraries(nsIServiceManager *servmgr);
|
1999-03-10 12:53:25 +03:00
|
|
|
|
1999-06-14 06:07:03 +04:00
|
|
|
// The following functions are the only ones that operate on the persistent
|
|
|
|
// registry
|
|
|
|
nsresult PlatformInit(void);
|
1999-03-10 12:53:25 +03:00
|
|
|
nsresult PlatformVersionCheck();
|
1999-06-14 06:07:03 +04:00
|
|
|
nsresult PlatformRegister(const char *cidString, const char *className, const char *progID, nsDll *dll);
|
|
|
|
nsresult PlatformUnregister(const char *cidString, const char *aLibrary);
|
1999-09-01 01:40:21 +04:00
|
|
|
nsresult PlatformFind(const nsCID &aCID, nsFactoryEntry* *result);
|
1999-03-10 12:53:25 +03:00
|
|
|
nsresult PlatformProgIDToCLSID(const char *aProgID, nsCID *aClass);
|
|
|
|
nsresult PlatformCLSIDToProgID(nsCID *aClass, char* *aClassName, char* *aProgID);
|
1999-03-09 12:44:27 +03:00
|
|
|
|
|
|
|
protected:
|
1999-07-28 12:01:03 +04:00
|
|
|
nsObjectHashtable* mFactories;
|
|
|
|
nsObjectHashtable* mProgIDs;
|
1999-09-01 01:40:21 +04:00
|
|
|
nsSupportsHashtable* mLoaders;
|
1999-07-28 12:01:03 +04:00
|
|
|
PRMonitor* mMon;
|
|
|
|
nsIRegistry* mRegistry;
|
|
|
|
nsIRegistry::Key mXPCOMKey;
|
|
|
|
nsIRegistry::Key mClassesKey;
|
|
|
|
nsIRegistry::Key mCLSIDKey;
|
1999-08-09 09:02:25 +04:00
|
|
|
PRBool mPrePopulationDone;
|
1999-09-02 11:00:29 +04:00
|
|
|
nsIRegistry::Key mLoadersKey;
|
1999-09-01 01:40:21 +04:00
|
|
|
nsNativeComponentLoader *mNativeComponentLoader;
|
1999-03-09 12:44:27 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#define NS_MAX_FILENAME_LEN 1024
|
|
|
|
|
|
|
|
#define NS_ERROR_IS_DIR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_XPCOM, 24)
|
|
|
|
|
1999-03-11 10:44:23 +03:00
|
|
|
#ifdef XP_UNIX
|
|
|
|
/* The default registry on the unix system is $HOME/.mozilla/registry per
|
|
|
|
* vr_findGlobalRegName(). vr_findRegFile() will create the registry file
|
|
|
|
* if it doesn't exist. But it wont create directories.
|
|
|
|
*
|
|
|
|
* Hence we need to create the directory if it doesn't exist already.
|
|
|
|
*
|
|
|
|
* Why create it here as opposed to the app ?
|
|
|
|
* ------------------------------------------
|
|
|
|
* The app cannot create the directory in main() as most of the registry
|
|
|
|
* and initialization happens due to use of static variables.
|
|
|
|
* And we dont want to be dependent on the order in which
|
|
|
|
* these static stuff happen.
|
|
|
|
*
|
|
|
|
* Permission for the $HOME/.mozilla will be Read,Write,Execute
|
|
|
|
* for user only. Nothing to group and others.
|
|
|
|
*/
|
|
|
|
#define NS_MOZILLA_DIR_NAME ".mozilla"
|
|
|
|
#define NS_MOZILLA_DIR_PERMISSION 00700
|
|
|
|
#endif /* XP_UNIX */
|
|
|
|
|
1999-06-29 14:27:58 +04:00
|
|
|
#ifdef XP_BEOS
|
|
|
|
#define NS_MOZILLA_DIR_NAME "mozilla"
|
|
|
|
#define NS_MOZILLA_DIR_PERMISSION 00700
|
|
|
|
#endif /* XP_BEOS */
|
|
|
|
|
1999-03-09 12:44:27 +03:00
|
|
|
/**
|
|
|
|
* When using the registry we put a version number in it.
|
|
|
|
* If the version number that is in the registry doesn't match
|
|
|
|
* the following, we ignore the registry. This lets news versions
|
|
|
|
* of the software deal with old formats of registry and not
|
|
|
|
*
|
|
|
|
* alpha0.20 : First time we did versioning
|
|
|
|
* alpha0.30 : Changing autoreg to begin registration from ./components on unix
|
1999-03-10 01:18:32 +03:00
|
|
|
* alpha0.40 : repository -> component manager
|
1999-03-31 11:04:12 +04:00
|
|
|
* alpha0.50 : using nsIRegistry
|
1999-05-26 05:38:36 +04:00
|
|
|
* alpha0.60 : xpcom 2.0 landing
|
1999-06-22 18:02:58 +04:00
|
|
|
* alpha0.70 : using nsIFileSpec. PRTime -> PRUint32
|
1999-09-01 01:40:21 +04:00
|
|
|
* alpha0.90 : using nsIComponentLoader, abs:/rel:/lib:, shaver-cleanup
|
1999-03-09 12:44:27 +03:00
|
|
|
*/
|
1999-09-01 01:40:21 +04:00
|
|
|
#define NS_XPCOM_COMPONENT_MANAGER_VERSION_STRING "alpha0.90"
|
1999-03-09 12:44:27 +03:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
/**
|
|
|
|
* Class: nsFactoryEntry()
|
|
|
|
*
|
|
|
|
* There are two types of FactoryEntries.
|
|
|
|
*
|
|
|
|
* 1. {CID, dll} mapping.
|
|
|
|
* Factory is a consequence of the dll. These can be either session
|
|
|
|
* specific or persistent based on whether we write this
|
|
|
|
* to the registry or not.
|
|
|
|
*
|
|
|
|
* 2. {CID, factory} mapping
|
|
|
|
* These are strictly session specific and in memory only.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class nsFactoryEntry {
|
|
|
|
public:
|
1999-09-01 01:40:21 +04:00
|
|
|
nsFactoryEntry(const nsCID &aClass, char *location, char *aType,
|
|
|
|
nsIComponentLoader *aLoader);
|
1999-03-10 12:53:25 +03:00
|
|
|
nsFactoryEntry(const nsCID &aClass, nsIFactory *aFactory);
|
|
|
|
~nsFactoryEntry();
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-09-01 01:40:21 +04:00
|
|
|
nsresult GetFactory(nsIFactory **aFactory) {
|
|
|
|
if (factory) {
|
|
|
|
*aFactory = factory.get();
|
|
|
|
NS_ADDREF(*aFactory);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
nsresult rv = loader->GetFactory(cid, location, type, aFactory);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
1999-09-02 11:00:29 +04:00
|
|
|
factory = do_QueryInterface(*aFactory);
|
1999-09-01 01:40:21 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0 /* unused? */
|
1999-03-12 14:25:17 +03:00
|
|
|
nsresult Init(nsHashtable* dllHashtable, const nsCID &aClass, const char *aLibrary,
|
1999-03-10 12:53:25 +03:00
|
|
|
PRTime lastModTime, PRUint32 fileSize);
|
1999-09-01 01:40:21 +04:00
|
|
|
#endif
|
1999-03-09 12:44:27 +03:00
|
|
|
|
1999-03-10 12:53:25 +03:00
|
|
|
nsCID cid;
|
1999-09-01 01:40:21 +04:00
|
|
|
char *location;
|
|
|
|
nsCOMPtr<nsIFactory> factory;
|
|
|
|
char *type;
|
|
|
|
nsCOMPtr<nsIComponentLoader> loader;
|
1999-03-09 12:44:27 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#endif // nsComponentManager_h__
|