Converted wallet.dll and wlltvwrs.dll to use nsIModule to prepare for memory leaks fixing. Bug# 14034. r=morse

This commit is contained in:
neeti%netscape.com 1999-10-06 04:42:59 +00:00
Родитель 606f3b77ab
Коммит fbfc9e36a9
2 изменённых файлов: 544 добавлений и 321 удалений

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

@ -21,6 +21,8 @@
#include "nsISupports.h"
#include "nsIServiceManager.h"
#include "nsCOMPtr.h"
#include "nsIModule.h"
#include "nsIGenericFactory.h"
#include "nsIWalletPreview.h"
#include "nsISignonViewer.h"
@ -36,221 +38,367 @@ static NS_DEFINE_CID(kSignonViewerCID, NS_SIGNONVIEWER_CID);
static NS_DEFINE_CID(kCookieViewerCID, NS_COOKIEVIEWER_CID);
static NS_DEFINE_CID(kWalletEditorCID, NS_WALLETEDITOR_CID);
class nsWalletViewerFactory : public nsIFactory
{
public:
// nsISupports methods
NS_IMETHOD QueryInterface(const nsIID &aIID,
void **aResult);
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
// nsIFactory methods
NS_IMETHOD CreateInstance(nsISupports *aOuter,
const nsIID &aIID,
void **aResult);
// Module implementation
class nsWalletViewerModule : public nsIModule
{
public:
nsWalletViewerModule();
virtual ~nsWalletViewerModule();
NS_IMETHOD LockFactory(PRBool aLock);
NS_DECL_ISUPPORTS
nsWalletViewerFactory(const nsCID &aClass);
NS_DECL_NSIMODULE
protected:
virtual ~nsWalletViewerFactory();
nsresult Initialize();
private:
nsrefcnt mRefCnt;
nsCID mClassID;
};
void Shutdown();
nsWalletViewerFactory::nsWalletViewerFactory(const nsCID &aClass)
{
mRefCnt = 0;
mClassID = aClass;
}
PRBool mInitialized;
nsCOMPtr<nsIGenericFactory> mWalletPreviewFactory;
nsCOMPtr<nsIGenericFactory> mSignonViewerFactory;
nsCOMPtr<nsIGenericFactory> mCookieViewerFactory;
nsCOMPtr<nsIGenericFactory> mWalletEditorFactory;
};
nsWalletViewerFactory::~nsWalletViewerFactory()
{
NS_ASSERTION(mRefCnt == 0, "non-zero refcnt at destruction");
}
//----------------------------------------------------------------------
// Functions used to create new instances of a given object by the
// generic factory.
static NS_IMETHODIMP
CreateNewWalletPreview(nsISupports* aOuter, REFNSIID aIID, void **aResult)
{
if (!aResult) {
return NS_ERROR_INVALID_POINTER;
}
if (aOuter) {
*aResult = nsnull;
return NS_ERROR_NO_AGGREGATION;
}
nsIWalletPreview* inst = nsnull;
nsresult rv = NS_NewWalletPreview(&inst);
if (NS_FAILED(rv)) {
*aResult = nsnull;
return rv;
}
rv = inst->QueryInterface(aIID, aResult);
if (NS_FAILED(rv)) {
*aResult = nsnull;
}
NS_RELEASE(inst); /* get rid of extra refcnt */
return rv;
}
static NS_IMETHODIMP
CreateNewSignonViewer(nsISupports* aOuter, REFNSIID aIID, void **aResult)
{
if (!aResult) {
return NS_ERROR_INVALID_POINTER;
}
if (aOuter) {
*aResult = nsnull;
return NS_ERROR_NO_AGGREGATION;
}
nsISignonViewer* inst = nsnull;
nsresult rv = NS_NewSignonViewer(&inst);
if (NS_FAILED(rv)) {
*aResult = nsnull;
return rv;
}
rv = inst->QueryInterface(aIID, aResult);
if (NS_FAILED(rv)) {
*aResult = nsnull;
}
NS_RELEASE(inst); /* get rid of extra refcnt */
return rv;
}
static NS_IMETHODIMP
CreateNewCookieViewer(nsISupports* aOuter, REFNSIID aIID, void **aResult)
{
if (!aResult) {
return NS_ERROR_INVALID_POINTER;
}
if (aOuter) {
*aResult = nsnull;
return NS_ERROR_NO_AGGREGATION;
}
nsICookieViewer* inst = nsnull;
nsresult rv = NS_NewCookieViewer(&inst);
if (NS_FAILED(rv)) {
*aResult = nsnull;
return rv;
}
rv = inst->QueryInterface(aIID, aResult);
if (NS_FAILED(rv)) {
*aResult = nsnull;
}
NS_RELEASE(inst); /* get rid of extra refcnt */
return rv;
}
static NS_IMETHODIMP
CreateNewWalletEditor(nsISupports* aOuter, REFNSIID aIID, void **aResult)
{
if (!aResult) {
return NS_ERROR_INVALID_POINTER;
}
if (aOuter) {
*aResult = nsnull;
return NS_ERROR_NO_AGGREGATION;
}
nsIWalletEditor* inst = nsnull;
nsresult rv = NS_NewWalletEditor(&inst);
if (NS_FAILED(rv)) {
*aResult = nsnull;
return rv;
}
rv = inst->QueryInterface(aIID, aResult);
if (NS_FAILED(rv)) {
*aResult = nsnull;
}
NS_RELEASE(inst); /* get rid of extra refcnt */
return rv;
}
//----------------------------------------------------------------------
nsWalletViewerModule::nsWalletViewerModule()
: mInitialized(PR_FALSE)
{
NS_INIT_ISUPPORTS();
}
nsWalletViewerModule::~nsWalletViewerModule()
{
Shutdown();
}
NS_IMPL_ISUPPORTS(nsWalletViewerModule, NS_GET_IID(nsIModule))
// Perform our one-time intialization for this module
nsresult
nsWalletViewerFactory::QueryInterface(const nsIID &aIID, void **aResult)
{
if (aResult == NULL) {
return NS_ERROR_NULL_POINTER;
}
// Always NULL result, in case of failure
*aResult = NULL;
if (aIID.Equals(kISupportsIID)) {
*aResult = (void *)(nsISupports*)this;
} else if (aIID.Equals(kIFactoryIID)) {
*aResult = (void *)(nsIFactory*)this;
}
if (*aResult == NULL) {
return NS_NOINTERFACE;
}
AddRef(); // Increase reference count for caller
return NS_OK;
}
nsrefcnt
nsWalletViewerFactory::AddRef()
{
return ++mRefCnt;
}
nsrefcnt
nsWalletViewerFactory::Release()
{
if (--mRefCnt == 0) {
delete this;
return 0; // Don't access mRefCnt after deleting!
}
return mRefCnt;
}
nsresult
nsWalletViewerFactory::CreateInstance(nsISupports *aOuter,
const nsIID &aIID,
void **aResult)
{
nsresult res;
PRBool refCounted = PR_TRUE;
if (aResult == NULL) {
return NS_ERROR_NULL_POINTER;
}
*aResult = NULL;
nsISupports *inst = nsnull;
if (mClassID.Equals(kWalletPreviewCID)) {
if (NS_FAILED(res = NS_NewWalletPreview((nsIWalletPreview**) &inst)))
return res;
}
else if (mClassID.Equals(kSignonViewerCID)) {
if (NS_FAILED(res = NS_NewSignonViewer((nsISignonViewer**) &inst)))
return res;
}
else if (mClassID.Equals(kCookieViewerCID)) {
if (NS_FAILED(res = NS_NewCookieViewer((nsICookieViewer**) &inst)))
return res;
}
else if (mClassID.Equals(kWalletEditorCID)) {
if (NS_FAILED(res = NS_NewWalletEditor((nsIWalletEditor**) &inst)))
return res;
}
else {
return NS_ERROR_NO_INTERFACE;
}
if (inst == NULL) {
return NS_ERROR_OUT_OF_MEMORY;
}
res = inst->QueryInterface(aIID, aResult);
if (refCounted) {
NS_RELEASE(inst);
}
else if (res != NS_OK) {
// We didn't get the right interface, so clean up
delete inst;
}
return res;
}
nsresult nsWalletViewerFactory::LockFactory(PRBool aLock)
{
// Not implemented in simplest case.
return NS_OK;
}
////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////
extern "C" PR_IMPLEMENT(nsresult)
NSGetFactory(nsISupports* serviceMgr,
const nsCID &aClass,
const char *aClassName,
const char *aProgID,
nsIFactory **aFactory)
nsWalletViewerModule::Initialize()
{
if (nsnull == aFactory) {
return NS_ERROR_NULL_POINTER;
}
*aFactory = new nsWalletViewerFactory(aClass);
if (nsnull == aFactory) {
return NS_ERROR_OUT_OF_MEMORY;
}
return (*aFactory)->QueryInterface(kIFactoryIID, (void**)aFactory);
if (mInitialized) {
return NS_OK;
}
mInitialized = PR_TRUE;
return NS_OK;
}
extern "C" PR_IMPLEMENT(nsresult)
NSRegisterSelf(nsISupports* aServMgr , const char* aPath)
// Shutdown this module, releasing all of the module resources
void
nsWalletViewerModule::Shutdown()
{
nsresult rv = NS_OK;
nsCOMPtr<nsIServiceManager> servMgr(do_QueryInterface(aServMgr, &rv));
if (NS_FAILED(rv)) return rv;
NS_WITH_SERVICE(nsIComponentManager, compMgr, kComponentManagerCID, &rv);
if (NS_FAILED(rv)) return rv;
rv = compMgr->RegisterComponent(kWalletPreviewCID,
"WalletPreview World Component",
"component://netscape/walletpreview/walletpreview-world",
aPath, PR_TRUE, PR_TRUE);
rv = compMgr->RegisterComponent(kSignonViewerCID,
"SignonViewer World Component",
"component://netscape/signonviewer/signonviewer-world",
aPath, PR_TRUE, PR_TRUE);
rv = compMgr->RegisterComponent(kCookieViewerCID,
"CookieViewer World Component",
"component://netscape/cookieviewer/cookieviewer-world",
aPath, PR_TRUE, PR_TRUE);
rv = compMgr->RegisterComponent(kWalletEditorCID,
"WalletEditor World Component",
"component://netscape/walleteditor/walleteditor-world",
aPath, PR_TRUE, PR_TRUE);
return NS_OK;
// Release the factory objects
mWalletPreviewFactory = nsnull;
mSignonViewerFactory = nsnull;
mCookieViewerFactory = nsnull;
mWalletEditorFactory = nsnull;
}
extern "C" PR_IMPLEMENT(nsresult)
NSUnregisterSelf(nsISupports* aServMgr, const char* aPath)
// Create a factory object for creating instances of aClass.
NS_IMETHODIMP
nsWalletViewerModule::GetClassObject(nsIComponentManager *aCompMgr,
const nsCID& aClass,
const nsIID& aIID,
void** r_classObj)
{
nsresult rv;
nsresult rv;
// Defensive programming: Initialize *r_classObj in case of error below
if (!r_classObj) {
return NS_ERROR_INVALID_POINTER;
}
*r_classObj = NULL;
nsCOMPtr<nsIServiceManager> servMgr(do_QueryInterface(aServMgr, &rv));
if (NS_FAILED(rv)) return rv;
// Do one-time-only initialization if necessary
if (!mInitialized) {
rv = Initialize();
if (NS_FAILED(rv)) {
// Initialization failed! yikes!
return rv;
}
}
NS_WITH_SERVICE(nsIComponentManager, compMgr, kComponentManagerCID, &rv);
if (NS_FAILED(rv)) return rv;
// Choose the appropriate factory, based on the desired instance
// class type (aClass).
nsCOMPtr<nsIGenericFactory> fact;
if (aClass.Equals(kWalletPreviewCID)) {
if (!mWalletPreviewFactory) {
// Create and save away the factory object for creating
// new instances of WalletPreview. This way if we are called
// again for the factory, we won't need to create a new
// one.
rv = NS_NewGenericFactory(getter_AddRefs(mWalletPreviewFactory),
CreateNewWalletPreview);
}
fact = mWalletPreviewFactory;
}
else if (aClass.Equals(kSignonViewerCID)) {
if (!mSignonViewerFactory) {
// Create and save away the factory object for creating
// new instances of SignonViewer. This way if we are called
// again for the factory, we won't need to create a new
// one.
rv = NS_NewGenericFactory(getter_AddRefs(mSignonViewerFactory),
CreateNewSignonViewer);
}
fact = mSignonViewerFactory;
}
else if (aClass.Equals(kCookieViewerCID)) {
if (!mCookieViewerFactory) {
// Create and save away the factory object for creating
// new instances of CookieViewer. This way if we are called
// again for the factory, we won't need to create a new
// one.
rv = NS_NewGenericFactory(getter_AddRefs(mCookieViewerFactory),
CreateNewCookieViewer);
}
fact = mCookieViewerFactory;
}
else if (aClass.Equals(kWalletEditorCID)) {
if (!mWalletEditorFactory) {
// Create and save away the factory object for creating
// new instances of WalletEditor. This way if we are called
// again for the factory, we won't need to create a new
// one.
rv = NS_NewGenericFactory(getter_AddRefs(mWalletEditorFactory),
CreateNewWalletEditor);
}
fact = mWalletEditorFactory;
}
else {
rv = NS_ERROR_FACTORY_NOT_REGISTERED;
#ifdef DEBUG
char* cs = aClass.ToString();
printf("+++ nsWalletViewerModule: unable to create factory for %s\n", cs);
nsCRT::free(cs);
#endif
}
rv = compMgr->UnregisterComponent(kWalletPreviewCID, aPath);
if (fact) {
rv = fact->QueryInterface(aIID, r_classObj);
}
rv = compMgr->UnregisterComponent(kSignonViewerCID, aPath);
rv = compMgr->UnregisterComponent(kCookieViewerCID, aPath);
rv = compMgr->UnregisterComponent(kWalletEditorCID, aPath);
return NS_OK;
return rv;
}
//----------------------------------------
struct Components {
const char* mDescription;
const nsID* mCID;
const char* mProgID;
};
// The list of components we register
static Components gComponents[] = {
{ "WalletPreview World Component", &kWalletPreviewCID,
"component://netscape/walletpreview/walletpreview-world", },
{ "SignonViewer World Component", &kSignonViewerCID,
"component://netscape/signonviewer/signonviewer-world", },
{ "CookieViewer World Component", &kCookieViewerCID,
"component://netscape/cookieviewer/cookieviewer-world", },
{ "WalletEditor World Component", &kWalletEditorCID,
"component://netscape/walleteditor/walleteditor-world", },
};
#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0]))
NS_IMETHODIMP
nsWalletViewerModule::RegisterSelf(nsIComponentManager *aCompMgr,
nsIFileSpec* aPath,
const char* registryLocation,
const char* componentType)
{
nsresult rv = NS_OK;
#ifdef DEBUG
printf("*** Registering walletviewer 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("nsWalletViewerModule: unable to register %s component => %x\n",
cp->mDescription, rv);
#endif
break;
}
cp++;
}
return rv;
}
NS_IMETHODIMP
nsWalletViewerModule::UnregisterSelf(nsIComponentManager* aCompMgr,
nsIFileSpec* aPath,
const char* registryLocation)
{
#ifdef DEBUG
printf("*** Unregistering walletviewer 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("nsWalletViewerModule: unable to unregister %s component => %x\n",
cp->mDescription, rv);
#endif
}
cp++;
}
return NS_OK;
}
NS_IMETHODIMP
nsWalletViewerModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload)
{
if (!okToUnload) {
return NS_ERROR_INVALID_POINTER;
}
*okToUnload = PR_FALSE;
return NS_ERROR_FAILURE;
}
//----------------------------------------------------------------------
static nsWalletViewerModule *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_NOT(gModule, NS_ERROR_FAILURE);
// Create and initialize the module instance
nsWalletViewerModule *m = new nsWalletViewerModule();
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;
}

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

