convert to CreateInstanceFromProgID
git-svn-id: svn://10.0.0.236/trunk@46048 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -411,9 +411,10 @@ nsFileChannel::AsyncRead(PRUint32 startPosition, PRInt32 readCount,
|
||||
rv = NS_GetGlobalComponentManager(&comMgr);
|
||||
|
||||
if (!mStreamConverter)
|
||||
rv = comMgr->CreateInstance(NS_ISTREAMCONVERTER_KEY "?from=message/rfc822?to=text/xul",
|
||||
NULL, NS_GET_IID(nsIStreamConverter),
|
||||
(void **) getter_AddRefs(mStreamConverter));
|
||||
rv = comMgr->CreateInstanceByProgID(NS_ISTREAMCONVERTER_KEY
|
||||
"?from=message/rfc822?to=text/xul",
|
||||
NULL, NS_GET_IID(nsIStreamConverter),
|
||||
(void **) getter_AddRefs(mStreamConverter));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// (1) and (2)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
nsIComponentManager.h
|
||||
nsIGenericFactory.h
|
||||
nsIRegistry.h
|
||||
nsIServiceManager.h
|
||||
nsIServiceProvider.h
|
||||
nsRepository.h
|
||||
nsXPComFactory.h
|
||||
nsComponentManagerUtils.h
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
nsIFactory.idl
|
||||
nsIComponentLoader.idl
|
||||
nsIComponentManager.idl
|
||||
|
||||
@@ -36,13 +36,14 @@ CPPSRCS = \
|
||||
$(NULL)
|
||||
|
||||
XPIDLSRCS = \
|
||||
nsIFactory.idl \
|
||||
nsIComponentLoader.idl \
|
||||
nsIComponentManager.idl \
|
||||
nsIFactory.idl \
|
||||
nsIModule.idl \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = \
|
||||
nsIComponentManager.h \
|
||||
nsComponentManagerUtils.h \
|
||||
nsIGenericFactory.h \
|
||||
nsIRegistry.h \
|
||||
nsIServiceManager.h \
|
||||
|
||||
@@ -698,7 +698,7 @@ nsComponentManagerImpl::PlatformProgIDToCLSID(const char *aProgID, nsCID *aClass
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsComponentManagerImpl::PlatformCLSIDToProgID(nsCID *aClass,
|
||||
nsComponentManagerImpl::PlatformCLSIDToProgID(const nsCID *aClass,
|
||||
char* *aClassName, char* *aProgID)
|
||||
{
|
||||
|
||||
@@ -1144,19 +1144,19 @@ nsComponentManagerImpl::ProgIDToCLSID(const char *aProgID, nsCID *aClass)
|
||||
* XXX Would be nice to hook in a cache here too.
|
||||
*/
|
||||
nsresult
|
||||
nsComponentManagerImpl::CLSIDToProgID(nsCID *aClass,
|
||||
nsComponentManagerImpl::CLSIDToProgID(const nsCID &aClass,
|
||||
char* *aClassName,
|
||||
char* *aProgID)
|
||||
{
|
||||
nsresult res = NS_ERROR_FACTORY_NOT_REGISTERED;
|
||||
|
||||
#ifdef USE_REGISTRY
|
||||
res = PlatformCLSIDToProgID(aClass, aClassName, aProgID);
|
||||
res = PlatformCLSIDToProgID(&aClass, aClassName, aProgID);
|
||||
#endif /* USE_REGISTRY */
|
||||
|
||||
if (PR_LOG_TEST(nsComponentManagerLog, PR_LOG_ALWAYS))
|
||||
{
|
||||
char *buf = aClass->ToString();
|
||||
char *buf = aClass.ToString();
|
||||
PR_LOG(nsComponentManagerLog, PR_LOG_WARNING,
|
||||
("nsComponentManager: CLSIDToProgID(%s)->%s", buf,
|
||||
NS_SUCCEEDED(res) ? *aProgID : "[FAILED]"));
|
||||
@@ -1179,14 +1179,6 @@ nsComponentManagerImpl::CreateInstance(const nsCID &aClass,
|
||||
const nsIID &aIID,
|
||||
void **aResult)
|
||||
{
|
||||
#ifdef DEBUG_shaver
|
||||
if (PR_LOG_TEST(nsComponentManagerLog, PR_LOG_ALWAYS))
|
||||
{
|
||||
char *buf = aClass.ToString();
|
||||
fprintf(stderr, "nsComponentManager: CreateInstance(%s)\n", buf);
|
||||
delete [] buf;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (aResult == NULL)
|
||||
{
|
||||
@@ -1223,10 +1215,10 @@ nsComponentManagerImpl::CreateInstance(const nsCID &aClass,
|
||||
* XXX This is a function overload. We need to remove it.
|
||||
*/
|
||||
nsresult
|
||||
nsComponentManagerImpl::CreateInstance(const char *aProgID,
|
||||
nsISupports *aDelegate,
|
||||
const nsIID &aIID,
|
||||
void **aResult)
|
||||
nsComponentManagerImpl::CreateInstanceByProgID(const char *aProgID,
|
||||
nsISupports *aDelegate,
|
||||
const nsIID &aIID,
|
||||
void **aResult)
|
||||
{
|
||||
nsCID clsid;
|
||||
nsresult rv = ProgIDToCLSID(aProgID, &clsid);
|
||||
@@ -1518,7 +1510,7 @@ nsComponentManagerImpl::GetLoaderForType(const char *aType,
|
||||
fprintf(stderr, "nCMI: constructing loader for type %s = %s\n", aType, progID);
|
||||
#endif
|
||||
|
||||
rv = CreateInstance(progID, nsnull, NS_GET_IID(nsIComponentLoader), (void **)&loader);
|
||||
rv = CreateInstanceByProgID(progID, nsnull, NS_GET_IID(nsIComponentLoader), (void **)&loader);
|
||||
PR_FREEIF(progID);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
@@ -1665,8 +1657,9 @@ nsComponentManagerImpl::UnregisterComponent(const nsCID &aClass,
|
||||
|
||||
// Convert the persistent descriptor into a nsIFileSpec
|
||||
nsCOMPtr<nsIFileSpec>libSpec;
|
||||
NS_DEFINE_IID(kFileSpecIID, NS_IFILESPEC_IID);
|
||||
rv = CreateInstance(NS_FILESPEC_PROGID, NULL, kFileSpecIID, getter_AddRefs(libSpec));
|
||||
rv = CreateInstanceByProgID(NS_FILESPEC_PROGID, NULL,
|
||||
NS_GET_IID(nsIFileSpec),
|
||||
getter_AddRefs(libSpec));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = libSpec->SetPersistentDescriptorString((char *)aLibrary);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
@@ -1802,7 +1795,7 @@ AutoRegister_enumerate(nsHashKey *key, void *aData, void *aClosure)
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsComponentManagerImpl::AutoRegister(RegistrationTime when, nsIFileSpec *inDirSpec)
|
||||
nsComponentManagerImpl::AutoRegister(PRInt32 when, nsIFileSpec *inDirSpec)
|
||||
{
|
||||
nsCOMPtr<nsIFileSpec> dir;
|
||||
nsresult rv;
|
||||
@@ -1898,7 +1891,7 @@ AutoRegisterComponent_enumerate(nsHashKey *key, void *aData, void *aClosure)
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsComponentManagerImpl::AutoRegisterComponent(RegistrationTime when,
|
||||
nsComponentManagerImpl::AutoRegisterComponent(PRInt32 when,
|
||||
nsIFileSpec *component)
|
||||
{
|
||||
struct AutoReg_closure closure;
|
||||
@@ -1940,9 +1933,11 @@ ConvertFactoryEntryToCID(nsHashKey *key, void *data, void *convert_data,
|
||||
|
||||
nsISupportsID* cidHolder;
|
||||
|
||||
if(NS_SUCCEEDED(rv = compMgr->CreateInstance(NS_SUPPORTS_ID_PROGID, nsnull,
|
||||
NS_GET_IID(nsISupportsID),
|
||||
(void **)&cidHolder)))
|
||||
if(NS_SUCCEEDED(rv =
|
||||
compMgr->CreateInstanceByProgID(NS_SUPPORTS_ID_PROGID,
|
||||
nsnull,
|
||||
NS_GET_IID(nsISupportsID),
|
||||
(void **)&cidHolder)))
|
||||
{
|
||||
nsFactoryEntry *fe = (nsFactoryEntry *) data;
|
||||
cidHolder->SetData(&fe->cid);
|
||||
@@ -1963,9 +1958,11 @@ ConvertProgIDKeyToString(nsHashKey *key, void *data, void *convert_data,
|
||||
|
||||
nsISupportsString* strHolder;
|
||||
|
||||
if(NS_SUCCEEDED(rv = compMgr->CreateInstance(NS_SUPPORTS_STRING_PROGID, nsnull,
|
||||
NS_GET_IID(nsISupportsString),
|
||||
(void **)&strHolder)))
|
||||
|
||||
rv = compMgr->CreateInstanceByProgID(NS_SUPPORTS_STRING_PROGID, nsnull,
|
||||
NS_GET_IID(nsISupportsString),
|
||||
(void **)&strHolder);
|
||||
if(NS_SUCCEEDED(rv))
|
||||
{
|
||||
nsStringKey *strKey = (nsStringKey *) key;
|
||||
const nsString& str = strKey->GetString();
|
||||
|
||||
@@ -50,121 +50,7 @@ extern const char fileSizeValueName[];
|
||||
class nsComponentManagerImpl : public nsIComponentManager {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIComponentManager methods:
|
||||
NS_IMETHOD FindFactory(const nsCID &aClass,
|
||||
nsIFactory **aFactory);
|
||||
|
||||
// nsIComponentManager methods:
|
||||
NS_IMETHOD GetClassObject(const nsCID &aClass, const nsIID &aIID,
|
||||
void **aResult);
|
||||
|
||||
// Finds a class ID for a specific Program ID
|
||||
NS_IMETHOD ProgIDToCLSID(const char *aProgID,
|
||||
nsCID *aClass);
|
||||
|
||||
// Finds a Program ID for a specific class ID
|
||||
// caller frees the result with delete[]
|
||||
NS_IMETHOD CLSIDToProgID(nsCID *aClass,
|
||||
char* *aClassName,
|
||||
char* *aProgID);
|
||||
|
||||
// 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,
|
||||
const char *aClassName,
|
||||
const char *aProgID,
|
||||
nsIFactory *aFactory,
|
||||
PRBool aReplace);
|
||||
|
||||
// Register the component loader for a given type.
|
||||
NS_IMETHOD RegisterComponentLoader(const char *aType,
|
||||
const char *aProgID,
|
||||
PRBool aReplace);
|
||||
|
||||
// Manually register a dynamically loaded component.
|
||||
// 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.
|
||||
NS_IMETHOD RegisterComponent(const nsCID &aClass,
|
||||
const char *aClassName,
|
||||
const char *aProgID,
|
||||
const char *aLibraryPersistentDescriptor,
|
||||
PRBool aReplace,
|
||||
PRBool aPersist);
|
||||
|
||||
// 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);
|
||||
|
||||
// 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);
|
||||
|
||||
// Manually unregister a dynamically loaded component
|
||||
NS_IMETHOD UnregisterComponentSpec(const nsCID &aClass,
|
||||
nsIFileSpec *aLibrary);
|
||||
|
||||
// Unload dynamically loaded factories that are not in use
|
||||
NS_IMETHOD FreeLibraries(void);
|
||||
|
||||
// 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);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// DLL registration support
|
||||
// Autoregistration will try only files with these extensions.
|
||||
// All extensions are case insensitive.
|
||||
// ".dll", // Windows
|
||||
// ".dso", // Unix
|
||||
// ".so", // Unix
|
||||
// ".sl", // Unix: HP
|
||||
// ".shlb", // Mac
|
||||
// ".dlm", // new for all platforms
|
||||
//
|
||||
//
|
||||
NS_IMETHOD AutoRegister(RegistrationTime when, nsIFileSpec *directory);
|
||||
NS_IMETHOD AutoRegisterComponent(RegistrationTime when, nsIFileSpec *component);
|
||||
NS_DECL_NSICOMPONENTMANAGER
|
||||
|
||||
// nsComponentManagerImpl methods:
|
||||
nsComponentManagerImpl();
|
||||
@@ -190,7 +76,7 @@ protected:
|
||||
nsresult LoadFactory(nsFactoryEntry *aEntry, nsIFactory **aFactory);
|
||||
nsFactoryEntry *GetFactoryEntry(const nsCID &aClass, PRBool checkRegistry);
|
||||
|
||||
nsresult SyncComponentsInDir(RegistrationTime when, nsIFileSpec *dirSpec);
|
||||
nsresult SyncComponentsInDir(PRInt32 when, nsIFileSpec *dirSpec);
|
||||
nsresult SelfRegisterDll(nsDll *dll);
|
||||
nsresult SelfUnregisterDll(nsDll *dll);
|
||||
nsresult HashProgID(const char *aprogID, const nsCID &aClass);
|
||||
@@ -204,7 +90,7 @@ protected:
|
||||
nsresult PlatformUnregister(const char *cidString, const char *aLibrary);
|
||||
nsresult PlatformFind(const nsCID &aCID, nsFactoryEntry* *result);
|
||||
nsresult PlatformProgIDToCLSID(const char *aProgID, nsCID *aClass);
|
||||
nsresult PlatformCLSIDToProgID(nsCID *aClass, char* *aClassName, char* *aProgID);
|
||||
nsresult PlatformCLSIDToProgID(const nsCID *aClass, char* *aClassName, char* *aProgID);
|
||||
|
||||
protected:
|
||||
nsObjectHashtable* mFactories;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* 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
|
||||
* Version 1.1 (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/
|
||||
*
|
||||
@@ -16,20 +16,8 @@
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsIComponentManager_h__
|
||||
#define nsIComponentManager_h__
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "nsCom.h"
|
||||
#include "nsID.h"
|
||||
#include "nsError.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsIFactory.h"
|
||||
|
||||
// XXX Need to substitute these includes with
|
||||
// XXX equivalent forward declarations.
|
||||
#include "nsIFileSpec.h"
|
||||
#include "nsIEnumerator.h"
|
||||
#ifndef nsComponentManagerUtils_h__
|
||||
#define nsComponentManagerUtils_h__
|
||||
|
||||
#ifndef OBSOLETE_MODULE_LOADING
|
||||
/*
|
||||
@@ -58,14 +46,6 @@ typedef nsresult (*nsRegisterProc)(nsISupports* aServMgr, const char *path);
|
||||
typedef nsresult (*nsUnregisterProc)(nsISupports* aServMgr, const char *path);
|
||||
#endif /* OBSOLETE_MODULE_LOADING */
|
||||
|
||||
#define NS_ICOMPONENTMANAGER_IID \
|
||||
{ /* 8458a740-d5dc-11d2-92fb-00e09805570f */ \
|
||||
0x8458a740, \
|
||||
0xd5dc, \
|
||||
0x11d2, \
|
||||
{0x92, 0xfb, 0x00, 0xe0, 0x98, 0x05, 0x57, 0x0f} \
|
||||
}
|
||||
|
||||
#define NS_COMPONENTMANAGER_CID \
|
||||
{ /* 91775d60-d5dc-11d2-92fb-00e09805570f */ \
|
||||
0x91775d60, \
|
||||
@@ -74,148 +54,6 @@ typedef nsresult (*nsUnregisterProc)(nsISupports* aServMgr, const char *path);
|
||||
{0x92, 0xfb, 0x00, 0xe0, 0x98, 0x05, 0x57, 0x0f} \
|
||||
}
|
||||
|
||||
/*
|
||||
* nsIComponentManager interface
|
||||
*/
|
||||
|
||||
class nsIComponentManager : public nsISupports {
|
||||
public:
|
||||
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ICOMPONENTMANAGER_IID)
|
||||
|
||||
// Get the factory for creation of the CID
|
||||
NS_IMETHOD FindFactory(const nsCID &aClass,
|
||||
nsIFactory **aFactory) = 0;
|
||||
|
||||
// Get the singleton class object that implements the CID aClass
|
||||
NS_IMETHOD GetClassObject(const nsCID &aClass, const nsIID &aIID,
|
||||
void **aResult) = 0;
|
||||
|
||||
// Finds a class ID for a specific Program ID
|
||||
NS_IMETHOD ProgIDToCLSID(const char *aProgID,
|
||||
nsCID *aClass) = 0;
|
||||
|
||||
// Finds a Program ID for a specific class ID
|
||||
// caller frees the result with delete[]
|
||||
NS_IMETHOD CLSIDToProgID(nsCID *aClass,
|
||||
char* *aClassName,
|
||||
char* *aProgID) = 0;
|
||||
|
||||
// Creates a class instance for a specific class ID
|
||||
NS_IMETHOD CreateInstance(const nsCID &aClass,
|
||||
nsISupports *aDelegate,
|
||||
const nsIID &aIID,
|
||||
void **aResult) = 0;
|
||||
|
||||
// Convenience routine, creates a class instance for a specific ProgID
|
||||
NS_IMETHOD CreateInstance(const char *aProgID,
|
||||
nsISupports *aDelegate,
|
||||
const nsIID &aIID,
|
||||
void **aResult) = 0;
|
||||
|
||||
// Manually registry a factory for a class
|
||||
NS_IMETHOD RegisterFactory(const nsCID &aClass,
|
||||
const char *aClassName,
|
||||
const char *aProgID,
|
||||
nsIFactory *aFactory,
|
||||
PRBool aReplace) = 0;
|
||||
|
||||
// Register the component loader for a given type.
|
||||
NS_IMETHOD RegisterComponentLoader(const char *aType,
|
||||
const char *aProgID,
|
||||
PRBool aReplace) = 0;
|
||||
|
||||
// Manually register a dynamically loaded component.
|
||||
// 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()
|
||||
//
|
||||
// WARNING: OBSOLETE
|
||||
// This function will go away in favour of RegisterComponentSpec. In fact,
|
||||
// it internally turns around and calls RegisterComponentSpec.
|
||||
NS_IMETHOD RegisterComponent(const nsCID &aClass,
|
||||
const char *aClassName,
|
||||
const char *aProgID,
|
||||
const char *aLibraryPersistentDescriptor,
|
||||
PRBool aReplace,
|
||||
PRBool aPersist) = 0;
|
||||
|
||||
// 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) = 0;
|
||||
|
||||
// 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) = 0;
|
||||
|
||||
// Manually unregister a factory for a class
|
||||
NS_IMETHOD UnregisterFactory(const nsCID &aClass,
|
||||
nsIFactory *aFactory) = 0;
|
||||
|
||||
// Manually unregister a dynamically loaded component
|
||||
//
|
||||
// WARNING: OBSOLETE
|
||||
// This function will go away in favour of UnregisterComponentSpec.
|
||||
NS_IMETHOD UnregisterComponent(const nsCID &aClass,
|
||||
const char *aLibrary) = 0;
|
||||
|
||||
// Manually unregister a dynamically loaded component
|
||||
NS_IMETHOD UnregisterComponentSpec(const nsCID &aClass,
|
||||
nsIFileSpec *aLibrarySpec) = 0;
|
||||
|
||||
// Unload dynamically loaded factories that are not in use
|
||||
NS_IMETHOD FreeLibraries(void) = 0;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// DLL registration support
|
||||
// Autoregistration will try only files with these extensions.
|
||||
// All extensions are case insensitive.
|
||||
// ".dll", // Windows
|
||||
// ".dso", // Unix
|
||||
// ".so", // Unix
|
||||
// ".sl", // Unix: HP
|
||||
// ".shlb", // Mac
|
||||
// ".dlm", // new for all platforms
|
||||
//
|
||||
// Directory and fullname are what NSPR will accept. For eg.
|
||||
// MAC /Hard drive/mozilla/dist/bin
|
||||
// WIN y:\Hard drive\mozilla\dist\bin (or) y:/Hard drive/mozilla/dist/bin
|
||||
// UNIX /Hard drive/mozilla/dist/bin
|
||||
//
|
||||
enum RegistrationTime {
|
||||
NS_Startup = 0,
|
||||
NS_Script = 1,
|
||||
NS_Timer = 2
|
||||
};
|
||||
|
||||
NS_IMETHOD AutoRegister(RegistrationTime when, nsIFileSpec* directory) = 0;
|
||||
NS_IMETHOD AutoRegisterComponent(RegistrationTime when, nsIFileSpec *component) = 0;
|
||||
|
||||
// Is the given CID currently registered?
|
||||
NS_IMETHOD IsRegistered(const nsCID &aClass,
|
||||
PRBool *aRegistered) = 0;
|
||||
|
||||
// Get an enumeration of all the CIDs
|
||||
NS_IMETHOD EnumerateCLSIDs(nsIEnumerator** aEmumerator) = 0;
|
||||
|
||||
// Get an enumeration of all the ProgIDs
|
||||
NS_IMETHOD EnumerateProgIDs(nsIEnumerator** aEmumerator) = 0;
|
||||
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
extern NS_COM nsresult
|
||||
NS_GetGlobalComponentManager(nsIComponentManager* *result);
|
||||
|
||||
@@ -318,10 +156,8 @@ public:
|
||||
// If directory is NULL, then AutoRegister will try registering components
|
||||
// in the default components directory which is got by
|
||||
// nsSpecialSystemDirectory(XPCOM_CurrentProcessComponentDirectory)
|
||||
static nsresult AutoRegister(nsIComponentManager::RegistrationTime when,
|
||||
nsIFileSpec* directory);
|
||||
static nsresult AutoRegisterComponent(nsIComponentManager::RegistrationTime when,
|
||||
nsIFileSpec *component);
|
||||
static nsresult AutoRegister(PRInt32 when, nsIFileSpec* directory);
|
||||
static nsresult AutoRegisterComponent(PRInt32 when, nsIFileSpec *component);
|
||||
|
||||
// Is the given CID currently registered?
|
||||
static nsresult IsRegistered(const nsCID &aClass,
|
||||
@@ -335,6 +171,4 @@ public:
|
||||
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif
|
||||
#endif /* nsComponentManagerUtils_h__ */
|
||||
80
mozilla/xpcom/components/nsIComponentManager.idl
Normal file
80
mozilla/xpcom/components/nsIComponentManager.idl
Normal file
@@ -0,0 +1,80 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (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.
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsIFileSpec.idl"
|
||||
#include "nsIFactory.idl"
|
||||
#include "nsIEnumerator.idl"
|
||||
|
||||
/* should this be in nsroot.idl? */
|
||||
native nsCID(nsCID);
|
||||
|
||||
[scriptable, uuid(8458a740-d5dc-11d2-92fb-00e09805570f)]
|
||||
interface nsIComponentManager : nsISupports
|
||||
{
|
||||
nsIFactory findFactory(in nsCIDRef aClass);
|
||||
[noscript] voidStar getClassObject(in nsCIDRef aClass, in nsIIDRef aIID);
|
||||
|
||||
[noscript] void progIDToCLSID(in string aProgID, out nsCID aClass);
|
||||
string CLSIDToProgID(in nsCIDRef aClass, out string aClassName);
|
||||
|
||||
[noscript] voidStar createInstance(in nsCIDRef aClass,
|
||||
in nsISupports aDelegate,
|
||||
in nsIIDRef aIID);
|
||||
[noscript] voidStar createInstanceByProgID(in string aProgID,
|
||||
in nsISupports aDelegate,
|
||||
in nsIIDRef IID);
|
||||
|
||||
void registerFactory(in nsCIDRef aClass, in string aClassName,
|
||||
in string aProgID, in nsIFactory aFactory,
|
||||
in boolean aReplace);
|
||||
void registerComponentLoader(in string aType, in string aProgID,
|
||||
in boolean aReplace);
|
||||
void registerComponent(in nsCIDRef aClass, in string aClassName,
|
||||
in string aProgID, in string aLocation,
|
||||
in boolean aReplace, in boolean aPersist);
|
||||
void registerComponentSpec(in nsCIDRef aClass, in string aClassName,
|
||||
in string aProgID, in nsIFileSpec aLibrary,
|
||||
in boolean aReplace, in boolean aPersist);
|
||||
void registerComponentLib(in nsCIDRef aClass, in string aClassName,
|
||||
in string aProgID, in string adllName,
|
||||
in boolean aReplace, in boolean aPersist);
|
||||
|
||||
void unregisterFactory(in nsCIDRef aClass, in nsIFactory aFactory);
|
||||
void unregisterComponent(in nsCIDRef aClass, in string aLibrary);
|
||||
void unregisterComponentSpec(in nsCIDRef aClass,
|
||||
in nsIFileSpec aLibrarySpec);
|
||||
|
||||
void freeLibraries();
|
||||
const long NS_Startup = 0;
|
||||
const long NS_Script = 1;
|
||||
const long NS_Timer = 2;
|
||||
|
||||
void autoRegister(in long when, in nsIFileSpec directory);
|
||||
void autoRegisterComponent(in long when, in nsIFileSpec component);
|
||||
|
||||
boolean isRegistered(in nsCIDRef aClass);
|
||||
nsIEnumerator enumerateCLSIDs();
|
||||
nsIEnumerator enumerateProgIDs();
|
||||
};
|
||||
|
||||
%{ C++
|
||||
/* include after the class def'n, because it needs to see it. */
|
||||
#include "nsComponentManagerUtils.h"
|
||||
%} C++
|
||||
|
||||
@@ -864,10 +864,6 @@ nsNativeComponentLoader::RegistryNameForSpec(nsIFileSpec *aSpec,
|
||||
* Who knew?
|
||||
*/
|
||||
const char *nativePath;
|
||||
nsFileSpec spec;
|
||||
rv = aSpec->GetFileSpec(&spec);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
nativePath = spec.GetNativePathCString();
|
||||
nativePath += mComponentsDirLen;
|
||||
#ifdef XP_MAC // XXX move relativize-fragment logic to nsFileSpec?
|
||||
|
||||
@@ -62,7 +62,7 @@ nsComponentManager::CLSIDToProgID(nsCID *aClass,
|
||||
nsIComponentManager* cm;
|
||||
nsresult rv = NS_GetGlobalComponentManager(&cm);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return cm->CLSIDToProgID(aClass, aClassName, aProgID);
|
||||
return cm->CLSIDToProgID(*aClass, aClassName, aProgID);
|
||||
}
|
||||
|
||||
nsresult
|
||||
@@ -86,7 +86,7 @@ nsComponentManager::CreateInstance(const char *aProgID,
|
||||
nsIComponentManager* cm;
|
||||
nsresult rv = NS_GetGlobalComponentManager(&cm);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return cm->CreateInstance(aProgID, aDelegate, aIID, aResult);
|
||||
return cm->CreateInstanceByProgID(aProgID, aDelegate, aIID, aResult);
|
||||
}
|
||||
|
||||
nsresult
|
||||
@@ -188,8 +188,7 @@ nsComponentManager::FreeLibraries(void)
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsComponentManager::AutoRegister(nsIComponentManager::RegistrationTime when,
|
||||
nsIFileSpec *directory)
|
||||
nsComponentManager::AutoRegister(PRInt32 when, nsIFileSpec *directory)
|
||||
{
|
||||
nsIComponentManager* cm;
|
||||
nsresult rv = NS_GetGlobalComponentManager(&cm);
|
||||
@@ -198,7 +197,7 @@ nsComponentManager::AutoRegister(nsIComponentManager::RegistrationTime when,
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsComponentManager::AutoRegisterComponent(nsIComponentManager::RegistrationTime when,
|
||||
nsComponentManager::AutoRegisterComponent(PRInt32 when,
|
||||
nsIFileSpec *fullname)
|
||||
{
|
||||
nsIComponentManager* cm;
|
||||
|
||||
174
mozilla/xpcom/glue/nsComponentManagerUtils.h
Normal file
174
mozilla/xpcom/glue/nsComponentManagerUtils.h
Normal file
@@ -0,0 +1,174 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (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 nsComponentManagerUtils_h__
|
||||
#define nsComponentManagerUtils_h__
|
||||
|
||||
#ifndef OBSOLETE_MODULE_LOADING
|
||||
/*
|
||||
* Prototypes for dynamic library export functions. Your DLL/DSO needs to export
|
||||
* these methods to play in the component world.
|
||||
*
|
||||
* THIS IS OBSOLETE. Look at nsIModule.idl
|
||||
*/
|
||||
|
||||
extern "C" NS_EXPORT nsresult NSGetFactory(nsISupports* aServMgr,
|
||||
const nsCID &aClass,
|
||||
const char *aClassName,
|
||||
const char *aProgID,
|
||||
nsIFactory **aFactory);
|
||||
extern "C" NS_EXPORT PRBool NSCanUnload(nsISupports* aServMgr);
|
||||
extern "C" NS_EXPORT nsresult NSRegisterSelf(nsISupports* aServMgr, const char *fullpath);
|
||||
extern "C" NS_EXPORT nsresult NSUnregisterSelf(nsISupports* aServMgr, const char *fullpath);
|
||||
|
||||
typedef nsresult (*nsFactoryProc)(nsISupports* aServMgr,
|
||||
const nsCID &aClass,
|
||||
const char *aClassName,
|
||||
const char *aProgID,
|
||||
nsIFactory **aFactory);
|
||||
typedef PRBool (*nsCanUnloadProc)(nsISupports* aServMgr);
|
||||
typedef nsresult (*nsRegisterProc)(nsISupports* aServMgr, const char *path);
|
||||
typedef nsresult (*nsUnregisterProc)(nsISupports* aServMgr, const char *path);
|
||||
#endif /* OBSOLETE_MODULE_LOADING */
|
||||
|
||||
#define NS_COMPONENTMANAGER_CID \
|
||||
{ /* 91775d60-d5dc-11d2-92fb-00e09805570f */ \
|
||||
0x91775d60, \
|
||||
0xd5dc, \
|
||||
0x11d2, \
|
||||
{0x92, 0xfb, 0x00, 0xe0, 0x98, 0x05, 0x57, 0x0f} \
|
||||
}
|
||||
|
||||
extern NS_COM nsresult
|
||||
NS_GetGlobalComponentManager(nsIComponentManager* *result);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Global Static Component Manager Methods
|
||||
// (for when you need to link with xpcom)
|
||||
|
||||
class NS_COM nsComponentManager {
|
||||
public:
|
||||
static nsresult Initialize(void);
|
||||
|
||||
// Finds a factory for a specific class ID
|
||||
static nsresult FindFactory(const nsCID &aClass,
|
||||
nsIFactory **aFactory);
|
||||
|
||||
// Get the singleton class object that implements the CID aClass
|
||||
static nsresult GetClassObject(const nsCID &aClass, const nsIID &aIID,
|
||||
void **aResult);
|
||||
|
||||
// Finds a class ID for a specific Program ID
|
||||
static nsresult ProgIDToCLSID(const char *aProgID,
|
||||
nsCID *aClass);
|
||||
|
||||
// Finds a Program ID for a specific class ID
|
||||
// caller frees the result with delete[]
|
||||
static nsresult CLSIDToProgID(nsCID *aClass,
|
||||
char* *aClassName,
|
||||
char* *aProgID);
|
||||
|
||||
// Creates a class instance for a specific class ID
|
||||
static nsresult CreateInstance(const nsCID &aClass,
|
||||
nsISupports *aDelegate,
|
||||
const nsIID &aIID,
|
||||
void **aResult);
|
||||
|
||||
// Convenience routine, creates a class instance for a specific ProgID
|
||||
static nsresult CreateInstance(const char *aProgID,
|
||||
nsISupports *aDelegate,
|
||||
const nsIID &aIID,
|
||||
void **aResult);
|
||||
|
||||
// Manually registry a factory for a class
|
||||
static nsresult RegisterFactory(const nsCID &aClass,
|
||||
const char *aClassName,
|
||||
const char *aProgID,
|
||||
nsIFactory *aFactory,
|
||||
PRBool aReplace);
|
||||
|
||||
// Manually register a dynamically loaded component.
|
||||
// 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.
|
||||
static nsresult RegisterComponent(const nsCID &aClass,
|
||||
const char *aClassName,
|
||||
const char *aProgID,
|
||||
const char *aLibraryPersistentDescriptor,
|
||||
PRBool aReplace,
|
||||
PRBool aPersist);
|
||||
|
||||
// Register a component using its FileSpec as its identification
|
||||
// This is the more prevalent use.
|
||||
static nsresult 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.
|
||||
static nsresult RegisterComponentLib(const nsCID &aClass,
|
||||
const char *aClassName,
|
||||
const char *aProgID,
|
||||
const char *adllName,
|
||||
PRBool aReplace,
|
||||
PRBool aPersist);
|
||||
|
||||
|
||||
// Manually unregister a factory for a class
|
||||
static nsresult UnregisterFactory(const nsCID &aClass,
|
||||
nsIFactory *aFactory);
|
||||
|
||||
// Manually unregister a dynamically loaded component
|
||||
static nsresult UnregisterComponent(const nsCID &aClass,
|
||||
const char *aLibrary);
|
||||
|
||||
// Manually unregister a dynamically loaded component
|
||||
static nsresult UnregisterComponentSpec(const nsCID &aClass,
|
||||
nsIFileSpec *aLibrarySpec);
|
||||
|
||||
// Unload dynamically loaded factories that are not in use
|
||||
static nsresult FreeLibraries(void);
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// DLL registration support
|
||||
|
||||
// If directory is NULL, then AutoRegister will try registering components
|
||||
// in the default components directory which is got by
|
||||
// nsSpecialSystemDirectory(XPCOM_CurrentProcessComponentDirectory)
|
||||
static nsresult AutoRegister(PRInt32 when, nsIFileSpec* directory);
|
||||
static nsresult AutoRegisterComponent(PRInt32 when, nsIFileSpec *component);
|
||||
|
||||
// Is the given CID currently registered?
|
||||
static nsresult IsRegistered(const nsCID &aClass,
|
||||
PRBool *aRegistered);
|
||||
|
||||
// Get an enumeration of all the CIDs
|
||||
static nsresult EnumerateCLSIDs(nsIEnumerator** aEmumerator);
|
||||
|
||||
// Get an enumeration of all the ProgIDs
|
||||
static nsresult EnumerateProgIDs(nsIEnumerator** aEmumerator);
|
||||
|
||||
};
|
||||
|
||||
#endif /* nsComponentManagerUtils_h__ */
|
||||
@@ -172,10 +172,11 @@ public:
|
||||
PRBool IsHidden() const {return (PRBool) (XPT_MD_IS_HIDDEN(flags) );}
|
||||
const char* GetName() const {return name;}
|
||||
uint8 GetParamCount() const {return num_args;}
|
||||
const nsXPTParamInfo GetParam(uint8 index) const
|
||||
/* idx was index before I got _sick_ of the warnings on Unix, sorry jband */
|
||||
const nsXPTParamInfo GetParam(uint8 idx) const
|
||||
{
|
||||
NS_PRECONDITION(index < GetParamCount(),"bad arg");
|
||||
return params[index];
|
||||
NS_PRECONDITION(idx < GetParamCount(),"bad arg");
|
||||
return params[idx];
|
||||
}
|
||||
const nsXPTParamInfo GetResult() const
|
||||
{return *result;}
|
||||
|
||||
@@ -70,8 +70,9 @@ int main( int argc, char *argv[] ) {
|
||||
|
||||
// Create the registry
|
||||
nsIRegistry *reg;
|
||||
static NS_DEFINE_IID(kRegistryIID, NS_IREGISTRY_IID);
|
||||
rv = compMgr->CreateInstance(NS_REGISTRY_PROGID, NULL, kRegistryIID, (void **) ®);
|
||||
rv = compMgr->CreateInstanceByProgID(NS_REGISTRY_PROGID, NULL,
|
||||
NS_GET_IID(nsIRegistry),
|
||||
(void **) ®);
|
||||
|
||||
// Check result.
|
||||
if ( NS_FAILED(rv) )
|
||||
|
||||
Reference in New Issue
Block a user