Converting to use nsIModule macro. r=dp.

This commit is contained in:
dougt%netscape.com 2000-01-03 23:37:30 +00:00
Родитель e3dc87a151
Коммит 4d1a1b38ed
7 изменённых файлов: 216 добавлений и 1711 удалений

Просмотреть файл

@ -20,23 +20,18 @@
* Contributor(s):
*/
#include "nsCOMPtr.h"
#include "nsIModule.h"
#include "nsIGenericFactory.h"
#include "nsIServiceManager.h"
#include "nsIComponentManager.h"
#include "nsIGenericFactory.h"
#include "nsIChromeRegistry.h"
#include "nsIChromeEntry.h"
#include "nscore.h"
#include "rdf.h"
#include "nsCOMPtr.h"
#include "nsIModule.h"
#include "nsChromeProtocolHandler.h"
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
static NS_DEFINE_CID(kGenericFactoryCID, NS_GENERICFACTORY_CID);
static NS_DEFINE_CID(kChromeRegistryCID, NS_CHROMEREGISTRY_CID);
static NS_DEFINE_CID(kChromeEntryCID, NS_CHROMEENTRY_CID);
static NS_DEFINE_CID(kChromeProtocolHandlerCID, NS_CHROMEPROTOCOLHANDLER_CID);
static NS_IMETHODIMP
NS_ConstructChromeRegistry(nsISupports *aOuter, REFNSIID aIID, void **aResult)
{
@ -72,253 +67,27 @@ NS_ConstructChromeEntry(nsISupports *aOuter, REFNSIID aIID, void **aResult)
}
// Module implementation
class nsChromeModule : public nsIModule
{
public:
nsChromeModule();
virtual ~nsChromeModule();
NS_DECL_ISUPPORTS
NS_DECL_NSIMODULE
protected:
nsresult Initialize();
void Shutdown();
PRBool mInitialized;
nsCOMPtr<nsIGenericFactory> mChromeRegistryFactory;
nsCOMPtr<nsIGenericFactory> mChromeProtocolHandlerFactory;
nsCOMPtr<nsIGenericFactory> mChromeEntryFactory;
};
//----------------------------------------------------------------------
// Functions used to create new instances of a given object by the
// generic factory.
//----------------------------------------------------------------------
nsChromeModule::nsChromeModule()
: mInitialized(PR_FALSE)
{
NS_INIT_ISUPPORTS();
}
nsChromeModule::~nsChromeModule()
{
Shutdown();
}
NS_IMPL_ISUPPORTS(nsChromeModule, NS_GET_IID(nsIModule))
// Perform our one-time intialization for this module
nsresult
nsChromeModule::Initialize()
{
if (mInitialized) {
return NS_OK;
}
mInitialized = PR_TRUE;
return NS_OK;
}
// Shutdown this module, releasing all of the module resources
void
nsChromeModule::Shutdown()
{
// Release the factory objects
mChromeRegistryFactory = nsnull;
mChromeProtocolHandlerFactory = nsnull;
mChromeEntryFactory = nsnull;
}
// Create a factory object for creating instances of aClass.
NS_IMETHODIMP
nsChromeModule::GetClassObject(nsIComponentManager *aCompMgr,
const nsCID& aClass,
const nsIID& aIID,
void** r_classObj)
{
nsresult rv;
// Defensive programming: Initialize *r_classObj in case of error below
if (!r_classObj) {
return NS_ERROR_INVALID_POINTER;
}
*r_classObj = NULL;
// Do one-time-only initialization if necessary
if (!mInitialized) {
rv = Initialize();
if (NS_FAILED(rv)) {
// Initialization failed! yikes!
return rv;
}
}
// Choose the appropriate factory, based on the desired instance
// class type (aClass).
nsCOMPtr<nsIGenericFactory> fact;
if (aClass.Equals(kChromeRegistryCID)) {
if (!mChromeRegistryFactory) {
// Create and save away the factory object for creating
// new instances of ChromeRegistry. This way if we are called
// again for the factory, we won't need to create a new
// one.
rv = NS_NewGenericFactory(getter_AddRefs(mChromeRegistryFactory),
NS_ConstructChromeRegistry);
}
fact = mChromeRegistryFactory;
}
else if (aClass.Equals(kChromeEntryCID)) {
if (!mChromeEntryFactory) {
// Create and save away the factory object for creating
// new instances of ChromeRegistry. This way if we are called
// again for the factory, we won't need to create a new
// one.
rv = NS_NewGenericFactory(getter_AddRefs(mChromeEntryFactory),
NS_ConstructChromeEntry);
}
fact = mChromeRegistryFactory;
}
else if (aClass.Equals(kChromeProtocolHandlerCID)) {
if (!mChromeProtocolHandlerFactory) {
// Create and save away the factory object for creating
// new instances of ChromeProtocolHandler. This way if we are called
// again for the factory, we won't need to create a new
// one.
rv = NS_NewGenericFactory(getter_AddRefs(mChromeProtocolHandlerFactory),
nsChromeProtocolHandler::Create);
}
fact = mChromeProtocolHandlerFactory;
}
else {
rv = NS_ERROR_FACTORY_NOT_REGISTERED;
#ifdef DEBUG
char* cs = aClass.ToString();
printf("+++ nsChromeModule: unable to create factory for %s\n", cs);
nsCRT::free(cs);
#endif
}
if (fact) {
rv = fact->QueryInterface(aIID, r_classObj);
}
return rv;
}
//----------------------------------------
struct Components {
const char* mDescription;
const nsID* mCID;
const char* mProgID;
};
// The list of components we register
static Components gComponents[] = {
{ "Chrome Registry", &kChromeRegistryCID,
"component://netscape/chrome/chrome-registry", },
{ "Chrome Entry", &kChromeEntryCID,
"component://netscape/chrome/chrome-entry", },
{ "Chrome Protocol Handler", &kChromeProtocolHandlerCID,
NS_NETWORK_PROTOCOL_PROGID_PREFIX "chrome", },
static nsModuleComponentInfo components[] =
{
{ "Chrome Registry",
NS_CHROMEREGISTRY_CID,
"component://netscape/chrome/chrome-registry",
NS_ConstructChromeRegistry
},
{ "Chrome Entry",
NS_CHROMEENTRY_CID,
"component://netscape/chrome/chrome-entry",
NS_ConstructChromeEntry
},
{ "Chrome Protocol Handler",
NS_CHROMEPROTOCOLHANDLER_CID,
NS_NETWORK_PROTOCOL_PROGID_PREFIX "chrome",
nsChromeProtocolHandler::Create
},
};
#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0]))
NS_IMETHODIMP
nsChromeModule::RegisterSelf(nsIComponentManager *aCompMgr,
nsIFileSpec* aPath,
const char* registryLocation,
const char* componentType)
{
nsresult rv = NS_OK;
NS_IMPL_NSGETMODULE("nsChromeModule", components);
#ifdef DEBUG
printf("*** Registering chrome components\n");
#endif
Components* cp = gComponents;
Components* end = cp + NUM_COMPONENTS;
while (cp < end) {
rv = aCompMgr->RegisterComponentSpec(*cp->mCID, cp->mDescription,
cp->mProgID, aPath, PR_TRUE,
PR_TRUE);
if (NS_FAILED(rv)) {
#ifdef DEBUG
printf("nsChromeModule: unable to register %s component => %x\n",
cp->mDescription, rv);
#endif
break;
}
cp++;
}
return rv;
}
NS_IMETHODIMP
nsChromeModule::UnregisterSelf(nsIComponentManager* aCompMgr,
nsIFileSpec* aPath,
const char* registryLocation)
{
#ifdef DEBUG
printf("*** Unregistering chrome components\n");
#endif
Components* cp = gComponents;
Components* end = cp + NUM_COMPONENTS;
while (cp < end) {
nsresult rv = aCompMgr->UnregisterComponentSpec(*cp->mCID, aPath);
if (NS_FAILED(rv)) {
#ifdef DEBUG
printf("nsChromeModule: unable to unregister %s component => %x\n",
cp->mDescription, rv);
#endif
}
cp++;
}
return NS_OK;
}
NS_IMETHODIMP
nsChromeModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload)
{
if (!okToUnload) {
return NS_ERROR_INVALID_POINTER;
}
*okToUnload = PR_FALSE;
return NS_ERROR_FAILURE;
}
//----------------------------------------------------------------------
static nsChromeModule *gModule = NULL;
extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr,
nsIFileSpec* location,
nsIModule** return_cobj)
{
nsresult rv = NS_OK;
NS_ENSURE_ARG_POINTER(return_cobj);
NS_ENSURE_FALSE(gModule, NS_ERROR_FAILURE);
// Create and initialize the module instance
nsChromeModule *m = new nsChromeModule();
if (!m) {
return NS_ERROR_OUT_OF_MEMORY;
}
// Increase refcnt and store away nsIModule interface to m in return_cobj
rv = m->QueryInterface(NS_GET_IID(nsIModule), (void**)return_cobj);
if (NS_FAILED(rv)) {
delete m;
m = nsnull;
}
gModule = m; // WARNING: Weak Reference
return rv;
}

