diff --git a/mozilla/modules/libjar/nsJARProtocolModule.cpp b/mozilla/modules/libjar/nsJARProtocolModule.cpp index 25eb97e2601..96ada9eb6f6 100644 --- a/mozilla/modules/libjar/nsJARProtocolModule.cpp +++ b/mozilla/modules/libjar/nsJARProtocolModule.cpp @@ -19,226 +19,20 @@ * * Contributor(s): */ -#include "nsCOMPtr.h" #include "nsIModule.h" #include "nsIGenericFactory.h" -#include "nsIComponentManager.h" -#include "nsIServiceManager.h" #include "nsJARProtocolHandler.h" -#include "nscore.h" -static NS_DEFINE_CID(kJARProtocolHandlerCID, NS_JARPROTOCOLHANDLER_CID); -/////////////////////////////////////////////////////////////////////////////// - -class nsJARProtocolModule : public nsIModule +static nsModuleComponentInfo components[] = { -public: - nsJARProtocolModule(); - virtual ~nsJARProtocolModule(); - - NS_DECL_ISUPPORTS - - NS_DECL_NSIMODULE - -protected: - nsresult Initialize(); - - void Shutdown(); - - PRBool mInitialized; - nsCOMPtr mProtocolHandlerFactory; + { "JAR Protocol Handler", + NS_JARPROTOCOLHANDLER_CID, + NS_NETWORK_PROTOCOL_PROGID_PREFIX "jar", + nsJARProtocolHandler::Create + }, }; -static NS_DEFINE_IID(kIModuleIID, NS_IMODULE_IID); +NS_IMPL_NSGETMODULE("nsJarProtocolModule", components); -nsJARProtocolModule::nsJARProtocolModule() - : mInitialized(PR_FALSE) -{ - NS_INIT_ISUPPORTS(); -} -nsJARProtocolModule::~nsJARProtocolModule() -{ - Shutdown(); -} - -NS_IMPL_ISUPPORTS(nsJARProtocolModule, kIModuleIID) - -// Perform our one-time intialization for this module -nsresult -nsJARProtocolModule::Initialize() -{ - if (mInitialized) { - return NS_OK; - } - mInitialized = PR_TRUE; - return NS_OK; -} - -// Shutdown this module, releasing all of the module resources -void -nsJARProtocolModule::Shutdown() -{ - // Release the factory object - mProtocolHandlerFactory = nsnull; -} - -// Create a factory object for creating instances of aClass. -NS_IMETHODIMP -nsJARProtocolModule::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 fact; - if (aClass.Equals(kJARProtocolHandlerCID)) { - if (!mProtocolHandlerFactory) { - rv = NS_NewGenericFactory(getter_AddRefs(mProtocolHandlerFactory), - nsJARProtocolHandler::Create); - } - fact = mProtocolHandlerFactory; - } - else { - rv = NS_ERROR_FACTORY_NOT_REGISTERED; -#ifdef DEBUG - char* cs = aClass.ToString(); - printf("+++ nsJARProtocolModule: 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[] = { - { "JAR Protocol Handler", &kJARProtocolHandlerCID, - NS_NETWORK_PROTOCOL_PROGID_PREFIX "jar", }, -}; -#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0])) - -NS_IMETHODIMP -nsJARProtocolModule::RegisterSelf(nsIComponentManager *aCompMgr, - nsIFileSpec* aPath, - const char* registryLocation, - const char* componentType) -{ - nsresult rv = NS_OK; - -#ifdef DEBUG - printf("*** Registering jar: 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("nsJARProtocolModule: unable to register %s component => %x\n", - cp->mDescription, rv); -#endif - break; - } - cp++; - } - - return rv; -} - -NS_IMETHODIMP -nsJARProtocolModule::UnregisterSelf(nsIComponentManager* aCompMgr, - nsIFileSpec* aPath, - const char* registryLocation) -{ -#ifdef DEBUG - printf("*** Unregistering jar: 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("nsJARProtocolModule: unable to unregister %s component => %x\n", - cp->mDescription, rv); -#endif - } - cp++; - } - - return NS_OK; -} - -NS_IMETHODIMP -nsJARProtocolModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload) -{ - if (!okToUnload) { - return NS_ERROR_INVALID_POINTER; - } - *okToUnload = PR_FALSE; - return NS_ERROR_FAILURE; -} - -//---------------------------------------------------------------------- - -static nsJARProtocolModule *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, "nsJARProtocolModule: Module already created."); - - // Create and initialize the module instance - nsJARProtocolModule *m = new nsJARProtocolModule(); - 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; -} diff --git a/mozilla/netwerk/protocol/jar/src/nsJARProtocolModule.cpp b/mozilla/netwerk/protocol/jar/src/nsJARProtocolModule.cpp index 25eb97e2601..96ada9eb6f6 100644 --- a/mozilla/netwerk/protocol/jar/src/nsJARProtocolModule.cpp +++ b/mozilla/netwerk/protocol/jar/src/nsJARProtocolModule.cpp @@ -19,226 +19,20 @@ * * Contributor(s): */ -#include "nsCOMPtr.h" #include "nsIModule.h" #include "nsIGenericFactory.h" -#include "nsIComponentManager.h" -#include "nsIServiceManager.h" #include "nsJARProtocolHandler.h" -#include "nscore.h" -static NS_DEFINE_CID(kJARProtocolHandlerCID, NS_JARPROTOCOLHANDLER_CID); -/////////////////////////////////////////////////////////////////////////////// - -class nsJARProtocolModule : public nsIModule +static nsModuleComponentInfo components[] = { -public: - nsJARProtocolModule(); - virtual ~nsJARProtocolModule(); - - NS_DECL_ISUPPORTS - - NS_DECL_NSIMODULE - -protected: - nsresult Initialize(); - - void Shutdown(); - - PRBool mInitialized; - nsCOMPtr mProtocolHandlerFactory; + { "JAR Protocol Handler", + NS_JARPROTOCOLHANDLER_CID, + NS_NETWORK_PROTOCOL_PROGID_PREFIX "jar", + nsJARProtocolHandler::Create + }, }; -static NS_DEFINE_IID(kIModuleIID, NS_IMODULE_IID); +NS_IMPL_NSGETMODULE("nsJarProtocolModule", components); -nsJARProtocolModule::nsJARProtocolModule() - : mInitialized(PR_FALSE) -{ - NS_INIT_ISUPPORTS(); -} -nsJARProtocolModule::~nsJARProtocolModule() -{ - Shutdown(); -} - -NS_IMPL_ISUPPORTS(nsJARProtocolModule, kIModuleIID) - -// Perform our one-time intialization for this module -nsresult -nsJARProtocolModule::Initialize() -{ - if (mInitialized) { - return NS_OK; - } - mInitialized = PR_TRUE; - return NS_OK; -} - -// Shutdown this module, releasing all of the module resources -void -nsJARProtocolModule::Shutdown() -{ - // Release the factory object - mProtocolHandlerFactory = nsnull; -} - -// Create a factory object for creating instances of aClass. -NS_IMETHODIMP -nsJARProtocolModule::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 fact; - if (aClass.Equals(kJARProtocolHandlerCID)) { - if (!mProtocolHandlerFactory) { - rv = NS_NewGenericFactory(getter_AddRefs(mProtocolHandlerFactory), - nsJARProtocolHandler::Create); - } - fact = mProtocolHandlerFactory; - } - else { - rv = NS_ERROR_FACTORY_NOT_REGISTERED; -#ifdef DEBUG - char* cs = aClass.ToString(); - printf("+++ nsJARProtocolModule: 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[] = { - { "JAR Protocol Handler", &kJARProtocolHandlerCID, - NS_NETWORK_PROTOCOL_PROGID_PREFIX "jar", }, -}; -#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0])) - -NS_IMETHODIMP -nsJARProtocolModule::RegisterSelf(nsIComponentManager *aCompMgr, - nsIFileSpec* aPath, - const char* registryLocation, - const char* componentType) -{ - nsresult rv = NS_OK; - -#ifdef DEBUG - printf("*** Registering jar: 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("nsJARProtocolModule: unable to register %s component => %x\n", - cp->mDescription, rv); -#endif - break; - } - cp++; - } - - return rv; -} - -NS_IMETHODIMP -nsJARProtocolModule::UnregisterSelf(nsIComponentManager* aCompMgr, - nsIFileSpec* aPath, - const char* registryLocation) -{ -#ifdef DEBUG - printf("*** Unregistering jar: 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("nsJARProtocolModule: unable to unregister %s component => %x\n", - cp->mDescription, rv); -#endif - } - cp++; - } - - return NS_OK; -} - -NS_IMETHODIMP -nsJARProtocolModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload) -{ - if (!okToUnload) { - return NS_ERROR_INVALID_POINTER; - } - *okToUnload = PR_FALSE; - return NS_ERROR_FAILURE; -} - -//---------------------------------------------------------------------- - -static nsJARProtocolModule *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, "nsJARProtocolModule: Module already created."); - - // Create and initialize the module instance - nsJARProtocolModule *m = new nsJARProtocolModule(); - 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; -} diff --git a/mozilla/netwerk/protocol/resource/src/nsResourceProtocolModule.cpp b/mozilla/netwerk/protocol/resource/src/nsResourceProtocolModule.cpp index 304da3c6462..d03d95cea68 100644 --- a/mozilla/netwerk/protocol/resource/src/nsResourceProtocolModule.cpp +++ b/mozilla/netwerk/protocol/resource/src/nsResourceProtocolModule.cpp @@ -19,225 +19,18 @@ * * Contributor(s): */ -#include "nsCOMPtr.h" #include "nsIModule.h" #include "nsIGenericFactory.h" -#include "nsIComponentManager.h" -#include "nsIServiceManager.h" #include "nsResourceProtocolHandler.h" -#include "nscore.h" - -static NS_DEFINE_CID(kResourceProtocolHandlerCID, NS_RESOURCEPROTOCOLHANDLER_CID); - -// Module implementation for the resource protocol library -class nsResourceProtocolModule : public nsIModule -{ -public: - nsResourceProtocolModule(); - virtual ~nsResourceProtocolModule(); - - NS_DECL_ISUPPORTS - - NS_DECL_NSIMODULE - -protected: - nsresult Initialize(); - - void Shutdown(); - - PRBool mInitialized; - nsCOMPtr mFactory; -}; - -static NS_DEFINE_IID(kIModuleIID, NS_IMODULE_IID); - -nsResourceProtocolModule::nsResourceProtocolModule() - : mInitialized(PR_FALSE) -{ - NS_INIT_ISUPPORTS(); -} - -nsResourceProtocolModule::~nsResourceProtocolModule() -{ - Shutdown(); -} - -NS_IMPL_ISUPPORTS(nsResourceProtocolModule, kIModuleIID) - -// Perform our one-time intialization for this module -nsresult -nsResourceProtocolModule::Initialize() -{ - if (mInitialized) { - return NS_OK; - } - mInitialized = PR_TRUE; - return NS_OK; -} - -// Shutdown this module, releasing all of the module resources -void -nsResourceProtocolModule::Shutdown() -{ - // Release the factory object - mFactory = nsnull; -} - -// Create a factory object for creating instances of aClass. -NS_IMETHODIMP -nsResourceProtocolModule::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 fact; - if (aClass.Equals(kResourceProtocolHandlerCID)) { - if (!mFactory) { - rv = NS_NewGenericFactory(getter_AddRefs(mFactory), - nsResourceProtocolHandler::Create); - } - fact = mFactory; - } - else { - rv = NS_ERROR_FACTORY_NOT_REGISTERED; -#ifdef DEBUG - char* cs = aClass.ToString(); - printf("+++ nsResourceProtocolModule: 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[] = { - { "Resource Protocol Handler", &kResourceProtocolHandlerCID, - NS_NETWORK_PROTOCOL_PROGID_PREFIX "res", }, +static nsModuleComponentInfo components[] = +{ + { "Resource Protocol Handler", + NS_RESOURCEPROTOCOLHANDLER_CID, + NS_NETWORK_PROTOCOL_PROGID_PREFIX "res", + nsResourceProtocolHandler::Create}, }; -#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0])) -NS_IMETHODIMP -nsResourceProtocolModule::RegisterSelf(nsIComponentManager *aCompMgr, - nsIFileSpec* aPath, - const char* registryLocation, - const char* componentType) -{ - nsresult rv = NS_OK; +NS_IMPL_NSGETMODULE("nsResourceProtocolModule", components); -#ifdef DEBUG - printf("*** Registering resource: 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("nsResourceProtocolModule: unable to register %s component => %x\n", - cp->mDescription, rv); -#endif - break; - } - cp++; - } - - return rv; -} - -NS_IMETHODIMP -nsResourceProtocolModule::UnregisterSelf(nsIComponentManager* aCompMgr, - nsIFileSpec* aPath, - const char* registryLocation) -{ -#ifdef DEBUG - printf("*** Unregistering resource: 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("nsResourceProtocolModule: unable to unregister %s component => %x\n", - cp->mDescription, rv); -#endif - } - cp++; - } - - return NS_OK; -} - -NS_IMETHODIMP -nsResourceProtocolModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload) -{ - if (!okToUnload) { - return NS_ERROR_INVALID_POINTER; - } - *okToUnload = PR_FALSE; - return NS_ERROR_FAILURE; -} - -//---------------------------------------------------------------------- - -static nsResourceProtocolModule *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, "nsResourceProtocolModule: Module already created."); - - // Create and initialize the module instance - nsResourceProtocolModule *m = new nsResourceProtocolModule(); - 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; -}