diff --git a/mozilla/extensions/pics/src/nsPICS.cpp b/mozilla/extensions/pics/src/nsPICS.cpp index e9e580177fc..9a55e673ef5 100644 --- a/mozilla/extensions/pics/src/nsPICS.cpp +++ b/mozilla/extensions/pics/src/nsPICS.cpp @@ -27,7 +27,7 @@ #include "nsIModule.h" #include "nsIGenericFactory.h" #include "nsIServiceManager.h" -#include "nsRepository.h" +#include "nsIComponentManager.h" #include "nsIPICS.h" #include "nsIPref.h" #include "nsIURL.h" diff --git a/mozilla/extensions/pics/src/nsPICSElementObserver.cpp b/mozilla/extensions/pics/src/nsPICSElementObserver.cpp index 5af0298de38..ff57d6305f0 100644 --- a/mozilla/extensions/pics/src/nsPICSElementObserver.cpp +++ b/mozilla/extensions/pics/src/nsPICSElementObserver.cpp @@ -25,7 +25,7 @@ #include "pratom.h" #include "nsIFactory.h" #include "nsIServiceManager.h" -#include "nsRepository.h" +#include "nsIComponentManager.h" //#include "nsIObserver.h" #include "nsIURL.h" #include "nsIIOService.h" diff --git a/mozilla/extensions/pics/tests/TestPICS.cpp b/mozilla/extensions/pics/tests/TestPICS.cpp index 1233edabbc0..19bf9fd8b7b 100644 --- a/mozilla/extensions/pics/tests/TestPICS.cpp +++ b/mozilla/extensions/pics/tests/TestPICS.cpp @@ -1,6 +1,6 @@ #define NS_IMPL_IDS #include "nsISupports.h" -#include "nsRepository.h" +#include "nsIComponentManager.h" #include "nsIServiceManager.h" #include "nsIPICS.h" #include "nsIPref.h" diff --git a/mozilla/mailnews/absync/src/nsAbSyncPostEngine.cpp b/mozilla/mailnews/absync/src/nsAbSyncPostEngine.cpp index 974fd8015a8..744e94af5fe 100644 --- a/mozilla/mailnews/absync/src/nsAbSyncPostEngine.cpp +++ b/mozilla/mailnews/absync/src/nsAbSyncPostEngine.cpp @@ -33,7 +33,7 @@ #include "prmem.h" #include "plstr.h" #include "nsIPref.h" -#include "nsRepository.h" +#include "nsIComponentManager.h" #include "nsIURI.h" #include "nsString.h" #include "nsAbSyncPostEngine.h" diff --git a/mozilla/mailnews/base/src/nsMsgPrintEngine.cpp b/mozilla/mailnews/base/src/nsMsgPrintEngine.cpp index b6871430ca8..255f2692d27 100644 --- a/mozilla/mailnews/base/src/nsMsgPrintEngine.cpp +++ b/mozilla/mailnews/base/src/nsMsgPrintEngine.cpp @@ -17,7 +17,7 @@ #include "nscore.h" #include "nsCOMPtr.h" -#include "nsRepository.h" +#include "nsIComponentManager.h" #include "nsISupports.h" diff --git a/mozilla/mailnews/compose/src/nsURLFetcher.cpp b/mozilla/mailnews/compose/src/nsURLFetcher.cpp index 2973950c056..9e40bf275ef 100644 --- a/mozilla/mailnews/compose/src/nsURLFetcher.cpp +++ b/mozilla/mailnews/compose/src/nsURLFetcher.cpp @@ -32,7 +32,7 @@ #include "comi18n.h" #include "prmem.h" #include "plstr.h" -#include "nsRepository.h" +#include "nsIComponentManager.h" #include "nsString.h" #include "nsIIOService.h" #include "nsIChannel.h" diff --git a/mozilla/mailnews/mime/src/nsStreamConverter.cpp b/mozilla/mailnews/mime/src/nsStreamConverter.cpp index bcee9e02603..ca946908713 100644 --- a/mozilla/mailnews/mime/src/nsStreamConverter.cpp +++ b/mozilla/mailnews/mime/src/nsStreamConverter.cpp @@ -33,7 +33,7 @@ #include "plstr.h" #include "mimemoz2.h" #include "nsMimeTypes.h" -#include "nsRepository.h" +#include "nsIComponentManager.h" #include "nsIURL.h" #include "nsString.h" #include "nsIServiceManager.h" diff --git a/mozilla/modules/libjar/nsJAR.h b/mozilla/modules/libjar/nsJAR.h index dd2bd441bb9..043f2f82f80 100644 --- a/mozilla/modules/libjar/nsJAR.h +++ b/mozilla/modules/libjar/nsJAR.h @@ -37,7 +37,6 @@ #include "prtypes.h" #include "prinrval.h" -#include "nsRepository.h" #include "nsIComponentManager.h" #include "nsCOMPtr.h" #include "nsString.h" diff --git a/mozilla/modules/plugin/base/public/nsplugin.h b/mozilla/modules/plugin/base/public/nsplugin.h index b4774b71b37..57da59aa3e3 100644 --- a/mozilla/modules/plugin/base/public/nsplugin.h +++ b/mozilla/modules/plugin/base/public/nsplugin.h @@ -82,8 +82,6 @@ #ifndef nsplugins_h___ #define nsplugins_h___ - -#include "nsRepository.h" // for NSGetFactory #include "nsIComponentManager.h" // for NSGetFactory //////////////////////////////////////////////////////////////////////////////// diff --git a/mozilla/netwerk/base/tests/urltest.cpp b/mozilla/netwerk/base/tests/urltest.cpp index ca4fc19c08f..39bf03ebf78 100644 --- a/mozilla/netwerk/base/tests/urltest.cpp +++ b/mozilla/netwerk/base/tests/urltest.cpp @@ -39,7 +39,7 @@ #include "nsIStreamListener.h" #include "nsIInputStream.h" #include "nsINetService.h" -#include "nsRepository.h" +#include "nsIComponentManager.h" #include "nsIServiceManager.h" #include "nsIEventQueueService.h" #include "nsString.h" diff --git a/mozilla/plugin/oji/MRJ/plugin/Source/MRJPlugin.cpp b/mozilla/plugin/oji/MRJ/plugin/Source/MRJPlugin.cpp index 036de9d59bb..fa3ad7ad508 100644 --- a/mozilla/plugin/oji/MRJ/plugin/Source/MRJPlugin.cpp +++ b/mozilla/plugin/oji/MRJ/plugin/Source/MRJPlugin.cpp @@ -36,7 +36,7 @@ #include "nsIServiceManager.h" #include "nsMemory.h" -#include "nsRepository.h" +#include "nsIComponentManager.h" #include "nsIJVMManager.h" #include "nsIJVMPluginTagInfo.h" #include "nsIPluginManager2.h" diff --git a/mozilla/profile/pref-migrator/src/nsPrefMigration.cpp b/mozilla/profile/pref-migrator/src/nsPrefMigration.cpp index c73a5877238..f34ae455603 100644 --- a/mozilla/profile/pref-migrator/src/nsPrefMigration.cpp +++ b/mozilla/profile/pref-migrator/src/nsPrefMigration.cpp @@ -24,7 +24,7 @@ */ #include "pratom.h" -#include "nsRepository.h" +#include "nsIComponentManager.h" #include "nsIAppShellService.h" #include "nsAppShellCIDs.h" #include "nsIComponentManager.h" diff --git a/mozilla/webshell/embed/xlib/gtk/nsEmbedXlibIntoGtk.cpp b/mozilla/webshell/embed/xlib/gtk/nsEmbedXlibIntoGtk.cpp index 68f51a6a02a..b4ddd2bfd5f 100644 --- a/mozilla/webshell/embed/xlib/gtk/nsEmbedXlibIntoGtk.cpp +++ b/mozilla/webshell/embed/xlib/gtk/nsEmbedXlibIntoGtk.cpp @@ -34,7 +34,7 @@ extern "C" { #include "nsIUnixToolkitService.h" #include "nsIWebShell.h" #include "nsIContentViewer.h" -#include "nsRepository.h" +#include "nsIComponentManager.h" #include "nsIPref.h" #include "xlibrgb.h" diff --git a/mozilla/webshell/embed/xlib/motif/nsEmbedXlibIntoMotif.cpp b/mozilla/webshell/embed/xlib/motif/nsEmbedXlibIntoMotif.cpp index 2e94ec3ee6f..1bc3b1b14b5 100644 --- a/mozilla/webshell/embed/xlib/motif/nsEmbedXlibIntoMotif.cpp +++ b/mozilla/webshell/embed/xlib/motif/nsEmbedXlibIntoMotif.cpp @@ -10,7 +10,7 @@ #include "nsIXlibWindowService.h" #include "nsIUnixToolkitService.h" #include "nsIWebShell.h" -#include "nsRepository.h" +#include "nsIComponentManager.h" #include "nsIPref.h" #include "xlibrgb.h" diff --git a/mozilla/webshell/embed/xlib/qt/QMozillaContainer.cpp b/mozilla/webshell/embed/xlib/qt/QMozillaContainer.cpp index ce7293a6834..6a46833e13e 100644 --- a/mozilla/webshell/embed/xlib/qt/QMozillaContainer.cpp +++ b/mozilla/webshell/embed/xlib/qt/QMozillaContainer.cpp @@ -29,7 +29,7 @@ #include "nsIXlibWindowService.h" #include "nsIUnixToolkitService.h" #include "nsIWebShell.h" -#include "nsRepository.h" +#include "nsIComponentManager.h" #include "nsIPref.h" #include "xlibrgb.h" diff --git a/mozilla/webshell/embed/xlib/xt/nsEmbedXlibIntoXt.cpp b/mozilla/webshell/embed/xlib/xt/nsEmbedXlibIntoXt.cpp index 7e50718ea5f..fbd054a0355 100644 --- a/mozilla/webshell/embed/xlib/xt/nsEmbedXlibIntoXt.cpp +++ b/mozilla/webshell/embed/xlib/xt/nsEmbedXlibIntoXt.cpp @@ -36,7 +36,7 @@ #include "nsIXlibWindowService.h" #include "nsIUnixToolkitService.h" #include "nsIWebShell.h" -#include "nsRepository.h" +#include "nsIComponentManager.h" #include "nsIPref.h" #include "xlibrgb.h" diff --git a/mozilla/widget/src/xpwidgets/nsHTMLFormatConverter.cpp b/mozilla/widget/src/xpwidgets/nsHTMLFormatConverter.cpp index 2a2c30d7b08..7e126aa6e74 100644 --- a/mozilla/widget/src/xpwidgets/nsHTMLFormatConverter.cpp +++ b/mozilla/widget/src/xpwidgets/nsHTMLFormatConverter.cpp @@ -23,7 +23,7 @@ #include "nsString.h" #include "nsISupportsArray.h" -#include "nsRepository.h" +#include "nsIComponentManager.h" #include "nsCOMPtr.h" #include "nsISupportsPrimitives.h" #include "nsXPIDLString.h" diff --git a/mozilla/xpcom/build/nsXPComInit.cpp b/mozilla/xpcom/build/nsXPComInit.cpp index 4a5a5c613e5..da06812143c 100644 --- a/mozilla/xpcom/build/nsXPComInit.cpp +++ b/mozilla/xpcom/build/nsXPComInit.cpp @@ -282,50 +282,31 @@ nsresult NS_COM NS_InitXPCOM2(nsIServiceManager* *result, StartupSpecialSystemDirectory(); - // 1. Create the Global Service Manager - nsIServiceManager* servMgr = NULL; - if (gServiceManager == NULL) - { - rv = NS_NewServiceManager(&servMgr); - if (NS_FAILED(rv)) return rv; - gServiceManager = servMgr; - if (result) - { - NS_ADDREF(servMgr); - *result = servMgr; - } - } - - // 2. Create the Component Manager and register with global service manager - // It is understood that the component manager can use the global service manager. - nsComponentManagerImpl *compMgr = NULL; + // Start the directory service so that the component manager init can use it. + rv = nsDirectoryService::Create(nsnull, + NS_GET_IID(nsIProperties), + (void**)&gDirectoryService); + if (NS_FAILED(rv)) + return rv; + + nsCOMPtr dirService = do_QueryInterface(gDirectoryService, &rv); + if (NS_FAILED(rv)) + return rv; + rv = dirService->Init(); + if (NS_FAILED(rv)) + return rv; + // Create the Component/Service Manager + nsComponentManagerImpl *compMgr = NULL; + if (nsComponentManagerImpl::gComponentManager == NULL) { compMgr = new nsComponentManagerImpl(); if (compMgr == NULL) return NS_ERROR_OUT_OF_MEMORY; NS_ADDREF(compMgr); - - rv = nsDirectoryService::Create(nsnull, - NS_GET_IID(nsIProperties), - (void**)&gDirectoryService); - if (NS_FAILED(rv)) - return rv; - - nsCOMPtr dirService = do_QueryInterface(gDirectoryService); - - if (!dirService) - return NS_ERROR_NO_INTERFACE; - - rv = dirService->Init(); - - if (NS_FAILED(rv)) - return rv; - PRBool value; - if (binDirectory) { rv = binDirectory->IsDirectory(&value); @@ -358,14 +339,15 @@ nsresult NS_COM NS_InitXPCOM2(nsIServiceManager* *result, return rv; } + gServiceManager = NS_STATIC_CAST(nsIServiceManager*, compMgr); nsComponentManagerImpl::gComponentManager = compMgr; } nsCOMPtr memory = getter_AddRefs(nsMemory::GetGlobalMemoryService()); - rv = servMgr->RegisterService(kMemoryCID, memory); + rv = gServiceManager->RegisterService(kMemoryCID, memory); if (NS_FAILED(rv)) return rv; - rv = servMgr->RegisterService(kComponentManagerCID, NS_STATIC_CAST(nsIComponentManager*, compMgr)); + rv = gServiceManager->RegisterService(kComponentManagerCID, NS_STATIC_CAST(nsIComponentManager*, compMgr)); if (NS_FAILED(rv)) return rv; #ifdef GC_LEAK_DETECTOR @@ -373,7 +355,7 @@ nsresult NS_COM NS_InitXPCOM2(nsIServiceManager* *result, if (NS_FAILED(rv)) return rv; #endif - // 3. Register the global services with the component manager so that + // 2. Register the global services with the component manager so that // clients can create new objects. // Registry diff --git a/mozilla/xpcom/build/win32.order b/mozilla/xpcom/build/win32.order index f68dd313e73..08677854885 100644 --- a/mozilla/xpcom/build/win32.order +++ b/mozilla/xpcom/build/win32.order @@ -1397,7 +1397,6 @@ NS_NewUnicodeLocalFile ; 2 ??_EnsAppFileLocationProvider@@MAEPAXI@Z ; 1 ??_EnsVoidArray@@UAEPAXI@Z ; 1 ??RnsGetServiceFromCategory@@UBEIABUnsID@@PAPAX@Z ; 1 -?NS_NewServiceManager@@YAIPAPAVnsIServiceManager@@@Z ; 1 ??0nsIOFileStream@@QAE@ABVnsFileSpec@@HH@Z ; 1 ?NS_PurgeAtomTable@@YAXXZ ; 1 ??0nsProxyObjectManager@@QAE@XZ ; 1 diff --git a/mozilla/xpcom/components/MANIFEST b/mozilla/xpcom/components/MANIFEST index f5ee38a8942..a7d78fc9c80 100644 --- a/mozilla/xpcom/components/MANIFEST +++ b/mozilla/xpcom/components/MANIFEST @@ -1,7 +1,6 @@ nsIGenericFactory.h nsIRegistryUtils.h nsIServiceManager.h -nsRepository.h nsXPComFactory.h nsComponentManagerUtils.h nsStaticComponent.h diff --git a/mozilla/xpcom/components/Makefile.in b/mozilla/xpcom/components/Makefile.in index 8d83f7f8f9c..49cf00ec223 100644 --- a/mozilla/xpcom/components/Makefile.in +++ b/mozilla/xpcom/components/Makefile.in @@ -36,8 +36,6 @@ CPPSRCS = \ nsGenericFactory.cpp \ nsNativeComponentLoader.cpp \ nsRegistry.cpp \ - nsRepository.cpp \ - nsServiceManager.cpp \ nsCategoryManager.cpp \ xcDll.cpp \ $(NULL) @@ -53,7 +51,6 @@ EXPORTS = \ nsIGenericFactory.h \ nsIRegistryUtils.h \ nsIServiceManager.h \ - nsRepository.h \ nsXPComFactory.h \ nsStaticComponent.h \ $(NULL) diff --git a/mozilla/xpcom/components/makefile.win b/mozilla/xpcom/components/makefile.win index a61917d2031..9628390425d 100644 --- a/mozilla/xpcom/components/makefile.win +++ b/mozilla/xpcom/components/makefile.win @@ -34,7 +34,6 @@ EXPORTS = \ nsIGenericFactory.h \ nsIRegistryUtils.h \ nsIServiceManager.h \ - nsRepository.h \ nsXPComFactory.h \ nsNativeComponentLoader.h \ nsStaticComponent.h \ @@ -77,8 +76,6 @@ CPP_OBJS = \ .\$(OBJDIR)\nsNativeComponentLoader.obj \ .\$(OBJDIR)\nsStaticComponentLoader.obj \ .\$(OBJDIR)\nsRegistry.obj \ - .\$(OBJDIR)\nsRepository.obj \ - .\$(OBJDIR)\nsServiceManager.obj \ .\$(OBJDIR)\nsCategoryManager.obj \ .\$(OBJDIR)\xcDll.obj \ $(NULL) diff --git a/mozilla/xpcom/components/nsComponentManager.cpp b/mozilla/xpcom/components/nsComponentManager.cpp index d0a314c8a13..5e89a2c64a6 100644 --- a/mozilla/xpcom/components/nsComponentManager.cpp +++ b/mozilla/xpcom/components/nsComponentManager.cpp @@ -84,6 +84,8 @@ #include "prlog.h" PRLogModuleInfo* nsComponentManagerLog = NULL; +#include "nsAutoLock.h" + // Enable printing of critical errors on screen even for release builds #define PRINT_CRITICAL_ERROR_TO_SCREEN @@ -119,16 +121,29 @@ const char XPCOM_LIB_PREFIX[] = "lib:"; // This is used to mark non-existent contractid mappings static nsFactoryEntry * kNonExistentContractID = (nsFactoryEntry*) 1; + + +#define NS_EMPTY_IID \ +{ \ + 0x00000000, \ + 0x0000, \ + 0x0000, \ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} \ +} + +NS_DEFINE_CID(kEmptyCID, NS_EMPTY_IID); + + +nsIServiceManager* gServiceManager = NULL; +PRBool gShuttingDown = PR_FALSE; + // Build is using USE_NSREG to turn off xpcom using registry // but internally we use USE_REGISTRY. Map them propertly. #ifdef USE_NSREG #define USE_REGISTRY #endif /* USE_NSREG */ - -extern PRBool gShuttingDown; nsresult - nsCreateInstanceByCID::operator()( const nsIID& aIID, void** aInstancePtr ) const { nsresult status = nsComponentManager::CreateInstance(mCID, mOuter, aIID, aInstancePtr); @@ -198,26 +213,248 @@ nsCreateInstanceFromCategory::operator()( const nsIID& aIID, return status; } + +nsresult +nsGetServiceByCID::operator()( const nsIID& aIID, void** aInstancePtr ) const + { + nsresult status; + // Too bad |nsServiceManager| isn't an |nsIServiceManager|, then this could have been one call + if ( mServiceManager ) + status = mServiceManager->GetService(mCID, aIID, NS_REINTERPRET_CAST(nsISupports**, aInstancePtr), 0); + else + status = nsServiceManager::GetService(mCID, aIID, NS_REINTERPRET_CAST(nsISupports**, aInstancePtr), 0); + + if ( !NS_SUCCEEDED(status) ) + *aInstancePtr = 0; + + if ( mErrorPtr ) + *mErrorPtr = status; + return status; + } + +nsresult +nsGetServiceByContractID::operator()( const nsIID& aIID, void** aInstancePtr ) const + { + nsresult status; + if ( mContractID ) + { + // Too bad |nsServiceManager| isn't an |nsIServiceManager|, then this could have been one call + if ( mServiceManager ) + status = mServiceManager->GetService(mContractID, aIID, NS_REINTERPRET_CAST(nsISupports**, aInstancePtr), 0); + else + status = nsServiceManager::GetService(mContractID, aIID, NS_REINTERPRET_CAST(nsISupports**, aInstancePtr), 0); + + if ( !NS_SUCCEEDED(status) ) + *aInstancePtr = 0; + } + else + status = NS_ERROR_NULL_POINTER; + + if ( mErrorPtr ) + *mErrorPtr = status; + return status; + } + +nsresult +nsGetServiceFromCategory::operator()( const nsIID& aIID, void** aInstancePtr) + const +{ + nsresult status; + nsXPIDLCString value; + nsCOMPtr catman = + do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &status); + + if (NS_FAILED(status)) goto error; + + if (!mCategory || !mEntry) { + // when categories have defaults, use that for null mEntry + status = NS_ERROR_NULL_POINTER; + goto error; + } + + /* find the contractID for category.entry */ + status = catman->GetCategoryEntry(mCategory, mEntry, + getter_Copies(value)); + if (NS_FAILED(status)) goto error; + if (!value) { + status = NS_ERROR_SERVICE_NOT_FOUND; + goto error; + } + + // Too bad |nsServiceManager| isn't an |nsIServiceManager|, then + // this could have been one call. + if ( mServiceManager ) + status = + mServiceManager->GetService(value, aIID, + NS_REINTERPRET_CAST(nsISupports**, + aInstancePtr), 0); + else + status = + nsServiceManager::GetService(value, aIID, + NS_REINTERPRET_CAST(nsISupports**, + aInstancePtr), 0); + if (NS_FAILED(status)) { + error: + *aInstancePtr = 0; + } + + *mErrorPtr = status; + return status; +} + + +/* + * CreateServicesFromCategory() + * + * Given a category, this convenience functions enumerates the category and + * creates a service of every CID or ContractID registered under the category. + * If observerTopic is non null and the service implements nsIObserver, + * this will attempt to notify the observer with the origin, observerTopic string + * as parameter. + */ +nsresult +NS_CreateServicesFromCategory(const char *category, + nsISupports *origin, + const PRUnichar *observerTopic) +{ + nsresult rv = NS_OK; + + int nFailed = 0; + nsCOMPtr categoryManager = + do_GetService("@mozilla.org/categorymanager;1", &rv); + if (!categoryManager) return rv; + + nsCOMPtr enumerator; + rv = categoryManager->EnumerateCategory(category, + getter_AddRefs(enumerator)); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr entry; + while (NS_SUCCEEDED(enumerator->GetNext(getter_AddRefs(entry)))) { + // From here on just skip any error we get. + nsCOMPtr catEntry = do_QueryInterface(entry, &rv); + if (NS_FAILED(rv)) { + nFailed++; + continue; + } + nsXPIDLCString entryString; + rv = catEntry->GetData(getter_Copies(entryString)); + if (NS_FAILED(rv)) { + nFailed++; + continue; + } + nsXPIDLCString contractID; + rv = categoryManager->GetCategoryEntry(category,(const char *)entryString, getter_Copies(contractID)); + if (NS_FAILED(rv)) { + nFailed++; + continue; + } + + nsCOMPtr instance = do_GetService(contractID, &rv); + if (NS_FAILED(rv)) { + nFailed++; + continue; + } + + if (observerTopic) { + // try an observer, if it implements it. + nsCOMPtr observer = do_QueryInterface(instance, &rv); + if (NS_SUCCEEDED(rv) && observer) + observer->Observe(origin, observerTopic, NS_LITERAL_STRING("").get()); + } + } + return (nFailed ? NS_ERROR_FAILURE : NS_OK); +} + /* prototypes for the Mac */ PRBool PR_CALLBACK nsFactoryEntry_Destroy(nsHashKey *aKey, void *aData, void* closure); + + +nsServiceEntry::nsServiceEntry(nsISupports* service, nsFactoryEntry* factEntry) + : mObject(service), + mListeners(NULL), + mShuttingDown(PR_FALSE), + mFactoryEntry(factEntry) +{ + NS_ASSERTION(mObject, "Service Entry initialized with null service"); + NS_IF_ADDREF(mObject); +} + +nsServiceEntry::~nsServiceEntry() +{ + NotifyListeners(); + + //special case the nsComponentManagerImpl. + // XXX review-notes we need to see why we need to do this + if ((void*)mObject != (void*)nsComponentManagerImpl::gComponentManager) + NS_IF_RELEASE(mObject); +} + +nsresult +nsServiceEntry::AddListener(nsIShutdownListener* listener) +{ + if (listener == NULL) + return NS_OK; + if (mListeners == NULL) { + mListeners = new nsVoidArray(); + if (mListeners == NULL) + return NS_ERROR_OUT_OF_MEMORY; + } + PRInt32 rv = mListeners->AppendElement(listener); + NS_ADDREF(listener); + return rv == -1 ? NS_ERROR_FAILURE : NS_OK; +} + +nsresult +nsServiceEntry::RemoveListener(nsIShutdownListener* listener) +{ + if (listener == NULL) + return NS_OK; + NS_ASSERTION(mListeners, "no listeners added yet"); + if ( mListeners->RemoveElement(listener) ) + return NS_OK; + NS_ASSERTION(0, "unregistered shutdown listener"); + return NS_ERROR_FAILURE; +} + +nsresult +nsServiceEntry::NotifyListeners(void) +{ + if (mListeners && mFactoryEntry) { + PRUint32 size = mListeners->Count(); + for (PRUint32 i = 0; i < size; i++) { + nsIShutdownListener* listener = (nsIShutdownListener*)(*mListeners)[0]; + nsresult rv = listener->OnShutdown(mFactoryEntry->cid, + mObject); + if (NS_FAILED(rv)) return rv; + NS_RELEASE(listener); + mListeners->RemoveElementAt(0); + } + NS_ASSERTION(mListeners->Count() == 0, "failed to notify all listeners"); + delete mListeners; + mListeners = NULL; + } + return NS_OK; +} + //////////////////////////////////////////////////////////////////////////////// // nsFactoryEntry //////////////////////////////////////////////////////////////////////////////// MOZ_DECL_CTOR_COUNTER(nsFactoryEntry) -nsFactoryEntry::nsFactoryEntry(const nsCID &aClass, const char *aLocation, +nsFactoryEntry::nsFactoryEntry(const nsCID &aClass, + const char *aLocation, int aType) - : cid(aClass), location(aLocation), factory(nsnull), typeIndex(aType) + : cid(aClass), location(aLocation), mServiceEntry(nsnull), typeIndex(aType) { MOZ_COUNT_CTOR(nsFactoryEntry); } nsFactoryEntry::nsFactoryEntry(const nsCID &aClass, nsIFactory *aFactory) - : cid(aClass), typeIndex(-1) - + : cid(aClass), mServiceEntry(nsnull), typeIndex(NS_COMPONENT_TYPE_FACTORY_ONLY) { MOZ_COUNT_CTOR(nsFactoryEntry); factory = aFactory; @@ -232,7 +469,7 @@ nsFactoryEntry::~nsFactoryEntry(void) nsresult nsFactoryEntry::ReInit(const nsCID &aClass, const char *aLocation, int aType) { - cid = aClass; + NS_ENSURE_TRUE(cid.Equals(aClass), NS_ERROR_INVALID_ARG); location = aLocation; typeIndex = aType; return NS_OK; @@ -241,9 +478,10 @@ nsFactoryEntry::ReInit(const nsCID &aClass, const char *aLocation, int aType) nsresult nsFactoryEntry::ReInit(const nsCID &aClass, nsIFactory *aFactory) { - cid = aClass; + NS_ENSURE_TRUE(cid.Equals(aClass), NS_ERROR_INVALID_ARG); + NS_ENSURE_TRUE(typeIndex >= 0, NS_ERROR_INVALID_ARG); factory = aFactory; - typeIndex = -1; + typeIndex = NS_COMPONENT_TYPE_FACTORY_ONLY; return NS_OK; } //////////////////////////////////////////////////////////////////////////////// @@ -254,20 +492,35 @@ nsFactoryEntry::ReInit(const nsCID &aClass, nsIFactory *aFactory) nsComponentManagerImpl::nsComponentManagerImpl() : mFactories(NULL), mContractIDs(NULL), mMon(NULL), mRegistry(NULL), mPrePopulationDone(PR_FALSE), - mNativeComponentLoader(0), mStaticComponentLoader(0), + mNativeComponentLoader(0), + mStaticComponentLoader(0), mShuttingDown(NS_SHUTDOWN_NEVERHAPPENED), mLoaderData(nsnull) { NS_INIT_REFCNT(); } -PRBool -nsFactoryEntry_Destroy(nsHashKey *aKey, void *aData, void* closure) +static PRBool +nsFactoryEntry_mFactoryDestroy(nsHashKey *aKey, void *aData, void* closure) { nsFactoryEntry* entry = NS_STATIC_CAST(nsFactoryEntry*, aData); delete entry; return PR_TRUE; } +static PRBool +nsFactoryEntry_mContractIDsDestory(nsHashKey *aKey, void *aData, void* closure) +{ + nsFactoryEntry* entry = NS_STATIC_CAST(nsFactoryEntry*, aData); + if (entry != kNonExistentContractID && + entry->typeIndex == NS_COMPONENT_TYPE_SERVICE_ONLY && + entry->cid.Equals(kEmptyCID)) { + // this object is owned by the hash. Time to delete it. + delete entry; + } + return PR_TRUE; +} + + nsresult nsComponentManagerImpl::Init(void) { PR_ASSERT(mShuttingDown != NS_SHUTDOWN_INPROGRESS); @@ -285,16 +538,17 @@ nsresult nsComponentManagerImpl::Init(void) if (mFactories == NULL) { mFactories = new nsObjectHashtable(nsnull, nsnull, // should never be copied - nsFactoryEntry_Destroy, nsnull, + nsFactoryEntry_mFactoryDestroy, nsnull, 256, /* Thread Safe */ PR_TRUE); if (mFactories == NULL) return NS_ERROR_OUT_OF_MEMORY; } if (mContractIDs == NULL) { - // No destroy function for these as they hold weak references to the factory entry. + // This hashtable holds references to the factory entry. All entries are non-owning + // unless the typeIndex is NS_COMPONENT_TYPE_SERVICE_ONLY. // The owning ref is from the mFactories hash table. mContractIDs = new nsObjectHashtable(nsnull, nsnull, // should never be copied - nsnull, nsnull, + nsFactoryEntry_mContractIDsDestory, nsnull, 256, /* Thread Safe */ PR_TRUE); if (mContractIDs == NULL) return NS_ERROR_OUT_OF_MEMORY; @@ -369,16 +623,11 @@ nsresult nsComponentManagerImpl::Shutdown(void) PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS, ("nsComponentManager: Beginning Shutdown.")); // Release all cached factories - if (mFactories) - delete mFactories; - + delete mContractIDs; + delete mFactories; // Unload libraries UnloadLibraries(NULL, NS_Shutdown); - // Release Contractid hash tables - if (mContractIDs) - delete mContractIDs; - #ifdef USE_REGISTRY // Release registry NS_IF_RELEASE(mRegistry); @@ -427,8 +676,11 @@ nsComponentManagerImpl::~nsComponentManagerImpl() PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS, ("nsComponentManager: Destroyed.")); } -NS_IMPL_ISUPPORTS3(nsComponentManagerImpl, nsIComponentManager, - nsISupportsWeakReference, nsIInterfaceRequestor) +NS_IMPL_ISUPPORTS4(nsComponentManagerImpl, + nsIComponentManager, + nsIServiceManager, + nsISupportsWeakReference, + nsIInterfaceRequestor) //////////////////////////////////////////////////////////////////////////////// // nsComponentManagerImpl: Platform methods @@ -763,7 +1015,7 @@ nsComponentManagerImpl::PlatformFind(const nsCID &aCID, nsFactoryEntry* *result) rv = mRegistry->GetStringUTF8(cidKey, componentTypeValueName, getter_Copies(componentTypeStr)); const char* componentType = componentTypeStr.get(); - int type = -1; + int type = NS_COMPONENT_TYPE_FACTORY_ONLY; if (NS_FAILED(rv)) { if (rv == NS_ERROR_REG_NOT_FOUND) { @@ -1354,6 +1606,385 @@ nsComponentManagerImpl::CreateInstanceByContractID(const char *aContractID, return res; } +// Service Manager Impl + +static PRBool FreeServiceEntry(nsHashKey *aKey, void *aData, void* aClosure) +{ + nsFactoryEntry* entry = NS_STATIC_CAST(nsFactoryEntry*, aData); + + if (!entry || entry == kNonExistentContractID) + return PR_TRUE; + + if (entry->mServiceEntry) { + delete entry->mServiceEntry; + entry->mServiceEntry = nsnull; + } + return PR_TRUE; +} + +nsresult +nsComponentManagerImpl::FreeServices() +{ + if (mFactories) + mFactories->Enumerate(FreeServiceEntry); + + if (mContractIDs) + mContractIDs->Enumerate(FreeServiceEntry); + + return NS_OK; +} +NS_IMETHODIMP +nsComponentManagerImpl::GetService(const nsCID& aClass, const nsIID& aIID, + nsISupports* *result, + nsIShutdownListener* shutdownListener) +{ + nsAutoMonitor mon(mMon); + + // test this first, since there's no point in returning a service during + // shutdown -- whether it's available or not would depend on the order it + // occurs in the list + if (gShuttingDown) { + // When processing shutdown, dont process new GetService() requests + NS_WARNING("Creating new service on shutdown. Denied."); + return NS_ERROR_UNEXPECTED; + } + + nsresult rv = NS_OK; + nsIDKey key(aClass); + nsFactoryEntry* entry = (nsFactoryEntry*)mFactories->Get(&key); + nsServiceEntry* serviceEntry; + if (entry && entry->mServiceEntry) { + serviceEntry = entry->mServiceEntry; + + if (!serviceEntry->mObject) + return NS_ERROR_NULL_POINTER; + + nsISupports* service; // keep as raw point (avoid extra addref/release) + rv = serviceEntry->mObject->QueryInterface(aIID, (void**)&service); + if (NS_SUCCEEDED(rv)) { + // The refcount acquired in QI() above is "returned" to + // the caller. + if (shutdownListener) { + rv = serviceEntry->AddListener(shutdownListener); + if (NS_FAILED(rv)) { + NS_RELEASE(service); + return rv; + } + } + + *result = service; + + // If someone else requested the service to be shut down, + // and we just asked to get it again before it could be + // released, then cancel their shutdown request: + if (serviceEntry->mShuttingDown) { + serviceEntry->mShuttingDown = PR_FALSE; + NS_ADDREF(service); // Released in UnregisterService + } + } + return rv; + } + + nsISupports* service; + // We need to not be holding the service manager's monitor while calling + // CreateInstance, because it invokes user code which could try to re-enter + // the service manager: + mon.Exit(); + rv = CreateInstance(aClass, NULL, aIID, (void**)&service); + mon.Enter(); + + if (NS_FAILED(rv)) + return rv; + + if (!entry) { // second hash lookup for GetService + entry = (nsFactoryEntry*)mFactories->Get(&key); + NS_ASSERTION(entry, "we should have a factory entry since CI succeeded - we should not get here"); + if (!entry) return NS_ERROR_FAILURE; + } + + serviceEntry = new nsServiceEntry(service, entry); + if (serviceEntry == NULL) { + NS_RELEASE(service); + return NS_ERROR_OUT_OF_MEMORY; + } + + if (shutdownListener) { + rv = serviceEntry->AddListener(shutdownListener); + if (NS_FAILED(rv)) { + NS_RELEASE(service); + delete serviceEntry; + return rv; + } + } + entry->mServiceEntry = serviceEntry; // deleted in nsFactoryEntry's destructor + *result = service; // transfer ownership + return rv; +} + +NS_IMETHODIMP +nsComponentManagerImpl::ReleaseService(const nsCID& aClass, nsISupports* service, + nsIShutdownListener* shutdownListener) +{ + PRBool serviceFound = PR_FALSE; + nsresult rv = NS_OK; + +#ifndef NS_DEBUG + // Do entry lookup only if there is a shutdownlistener to be removed. + // + // For Debug builds, Consistency check for entry always. Releasing service + // when the service is not with the servicemanager is mostly wrong. + if (shutdownListener) +#endif + { + nsAutoMonitor mon(mMon); + nsIDKey key(aClass); + nsFactoryEntry* entry = (nsFactoryEntry*)mFactories->Get(&key); + + if (entry && entry->mServiceEntry) { + rv = entry->mServiceEntry->RemoveListener(shutdownListener); + serviceFound = PR_TRUE; + } + } + + nsrefcnt cnt; + NS_RELEASE2(service, cnt); + + // Consistency check: Service ref count cannot go to zero because of the + // extra addref the service manager does, unless the service has been + // unregistered (ie) not found in the service managers hash table. + // + NS_ASSERTION(cnt > 0 || !serviceFound, + "*** Service in hash table but is being deleted. Dangling pointer\n" + "*** in service manager hash table."); + + return rv; +} + + +NS_IMETHODIMP +nsComponentManagerImpl::RegisterService(const nsCID& aClass, nsISupports* aService) +{ + nsAutoMonitor mon(mMon); + + // check to see if we have a factory entry for the service + nsIDKey key(aClass); + nsFactoryEntry *entry = GetFactoryEntry(aClass, key, 0); + + if (!entry) { // XXXdougt - should we require that all services register factories?? probably not. + entry = new nsFactoryEntry(aClass, nsnull); + if (entry == NULL) + return NS_ERROR_OUT_OF_MEMORY; + entry->typeIndex = NS_COMPONENT_TYPE_SERVICE_ONLY; + mFactories->Put(&key, entry); + } + else { + if (entry->mServiceEntry) + return NS_ERROR_FAILURE; + } + + nsServiceEntry *serviceEntry = new nsServiceEntry(aService, entry); //owns a ref to aService + if (serviceEntry == NULL) + return NS_ERROR_OUT_OF_MEMORY; + + entry->mServiceEntry = serviceEntry; + return NS_OK; +} + +NS_IMETHODIMP +nsComponentManagerImpl::UnregisterService(const nsCID& aClass) +{ + nsresult rv = NS_OK; + nsAutoMonitor mon(mMon); + + nsIDKey key(aClass); + nsFactoryEntry* entry = (nsFactoryEntry*)mFactories->Get(&key); + + if (entry == NULL || entry->mServiceEntry == NULL) + return NS_ERROR_SERVICE_NOT_FOUND; + + delete entry->mServiceEntry; + entry->mServiceEntry = nsnull; + return rv; +} + +NS_IMETHODIMP +nsComponentManagerImpl::RegisterService(const char* aContractID, nsISupports* aService) +{ + nsAutoMonitor mon(mMon); + + // check to see if we have a factory entry for the service + nsCStringKey key(aContractID); + nsFactoryEntry *entry = GetFactoryEntry(aContractID, 0); + + if (entry == kNonExistentContractID) + entry = nsnull; + + if (!entry) { // XXXdougt - should we require that all services register factories?? probably not. + entry = new nsFactoryEntry(kEmptyCID, nsnull); + if (entry == NULL) + return NS_ERROR_OUT_OF_MEMORY; + entry->typeIndex = NS_COMPONENT_TYPE_SERVICE_ONLY; + mContractIDs->Put(&key, entry); + } + else { + if (entry->mServiceEntry) + return NS_ERROR_FAILURE; + } + + nsServiceEntry *serviceEntry = new nsServiceEntry(aService, entry); //owns a ref to aService + if (serviceEntry == NULL) + return NS_ERROR_OUT_OF_MEMORY; + + entry->mServiceEntry = serviceEntry; + return NS_OK; +} + +NS_IMETHODIMP +nsComponentManagerImpl::UnregisterService(const char* aContractID) +{ + nsresult rv = NS_OK; + nsAutoMonitor mon(mMon); + + nsCStringKey key(aContractID); + nsFactoryEntry* entry = (nsFactoryEntry*)mFactories->Get(&key); + + if (entry == NULL || entry == kNonExistentContractID || entry->mServiceEntry == NULL) + return NS_ERROR_SERVICE_NOT_FOUND; + + delete entry->mServiceEntry; + entry->mServiceEntry = nsnull; + return rv; +} + +NS_IMETHODIMP +nsComponentManagerImpl::GetService(const char* aContractID, const nsIID& aIID, + nsISupports* *result, + nsIShutdownListener* shutdownListener) +{ + nsAutoMonitor mon(mMon); + + // test this first, since there's no point in returning a service during + // shutdown -- whether it's available or not would depend on the order it + // occurs in the list + if (gShuttingDown) { + // When processing shutdown, dont process new GetService() requests + NS_WARNING("Creating new service on shutdown. Denied."); + return NS_ERROR_UNEXPECTED; + } + + nsresult rv = NS_OK; + nsCStringKey key(aContractID); + nsFactoryEntry *entry = (nsFactoryEntry *) mContractIDs->Get(&key); + nsServiceEntry* serviceEntry; + if (entry && entry != kNonExistentContractID && entry->mServiceEntry) { + serviceEntry = entry->mServiceEntry; + + if (!serviceEntry->mObject) + return NS_ERROR_NULL_POINTER; + + nsISupports* service; // keep as raw point (avoid extra addref/release) + rv = serviceEntry->mObject->QueryInterface(aIID, (void**)&service); + if (NS_SUCCEEDED(rv)) { + // The refcount acquired in QI() above is "returned" to + // the caller. + if (shutdownListener) { + rv = serviceEntry->AddListener(shutdownListener); + if (NS_FAILED(rv)) { + NS_RELEASE(service); + return rv; + } + } + + *result = service; + + // If someone else requested the service to be shut down, + // and we just asked to get it again before it could be + // released, then cancel their shutdown request: + if (serviceEntry->mShuttingDown) { + serviceEntry->mShuttingDown = PR_FALSE; + NS_ADDREF(service); // Released in UnregisterService + } + } + return rv; + } + + nsISupports* service; + // We need to not be holding the service manager's monitor while calling + // CreateInstance, because it invokes user code which could try to re-enter + // the service manager: + mon.Exit(); + rv = CreateInstanceByContractID(aContractID, NULL, aIID, (void**)&service); + mon.Enter(); + + if (NS_FAILED(rv)) + return rv; + + if (!entry) { // second hash lookup for GetService + entry = (nsFactoryEntry*)mContractIDs->Get(&key); + NS_ASSERTION(entry, "we should have a factory entry since CI succeeded - we should not get here"); + if (!entry) return NS_ERROR_FAILURE; + } + + serviceEntry = new nsServiceEntry(service, entry); + if (serviceEntry == NULL) { + NS_RELEASE(service); + return NS_ERROR_OUT_OF_MEMORY; + } + + if (shutdownListener) { + rv = serviceEntry->AddListener(shutdownListener); + if (NS_FAILED(rv)) { + NS_RELEASE(service); + delete serviceEntry; + return rv; + } + } + entry->mServiceEntry = serviceEntry; // deleted in nsFactoryEntry's destructor + *result = service; // transfer ownership + return rv; +} + +NS_IMETHODIMP +nsComponentManagerImpl::ReleaseService(const char* aContractID, nsISupports* service, + nsIShutdownListener* shutdownListener) +{ + PRBool serviceFound = PR_FALSE; + nsresult rv = NS_OK; + +#ifndef NS_DEBUG + // Do entry lookup only if there is a shutdownlistener to be removed. + // + // For Debug builds, Consistency check for entry always. Releasing service + // when the service is not with the servicemanager is mostly wrong. + if (shutdownListener) +#endif + { + nsAutoMonitor mon(mMon); + nsCStringKey key(aContractID); + nsFactoryEntry* entry = (nsFactoryEntry*)mContractIDs->Get(&key); + + if (entry && entry->mServiceEntry) { + rv = entry->mServiceEntry->RemoveListener(shutdownListener); + serviceFound = PR_TRUE; + } + } + + nsrefcnt cnt; + NS_RELEASE2(service, cnt); + + // Consistency check: Service ref count cannot go to zero because of the + // extra addref the service manager does, unless the service has been + // unregistered (ie) not found in the service managers hash table. + // + NS_ASSERTION(cnt > 0 || !serviceFound, + "*** Service in hash table but is being deleted. Dangling pointer\n" + "*** in service manager hash table."); + + return rv; +} + + + /* * I want an efficient way to allocate a buffer to the right size * and stick the prefix and dllName in, then be able to hand that buffer @@ -2310,7 +2941,7 @@ nsComponentManagerImpl::GetLoaderType(const char *typeStr) return i; } // Not found - return -1; + return NS_COMPONENT_TYPE_FACTORY_ONLY; } // Add a loader type if not already known. Return the typeIndex @@ -2369,4 +3000,364 @@ NS_GetGlobalComponentManager(nsIComponentManager* *result) return rv; } + + +//////////////////////////////////////////////////////////////////////////////// +// Global component manager interface + +nsresult +nsComponentManager::Initialize(void) +{ + return NS_OK; +} + +nsresult +nsComponentManager::FindFactory(const nsCID &aClass, + nsIFactory **aFactory) +{ + nsIComponentManager* cm; + nsresult rv = NS_GetGlobalComponentManager(&cm); + if (NS_FAILED(rv)) return rv; + return cm->FindFactory(aClass, aFactory); +} + +nsresult +nsComponentManager::GetClassObject(const nsCID &aClass, const nsIID &aIID, + void **aResult) +{ + nsIComponentManager* cm; + nsresult rv = NS_GetGlobalComponentManager(&cm); + if (NS_FAILED(rv)) return rv; + return cm->GetClassObject(aClass, aIID, aResult); +} + +nsresult +nsComponentManager::ContractIDToClassID(const char *aContractID, + nsCID *aClass) +{ + nsIComponentManager* cm; + nsresult rv = NS_GetGlobalComponentManager(&cm); + if (NS_FAILED(rv)) return rv; + return cm->ContractIDToClassID(aContractID, aClass); +} + +nsresult +nsComponentManager::CLSIDToContractID(nsCID *aClass, + char* *aClassName, + char* *aContractID) +{ + nsIComponentManager* cm; + nsresult rv = NS_GetGlobalComponentManager(&cm); + if (NS_FAILED(rv)) return rv; + return cm->CLSIDToContractID(*aClass, aClassName, aContractID); +} + +nsresult +nsComponentManager::CreateInstance(const nsCID &aClass, + nsISupports *aDelegate, + const nsIID &aIID, + void **aResult) +{ + nsIComponentManager* cm; + nsresult rv = NS_GetGlobalComponentManager(&cm); + if (NS_FAILED(rv)) return rv; + return cm->CreateInstance(aClass, aDelegate, aIID, aResult); +} + +nsresult +nsComponentManager::CreateInstance(const char *aContractID, + nsISupports *aDelegate, + const nsIID &aIID, + void **aResult) +{ + nsIComponentManager* cm; + nsresult rv = NS_GetGlobalComponentManager(&cm); + if (NS_FAILED(rv)) return rv; + return cm->CreateInstanceByContractID(aContractID, aDelegate, aIID, aResult); +} + +nsresult +nsComponentManager::RegisterFactory(const nsCID &aClass, + const char *aClassName, + const char *aContractID, + nsIFactory *aFactory, + PRBool aReplace) +{ + nsIComponentManager* cm; + nsresult rv = NS_GetGlobalComponentManager(&cm); + if (NS_FAILED(rv)) return rv; + return cm->RegisterFactory(aClass, aClassName, aContractID, + aFactory, aReplace); +} + +nsresult +nsComponentManager::RegisterComponent(const nsCID &aClass, + const char *aClassName, + const char *aContractID, + const char *aLibraryPersistentDescriptor, + PRBool aReplace, + PRBool aPersist) +{ + nsIComponentManager* cm; + nsresult rv = NS_GetGlobalComponentManager(&cm); + if (NS_FAILED(rv)) return rv; + return cm->RegisterComponent(aClass, aClassName, aContractID, + aLibraryPersistentDescriptor, aReplace, aPersist); +} + +nsresult +nsComponentManager::RegisterComponentSpec(const nsCID &aClass, + const char *aClassName, + const char *aContractID, + nsIFile *aLibrary, + PRBool aReplace, + PRBool aPersist) +{ + nsIComponentManager* cm; + nsresult rv = NS_GetGlobalComponentManager(&cm); + if (NS_FAILED(rv)) return rv; + return cm->RegisterComponentSpec(aClass, aClassName, aContractID, + aLibrary, aReplace, aPersist); +} + +nsresult +nsComponentManager::RegisterComponentLib(const nsCID &aClass, + const char *aClassName, + const char *aContractID, + const char *adllName, + PRBool aReplace, + PRBool aPersist) +{ + nsIComponentManager* cm; + nsresult rv = NS_GetGlobalComponentManager(&cm); + if (NS_FAILED(rv)) return rv; + return cm->RegisterComponentLib(aClass, aClassName, aContractID, + adllName, aReplace, aPersist); +} + +nsresult +nsComponentManager::UnregisterFactory(const nsCID &aClass, + nsIFactory *aFactory) +{ + nsIComponentManager* cm; + nsresult rv = NS_GetGlobalComponentManager(&cm); + if (NS_FAILED(rv)) return rv; + return cm->UnregisterFactory(aClass, aFactory); +} + +nsresult +nsComponentManager::UnregisterComponent(const nsCID &aClass, + const char *aLibrary) +{ + nsIComponentManager* cm; + nsresult rv = NS_GetGlobalComponentManager(&cm); + if (NS_FAILED(rv)) return rv; + return cm->UnregisterComponent(aClass, aLibrary); +} + +nsresult +nsComponentManager::UnregisterComponentSpec(const nsCID &aClass, + nsIFile *aLibrarySpec) +{ + nsIComponentManager* cm; + nsresult rv = NS_GetGlobalComponentManager(&cm); + if (NS_FAILED(rv)) return rv; + return cm->UnregisterComponentSpec(aClass, aLibrarySpec); +} + +nsresult +nsComponentManager::FreeLibraries(void) +{ + nsIComponentManager* cm; + nsresult rv = NS_GetGlobalComponentManager(&cm); + if (NS_FAILED(rv)) return rv; + return cm->FreeLibraries(); +} + +nsresult +nsComponentManager::AutoRegister(PRInt32 when, nsIFile *directory) +{ + nsIComponentManager* cm; + nsresult rv = NS_GetGlobalComponentManager(&cm); + if (NS_FAILED(rv)) return rv; + return cm->AutoRegister(when, directory); +} + +nsresult +nsComponentManager::AutoRegisterComponent(PRInt32 when, + nsIFile *fullname) +{ + nsIComponentManager* cm; + nsresult rv = NS_GetGlobalComponentManager(&cm); + if (NS_FAILED(rv)) return rv; + return cm->AutoRegisterComponent(when, fullname); +} + +nsresult +nsComponentManager::AutoUnregisterComponent(PRInt32 when, + nsIFile *fullname) +{ + nsIComponentManager* cm; + nsresult rv = NS_GetGlobalComponentManager(&cm); + if (NS_FAILED(rv)) return rv; + return cm->AutoUnregisterComponent(when, fullname); +} + +nsresult +nsComponentManager::IsRegistered(const nsCID &aClass, + PRBool *aRegistered) +{ + nsIComponentManager* cm; + nsresult rv = NS_GetGlobalComponentManager(&cm); + if (NS_FAILED(rv)) return rv; + return cm->IsRegistered(aClass, aRegistered); +} + +nsresult +nsComponentManager::EnumerateCLSIDs(nsIEnumerator** aEmumerator) +{ + nsIComponentManager* cm; + nsresult rv = NS_GetGlobalComponentManager(&cm); + if (NS_FAILED(rv)) return rv; + return cm->EnumerateCLSIDs(aEmumerator); +} + +nsresult +nsComponentManager::EnumerateContractIDs(nsIEnumerator** aEmumerator) +{ + nsIComponentManager* cm; + nsresult rv = NS_GetGlobalComponentManager(&cm); + if (NS_FAILED(rv)) return rv; + return cm->EnumerateContractIDs(aEmumerator); +} + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// Global service manager interface (see nsIServiceManager.h) + +nsresult +nsServiceManager::GetGlobalServiceManager(nsIServiceManager* *result) +{ + if (gShuttingDown) + return NS_ERROR_UNEXPECTED; + + nsresult rv = NS_OK; + if (gServiceManager == NULL) { + // XPCOM not initialized yet. Let us do initialization of our module. + rv = NS_InitXPCOM(NULL, NULL); + } + // No ADDREF as we are advicing no release of this. + if (NS_SUCCEEDED(rv)) + *result = gServiceManager; + + return rv; +} + +nsresult +nsServiceManager::ShutdownGlobalServiceManager(nsIServiceManager* *result) +{ + if (gServiceManager != NULL) { + nsrefcnt cnt; + + nsComponentManagerImpl* compImpl = NS_STATIC_CAST(nsComponentManagerImpl*, gServiceManager); + compImpl->FreeServices(); + + NS_RELEASE2(gServiceManager, cnt); + // the only reference at this point should be the component manager. + NS_ASSERTION(cnt == 1, "Service Manager being held past XPCOM shutdown."); + gServiceManager = NULL; + } + return NS_OK; +} + +nsresult +nsServiceManager::GetService(const nsCID& aClass, const nsIID& aIID, + nsISupports* *result, + nsIShutdownListener* shutdownListener) +{ + nsIServiceManager* mgr; + nsresult rv = GetGlobalServiceManager(&mgr); + if (NS_FAILED(rv)) return rv; + return mgr->GetService(aClass, aIID, result, shutdownListener); +} + +nsresult +nsServiceManager::ReleaseService(const nsCID& aClass, nsISupports* service, + nsIShutdownListener* shutdownListener) +{ + // Don't create the global service manager here because we might be shutting + // down, and releasing all the services in its destructor + if (gServiceManager) + return gServiceManager->ReleaseService(aClass, service, shutdownListener); + // If there wasn't a global service manager, just release the object: + NS_RELEASE(service); + return NS_OK; +} + +nsresult +nsServiceManager::RegisterService(const nsCID& aClass, nsISupports* aService) +{ + nsIServiceManager* mgr; + nsresult rv = GetGlobalServiceManager(&mgr); + if (NS_FAILED(rv)) return rv; + return mgr->RegisterService(aClass, aService); +} + +nsresult +nsServiceManager::UnregisterService(const nsCID& aClass) +{ + nsIServiceManager* mgr; + nsresult rv = GetGlobalServiceManager(&mgr); + if (NS_FAILED(rv)) return rv; + return mgr->UnregisterService(aClass); +} + +//////////////////////////////////////////////////////////////////////////////// +// let's do it again, this time with ContractIDs... + +nsresult +nsServiceManager::GetService(const char* aContractID, const nsIID& aIID, + nsISupports* *result, + nsIShutdownListener* shutdownListener) +{ + nsIServiceManager* mgr; + nsresult rv = GetGlobalServiceManager(&mgr); + if (NS_FAILED(rv)) return rv; + return mgr->GetService(aContractID, aIID, result, shutdownListener); +} + +nsresult +nsServiceManager::ReleaseService(const char* aContractID, nsISupports* service, + nsIShutdownListener* shutdownListener) +{ + // Don't create the global service manager here because we might + // be shutting down, and releasing all the services in its + // destructor + if (gServiceManager) + return gServiceManager->ReleaseService(aContractID, service, shutdownListener); + // If there wasn't a global service manager, just release the object: + NS_RELEASE(service); + return NS_OK; +} + +nsresult +nsServiceManager::RegisterService(const char* aContractID, nsISupports* aService) +{ + nsIServiceManager* mgr; + nsresult rv = GetGlobalServiceManager(&mgr); + if (NS_FAILED(rv)) return rv; + return mgr->RegisterService(aContractID, aService); +} + +nsresult +nsServiceManager::UnregisterService(const char* aContractID) +{ + // Don't create the global service manager here because we might + // be shutting down, and releasing all the services in its + // destructor + if (gServiceManager) + return gServiceManager->UnregisterService(aContractID); + return NS_OK; +} + //////////////////////////////////////////////////////////////////////////////// diff --git a/mozilla/xpcom/components/nsComponentManager.h b/mozilla/xpcom/components/nsComponentManager.h index 07a438caad2..cb77cbf0a6f 100644 --- a/mozilla/xpcom/components/nsComponentManager.h +++ b/mozilla/xpcom/components/nsComponentManager.h @@ -26,6 +26,7 @@ #include "nsIComponentLoader.h" #include "nsNativeComponentLoader.h" #include "nsIComponentManager.h" +#include "nsIServiceManager.h" #include "nsIFactory.h" #include "nsRegistry.h" #include "nsIInterfaceRequestor.h" @@ -52,19 +53,56 @@ extern "C" NS_EXPORT nsresult NS_RegistryGetFactory(nsIFactory** aFactory); // Predefined loader types. Do not change the numbers. // NATIVE should be 0 as it is being used as the first array index. #define NS_COMPONENT_TYPE_NATIVE 0 +#define NS_COMPONENT_TYPE_FACTORY_ONLY -1 +// this define means that the factory entry only has a ContractID +// to service mapping and has no cid mapping. +#define NS_COMPONENT_TYPE_SERVICE_ONLY -2 extern const char XPCOM_LIB_PREFIX[]; //////////////////////////////////////////////////////////////////////////////// class nsComponentManagerImpl - : public nsIComponentManager, public nsSupportsWeakReference, + : public nsIComponentManager, + public nsIServiceManager, + public nsSupportsWeakReference, public nsIInterfaceRequestor { public: NS_DECL_ISUPPORTS NS_DECL_NSICOMPONENTMANAGER NS_DECL_NSIINTERFACEREQUESTOR + // Service Manager + NS_IMETHOD + RegisterService(const nsCID& aClass, nsISupports* aService); + + NS_IMETHOD + UnregisterService(const nsCID& aClass); + + NS_IMETHOD + GetService(const nsCID& aClass, const nsIID& aIID, + nsISupports* *result, + nsIShutdownListener* shutdownListener = NULL); + + NS_IMETHOD + ReleaseService(const nsCID& aClass, nsISupports* service, + nsIShutdownListener* shutdownListener = NULL); + + NS_IMETHOD + RegisterService(const char* aContractID, nsISupports* aService); + + NS_IMETHOD + UnregisterService(const char* aContractID); + + NS_IMETHOD + GetService(const char* aContractID, const nsIID& aIID, + nsISupports* *result, + nsIShutdownListener* shutdownListener = NULL); + + NS_IMETHOD + ReleaseService(const char* aContractID, nsISupports* service, + nsIShutdownListener* shutdownListener = NULL); + // nsComponentManagerImpl methods: nsComponentManagerImpl(); virtual ~nsComponentManagerImpl(); @@ -75,6 +113,7 @@ public: nsresult Shutdown(void); friend class nsFactoryEntry; + friend class nsServiceManager; protected: nsresult RegistryNameForLib(const char *aLibName, char **aRegistryName); nsresult RegisterComponentCommon(const nsCID &aClass, @@ -103,7 +142,8 @@ protected: nsresult HashContractID(const char *acontractID, const nsCID &aClass, nsFactoryEntry **fe_ptr = NULL); nsresult HashContractID(const char *acontractID, const nsCID &aClass, nsIDKey &cidKey, nsFactoryEntry **fe_ptr = NULL); nsresult UnloadLibraries(nsIServiceManager *servmgr, PRInt32 when); - + + nsresult FreeServices(); // The following functions are the only ones that operate on the persistent // registry nsresult PlatformInit(void); @@ -159,6 +199,7 @@ protected: int mMaxNLoaderData; }; + #define NS_MAX_FILENAME_LEN 1024 #define NS_ERROR_IS_DIR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_XPCOM, 24) @@ -207,6 +248,21 @@ protected: */ #define NS_XPCOM_COMPONENT_MANAGER_VERSION_STRING "alpha0.93" +class nsServiceEntry { +public: + nsServiceEntry(nsISupports* service, nsFactoryEntry* factEntry); + ~nsServiceEntry(); + + nsresult AddListener(nsIShutdownListener* listener); + nsresult RemoveListener(nsIShutdownListener* listener); + nsresult NotifyListeners(void); + + nsISupports* mObject; + nsVoidArray* mListeners; + PRBool mShuttingDown; + nsFactoryEntry* mFactoryEntry; // non-owning back pointer +}; + //////////////////////////////////////////////////////////////////////////////// /** * Class: nsFactoryEntry() @@ -257,6 +313,7 @@ public: nsCID cid; nsCString location; nsCOMPtr factory; + nsServiceEntry *mServiceEntry; // This is an index into the mLoaderData array that holds the type string and the loader int typeIndex; }; diff --git a/mozilla/xpcom/components/nsIServiceManager.h b/mozilla/xpcom/components/nsIServiceManager.h index a10c9f58568..4d3fec18507 100644 --- a/mozilla/xpcom/components/nsIServiceManager.h +++ b/mozilla/xpcom/components/nsIServiceManager.h @@ -379,12 +379,6 @@ CallGetService( const char *aContractID, nsnull); } -//////////////////////////////////////////////////////////////////////////////// -// NS_NewServiceManager: For when you want to create a service manager -// in a given context. - -extern NS_COM nsresult -NS_NewServiceManager(nsIServiceManager* *result); //////////////////////////////////////////////////////////////////////////////// // Initialization of XPCOM. Creates the global ComponentManager, ServiceManager diff --git a/mozilla/xpcom/components/nsRepository.cpp b/mozilla/xpcom/components/nsRepository.cpp deleted file mode 100644 index f9f470ae157..00000000000 --- a/mozilla/xpcom/components/nsRepository.cpp +++ /dev/null @@ -1,252 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ - -#include "nsIComponentManager.h" - -nsresult -nsComponentManager::Initialize(void) -{ - return NS_OK; -} - -nsresult -nsComponentManager::FindFactory(const nsCID &aClass, - nsIFactory **aFactory) -{ - nsIComponentManager* cm; - nsresult rv = NS_GetGlobalComponentManager(&cm); - if (NS_FAILED(rv)) return rv; - return cm->FindFactory(aClass, aFactory); -} - -nsresult -nsComponentManager::GetClassObject(const nsCID &aClass, const nsIID &aIID, - void **aResult) -{ - nsIComponentManager* cm; - nsresult rv = NS_GetGlobalComponentManager(&cm); - if (NS_FAILED(rv)) return rv; - return cm->GetClassObject(aClass, aIID, aResult); -} - -nsresult -nsComponentManager::ContractIDToClassID(const char *aContractID, - nsCID *aClass) -{ - nsIComponentManager* cm; - nsresult rv = NS_GetGlobalComponentManager(&cm); - if (NS_FAILED(rv)) return rv; - return cm->ContractIDToClassID(aContractID, aClass); -} - -nsresult -nsComponentManager::CLSIDToContractID(nsCID *aClass, - char* *aClassName, - char* *aContractID) -{ - nsIComponentManager* cm; - nsresult rv = NS_GetGlobalComponentManager(&cm); - if (NS_FAILED(rv)) return rv; - return cm->CLSIDToContractID(*aClass, aClassName, aContractID); -} - -nsresult -nsComponentManager::CreateInstance(const nsCID &aClass, - nsISupports *aDelegate, - const nsIID &aIID, - void **aResult) -{ - nsIComponentManager* cm; - nsresult rv = NS_GetGlobalComponentManager(&cm); - if (NS_FAILED(rv)) return rv; - return cm->CreateInstance(aClass, aDelegate, aIID, aResult); -} - -nsresult -nsComponentManager::CreateInstance(const char *aContractID, - nsISupports *aDelegate, - const nsIID &aIID, - void **aResult) -{ - nsIComponentManager* cm; - nsresult rv = NS_GetGlobalComponentManager(&cm); - if (NS_FAILED(rv)) return rv; - return cm->CreateInstanceByContractID(aContractID, aDelegate, aIID, aResult); -} - -nsresult -nsComponentManager::RegisterFactory(const nsCID &aClass, - const char *aClassName, - const char *aContractID, - nsIFactory *aFactory, - PRBool aReplace) -{ - nsIComponentManager* cm; - nsresult rv = NS_GetGlobalComponentManager(&cm); - if (NS_FAILED(rv)) return rv; - return cm->RegisterFactory(aClass, aClassName, aContractID, - aFactory, aReplace); -} - -nsresult -nsComponentManager::RegisterComponent(const nsCID &aClass, - const char *aClassName, - const char *aContractID, - const char *aLibraryPersistentDescriptor, - PRBool aReplace, - PRBool aPersist) -{ - nsIComponentManager* cm; - nsresult rv = NS_GetGlobalComponentManager(&cm); - if (NS_FAILED(rv)) return rv; - return cm->RegisterComponent(aClass, aClassName, aContractID, - aLibraryPersistentDescriptor, aReplace, aPersist); -} - -nsresult -nsComponentManager::RegisterComponentSpec(const nsCID &aClass, - const char *aClassName, - const char *aContractID, - nsIFile *aLibrary, - PRBool aReplace, - PRBool aPersist) -{ - nsIComponentManager* cm; - nsresult rv = NS_GetGlobalComponentManager(&cm); - if (NS_FAILED(rv)) return rv; - return cm->RegisterComponentSpec(aClass, aClassName, aContractID, - aLibrary, aReplace, aPersist); -} - -nsresult -nsComponentManager::RegisterComponentLib(const nsCID &aClass, - const char *aClassName, - const char *aContractID, - const char *adllName, - PRBool aReplace, - PRBool aPersist) -{ - nsIComponentManager* cm; - nsresult rv = NS_GetGlobalComponentManager(&cm); - if (NS_FAILED(rv)) return rv; - return cm->RegisterComponentLib(aClass, aClassName, aContractID, - adllName, aReplace, aPersist); -} - -nsresult -nsComponentManager::UnregisterFactory(const nsCID &aClass, - nsIFactory *aFactory) -{ - nsIComponentManager* cm; - nsresult rv = NS_GetGlobalComponentManager(&cm); - if (NS_FAILED(rv)) return rv; - return cm->UnregisterFactory(aClass, aFactory); -} - -nsresult -nsComponentManager::UnregisterComponent(const nsCID &aClass, - const char *aLibrary) -{ - nsIComponentManager* cm; - nsresult rv = NS_GetGlobalComponentManager(&cm); - if (NS_FAILED(rv)) return rv; - return cm->UnregisterComponent(aClass, aLibrary); -} - -nsresult -nsComponentManager::UnregisterComponentSpec(const nsCID &aClass, - nsIFile *aLibrarySpec) -{ - nsIComponentManager* cm; - nsresult rv = NS_GetGlobalComponentManager(&cm); - if (NS_FAILED(rv)) return rv; - return cm->UnregisterComponentSpec(aClass, aLibrarySpec); -} - -nsresult -nsComponentManager::FreeLibraries(void) -{ - nsIComponentManager* cm; - nsresult rv = NS_GetGlobalComponentManager(&cm); - if (NS_FAILED(rv)) return rv; - return cm->FreeLibraries(); -} - -nsresult -nsComponentManager::AutoRegister(PRInt32 when, nsIFile *directory) -{ - nsIComponentManager* cm; - nsresult rv = NS_GetGlobalComponentManager(&cm); - if (NS_FAILED(rv)) return rv; - return cm->AutoRegister(when, directory); -} - -nsresult -nsComponentManager::AutoRegisterComponent(PRInt32 when, - nsIFile *fullname) -{ - nsIComponentManager* cm; - nsresult rv = NS_GetGlobalComponentManager(&cm); - if (NS_FAILED(rv)) return rv; - return cm->AutoRegisterComponent(when, fullname); -} - -nsresult -nsComponentManager::AutoUnregisterComponent(PRInt32 when, - nsIFile *fullname) -{ - nsIComponentManager* cm; - nsresult rv = NS_GetGlobalComponentManager(&cm); - if (NS_FAILED(rv)) return rv; - return cm->AutoUnregisterComponent(when, fullname); -} - -nsresult -nsComponentManager::IsRegistered(const nsCID &aClass, - PRBool *aRegistered) -{ - nsIComponentManager* cm; - nsresult rv = NS_GetGlobalComponentManager(&cm); - if (NS_FAILED(rv)) return rv; - return cm->IsRegistered(aClass, aRegistered); -} - -nsresult -nsComponentManager::EnumerateCLSIDs(nsIEnumerator** aEmumerator) -{ - nsIComponentManager* cm; - nsresult rv = NS_GetGlobalComponentManager(&cm); - if (NS_FAILED(rv)) return rv; - return cm->EnumerateCLSIDs(aEmumerator); -} - -nsresult -nsComponentManager::EnumerateContractIDs(nsIEnumerator** aEmumerator) -{ - nsIComponentManager* cm; - nsresult rv = NS_GetGlobalComponentManager(&cm); - if (NS_FAILED(rv)) return rv; - return cm->EnumerateContractIDs(aEmumerator); -} - - - diff --git a/mozilla/xpcom/components/nsRepository.h b/mozilla/xpcom/components/nsRepository.h deleted file mode 100644 index a82358e3754..00000000000 --- a/mozilla/xpcom/components/nsRepository.h +++ /dev/null @@ -1,32 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ - -#ifndef __nsRespository_h -#define __nsRespository_h - -#include "nsIComponentManager.h" - -// XXX nsRepository is obsolete! Use nsComponentManager now! - -#define nsRepository nsComponentManager - -#endif diff --git a/mozilla/xpcom/components/nsServiceManager.cpp b/mozilla/xpcom/components/nsServiceManager.cpp deleted file mode 100644 index 7069e4bc4d1..00000000000 --- a/mozilla/xpcom/components/nsServiceManager.cpp +++ /dev/null @@ -1,705 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - * IBM Corp. - */ - -#include "nsIServiceManager.h" -#include "nsICategoryManager.h" -#include "nsXPIDLString.h" -#include "nsVoidArray.h" -#include "nsHashtable.h" -#include "prcmon.h" -#include "prthread.h" /* XXX: only used for the NSPR initialization hack (rick) */ -#include "nsAutoLock.h" -#include "nsISupportsPrimitives.h" -#include "nsIObserver.h" - -nsIServiceManager* gServiceManager = NULL; -PRBool gShuttingDown = PR_FALSE; - -nsresult -nsGetServiceByCID::operator()( const nsIID& aIID, void** aInstancePtr ) const - { - nsresult status; - // Too bad |nsServiceManager| isn't an |nsIServiceManager|, then this could have been one call - if ( mServiceManager ) - status = mServiceManager->GetService(mCID, aIID, NS_REINTERPRET_CAST(nsISupports**, aInstancePtr), 0); - else - status = nsServiceManager::GetService(mCID, aIID, NS_REINTERPRET_CAST(nsISupports**, aInstancePtr), 0); - - if ( !NS_SUCCEEDED(status) ) - *aInstancePtr = 0; - - if ( mErrorPtr ) - *mErrorPtr = status; - return status; - } - -nsresult -nsGetServiceByContractID::operator()( const nsIID& aIID, void** aInstancePtr ) const - { - nsresult status; - if ( mContractID ) - { - // Too bad |nsServiceManager| isn't an |nsIServiceManager|, then this could have been one call - if ( mServiceManager ) - status = mServiceManager->GetService(mContractID, aIID, NS_REINTERPRET_CAST(nsISupports**, aInstancePtr), 0); - else - status = nsServiceManager::GetService(mContractID, aIID, NS_REINTERPRET_CAST(nsISupports**, aInstancePtr), 0); - - if ( !NS_SUCCEEDED(status) ) - *aInstancePtr = 0; - } - else - status = NS_ERROR_NULL_POINTER; - - if ( mErrorPtr ) - *mErrorPtr = status; - return status; - } - -nsresult -nsGetServiceFromCategory::operator()( const nsIID& aIID, void** aInstancePtr) - const -{ - nsresult status; - nsXPIDLCString value; - nsCOMPtr catman = - do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &status); - - if (NS_FAILED(status)) goto error; - - if (!mCategory || !mEntry) { - // when categories have defaults, use that for null mEntry - status = NS_ERROR_NULL_POINTER; - goto error; - } - - /* find the contractID for category.entry */ - status = catman->GetCategoryEntry(mCategory, mEntry, - getter_Copies(value)); - if (NS_FAILED(status)) goto error; - if (!value) { - status = NS_ERROR_SERVICE_NOT_FOUND; - goto error; - } - - // Too bad |nsServiceManager| isn't an |nsIServiceManager|, then - // this could have been one call. - if ( mServiceManager ) - status = - mServiceManager->GetService(value, aIID, - NS_REINTERPRET_CAST(nsISupports**, - aInstancePtr), 0); - else - status = - nsServiceManager::GetService(value, aIID, - NS_REINTERPRET_CAST(nsISupports**, - aInstancePtr), 0); - if (NS_FAILED(status)) { - error: - *aInstancePtr = 0; - } - - *mErrorPtr = status; - return status; -} - -class nsServiceEntry { -public: - - nsServiceEntry(const nsCID& cid, nsISupports* service); - ~nsServiceEntry(); - - nsresult AddListener(nsIShutdownListener* listener); - nsresult RemoveListener(nsIShutdownListener* listener); - nsresult NotifyListeners(void); - - const nsCID& mClassID; - nsISupports* mService; - nsVoidArray* mListeners; - PRBool mShuttingDown; -}; - -nsServiceEntry::nsServiceEntry(const nsCID& cid, nsISupports* service) - : mClassID(cid), mService(service), mListeners(NULL), mShuttingDown(PR_FALSE) -{ -} - -nsServiceEntry::~nsServiceEntry() -{ - if (mListeners) { - NS_ASSERTION(mListeners->Count() == 0, "listeners not removed or notified"); -#if 0 - PRUint32 size = mListeners->Count(); - for (PRUint32 i = 0; i < size; i++) { - nsIShutdownListener* listener = (nsIShutdownListener*)(*mListeners)[i]; - NS_RELEASE(listener); - } -#endif - delete mListeners; - } -} - -nsresult -nsServiceEntry::AddListener(nsIShutdownListener* listener) -{ - if (listener == NULL) - return NS_OK; - if (mListeners == NULL) { - mListeners = new nsVoidArray(); - if (mListeners == NULL) - return NS_ERROR_OUT_OF_MEMORY; - } - PRInt32 rv = mListeners->AppendElement(listener); - NS_ADDREF(listener); - return rv == -1 ? NS_ERROR_FAILURE : NS_OK; -} - -nsresult -nsServiceEntry::RemoveListener(nsIShutdownListener* listener) -{ - if (listener == NULL) - return NS_OK; - NS_ASSERTION(mListeners, "no listeners added yet"); - if ( mListeners->RemoveElement(listener) ) - return NS_OK; - NS_ASSERTION(0, "unregistered shutdown listener"); - return NS_ERROR_FAILURE; -} - -nsresult -nsServiceEntry::NotifyListeners(void) -{ - if (mListeners) { - PRUint32 size = mListeners->Count(); - for (PRUint32 i = 0; i < size; i++) { - nsIShutdownListener* listener = (nsIShutdownListener*)(*mListeners)[0]; - nsresult rv = listener->OnShutdown(mClassID, mService); - if (NS_FAILED(rv)) return rv; - NS_RELEASE(listener); - mListeners->RemoveElementAt(0); - } - NS_ASSERTION(mListeners->Count() == 0, "failed to notify all listeners"); - delete mListeners; - mListeners = NULL; - } - return NS_OK; -} - -//////////////////////////////////////////////////////////////////////////////// - -class nsServiceManagerImpl : public nsIServiceManager { -public: - - NS_IMETHOD - RegisterService(const nsCID& aClass, nsISupports* aService); - - NS_IMETHOD - UnregisterService(const nsCID& aClass); - - NS_IMETHOD - GetService(const nsCID& aClass, const nsIID& aIID, - nsISupports* *result, - nsIShutdownListener* shutdownListener = NULL); - - NS_IMETHOD - ReleaseService(const nsCID& aClass, nsISupports* service, - nsIShutdownListener* shutdownListener = NULL); - - NS_IMETHOD - RegisterService(const char* aContractID, nsISupports* aService); - - NS_IMETHOD - UnregisterService(const char* aContractID); - - NS_IMETHOD - GetService(const char* aContractID, const nsIID& aIID, - nsISupports* *result, - nsIShutdownListener* shutdownListener = NULL); - - NS_IMETHOD - ReleaseService(const char* aContractID, nsISupports* service, - nsIShutdownListener* shutdownListener = NULL); - - nsServiceManagerImpl(void); - - NS_DECL_ISUPPORTS - -protected: - - virtual ~nsServiceManagerImpl(void); - - nsObjectHashtable/**/* mServices; - PRMonitor* mMonitor; -}; - -static PRBool PR_CALLBACK -DeleteEntry(nsHashKey *aKey, void *aData, void* closure) -{ - nsServiceEntry* entry = (nsServiceEntry*)aData; - entry->NotifyListeners(); - NS_RELEASE(entry->mService); - delete entry; - return PR_TRUE; -} - -nsServiceManagerImpl::nsServiceManagerImpl(void) - : mMonitor(0) -{ - NS_INIT_REFCNT(); - mServices = new nsObjectHashtable(nsnull, nsnull, // should never be cloned - DeleteEntry, nsnull, - 256, PR_TRUE); // Get a threadSafe hashtable - NS_ASSERTION(mServices, "out of memory already?"); - - /* XXX: This is a hack to force NSPR initialization.. This should be - * removed once PR_CEnterMonitor(...) initializes NSPR... (rick) - */ - (void)PR_GetCurrentThread(); - mMonitor = nsAutoMonitor::NewMonitor("nsServiceManagerImpl"); - NS_ASSERTION(mMonitor, "unable to get service manager monitor. Uh oh."); -} - -nsServiceManagerImpl::~nsServiceManagerImpl(void) -{ - if (mServices) { - delete mServices; - } - - if (mMonitor) { - nsAutoMonitor::DestroyMonitor(mMonitor); - mMonitor = 0; - } -} - -NS_IMPL_ISUPPORTS1(nsServiceManagerImpl, nsIServiceManager) - -NS_IMETHODIMP -nsServiceManagerImpl::GetService(const nsCID& aClass, const nsIID& aIID, - nsISupports* *result, - nsIShutdownListener* shutdownListener) -{ - nsAutoMonitor mon(mMonitor); - - // test this first, since there's no point in returning a service during - // shutdown -- whether it's available or not would depend on the order it - // occurs in the list - if (gShuttingDown) { - // When processing shutdown, dont process new GetService() requests - NS_WARNING("Creating new service on shutdown. Denied."); - return NS_ERROR_UNEXPECTED; - } - - nsresult rv = NS_OK; - nsIDKey key(aClass); - nsServiceEntry* entry = (nsServiceEntry*)mServices->Get(&key); - - if (entry) { - nsISupports* service; - rv = entry->mService->QueryInterface(aIID, (void**)&service); - if (NS_SUCCEEDED(rv)) { - // The refcount acquired in QI() above is "returned" to - // the caller. - - rv = entry->AddListener(shutdownListener); - if (NS_SUCCEEDED(rv)) { - *result = service; - - // If someone else requested the service to be shut down, - // and we just asked to get it again before it could be - // released, then cancel their shutdown request: - if (entry->mShuttingDown) { - entry->mShuttingDown = PR_FALSE; - NS_ADDREF(service); // Released in UnregisterService - } - } - } - return rv; - } - - nsISupports* service; - // We need to not be holding the service manager's monitor while calling - // CreateInstance, because it invokes user code which could try to re-enter - // the service manager: - mon.Exit(); - rv = nsComponentManager::CreateInstance(aClass, NULL, aIID, (void**)&service); - mon.Enter(); - - // If you hit this assertion, it means that someone tried (and - // succeeded!) to get your service during your service's - // initialization. This will mean that one instance of your - // service will leak, and may mean that the client that - // successfully acquired the service got a partially constructed - // object. - NS_ASSERTION(!mServices->Get(&key), "re-entrant call to service manager created service twice!"); - - if (NS_SUCCEEDED(rv)) { - entry = new nsServiceEntry(aClass, service); - if (entry == NULL) { - NS_RELEASE(service); - rv = NS_ERROR_OUT_OF_MEMORY; - } - else { - rv = entry->AddListener(shutdownListener); - if (NS_SUCCEEDED(rv)) { - mServices->Put(&key, entry); - *result = service; - NS_ADDREF(service); // Released in service manager destructor - } - else { - NS_RELEASE(service); - delete entry; - } - } - } - return rv; -} - -NS_IMETHODIMP -nsServiceManagerImpl::ReleaseService(const nsCID& aClass, nsISupports* service, - nsIShutdownListener* shutdownListener) -{ - PRBool serviceFound = PR_FALSE; - nsresult rv = NS_OK; - -#ifndef NS_DEBUG - // Do entry lookup only if there is a shutdownlistener to be removed. - // - // For Debug builds, Consistency check for entry always. Releasing service - // when the service is not with the servicemanager is mostly wrong. - if (shutdownListener) -#endif - { - nsAutoMonitor mon(mMonitor); - nsIDKey key(aClass); - nsServiceEntry* entry = (nsServiceEntry*)mServices->Get(&key); - - if (entry) { - rv = entry->RemoveListener(shutdownListener); - serviceFound = PR_TRUE; - } - } - - nsrefcnt cnt; - NS_RELEASE2(service, cnt); - - // Consistency check: Service ref count cannot go to zero because of the - // extra addref the service manager does, unless the service has been - // unregistered (ie) not found in the service managers hash table. - // - NS_ASSERTION(cnt > 0 || !serviceFound, - "*** Service in hash table but is being deleted. Dangling pointer\n" - "*** in service manager hash table."); - - return rv; -} - -NS_IMETHODIMP -nsServiceManagerImpl::RegisterService(const nsCID& aClass, nsISupports* aService) -{ - nsresult rv = NS_OK; - nsAutoMonitor mon(mMonitor); - - nsIDKey key(aClass); - nsServiceEntry* entry = (nsServiceEntry*)mServices->Get(&key); - if (entry) { - rv = NS_ERROR_FAILURE; - } - else { - entry = new nsServiceEntry(aClass, aService); - if (entry == NULL) - rv = NS_ERROR_OUT_OF_MEMORY; - else { - mServices->Put(&key, entry); - NS_ADDREF(aService); // Released in DeleteEntry from UnregisterService - } - } - return rv; -} - -NS_IMETHODIMP -nsServiceManagerImpl::UnregisterService(const nsCID& aClass) -{ - nsresult rv = NS_OK; - nsAutoMonitor mon(mMonitor); - - nsIDKey key(aClass); - nsServiceEntry* entry = (nsServiceEntry*)mServices->Get(&key); - - if (entry == NULL) { - rv = NS_ERROR_SERVICE_NOT_FOUND; - } - else { - rv = entry->NotifyListeners(); // break the cycles - entry->mShuttingDown = PR_TRUE; - mServices->RemoveAndDelete(&key); // This will call the delete entry func - } - return rv; -} - -//////////////////////////////////////////////////////////////////////////////// -// let's do it again, this time with ContractIDs... - -NS_IMETHODIMP -nsServiceManagerImpl::RegisterService(const char* aContractID, nsISupports* aService) -{ - nsCID aClass; - nsresult rv; - rv = nsComponentManager::ContractIDToClassID(aContractID, &aClass); - if (NS_FAILED(rv)) return rv; - return RegisterService(aClass, aService); -} - -NS_IMETHODIMP -nsServiceManagerImpl::UnregisterService(const char* aContractID) -{ - nsCID aClass; - nsresult rv; - rv = nsComponentManager::ContractIDToClassID(aContractID, &aClass); - if (NS_FAILED(rv)) return rv; - return UnregisterService(aClass); -} - -NS_IMETHODIMP -nsServiceManagerImpl::GetService(const char* aContractID, const nsIID& aIID, - nsISupports* *result, - nsIShutdownListener* shutdownListener) -{ - nsCID aClass; - nsresult rv; - rv = nsComponentManager::ContractIDToClassID(aContractID, &aClass); - if (NS_FAILED(rv)) return rv; - return GetService(aClass, aIID, result, shutdownListener); -} - -NS_IMETHODIMP -nsServiceManagerImpl::ReleaseService(const char* aContractID, nsISupports* service, - nsIShutdownListener* shutdownListener) -{ - nsCID aClass; - nsresult rv; - rv = nsComponentManager::ContractIDToClassID(aContractID, &aClass); - if (NS_FAILED(rv)) return rv; - return ReleaseService(aClass, service, shutdownListener); -} - -//////////////////////////////////////////////////////////////////////////////// - -nsresult -NS_NewServiceManager(nsIServiceManager* *result) -{ - nsServiceManagerImpl* servMgr = new nsServiceManagerImpl(); - if (servMgr == NULL) - return NS_ERROR_OUT_OF_MEMORY; - NS_ADDREF(servMgr); - *result = servMgr; - return NS_OK; -} - -//////////////////////////////////////////////////////////////////////////////// -// Global service manager interface (see nsIServiceManager.h) - -nsresult -nsServiceManager::GetGlobalServiceManager(nsIServiceManager* *result) -{ - if (gShuttingDown) - return NS_ERROR_UNEXPECTED; - - nsresult rv = NS_OK; - if (gServiceManager == NULL) { - // XPCOM not initialized yet. Let us do initialization of our module. - rv = NS_InitXPCOM(NULL, NULL); - } - // No ADDREF as we are advicing no release of this. - if (NS_SUCCEEDED(rv)) - *result = gServiceManager; - - return rv; -} - -nsresult -nsServiceManager::ShutdownGlobalServiceManager(nsIServiceManager* *result) -{ - if (gServiceManager != NULL) { - nsrefcnt cnt; - NS_RELEASE2(gServiceManager, cnt); - NS_ASSERTION(cnt == 0, "Service Manager being held past XPCOM shutdown."); - gServiceManager = NULL; - } - return NS_OK; -} - -nsresult -nsServiceManager::GetService(const nsCID& aClass, const nsIID& aIID, - nsISupports* *result, - nsIShutdownListener* shutdownListener) -{ - nsIServiceManager* mgr; - nsresult rv = GetGlobalServiceManager(&mgr); - if (NS_FAILED(rv)) return rv; - return mgr->GetService(aClass, aIID, result, shutdownListener); -} - -nsresult -nsServiceManager::ReleaseService(const nsCID& aClass, nsISupports* service, - nsIShutdownListener* shutdownListener) -{ - // Don't create the global service manager here because we might be shutting - // down, and releasing all the services in its destructor - if (gServiceManager) - return gServiceManager->ReleaseService(aClass, service, shutdownListener); - // If there wasn't a global service manager, just release the object: - NS_RELEASE(service); - return NS_OK; -} - -nsresult -nsServiceManager::RegisterService(const nsCID& aClass, nsISupports* aService) -{ - nsIServiceManager* mgr; - nsresult rv = GetGlobalServiceManager(&mgr); - if (NS_FAILED(rv)) return rv; - return mgr->RegisterService(aClass, aService); -} - -nsresult -nsServiceManager::UnregisterService(const nsCID& aClass) -{ - nsIServiceManager* mgr; - nsresult rv = GetGlobalServiceManager(&mgr); - if (NS_FAILED(rv)) return rv; - return mgr->UnregisterService(aClass); -} - -//////////////////////////////////////////////////////////////////////////////// -// let's do it again, this time with ContractIDs... - -nsresult -nsServiceManager::GetService(const char* aContractID, const nsIID& aIID, - nsISupports* *result, - nsIShutdownListener* shutdownListener) -{ - nsIServiceManager* mgr; - nsresult rv = GetGlobalServiceManager(&mgr); - if (NS_FAILED(rv)) return rv; - return mgr->GetService(aContractID, aIID, result, shutdownListener); -} - -nsresult -nsServiceManager::ReleaseService(const char* aContractID, nsISupports* service, - nsIShutdownListener* shutdownListener) -{ - // Don't create the global service manager here because we might - // be shutting down, and releasing all the services in its - // destructor - if (gServiceManager) - return gServiceManager->ReleaseService(aContractID, service, shutdownListener); - // If there wasn't a global service manager, just release the object: - NS_RELEASE(service); - return NS_OK; -} - -nsresult -nsServiceManager::RegisterService(const char* aContractID, nsISupports* aService) -{ - nsIServiceManager* mgr; - nsresult rv = GetGlobalServiceManager(&mgr); - if (NS_FAILED(rv)) return rv; - return mgr->RegisterService(aContractID, aService); -} - -nsresult -nsServiceManager::UnregisterService(const char* aContractID) -{ - // Don't create the global service manager here because we might - // be shutting down, and releasing all the services in its - // destructor - if (gServiceManager) - return gServiceManager->UnregisterService(aContractID); - return NS_OK; -} - -//////////////////////////////////////////////////////////////////////////////// - -/* - * CreateServicesFromCategory() - * - * Given a category, this convenience functions enumerates the category and - * creates a service of every CID or ContractID registered under the category. - * If observerTopic is non null and the service implements nsIObserver, - * this will attempt to notify the observer with the origin, observerTopic string - * as parameter. - */ -nsresult -NS_CreateServicesFromCategory(const char *category, - nsISupports *origin, - const PRUnichar *observerTopic) -{ - nsresult rv = NS_OK; - - int nFailed = 0; - nsCOMPtr categoryManager = - do_GetService("@mozilla.org/categorymanager;1", &rv); - if (!categoryManager) return rv; - - nsCOMPtr enumerator; - rv = categoryManager->EnumerateCategory(category, - getter_AddRefs(enumerator)); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr entry; - while (NS_SUCCEEDED(enumerator->GetNext(getter_AddRefs(entry)))) { - // From here on just skip any error we get. - nsCOMPtr catEntry = do_QueryInterface(entry, &rv); - if (NS_FAILED(rv)) { - nFailed++; - continue; - } - nsXPIDLCString entryString; - rv = catEntry->GetData(getter_Copies(entryString)); - if (NS_FAILED(rv)) { - nFailed++; - continue; - } - nsXPIDLCString contractID; - rv = categoryManager->GetCategoryEntry(category,(const char *)entryString, getter_Copies(contractID)); - if (NS_FAILED(rv)) { - nFailed++; - continue; - } - - nsCOMPtr instance = do_GetService(contractID, &rv); - if (NS_FAILED(rv)) { - nFailed++; - continue; - } - - if (observerTopic) { - // try an observer, if it implements it. - nsCOMPtr observer = do_QueryInterface(instance, &rv); - if (NS_SUCCEEDED(rv) && observer) - observer->Observe(origin, observerTopic, NS_LITERAL_STRING("").get()); - } - } - return (nFailed ? NS_ERROR_FAILURE : NS_OK); -} - diff --git a/mozilla/xpcom/ds/nsObserver.cpp b/mozilla/xpcom/ds/nsObserver.cpp index 29cafeb79c9..64bcd8ee7ee 100644 --- a/mozilla/xpcom/ds/nsObserver.cpp +++ b/mozilla/xpcom/ds/nsObserver.cpp @@ -25,7 +25,7 @@ #include "pratom.h" #include "nsIFactory.h" #include "nsIServiceManager.h" -#include "nsRepository.h" +#include "nsIComponentManager.h" #include "nsIObserver.h" #include "nsObserver.h" diff --git a/mozilla/xpcom/ds/nsObserverService.cpp b/mozilla/xpcom/ds/nsObserverService.cpp index b33097f3bdf..2ba25c691b2 100644 --- a/mozilla/xpcom/ds/nsObserverService.cpp +++ b/mozilla/xpcom/ds/nsObserverService.cpp @@ -26,7 +26,7 @@ #include "prlock.h" #include "nsIFactory.h" #include "nsIServiceManager.h" -#include "nsRepository.h" +#include "nsIComponentManager.h" #include "nsIObserverService.h" #include "nsObserverService.h" #include "nsIObserverList.h" diff --git a/mozilla/xpcom/makefile.win b/mozilla/xpcom/makefile.win index ab3a7f9f427..d654851dfa3 100644 --- a/mozilla/xpcom/makefile.win +++ b/mozilla/xpcom/makefile.win @@ -32,7 +32,6 @@ DIRS= typelib \ reflect \ proxy \ build \ - appshell \ tools \ !if defined(MOZ_DEBUG) windbgdlg \ diff --git a/mozilla/xpcom/proxy/src/nsProxyEvent.cpp b/mozilla/xpcom/proxy/src/nsProxyEvent.cpp index c9e15b794fd..57036a1e9b7 100644 --- a/mozilla/xpcom/proxy/src/nsProxyEvent.cpp +++ b/mozilla/xpcom/proxy/src/nsProxyEvent.cpp @@ -40,7 +40,7 @@ #include "prmem.h" #include "xptcall.h" -#include "nsRepository.h" +#include "nsIComponentManager.h" #include "nsIServiceManager.h" #include "nsMemory.h" #include "nsIEventQueueService.h" @@ -403,20 +403,41 @@ nsProxyObject::Post( PRUint32 methodIndex, nsXPTMethodInfo *methodInfo, nsXPTCMi if (methodInfo->IsNotXPCOM()) return NS_ERROR_PROXY_INVALID_IN_PARAMETER; - - PLEvent *event = PR_NEW(PLEvent); - - if (event == nsnull) - return NS_ERROR_OUT_OF_MEMORY; - nsXPTCVariant *fullParam; uint8 paramCount; rv = convertMiniVariantToVariant(methodInfo, params, &fullParam, ¶mCount); if (NS_FAILED(rv)) - { - PR_DELETE(event); return rv; + + PRBool callDirectly; + + // see if we should call into the method directly. Either it is a QI function call + // (methodIndex == 0), or it is a sync proxy and this code is running on the same thread + // as the destination event queue. + if ( (methodIndex == 0) || + (mProxyType & PROXY_SYNC && + NS_SUCCEEDED(mDestQueue->IsQueueOnCurrentThread(&callDirectly)) && + callDirectly)) + { + + // invoke the magic of xptc... + nsresult rv = XPTC_InvokeByIndex( mRealObject, + methodIndex, + paramCount, + fullParam); + + if (fullParam) + free(fullParam); + return rv; + } + + PLEvent *event = PR_NEW(PLEvent); + + if (event == nsnull) { + if (fullParam) + free(fullParam); + return NS_ERROR_OUT_OF_MEMORY; } nsProxyObjectCallInfo *proxyInfo = new nsProxyObjectCallInfo(this, @@ -426,11 +447,10 @@ nsProxyObject::Post( PRUint32 methodIndex, nsXPTMethodInfo *methodInfo, nsXPTCMi paramCount, event); // will be deleted by ~() - if (proxyInfo == nsnull) - { + if (proxyInfo == nsnull) { PR_DELETE(event); if (fullParam) - free(fullParam); // allocated with malloc + free(fullParam); return NS_ERROR_OUT_OF_MEMORY; } @@ -441,25 +461,10 @@ nsProxyObject::Post( PRUint32 methodIndex, nsXPTMethodInfo *methodInfo, nsXPTCMi if (mProxyType & PROXY_SYNC) { - PRBool callDirectly; - mDestQueue->IsQueueOnCurrentThread(&callDirectly); - - if (callDirectly) - { - EventHandler(event); - PL_DestroyEvent(event); - // there is no need to call the DestroyHandler() because - // there is no need to wake up the nested event loop. - } - else - { - rv = PostAndWait(proxyInfo); - - if (NS_FAILED(rv)) - return rv; - } + rv = PostAndWait(proxyInfo); - rv = proxyInfo->GetResult(); + if (NS_SUCCEEDED(rv)) + rv = proxyInfo->GetResult(); delete proxyInfo; return rv; } diff --git a/mozilla/xpcom/proxy/src/nsProxyEventClass.cpp b/mozilla/xpcom/proxy/src/nsProxyEventClass.cpp index ff11ec65b0b..0d0c6d26c42 100644 --- a/mozilla/xpcom/proxy/src/nsProxyEventClass.cpp +++ b/mozilla/xpcom/proxy/src/nsProxyEventClass.cpp @@ -26,7 +26,7 @@ #include "nsIProxyObjectManager.h" #include "nsProxyEventPrivate.h" -#include "nsRepository.h" +#include "nsIComponentManager.h" #include "nsIServiceManager.h" #include "nsCOMPtr.h" diff --git a/mozilla/xpcom/proxy/src/nsProxyObjectManager.cpp b/mozilla/xpcom/proxy/src/nsProxyObjectManager.cpp index e74a2e8da06..02c14dae6f8 100644 --- a/mozilla/xpcom/proxy/src/nsProxyObjectManager.cpp +++ b/mozilla/xpcom/proxy/src/nsProxyObjectManager.cpp @@ -37,7 +37,7 @@ #include "nsIProxyCreateInstance.h" -#include "nsRepository.h" +#include "nsIComponentManager.h" #include "nsIServiceManager.h" #include "nsCOMPtr.h" diff --git a/mozilla/xpcom/proxy/tests/proxytests.cpp b/mozilla/xpcom/proxy/tests/proxytests.cpp index c4a8f617300..abb1bf6a82c 100644 --- a/mozilla/xpcom/proxy/tests/proxytests.cpp +++ b/mozilla/xpcom/proxy/tests/proxytests.cpp @@ -23,7 +23,7 @@ #include -#include "nsRepository.h" +#include "nsIComponentManager.h" #include "nsIServiceManager.h" #include "nsCOMPtr.h" #include "nsSpecialSystemDirectory.h" // For exe dir diff --git a/mozilla/xpcom/tests/TestObserverService.cpp b/mozilla/xpcom/tests/TestObserverService.cpp index 087692ca44d..789dc7c6bf8 100644 --- a/mozilla/xpcom/tests/TestObserverService.cpp +++ b/mozilla/xpcom/tests/TestObserverService.cpp @@ -23,7 +23,7 @@ #define NS_IMPL_IDS #include "nsISupports.h" -#include "nsRepository.h" +#include "nsIComponentManager.h" #include "nsIObserverService.h" #include "nsIObserver.h" #include "nsString.h" diff --git a/mozilla/xpcom/tests/windows/makefile.win b/mozilla/xpcom/tests/windows/makefile.win index 70e8ea976fd..3c2020ce984 100644 --- a/mozilla/xpcom/tests/windows/makefile.win +++ b/mozilla/xpcom/tests/windows/makefile.win @@ -25,10 +25,10 @@ DEPTH=..\..\.. MAKE_OBJ_TYPE = EXE PROG1 = .\$(OBJDIR)\TestCOM.exe -PROG2 = .\$(OBJDIR)\TestHelloXPLoop.exe +#PROG2 = .\$(OBJDIR)\TestHelloXPLoop.exe #PROG3 = .\$(OBJDIR)\nsStringTest.exe #PROGRAMS = $(PROG1) $(PROG2) $(PROG3) -PROGRAMS = $(PROG1) $(PROG2) +PROGRAMS = $(PROG1) LINCS=-I$(PUBLIC)\xpcom @@ -47,6 +47,6 @@ clobber:: -for %p in ($(PROGRAMS)) do $(RM) %p $(DIST)\bin\%p $(PROG1): $(OBJDIR) TestCOM.cpp -$(PROG2): $(OBJDIR) TestHelloXPLoop.cpp +#$(PROG2): $(OBJDIR) TestHelloXPLoop.cpp #$(PROG3): $(OBJDIR) nsStringTest.cpp diff --git a/mozilla/xpfe/appshell/src/nsAppShellFactory.cpp b/mozilla/xpfe/appshell/src/nsAppShellFactory.cpp index ede7ccab465..3170de498b5 100644 --- a/mozilla/xpfe/appshell/src/nsAppShellFactory.cpp +++ b/mozilla/xpfe/appshell/src/nsAppShellFactory.cpp @@ -20,7 +20,7 @@ * Contributor(s): */ #include "nsIFactory.h" -#include "nsRepository.h" +#include "nsIComponentManager.h" #include "nscore.h" #include "nsIComponentManager.h" #include "nsAppShellCIDs.h" diff --git a/mozilla/xpinstall/src/nsInstall.cpp b/mozilla/xpinstall/src/nsInstall.cpp index 58c25aa8600..2af9876b45e 100644 --- a/mozilla/xpinstall/src/nsInstall.cpp +++ b/mozilla/xpinstall/src/nsInstall.cpp @@ -30,7 +30,7 @@ #include "nsIFactory.h" #include "nsISupports.h" -#include "nsRepository.h" +#include "nsIComponentManager.h" #include "nsIServiceManager.h" #include "nsHashtable.h" diff --git a/mozilla/xpinstall/src/nsInstallFolder.cpp b/mozilla/xpinstall/src/nsInstallFolder.cpp index b1a7c141a32..1f97dc4b084 100644 --- a/mozilla/xpinstall/src/nsInstallFolder.cpp +++ b/mozilla/xpinstall/src/nsInstallFolder.cpp @@ -28,7 +28,7 @@ #include "nscore.h" #include "prtypes.h" -#include "nsRepository.h" +#include "nsIComponentManager.h" #include "nsString.h" #include "nsXPIDLString.h" diff --git a/mozilla/xpinstall/src/nsInstallTrigger.cpp b/mozilla/xpinstall/src/nsInstallTrigger.cpp index 0281640d161..2e7d0c9a1b8 100644 --- a/mozilla/xpinstall/src/nsInstallTrigger.cpp +++ b/mozilla/xpinstall/src/nsInstallTrigger.cpp @@ -34,7 +34,7 @@ #include "nsIPref.h" -#include "nsRepository.h" +#include "nsIComponentManager.h" #include "nsIServiceManager.h" #include "nsIDirectoryService.h" diff --git a/mozilla/xpinstall/src/nsJSInstallTriggerGlobal.cpp b/mozilla/xpinstall/src/nsJSInstallTriggerGlobal.cpp index 1886905501a..e3a7827bba9 100644 --- a/mozilla/xpinstall/src/nsJSInstallTriggerGlobal.cpp +++ b/mozilla/xpinstall/src/nsJSInstallTriggerGlobal.cpp @@ -32,7 +32,7 @@ #include "nsInstallTrigger.h" #include "nsXPITriggerInfo.h" -#include "nsRepository.h" +#include "nsIComponentManager.h" #include "nsSoftwareUpdateIIDs.h" @@ -85,7 +85,7 @@ static JSBool CreateNativeObject(JSContext *cx, JSObject *obj, nsIDOMInstallTrig static NS_DEFINE_CID(kInstallTrigger_CID, NS_SoftwareUpdateInstallTrigger_CID); - result = nsRepository::CreateInstance(kInstallTrigger_CID, + result = nsComponentManager::CreateInstance(kInstallTrigger_CID, nsnull, NS_GET_IID(nsIDOMInstallTriggerGlobal), (void **)&nativeThis); diff --git a/mozilla/xpinstall/src/nsJSInstallVersion.cpp b/mozilla/xpinstall/src/nsJSInstallVersion.cpp index 50a60820715..e6d8d2c59d9 100644 --- a/mozilla/xpinstall/src/nsJSInstallVersion.cpp +++ b/mozilla/xpinstall/src/nsJSInstallVersion.cpp @@ -29,7 +29,7 @@ #include "nsString.h" #include "nsIDOMInstallVersion.h" #include "nsIScriptNameSpaceManager.h" -#include "nsRepository.h" +#include "nsIComponentManager.h" #include "nsDOMCID.h" #include "nsSoftwareUpdateIIDs.h" @@ -514,7 +514,7 @@ InstallVersion(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rva static NS_DEFINE_IID(kInstallVersion_CID, NS_SoftwareUpdateInstallVersion_CID); - result = nsRepository::CreateInstance(kInstallVersion_CID, + result = nsComponentManager::CreateInstance(kInstallVersion_CID, nsnull, NS_GET_IID(nsIDOMInstallVersion), (void **)&nativeThis); diff --git a/mozilla/xpinstall/src/nsSoftwareUpdateRun.cpp b/mozilla/xpinstall/src/nsSoftwareUpdateRun.cpp index 31ed845ad17..afdd88a8797 100644 --- a/mozilla/xpinstall/src/nsSoftwareUpdateRun.cpp +++ b/mozilla/xpinstall/src/nsSoftwareUpdateRun.cpp @@ -29,7 +29,7 @@ #include "nsInstall.h" -#include "nsRepository.h" +#include "nsIComponentManager.h" #include "nsIServiceManager.h" #include "nsSpecialSystemDirectory.h" diff --git a/mozilla/xpinstall/standalone/standalone.cpp b/mozilla/xpinstall/standalone/standalone.cpp index 336115a31dd..f18c09258b8 100644 --- a/mozilla/xpinstall/standalone/standalone.cpp +++ b/mozilla/xpinstall/standalone/standalone.cpp @@ -22,7 +22,7 @@ #include -#include "nsRepository.h" +#include "nsIComponentManager.h" #include "nsIServiceManager.h" #include "nsCOMPtr.h" diff --git a/mozilla/xpinstall/stub/xpistub.cpp b/mozilla/xpinstall/stub/xpistub.cpp index a7d4fe0a3ff..cb114c73f9c 100644 --- a/mozilla/xpinstall/stub/xpistub.cpp +++ b/mozilla/xpinstall/stub/xpistub.cpp @@ -25,7 +25,7 @@ #include "xpistub.h" -#include "nsRepository.h" +#include "nsIComponentManager.h" #include "nsIServiceManager.h" #include "nsCOMPtr.h" #include "nsSpecialSystemDirectory.h"