Просмотреть файл

@ -32,32 +32,6 @@ nsresult NS_NewFTPDirListingConv(nsFTPDirListingConv** result);
nsresult NS_NewMultiMixedConv(nsMultiMixedConv** result);
nsresult MOZ_NewTXTToHTMLConv(mozTXTToHTMLConv** result);
// Module implementation
class nsConvModule : public nsIModule
{
public:
nsConvModule();
virtual ~nsConvModule();
NS_DECL_ISUPPORTS
NS_DECL_NSIMODULE
protected:
nsresult Initialize();
void Shutdown();
PRBool mInitialized;
nsCOMPtr<nsIGenericFactory> mFTPDirListingConvFactory;
nsCOMPtr<nsIGenericFactory> mMultiMixedConvFactory;
nsCOMPtr<nsIGenericFactory> mTXTToHTMLConvFactory;
};
//----------------------------------------------------------------------
// Functions used to create new instances of a given object by the
// generic factory.
static NS_IMETHODIMP
CreateNewFTPDirListingConv(nsISupports* aOuter, REFNSIID aIID, void **aResult)
@ -131,230 +105,32 @@ CreateNewTXTToHTMLConvFactory(nsISupports* aOuter, REFNSIID aIID, void **aResult
return rv;
}
//----------------------------------------------------------------------
nsConvModule::nsConvModule()
: mInitialized(PR_FALSE)
{
NS_INIT_ISUPPORTS();
}
nsConvModule::~nsConvModule()
{
Shutdown();
}
NS_IMPL_ISUPPORTS(nsConvModule, NS_GET_IID(nsIModule))
// Perform our one-time intialization for this module
nsresult
nsConvModule::Initialize()
{
if (mInitialized) {
return NS_OK;
}
mInitialized = PR_TRUE;
return NS_OK;
}
// Shutdown this module, releasing all of the module resources
void
nsConvModule::Shutdown()
{
// Release the factory objects
mFTPDirListingConvFactory = nsnull;
mMultiMixedConvFactory = nsnull;
mTXTToHTMLConvFactory = nsnull;
}
// Create a factory object for creating instances of aClass.
NS_IMETHODIMP
nsConvModule::GetClassObject(nsIComponentManager *aCompMgr,
const nsCID& aClass,
const nsIID& aIID,
void** r_classObj)
{
nsresult rv;
// Defensive programming: Initialize *r_classObj in case of error below
if (!r_classObj) {
return NS_ERROR_INVALID_POINTER;
}
*r_classObj = NULL;
// Do one-time-only initialization if necessary
if (!mInitialized) {
rv = Initialize();
if (NS_FAILED(rv)) {
// Initialization failed! yikes!
return rv;
}
}
// Choose the appropriate factory, based on the desired instance
// class type (aClass).
nsCOMPtr<nsIGenericFactory> fact;
if (aClass.Equals(kFTPDirListingConverterCID)) {
if (!mFTPDirListingConvFactory) {
// Create and save away the factory object for creating
// new instances of FTPDirListingConv. This way if we are called
// again for the factory, we won't need to create a new
// one.
rv = NS_NewGenericFactory(getter_AddRefs(mFTPDirListingConvFactory),
CreateNewFTPDirListingConv);
}
fact = mFTPDirListingConvFactory;
}
else if (aClass.Equals(kMultiMixedConverterCID)) {
if (!mMultiMixedConvFactory) {
// Create and save away the factory object for creating
// new instances of MultiMixedConv. This way if we are called
// again for the factory, we won't need to create a new
// one.
rv = NS_NewGenericFactory(getter_AddRefs(mMultiMixedConvFactory),
CreateNewMultiMixedConvFactory);
}
fact = mMultiMixedConvFactory;
}
else if (aClass.Equals(kTXTToHTMLConvCID)) {
if (!mTXTToHTMLConvFactory) {
// Create and save away the factory object for creating
// new instances of MultiMixedConv. This way if we are called
// again for the factory, we won't need to create a new
// one.
rv = NS_NewGenericFactory(getter_AddRefs(mTXTToHTMLConvFactory),
CreateNewTXTToHTMLConvFactory);
}
fact = mTXTToHTMLConvFactory;
}
else {
rv = NS_ERROR_FACTORY_NOT_REGISTERED;
#ifdef DEBUG
char* cs = aClass.ToString();
printf("+++ nsConvModule: unable to create factory for %s\n", cs);
nsCRT::free(cs);
#endif
}
if (fact) {
rv = fact->QueryInterface(aIID, r_classObj);
}
return rv;
}
//----------------------------------------
struct Components {
const char* mDescription;
const nsID* mCID;
const char* mProgID;
};
// The list of components we register
static Components gComponents[] = {
{ "FTPDirListingConverter", &kFTPDirListingConverterCID,
NS_ISTREAMCONVERTER_KEY "?from=text/ftp-dir-unix?to=application/http-index-format", },
{ "FTPDirListingConverter", &kFTPDirListingConverterCID,
NS_ISTREAMCONVERTER_KEY "?from=text/ftp-dir-nt?to=application/http-index-format", },
{ "MultiMixedConverter", &kMultiMixedConverterCID,
NS_ISTREAMCONVERTER_KEY "?from=multipart/x-mixed-replace?to=text/html", },
{ "TXTToHTMLConverter", &kTXTToHTMLConvCID,
NS_ISTREAMCONVERTER_KEY "?from=text/plain?to=text/html", },
static nsModuleComponentInfo components[] =
{
{ "FTPDirListingConverter",
NS_FTPDIRLISTINGCONVERTER_CID,
NS_ISTREAMCONVERTER_KEY "?from=text/ftp-dir-unix?to=application/http-index-format",
CreateNewFTPDirListingConv
},
{ "FTPDirListingConverter",
NS_FTPDIRLISTINGCONVERTER_CID,
NS_ISTREAMCONVERTER_KEY "?from=text/ftp-dir-nt?to=application/http-index-format",
CreateNewFTPDirListingConv
},
{ "MultiMixedConverter",
NS_MULTIMIXEDCONVERTER_CID,
NS_ISTREAMCONVERTER_KEY "?from=multipart/x-mixed-replace?to=text/html",
CreateNewMultiMixedConvFactory
},
{ "TXTToHTMLConverter",
MOZITXTTOHTMLCONV_CID,
NS_ISTREAMCONVERTER_KEY "?from=text/plain?to=text/html",
CreateNewTXTToHTMLConvFactory
},
};
#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0]))
NS_IMETHODIMP
nsConvModule::RegisterSelf(nsIComponentManager *aCompMgr,
nsIFileSpec* aPath,
const char* registryLocation,
const char* componentType)
{
nsresult rv = NS_OK;
#ifdef DEBUG
printf("*** Registering Conv components\n");
#endif
Components* cp = gComponents;
Components* end = cp + NUM_COMPONENTS;
while (cp < end) {
rv = aCompMgr->RegisterComponentSpec(*cp->mCID, cp->mDescription,
cp->mProgID, aPath, PR_TRUE,
PR_TRUE);
if (NS_FAILED(rv)) {
#ifdef DEBUG
printf("nsConvModule: unable to register %s component => %x\n",
cp->mDescription, rv);
#endif
break;
}
cp++;
}
return rv;
}
NS_IMETHODIMP
nsConvModule::UnregisterSelf(nsIComponentManager* aCompMgr,
nsIFileSpec* aPath,
const char* registryLocation)
{
#ifdef DEBUG
printf("*** Unregistering Conv components\n");
#endif
Components* cp = gComponents;
Components* end = cp + NUM_COMPONENTS;
while (cp < end) {
nsresult rv = aCompMgr->UnregisterComponentSpec(*cp->mCID, aPath);
if (NS_FAILED(rv)) {
#ifdef DEBUG
printf("nsConvModule: unable to unregister %s component => %x\n",
cp->mDescription, rv);
#endif
}
cp++;
}
return NS_OK;
}
NS_IMETHODIMP
nsConvModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload)
{
if (!okToUnload) {
return NS_ERROR_INVALID_POINTER;
}
*okToUnload = PR_FALSE;
return NS_ERROR_FAILURE;
}
//----------------------------------------------------------------------
static nsConvModule *gModule = NULL;
extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr,
nsIFileSpec* location,
nsIModule** return_cobj)
{
nsresult rv = NS_OK;
NS_ENSURE_ARG_POINTER(return_cobj);
NS_ENSURE_FALSE(gModule, NS_ERROR_FAILURE);
// Create and initialize the module instance
nsConvModule *m = new nsConvModule();
if (!m) {
return NS_ERROR_OUT_OF_MEMORY;
}
// Increase refcnt and store away nsIModule interface to m in return_cobj
rv = m->QueryInterface(NS_GET_IID(nsIModule), (void**)return_cobj);
if (NS_FAILED(rv)) {
delete m;
m = nsnull;
}
gModule = m; // WARNING: Weak Reference
return rv;
}
NS_IMPL_NSGETMODULE("nsConvModule", components);

Просмотреть файл

@ -79,199 +79,14 @@ CreateNewStreamConv(nsISupports* aOuter, REFNSIID aIID, void **aResult)
return rv;
}
//----------------------------------------------------------------------
nsStreamConvModule::nsStreamConvModule()
: mInitialized(PR_FALSE)
static nsModuleComponentInfo components[] =
{
NS_INIT_ISUPPORTS();
}
nsStreamConvModule::~nsStreamConvModule()
{
Shutdown();
}
NS_IMPL_ISUPPORTS(nsStreamConvModule, NS_GET_IID(nsIModule))
// Perform our one-time intialization for this module
nsresult
nsStreamConvModule::Initialize()
{
if (mInitialized) {
return NS_OK;
}
mInitialized = PR_TRUE;
return NS_OK;
}
// Shutdown this module, releasing all of the module resources
void
nsStreamConvModule::Shutdown()
{
// Release the factory objects
mStreamConvFactory = nsnull;
}
// Create a factory object for creating instances of aClass.
NS_IMETHODIMP
nsStreamConvModule::GetClassObject(nsIComponentManager *aCompMgr,
const nsCID& aClass,
const nsIID& aIID,
void** r_classObj)
{
nsresult rv;
// Defensive programming: Initialize *r_classObj in case of error below
if (!r_classObj) {
return NS_ERROR_INVALID_POINTER;
}
*r_classObj = NULL;
// Do one-time-only initialization if necessary
if (!mInitialized) {
rv = Initialize();
if (NS_FAILED(rv)) {
// Initialization failed! yikes!
return rv;
}
}
// Choose the appropriate factory, based on the desired instance
// class type (aClass).
nsCOMPtr<nsIGenericFactory> fact;
if (aClass.Equals(kStreamConvServiceCID)) {
if (!mStreamConvFactory) {
// Create and save away the factory object for creating
// new instances of StreamConv. This way if we are called
// again for the factory, we won't need to create a new
// one.
rv = NS_NewGenericFactory(getter_AddRefs(mStreamConvFactory),
CreateNewStreamConv);
}
fact = mStreamConvFactory;
}
else {
rv = NS_ERROR_FACTORY_NOT_REGISTERED;
#ifdef DEBUG
char* cs = aClass.ToString();
printf("+++ nsStreamConvModule: unable to create factory for %s\n", cs);
nsCRT::free(cs);
#endif
}
if (fact) {
rv = fact->QueryInterface(aIID, r_classObj);
}
return rv;
}
//----------------------------------------
struct Components {
const char* mDescription;
const nsID* mCID;
const char* mProgID;
{ "Stream Converter Service",
NS_STREAMCONVERTERSERVICE_CID,
"component:||netscape|streamConverters",
CreateNewStreamConv
},
};
// The list of components we register
static Components gComponents[] = {
{ "Stream Converter Service", &kStreamConvServiceCID,
"component:||netscape|streamConverters", },
};
#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0]))
NS_IMETHODIMP
nsStreamConvModule::RegisterSelf(nsIComponentManager *aCompMgr,
nsIFileSpec* aPath,
const char* registryLocation,
const char* componentType)
{
nsresult rv = NS_OK;
#ifdef DEBUG
printf("*** Registering StreamConv components\n");
#endif
Components* cp = gComponents;
Components* end = cp + NUM_COMPONENTS;
while (cp < end) {
rv = aCompMgr->RegisterComponentSpec(*cp->mCID, cp->mDescription,
cp->mProgID, aPath, PR_TRUE,
PR_TRUE);
if (NS_FAILED(rv)) {
#ifdef DEBUG
printf("nsStreamConvModule: unable to register %s component => %x\n",
cp->mDescription, rv);
#endif
break;
}
cp++;
}
return rv;
}
NS_IMETHODIMP
nsStreamConvModule::UnregisterSelf(nsIComponentManager* aCompMgr,
nsIFileSpec* aPath,
const char* registryLocation)
{
#ifdef DEBUG
printf("*** Unregistering StreamConv components\n");
#endif
Components* cp = gComponents;
Components* end = cp + NUM_COMPONENTS;
while (cp < end) {
nsresult rv = aCompMgr->UnregisterComponentSpec(*cp->mCID, aPath);
if (NS_FAILED(rv)) {
#ifdef DEBUG
printf("nsStreamConvModule: unable to unregister %s component => %x\n",
cp->mDescription, rv);
#endif
}
cp++;
}
return NS_OK;
}
NS_IMETHODIMP
nsStreamConvModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload)
{
if (!okToUnload) {
return NS_ERROR_INVALID_POINTER;
}
*okToUnload = PR_FALSE;
return NS_ERROR_FAILURE;
}
//----------------------------------------------------------------------
static nsStreamConvModule *gModule = NULL;
extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr,
nsIFileSpec* location,
nsIModule** return_cobj)
{
nsresult rv = NS_OK;
NS_ENSURE_ARG_POINTER(return_cobj);
NS_ENSURE_FALSE(gModule, NS_ERROR_FAILURE);
// Create and initialize the module instance
nsStreamConvModule *m = new nsStreamConvModule();
if (!m) {
return NS_ERROR_OUT_OF_MEMORY;
}
// Increase refcnt and store away nsIModule interface to m in return_cobj
rv = m->QueryInterface(NS_GET_IID(nsIModule), (void**)return_cobj);
if (NS_FAILED(rv)) {
delete m;
m = nsnull;
}
gModule = m; // WARNING: Weak Reference
return rv;
}
NS_IMPL_NSGETMODULE("nsStreamConvModule", components);

