зеркало из https://github.com/mozilla/gecko-dev.git
Converting to use nsIModule macro. r=dp.
This commit is contained in:
Родитель
5a0b3e6330
Коммит
2e995c5f17
|
@ -29,8 +29,6 @@
|
|||
#include "nsIPrincipal.h"
|
||||
#include "nsCodebasePrincipal.h"
|
||||
|
||||
|
||||
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsCodebasePrincipal)
|
||||
|
||||
static NS_IMETHODIMP
|
||||
|
@ -50,254 +48,22 @@ Construct_nsIScriptSecurityManager(nsISupports *aOuter, REFNSIID aIID,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Module implementation
|
||||
class nsSecurityManagerModule : public nsIModule
|
||||
static nsModuleComponentInfo components[] =
|
||||
{
|
||||
public:
|
||||
nsSecurityManagerModule();
|
||||
virtual ~nsSecurityManagerModule();
|
||||
{ NS_SCRIPTSECURITYMANAGER_CLASSNAME,
|
||||
NS_SCRIPTSECURITYMANAGER_CID,
|
||||
NS_SCRIPTSECURITYMANAGER_PROGID,
|
||||
Construct_nsIScriptSecurityManager
|
||||
},
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_DECL_NSIMODULE
|
||||
|
||||
protected:
|
||||
nsresult Initialize();
|
||||
|
||||
void Shutdown();
|
||||
|
||||
PRBool mInitialized;
|
||||
nsCOMPtr<nsIGenericFactory> mScriptSecurityManagerFactory;
|
||||
nsCOMPtr<nsIGenericFactory> mCodebasePrincipalFactory;
|
||||
{ NS_CODEBASEPRINCIPAL_CLASSNAME,
|
||||
NS_CODEBASEPRINCIPAL_CID,
|
||||
NS_CODEBASEPRINCIPAL_PROGID,
|
||||
nsCodebasePrincipalConstructor
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
nsSecurityManagerModule::nsSecurityManagerModule()
|
||||
: mInitialized(PR_FALSE)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
||||
nsSecurityManagerModule::~nsSecurityManagerModule()
|
||||
{
|
||||
Shutdown();
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsSecurityManagerModule, NS_GET_IID(nsIModule))
|
||||
|
||||
|
||||
|
||||
// Perform our one-time intialization for this module
|
||||
nsresult
|
||||
nsSecurityManagerModule::Initialize()
|
||||
{
|
||||
if (mInitialized) {
|
||||
return NS_OK;
|
||||
}
|
||||
mInitialized = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Shutdown this module, releasing all of the module resources
|
||||
void
|
||||
nsSecurityManagerModule::Shutdown()
|
||||
{
|
||||
// XXX FIX this: nsScriptSecurityManager::GetScriptSecurityManager() leaks!
|
||||
|
||||
// Release the factory object
|
||||
mScriptSecurityManagerFactory = nsnull;
|
||||
mCodebasePrincipalFactory = nsnull;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Create a factory object for creating instances of aClass.
|
||||
NS_IMETHODIMP
|
||||
nsSecurityManagerModule::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;
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIGenericFactory> fact;
|
||||
|
||||
// Choose the appropriate factory, based on the desired instance
|
||||
// class type (aClass).
|
||||
if (aClass.Equals(nsScriptSecurityManager::GetCID()))
|
||||
{
|
||||
if (!mScriptSecurityManagerFactory) {
|
||||
rv = NS_NewGenericFactory(getter_AddRefs(mScriptSecurityManagerFactory),
|
||||
Construct_nsIScriptSecurityManager);
|
||||
}
|
||||
fact = mScriptSecurityManagerFactory;
|
||||
}
|
||||
else if (aClass.Equals(nsCodebasePrincipal::GetCID()))
|
||||
{
|
||||
if (!mCodebasePrincipalFactory) {
|
||||
rv = NS_NewGenericFactory(getter_AddRefs(mCodebasePrincipalFactory),
|
||||
nsCodebasePrincipalConstructor);
|
||||
}
|
||||
fact = mCodebasePrincipalFactory;
|
||||
}
|
||||
else {
|
||||
rv = NS_ERROR_FACTORY_NOT_REGISTERED;
|
||||
#ifdef DEBUG
|
||||
char* cs = aClass.ToString();
|
||||
printf("+++ nsSecurityManagerModule: 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[] = {
|
||||
{ "Script Security Manager", &nsScriptSecurityManager::GetCID(), NS_SCRIPTSECURITYMANAGER_PROGID },
|
||||
{ "Codebase Principal", &nsCodebasePrincipal::GetCID(), NS_CODEBASEPRINCIPAL_PROGID }
|
||||
};
|
||||
#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0]))
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSecurityManagerModule::RegisterSelf(nsIComponentManager *aCompMgr,
|
||||
nsIFileSpec* aPath,
|
||||
const char* registryLocation,
|
||||
const char* componentType)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("*** Registering nsSecurityManagerModule\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("nsSecurityManagerModule: unable to register %s component => %x\n",
|
||||
cp->mDescription, rv);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
cp++;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSecurityManagerModule::UnregisterSelf(nsIComponentManager* aCompMgr,
|
||||
nsIFileSpec* aPath,
|
||||
const char* registryLocation)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
printf("*** Unregistering nsSecurityManagerModule\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("nsSecurityManagerModule: unable to unregister %s component => %x\n",
|
||||
cp->mDescription, rv);
|
||||
#endif
|
||||
}
|
||||
cp++;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSecurityManagerModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload)
|
||||
{
|
||||
if (!okToUnload) {
|
||||
return NS_ERROR_INVALID_POINTER;
|
||||
}
|
||||
*okToUnload = PR_FALSE;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
static nsSecurityManagerModule *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
|
||||
nsSecurityManagerModule *m = new nsSecurityManagerModule();
|
||||
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("nsSecurityManagerModule", components);
|
||||
|
||||
|
||||
|
|
|
@ -39,192 +39,21 @@ public:
|
|||
|
||||
};
|
||||
|
||||
|
||||
// include files for components this factory creates...
|
||||
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
|
||||
static NS_DEFINE_CID(kCMorkFactory, NS_MORK_CID);
|
||||
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMorkFactoryFactory)
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
class nsMorkModule : public nsIModule
|
||||
{
|
||||
public:
|
||||
|
||||
nsMorkModule();
|
||||
virtual ~nsMorkModule();
|
||||
|
||||
// nsISupports methods
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_DECL_NSIMODULE
|
||||
|
||||
protected:
|
||||
nsresult Initialize();
|
||||
|
||||
void Shutdown();
|
||||
|
||||
PRBool mInitialized;
|
||||
nsCOMPtr<nsIGenericFactory> mMorkFactory;
|
||||
};
|
||||
|
||||
nsMorkModule::nsMorkModule()
|
||||
: mInitialized(PR_FALSE)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsMorkModule, NS_GET_IID(nsIModule))
|
||||
|
||||
nsMorkModule::~nsMorkModule()
|
||||
static nsModuleComponentInfo components[] =
|
||||
{
|
||||
Shutdown();
|
||||
}
|
||||
|
||||
// Perform our one-time intialization for this module
|
||||
nsresult nsMorkModule::Initialize()
|
||||
{
|
||||
if (mInitialized)
|
||||
return NS_OK;
|
||||
|
||||
mInitialized = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Shutdown this module, releasing all of the module resources
|
||||
void nsMorkModule::Shutdown()
|
||||
{
|
||||
// Release the factory objects
|
||||
mMorkFactory = null_nsCOMPtr();
|
||||
}
|
||||
|
||||
// Create a factory object for creating instances of aClass.
|
||||
NS_IMETHODIMP nsMorkModule::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;
|
||||
{ "Mork Factory",
|
||||
NS_MORK_CID,
|
||||
nsnull,
|
||||
nsMorkFactoryFactoryConstructor
|
||||
}
|
||||
|
||||
// Choose the appropriate factory, based on the desired instance
|
||||
// class type (aClass).
|
||||
nsCOMPtr<nsIGenericFactory> fact;
|
||||
|
||||
if (aClass.Equals(kCMorkFactory))
|
||||
{
|
||||
if (!mMorkFactory)
|
||||
rv = NS_NewGenericFactory(getter_AddRefs(mMorkFactory), &nsMorkFactoryFactoryConstructor);
|
||||
fact = mMorkFactory;
|
||||
}
|
||||
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[] = {
|
||||
{ "Mork Factory", &kCMorkFactory,
|
||||
nsnull },
|
||||
};
|
||||
#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0]))
|
||||
NS_IMPL_NSGETMODULE("nsMorkModule", components);
|
||||
|
||||
NS_IMETHODIMP nsMorkModule::RegisterSelf(nsIComponentManager *aCompMgr,
|
||||
nsIFileSpec* aPath,
|
||||
const char* registryLocation,
|
||||
const char* componentType)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
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))
|
||||
break;
|
||||
cp++;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMorkModule::UnregisterSelf(nsIComponentManager* aCompMgr,
|
||||
nsIFileSpec* aPath,
|
||||
const char* registryLocation)
|
||||
{
|
||||
Components* cp = gComponents;
|
||||
Components* end = cp + NUM_COMPONENTS;
|
||||
while (cp < end)
|
||||
{
|
||||
aCompMgr->UnregisterComponentSpec(*cp->mCID, aPath);
|
||||
cp++;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMorkModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload)
|
||||
{
|
||||
if (!okToUnload)
|
||||
return NS_ERROR_INVALID_POINTER;
|
||||
|
||||
*okToUnload = PR_FALSE;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
static nsMorkModule *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, "nsMorkModule: Module already created.");
|
||||
|
||||
// Create an initialize the imap module instance
|
||||
nsMorkModule *module = new nsMorkModule();
|
||||
if (!module)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
// Increase refcnt and store away nsIModule interface to m in return_cobj
|
||||
rv = module->QueryInterface(nsIModule::GetIID(), (void**)return_cobj);
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
delete module;
|
||||
module = nsnull;
|
||||
}
|
||||
gModule = module; // WARNING: Weak Reference
|
||||
return rv;
|
||||
}
|
||||
|
||||
static nsIMdbFactory *gMDBFactory = nsnull;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче