mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-19 09:30:44 +00:00
Converted nsxpi.dll and xpiflash.dll to use nsIModule to prepare for memory leaks fixing. Bug# 14034. r=dougt
This commit is contained in:
parent
0e55264368
commit
568a96b2e7
@ -696,83 +696,220 @@ static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
|
||||
static NS_DEFINE_CID(kGenericFactoryCID, NS_GENERICFACTORY_CID);
|
||||
static NS_DEFINE_CID(kXPIUpdateNotifierCID, NS_XPIUPDATENOTIFIER_CID);
|
||||
|
||||
|
||||
extern "C" PR_IMPLEMENT(nsresult)
|
||||
NSGetFactory(nsISupports* aServiceMgr,
|
||||
const nsCID &aClass,
|
||||
const char *aClassName,
|
||||
const char *aProgID,
|
||||
nsIFactory **aFactory)
|
||||
// Module implementation
|
||||
class nsXPINotifierModule : public nsIModule
|
||||
{
|
||||
NS_PRECONDITION(aFactory != nsnull, "null ptr");
|
||||
if (! aFactory)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
public:
|
||||
nsXPINotifierModule();
|
||||
virtual ~nsXPINotifierModule();
|
||||
|
||||
nsIGenericFactory::ConstructorProcPtr constructor;
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_DECL_NSIMODULE
|
||||
|
||||
protected:
|
||||
nsresult Initialize();
|
||||
|
||||
void Shutdown();
|
||||
|
||||
PRBool mInitialized;
|
||||
nsCOMPtr<nsIGenericFactory> mFactory;
|
||||
};
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
nsXPINotifierModule::nsXPINotifierModule()
|
||||
: mInitialized(PR_FALSE)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
||||
nsXPINotifierModule::~nsXPINotifierModule()
|
||||
{
|
||||
Shutdown();
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsXPINotifierModule, NS_GET_IID(nsIModule))
|
||||
|
||||
// Perform our one-time intialization for this module
|
||||
nsresult
|
||||
nsXPINotifierModule::Initialize()
|
||||
{
|
||||
if (mInitialized) {
|
||||
return NS_OK;
|
||||
}
|
||||
mInitialized = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Shutdown this module, releasing all of the module resources
|
||||
void
|
||||
nsXPINotifierModule::Shutdown()
|
||||
{
|
||||
// Release the factory object
|
||||
mFactory = nsnull;
|
||||
}
|
||||
|
||||
// Create a factory object for creating instances of aClass.
|
||||
NS_IMETHODIMP
|
||||
nsXPINotifierModule::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(kXPIUpdateNotifierCID)) {
|
||||
constructor = nsXPINotifierImpl::New;
|
||||
if (!mFactory) {
|
||||
// Create and save away the factory object for creating
|
||||
// new instances of XPINotifier. 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),
|
||||
nsXPINotifierImpl::New);
|
||||
}
|
||||
fact = mFactory;
|
||||
}
|
||||
else {
|
||||
*aFactory = nsnull;
|
||||
return NS_NOINTERFACE; // XXX
|
||||
rv = NS_ERROR_FACTORY_NOT_REGISTERED;
|
||||
#ifdef DEBUG
|
||||
char* cs = aClass.ToString();
|
||||
printf("+++ nsXPINotifierModule: unable to create factory for %s\n", cs);
|
||||
nsCRT::free(cs);
|
||||
#endif
|
||||
}
|
||||
|
||||
nsresult rv;
|
||||
NS_WITH_SERVICE1(nsIComponentManager, compMgr, aServiceMgr, kComponentManagerCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (fact) {
|
||||
rv = fact->QueryInterface(aIID, r_classObj);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIGenericFactory> factory;
|
||||
rv = compMgr->CreateInstance(kGenericFactoryCID,
|
||||
nsnull,
|
||||
nsIGenericFactory::GetIID(),
|
||||
getter_AddRefs(factory));
|
||||
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = factory->SetConstructor(constructor);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
*aFactory = factory;
|
||||
NS_ADDREF(*aFactory);
|
||||
return NS_OK;
|
||||
return rv;
|
||||
}
|
||||
|
||||
//----------------------------------------
|
||||
|
||||
struct Components {
|
||||
const char* mDescription;
|
||||
const nsID* mCID;
|
||||
const char* mProgID;
|
||||
};
|
||||
|
||||
extern "C" PR_IMPLEMENT(nsresult)
|
||||
NSRegisterSelf(nsISupports* aServMgr , const char* aPath)
|
||||
// The list of components we register
|
||||
static Components gComponents[] = {
|
||||
{ "XPInstall Update Notifier", &kXPIUpdateNotifierCID,
|
||||
"component://netscape/rdf/datasource?name=xpinstall-update-notifier", },
|
||||
};
|
||||
#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0]))
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXPINotifierModule::RegisterSelf(nsIComponentManager *aCompMgr,
|
||||
nsIFileSpec* aPath,
|
||||
const char* registryLocation,
|
||||
const char* componentType)
|
||||
{
|
||||
nsresult rv;
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
nsCOMPtr<nsIServiceManager> servMgr(do_QueryInterface(aServMgr, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
#ifdef DEBUG
|
||||
printf("*** Registering XPINotifier components\n");
|
||||
#endif
|
||||
|
||||
NS_WITH_SERVICE1(nsIComponentManager, compMgr, servMgr, kComponentManagerCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
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("nsXPINotifierModule: unable to register %s component => %x\n",
|
||||
cp->mDescription, rv);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
cp++;
|
||||
}
|
||||
|
||||
rv = compMgr->RegisterComponent(kXPIUpdateNotifierCID,
|
||||
"XPInstall Update Notifier",
|
||||
"component://netscape/rdf/datasource?name=xpinstall-update-notifier",
|
||||
aPath, PR_TRUE, PR_TRUE);
|
||||
|
||||
return NS_OK;
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
|
||||
extern "C" PR_IMPLEMENT(nsresult)
|
||||
NSUnregisterSelf(nsISupports* aServMgr, const char* aPath)
|
||||
NS_IMETHODIMP
|
||||
nsXPINotifierModule::UnregisterSelf(nsIComponentManager* aCompMgr,
|
||||
nsIFileSpec* aPath,
|
||||
const char* registryLocation)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIServiceManager> servMgr(do_QueryInterface(aServMgr, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
NS_WITH_SERVICE1(nsIComponentManager, compMgr, servMgr, kComponentManagerCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = compMgr->UnregisterComponent(kXPIUpdateNotifierCID, aPath);
|
||||
#ifdef DEBUG
|
||||
printf("*** Unregistering XPINotifier 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("nsXPINotifierModule: unable to unregister %s component => %x\n",
|
||||
cp->mDescription, rv);
|
||||
#endif
|
||||
}
|
||||
cp++;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXPINotifierModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload)
|
||||
{
|
||||
if (!okToUnload) {
|
||||
return NS_ERROR_INVALID_POINTER;
|
||||
}
|
||||
*okToUnload = PR_FALSE;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
static nsXPINotifierModule *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
|
||||
nsXPINotifierModule *m = new nsXPINotifierModule();
|
||||
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,6 +32,9 @@
|
||||
#include "nsIFileSpec.h"
|
||||
|
||||
#include "nsIXPINotifier.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIModule.h"
|
||||
#include "nsIGenericFactory.h"
|
||||
|
||||
#define NS_IXPINSTALLCOMPONENT_PROGID NS_IAPPSHELLCOMPONENT_PROGID "/xpinstall"
|
||||
#define NS_IXPINSTALLCOMPONENT_CLASSNAME "Mozilla XPInstall Component"
|
||||
@ -73,21 +76,26 @@ class nsISoftwareUpdate : public nsISupports
|
||||
};
|
||||
|
||||
|
||||
class nsSoftwareUpdateFactory : public nsIFactory
|
||||
// Module implementation
|
||||
class nsSoftwareUpdateModule : public nsIModule
|
||||
{
|
||||
public:
|
||||
|
||||
nsSoftwareUpdateFactory();
|
||||
virtual ~nsSoftwareUpdateFactory();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
public:
|
||||
nsSoftwareUpdateModule();
|
||||
virtual ~nsSoftwareUpdateModule();
|
||||
|
||||
NS_IMETHOD CreateInstance(nsISupports *aOuter,
|
||||
REFNSIID aIID,
|
||||
void **aResult);
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD LockFactory(PRBool aLock);
|
||||
NS_DECL_NSIMODULE
|
||||
|
||||
protected:
|
||||
nsresult Initialize();
|
||||
|
||||
void Shutdown();
|
||||
|
||||
PRBool mInitialized;
|
||||
nsCOMPtr<nsIGenericFactory> mSoftwareUpdateFactory;
|
||||
nsCOMPtr<nsIGenericFactory> mInstallTriggerFactory;
|
||||
nsCOMPtr<nsIGenericFactory> mInstallVersionFactory;
|
||||
};
|
||||
|
||||
|
||||
|
@ -484,74 +484,3 @@ nsInstallTrigger::CreateTempFileFromURL(const nsString& aURL, nsString& tempFile
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
nsInstallTriggerFactory::nsInstallTriggerFactory(void)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
||||
nsInstallTriggerFactory::~nsInstallTriggerFactory(void)
|
||||
{
|
||||
NS_ASSERTION(mRefCnt == 0, "non-zero refcnt at destruction");
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInstallTriggerFactory::QueryInterface(const nsIID &aIID, void **aResult)
|
||||
{
|
||||
if (! aResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
// Always NULL result, in case of failure
|
||||
*aResult = nsnull;
|
||||
|
||||
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();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsInstallTriggerFactory);
|
||||
NS_IMPL_RELEASE(nsInstallTriggerFactory);
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInstallTriggerFactory::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
||||
{
|
||||
if (! aResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aResult = nsnull;
|
||||
|
||||
nsresult rv;
|
||||
|
||||
nsInstallTrigger *inst = new nsInstallTrigger();
|
||||
|
||||
if (! inst)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
if (NS_FAILED(rv = inst->QueryInterface(aIID, aResult)))
|
||||
{
|
||||
// We didn't get the right interface.
|
||||
NS_ERROR("didn't support the interface you wanted");
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInstallTriggerFactory::LockFactory(PRBool aLock)
|
||||
{
|
||||
// Not implemented in simplest case.
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -51,22 +51,5 @@ class nsInstallTrigger: public nsIScriptObjectOwner, public nsIDOMInstallTrigger
|
||||
|
||||
};
|
||||
|
||||
|
||||
class nsInstallTriggerFactory : public nsIFactory
|
||||
{
|
||||
public:
|
||||
|
||||
nsInstallTriggerFactory();
|
||||
virtual ~nsInstallTriggerFactory();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD CreateInstance(nsISupports *aOuter,
|
||||
REFNSIID aIID,
|
||||
void **aResult);
|
||||
|
||||
NS_IMETHOD LockFactory(PRBool aLock);
|
||||
|
||||
};
|
||||
|
||||
#define NS_INSTALLTRIGGERCOMPONENT_PROGID NS_IXPINSTALLCOMPONENT_PROGID "/installtrigger"
|
||||
#endif
|
||||
|
@ -336,70 +336,3 @@ nsInstallVersion::StringToVersionNumbers(const nsString& version, PRInt32 *aMajo
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsInstallVersionFactory::nsInstallVersionFactory(void)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsInstallVersionFactory::~nsInstallVersionFactory(void)
|
||||
{
|
||||
NS_ASSERTION(mRefCnt == 0, "non-zero refcnt at destruction");
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInstallVersionFactory::QueryInterface(const nsIID &aIID, void **aResult)
|
||||
{
|
||||
if (! aResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
// Always NULL result, in case of failure
|
||||
*aResult = nsnull;
|
||||
|
||||
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();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsInstallVersionFactory);
|
||||
NS_IMPL_RELEASE(nsInstallVersionFactory);
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInstallVersionFactory::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
||||
{
|
||||
if (aResult == NULL)
|
||||
{
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
*aResult = NULL;
|
||||
|
||||
/* do I have to use iSupports? */
|
||||
nsInstallVersion *inst = new nsInstallVersion();
|
||||
|
||||
if (inst == NULL)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsresult result = inst->QueryInterface(aIID, aResult);
|
||||
|
||||
if (NS_FAILED(result))
|
||||
delete inst;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInstallVersionFactory::LockFactory(PRBool aLock)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -56,21 +56,5 @@ class nsInstallVersion: public nsIScriptObjectOwner, public nsIDOMInstallVersion
|
||||
};
|
||||
|
||||
|
||||
class nsInstallVersionFactory : public nsIFactory
|
||||
{
|
||||
public:
|
||||
|
||||
nsInstallVersionFactory();
|
||||
virtual ~nsInstallVersionFactory();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD CreateInstance(nsISupports *aOuter,
|
||||
REFNSIID aIID,
|
||||
void **aResult);
|
||||
|
||||
NS_IMETHOD LockFactory(PRBool aLock);
|
||||
|
||||
};
|
||||
|
||||
#define NS_INSTALLVERSIONCOMPONENT_PROGID NS_IXPINSTALLCOMPONENT_PROGID "/installversion"
|
||||
#endif
|
||||
|
@ -402,63 +402,6 @@ nsSoftwareUpdate::SetProgramDirectory(nsIFileSpec *aDir)
|
||||
}
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
static PRInt32 gSoftwareUpdateLock = 0;
|
||||
|
||||
nsSoftwareUpdateFactory::nsSoftwareUpdateFactory(void)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
||||
nsSoftwareUpdateFactory::~nsSoftwareUpdateFactory(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsSoftwareUpdateFactory,kIFactoryIID)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSoftwareUpdateFactory::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
||||
{
|
||||
if (aResult == NULL)
|
||||
{
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
*aResult = NULL;
|
||||
|
||||
nsSoftwareUpdate *inst = nsSoftwareUpdate::GetInstance();
|
||||
|
||||
if (inst == NULL)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsresult result = inst->QueryInterface(aIID, aResult);
|
||||
|
||||
if (NS_FAILED(result))
|
||||
{
|
||||
*aResult = NULL;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSoftwareUpdateFactory::LockFactory(PRBool aLock)
|
||||
{
|
||||
if (aLock)
|
||||
PR_AtomicIncrement(&gSoftwareUpdateLock);
|
||||
else
|
||||
PR_AtomicDecrement(&gSoftwareUpdateLock);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsSoftwareUpdateNameSet
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@ -525,160 +468,333 @@ nsSoftwareUpdateNameSet::AddNameSet(nsIScriptContext* aScriptContext)
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// DLL Entry Points:
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Functions used to create new instances of a given object by the
|
||||
// generic factory.
|
||||
|
||||
extern "C" NS_EXPORT PRBool
|
||||
NSCanUnload(nsISupports* aServMgr)
|
||||
{
|
||||
return PR_FALSE;
|
||||
static NS_IMETHODIMP
|
||||
CreateNewSoftwareUpdate(nsISupports* aOuter, REFNSIID aIID, void **aResult)
|
||||
{
|
||||
if (!aResult) {
|
||||
return NS_ERROR_INVALID_POINTER;
|
||||
}
|
||||
if (aOuter) {
|
||||
*aResult = nsnull;
|
||||
return NS_ERROR_NO_AGGREGATION;
|
||||
}
|
||||
nsSoftwareUpdate* inst = nsSoftwareUpdate::GetInstance();
|
||||
if (inst == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsresult rv = inst->QueryInterface(aIID, aResult);
|
||||
if (NS_FAILED(rv)) {
|
||||
*aResult = nsnull;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
extern "C" NS_EXPORT nsresult
|
||||
NSRegisterSelf(nsISupports* aServMgr, const char *path)
|
||||
|
||||
static NS_IMETHODIMP
|
||||
CreateNewInstallTrigger(nsISupports* aOuter, REFNSIID aIID, void **aResult)
|
||||
{
|
||||
if (!aResult) {
|
||||
return NS_ERROR_INVALID_POINTER;
|
||||
}
|
||||
if (aOuter) {
|
||||
*aResult = nsnull;
|
||||
return NS_ERROR_NO_AGGREGATION;
|
||||
}
|
||||
nsInstallTrigger* inst = new nsInstallTrigger();
|
||||
if (inst == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(inst);
|
||||
nsresult rv = inst->QueryInterface(aIID, aResult);
|
||||
if (NS_FAILED(rv)) {
|
||||
*aResult = nsnull;
|
||||
}
|
||||
NS_RELEASE(inst);
|
||||
return rv;
|
||||
}
|
||||
|
||||
static NS_IMETHODIMP
|
||||
CreateNewInstallVersion(nsISupports* aOuter, REFNSIID aIID, void **aResult)
|
||||
{
|
||||
if (!aResult) {
|
||||
return NS_ERROR_INVALID_POINTER;
|
||||
}
|
||||
if (aOuter) {
|
||||
*aResult = nsnull;
|
||||
return NS_ERROR_NO_AGGREGATION;
|
||||
}
|
||||
nsInstallVersion* inst = new nsInstallVersion();
|
||||
if (inst == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(inst);
|
||||
nsresult rv = inst->QueryInterface(aIID, aResult);
|
||||
if (NS_FAILED(rv)) {
|
||||
*aResult = nsnull;
|
||||
}
|
||||
NS_RELEASE(inst); /* get rid of extra refcnt */
|
||||
return rv;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
nsSoftwareUpdateModule::nsSoftwareUpdateModule()
|
||||
: mInitialized(PR_FALSE)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
||||
nsSoftwareUpdateModule::~nsSoftwareUpdateModule()
|
||||
{
|
||||
Shutdown();
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsSoftwareUpdateModule, NS_GET_IID(nsIModule))
|
||||
|
||||
// Perform our one-time intialization for this module
|
||||
nsresult
|
||||
nsSoftwareUpdateModule::Initialize()
|
||||
{
|
||||
if (mInitialized) {
|
||||
return NS_OK;
|
||||
}
|
||||
mInitialized = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Shutdown this module, releasing all of the module resources
|
||||
void
|
||||
nsSoftwareUpdateModule::Shutdown()
|
||||
{
|
||||
// Release the factory objects
|
||||
mSoftwareUpdateFactory = nsnull;
|
||||
mInstallTriggerFactory = nsnull;
|
||||
mInstallVersionFactory = nsnull;
|
||||
}
|
||||
|
||||
// Create a factory object for creating instances of aClass.
|
||||
NS_IMETHODIMP
|
||||
nsSoftwareUpdateModule::GetClassObject(nsIComponentManager *aCompMgr,
|
||||
const nsCID& aClass,
|
||||
const nsIID& aIID,
|
||||
void** r_classObj)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIServiceManager> servMgr(do_QueryInterface(aServMgr, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
// Defensive programming: Initialize *r_classObj in case of error below
|
||||
if (!r_classObj) {
|
||||
return NS_ERROR_INVALID_POINTER;
|
||||
}
|
||||
*r_classObj = NULL;
|
||||
|
||||
nsIComponentManager* compMgr;
|
||||
rv = servMgr->GetService(kComponentManagerCID,
|
||||
nsIComponentManager::GetIID(),
|
||||
(nsISupports**)&compMgr);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
// Choose the appropriate factory, based on the desired instance
|
||||
// class type (aClass).
|
||||
nsCOMPtr<nsIGenericFactory> fact;
|
||||
if (aClass.Equals(kSoftwareUpdate_CID)) {
|
||||
if (!mSoftwareUpdateFactory) {
|
||||
// Create and save away the factory object for creating
|
||||
// new instances of SoftwareUpdate. This way if we are called
|
||||
// again for the factory, we won't need to create a new
|
||||
// one.
|
||||
rv = NS_NewGenericFactory(getter_AddRefs(mSoftwareUpdateFactory),
|
||||
CreateNewSoftwareUpdate);
|
||||
}
|
||||
fact = mSoftwareUpdateFactory;
|
||||
}
|
||||
else if (aClass.Equals(kInstallTrigger_CID)) {
|
||||
if (!mInstallTriggerFactory) {
|
||||
// Create and save away the factory object for creating
|
||||
// new instances of InstallTrigger. This way if we are called
|
||||
// again for the factory, we won't need to create a new
|
||||
// one.
|
||||
rv = NS_NewGenericFactory(getter_AddRefs(mInstallTriggerFactory),
|
||||
CreateNewInstallTrigger);
|
||||
}
|
||||
fact = mInstallTriggerFactory;
|
||||
}
|
||||
else if (aClass.Equals(kInstallVersion_CID)) {
|
||||
if (!mInstallVersionFactory) {
|
||||
// Create and save away the factory object for creating
|
||||
// new instances of InstallVersion. This way if we are called
|
||||
// again for the factory, we won't need to create a new
|
||||
// one.
|
||||
rv = NS_NewGenericFactory(getter_AddRefs(mInstallVersionFactory),
|
||||
CreateNewInstallVersion);
|
||||
}
|
||||
fact = mInstallVersionFactory;
|
||||
}
|
||||
else {
|
||||
rv = NS_ERROR_FACTORY_NOT_REGISTERED;
|
||||
#ifdef DEBUG
|
||||
char* cs = aClass.ToString();
|
||||
printf("+++ nsSoftwareUpdateModule: 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[] = {
|
||||
{ "SoftwareUpdate Component", &kSoftwareUpdate_CID,
|
||||
NS_IXPINSTALLCOMPONENT_PROGID, },
|
||||
{ "InstallTrigger Component", &kInstallTrigger_CID,
|
||||
NS_INSTALLTRIGGERCOMPONENT_PROGID, },
|
||||
{ "InstallVersion Component", &kInstallVersion_CID,
|
||||
NS_INSTALLVERSIONCOMPONENT_PROGID, },
|
||||
};
|
||||
#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0]))
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSoftwareUpdateModule::RegisterSelf(nsIComponentManager *aCompMgr,
|
||||
nsIFileSpec* aPath,
|
||||
const char* registryLocation,
|
||||
const char* componentType)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("*** XPInstall is being registered\n");
|
||||
#endif
|
||||
|
||||
rv = compMgr->RegisterComponent( kSoftwareUpdate_CID,
|
||||
NS_IXPINSTALLCOMPONENT_CLASSNAME,
|
||||
NS_IXPINSTALLCOMPONENT_PROGID,
|
||||
path,
|
||||
PR_TRUE,
|
||||
PR_TRUE );
|
||||
|
||||
if (NS_FAILED(rv)) goto done;
|
||||
|
||||
nsIRegistry *registry;
|
||||
rv = servMgr->GetService( NS_REGISTRY_PROGID,
|
||||
nsIRegistry::GetIID(),
|
||||
(nsISupports**)®istry );
|
||||
|
||||
Components* cp = gComponents;
|
||||
Components* end = cp + NUM_COMPONENTS;
|
||||
rv = aCompMgr->RegisterComponentSpec(*cp->mCID, cp->mDescription,
|
||||
cp->mProgID, aPath, PR_TRUE,
|
||||
PR_TRUE);
|
||||
if ( NS_SUCCEEDED( rv ) )
|
||||
{
|
||||
registry->OpenWellKnownRegistry(nsIRegistry::ApplicationComponentRegistry);
|
||||
char buffer[256];
|
||||
char *cid = nsSoftwareUpdate::GetCID().ToString();
|
||||
PR_snprintf( buffer,
|
||||
sizeof buffer,
|
||||
"%s/%s",
|
||||
NS_IAPPSHELLCOMPONENT_KEY,
|
||||
cid ? cid : "unknown" );
|
||||
nsCRT::free(cid);
|
||||
// get the registry
|
||||
nsIRegistry* registry;
|
||||
rv = nsServiceManager::GetService(NS_REGISTRY_PROGID,
|
||||
nsIRegistry::GetIID(),
|
||||
(nsISupports**)®istry);
|
||||
if ( NS_SUCCEEDED( rv ) )
|
||||
{
|
||||
registry->OpenWellKnownRegistry(nsIRegistry::ApplicationComponentRegistry);
|
||||
char buffer[256];
|
||||
char *cid = nsSoftwareUpdate::GetCID().ToString();
|
||||
PR_snprintf( buffer,
|
||||
sizeof buffer,
|
||||
"%s/%s",
|
||||
NS_IAPPSHELLCOMPONENT_KEY,
|
||||
cid ? cid : "unknown" );
|
||||
nsCRT::free(cid);
|
||||
|
||||
nsRegistryKey key;
|
||||
rv = registry->AddSubtree( nsIRegistry::Common,
|
||||
buffer,
|
||||
&key );
|
||||
servMgr->ReleaseService( NS_REGISTRY_PROGID, registry );
|
||||
}
|
||||
|
||||
rv = compMgr->RegisterComponent(kInstallTrigger_CID, NULL, NULL, path, PR_TRUE, PR_TRUE);
|
||||
if (NS_FAILED(rv)) goto done;
|
||||
|
||||
rv = compMgr->RegisterComponent(kInstallVersion_CID, NULL, NULL, path, PR_TRUE, PR_TRUE);
|
||||
|
||||
done:
|
||||
(void)servMgr->ReleaseService(kComponentManagerCID, compMgr);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
extern "C" NS_EXPORT nsresult
|
||||
NSUnregisterSelf(nsISupports* aServMgr, const char *path)
|
||||
{
|
||||
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;
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
printf("*** XPInstall is being unregistered\n");
|
||||
nsRegistryKey key;
|
||||
rv = registry->AddSubtree( nsIRegistry::Common,
|
||||
buffer,
|
||||
&key );
|
||||
nsServiceManager::ReleaseService(NS_REGISTRY_PROGID, registry);
|
||||
}
|
||||
cp++;
|
||||
while (cp < end) {
|
||||
rv = aCompMgr->RegisterComponentSpec(*cp->mCID, cp->mDescription,
|
||||
cp->mProgID, aPath, PR_TRUE,
|
||||
PR_TRUE);
|
||||
if (NS_FAILED(rv)) {
|
||||
#ifdef DEBUG
|
||||
printf("nsSoftwareUpdateModule: unable to register %s component => %x\n",
|
||||
cp->mDescription, rv);
|
||||
#endif
|
||||
|
||||
rv = compMgr->UnregisterComponent(kSoftwareUpdate_CID, path);
|
||||
if (NS_FAILED(rv)) goto done;
|
||||
rv = compMgr->UnregisterComponent(kInstallTrigger_CID, path);
|
||||
if (NS_FAILED(rv)) goto done;
|
||||
rv = compMgr->UnregisterComponent(kInstallVersion_CID, path);
|
||||
break;
|
||||
}
|
||||
cp++;
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
(void)servMgr->ReleaseService(kComponentManagerCID, compMgr);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
|
||||
extern "C" NS_EXPORT nsresult
|
||||
NSGetFactory(nsISupports* serviceMgr,
|
||||
const nsCID &aClass,
|
||||
const char *aClassName,
|
||||
const char *aProgID,
|
||||
nsIFactory **aFactory)
|
||||
NS_IMETHODIMP
|
||||
nsSoftwareUpdateModule::UnregisterSelf(nsIComponentManager* aCompMgr,
|
||||
nsIFileSpec* aPath,
|
||||
const char* registryLocation)
|
||||
{
|
||||
|
||||
if (aFactory == NULL)
|
||||
{
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
#ifdef DEBUG
|
||||
printf("*** Unregistering SoftwareUpdate 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("nsSoftwareUpdateModule: unable to unregister %s component => %x\n",
|
||||
cp->mDescription, rv);
|
||||
#endif
|
||||
}
|
||||
cp++;
|
||||
}
|
||||
|
||||
*aFactory = NULL;
|
||||
nsISupports *inst;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
if (aClass.Equals(kInstallTrigger_CID) )
|
||||
{
|
||||
inst = new nsInstallTriggerFactory();
|
||||
}
|
||||
else if (aClass.Equals(kInstallVersion_CID) )
|
||||
{
|
||||
inst = new nsInstallVersionFactory();
|
||||
}
|
||||
else if (aClass.Equals(kSoftwareUpdate_CID) )
|
||||
{
|
||||
inst = new nsSoftwareUpdateFactory();
|
||||
}
|
||||
else
|
||||
{
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
NS_IMETHODIMP
|
||||
nsSoftwareUpdateModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload)
|
||||
{
|
||||
if (!okToUnload) {
|
||||
return NS_ERROR_INVALID_POINTER;
|
||||
}
|
||||
*okToUnload = PR_FALSE;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
if (inst == NULL)
|
||||
{
|
||||
static nsSoftwareUpdateModule *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
|
||||
nsSoftwareUpdateModule *m = new nsSoftwareUpdateModule();
|
||||
if (!m) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
|
||||
nsresult res = inst->QueryInterface(kIFactoryIID, (void**) aFactory);
|
||||
|
||||
if (NS_FAILED(res))
|
||||
{
|
||||
delete inst;
|
||||
// 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;
|
||||
}
|
||||
|
||||
return res;
|
||||
|
||||
gModule = m; // WARNING: Weak Reference
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user