Просмотреть файл

@ -21,27 +21,12 @@
*/
#include "pratom.h"
#include "nsIComponentManager.h"
#include "nsIServiceManager.h"
#include "NSReg.h"
#include "nsCOMPtr.h"
#include "nsIModule.h"
#include "nsIGenericFactory.h"
#include "nsPrefMigration.h"
#include "nsPrefMigrationFactory.h"
/*-------------------------------------------------------------------------*/
/* Pref Migration Factory routines */
/*-------------------------------------------------------------------------*/
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); /* Need to remove these defines from this */
static NS_DEFINE_IID(kPrefMigrationCID, NS_PREFMIGRATION_CID);
//----------------------------------------------------------------------
// Functions used to create new instances of a given object by the
// generic factory.
static NS_IMETHODIMP
CreateNewPrefMigration(nsISupports* aOuter, REFNSIID aIID, void **aResult)
{
@ -63,200 +48,14 @@ CreateNewPrefMigration(nsISupports* aOuter, REFNSIID aIID, void **aResult)
return rv;
}
//----------------------------------------------------------------------
nsPrefMigrationModule::nsPrefMigrationModule()
: mInitialized(PR_FALSE)
static nsModuleComponentInfo components[] =
{
NS_INIT_ISUPPORTS();
}
nsPrefMigrationModule::~nsPrefMigrationModule()
{
Shutdown();
}
NS_IMPL_ISUPPORTS(nsPrefMigrationModule, NS_GET_IID(nsIModule))
// Perform our one-time intialization for this module
nsresult
nsPrefMigrationModule::Initialize()
{
if (mInitialized) {
return NS_OK;
{ "Profile Migration",
NS_PREFMIGRATION_CID,
NS_PROFILEMIGRATION_PROGID,
CreateNewPrefMigration
}
mInitialized = PR_TRUE;
return NS_OK;
}
// Shutdown this module, releasing all of the module resources
void
nsPrefMigrationModule::Shutdown()
{
// Release the factory object
mFactory = nsnull;
}
// Create a factory object for creating instances of aClass.
NS_IMETHODIMP
nsPrefMigrationModule::GetClassObject(nsIComponentManager *aCompMgr,
const nsCID& aClass,
const nsIID& aIID,
void** r_classObj)
{
nsresult rv;
// Defensive programming: Initialize *r_classObj in case of error below
if (!r_classObj) {
return NS_ERROR_INVALID_POINTER;
}
*r_classObj = NULL;
// Do one-time-only initialization if necessary
if (!mInitialized) {
rv = Initialize();
if (NS_FAILED(rv)) {
// Initialization failed! yikes!
return rv;
}
}
// Choose the appropriate factory, based on the desired instance
// class type (aClass).
nsCOMPtr<nsIGenericFactory> fact;
if (aClass.Equals(kPrefMigrationCID)) {
if (!mFactory) {
// Create and save away the factory object for creating
// new instances of prefMigration. This way if we are called
// again for the factory, we won't need to create a new
// one.
rv = NS_NewGenericFactory(getter_AddRefs(mFactory),
CreateNewPrefMigration);
}
fact = mFactory;
}
else {
rv = NS_ERROR_FACTORY_NOT_REGISTERED;
#ifdef DEBUG
char* cs = aClass.ToString();
printf("+++ nsPrefMigrationModule: unable to create factory for %s\n", cs);
nsCRT::free(cs);
#endif
}
if (fact) {
rv = fact->QueryInterface(aIID, r_classObj);
}
return rv;
}
//----------------------------------------
struct Components {
const char* mDescription;
const nsID* mCID;
const char* mProgID;
};
// The list of components we register
static Components gComponents[] = {
{ "Profile Migration", &kPrefMigrationCID,
NS_PROFILEMIGRATION_PROGID, },
};
#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0]))
NS_IMETHODIMP
nsPrefMigrationModule::RegisterSelf(nsIComponentManager *aCompMgr,
nsIFileSpec* aPath,
const char* registryLocation,
const char* componentType)
{
nsresult rv = NS_OK;
#ifdef DEBUG
printf("*** Registering PrefMigration components\n");
#endif
Components* cp = gComponents;
Components* end = cp + NUM_COMPONENTS;
while (cp < end) {
rv = aCompMgr->RegisterComponentSpec(*cp->mCID, cp->mDescription,
cp->mProgID, aPath, PR_TRUE,
PR_TRUE);
if (NS_FAILED(rv)) {
#ifdef DEBUG
printf("nsPrefMigrationModule: unable to register %s component => %x\n",
cp->mDescription, rv);
#endif
break;
}
cp++;
}
return rv;
}
NS_IMETHODIMP
nsPrefMigrationModule::UnregisterSelf(nsIComponentManager* aCompMgr,
nsIFileSpec* aPath,
const char* registryLocation)
{
#ifdef DEBUG
printf("*** Unregistering PrefMigration components\n");
#endif
Components* cp = gComponents;
Components* end = cp + NUM_COMPONENTS;
while (cp < end) {
nsresult rv = aCompMgr->UnregisterComponentSpec(*cp->mCID, aPath);
if (NS_FAILED(rv)) {
#ifdef DEBUG
printf("nsPrefMigrationModule: unable to unregister %s component => %x\n",
cp->mDescription, rv);
#endif
}
cp++;
}
return NS_OK;
}
NS_IMETHODIMP
nsPrefMigrationModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload)
{
if (!okToUnload) {
return NS_ERROR_INVALID_POINTER;
}
*okToUnload = PR_FALSE;
return NS_ERROR_FAILURE;
}
//----------------------------------------------------------------------
static nsPrefMigrationModule *gModule = NULL;
extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr,
nsIFileSpec* location,
nsIModule** return_cobj)
{
nsresult rv = NS_OK;
NS_ENSURE_ARG_POINTER(return_cobj);
NS_ENSURE_FALSE(gModule, NS_ERROR_FAILURE);
// Create and initialize the module instance
nsPrefMigrationModule *m = new nsPrefMigrationModule();
if (!m) {
return NS_ERROR_OUT_OF_MEMORY;
}
// Increase refcnt and store away nsIModule interface to m in return_cobj
rv = m->QueryInterface(NS_GET_IID(nsIModule), (void**)return_cobj);
if (NS_FAILED(rv)) {
delete m;
m = nsnull;
}
gModule = m; // WARNING: Weak Reference
return rv;
}
NS_IMPL_NSGETMODULE("nsPrefMigrationModule", components);

Просмотреть файл

@ -22,257 +22,17 @@
#include "nsProfile.h"
#include "nsIModule.h"
#include "nsCOMPtr.h"
#include "nsIFileSpec.h"
#include "nsIComponentManager.h"
#include "nsIGenericFactory.h"
static NS_DEFINE_CID(kProfileCID, NS_PROFILE_CID);
NS_GENERIC_FACTORY_CONSTRUCTOR(nsProfile);
class nsProfileModule : public nsIModule
static nsModuleComponentInfo components[] =
{
public:
nsProfileModule();
virtual ~nsProfileModule();
NS_DECL_ISUPPORTS
NS_DECL_NSIMODULE
protected:
nsresult Initialize();
void Shutdown();
PRBool mInitialized;
nsCOMPtr<nsIGenericFactory> mFactory;
{ "Profile Manager",
NS_PROFILE_CID,
NS_PROFILE_PROGID,
nsProfileConstructor,
}
};
//----------------------------------------------------------------------
// Functions used to create new instances of a given object by the
// generic factory.
static NS_IMETHODIMP
CreateNewProfileObject(nsISupports* aOuter, REFNSIID aIID, void **aResult)
{
nsresult rv = NS_OK;
if (!aResult) {
return NS_ERROR_INVALID_POINTER;
}
if (aOuter) {
*aResult = nsnull;
return NS_ERROR_NO_AGGREGATION;
}
nsIProfile *inst = new nsProfile();
if (!inst) {
*aResult = nsnull;
rv = NS_ERROR_OUT_OF_MEMORY;
return rv;
}
NS_ADDREF(inst);
rv = inst->QueryInterface(aIID, aResult);
if (NS_FAILED(rv)) {
*aResult = nsnull;
}
NS_RELEASE(inst); /* get rid of extra refcnt */
return rv;
}
//----------------------------------------------------------------------
nsProfileModule::nsProfileModule()
: mInitialized(PR_FALSE)
{
NS_INIT_ISUPPORTS();
}
nsProfileModule::~nsProfileModule()
{
Shutdown();
}
NS_IMPL_ISUPPORTS(nsProfileModule, NS_GET_IID(nsIModule))
// Perform our one-time intialization for this module
nsresult
nsProfileModule::Initialize()
{
if (mInitialized) {
return NS_OK;
}
mInitialized = PR_TRUE;
return NS_OK;
}
// Shutdown this module, releasing all of the module resources
void
nsProfileModule::Shutdown()
{
// Release the factory object
mFactory = nsnull;
}
// Create a factory object for creating instances of aClass.
NS_IMETHODIMP
nsProfileModule::GetClassObject(nsIComponentManager *aCompMgr,
const nsCID& aClass,
const nsIID& aIID,
void** r_classObj)
{
nsresult rv;
// Defensive programming: Initialize *r_classObj in case of error below
if (!r_classObj) {
return NS_ERROR_INVALID_POINTER;
}
*r_classObj = NULL;
// Do one-time-only initialization if necessary
if (!mInitialized) {
rv = Initialize();
if (NS_FAILED(rv)) {
// Initialization failed! yikes!
return rv;
}
}
// Choose the appropriate factory, based on the desired instance
// class type (aClass).
nsCOMPtr<nsIGenericFactory> fact;
if (aClass.Equals(kProfileCID)) {
if (!mFactory) {
// Create and save away the factory object for creating
// new instances of Profile. This way if we are called
// again for the factory, we won't need to create a new
// one.
rv = NS_NewGenericFactory(getter_AddRefs(mFactory),
CreateNewProfileObject);
}
fact = mFactory;
}
else {
rv = NS_ERROR_FACTORY_NOT_REGISTERED;
#ifdef DEBUG
char* cs = aClass.ToString();
printf("+++ nsProfileModule: unable to create factory for %s\n", cs);
nsCRT::free(cs);
#endif
}
if (fact) {
rv = fact->QueryInterface(aIID, r_classObj);
}
return rv;
}
//----------------------------------------
struct Components {
const char* mDescription;
const nsID* mCID;
const char* mProgID;
};
// The list of components we register
static Components gComponents[] = {
{ "Profile Manager", &kProfileCID,
NS_PROFILE_PROGID, },
};
#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0]))
NS_IMETHODIMP
nsProfileModule::RegisterSelf(nsIComponentManager *aCompMgr,
nsIFileSpec* aPath,
const char* registryLocation,
const char* componentType)
{
nsresult rv = NS_OK;
#ifdef DEBUG
printf("*** Registering profile components\n");
#endif
Components* cp = gComponents;
Components* end = cp + NUM_COMPONENTS;
while (cp < end) {
rv = aCompMgr->RegisterComponentSpec(*cp->mCID, cp->mDescription,
cp->mProgID, aPath, PR_TRUE,
PR_TRUE);
if (NS_FAILED(rv)) {
#ifdef DEBUG
printf("nsProfileModule: unable to register %s component => %x\n",
cp->mDescription, rv);
#endif
break;
}
cp++;
}
return rv;
}
NS_IMETHODIMP
nsProfileModule::UnregisterSelf(nsIComponentManager* aCompMgr,
nsIFileSpec* aPath,
const char* registryLocation)
{
#ifdef DEBUG
printf("*** Unregistering profile components\n");
#endif
Components* cp = gComponents;
Components* end = cp + NUM_COMPONENTS;
while (cp < end) {
nsresult rv = aCompMgr->UnregisterComponentSpec(*cp->mCID, aPath);
if (NS_FAILED(rv)) {
#ifdef DEBUG
printf("nsProfileModule: unable to unregister %s component => %x\n",
cp->mDescription, rv);
#endif
}
cp++;
}
return NS_OK;
}
NS_IMETHODIMP
nsProfileModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload)
{
if (!okToUnload) {
return NS_ERROR_INVALID_POINTER;
}
*okToUnload = PR_FALSE;
return NS_ERROR_FAILURE;
}
//----------------------------------------------------------------------
static nsProfileModule *gModule = NULL;
extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr,
nsIFileSpec* location,
nsIModule** return_cobj)
{
nsresult rv = NS_OK;
NS_ENSURE_ARG_POINTER(return_cobj);
NS_ENSURE_FALSE(gModule, NS_ERROR_FAILURE);
// Create an initialize the layout module instance
nsProfileModule *m = new nsProfileModule();
if (!m) {
return NS_ERROR_OUT_OF_MEMORY;
}
// Increase refcnt and store away nsIModule interface to m in return_cobj
rv = m->QueryInterface(nsIModule::GetIID(), (void**)return_cobj);
if (NS_FAILED(rv)) {
delete m;
m = nsnull;
}
gModule = m; // WARNING: Weak Reference
return rv;
}
NS_IMPL_NSGETMODULE("nsProfileModule", components);

Просмотреть файл

