From 450ceda4e08633c01c843db4103c8201bc8619ec Mon Sep 17 00:00:00 2001 From: "alecf%netscape.com" Date: Fri, 22 Oct 1999 21:05:31 +0000 Subject: [PATCH] convert nsPrefWindow to a module prefwindow was doing it's own singleton management, so changed it to use getService() git-svn-id: svn://10.0.0.236/trunk@51560 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/suite/common/pref/preftree.xul | 2 +- .../resources/content/PrefsWindow.js | 2 +- .../prefwindow/resources/content/preftree.xul | 2 +- .../prefwindow/src/nsPrefWindowFactory.cpp | 161 ++---------------- 4 files changed, 17 insertions(+), 150 deletions(-) diff --git a/mozilla/suite/common/pref/preftree.xul b/mozilla/suite/common/pref/preftree.xul index b273bddab0c..48ff193c2bd 100644 --- a/mozilla/suite/common/pref/preftree.xul +++ b/mozilla/suite/common/pref/preftree.xul @@ -50,7 +50,7 @@ if (prefwindow == null) { dump("Creating prefwindow object..."); - prefwindow = Components.classes['component://netscape/prefwindow'].createInstance(Components.interfaces.nsIPrefWindow); + prefwindow = Components.classes['component://netscape/prefwindow'].getService(Components.interfaces.nsIPrefWindow); dump("...created\n"); } else diff --git a/mozilla/xpfe/components/prefwindow/resources/content/PrefsWindow.js b/mozilla/xpfe/components/prefwindow/resources/content/PrefsWindow.js index 48e757ee7ac..82c5de37f19 100644 --- a/mozilla/xpfe/components/prefwindow/resources/content/PrefsWindow.js +++ b/mozilla/xpfe/components/prefwindow/resources/content/PrefsWindow.js @@ -29,7 +29,7 @@ function StartUp(windowName) if (prefwindow == null) { dump("Creating prefwindow object...\n"); - prefwindow = Components.classes['component://netscape/prefwindow'].createInstance(Components.interfaces.nsIPrefWindow); + prefwindow = Components.classes['component://netscape/prefwindow'].getService(Components.interfaces.nsIPrefWindow); } else { diff --git a/mozilla/xpfe/components/prefwindow/resources/content/preftree.xul b/mozilla/xpfe/components/prefwindow/resources/content/preftree.xul index b273bddab0c..48ff193c2bd 100644 --- a/mozilla/xpfe/components/prefwindow/resources/content/preftree.xul +++ b/mozilla/xpfe/components/prefwindow/resources/content/preftree.xul @@ -50,7 +50,7 @@ if (prefwindow == null) { dump("Creating prefwindow object..."); - prefwindow = Components.classes['component://netscape/prefwindow'].createInstance(Components.interfaces.nsIPrefWindow); + prefwindow = Components.classes['component://netscape/prefwindow'].getService(Components.interfaces.nsIPrefWindow); dump("...created\n"); } else diff --git a/mozilla/xpfe/components/prefwindow/src/nsPrefWindowFactory.cpp b/mozilla/xpfe/components/prefwindow/src/nsPrefWindowFactory.cpp index dba25cfd54f..7ba4bda6f24 100644 --- a/mozilla/xpfe/components/prefwindow/src/nsPrefWindowFactory.cpp +++ b/mozilla/xpfe/components/prefwindow/src/nsPrefWindowFactory.cpp @@ -24,154 +24,21 @@ // include files for components this factory creates... #include "nsPrefWindow.h" +#include "nsIModule.h" +#include "nsIGenericFactory.h" -static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID); -//static NS_DEFINE_CID(kPrefWindowCID, NS_PREFWINDOW_CID); +NS_GENERIC_FACTORY_CONSTRUCTOR(nsPrefWindow) -static PRInt32 gLockCount = 0; +struct components_t { + nsCID cid; + nsIGenericFactory::ConstructorProcPtr constructor; + const char *progid; + const char *description; +}; -//======================================================================================== -class nsPrefWindowFactory : public nsIFactory -//======================================================================================== -{ -public: - // nsISupports methods - NS_DECL_ISUPPORTS +components_t components[] = { + { NS_PREFWINDOW_CID, &nsPrefWindowConstructor, NS_PREFWINDOW_PROGID, "Preferences window helper object", }, +}; - nsPrefWindowFactory(/*const nsCID &aClass, const char* aClassName, const char* aProgID*/); - - // nsIFactory methods - NS_IMETHOD CreateInstance(nsISupports *aOuter, const nsIID &aIID, void **aResult); - NS_IMETHOD LockFactory(PRBool aLock); - -protected: - virtual ~nsPrefWindowFactory(); - -// DATA - -protected: - -// nsCID mClassID; -// char* mClassName; -// char* mProgID; -}; - -//---------------------------------------------------------------------------------------- -nsPrefWindowFactory::nsPrefWindowFactory( - /*const nsCID &aClass, - const char* aClassName, - const char* aProgID*/) -//---------------------------------------------------------------------------------------- -// : mClassID(aClass) -// , mClassName(nsCRT::strdup(aClassName)) -// , mProgID(nsCRT::strdup(aProgID)) -{ - NS_INIT_REFCNT(); -} - -//---------------------------------------------------------------------------------------- -nsPrefWindowFactory::~nsPrefWindowFactory() -//---------------------------------------------------------------------------------------- -{ -// nsCRT::free(mClassName); -// nsCRT::free(mProgID); -} - -NS_IMPL_ISUPPORTS(nsPrefWindowFactory, nsIFactory::GetIID()); - -//---------------------------------------------------------------------------------------- -nsresult nsPrefWindowFactory::CreateInstance( - nsISupports* /* aOuter */, - const nsIID &aIID, - void** aResult) -//---------------------------------------------------------------------------------------- -{ - if (aResult == nsnull) - return NS_ERROR_NULL_POINTER; - *aResult = nsnull; - -// if (!mClassID.Equals(nsPrefWindow::GetCID())) -// return NS_NOINTERFACE; - - *aResult = nsPrefWindow::Get(); - return NS_OK; -} // nsPrefWindowFactory::CreateInstanc - -//---------------------------------------------------------------------------------------- -nsresult nsPrefWindowFactory::LockFactory(PRBool aLock) -//---------------------------------------------------------------------------------------- -{ - if (aLock) - PR_AtomicIncrement(&gLockCount); - else - PR_AtomicDecrement(&gLockCount); - return NS_OK; -} // nsPrefWindowFactory::LockFactory - -//---------------------------------------------------------------------------------------- -extern "C" NS_EXPORT nsresult NSGetFactory( - nsISupports* /* aServMgr */, - const nsCID &aClass, - const char *aClassName, - const char *aProgID, - nsIFactory **aFactory) -//---------------------------------------------------------------------------------------- -{ - if (nsnull == aFactory) - return NS_ERROR_NULL_POINTER; - - // If we decide to implement multiple factories, then we need to - // check the class type here and create the appropriate factory. - *aFactory = new nsPrefWindowFactory(/*aClass, aClassName, aProgID*/); - if (!aFactory) - return NS_ERROR_OUT_OF_MEMORY; - return (*aFactory)->QueryInterface(nsIFactory::GetIID(), (void**)aFactory); - // they want a Factory Interface so give it to them -} // NSGetFactory - -//---------------------------------------------------------------------------------------- -extern "C" NS_EXPORT PRBool NSCanUnload(nsISupports* /* aServMgr */) -//---------------------------------------------------------------------------------------- -{ - return PRBool(!nsPrefWindow::InstanceExists() && gLockCount == 0); -} // NSCanUnload - -//---------------------------------------------------------------------------------------- -extern "C" NS_EXPORT nsresult NSRegisterSelf(nsISupports* /*aServMgr*/, const char* path) -//---------------------------------------------------------------------------------------- -{ - nsresult rv; -// nsCOMPtr servMgr(do_QueryInterface(aServMgr, &rv)); -// if (NS_FAILED(rv)) -// return rv; - NS_WITH_SERVICE(nsIComponentManager, compMgr, kComponentManagerCID, &rv); - if (NS_FAILED(rv)) - return rv; -#ifdef NS_DEBUG - printf("Registering the PrefsWindow\n"); -#endif - rv = compMgr->RegisterComponent( - nsPrefWindow::GetCID(), - "nsPrefWindow", // classname - NS_PREFWINDOW_PROGID, // progid - path, - PR_TRUE, // replace - PR_TRUE // persist - ); - return rv; -} // NSRegisterSelf - -//---------------------------------------------------------------------------------------- -extern "C" NS_EXPORT nsresult NSUnregisterSelf(nsISupports* /*aServMgr*/, const char* path) -//---------------------------------------------------------------------------------------- -{ - nsresult rv; -// nsCOMPtr 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->UnregisterComponent(nsPrefWindow::GetCID(), path); - return rv; -} // NSUnregisterSelf +NS_IMPL_MODULE(components) +NS_IMPL_NSGETMODULE(nsModule)