@ -22,6 +22,8 @@
#include "nsIFactory.h"
#include "nsIWalletService.h"
#include "nsIServiceManager.h"
#include "nsIModule.h"
#include "nsIGenericFactory.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
@ -34,177 +36,250 @@ static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
//#define NS_STATIC_CAST(__type, __ptr) ((__type)(__ptr))
//#endif
// factory functions
nsresult NS_NewWalletService(nsIWalletService** result);
class WalletFactoryImpl : public nsIFactory
// Module implementation
class nsWalletModule : public nsIModule
{
public:
WalletFactoryImpl(const nsCID &aClass);
nsWalletModule();
virtual ~nsWalletModule();
// nsISupports methods
NS_DECL_ISUPPORTS
// nsIFactory methods
NS_IMETHOD CreateInstance(nsISupports *aOuter,
const nsIID &aIID,
void **aResult);
NS_IMETHOD LockFactory(PRBool aLock);
NS_DECL_NSIMODULE
protected:
virtual ~WalletFactoryImpl();
nsresult Initialize();
private:
nsCID mClassID;
void Shutdown();
PRBool mInitialized;
nsCOMPtr<nsIGenericFactory> mFactory;
};
////////////////////////////////////////////////////////////////////////
//----------------------------------------------------------------------
WalletFactoryImpl::WalletFactoryImpl(const nsCID &aClass)
{
NS_INIT_REFCNT();
mClassID = aClass;
// Functions used to create new instances of a given object by the
// generic factory.
static NS_IMETHODIMP
CreateNewWallet(nsISupports* aOuter, REFNSIID aIID, void **aResult)
{
if (!aResult) {
return NS_ERROR_INVALID_POINTER;
}
if (aOuter) {
*aResult = nsnull;
return NS_ERROR_NO_AGGREGATION;
}
nsIWalletService* inst;
nsresult rv = NS_NewWalletService(&inst);
if (NS_FAILED(rv)) {
*aResult = nsnull;
return rv;
}
rv = inst->QueryInterface(aIID, aResult);
if (NS_FAILED(rv)) {
*aResult = nsnull;
}
NS_RELEASE(inst); /* get rid of extra refcnt */
return rv;
}
WalletFactoryImpl::~WalletFactoryImpl()
//----------------------------------------------------------------------
nsWalletModule::nsWalletModule()
: mInitialized(PR_FALSE)
{
NS_ASSERTION(mRefCnt == 0, "non-zero refcnt at destruction");
NS_INIT_ISUPPORTS();
}
NS_IMETHODIMP
WalletFactoryImpl::QueryInterface(const nsIID &aIID,
void **aResult)
nsWalletModule::~nsWalletModule()
{
if (! aResult) {
return NS_ERROR_NULL_POINTER;
}
Shutdown();
}
// Always NULL result, in case of failure
*aResult = nsnull;
NS_IMPL_ISUPPORTS(nsWalletModule, NS_GET_IID(nsIModule))
if (aIID.Equals(kISupportsIID)) {
*aResult = NS_STATIC_CAST(nsISupports*, this);
AddRef();
return NS_OK;
} else if (aIID.Equals(kIFactoryIID)) {
*aResult = NS_STATIC_CAST(nsIFactory*, this);
AddRef();
// Perform our one-time intialization for this module
nsresult
nsWalletModule::Initialize()
{
if (mInitialized) {
return NS_OK;
}
return NS_NOINTERFACE;
mInitialized = PR_TRUE;
return NS_OK;
}
NS_IMPL_ADDREF(WalletFactoryImpl);
NS_IMPL_RELEASE(WalletFactoryImpl);
// Shutdown this module, releasing all of the module resources
void
nsWalletModule::Shutdown()
{
// Release the factory object
mFactory = nsnull;
}
// Create a factory object for creating instances of aClass.
NS_IMETHODIMP
nsWalletModule::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(kWalletServiceCID)) {
if (!mFactory) {
// Create and save away the factory object for creating
// new instances of Wallet. 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),
CreateNewWallet);
}
fact = mFactory;
}
else {
rv = NS_ERROR_FACTORY_NOT_REGISTERED;
#ifdef DEBUG
char* cs = aClass.ToString();
printf("+++ nsWalletModule: 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[] = {
{ NS_WALLETSERVICE_CLASSNAME, &kWalletServiceCID,
"component://netscape/wallet", },
};
#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0]))
NS_IMETHODIMP
WalletFactoryImpl::CreateInstance(nsISupports *aOuter,
const nsIID &aIID,
void **aResult)
nsWalletModule::RegisterSelf(nsIComponentManager *aCompMgr,
nsIFileSpec* aPath,
const char* registryLocation,
const char* componentType)
{
if (! aResult){
return NS_ERROR_NULL_POINTER;
}
if (aOuter) {
return NS_ERROR_NO_AGGREGATION;
}
*aResult = nsnull;
nsresult rv = NS_OK;
nsresult rv;
nsISupports *inst = nsnull;
if (mClassID.Equals(kWalletServiceCID)) {
if (NS_FAILED(rv = NS_NewWalletService((nsIWalletService**) &inst))) {
return rv;
#ifdef DEBUG
printf("*** Registering wallet 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("nsWalletModule: unable to register %s component => %x\n",
cp->mDescription, rv);
#endif
break;
}
} else {
return NS_ERROR_NO_INTERFACE;
cp++;
}
rv = inst->QueryInterface(aIID, aResult);
NS_IF_RELEASE(inst);
return rv;
}
nsresult WalletFactoryImpl::LockFactory(PRBool aLock)
NS_IMETHODIMP
nsWalletModule::UnregisterSelf(nsIComponentManager* aCompMgr,
nsIFileSpec* aPath,
const char* registryLocation)
{
// Not implemented in simplest case.
#ifdef DEBUG
printf("*** Unregistering wallet 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("nsWalletModule: unable to unregister %s component => %x\n",
cp->mDescription, rv);
#endif
}
cp++;
}
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
// return the proper factory to the caller
extern "C" PR_IMPLEMENT(nsresult)
NSGetFactory(nsISupports* serviceMgr,
const nsCID &aClass,
const char *aClassName,
const char *aProgID,
nsIFactory **aFactory)
NS_IMETHODIMP
nsWalletModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload)
{
if (! aFactory) {
return NS_ERROR_NULL_POINTER;
if (!okToUnload) {
return NS_ERROR_INVALID_POINTER;
}
WalletFactoryImpl* factory = new WalletFactoryImpl(aClass);
if (factory == nsnull) {
*okToUnload = PR_FALSE;
return NS_ERROR_FAILURE;
}
//----------------------------------------------------------------------
static nsWalletModule *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_NOT(gModule, NS_ERROR_FAILURE);
// Create and initialize the module instance
nsWalletModule *m = new nsWalletModule();
if (!m) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(factory);
*aFactory = factory;
return NS_OK;
}
extern "C" PR_IMPLEMENT(nsresult)
NSRegisterSelf(nsISupports* aServMgr , const char* aPath)
{
nsresult rv;
nsCOMPtr<nsIServiceManager> servMgr(do_QueryInterface(aServMgr, &rv));
if (NS_FAILED(rv)) return rv;
nsIComponentManager* compMgr;
rv = servMgr->GetService(kComponentManagerCID,
nsIComponentManager::GetIID(),
(nsISupports**)&compMgr);
// 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)) {
return rv;
delete m;
m = nsnull;
}
// register wallet service
rv = compMgr->RegisterComponent(kWalletServiceCID,
NS_WALLETSERVICE_CLASSNAME,
NS_WALLETSERVICE_PROGID,
aPath, PR_TRUE, PR_TRUE);
(void)servMgr->ReleaseService(kComponentManagerCID, compMgr);
return rv;
}
extern "C" PR_IMPLEMENT(nsresult)
NSUnregisterSelf(nsISupports* aServMgr , const char* aPath)
{
nsresult rv;
nsCOMPtr<nsIServiceManager> servMgr(do_QueryInterface(aServMgr, &rv));
if (NS_FAILED(rv)) {
return rv;
}
nsIComponentManager* compMgr;
rv = servMgr->GetService(kComponentManagerCID,
nsIComponentManager::GetIID(),
(nsISupports**)&compMgr);
if (NS_FAILED(rv)) {
return rv;
}
// unregister wallet component
rv = compMgr->UnregisterComponent(kWalletServiceCID, aPath);
(void)servMgr->ReleaseService(kComponentManagerCID, compMgr);
gModule = m; // WARNING: Weak Reference
return rv;
}