@ -20,9 +20,11 @@
* Contributor(s):
*/
#include "nsCOMPtr.h"
#include "nsIGenericFactory.h"
#include "nsIModule.h"
#include "nsRDFModule.h"
#include "nsIFactory.h"
#include "nsIGenericFactory.h"
#include "nsILocalStore.h"
#include "nsIRDFContainer.h"
#include "nsIRDFContainerUtils.h"
@ -46,33 +48,6 @@
#include "nsIXULKeyListener.h"
#include "nsIServiceManager.h"
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
static NS_DEFINE_CID(kGenericFactoryCID, NS_GENERICFACTORY_CID);
static NS_DEFINE_CID(kLocalStoreCID, NS_LOCALSTORE_CID);
static NS_DEFINE_CID(kRDFCompositeDataSourceCID, NS_RDFCOMPOSITEDATASOURCE_CID);
static NS_DEFINE_CID(kRDFContainerCID, NS_RDFCONTAINER_CID);
static NS_DEFINE_CID(kRDFContainerUtilsCID, NS_RDFCONTAINERUTILS_CID);
static NS_DEFINE_CID(kRDFContentSinkCID, NS_RDFCONTENTSINK_CID);
static NS_DEFINE_CID(kRDFDefaultResourceCID, NS_RDFDEFAULTRESOURCE_CID);
static NS_DEFINE_CID(kRDFFileSystemDataSourceCID, NS_RDFFILESYSTEMDATASOURCE_CID);
static NS_DEFINE_CID(kRDFSearchDataSourceCID, NS_RDFSEARCHDATASOURCE_CID);
static NS_DEFINE_CID(kRDFFindDataSourceCID, NS_RDFFINDDATASOURCE_CID);
static NS_DEFINE_CID(kRDFInMemoryDataSourceCID, NS_RDFINMEMORYDATASOURCE_CID);
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static NS_DEFINE_CID(kRDFXMLDataSourceCID, NS_RDFXMLDATASOURCE_CID);
static NS_DEFINE_CID(kXULContentSinkCID, NS_XULCONTENTSINK_CID);
static NS_DEFINE_CID(kXULContentUtilsCID, NS_XULCONTENTUTILS_CID);
static NS_DEFINE_CID(kXULDocumentCID, NS_XULDOCUMENT_CID);
static NS_DEFINE_CID(kXULSortServiceCID, NS_XULSORTSERVICE_CID);
static NS_DEFINE_CID(kXULPopupListenerCID, NS_XULPOPUPLISTENER_CID);
static NS_DEFINE_CID(kXULPrototypeCacheCID, NS_XULPROTOTYPECACHE_CID);
static NS_DEFINE_CID(kXULKeyListenerCID, NS_XULKEYLISTENER_CID);
static NS_DEFINE_CID(kXULControllersCID, NS_XULCONTROLLERS_CID);
static NS_DEFINE_CID(kXULTemplateBuilderCID, NS_XULTEMPLATEBUILDER_CID);
//----------------------------------------------------------------------
// Functions used to create new instances of a given object by the
@ -129,286 +104,128 @@ MAKE_CTOR(XULContentSink,XULContentSink,XULContentSink)
MAKE_CTOR(RDFDefaultResource,DefaultResource,RDFResource)
MAKE_CTOR(LocalStore,LocalStore,LocalStore)
//----------------------------------------------------------------------
static NS_DEFINE_IID(kIModuleIID, NS_IMODULE_IID);
nsRDFModule::nsRDFModule()
: mInitialized(PR_FALSE)
{
NS_INIT_ISUPPORTS();
}
nsRDFModule::~nsRDFModule()
{
Shutdown();
}
NS_IMPL_ISUPPORTS(nsRDFModule, kIModuleIID)
// Perform our one-time intialization for this module
nsresult
nsRDFModule::Initialize()
{
if (mInitialized) {
return NS_OK;
}
return NS_OK;
}
// Shutdown this module, releasing all of the module resources
void
nsRDFModule::Shutdown()
{
}
NS_IMETHODIMP
nsRDFModule::GetClassObject(nsIComponentManager *aCompMgr,
const nsCID& aClass,
const nsIID& aIID,
void** r_classObj)
{
nsresult rv;
// Defensive programming: Initialize *r_classObj in case of error below
if (!r_classObj) {
return NS_ERROR_INVALID_POINTER;
}
*r_classObj = NULL;
if (!mInitialized) {
rv = Initialize();
if (NS_FAILED(rv)) {
return rv;
}
mInitialized = PR_TRUE;
}
nsCOMPtr<nsIGenericFactory> fact;
// Note: these are in the same order as the registration table
// below, not in frequency of use order.
if (aClass.Equals(kRDFCompositeDataSourceCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), CreateNewRDFCompositeDataSource);
}
else if (aClass.Equals(kRDFFileSystemDataSourceCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), CreateNewRDFFileSystemDataSource);
}
else if (aClass.Equals(kRDFInMemoryDataSourceCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), NS_NewRDFInMemoryDataSource);
}
else if (aClass.Equals(kLocalStoreCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), CreateNewLocalStore);
}
else if (aClass.Equals(kRDFXMLDataSourceCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), CreateNewRDFXMLDataSource);
}
else if (aClass.Equals(kRDFDefaultResourceCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), CreateNewRDFDefaultResource);
}
else if (aClass.Equals(kRDFContentSinkCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), CreateNewRDFContentSink);
}
else if (aClass.Equals(kRDFContainerCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), CreateNewRDFContainer);
}
else if (aClass.Equals(kRDFContainerUtilsCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), CreateNewRDFContainerUtils);
}
else if (aClass.Equals(kRDFServiceCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), CreateNewRDFService);
}
else if (aClass.Equals(kXULSortServiceCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), CreateNewXULSortService);
}
else if (aClass.Equals(kXULTemplateBuilderCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), CreateNewXULTemplateBuilder);
}
else if (aClass.Equals(kXULContentSinkCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), CreateNewXULContentSink);
}
else if (aClass.Equals(kXULDocumentCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), CreateNewXULDocument);
}
else if (aClass.Equals(kXULPopupListenerCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), CreateNewXULPopupListener);
}
else if (aClass.Equals(kXULKeyListenerCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), CreateNewXULKeyListener);
}
else if (aClass.Equals(kXULControllersCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), NS_NewXULControllers);
}
else if (aClass.Equals(kXULContentUtilsCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), NS_NewXULContentUtils);
}
else if (aClass.Equals(kXULPrototypeCacheCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), NS_NewXULPrototypeCache);
}
else {
rv = NS_ERROR_FACTORY_NOT_REGISTERED;
#ifdef DEBUG
char* cs = aClass.ToString();
printf("+++ nsRDFModule: unable to create factory for %s\n", cs);
nsCRT::free(cs);
#endif
}
if (fact) {
rv = fact->QueryInterface(aIID, r_classObj);
}
return rv;
}
//----------------------------------------
struct Components {
const char* mDescription;
const nsID* mCID;
const char* mProgID;
};
// The list of components we register
static Components gComponents[] = {
// register our build-in datasources:
{ "RDF Composite Data Source", &kRDFCompositeDataSourceCID,
NS_RDF_DATASOURCE_PROGID_PREFIX "composite-datasource", },
{ "RDF File System Data Source", &kRDFFileSystemDataSourceCID,
NS_RDF_DATASOURCE_PROGID_PREFIX "files", },
{ "RDF In-Memory Data Source", &kRDFInMemoryDataSourceCID,
NS_RDF_DATASOURCE_PROGID_PREFIX "in-memory-datasource", },
{ "Local Store", &kLocalStoreCID,
NS_RDF_DATASOURCE_PROGID_PREFIX "local-store", },
{ "RDF XML Data Source", &kRDFXMLDataSourceCID,
NS_RDF_DATASOURCE_PROGID_PREFIX "xml-datasource", },
static nsModuleComponentInfo components[] =
{ // register our build-in datasources:
{
"RDF Composite Data Source",
NS_RDFCOMPOSITEDATASOURCE_CID,
NS_RDF_DATASOURCE_PROGID_PREFIX "composite-datasource",
CreateNewRDFCompositeDataSource
},
{
"RDF File System Data Source",
NS_RDFFILESYSTEMDATASOURCE_CID,
NS_RDF_DATASOURCE_PROGID_PREFIX "files",
CreateNewRDFFileSystemDataSource
},
{ "RDF In-Memory Data Source",
NS_RDFINMEMORYDATASOURCE_CID,
NS_RDF_DATASOURCE_PROGID_PREFIX "in-memory-datasource",
NS_NewRDFInMemoryDataSource
},
{ "Local Store",
NS_LOCALSTORE_CID,
NS_RDF_DATASOURCE_PROGID_PREFIX "local-store",
CreateNewLocalStore
},
{ "RDF XML Data Source",
NS_RDFXMLDATASOURCE_CID,
NS_RDF_DATASOURCE_PROGID_PREFIX "xml-datasource",
CreateNewRDFXMLDataSource
},
// register our built-in resource factories:
{ "RDF Default Resource Factory", &kRDFDefaultResourceCID,
{ "RDF Default Resource Factory",
NS_RDFDEFAULTRESOURCE_CID,
// Note: default resource factory has no name= part
NS_RDF_RESOURCE_FACTORY_PROGID, },
NS_RDF_RESOURCE_FACTORY_PROGID,
CreateNewRDFDefaultResource
},
// register all the other rdf components:
{ "RDF Content Sink", &kRDFContentSinkCID,
NS_RDF_PROGID "/content-sink", },
{ "RDF Container", &kRDFContainerCID,
NS_RDF_PROGID "/container", },
{ "RDF Container Utilities", &kRDFContainerUtilsCID,
NS_RDF_PROGID "/container-utils", },
{ "RDF Service", &kRDFServiceCID,
NS_RDF_PROGID "/rdf-service", },
{ "XUL Sort Service", &kXULSortServiceCID,
NS_RDF_PROGID "/xul-sort-service", },
{ "XUL Template Builder", &kXULTemplateBuilderCID,
NS_RDF_PROGID "/xul-template-builder", },
{ "XUL Content Sink", &kXULContentSinkCID,
NS_RDF_PROGID "/xul-content-sink", },
{ "XUL Document", &kXULDocumentCID,
NS_RDF_PROGID "/xul-document", },
{ "XUL PopupListener", &kXULPopupListenerCID,
NS_RDF_PROGID "/xul-popup-listener", },
{ "XUL KeyListener", &kXULKeyListenerCID,
NS_RDF_PROGID "/xul-key-listener", },
{ "XUL Controllers", &kXULControllersCID,
NS_RDF_PROGID "/xul-controllers", },
{ "XUL Content Utilities", &kXULContentUtilsCID,
NS_RDF_PROGID "/xul-content-utils", },
{ "XUL Prototype Cache", &kXULPrototypeCacheCID,
NS_RDF_PROGID "/xul-prototype-cache", },
{ "RDF Content Sink",
NS_RDFCONTENTSINK_CID,
NS_RDF_PROGID "/content-sink",
CreateNewRDFContentSink
},
{ "RDF Container",
NS_RDFCONTAINER_CID,
NS_RDF_PROGID "/container",
CreateNewRDFContainer
},
{ "RDF Container Utilities",
NS_RDFCONTAINERUTILS_CID,
NS_RDF_PROGID "/container-utils",
CreateNewRDFContainerUtils
},
{ "RDF Service",
NS_RDFSERVICE_CID,
NS_RDF_PROGID "/rdf-service",
CreateNewRDFService
},
{ "XUL Sort Service",
NS_XULSORTSERVICE_CID,
NS_RDF_PROGID "/xul-sort-service",
CreateNewXULSortService
},
{ "XUL Template Builder",
NS_XULTEMPLATEBUILDER_CID,
NS_RDF_PROGID "/xul-template-builder",
CreateNewXULTemplateBuilder
},
{ "XUL Content Sink",
NS_XULCONTENTSINK_CID,
NS_RDF_PROGID "/xul-content-sink",
CreateNewXULContentSink
},
{ "XUL Document",
NS_XULDOCUMENT_CID,
NS_RDF_PROGID "/xul-document",
CreateNewXULDocument
},
{ "XUL PopupListener",
NS_XULPOPUPLISTENER_CID,
NS_RDF_PROGID "/xul-popup-listener",
CreateNewXULPopupListener
},
{ "XUL KeyListener",
NS_XULKEYLISTENER_CID,
NS_RDF_PROGID "/xul-key-listener",
CreateNewXULKeyListener
},
{ "XUL Controllers",
NS_XULCONTROLLERS_CID,
NS_RDF_PROGID "/xul-controllers",
NS_NewXULControllers
},
{ "XUL Content Utilities",
NS_XULCONTENTUTILS_CID ,
NS_RDF_PROGID "/xul-content-utils",
NS_NewXULContentUtils
},
{ "XUL Prototype Cache",
NS_XULPROTOTYPECACHE_CID,
NS_RDF_PROGID "/xul-prototype-cache",
NS_NewXULPrototypeCache
},
};
#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0]))
NS_IMETHODIMP
nsRDFModule::RegisterSelf(nsIComponentManager *aCompMgr,
nsIFileSpec* aPath,
const char* registryLocation,
const char* componentType)
{
nsresult rv = NS_OK;
#ifdef DEBUG
printf("*** Registering rdf components\n");
#endif
Components* cp = gComponents;
Components* end = cp + NUM_COMPONENTS;
while (cp < end) {
rv = aCompMgr->RegisterComponentSpec(*cp->mCID, cp->mDescription,
cp->mProgID, aPath, PR_TRUE,
PR_TRUE);
if (NS_FAILED(rv)) {
#ifdef DEBUG
printf("nsRDFModule: unable to register %s component => %x\n",
cp->mDescription, rv);
#endif
break;
}
cp++;
}
return rv;
}
NS_IMETHODIMP
nsRDFModule::UnregisterSelf(nsIComponentManager* aCompMgr,
nsIFileSpec* aPath,
const char* registryLocation)
{
#ifdef DEBUG
printf("*** Unregistering rdf components\n");
#endif
Components* cp = gComponents;
Components* end = cp + NUM_COMPONENTS;
while (cp < end) {
nsresult rv = aCompMgr->UnregisterComponentSpec(*cp->mCID, aPath);
if (NS_FAILED(rv)) {
#ifdef DEBUG
printf("nsRDFModule: unable to unregister %s component => %x\n",
cp->mDescription, rv);
#endif
}
cp++;
}
return NS_OK;
}
NS_IMETHODIMP
nsRDFModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload)
{
if (!okToUnload) {
return NS_ERROR_INVALID_POINTER;
}
*okToUnload = PR_FALSE;
return NS_ERROR_FAILURE;
}
//----------------------------------------------------------------------
static nsRDFModule *gModule = NULL;
extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr,
nsIFileSpec* location,
nsIModule** return_cobj)
{
nsresult rv = NS_OK;
NS_ASSERTION(return_cobj, "Null argument");
NS_ASSERTION(gModule == NULL, "nsRDFModule: Module already created.");
// Create an initialize the layout module instance
nsRDFModule *m = new nsRDFModule();
if (!m) {
return NS_ERROR_OUT_OF_MEMORY;
}
// Increase refcnt and store away nsIModule interface to m in return_cobj
rv = m->QueryInterface(nsIModule::GetIID(), (void**)return_cobj);
if (NS_FAILED(rv)) {
delete m;
m = nsnull;
}
gModule = m; // WARNING: Weak Reference
return rv;
}
NS_IMPL_NSGETMODULE("nsRDFModule", components);

Просмотреть файл

@ -20,23 +20,18 @@
* Contributor(s):
*/
#include "nsCOMPtr.h"
#include "nsIModule.h"
#include "nsIGenericFactory.h"
#include "nsIServiceManager.h"
#include "nsIComponentManager.h"
#include "nsIGenericFactory.h"
#include "nsIChromeRegistry.h"
#include "nsIChromeEntry.h"
#include "nscore.h"
#include "rdf.h"
#include "nsCOMPtr.h"
#include "nsIModule.h"
#include "nsChromeProtocolHandler.h"
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
static NS_DEFINE_CID(kGenericFactoryCID, NS_GENERICFACTORY_CID);
static NS_DEFINE_CID(kChromeRegistryCID, NS_CHROMEREGISTRY_CID);
static NS_DEFINE_CID(kChromeEntryCID, NS_CHROMEENTRY_CID);
static NS_DEFINE_CID(kChromeProtocolHandlerCID, NS_CHROMEPROTOCOLHANDLER_CID);
static NS_IMETHODIMP
NS_ConstructChromeRegistry(nsISupports *aOuter, REFNSIID aIID, void **aResult)
{
@ -72,253 +67,27 @@ NS_ConstructChromeEntry(nsISupports *aOuter, REFNSIID aIID, void **aResult)
}
// Module implementation
class nsChromeModule : public nsIModule
{
public:
nsChromeModule();
virtual ~nsChromeModule();
NS_DECL_ISUPPORTS
NS_DECL_NSIMODULE
protected:
nsresult Initialize();
void Shutdown();
PRBool mInitialized;
nsCOMPtr<nsIGenericFactory> mChromeRegistryFactory;
nsCOMPtr<nsIGenericFactory> mChromeProtocolHandlerFactory;
nsCOMPtr<nsIGenericFactory> mChromeEntryFactory;
};
//----------------------------------------------------------------------
// Functions used to create new instances of a given object by the
// generic factory.
//----------------------------------------------------------------------
nsChromeModule::nsChromeModule()
: mInitialized(PR_FALSE)
{
NS_INIT_ISUPPORTS();
}
nsChromeModule::~nsChromeModule()
{
Shutdown();
}
NS_IMPL_ISUPPORTS(nsChromeModule, NS_GET_IID(nsIModule))
// Perform our one-time intialization for this module
nsresult
nsChromeModule::Initialize()
{
if (mInitialized) {
return NS_OK;
}
mInitialized = PR_TRUE;
return NS_OK;
}
// Shutdown this module, releasing all of the module resources
void
nsChromeModule::Shutdown()
{
// Release the factory objects
mChromeRegistryFactory = nsnull;
mChromeProtocolHandlerFactory = nsnull;
mChromeEntryFactory = nsnull;
}
// Create a factory object for creating instances of aClass.
NS_IMETHODIMP
nsChromeModule::GetClassObject(nsIComponentManager *aCompMgr,
const nsCID& aClass,
const nsIID& aIID,
void** r_classObj)
{
nsresult rv;
// Defensive programming: Initialize *r_classObj in case of error below
if (!r_classObj) {
return NS_ERROR_INVALID_POINTER;
}
*r_classObj = NULL;
// Do one-time-only initialization if necessary
if (!mInitialized) {
rv = Initialize();
if (NS_FAILED(rv)) {
// Initialization failed! yikes!
return rv;
}
}
// Choose the appropriate factory, based on the desired instance
// class type (aClass).
nsCOMPtr<nsIGenericFactory> fact;
if (aClass.Equals(kChromeRegistryCID)) {
if (!mChromeRegistryFactory) {
// Create and save away the factory object for creating
// new instances of ChromeRegistry. This way if we are called
// again for the factory, we won't need to create a new
// one.
rv = NS_NewGenericFactory(getter_AddRefs(mChromeRegistryFactory),
NS_ConstructChromeRegistry);
}
fact = mChromeRegistryFactory;
}
else if (aClass.Equals(kChromeEntryCID)) {
if (!mChromeEntryFactory) {
// Create and save away the factory object for creating
// new instances of ChromeRegistry. This way if we are called
// again for the factory, we won't need to create a new
// one.
rv = NS_NewGenericFactory(getter_AddRefs(mChromeEntryFactory),
NS_ConstructChromeEntry);
}
fact = mChromeRegistryFactory;
}
else if (aClass.Equals(kChromeProtocolHandlerCID)) {
if (!mChromeProtocolHandlerFactory) {
// Create and save away the factory object for creating
// new instances of ChromeProtocolHandler. This way if we are called
// again for the factory, we won't need to create a new
// one.
rv = NS_NewGenericFactory(getter_AddRefs(mChromeProtocolHandlerFactory),
nsChromeProtocolHandler::Create);
}
fact = mChromeProtocolHandlerFactory;
}
else {
rv = NS_ERROR_FACTORY_NOT_REGISTERED;
#ifdef DEBUG
char* cs = aClass.ToString();
printf("+++ nsChromeModule: unable to create factory for %s\n", cs);
nsCRT::free(cs);
#endif
}
if (fact) {
rv = fact->QueryInterface(aIID, r_classObj);
}
return rv;
}
//----------------------------------------
struct Components {
const char* mDescription;
const nsID* mCID;
const char* mProgID;
};
// The list of components we register
static Components gComponents[] = {
{ "Chrome Registry", &kChromeRegistryCID,
"component://netscape/chrome/chrome-registry", },
{ "Chrome Entry", &kChromeEntryCID,
"component://netscape/chrome/chrome-entry", },
{ "Chrome Protocol Handler", &kChromeProtocolHandlerCID,
NS_NETWORK_PROTOCOL_PROGID_PREFIX "chrome", },
static nsModuleComponentInfo components[] =
{
{ "Chrome Registry",
NS_CHROMEREGISTRY_CID,
"component://netscape/chrome/chrome-registry",
NS_ConstructChromeRegistry
},
{ "Chrome Entry",
NS_CHROMEENTRY_CID,
"component://netscape/chrome/chrome-entry",
NS_ConstructChromeEntry
},
{ "Chrome Protocol Handler",
NS_CHROMEPROTOCOLHANDLER_CID,
NS_NETWORK_PROTOCOL_PROGID_PREFIX "chrome",
nsChromeProtocolHandler::Create
},
};
#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0]))
NS_IMETHODIMP
nsChromeModule::RegisterSelf(nsIComponentManager *aCompMgr,
nsIFileSpec* aPath,
const char* registryLocation,
const char* componentType)
{
nsresult rv = NS_OK;
NS_IMPL_NSGETMODULE("nsChromeModule", components);
#ifdef DEBUG
printf("*** Registering chrome components\n");
#endif
Components* cp = gComponents;
Components* end = cp + NUM_COMPONENTS;
while (cp < end) {
rv = aCompMgr->RegisterComponentSpec(*cp->mCID, cp->mDescription,
cp->mProgID, aPath, PR_TRUE,
PR_TRUE);
if (NS_FAILED(rv)) {
#ifdef DEBUG
printf("nsChromeModule: unable to register %s component => %x\n",
cp->mDescription, rv);
#endif
break;
}
cp++;
}
return rv;
}
NS_IMETHODIMP
nsChromeModule::UnregisterSelf(nsIComponentManager* aCompMgr,
nsIFileSpec* aPath,
const char* registryLocation)
{
#ifdef DEBUG
printf("*** Unregistering chrome components\n");
#endif
Components* cp = gComponents;
Components* end = cp + NUM_COMPONENTS;
while (cp < end) {
nsresult rv = aCompMgr->UnregisterComponentSpec(*cp->mCID, aPath);
if (NS_FAILED(rv)) {
#ifdef DEBUG
printf("nsChromeModule: unable to unregister %s component => %x\n",
cp->mDescription, rv);
#endif
}
cp++;
}
return NS_OK;
}
NS_IMETHODIMP
nsChromeModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload)
{
if (!okToUnload) {
return NS_ERROR_INVALID_POINTER;
}
*okToUnload = PR_FALSE;
return NS_ERROR_FAILURE;
}
//----------------------------------------------------------------------
static nsChromeModule *gModule = NULL;
extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr,
nsIFileSpec* location,
nsIModule** return_cobj)
{
nsresult rv = NS_OK;
NS_ENSURE_ARG_POINTER(return_cobj);
NS_ENSURE_FALSE(gModule, NS_ERROR_FAILURE);
// Create and initialize the module instance
nsChromeModule *m = new nsChromeModule();
if (!m) {
return NS_ERROR_OUT_OF_MEMORY;
}
// Increase refcnt and store away nsIModule interface to m in return_cobj
rv = m->QueryInterface(NS_GET_IID(nsIModule), (void**)return_cobj);
if (NS_FAILED(rv)) {
delete m;
m = nsnull;
}
gModule = m; // WARNING: Weak Reference
return rv;
}