From 011f9b10e5f440b5826fc038dc2fa5dafe5b9266 Mon Sep 17 00:00:00 2001 From: "dougt%netscape.com" Date: Tue, 29 Jan 2002 21:22:13 +0000 Subject: [PATCH] 1. Converts callers of nsIComponentManagerObsolete to use nsIComponentRegistrar. 2. Converts callers of nsComponentManager::AutoRegister to use nsIComponentRegistrar's autoRegistrar method. 3. Add nsIComponentRegistrar implmentation to nsComponentManagerImpl. 4. Rearrange nsComponentManager.cpp so that related methods are in the same place. 5. Added a C-style function NS_GetComponentRegistrar so that getting the registrar is easier in some places. 6. Added a nsISimpleEnumerator interface on PLDHashTableEnumeratorImpl. in this way, the same base class can support both old style and new style enumerations. 7. Fixed a nasty bug where unregistring factories will leave the contract id hash with a dangling pointer. Now, when unregister is called we search the contract id hash for entries which have the given doomned cid and remove them. Bug 115853. r=dp@netscape.com, sr=rpotts@netscape.com git-svn-id: svn://10.0.0.236/trunk@113143 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/build/nsContentDLF.cpp | 22 +- .../xpcom/datasource/nsLDAPDataSource.js | 22 +- mozilla/embedding/base/nsEmbedAPI.cpp | 12 +- .../ui/helperAppDlg/nsHelperAppDlg.js | 16 +- .../irc/js/lib/chatzilla-service.js | 37 +- .../extensions/venkman/js/venkman-service.js | 16 +- .../extensions/xml-rpc/src/nsDictionary.js | 15 +- .../extensions/xml-rpc/src/nsXmlRpcClient.js | 24 +- .../extensions/xmlterm/ui/xmlterm-service.js | 36 +- mozilla/htmlparser/tests/outsinks/Convert.cpp | 10 +- .../intl/strres/tests/StringBundleTest.cpp | 46 +- mozilla/js/src/xpconnect/shell/xpcshell.cpp | 17 +- .../js/src/xpconnect/src/xpccomponents.cpp | 48 +- mozilla/js/src/xpconnect/src/xpcprivate.h | 2 + mozilla/js/src/xpconnect/tests/TestXPC.cpp | 17 +- mozilla/layout/build/nsContentDLF.cpp | 22 +- mozilla/mailnews/addrbook/src/nsAbView.cpp | 11 +- .../addrbook/src/nsLDAPPrefsService.js | 16 +- .../extensions/smime/src/smime-service.js | 16 +- .../plugin/base/src/nsPluginHostImpl.cpp | 14 +- mozilla/netwerk/base/src/nsFilters.js | 11 +- mozilla/netwerk/base/src/nsProxyAutoConfig.js | 13 +- mozilla/netwerk/base/tests/urltest.cpp | 10 +- .../streamconv/test/TestStreamConv.cpp | 11 +- mozilla/netwerk/test/TestCacheBlockFiles.cpp | 14 +- mozilla/netwerk/test/TestCacheMgr.cpp | 17 +- mozilla/netwerk/test/TestFileInput.cpp | 15 +- mozilla/netwerk/test/TestFileInput2.cpp | 15 +- mozilla/netwerk/test/TestFileTransport.cpp | 14 +- mozilla/netwerk/test/TestHttp.cpp | 13 +- mozilla/netwerk/test/TestMakeAbs.cpp | 14 +- mozilla/netwerk/test/TestPageLoad.cpp | 18 +- mozilla/netwerk/test/TestPerf.cpp | 8 +- mozilla/netwerk/test/TestRawCache.cpp | 16 +- mozilla/netwerk/test/TestRes.cpp | 18 +- mozilla/netwerk/test/TestSocketInput.cpp | 14 +- mozilla/netwerk/test/TestSocketTransport.cpp | 15 +- mozilla/netwerk/test/TestUpload.cpp | 15 +- mozilla/netwerk/test/TestWriteStream.cpp | 17 +- mozilla/netwerk/test/urltest.cpp | 14 +- .../htmlparser/tests/outsinks/Convert.cpp | 10 +- mozilla/webshell/tests/viewer/nsViewerApp.cpp | 11 +- mozilla/xpcom/build/nsXPCOM.h | 14 + mozilla/xpcom/build/nsXPComInit.cpp | 10 +- .../xpcom/components/nsComponentManager.cpp | 1224 ++++++++++------- mozilla/xpcom/components/nsComponentManager.h | 60 +- mozilla/xpcom/components/nsGenericFactory.cpp | 28 +- mozilla/xpcom/components/nsIModule.idl | 2 +- .../components/nsIServiceManagerObsolete.h | 11 + .../components/nsNativeComponentLoader.cpp | 1 - mozilla/xpcom/ds/nsVoidArray.h | 4 +- mozilla/xpcom/glue/nsGenericFactory.cpp | 28 +- mozilla/xpcom/io/MANIFEST | 1 + mozilla/xpcom/io/Makefile.in | 1 + mozilla/xpcom/io/makefile.win | 1 + mozilla/xpcom/io/nsIDirectoryService.idl | 4 +- mozilla/xpcom/io/nsIFile.idl | 82 +- mozilla/xpcom/proxy/tests/proxytests.cpp | 12 +- mozilla/xpcom/sample/nsSample.js | 15 +- mozilla/xpcom/sample/nsTestSample.cpp | 28 +- mozilla/xpcom/tests/PropertiesTest.cpp | 10 +- mozilla/xpcom/tests/RegFactory.cpp | 25 +- mozilla/xpcom/tests/TestFactory.cpp | 98 +- mozilla/xpcom/tests/nsIFileEnumerator.cpp | 11 +- mozilla/xpcom/tests/nsIFileTest.cpp | 12 +- .../xpcom/tests/windows/TestHelloXPLoop.cpp | 115 +- mozilla/xpcom/tools/registry/regxpcom.cpp | 40 +- .../xpfe/appshell/src/nsCloseAllWindows.js | 16 +- .../components/console/jsconsole-clhandler.js | 16 +- .../components/filepicker/src/nsFilePicker.js | 11 +- .../filepicker/src/nsFilePicker.js.in | 11 +- .../xpfe/components/sidebar/src/nsSidebar.js | 11 +- .../startup/src/nsCloseAllWindows.js | 16 +- mozilla/xpinstall/src/nsSoftwareUpdate.cpp | 7 +- mozilla/xpinstall/standalone/standalone.cpp | 14 +- mozilla/xpinstall/stub/xpistub.cpp | 10 +- 76 files changed, 1470 insertions(+), 1201 deletions(-) diff --git a/mozilla/content/build/nsContentDLF.cpp b/mozilla/content/build/nsContentDLF.cpp index 2ae702f9ed0..bb95a4e3ef7 100644 --- a/mozilla/content/build/nsContentDLF.cpp +++ b/mozilla/content/build/nsContentDLF.cpp @@ -40,6 +40,7 @@ #include "nsGenericHTMLElement.h" #include "nsHTMLAtoms.h" #include "nsIComponentManager.h" +#include "nsIComponentRegistrar.h" #include "nsICategoryManager.h" #include "nsIDocumentLoader.h" #include "nsIDocumentLoaderFactory.h" @@ -580,16 +581,16 @@ RegisterTypes(nsIComponentManager* aCompMgr, #ifdef NOISY_REGISTRY printf("Register %s => %s\n", contractid, aPath); #endif - - // what I want to do here is QI for a Component Registration Manager. Since this - // has not been invented yet, QI to the obsolete manager. Kids, don't do this at home. - nsCOMPtr obsoleteManager = do_QueryInterface(aCompMgr, &rv); + nsCOMPtr registrar = do_QueryInterface(aCompMgr, &rv); if (NS_FAILED(rv)) return rv; - rv = obsoleteManager->RegisterComponentWithType(kDocumentFactoryImplCID, "Layout", - contractid, aPath, aLocation, - PR_TRUE, PR_TRUE, aType); + rv = registrar->RegisterFactoryLocation(kDocumentFactoryImplCID, + "Layout", + contractid, + aPath, + aLocation, + aType); if (NS_FAILED(rv)) break; // add the MIME types layotu can handle to the handlers category. @@ -657,15 +658,12 @@ nsContentDLF::UnregisterDocumentFactories(nsIComponentManager* aCompMgr, const nsModuleComponentInfo* aInfo) { // XXXwaterson seems like this leaves the registry pretty dirty. - - // what I want to do here is QI for a Component Registration Manager. Since this - // has not been invented yet, QI to the obsolete manager. Kids, don't do this at home. nsresult rv; - nsCOMPtr obsoleteManager = do_QueryInterface(aCompMgr, &rv); + nsCOMPtr registrar = do_QueryInterface(aCompMgr, &rv); if (NS_FAILED(rv)) return rv; - return obsoleteManager->UnregisterComponentSpec(kDocumentFactoryImplCID, aPath); + return registrar->UnregisterFactoryLocation(kDocumentFactoryImplCID, aPath); } /* static */ nsresult diff --git a/mozilla/directory/xpcom/datasource/nsLDAPDataSource.js b/mozilla/directory/xpcom/datasource/nsLDAPDataSource.js index e09119f91f9..ec678ec7cf3 100644 --- a/mozilla/directory/xpcom/datasource/nsLDAPDataSource.js +++ b/mozilla/directory/xpcom/datasource/nsLDAPDataSource.js @@ -1358,41 +1358,41 @@ var nsLDAPDataSourceModule = { debug("*** Registering LDAP datasource components" + " (all right -- a JavaScript module!)\n"); - compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentManagerObsolete); + compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponenRegistrar); - compMgr.registerComponentWithType( + compMgr.registerFactoryLocation( NS_LDAPDATASOURCE_CID, 'LDAP RDF DataSource', NS_LDAPDATASOURCE_CONTRACTID, - fileSpec, location, true, true, + fileSpec, location, type); - compMgr.registerComponentWithType( + compMgr.registerFactoryLocation( NS_LDAPMESSAGERDFDELEGATEFACTORY_CID, 'LDAP Message RDF Delegate', NS_LDAPMESSAGERDFDELEGATEFACTORY_CONTRACTID, - fileSpec, location, true, true, + fileSpec, location, type); - compMgr.registerComponentWithType( + compMgr.registerFactoryLocation( NS_LDAPMESSAGERDFDELEGATEFACTORY_CID, 'LDAP Flat MessageList RDF Delegate', NS_LDAPFLATMESSAGELISTRDFDELEGATEFACTORY_CONTRACTID, - fileSpec, location, true, true, + fileSpec, location, type); - compMgr.registerComponentWithType( + compMgr.registerFactoryLocation( NS_LDAPMESSAGERDFDELEGATEFACTORY_CID, 'LDAP Recursive MessageList RDF Delegate', NS_LDAPRECURSIVEMESSAGELISTRDFDELEGATEFACTORY_CONTRACTID, - fileSpec, location, true, true, + fileSpec, location, type); - compMgr.registerComponentWithType( + compMgr.registerFactoryLocation( NS_LDAPURLRDFDELEGATEFACTORY_CID, 'LDAP URL RDF Delegate', NS_LDAPURLRDFDELEGATEFACTORY_CONTRACTID, - fileSpec, location, true, true, + fileSpec, location, type); }, diff --git a/mozilla/embedding/base/nsEmbedAPI.cpp b/mozilla/embedding/base/nsEmbedAPI.cpp index d1c128ef887..8fcf47a2161 100644 --- a/mozilla/embedding/base/nsEmbedAPI.cpp +++ b/mozilla/embedding/base/nsEmbedAPI.cpp @@ -23,6 +23,7 @@ */ #include "nsIServiceManager.h" +#include "nsIComponentRegistrar.h" #include "nsIEventQueueService.h" #include "nsIAppStartupNotifier.h" #include "nsIStringBundle.h" @@ -106,8 +107,15 @@ nsresult NS_InitEmbedding(nsILocalFile *mozBinDirectory, // Register components if (!sRegistryInitializedFlag) { - rv = nsComponentManager::AutoRegister(nsIComponentManagerObsolete::NS_Startup, - NULL /* default */); + nsCOMPtr registrar = do_QueryInterface(sServiceManager, &rv); + if (NS_FAILED(rv)) + { + NS_ASSERTION(PR_FALSE, "Could not QI to registrar"); + return rv; + } + + rv = registrar->AutoRegister(nsnull); + if (NS_FAILED(rv)) { NS_ASSERTION(PR_FALSE, "Could not AutoRegister"); diff --git a/mozilla/embedding/components/ui/helperAppDlg/nsHelperAppDlg.js b/mozilla/embedding/components/ui/helperAppDlg/nsHelperAppDlg.js index e892d0d16a2..43a183b4e7e 100644 --- a/mozilla/embedding/components/ui/helperAppDlg/nsHelperAppDlg.js +++ b/mozilla/embedding/components/ui/helperAppDlg/nsHelperAppDlg.js @@ -591,16 +591,14 @@ var module = { this.firstTime = false; throw Components.results.NS_ERROR_FACTORY_REGISTER_AGAIN; } - compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentManagerObsolete); + compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar); - compMgr.registerComponentWithType( this.cid, - "Mozilla Helper App Launcher Dialog", - this.contractId, - fileSpec, - location, - true, - true, - type ); + compMgr.registerFactoryLocation( this.cid, + "Mozilla Helper App Launcher Dialog", + this.contractId, + fileSpec, + location, + type ); }, // getClassObject: Return this component's factory object. diff --git a/mozilla/extensions/irc/js/lib/chatzilla-service.js b/mozilla/extensions/irc/js/lib/chatzilla-service.js index c9f1c2163ff..b76caf0a07a 100644 --- a/mozilla/extensions/irc/js/lib/chatzilla-service.js +++ b/mozilla/extensions/irc/js/lib/chatzilla-service.js @@ -282,12 +282,14 @@ function (compMgr, fileSpec, location, type) { dump("*** Registering -chat handler.\n"); - compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentManagerObsolete); + compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar); - compMgr.registerComponentWithType(CLINE_SERVICE_CID, - "Chatzilla CommandLine Service", - CLINE_SERVICE_CONTRACTID, fileSpec, - location, true, true, type); + compMgr.registerFactoryLocation(CLINE_SERVICE_CID, + "Chatzilla CommandLine Service", + CLINE_SERVICE_CONTRACTID, + fileSpec, + location, + type); catman = Components.classes["@mozilla.org/categorymanager;1"] .getService(nsICategoryManager); @@ -296,16 +298,20 @@ function (compMgr, fileSpec, location, type) CLINE_SERVICE_CONTRACTID, true, true); dump("*** Registering x-application-irc handler.\n"); - compMgr.registerComponentWithType(IRCCNT_HANDLER_CID, - "IRC Content Handler", - IRCCNT_HANDLER_CONTRACTID, fileSpec, - location, true, true, type); + compMgr.registerFactoryLocation(IRCCNT_HANDLER_CID, + "IRC Content Handler", + IRCCNT_HANDLER_CONTRACTID, + fileSpec, + location, + type); dump("*** Registering irc protocol handler.\n"); - compMgr.registerComponentWithType(IRCPROT_HANDLER_CID, - "IRC protocol handler", - IRCPROT_HANDLER_CONTRACTID, fileSpec, location, - true, true, type); + compMgr.registerFactoryLocation(IRCPROT_HANDLER_CID, + "IRC protocol handler", + IRCPROT_HANDLER_CONTRACTID, + fileSpec, + location, + type); } @@ -313,9 +319,10 @@ ChatzillaModule.unregisterSelf = function(compMgr, fileSpec, location) { - compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentManagerObsolete); + compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar); - compMgr.unregisterComponentSpec(CLINE_SERVICE_CID, fileSpec); + compMgr.unregisterFactoryLocation(CLINE_SERVICE_CID, + fileSpec); catman = Components.classes["@mozilla.org/categorymanager;1"] .getService(nsICategoryManager); catman.deleteCategoryEntry("command-line-argument-handlers", diff --git a/mozilla/extensions/venkman/js/venkman-service.js b/mozilla/extensions/venkman/js/venkman-service.js index 3467b126436..8bde5dda923 100644 --- a/mozilla/extensions/venkman/js/venkman-service.js +++ b/mozilla/extensions/venkman/js/venkman-service.js @@ -77,12 +77,14 @@ function (compMgr, fileSpec, location, type) { dump("*** Registering -venkman handler.\n"); - compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentManagerObsolete); + compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar); - compMgr.registerComponentWithType(CLINE_SERVICE_CID, - "Venkman CommandLine Service", - CLINE_SERVICE_CTRID, fileSpec, - location, true, true, type); + compMgr.registerFactoryLocation(CLINE_SERVICE_CID, + "Venkman CommandLine Service", + CLINE_SERVICE_CTRID, + fileSpec, + location, + type); catman = Components.classes[CATMAN_CTRID].getService(nsICategoryManager); catman.addCategoryEntry("command-line-argument-handlers", @@ -94,9 +96,9 @@ function (compMgr, fileSpec, location, type) Module.unregisterSelf = function(compMgr, fileSpec, location) { - compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentManagerObsolete); + compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar); - compMgr.unregisterComponentSpec(CLINE_SERVICE_CID, fileSpec); + compMgr.unregisterFactoryLocation(CLINE_SERVICE_CID, fileSpec); catman = Components.classes[CATMAN_CTRID].getService(nsICategoryManager); catman.deleteCategoryEntry("command-line-argument-handlers", CLINE_SERVICE_CTRID, true); diff --git a/mozilla/extensions/xml-rpc/src/nsDictionary.js b/mozilla/extensions/xml-rpc/src/nsDictionary.js index 14a838c87e4..acd59874221 100644 --- a/mozilla/extensions/xml-rpc/src/nsDictionary.js +++ b/mozilla/extensions/xml-rpc/src/nsDictionary.js @@ -18,9 +18,9 @@ /* * nsDictionary XPCOM component - * Version: $Revision: 1.5 $ + * Version: $Revision: 1.6 $ * - * $Id: nsDictionary.js,v 1.5 2001-12-19 00:11:33 dougt%netscape.com Exp $ + * $Id: nsDictionary.js,v 1.6 2002-01-29 21:21:33 dougt%netscape.com Exp $ */ /* @@ -83,10 +83,13 @@ nsDictionary.prototype= { /* nsDictionary Module (for XPCOM registration) */ var nsDictionaryModule = { registerSelf: function(compMgr, fileSpec, location, type) { - compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentManagerObsolete); - compMgr.registerComponentWithType(DICTIONARY_CID, - "nsDictionary JS component", DICTIONARY_CONTRACTID, fileSpec, location, - true, true, type); + compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar); + compMgr.registerFactoryLocation(DICTIONARY_CID, + "nsDictionary JS component", + DICTIONARY_CONTRACTID, + fileSpec, + location, + type); }, getClassObject: function(compMgr, cid, iid) { diff --git a/mozilla/extensions/xml-rpc/src/nsXmlRpcClient.js b/mozilla/extensions/xml-rpc/src/nsXmlRpcClient.js index ca93052bc30..fd41b85da64 100644 --- a/mozilla/extensions/xml-rpc/src/nsXmlRpcClient.js +++ b/mozilla/extensions/xml-rpc/src/nsXmlRpcClient.js @@ -20,9 +20,9 @@ /* * nsXmlRpcClient XPCOM component - * Version: $Revision: 1.20 $ + * Version: $Revision: 1.21 $ * - * $Id: nsXmlRpcClient.js,v 1.20 2002-01-24 22:31:28 heikki%netscape.com Exp $ + * $Id: nsXmlRpcClient.js,v 1.21 2002-01-29 21:21:33 dougt%netscape.com Exp $ */ /* @@ -1174,14 +1174,20 @@ PushbackInputStream.prototype = { /* nsXmlRpcClient Module (for XPCOM registration) */ var nsXmlRpcClientModule = { registerSelf: function(compMgr, fileSpec, location, type) { - compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentManagerObsolete); + compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar); - compMgr.registerComponentWithType(XMLRPCCLIENT_CID, - 'XML-RPC Client JS component', XMLRPCCLIENT_CONTRACTID, fileSpec, - location, true, true, type); - compMgr.registerComponentWithType(XMLRPCFAULT_CID, - 'XML-RPC Fault JS component', XMLRPCFAULT_CONTRACTID, fileSpec, - location, true, true, type); + compMgr.registerFactoryLocation(XMLRPCCLIENT_CID, + 'XML-RPC Client JS component', + XMLRPCCLIENT_CONTRACTID, + fileSpec, + location, + type); + compMgr.registerFactoryLocation(XMLRPCFAULT_CID, + 'XML-RPC Fault JS component', + XMLRPCFAULT_CONTRACTID, + fileSpec, + location, + type); }, getClassObject: function(compMgr, cid, iid) { diff --git a/mozilla/extensions/xmlterm/ui/xmlterm-service.js b/mozilla/extensions/xmlterm/ui/xmlterm-service.js index 15e2a33e503..15fa8ae79f2 100644 --- a/mozilla/extensions/xmlterm/ui/xmlterm-service.js +++ b/mozilla/extensions/xmlterm/ui/xmlterm-service.js @@ -324,12 +324,14 @@ function (compMgr, fileSpec, location, type) { dump("*** Registering -terminal handler.\n"); - compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentManagerObsolete); + compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar); - compMgr.registerComponentWithType(XMLTERMCLINE_SERVICE_CID, - "XMLterm CommandLine Service", - XMLTERMCLINE_SERVICE_CONTRACTID, fileSpec, - location, true, true, type); + compMgr.registerFactoryLocation(XMLTERMCLINE_SERVICE_CID, + "XMLterm CommandLine Service", + XMLTERMCLINE_SERVICE_CONTRACTID, + fileSpec, + location, + type); catman = Components.classes["@mozilla.org/categorymanager;1"] .getService(nsICategoryManager); @@ -338,24 +340,28 @@ function (compMgr, fileSpec, location, type) XMLTERMCLINE_SERVICE_CONTRACTID, true, true); dump("*** Registering x-application-terminal handler.\n"); - compMgr.registerComponentWithType(XMLTERMCNT_HANDLER_CID, - "XMLTerm Content Handler", - XMLTERMCNT_HANDLER_CONTRACTID, fileSpec, - location, true, true, type); + compMgr.registerFactoryLocation(XMLTERMCNT_HANDLER_CID, + "XMLTerm Content Handler", + XMLTERMCNT_HANDLER_CONTRACTID, + fileSpec, + location, + type); dump("*** Registering terminal protocol handler.\n"); - compMgr.registerComponentWithType(XMLTERMPROT_HANDLER_CID, - "XMLTerm protocol handler", - XMLTERMPROT_HANDLER_CONTRACTID, fileSpec, location, - true, true, type); + compMgr.registerFactoryLocation(XMLTERMPROT_HANDLER_CID, + "XMLTerm protocol handler", + XMLTERMPROT_HANDLER_CONTRACTID, + fileSpec, + location, + type); } XMLtermModule.unregisterSelf = function(compMgr, fileSpec, location) { - compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentManagerObsolete); - compMgr.unregisterComponentSpec(XMLTERMCLINE_SERVICE_CID, fileSpec); + compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar); + compMgr.unregisterFactoryLocation(XMLTERMCLINE_SERVICE_CID, fileSpec); catman = Components.classes["@mozilla.org/categorymanager;1"] .getService(nsICategoryManager); catman.deleteCategoryEntry("command-line-argument-handlers", diff --git a/mozilla/htmlparser/tests/outsinks/Convert.cpp b/mozilla/htmlparser/tests/outsinks/Convert.cpp index d4f18264664..bd9dd973d7b 100644 --- a/mozilla/htmlparser/tests/outsinks/Convert.cpp +++ b/mozilla/htmlparser/tests/outsinks/Convert.cpp @@ -30,6 +30,8 @@ #include "nsLayoutCID.h" #include "nsIHTMLToTextSink.h" #include "nsIComponentManager.h" +#include "nsIServiceManager.h" +#include "nsIComponentRegistrar.h" #include "nsReadableUtils.h" static NS_DEFINE_IID(kIParserIID, NS_IPARSER_IID); @@ -288,8 +290,12 @@ Usage: %s [-i intype] [-o outtype] [-f flags] [-w wrapcol] [-c comparison_file] } else file = stdin; - NS_InitXPCOM2(nsnull, nsnull, nsnull); - nsComponentManager::AutoRegister(nsIComponentManagerObsolete::NS_Startup, 0); + + nsCOMPtr servMan; + NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + registrar->AutoRegister(nsnull); // Read in the string: very inefficient, but who cares? nsString inString; diff --git a/mozilla/intl/strres/tests/StringBundleTest.cpp b/mozilla/intl/strres/tests/StringBundleTest.cpp index 0ca797a4a8e..22289f1c696 100644 --- a/mozilla/intl/strres/tests/StringBundleTest.cpp +++ b/mozilla/intl/strres/tests/StringBundleTest.cpp @@ -48,6 +48,7 @@ #include "nsIIOService.h" #include "nsIURL.h" #include "nsIServiceManager.h" +#include "nsIComponentRegistrar.h" #include "nsNetCID.h" #include "nsIServiceManager.h" @@ -135,51 +136,18 @@ getUILangCountry(PRUnichar** aUILang, PRUnichar** aCountry) return result; } -//////////////////////////////////////////////////////////////////////////////////////////////////// -// -// end of locale stuff -// -//////////////////////////////////////////////////////////////////////////////////////////////////// -nsresult NS_AutoregisterComponents() -{ - nsresult rv = nsComponentManager::AutoRegister(nsIComponentManagerObsolete::NS_Startup, - NULL /* default */); - - // startup netlib: - nsComponentManager::RegisterComponent(kEventQueueServiceCID, - NULL, NULL, - XPCOM_DLL, - PR_FALSE, PR_FALSE); - nsComponentManager::RegisterComponent(kIOServiceCID, NULL, NULL, NETLIB_DLL, PR_FALSE, PR_FALSE); - - // Create the Event Queue for this thread... - nsIEventQueueService* pEventQService; - - pEventQService = nsnull; - nsresult result = nsServiceManager::GetService(kEventQueueServiceCID, - kIEventQueueServiceIID, - (nsISupports **)&pEventQService); - if (NS_SUCCEEDED(result)) { - // XXX: What if this fails? - result = pEventQService->CreateThreadEventQueue(); - } - - nsComponentManager::RegisterComponent(kPersistentPropertiesCID, - NULL, - NULL, - RAPTORBASE_DLL, - PR_FALSE, - PR_FALSE); - return rv; -} int main(int argc, char *argv[]) { nsresult ret; - NS_AutoregisterComponents(); - + nsCOMPtr servMan; + NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + registrar->AutoRegister(nsnull); + nsIStringBundleService* service = nsnull; ret = nsServiceManager::GetService(kStringBundleServiceCID, kIStringBundleServiceIID, (nsISupports**) &service); diff --git a/mozilla/js/src/xpconnect/shell/xpcshell.cpp b/mozilla/js/src/xpconnect/shell/xpcshell.cpp index b47082f39b1..f218f111ce7 100644 --- a/mozilla/js/src/xpconnect/shell/xpcshell.cpp +++ b/mozilla/js/src/xpconnect/shell/xpcshell.cpp @@ -45,6 +45,7 @@ #include "nsIXPCScriptable.h" #include "nsIServiceManager.h" #include "nsIComponentManager.h" +#include "nsIComponentRegistrar.h" #include "jsapi.h" #include "jsprf.h" #include "nscore.h" @@ -78,13 +79,6 @@ /***************************************************************************/ -static void SetupRegistry() -{ - nsComponentManager::AutoRegister(nsIComponentManagerObsolete::NS_Startup, nsnull); -} - -/***************************************************************************/ - #ifdef JS_THREADSAFE #define DoBeginRequest(cx) JS_BeginRequest((cx)) #define DoEndRequest(cx) JS_EndRequest((cx)) @@ -834,13 +828,16 @@ main(int argc, char **argv) gErrFile = stderr; gOutFile = stdout; - rv = NS_InitXPCOM2(NULL, NULL, NULL); + nsCOMPtr servMan; + rv = NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); if (NS_FAILED(rv)) { printf("NS_InitXPCOM failed!\n"); return 1; } - - SetupRegistry(); + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + registrar->AutoRegister(nsnull); + nsCOMPtr rtsvc = do_GetService("@mozilla.org/js/xpc/RuntimeService;1"); // get the JSRuntime from the runtime svc diff --git a/mozilla/js/src/xpconnect/src/xpccomponents.cpp b/mozilla/js/src/xpconnect/src/xpccomponents.cpp index 1a3e7af9369..37f63f7e5fb 100644 --- a/mozilla/js/src/xpconnect/src/xpccomponents.cpp +++ b/mozilla/js/src/xpconnect/src/xpccomponents.cpp @@ -363,17 +363,15 @@ nsXPCComponents_Classes::NewEnumerate(nsIXPConnectWrappedNative *wrapper, PRUint32 enum_op, jsval * statep, jsid * idp, PRBool *_retval) { - nsIEnumerator* e; + nsISimpleEnumerator* e; switch(enum_op) { case JSENUMERATE_INIT: { - nsIComponentManagerObsolete* compMgr; - if(NS_FAILED(NS_GetGlobalComponentManager((nsIComponentManager**)&compMgr)) || - !compMgr || NS_FAILED(compMgr->EnumerateContractIDs(&e)) || !e || - NS_FAILED(e->First())) - + nsCOMPtr compMgr; + if(NS_FAILED(NS_GetComponentRegistrar(getter_AddRefs(compMgr))) || !compMgr || + NS_FAILED(compMgr->EnumerateContractIDs(&e)) || !e ) { *statep = JSVAL_NULL; return NS_ERROR_UNEXPECTED; @@ -387,12 +385,12 @@ nsXPCComponents_Classes::NewEnumerate(nsIXPConnectWrappedNative *wrapper, case JSENUMERATE_NEXT: { nsCOMPtr isup; - - e = (nsIEnumerator*) JSVAL_TO_PRIVATE(*statep); - if(NS_COMFALSE == e->IsDone() && - NS_SUCCEEDED(e->CurrentItem(getter_AddRefs(isup))) && isup) + PRBool hasMore; + e = (nsISimpleEnumerator*) JSVAL_TO_PRIVATE(*statep); + + if(NS_SUCCEEDED(e->HasMoreElements(&hasMore)) && hasMore && + NS_SUCCEEDED(e->GetNext(getter_AddRefs(isup))) && isup) { - e->Next(); nsCOMPtr holder(do_QueryInterface(isup)); if(holder) { @@ -414,7 +412,7 @@ nsXPCComponents_Classes::NewEnumerate(nsIXPConnectWrappedNative *wrapper, case JSENUMERATE_DESTROY: default: - e = (nsIEnumerator*) JSVAL_TO_PRIVATE(*statep); + e = (nsISimpleEnumerator*) JSVAL_TO_PRIVATE(*statep); NS_IF_RELEASE(e); *statep = JSVAL_NULL; return NS_OK; @@ -523,17 +521,15 @@ nsXPCComponents_ClassesByID::NewEnumerate(nsIXPConnectWrappedNative *wrapper, PRUint32 enum_op, jsval * statep, jsid * idp, PRBool *_retval) { - nsIEnumerator* e; + nsISimpleEnumerator* e; switch(enum_op) { case JSENUMERATE_INIT: { - nsIComponentManagerObsolete* compMgr; - if(NS_FAILED(NS_GetGlobalComponentManager((nsIComponentManager**)&compMgr)) || - !compMgr || NS_FAILED(compMgr->EnumerateCLSIDs(&e)) || !e || - NS_FAILED(e->First())) - + nsCOMPtr compMgr; + if(NS_FAILED(NS_GetComponentRegistrar(getter_AddRefs(compMgr))) || !compMgr || + NS_FAILED(compMgr->EnumerateCIDs(&e)) || !e ) { *statep = JSVAL_NULL; return NS_ERROR_UNEXPECTED; @@ -547,12 +543,12 @@ nsXPCComponents_ClassesByID::NewEnumerate(nsIXPConnectWrappedNative *wrapper, case JSENUMERATE_NEXT: { nsCOMPtr isup; + PRBool hasMore; + e = (nsISimpleEnumerator*) JSVAL_TO_PRIVATE(*statep); - e = (nsIEnumerator*) JSVAL_TO_PRIVATE(*statep); - if(NS_COMFALSE == e->IsDone() && - NS_SUCCEEDED(e->CurrentItem(getter_AddRefs(isup))) && isup) + if(NS_SUCCEEDED(e->HasMoreElements(&hasMore)) && hasMore && + NS_SUCCEEDED(e->GetNext(getter_AddRefs(isup))) && isup) { - e->Next(); nsCOMPtr holder(do_QueryInterface(isup)); if(holder) { @@ -574,7 +570,7 @@ nsXPCComponents_ClassesByID::NewEnumerate(nsIXPConnectWrappedNative *wrapper, case JSENUMERATE_DESTROY: default: - e = (nsIEnumerator*) JSVAL_TO_PRIVATE(*statep); + e = (nsISimpleEnumerator*) JSVAL_TO_PRIVATE(*statep); NS_IF_RELEASE(e); *statep = JSVAL_NULL; return NS_OK; @@ -590,9 +586,9 @@ IsRegisteredCLSID(const char* str) if(!id.Parse(str)) return PR_FALSE; - nsIComponentManagerObsolete* compMgr; - if(NS_FAILED(NS_GetGlobalComponentManager((nsIComponentManager**)&compMgr)) || - !compMgr || NS_FAILED(compMgr->IsRegistered(id, ®istered))) + nsCOMPtr compMgr; + if(NS_FAILED(NS_GetComponentRegistrar(getter_AddRefs(compMgr))) || !compMgr || + NS_FAILED(compMgr->IsCIDRegistered(id, ®istered))) return PR_FALSE; return registered; diff --git a/mozilla/js/src/xpconnect/src/xpcprivate.h b/mozilla/js/src/xpconnect/src/xpcprivate.h index 96005ba7dfd..be9a28c9c2c 100644 --- a/mozilla/js/src/xpconnect/src/xpcprivate.h +++ b/mozilla/js/src/xpconnect/src/xpcprivate.h @@ -45,10 +45,12 @@ #include #include #include "nscore.h" +#include "nsXPCOM.h" #include "nsISupports.h" #include "nsIServiceManager.h" #include "nsIClassInfo.h" #include "nsIComponentManager.h" +#include "nsIComponentRegistrar.h" #include "nsISupportsPrimitives.h" #include "nsIGenericFactory.h" #include "nsMemory.h" diff --git a/mozilla/js/src/xpconnect/tests/TestXPC.cpp b/mozilla/js/src/xpconnect/tests/TestXPC.cpp index b6b5606b8fc..3ac0174e446 100644 --- a/mozilla/js/src/xpconnect/tests/TestXPC.cpp +++ b/mozilla/js/src/xpconnect/tests/TestXPC.cpp @@ -41,6 +41,7 @@ #include "nsIScriptError.h" #include "nsIServiceManager.h" #include "nsIComponentManager.h" +#include "nsIComponentRegistrar.h" #include "nsIJSContextStack.h" #include "nsIJSRuntimeService.h" #include "nsMemory.h" @@ -54,14 +55,6 @@ #include "xpctest.h" -/***************************************************************************/ -// initialization stuff for the xpcom runtime - -static void SetupRegistry() -{ - nsComponentManager::AutoRegister(nsIComponentManagerObsolete::NS_Startup, nsnull); -} - /***************************************************************************/ // host support for jsengine @@ -713,8 +706,12 @@ int main() gErrFile = stderr; gOutFile = stdout; - SetupRegistry(); - + nsCOMPtr servMan; + NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + registrar->AutoRegister(nsnull); + // get the JSRuntime from the runtime svc, if possible nsCOMPtr rtsvc = do_GetService("@mozilla.org/js/xpc/RuntimeService;1", &rv); diff --git a/mozilla/layout/build/nsContentDLF.cpp b/mozilla/layout/build/nsContentDLF.cpp index 2ae702f9ed0..bb95a4e3ef7 100644 --- a/mozilla/layout/build/nsContentDLF.cpp +++ b/mozilla/layout/build/nsContentDLF.cpp @@ -40,6 +40,7 @@ #include "nsGenericHTMLElement.h" #include "nsHTMLAtoms.h" #include "nsIComponentManager.h" +#include "nsIComponentRegistrar.h" #include "nsICategoryManager.h" #include "nsIDocumentLoader.h" #include "nsIDocumentLoaderFactory.h" @@ -580,16 +581,16 @@ RegisterTypes(nsIComponentManager* aCompMgr, #ifdef NOISY_REGISTRY printf("Register %s => %s\n", contractid, aPath); #endif - - // what I want to do here is QI for a Component Registration Manager. Since this - // has not been invented yet, QI to the obsolete manager. Kids, don't do this at home. - nsCOMPtr obsoleteManager = do_QueryInterface(aCompMgr, &rv); + nsCOMPtr registrar = do_QueryInterface(aCompMgr, &rv); if (NS_FAILED(rv)) return rv; - rv = obsoleteManager->RegisterComponentWithType(kDocumentFactoryImplCID, "Layout", - contractid, aPath, aLocation, - PR_TRUE, PR_TRUE, aType); + rv = registrar->RegisterFactoryLocation(kDocumentFactoryImplCID, + "Layout", + contractid, + aPath, + aLocation, + aType); if (NS_FAILED(rv)) break; // add the MIME types layotu can handle to the handlers category. @@ -657,15 +658,12 @@ nsContentDLF::UnregisterDocumentFactories(nsIComponentManager* aCompMgr, const nsModuleComponentInfo* aInfo) { // XXXwaterson seems like this leaves the registry pretty dirty. - - // what I want to do here is QI for a Component Registration Manager. Since this - // has not been invented yet, QI to the obsolete manager. Kids, don't do this at home. nsresult rv; - nsCOMPtr obsoleteManager = do_QueryInterface(aCompMgr, &rv); + nsCOMPtr registrar = do_QueryInterface(aCompMgr, &rv); if (NS_FAILED(rv)) return rv; - return obsoleteManager->UnregisterComponentSpec(kDocumentFactoryImplCID, aPath); + return registrar->UnregisterFactoryLocation(kDocumentFactoryImplCID, aPath); } /* static */ nsresult diff --git a/mozilla/mailnews/addrbook/src/nsAbView.cpp b/mozilla/mailnews/addrbook/src/nsAbView.cpp index dc108617d22..dfad8d84901 100644 --- a/mozilla/mailnews/addrbook/src/nsAbView.cpp +++ b/mozilla/mailnews/addrbook/src/nsAbView.cpp @@ -533,13 +533,16 @@ NS_IMETHODIMP nsAbView::PerformActionOnCell(const PRUnichar *action, PRInt32 row NS_IMETHODIMP nsAbView::GetCardFromRow(PRInt32 row, nsIAbCard **aCard) { - if ((mCards.Count() <= row) || (row < 0)) { - *aCard = nsnull; + *aCard = nsnull; + if ((mCards.Count() <= row) || (row < 0)) { return NS_OK; } - *aCard = ((AbCard *)(mCards.ElementAt(row)))->card; - NS_IF_ADDREF(*aCard); + AbCard *a = ((AbCard *)(mCards.ElementAt(row))); + if (!a) + return NS_OK; + + NS_IF_ADDREF(*aCard = a->card); return NS_OK; } diff --git a/mozilla/mailnews/addrbook/src/nsLDAPPrefsService.js b/mozilla/mailnews/addrbook/src/nsLDAPPrefsService.js index ebcd3ae1bca..cda9135019a 100644 --- a/mozilla/mailnews/addrbook/src/nsLDAPPrefsService.js +++ b/mozilla/mailnews/addrbook/src/nsLDAPPrefsService.js @@ -278,19 +278,21 @@ var nsLDAPPrefsModule = new Object(); nsLDAPPrefsModule.registerSelf = function (compMgr, fileSpec, location, type) { - compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentManagerObsolete); + compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar); - compMgr.registerComponentWithType(NS_LDAPPREFSSERVICE_CID, - "nsLDAPPrefs Service", - NS_LDAPPREFSSERVICE_CONTRACTID, fileSpec, - location, true, true, type); + compMgr.registerFactoryLocation(NS_LDAPPREFSSERVICE_CID, + "nsLDAPPrefs Service", + NS_LDAPPREFSSERVICE_CONTRACTID, + fileSpec, + location, + type); } nsLDAPPrefsModule.unregisterSelf = function(compMgr, fileSpec, location) { - compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentManagerObsolete); - compMgr.unregisterComponentSpec(NS_LDAPPREFSSERVICE_CID, fileSpec); + compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar); + compMgr.unregisterFactoryLocation(NS_LDAPPREFSSERVICE_CID, fileSpec); } nsLDAPPrefsModule.getClassObject = diff --git a/mozilla/mailnews/extensions/smime/src/smime-service.js b/mozilla/mailnews/extensions/smime/src/smime-service.js index 235bffb623c..407c123e1ac 100644 --- a/mozilla/mailnews/extensions/smime/src/smime-service.js +++ b/mozilla/mailnews/extensions/smime/src/smime-service.js @@ -66,11 +66,13 @@ SMIMEModule.registerSelf = function (compMgr, fileSpec, location, type) { dump("*** Registering smime account manager extension.\n"); - compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentManagerObsolete); - compMgr.registerComponentWithType(SMIME_EXTENSION_SERVICE_CID, - "SMIME Account Manager Extension Service", - SMIME_EXTENSION_SERVICE_CONTRACTID, fileSpec, - location, true, true, type); + compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar); + compMgr.registerFactoryLocation(SMIME_EXTENSION_SERVICE_CID, + "SMIME Account Manager Extension Service", + SMIME_EXTENSION_SERVICE_CONTRACTID, + fileSpec, + location, + type); catman = Components.classes["@mozilla.org/categorymanager;1"].getService(nsICategoryManager); catman.addCategoryEntry("mailnews-accountmanager-extensions", "smime account manager extension", @@ -80,8 +82,8 @@ function (compMgr, fileSpec, location, type) SMIMEModule.unregisterSelf = function(compMgr, fileSpec, location) { - compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentManagerObsolete); - compMgr.unregisterComponentSpec(SMIME_EXTENSION_SERVICE_CID, fileSpec); + compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar); + compMgr.unregisterFactoryLocation(SMIME_EXTENSION_SERVICE_CID, fileSpec); catman = Components.classes["@mozilla.org/categorymanager;1"].getService(nsICategoryManager); catman.deleteCategoryEntry("mailnews-accountmanager-extensions", SMIME_EXTENSION_SERVICE_CONTRACTID, true); diff --git a/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp b/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp index dafe9cc7d45..84ca0005e77 100644 --- a/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp +++ b/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp @@ -86,7 +86,7 @@ #include "nsHashtable.h" #include "nsIProxyInfo.h" #include "nsObsoleteModuleLoading.h" - +#include "nsIComponentRegistrar.h" #include "nsPluginLogging.h" #include "nsDirectoryServiceDefs.h" #include "nsAppDirectoryServiceDefs.h" @@ -2639,10 +2639,18 @@ nsresult nsPluginHostImpl::ReloadPlugins(PRBool reloadPages) mPluginsLoaded = PR_FALSE; //refresh the component registry first - nsComponentManager::AutoRegister(nsIComponentManagerObsolete::NS_Startup, nsnull); + nsCOMPtr servManager; + NS_GetServiceManager(getter_AddRefs(servManager)); + nsCOMPtr registrar = do_QueryInterface(servManager); + if (!registrar) { + NS_ASSERTION(0, "No nsIComponentRegistrar from get service"); + return NS_ERROR_FAILURE; + } + NS_ASSERTION(registrar, "No nsIComponentRegistrar from get service"); + nsresult rv = registrar->AutoRegister(nsnull); // load them again - nsresult rv = LoadPlugins(); + rv = LoadPlugins(); PLUGIN_LOG(PLUGIN_LOG_NORMAL, ("nsPluginHostImpl::ReloadPlugins End active_instance_count=%d\n", diff --git a/mozilla/netwerk/base/src/nsFilters.js b/mozilla/netwerk/base/src/nsFilters.js index 135db650065..8f3766606c4 100644 --- a/mozilla/netwerk/base/src/nsFilters.js +++ b/mozilla/netwerk/base/src/nsFilters.js @@ -67,12 +67,13 @@ var filterModule = new Object(); filterModule.registerSelf = function (compMgr, fileSpec, location, type) { dump("*** Registering Web Filters (a Javascript module!)\n"); - compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentManagerObsolete); + compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar); compMgr.registerComponentWithType(kFILTERS_CID, - "Javascript Web Filters", - kFILTERS_CONTRACTID, - fileSpec, location, - true, true, type); + "Javascript Web Filters", + kFILTERS_CONTRACTID, + fileSpec, + location, + type); } filterModule.getClassObject = diff --git a/mozilla/netwerk/base/src/nsProxyAutoConfig.js b/mozilla/netwerk/base/src/nsProxyAutoConfig.js index ddb03df1672..3d57f0182b5 100644 --- a/mozilla/netwerk/base/src/nsProxyAutoConfig.js +++ b/mozilla/netwerk/base/src/nsProxyAutoConfig.js @@ -188,12 +188,13 @@ var pacModule = new Object(); pacModule.registerSelf = function (compMgr, fileSpec, location, type) { - compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentManagerObsolete); - compMgr.registerComponentWithType(kPAC_CID, - "Proxy Auto Config", - kPAC_CONTRACTID, - fileSpec, location, - true, true, type); + compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar); + compMgr.registerFactoryLocation(kPAC_CID, + "Proxy Auto Config", + kPAC_CONTRACTID, + fileSpec, + location, + type); } pacModule.getClassObject = diff --git a/mozilla/netwerk/base/tests/urltest.cpp b/mozilla/netwerk/base/tests/urltest.cpp index 3bb3c3a07d5..c41aceb2290 100644 --- a/mozilla/netwerk/base/tests/urltest.cpp +++ b/mozilla/netwerk/base/tests/urltest.cpp @@ -50,7 +50,7 @@ #include "nsIEventQueue.h" #include "nsIComponentManager.h" - +#include "nsIComponentRegistrar.h" #include "nsIStreamListener.h" #include "nsIInputStream.h" #include "nsINetService.h" @@ -252,8 +252,12 @@ int main(int argc, char **argv) return 0; } - nsComponentManager::AutoRegister(nsIComponentManagerObsolete::NS_Startup, "./components"); - + nsCOMPtr servMan; + NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + registrar->AutoRegister(nsnull); + testURL(argv[1]); return 0; #if 0 diff --git a/mozilla/netwerk/streamconv/test/TestStreamConv.cpp b/mozilla/netwerk/streamconv/test/TestStreamConv.cpp index c56fb8d9d2e..d9ea72b78b5 100644 --- a/mozilla/netwerk/streamconv/test/TestStreamConv.cpp +++ b/mozilla/netwerk/streamconv/test/TestStreamConv.cpp @@ -37,6 +37,7 @@ #include "nsIServiceManager.h" #include "nsIComponentManager.h" +#include "nsIComponentRegistrar.h" #include "nsIStreamConverterService.h" #include "nsIStreamConverter.h" #include "nsICategoryManager.h" @@ -139,7 +140,12 @@ int main(int argc, char* argv[]) { nsresult rv; - + nsCOMPtr servMan; + NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + registrar->AutoRegister(nsnull); + // Create the Event Queue for this thread... nsCOMPtr eventQService = do_GetService(kEventQueueServiceCID, &rv); @@ -150,9 +156,6 @@ main(int argc, char* argv[]) eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, &gEventQ); - rv = nsComponentManager::AutoRegister(nsIComponentManagerObsolete::NS_Startup, NULL /* default */); - if (NS_FAILED(rv)) return rv; - nsCOMPtr catman = do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv); if (NS_FAILED(rv)) return rv; diff --git a/mozilla/netwerk/test/TestCacheBlockFiles.cpp b/mozilla/netwerk/test/TestCacheBlockFiles.cpp index a083de80b72..095a6f8e902 100644 --- a/mozilla/netwerk/test/TestCacheBlockFiles.cpp +++ b/mozilla/netwerk/test/TestCacheBlockFiles.cpp @@ -18,11 +18,12 @@ #include "nsDirectoryServiceDefs.h" #include "nsError.h" #include "nsIComponentManager.h" +#include "nsIComponentRegistrar.h" #include "nsIFile.h" #include "nsILocalFile.h" #include "nsIFileStreams.h" #include "nsMemory.h" - +#include "nsIComponentRegistrar.h" #include "nsANSIFileStreams.h" #include "nsDiskCacheBlockFile.h" @@ -212,12 +213,11 @@ main(void) nsresult rv = NS_OK; // Start up XPCOM - rv = NS_InitXPCOM2(nsnull, nsnull, nsnull); - if (NS_FAILED(rv)) return rv; - - // Register components - nsComponentManager::AutoRegister(nsIComponentManagerObsolete::NS_Startup, nsnull); - + nsCOMPtr servMan; + NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + registrar->AutoRegister(nsnull); // Get default directory rv = NS_GetSpecialDirectory(NS_XPCOM_CURRENT_PROCESS_DIR, diff --git a/mozilla/netwerk/test/TestCacheMgr.cpp b/mozilla/netwerk/test/TestCacheMgr.cpp index 2c88594a748..e6dfeae3e0c 100644 --- a/mozilla/netwerk/test/TestCacheMgr.cpp +++ b/mozilla/netwerk/test/TestCacheMgr.cpp @@ -19,6 +19,7 @@ #include "nsIStreamListener.h" #include "nsIRequestObserver.h" #include "nsIServiceManager.h" +#include "nsIComponentRegistrar.h" #include "nsIInputStream.h" #include "nsIOutputStream.h" #include "nsIEventQueue.h" @@ -542,13 +543,6 @@ FillCache(nsINetDataCacheManager *aCache, PRUint32 aFlags, PRUint32 aCacheCapaci return NS_OK; } -nsresult NS_AutoregisterComponents() -{ - nsresult rv = nsComponentManager::AutoRegister(nsIComponentManagerObsolete::NS_Startup, - NULL /* default */); - return rv; -} - nsresult Test(nsINetDataCacheManager *aCache, PRUint32 aFlags, PRUint32 aCacheCapacity) { @@ -583,8 +577,13 @@ main(int argc, char* argv[]) nsresult rv; nsCOMPtr cache; - rv = NS_AutoregisterComponents(); - NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't register XPCOM components"); + + // Start up XPCOM + nsCOMPtr servMan; + NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + registrar->AutoRegister(nsnull); rv = nsComponentManager::CreateInstance(NS_NETWORK_CACHE_MANAGER_CONTRACTID, nsnull, diff --git a/mozilla/netwerk/test/TestFileInput.cpp b/mozilla/netwerk/test/TestFileInput.cpp index 7db7ccc4616..517d7583e36 100644 --- a/mozilla/netwerk/test/TestFileInput.cpp +++ b/mozilla/netwerk/test/TestFileInput.cpp @@ -38,6 +38,7 @@ #include "nsIFileTransportService.h" #include "nsIStreamListener.h" #include "nsIServiceManager.h" +#include "nsIComponentRegistrar.h" #include "nsIInputStream.h" #include "nsIEventQueue.h" #include "nsIEventQueueService.h" @@ -393,12 +394,6 @@ ParallelReadTest(char* dirName, nsIFileTransportService* fts) NS_ASSERTION(status == PR_SUCCESS, "can't close dir"); } -nsresult NS_AutoregisterComponents() -{ - nsresult rv = nsComponentManager::AutoRegister(nsIComponentManagerObsolete::NS_Startup, NULL /* default */); - return rv; -} - int main(int argc, char* argv[]) { @@ -410,8 +405,12 @@ main(int argc, char* argv[]) } char* dirName = argv[1]; - rv = NS_AutoregisterComponents(); - if (NS_FAILED(rv)) return rv; + + nsCOMPtr servMan; + NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + registrar->AutoRegister(nsnull); nsCOMPtr fts = do_GetService(kFileTransportServiceCID, &rv); diff --git a/mozilla/netwerk/test/TestFileInput2.cpp b/mozilla/netwerk/test/TestFileInput2.cpp index b612f0a0e93..3fc48997dac 100644 --- a/mozilla/netwerk/test/TestFileInput2.cpp +++ b/mozilla/netwerk/test/TestFileInput2.cpp @@ -36,6 +36,7 @@ * ***** END LICENSE BLOCK ***** */ #include "nsIServiceManager.h" +#include "nsIComponentRegistrar.h" #include "nsIInputStream.h" #include "nsIOutputStream.h" #include "nsIRunnable.h" @@ -443,12 +444,6 @@ Test(CreateFun create, PRUint32 count, //////////////////////////////////////////////////////////////////////////////// -nsresult NS_AutoregisterComponents() -{ - nsresult rv = nsComponentManager::AutoRegister(nsIComponentManagerObsolete::NS_Startup, NULL /* default */); - return rv; -} - int main(int argc, char* argv[]) { @@ -461,8 +456,12 @@ main(int argc, char* argv[]) char* inDir = argv[1]; char* outDir = argv[2]; - rv = NS_AutoregisterComponents(); - if (NS_FAILED(rv)) return rv; + + nsCOMPtr servMan; + NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + registrar->AutoRegister(nsnull); nsCOMPtr inDirFile; rv = NS_NewLocalFile(inDir, PR_FALSE, getter_AddRefs(inDirFile)); diff --git a/mozilla/netwerk/test/TestFileTransport.cpp b/mozilla/netwerk/test/TestFileTransport.cpp index 472edbd8394..5f41e363623 100644 --- a/mozilla/netwerk/test/TestFileTransport.cpp +++ b/mozilla/netwerk/test/TestFileTransport.cpp @@ -35,6 +35,7 @@ * * ***** END LICENSE BLOCK ***** */ +#include "nsIComponentRegistrar.h" #include "nsIFileTransportService.h" #include "nsITransport.h" #include "nsIProgressEventSink.h" @@ -339,12 +340,6 @@ NS_IMPL_ISUPPORTS1(MyOpenObserver, nsIRequestObserver); //////////////////////////////////////////////////////////////////////////////// -nsresult -NS_AutoregisterComponents() -{ - nsresult rv = nsComponentManager::AutoRegister(nsIComponentManagerObsolete::NS_Startup, NULL /* default */); - return rv; -} int main(int argc, char* argv[]) @@ -361,8 +356,11 @@ main(int argc, char* argv[]) } char* fileName = argv[1]; - rv = NS_AutoregisterComponents(); - if (NS_FAILED(rv)) return rv; + nsCOMPtr servMan; + NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + registrar->AutoRegister(nsnull); nsCOMPtr eventQService = do_GetService(kEventQueueServiceCID, &rv); diff --git a/mozilla/netwerk/test/TestHttp.cpp b/mozilla/netwerk/test/TestHttp.cpp index ccf23d962ed..5f0d4a5a208 100644 --- a/mozilla/netwerk/test/TestHttp.cpp +++ b/mozilla/netwerk/test/TestHttp.cpp @@ -1,6 +1,7 @@ #include "nsNetUtil.h" #include "nsIEventQueueService.h" #include "nsIServiceManager.h" +#include "nsIComponentRegistrar.h" #include "nsIInterfaceRequestor.h" #include "nsIInterfaceRequestorUtils.h" #include "nsIProgressEventSink.h" @@ -124,11 +125,6 @@ MyNotifications::OnProgress(nsIRequest *req, nsISupports *ctx, // main, etc.. //----------------------------------------------------------------------------- -nsresult NS_AutoregisterComponents() -{ - nsresult rv = nsComponentManager::AutoRegister(nsIComponentManagerObsolete::NS_Startup, NULL /* default */); - return rv; -} int main(int argc, char **argv) { @@ -139,8 +135,11 @@ int main(int argc, char **argv) return -1; } - rv = NS_AutoregisterComponents(); - RETURN_IF_FAILED(rv, "NS_AutoregisterComponents"); + nsCOMPtr servMan; + NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + registrar->AutoRegister(nsnull); // Create the Event Queue for this thread... nsCOMPtr eqs = diff --git a/mozilla/netwerk/test/TestMakeAbs.cpp b/mozilla/netwerk/test/TestMakeAbs.cpp index 822d5ad663d..e6ec0f7d6b6 100644 --- a/mozilla/netwerk/test/TestMakeAbs.cpp +++ b/mozilla/netwerk/test/TestMakeAbs.cpp @@ -40,16 +40,11 @@ #include "nsCOMPtr.h" #include "nsIIOService.h" #include "nsIServiceManager.h" +#include "nsIComponentRegistrar.h" #include "nsIURI.h" static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); -nsresult NS_AutoregisterComponents() -{ - nsresult rv = nsComponentManager::AutoRegister(nsIComponentManagerObsolete::NS_Startup, NULL /* default */); - return rv; -} - nsresult ServiceMakeAbsolute(nsIURI *baseURI, char *relativeInfo, char **_retval) { nsresult rv; nsCOMPtr serv(do_GetService(kIOServiceCID, &rv)); @@ -75,8 +70,11 @@ main(int argc, char* argv[]) char *base = argv[2]; char *rel = argv[3]; - rv = NS_AutoregisterComponents(); - if (NS_FAILED(rv)) return rv; + nsCOMPtr servMan; + NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + registrar->AutoRegister(nsnull); nsCOMPtr serv(do_GetService(kIOServiceCID, &rv)); if (NS_FAILED(rv)) return rv; diff --git a/mozilla/netwerk/test/TestPageLoad.cpp b/mozilla/netwerk/test/TestPageLoad.cpp index 0f692c3df99..9777086211b 100644 --- a/mozilla/netwerk/test/TestPageLoad.cpp +++ b/mozilla/netwerk/test/TestPageLoad.cpp @@ -50,7 +50,7 @@ #include "nsSupportsArray.h" #include #include "nsReadableUtils.h" - +#include "nsIComponentRegistrar.h" int getStrLine(const char *src, char *str, int ind, int max); nsresult auxLoad(char *uriBuf); //---------------------------------------------------------------------- @@ -265,13 +265,6 @@ MyNotifications::OnProgress(nsIRequest *req, nsISupports *ctx, // main, etc.. //----------------------------------------------------------------------------- -nsresult NS_AutoregisterComponents() -{ - - nsresult rv = nsComponentManager::AutoRegister(nsIComponentManagerObsolete::NS_Startup, NULL /* default */); - return rv; -} - //---------getStrLine Helper function--------------- //Finds a newline in src starting at ind. Puts the //line in str (must be big enough). Returns the index @@ -361,14 +354,17 @@ int main(int argc, char **argv) return -1; } + nsCOMPtr servMan; + NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + registrar->AutoRegister(nsnull); + PRTime start, finish; rv = NS_NewISupportsArray(getter_AddRefs(uriList)); RETURN_IF_FAILED(rv, "NS_NewISupportsArray"); - rv = NS_AutoregisterComponents(); - RETURN_IF_FAILED(rv, "NS_AutoregisterComponents"); - // Create the Event Queue for this thread... nsCOMPtr eqs = do_GetService(kEventQueueServiceCID, &rv); diff --git a/mozilla/netwerk/test/TestPerf.cpp b/mozilla/netwerk/test/TestPerf.cpp index 784fd23a3a7..8a1e1e4f2e0 100644 --- a/mozilla/netwerk/test/TestPerf.cpp +++ b/mozilla/netwerk/test/TestPerf.cpp @@ -2,6 +2,7 @@ #include "nsNetUtil.h" #include "nsIEventQueueService.h" #include "nsIServiceManager.h" +#include "nsIComponentRegistrar.h" #include "nsISupportsArray.h" static nsIIOService *gIOService = nsnull; @@ -227,8 +228,11 @@ main(int argc, char **argv) return -1; } - rv = nsComponentManager::AutoRegister(nsIComponentManagerObsolete::NS_Startup, NULL); - if (NS_FAILED(rv)) return -1; + nsCOMPtr servMan; + NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + registrar->AutoRegister(nsnull); // cache the io service { diff --git a/mozilla/netwerk/test/TestRawCache.cpp b/mozilla/netwerk/test/TestRawCache.cpp index 35101ab6d87..09ba6411199 100644 --- a/mozilla/netwerk/test/TestRawCache.cpp +++ b/mozilla/netwerk/test/TestRawCache.cpp @@ -18,6 +18,7 @@ #include "nsIStreamListener.h" #include "nsIServiceManager.h" +#include "nsIComponentRegistrar.h" #include "nsIInputStream.h" #include "nsIOutputStream.h" #include "nsIEventQueue.h" @@ -683,13 +684,6 @@ FillCache(nsINetDataCache *cache) return NS_OK; } -nsresult NS_AutoregisterComponents() -{ - nsresult rv = nsComponentManager::AutoRegister(nsIComponentManagerObsolete::NS_Startup, - NULL /* default */); - return rv; -} - PRBool initPref () { nsresult rv; @@ -733,8 +727,12 @@ main(int argc, char* argv[]) nsCOMPtr cache; - rv = NS_AutoregisterComponents(); - NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't register XPCOM components"); + + nsCOMPtr servMan; + NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + registrar->AutoRegister(nsnull); if (PL_strcasecmp(argv[1], "-m") == 0) { rv = nsComponentManager::CreateInstance(kMemCacheCID, nsnull, diff --git a/mozilla/netwerk/test/TestRes.cpp b/mozilla/netwerk/test/TestRes.cpp index adb98e30fa5..cd187299ea6 100644 --- a/mozilla/netwerk/test/TestRes.cpp +++ b/mozilla/netwerk/test/TestRes.cpp @@ -40,6 +40,7 @@ #include "nsIIOService.h" #include "nsIInputStream.h" #include "nsIComponentManager.h" +#include "nsIComponentRegistrar.h" #include "nsIStreamListener.h" #include "nsIEventQueueService.h" #include "nsIURI.h" @@ -240,22 +241,17 @@ TestAsyncRead(const char* url) return rv; } -//////////////////////////////////////////////////////////////////////////////// - -nsresult -NS_AutoregisterComponents() -{ - nsresult rv = nsComponentManager::AutoRegister(nsIComponentManagerObsolete::NS_Startup, - NULL /* default */); - return rv; -} - int main(int argc, char* argv[]) { nsresult rv; - rv = NS_AutoregisterComponents(); + nsCOMPtr servMan; + NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + registrar->AutoRegister(nsnull); + NS_ASSERTION(NS_SUCCEEDED(rv), "AutoregisterComponents failed"); if (argc < 2) { diff --git a/mozilla/netwerk/test/TestSocketInput.cpp b/mozilla/netwerk/test/TestSocketInput.cpp index dc4c99ee0cc..35d122ff5dc 100644 --- a/mozilla/netwerk/test/TestSocketInput.cpp +++ b/mozilla/netwerk/test/TestSocketInput.cpp @@ -48,6 +48,7 @@ #include "nsISocketTransportService.h" #include "nsIEventQueueService.h" #include "nsIServiceManager.h" +#include "nsIComponentRegistrar.h" #include "nsITransport.h" #include "nsIRequest.h" #include "nsIStreamListener.h" @@ -134,12 +135,6 @@ InputTestConsumer::OnStopRequest(nsIRequest *request, nsISupports* context, } -nsresult NS_AutoregisterComponents() -{ - nsresult rv = nsComponentManager::AutoRegister(nsIComponentManagerObsolete::NS_Startup, NULL /* default */); - return rv; -} - int main(int argc, char* argv[]) { @@ -157,8 +152,11 @@ main(int argc, char* argv[]) //port = portString.ToInteger(&rv); port = 13; - rv = NS_AutoregisterComponents(); - if (NS_FAILED(rv)) return rv; + nsCOMPtr servMan; + NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + registrar->AutoRegister(nsnull); // Create the Event Queue for this thread... nsCOMPtr eventQService = diff --git a/mozilla/netwerk/test/TestSocketTransport.cpp b/mozilla/netwerk/test/TestSocketTransport.cpp index 261ac32245d..a9f22af2289 100644 --- a/mozilla/netwerk/test/TestSocketTransport.cpp +++ b/mozilla/netwerk/test/TestSocketTransport.cpp @@ -54,6 +54,7 @@ #include "nsISocketTransportService.h" #include "nsIEventQueueService.h" #include "nsIServiceManager.h" +#include "nsIComponentRegistrar.h" #include "nsIRequestObserver.h" #include "nsIStreamListener.h" #include "nsIPipe.h" @@ -579,13 +580,6 @@ void TimerCallback(nsITimer* aTimer, void* aClosure) #endif /* USE_TIMERS */ -nsresult NS_AutoregisterComponents(); -nsresult NS_AutoregisterComponents() -{ - nsresult rv = nsComponentManager::AutoRegister(nsIComponentManagerObsolete::NS_Startup, NULL /* default */); - return rv; -} - int main(int argc, char* argv[]) { @@ -636,8 +630,11 @@ main(int argc, char* argv[]) // // ----- - rv = NS_AutoregisterComponents(); - if (NS_FAILED(rv)) return rv; + nsCOMPtr servMan; + NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + registrar->AutoRegister(nsnull); // Create the Event Queue for this thread... nsCOMPtr eventQService = diff --git a/mozilla/netwerk/test/TestUpload.cpp b/mozilla/netwerk/test/TestUpload.cpp index c360be578c5..70dd1e1c084 100644 --- a/mozilla/netwerk/test/TestUpload.cpp +++ b/mozilla/netwerk/test/TestUpload.cpp @@ -39,6 +39,7 @@ #include #endif +#include "nsIComponentRegistrar.h" #include "nsIEventQueueService.h" #include "nsIIOService.h" #include "nsIServiceManager.h" @@ -53,12 +54,6 @@ static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); static int gKeepRunning = 1; static nsIEventQueue* gEventQ = nsnull; - -nsresult NS_AutoregisterComponents() -{ - nsresult rv = nsComponentManager::AutoRegister(nsIComponentManagerObsolete::NS_Startup, NULL /* default */); - return rv; -} //----------------------------------------------------------------------------- // InputTestConsumer //----------------------------------------------------------------------------- @@ -138,10 +133,12 @@ main(int argc, char* argv[]) char* uriSpec = argv[1]; char* fileName = argv[2]; - - rv = NS_AutoregisterComponents(); - if (NS_FAILED(rv)) return rv; + nsCOMPtr servMan; + NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + registrar->AutoRegister(nsnull); // Create the Event Queue for this thread... nsCOMPtr eventQService = diff --git a/mozilla/netwerk/test/TestWriteStream.cpp b/mozilla/netwerk/test/TestWriteStream.cpp index f329d24d98c..dc740cb40e9 100644 --- a/mozilla/netwerk/test/TestWriteStream.cpp +++ b/mozilla/netwerk/test/TestWriteStream.cpp @@ -49,7 +49,7 @@ #include "nsIEventQueue.h" #include "nsILocalFile.h" #include "plhash.h" - +#include "nsIComponentRegistrar.h" static NS_DEFINE_CID(kFileTransportServiceCID, NS_FILETRANSPORTSERVICE_CID); @@ -193,14 +193,6 @@ TestSyncWrites(char* filenamePrefix, PRUint32 startPosition, PRInt32 length) } //////////////////////////////////////////////////////////////////////////////// - -nsresult -NS_AutoregisterComponents() -{ - nsresult rv = nsComponentManager::AutoRegister(nsIComponentManagerObsolete::NS_Startup, NULL /* default */); - return rv; -} - int main(int argc, char* argv[]) { @@ -213,8 +205,11 @@ main(int argc, char* argv[]) char* fileName = argv[1]; int length = atoi(argv[2]); - rv = NS_AutoregisterComponents(); - if (NS_FAILED(rv)) return rv; + nsCOMPtr servMan; + NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + registrar->AutoRegister(nsnull); rv = TestSyncWrites(fileName, 0, length); NS_ASSERTION(NS_SUCCEEDED(rv), "TestAsyncRead failed"); diff --git a/mozilla/netwerk/test/urltest.cpp b/mozilla/netwerk/test/urltest.cpp index c4354560664..3d6f3d89015 100644 --- a/mozilla/netwerk/test/urltest.cpp +++ b/mozilla/netwerk/test/urltest.cpp @@ -55,6 +55,7 @@ #include "nsString.h" #include "nsReadableUtils.h" #include "nsNetCID.h" +#include "nsIComponentRegistrar.h" // Define CIDs... static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); @@ -393,12 +394,6 @@ int doMakeAbsTest(const char* i_URL = 0, const char* i_relativePortion=0) } } -nsresult NS_AutoregisterComponents() -{ - nsresult rv = nsComponentManager::AutoRegister(nsIComponentManagerObsolete::NS_Startup, NULL /* default */); - return rv; -} - void printusage(void) { cout << "urltest [-std] [-file ] " << @@ -422,8 +417,11 @@ int main(int argc, char **argv) return NS_OK; } - result = NS_AutoregisterComponents(); - if (NS_FAILED(result)) return result; + nsCOMPtr servMan; + NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + registrar->AutoRegister(nsnull); // end of all messages from register components... cout << "------------------" << endl << endl; diff --git a/mozilla/parser/htmlparser/tests/outsinks/Convert.cpp b/mozilla/parser/htmlparser/tests/outsinks/Convert.cpp index d4f18264664..bd9dd973d7b 100644 --- a/mozilla/parser/htmlparser/tests/outsinks/Convert.cpp +++ b/mozilla/parser/htmlparser/tests/outsinks/Convert.cpp @@ -30,6 +30,8 @@ #include "nsLayoutCID.h" #include "nsIHTMLToTextSink.h" #include "nsIComponentManager.h" +#include "nsIServiceManager.h" +#include "nsIComponentRegistrar.h" #include "nsReadableUtils.h" static NS_DEFINE_IID(kIParserIID, NS_IPARSER_IID); @@ -288,8 +290,12 @@ Usage: %s [-i intype] [-o outtype] [-f flags] [-w wrapcol] [-c comparison_file] } else file = stdin; - NS_InitXPCOM2(nsnull, nsnull, nsnull); - nsComponentManager::AutoRegister(nsIComponentManagerObsolete::NS_Startup, 0); + + nsCOMPtr servMan; + NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + registrar->AutoRegister(nsnull); // Read in the string: very inefficient, but who cares? nsString inString; diff --git a/mozilla/webshell/tests/viewer/nsViewerApp.cpp b/mozilla/webshell/tests/viewer/nsViewerApp.cpp index 44c5ba37fc8..8b6a478b1f0 100644 --- a/mozilla/webshell/tests/viewer/nsViewerApp.cpp +++ b/mozilla/webshell/tests/viewer/nsViewerApp.cpp @@ -56,6 +56,7 @@ #include "nsIComponentManager.h" +#include "nsIComponentRegistrar.h" #include "nsIServiceManager.h" #include "nsIEventQueueService.h" #include "nsIInterfaceRequestor.h" @@ -255,13 +256,17 @@ nsresult nsViewerApp::SetupRegistry() { nsresult rv; - nsComponentManager::AutoRegister(nsIComponentManagerObsolete::NS_Startup, - NULL /* default */); + + nsCOMPtr servManager; + NS_GetServiceManager(getter_AddRefs(servManager)); + nsCOMPtr registrar = do_QueryInterface(servManager); + NS_ASSERTION(registrar, "No nsIComponentRegistrar from get service. see dougt"); + rv = registrar->AutoRegister(nsnull); // Register our browser window factory nsIFactory* bwf; NS_NewXPBaseWindowFactory(&bwf); - nsComponentManager::RegisterFactory(kXPBaseWindowCID, 0, 0, bwf, PR_FALSE); + registrar->RegisterFactory(kXPBaseWindowCID, 0, 0, bwf); NS_RELEASE(bwf); // register the cookie manager diff --git a/mozilla/xpcom/build/nsXPCOM.h b/mozilla/xpcom/build/nsXPCOM.h index e311e583aba..72027624110 100644 --- a/mozilla/xpcom/build/nsXPCOM.h +++ b/mozilla/xpcom/build/nsXPCOM.h @@ -41,6 +41,7 @@ #include "nscore.h" class nsIComponentManager; +class nsIComponentRegistrar; class nsIServiceManager; class nsIFile; class nsIDirectoryServiceProvider; @@ -124,6 +125,19 @@ NS_GetServiceManager(nsIServiceManager* *result); extern "C" NS_COM nsresult NS_GetComponentManager(nsIComponentManager* *result); +/** + * Public Method to access to the component registration manager. + * + * @status FROZEN + * @param result Interface pointer to the service + * + * @return NS_OK for success; + * other error codes indicate a failure during initialisation. + * + */ +extern "C" NS_COM nsresult +NS_GetComponentRegistrar(nsIComponentRegistrar* *result); + /** * Public Method to access to the memory manager. See nsIMemory * diff --git a/mozilla/xpcom/build/nsXPComInit.cpp b/mozilla/xpcom/build/nsXPComInit.cpp index fa2a1090db3..e0f0a609381 100644 --- a/mozilla/xpcom/build/nsXPComInit.cpp +++ b/mozilla/xpcom/build/nsXPComInit.cpp @@ -185,10 +185,12 @@ RegisterGenericFactory(nsIComponentManager* compMgr, // what I want to do here is QI for a Component Registration Manager. Since this // has not been invented yet, QI to the obsolete manager. Kids, don't do this at home. - nsCOMPtr obsoleteManager = do_QueryInterface(compMgr, &rv); - if (obsoleteManager) - rv = obsoleteManager->RegisterFactory(info->mCID, info->mDescription, - info->mContractID, fact, PR_TRUE); + nsCOMPtr registrar = do_QueryInterface(compMgr, &rv); + if (registrar) + rv = registrar->RegisterFactory(info->mCID, + info->mDescription, + info->mContractID, + fact); NS_RELEASE(fact); return rv; } diff --git a/mozilla/xpcom/components/nsComponentManager.cpp b/mozilla/xpcom/components/nsComponentManager.cpp index 7f78f442939..e1ae6887d00 100644 --- a/mozilla/xpcom/components/nsComponentManager.cpp +++ b/mozilla/xpcom/components/nsComponentManager.cpp @@ -34,57 +34,46 @@ #include "nsCRT.h" #include "nspr.h" -// this after nsISupports, to pick up IID -// so that xpt stuff doesn't try to define it itself... -#include "xptinfo.h" -#include "nsIInterfaceInfoManager.h" - +#include "NSReg.h" +#include "nsAutoLock.h" #include "nsCOMPtr.h" #include "nsComponentManager.h" #include "nsComponentManagerObsolete.h" -#include "nsICategoryManager.h" - -#include "nsIEnumerator.h" -#include "nsIModule.h" -#include "nsISupportsPrimitives.h" -#include "nsIComponentLoader.h" -#include "nsNativeComponentLoader.h" -#include "nsXPIDLString.h" - -#include "nsIObserverService.h" - -#include "nsLocalFile.h" #include "nsDirectoryService.h" #include "nsDirectoryServiceDefs.h" - -#include "NSReg.h" - +#include "nsICategoryManager.h" +#include "nsIComponentLoader.h" +#include "nsIEnumerator.h" +#include "nsIInterfaceInfoManager.h" +#include "nsIModule.h" +#include "nsIObserverService.h" +#include "nsISimpleEnumerator.h" +#include "nsISupportsPrimitives.h" +#include "nsLocalFile.h" +#include "nsNativeComponentLoader.h" +#include "nsRegistry.h" +#include "nsXPIDLString.h" #include "prcmon.h" #include "prthread.h" /* XXX: only used for the NSPR initialization hack (rick) */ +#include "xptinfo.h" // this after nsISupports, to pick up IID so that xpt stuff doesn't try to define it itself... #ifdef XP_BEOS #include #include #endif -#include "nsRegistry.h" - // Logging of debug output #ifdef MOZ_LOGGING #define FORCE_PR_LOG /* Allow logging in the release build */ #endif #include "prlog.h" + PRLogModuleInfo* nsComponentManagerLog = NULL; #if defined(DEBUG) #define SHOW_DENIED_ON_SHUTDOWN #endif -#include "nsAutoLock.h" - -// Enable printing of critical errors on screen even for release builds -#define PRINT_CRITICAL_ERROR_TO_SCREEN - // Loader Types #define NS_LOADER_DATA_ALLOC_STEP 6 @@ -94,25 +83,25 @@ PRLogModuleInfo* nsComponentManagerLog = NULL; #define BIG_REGISTRY_BUFLEN (512*1024) // Common Key Names -const char xpcomKeyName[]="software/mozilla/XPCOM"; -const char classesKeyName[]="contractID"; const char classIDKeyName[]="classID"; -const char componentsKeyName[]="components"; +const char classesKeyName[]="contractID"; const char componentLoadersKeyName[]="componentLoaders"; +const char componentsKeyName[]="components"; const char xpcomComponentsKeyName[]="software/mozilla/XPCOM/components"; +const char xpcomKeyName[]="software/mozilla/XPCOM"; // Common Value Names const char classIDValueName[]="ClassID"; -const char versionValueName[]="VersionString"; -const char lastModValueName[]="LastModTimeStamp"; -const char fileSizeValueName[]="FileSize"; -const char componentCountValueName[]="ComponentsCount"; -const char contractIDValueName[]="ContractID"; const char classNameValueName[]="ClassName"; -const char inprocServerValueName[]="InprocServer"; +const char componentCountValueName[]="ComponentsCount"; const char componentTypeValueName[]="ComponentType"; +const char contractIDValueName[]="ContractID"; +const char fileSizeValueName[]="FileSize"; +const char inprocServerValueName[]="InprocServer"; +const char lastModValueName[]="LastModTimeStamp"; const char nativeComponentType[]="application/x-mozilla-native"; const char staticComponentType[]="application/x-mozilla-static"; +const char versionValueName[]="VersionString"; const static char XPCOM_ABSCOMPONENT_PREFIX[] = "abs:"; const static char XPCOM_RELCOMPONENT_PREFIX[] = "rel:"; @@ -123,7 +112,6 @@ const char XPCOM_LIB_PREFIX[] = "lib:"; static nsFactoryEntry * kNonExistentContractID = (nsFactoryEntry*) 1; - #define NS_EMPTY_IID \ { \ 0x00000000, \ @@ -298,7 +286,10 @@ nsGetServiceFromCategory::operator()( const nsIID& aIID, void** aInstancePtr) return status; } -/* prototypes for the Mac */ +//////////////////////////////////////////////////////////////////////////////// +// Hashtable Callbacks +//////////////////////////////////////////////////////////////////////////////// + PRBool PR_CALLBACK nsFactoryEntry_Destroy(nsHashKey *aKey, void *aData, void* closure); @@ -382,7 +373,7 @@ contractID_ClearEntry(PLDHashTable *aTable, PLDHashEntryHdr *aHdr) } nsCRT::free(entry->mContractID); - + PL_DHashClearEntryStub(aTable, aHdr); } @@ -402,7 +393,6 @@ static PLDHashTableOps contractID_DHashTableOps = { //////////////////////////////////////////////////////////////////////////////// MOZ_DECL_CTOR_COUNTER(nsFactoryEntry) - nsFactoryEntry::nsFactoryEntry(const nsCID &aClass, const char *aLocation, int aType) @@ -454,6 +444,272 @@ nsFactoryEntry::ReInit(const nsCID &aClass, nsIFactory *aFactory) typeIndex = NS_COMPONENT_TYPE_FACTORY_ONLY; return NS_OK; } + + +//////////////////////////////////////////////////////////////////////////////// +// Hashtable Enumeration +//////////////////////////////////////////////////////////////////////////////// +typedef NS_CALLBACK(EnumeratorConverter)(PLDHashTable *table, + const PLDHashEntryHdr *hdr, + void *data, + nsISupports **retval); + +class PLDHashTableEnumeratorImpl : public nsIBidirectionalEnumerator, + public nsISimpleEnumerator +{ +public: + NS_DECL_ISUPPORTS + NS_DECL_NSIENUMERATOR + NS_DECL_NSIBIDIRECTIONALENUMERATOR + NS_DECL_NSISIMPLEENUMERATOR + + virtual ~PLDHashTableEnumeratorImpl(); + PLDHashTableEnumeratorImpl(PLDHashTable *table, + EnumeratorConverter converter, + void *converterData); + PRInt32 Count() { return mCount; } +private: + PLDHashTableEnumeratorImpl(); /* no implementation */ + NS_IMETHODIMP ReleaseElements(); + + nsVoidArray mElements; + PRInt32 mCount, mCurrent; + PRMonitor* mMonitor; + + struct Closure { + PRBool succeeded; + EnumeratorConverter converter; + void *data; + PLDHashTableEnumeratorImpl *impl; + }; + + static PLDHashOperator PR_CALLBACK Enumerator(PLDHashTable *table, + PLDHashEntryHdr *hdr, + PRUint32 number, + void *data); +}; + +// static +PLDHashOperator PR_CALLBACK +PLDHashTableEnumeratorImpl::Enumerator(PLDHashTable *table, + PLDHashEntryHdr *hdr, + PRUint32 number, + void *data) +{ + Closure *c = NS_REINTERPRET_CAST(Closure *, data); + nsISupports *converted; + if (NS_FAILED(c->converter(table, hdr, c->data, &converted)) || + !c->impl->mElements.AppendElement(converted)) { + c->succeeded = PR_FALSE; + return PL_DHASH_STOP; + } + + c->succeeded = PR_TRUE; + return PL_DHASH_NEXT; +} + +PLDHashTableEnumeratorImpl::PLDHashTableEnumeratorImpl(PLDHashTable *table, + EnumeratorConverter converter, + void *converterData) +: mCurrent(0) +{ + mMonitor = nsAutoMonitor::NewMonitor("PLDHashTableEnumeratorImpl"); + NS_ASSERTION(mMonitor, "NULL Monitor"); + + nsAutoMonitor mon(mMonitor); + + NS_INIT_REFCNT(); + Closure c = { PR_FALSE, converter, converterData, this }; + mCount = PL_DHashTableEnumerate(table, Enumerator, &c); + if (!c.succeeded) { + ReleaseElements(); + mCount = 0; + } +} + +NS_IMPL_ISUPPORTS3(PLDHashTableEnumeratorImpl, + nsIBidirectionalEnumerator, + nsIEnumerator, + nsISimpleEnumerator); + +PLDHashTableEnumeratorImpl::~PLDHashTableEnumeratorImpl() +{ + (void) ReleaseElements(); + + // Destroy the Lock + if (mMonitor) + PR_DestroyMonitor(mMonitor); +} + +NS_IMETHODIMP +PLDHashTableEnumeratorImpl::ReleaseElements() +{ + for (PRInt32 i = 0; i < mCount; i++) { + nsISupports *supports = NS_REINTERPRET_CAST(nsISupports *, + mElements[i]); + NS_IF_RELEASE(supports); + } + return NS_OK; +} + +NS_IMETHODIMP +PL_NewDHashTableEnumerator(PLDHashTable *table, + EnumeratorConverter converter, + void *converterData, + PLDHashTableEnumeratorImpl **retval) +{ + PLDHashTableEnumeratorImpl *impl = + new PLDHashTableEnumeratorImpl(table, converter, converterData); + + if (!impl) + return NS_ERROR_OUT_OF_MEMORY; + + if (impl->Count() == -1) { + // conversion failed + delete impl; + return NS_ERROR_FAILURE; + } + + NS_ADDREF(*retval = impl); + return NS_OK; +} + +NS_IMETHODIMP +PLDHashTableEnumeratorImpl::First() +{ + if (!mCount) + return NS_ERROR_FAILURE; + + mCurrent = 0; + return NS_OK; +} + +NS_IMETHODIMP +PLDHashTableEnumeratorImpl::Last() +{ + if (!mCount) + return NS_ERROR_FAILURE; + mCurrent = mCount - 1; + return NS_OK; +} + +NS_IMETHODIMP +PLDHashTableEnumeratorImpl::Prev() +{ + if (!mCurrent) + return NS_ERROR_FAILURE; + + mCurrent--; + return NS_OK; +} + +NS_IMETHODIMP +PLDHashTableEnumeratorImpl::Next() +{ + // If empty or we're past the end, or we are at the end return error + if (!mCount || (mCurrent == mCount) || (++mCurrent == mCount)) + return NS_ERROR_FAILURE; + + return NS_OK; +} + +NS_IMETHODIMP +PLDHashTableEnumeratorImpl::CurrentItem(nsISupports **retval) +{ + if (!mCount || mCurrent == mCount) + return NS_ERROR_FAILURE; + + *retval = NS_REINTERPRET_CAST(nsISupports *, mElements[mCurrent]); + if (*retval) + NS_ADDREF(*retval); + + return NS_OK; +} + +NS_IMETHODIMP +PLDHashTableEnumeratorImpl::IsDone() +{ + if (!mCount || (mCurrent == mCount)) + return NS_OK; + + return NS_COMFALSE; +} + +NS_IMETHODIMP +PLDHashTableEnumeratorImpl::HasMoreElements(PRBool *_retval) +{ + if (!mCount || (mCurrent == mCount)) + *_retval = PR_FALSE; + else + *_retval = PR_TRUE; + + return NS_OK; +} + +NS_IMETHODIMP +PLDHashTableEnumeratorImpl::GetNext(nsISupports **_retval) +{ + nsresult rv = Next(); + if (NS_FAILED(rv)) return rv; + + return CurrentItem(_retval); +} + +static NS_IMETHODIMP +ConvertFactoryEntryToCID(PLDHashTable *table, + const PLDHashEntryHdr *hdr, + void *data, nsISupports **retval) +{ + nsresult rv; + + nsCOMPtr wrapper = + do_CreateInstance(NS_SUPPORTS_ID_CONTRACTID, &rv); + NS_ENSURE_SUCCESS(rv, rv); + + const nsFactoryTableEntry *entry = + NS_REINTERPRET_CAST(const nsFactoryTableEntry *, hdr); + if(entry) { + nsFactoryEntry *fe = entry->mFactoryEntry; + + wrapper->SetData(&fe->cid); + *retval = wrapper; + NS_ADDREF(*retval); + return NS_OK; + } + else + *retval = nsnull; + + return rv; + +} + +static NS_IMETHODIMP +ConvertContractIDKeyToString(PLDHashTable *table, + const PLDHashEntryHdr *hdr, + void *data, nsISupports **retval) +{ + nsresult rv; + + nsCOMPtr wrapper = + do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID, &rv); + NS_ENSURE_SUCCESS(rv, rv); + + const nsContractIDTableEntry *entry = + NS_REINTERPRET_CAST(const nsContractIDTableEntry *, hdr); + const char *contractID = entry->mContractID; + nsCAutoString converted; + + converted.Append(contractID); + + wrapper->SetData(converted.get()); + *retval = wrapper; + NS_ADDREF(*retval); + return NS_OK; + +} + + + //////////////////////////////////////////////////////////////////////////////// // nsComponentManagerImpl //////////////////////////////////////////////////////////////////////////////// @@ -645,14 +901,31 @@ nsComponentManagerImpl::~nsComponentManagerImpl() PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS, ("nsComponentManager: Destroyed.")); } -NS_IMPL_THREADSAFE_ISUPPORTS6(nsComponentManagerImpl, +NS_IMPL_THREADSAFE_ISUPPORTS7(nsComponentManagerImpl, nsIComponentManager, nsIServiceManager, nsISupportsWeakReference, nsIInterfaceRequestor, + nsIComponentRegistrar, nsIServiceManagerObsolete, nsIComponentManagerObsolete) + +nsresult +nsComponentManagerImpl::GetInterface(const nsIID & uuid, void **result) +{ + if (uuid.Equals(NS_GET_IID(nsIServiceManager))) + { + *result = NS_STATIC_CAST(nsIServiceManager*, this); + NS_ADDREF_THIS(); + return NS_OK; + } + + // fall through to QI as anything QIable is a superset of what canbe + // got via the GetInterface() + return QueryInterface(uuid, result); +} + //////////////////////////////////////////////////////////////////////////////// // nsComponentManagerImpl: Platform methods //////////////////////////////////////////////////////////////////////////////// @@ -719,10 +992,7 @@ nsComponentManagerImpl::PlatformInit(void) mComponentsOffset = strlen(componentDescriptor); - if (componentDescriptor) - nsMemory::Free(componentDescriptor); - - + nsMemory::Free(componentDescriptor); if (mNativeComponentLoader) { /* now that we have the registry, Init the native loader */ @@ -816,89 +1086,6 @@ nsComponentManagerImpl::PlatformVersionCheck(nsRegistryKey *aXPCOMRootKey) return NS_OK; } -#if 0 -// If ever revived, this code is not fully updated to escape the dll location -void -nsComponentManagerImpl::PlatformSetFileInfo(nsRegistryKey key, PRUint32 lastModifiedTime, PRUint32 fileSize) -{ - mRegistry->SetInt(key, lastModValueName, lastModifiedTime); - mRegistry->SetInt(key, fileSizeValueName, fileSize); -} - -/** - * PlatformMarkNoComponents(nsDll *dll) - * - * Stores the dll name, last modified time, size and 0 for number of - * components in dll in the registry at location - * ROOTKEY_COMMON/Software/Mozilla/XPCOM/Components/dllname - */ -nsresult -nsComponentManagerImpl::PlatformMarkNoComponents(nsDll *dll) -{ - PR_ASSERT(mRegistry!=NULL); - - nsresult rv; - - nsRegistryKey dllPathKey; - rv = mRegistry->AddSubtreeRaw(mXPCOMKey, dll->GetPersistentDescriptorString(), &dllPathKey); - if(NS_FAILED(rv)) - { - return rv; - } - - PlatformSetFileInfo(dllPathKey, dll->GetLastModifiedTime(), dll->GetSize()); - rv = mRegistry->SetInt(dllPathKey, componentCountValueName, 0); - - return rv; -} - -nsresult -nsComponentManagerImpl::PlatformRegister(const char *cidString, - const char *className, - const char * contractID, nsDll *dll) -{ - // Preconditions - PR_ASSERT(cidString != NULL); - PR_ASSERT(dll != NULL); - PR_ASSERT(mRegistry !=NULL); - - nsresult rv; - - nsRegistryKey IDkey; - rv = mRegistry->AddSubtreeRaw(mCLSIDKey, cidString, &IDkey); - if (NS_FAILED(rv)) return (rv); - - - rv = mRegistry->SetStringUTF8(IDkey,classNameValueName, className); - if (contractID) - { - rv = mRegistry->SetStringUTF8(IDkey,contractIDValueName, contractID); - } - rv = mRegistry->SetBytesUTF8(IDkey, inprocServerValueName, - strlen(dll->GetPersistentDescriptorString()) + 1, - NS_REINTERPRET_CAST(char*, dll->GetPersistentDescriptorString())); - - if (contractID) - { - nsRegistryKey contractIDKey; - rv = mRegistry->AddSubtreeRaw(mClassesKey, contractID, &contractIDKey); - rv = mRegistry->SetStringUTF8(contractIDKey, classIDValueName, cidString); - } - - nsRegistryKey dllPathKey; - rv = mRegistry->AddSubtreeRaw(mXPCOMKey,dll->GetPersistentDescriptorString(), &dllPathKey); - - PlatformSetFileInfo(dllPathKey, dll->GetLastModifiedTime(), dll->GetSize()); - - PRInt32 nComponents = 0; - rv = mRegistry->GetInt(dllPathKey, componentCountValueName, &nComponents); - nComponents++; - rv = mRegistry->SetInt(dllPathKey,componentCountValueName, nComponents); - - return rv; -} -#endif - nsresult nsComponentManagerImpl::PlatformUnregister(const char *cidString, const char *aLibrary) @@ -1035,7 +1222,8 @@ nsComponentManagerImpl::PlatformContractIDToCLSID(const char *aContractID, nsCID nsresult nsComponentManagerImpl::PlatformCLSIDToContractID(const nsCID *aClass, - char* *aClassName, char* *aContractID) + char* *aClassName, + char* *aContractID) { PR_ASSERT(aClass); @@ -1049,16 +1237,19 @@ nsComponentManagerImpl::PlatformCLSIDToContractID(const nsCID *aClass, if(NS_FAILED(rv)) return rv; PR_FREEIF(cidStr); - char* classnameString; - rv = mRegistry->GetStringUTF8(cidKey, classNameValueName, &classnameString); - if(NS_FAILED(rv)) return rv; - *aClassName = classnameString; - - char* contractidString; - rv = mRegistry->GetStringUTF8(cidKey,contractIDValueName,&contractidString); - if (NS_FAILED(rv)) return rv; - *aContractID = contractidString; + if (aClassName) { + char* classnameString; + rv = mRegistry->GetStringUTF8(cidKey, classNameValueName, &classnameString); + if(NS_FAILED(rv)) return rv; + *aClassName = classnameString; + } + if (aContractID) { + char* contractidString; + rv = mRegistry->GetStringUTF8(cidKey,contractIDValueName,&contractidString); + if (NS_FAILED(rv)) return rv; + *aContractID = contractidString; + } return NS_OK; } @@ -1193,9 +1384,9 @@ nsresult nsComponentManagerImpl::PlatformPrePopulateRegistry() #endif /* USE_REGISTRY */ -// -// HashContractID -// +//////////////////////////////////////////////////////////////////////////////// +// Hash Functions +//////////////////////////////////////////////////////////////////////////////// nsresult nsComponentManagerImpl::HashContractID(const char *aContractID, const nsCID &aClass, nsFactoryEntry **pfe) { @@ -1252,10 +1443,6 @@ nsComponentManagerImpl::HashContractID(const char *aContractID, nsFactoryEntry * return NS_OK; } -//////////////////////////////////////////////////////////////////////////////// -// nsComponentManagerImpl: Public methods -//////////////////////////////////////////////////////////////////////////////// - /** * LoadFactory() * @@ -1505,7 +1692,7 @@ nsComponentManagerImpl::GetClassObjectByContractID(const char *contractID, * */ nsresult -nsComponentManagerImpl::ContractIDToClassID(const char *aContractID, nsCID *aClass) +nsComponentManagerImpl::ContractIDToClassID(const char *aContractID, nsCID *aClass) { NS_PRECONDITION(aContractID != NULL, "null ptr"); if (! aContractID) @@ -1547,8 +1734,8 @@ nsComponentManagerImpl::ContractIDToClassID(const char *aContractID, nsCID *aCla */ nsresult nsComponentManagerImpl::CLSIDToContractID(const nsCID &aClass, - char* *aClassName, - char* *aContractID) + char* *aClassName, + char* *aContractID) { nsresult res = NS_ERROR_FACTORY_NOT_REGISTERED; @@ -1683,7 +1870,7 @@ nsComponentManagerImpl::CreateInstanceByContractID(const char *aContractID, } // Service Manager Impl - +static PLDHashOperator PR_CALLBACK FreeServiceFactoryEntryEnumerate(PLDHashTable *aTable, PLDHashEntryHdr *aHdr, @@ -1699,7 +1886,7 @@ FreeServiceFactoryEntryEnumerate(PLDHashTable *aTable, factoryEntry->mServiceObject = nsnull; return PL_DHASH_NEXT; } - +static PLDHashOperator PR_CALLBACK FreeServiceContractIDEntryEnumerate(PLDHashTable *aTable, PLDHashEntryHdr *aHdr, @@ -1724,14 +1911,15 @@ nsComponentManagerImpl::FreeServices() if (!gXPCOMShuttingDown) return NS_ERROR_FAILURE; - if (mFactories.ops) { - PL_DHashTableEnumerate(&mFactories, FreeServiceFactoryEntryEnumerate, nsnull); - } - if (mContractIDs.ops) { PL_DHashTableEnumerate(&mContractIDs, FreeServiceContractIDEntryEnumerate, nsnull); } + + if (mFactories.ops) { + PL_DHashTableEnumerate(&mFactories, FreeServiceFactoryEntryEnumerate, nsnull); + } + return NS_OK; } NS_IMETHODIMP @@ -2552,6 +2740,60 @@ nsComponentManagerImpl::GetLoaderForType(int aType, return rv; } + +// Convert a loader type string into an index into the component data +// array. Empty loader types are converted to NATIVE. Returns -1 if +// loader type cannot be determined. +int +nsComponentManagerImpl::GetLoaderType(const char *typeStr) +{ + if (!typeStr || !*typeStr) { + // Empty type strings are NATIVE + return NS_COMPONENT_TYPE_NATIVE; + } + + for (int i=NS_COMPONENT_TYPE_NATIVE; i= 0) { + return typeIndex; + } + + // Add the loader type + if (mNLoaderData >= mMaxNLoaderData) { + NS_ASSERTION(mNLoaderData == mMaxNLoaderData, + "Memory corruption. nsComponentManagerImpl::mLoaderData array overrun."); + // Need to increase our loader array + nsLoaderdata *new_mLoaderData = (nsLoaderdata *) PR_Realloc(mLoaderData, (mMaxNLoaderData + NS_LOADER_DATA_ALLOC_STEP) * sizeof(nsLoaderdata)); + if (!new_mLoaderData) + return NS_ERROR_OUT_OF_MEMORY; + mLoaderData = new_mLoaderData; + mMaxNLoaderData += NS_LOADER_DATA_ALLOC_STEP; + } + + typeIndex = mNLoaderData; + mLoaderData[typeIndex].type = PL_strdup(typeStr); + if (!mLoaderData[typeIndex].type) { + // mmh! no memory. return failure. + return NS_ERROR_OUT_OF_MEMORY; + } + mLoaderData[typeIndex].loader = nsnull; + mNLoaderData++; + + return typeIndex; +} + nsresult nsComponentManagerImpl::AddComponentToRegistry(const nsCID &aClass, const char *aClassName, @@ -2629,6 +2871,56 @@ nsComponentManagerImpl::AddComponentToRegistry(const nsCID &aClass, return rv; } +typedef struct +{ + const nsCID* cid; + const char* regName; + nsIFactory* factory; +} UnregisterConditions; + +static PLDHashOperator PR_CALLBACK +DeleteFoundCIDs(PLDHashTable *aTable, + PLDHashEntryHdr *aHdr, + PRUint32 aNumber, + void *aData) +{ + nsContractIDTableEntry* entry = NS_STATIC_CAST(nsContractIDTableEntry*, aHdr); + + if (!entry->mFactoryEntry || entry->mFactoryEntry == kNonExistentContractID) + return PL_DHASH_NEXT; + + UnregisterConditions* data = (UnregisterConditions*)aData; + + nsFactoryEntry* factoryEntry = entry->mFactoryEntry; + if (data->cid->Equals(factoryEntry->cid) && + ((data->regName && !PL_strcasecmp(factoryEntry->location, data->regName)) || + (data->factory && data->factory == factoryEntry->factory.get()))) + return PL_DHASH_REMOVE; + + return PL_DHASH_NEXT; +} + +void +nsComponentManagerImpl::DeleteContractIDEntriesByCID(const nsCID* aClass, const char*registryName) +{ + UnregisterConditions aData; + aData.cid = aClass; + aData.regName = registryName; + aData.factory = nsnull; + PL_DHashTableEnumerate(&mContractIDs, DeleteFoundCIDs, (void*)&aData); + +} + +void +nsComponentManagerImpl::DeleteContractIDEntriesByCID(const nsCID* aClass, nsIFactory* factory) +{ + UnregisterConditions aData; + aData.cid = aClass; + aData.regName = nsnull; + aData.factory = factory; + PL_DHashTableEnumerate(&mContractIDs, DeleteFoundCIDs, (void*)&aData); +} + nsresult nsComponentManagerImpl::UnregisterFactory(const nsCID &aClass, nsIFactory *aFactory) @@ -2641,21 +2933,21 @@ nsComponentManagerImpl::UnregisterFactory(const nsCID &aClass, delete [] buf; } + nsFactoryEntry *old; + + // first delete all contract id entries that are registered with this cid. + DeleteContractIDEntriesByCID(&aClass, aFactory); + + // next check to see if there is a CID registered nsIDKey key(aClass); nsresult res = NS_ERROR_FACTORY_NOT_REGISTERED; - nsFactoryEntry *old = GetFactoryEntry(aClass, key, - 0 /* dont check registry */); - if (old != NULL) - { - if (old->factory.get() == aFactory) - { - nsAutoMonitor mon(mMon); - - PL_DHashTableOperate(&mFactories, &aClass, PL_DHASH_REMOVE); - old = NULL; - res = NS_OK; - } - + old = GetFactoryEntry(aClass, key, 0 /* dont check registry */); + + if (old && (old->factory.get() == aFactory)) + { + nsAutoMonitor mon(mMon); + PL_DHashTableOperate(&mFactories, &aClass, PL_DHASH_REMOVE); + res = NS_OK; } PR_LOG(nsComponentManagerLog, PR_LOG_WARNING, @@ -2668,20 +2960,28 @@ nsresult nsComponentManagerImpl::UnregisterComponent(const nsCID &aClass, const char *registryName) { - nsresult rv = NS_OK; + if (PR_LOG_TEST(nsComponentManagerLog, PR_LOG_ALWAYS)) + { + char *buf = aClass.ToString(); + PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG, + ("nsComponentManager: UnregisterComponent(%s)", buf)); + delete [] buf; + } NS_ENSURE_ARG_POINTER(registryName); + nsresult rv; + nsFactoryEntry *old; + + // first delete all contract id entries that are registered with this cid. + DeleteContractIDEntriesByCID(&aClass, registryName); - nsAutoMonitor mon(mMon); - - // Remove any stored factory entries + // next check to see if there is a CID registered nsIDKey key(aClass); - nsFactoryEntry *entry = GetFactoryEntry(aClass, key, - 0 /* dont check registry */); - if (entry && entry->location && !PL_strcasecmp(entry->location, registryName)) - { + old = GetFactoryEntry(aClass, key, 0 /* dont check registry */); + if (old && old->location && !PL_strcasecmp(old->location, registryName)) + { + nsAutoMonitor mon(mMon); PL_DHashTableOperate(&mFactories, &aClass, PL_DHASH_REMOVE); - entry = nsnull; } #ifdef USE_REGISTRY @@ -2748,11 +3048,11 @@ nsComponentManagerImpl::UnloadLibraries(nsIServiceManager *serviceMgr, PRInt32 a * AutoRegister(RegistrationInstant, const char *directory) * * Given a directory in the following format, this will ensure proper registration - * of all components. No default director is looked at. + * of all components. No default directory is looked at. * * Directory and fullname are what NSPR will accept. For eg. - * WIN y:/home/dp/mozilla/dist/bin - * UNIX /home/dp/mozilla/dist/bin + * WIN y:/home/dp/mozilla/dist/bin + * UNIX /home/dp/mozilla/dist/bin * MAC /Hard drive/mozilla/dist/apprunner * * This will take care not loading already registered dlls, finding and @@ -2772,7 +3072,9 @@ nsComponentManagerImpl::AutoRegister(PRInt32 when, nsIFile *inDirSpec) } nsresult -nsComponentManagerImpl::AutoRegisterImpl(PRInt32 when, nsIFile *inDirSpec) +nsComponentManagerImpl::AutoRegisterImpl(PRInt32 when, + nsIFile *inDirSpec, + PRBool fileIsCompDir) { nsCOMPtr dir; nsresult rv; @@ -2786,26 +3088,32 @@ nsComponentManagerImpl::AutoRegisterImpl(PRInt32 when, nsIFile *inDirSpec) { // Use supplied components' directory dir = inDirSpec; - - // Set components' directory for AutoRegisterInterfces to query - nsCOMPtr directoryService = - do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv); - if (NS_FAILED(rv)) return rv; - - // Don't care if undefining fails - directoryService->Undefine(NS_XPCOM_COMPONENT_DIR); - rv = directoryService->Define(NS_XPCOM_COMPONENT_DIR, dir); - if (NS_FAILED(rv)) return rv; + + if (fileIsCompDir) { + // Set components' directory for AutoRegisterInterfces to query + nsCOMPtr directoryService = + do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv); + if (NS_FAILED(rv)) return rv; + + // Don't care if undefining fails + directoryService->Undefine(NS_XPCOM_COMPONENT_DIR); + rv = directoryService->Define(NS_XPCOM_COMPONENT_DIR, dir); + if (NS_FAILED(rv)) return rv; + } } else { // Do default components directory nsCOMPtr directoryService = - do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv); - if (NS_FAILED(rv)) return rv; + do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv); + if (NS_FAILED(rv)) + return rv; - rv = directoryService->Get(NS_XPCOM_COMPONENT_DIR, NS_GET_IID(nsIFile), getter_AddRefs(dir)); - if (NS_FAILED(rv)) return rv; // XXX translate error code? + rv = directoryService->Get(NS_XPCOM_COMPONENT_DIR, + NS_GET_IID(nsIFile), + getter_AddRefs(dir)); + if (NS_FAILED(rv)) + return rv; // XXX translate error code? } nsCOMPtr iim = @@ -2815,7 +3123,8 @@ nsComponentManagerImpl::AutoRegisterImpl(PRInt32 when, nsIFile *inDirSpec) return NS_ERROR_UNEXPECTED; // Notify observers of xpcom autoregistration start - NS_CreateServicesFromCategory(NS_XPCOM_AUTOREGISTRATION_OBSERVER_ID, nsnull, + NS_CreateServicesFromCategory(NS_XPCOM_AUTOREGISTRATION_OBSERVER_ID, + nsnull, "start"); /* do the native loader first, so we can find other loaders */ @@ -2892,9 +3201,9 @@ nsComponentManagerImpl::AutoRegisterImpl(PRInt32 when, nsIFile *inDirSpec) } // Notify observers of xpcom autoregistration completion - NS_CreateServicesFromCategory(NS_XPCOM_AUTOREGISTRATION_OBSERVER_ID, nsnull, - "end"); - + NS_CreateServicesFromCategory(NS_XPCOM_AUTOREGISTRATION_OBSERVER_ID, + nsnull, + "end"); return rv; } @@ -2954,240 +3263,6 @@ nsComponentManagerImpl::IsRegistered(const nsCID &aClass, return NS_OK; } - -typedef NS_CALLBACK(EnumeratorConverter)(PLDHashTable *table, - const PLDHashEntryHdr *hdr, - void *data, - nsISupports **retval); - -class PLDHashTableEnumeratorImpl : public nsIBidirectionalEnumerator -{ -public: - NS_DECL_ISUPPORTS - NS_DECL_NSIENUMERATOR - NS_DECL_NSIBIDIRECTIONALENUMERATOR - - virtual ~PLDHashTableEnumeratorImpl(); - PLDHashTableEnumeratorImpl(PLDHashTable *table, - EnumeratorConverter converter, - void *converterData); - PRInt32 Count() { return mCount; } -private: - PLDHashTableEnumeratorImpl(); /* no implementation */ - NS_IMETHODIMP ReleaseElements(); - - nsVoidArray mElements; - PRInt32 mCount, mCurrent; - PRMonitor* mMonitor; - - struct Closure { - PRBool succeeded; - EnumeratorConverter converter; - void *data; - PLDHashTableEnumeratorImpl *impl; - }; - - static PLDHashOperator PR_CALLBACK Enumerator(PLDHashTable *table, - PLDHashEntryHdr *hdr, PRUint32 number, - void *data); -}; - -// static -PLDHashOperator PR_CALLBACK -PLDHashTableEnumeratorImpl::Enumerator(PLDHashTable *table, - PLDHashEntryHdr *hdr, PRUint32 number, - void *data) -{ - Closure *c = NS_REINTERPRET_CAST(Closure *, data); - nsISupports *converted; - if (NS_FAILED(c->converter(table, hdr, c->data, &converted)) || - !c->impl->mElements.AppendElement(converted)) { - c->succeeded = PR_FALSE; - return PL_DHASH_STOP; - } - - c->succeeded = PR_TRUE; - return PL_DHASH_NEXT; -} - -PLDHashTableEnumeratorImpl::PLDHashTableEnumeratorImpl -(PLDHashTable *table, EnumeratorConverter converter, - void *converterData) : - mCurrent(0) -{ - mMonitor = nsAutoMonitor::NewMonitor("PLDHashTableEnumeratorImpl"); - - nsAutoMonitor mon(mMonitor); - - NS_INIT_REFCNT(); - Closure c = { PR_FALSE, converter, converterData, this }; - mCount = PL_DHashTableEnumerate(table, Enumerator, &c); - if (!c.succeeded) { - ReleaseElements(); - mCount = 0; - } -} - -NS_IMPL_ISUPPORTS2(PLDHashTableEnumeratorImpl, nsIBidirectionalEnumerator, - nsIEnumerator); - -PLDHashTableEnumeratorImpl::~PLDHashTableEnumeratorImpl() -{ - (void) ReleaseElements(); - - // Destroy the Lock - if (mMonitor) - PR_DestroyMonitor(mMonitor); -} - -NS_IMETHODIMP -PLDHashTableEnumeratorImpl::ReleaseElements() -{ - for (PRInt32 i = 0; i < mCount; i++) { - nsISupports *supports = NS_REINTERPRET_CAST(nsISupports *, - mElements[i]); - NS_IF_RELEASE(supports); - } - return NS_OK; -} - -NS_IMETHODIMP -PL_NewDHashTableEnumerator(PLDHashTable *table, - EnumeratorConverter converter, - void *converterData, nsIEnumerator **retval) -{ - PLDHashTableEnumeratorImpl *impl = - new PLDHashTableEnumeratorImpl(table, converter, converterData); - - if (!impl) - return NS_ERROR_OUT_OF_MEMORY; - - if (impl->Count() == -1) { - // conversion failed - delete impl; - return NS_ERROR_FAILURE; - } - - return impl->QueryInterface(NS_GET_IID(nsIEnumerator), (void **)retval); -} - -NS_IMETHODIMP -PLDHashTableEnumeratorImpl::First() -{ - if (!mCount) - return NS_ERROR_FAILURE; - - mCurrent = 0; - return NS_OK; -} - -NS_IMETHODIMP -PLDHashTableEnumeratorImpl::Last() -{ - if (!mCount) - return NS_ERROR_FAILURE; - mCurrent = mCount - 1; - return NS_OK; -} - -NS_IMETHODIMP -PLDHashTableEnumeratorImpl::Prev() -{ - if (!mCurrent) - return NS_ERROR_FAILURE; - - mCurrent--; - return NS_OK; -} - -NS_IMETHODIMP -PLDHashTableEnumeratorImpl::Next() -{ - // If empty or we're past the end, or we are at the end return error - if (!mCount || (mCurrent == mCount) || (++mCurrent == mCount)) - return NS_ERROR_FAILURE; - - return NS_OK; -} - -NS_IMETHODIMP -PLDHashTableEnumeratorImpl::CurrentItem(nsISupports **retval) -{ - if (!mCount || mCurrent == mCount) - return NS_ERROR_FAILURE; - - *retval = NS_REINTERPRET_CAST(nsISupports *, mElements[mCurrent]); - if (*retval) - NS_ADDREF(*retval); - - return NS_OK; -} - -NS_IMETHODIMP -PLDHashTableEnumeratorImpl::IsDone() -{ - if (!mCount || (mCurrent == mCount)) { - return NS_OK; - } - - return NS_COMFALSE; -} - - - -static NS_IMETHODIMP -ConvertFactoryEntryToCID(PLDHashTable *table, - const PLDHashEntryHdr *hdr, - void *data, nsISupports **retval) -{ - nsresult rv; - - nsCOMPtr wrapper = - do_CreateInstance(NS_SUPPORTS_ID_CONTRACTID, &rv); - NS_ENSURE_SUCCESS(rv, rv); - - const nsFactoryTableEntry *entry = - NS_REINTERPRET_CAST(const nsFactoryTableEntry *, hdr); - if(entry) { - nsFactoryEntry *fe = entry->mFactoryEntry; - - wrapper->SetData(&fe->cid); - *retval = wrapper; - NS_ADDREF(*retval); - return NS_OK; - } - else - *retval = nsnull; - - return rv; - -} - -static NS_IMETHODIMP -ConvertContractIDKeyToString(PLDHashTable *table, - const PLDHashEntryHdr *hdr, - void *data, nsISupports **retval) -{ - nsresult rv; - - nsCOMPtr wrapper = - do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID, &rv); - NS_ENSURE_SUCCESS(rv, rv); - - const nsContractIDTableEntry *entry = - NS_REINTERPRET_CAST(const nsContractIDTableEntry *, hdr); - const char *contractID = entry->mContractID; - nsCAutoString converted; - - converted.Append(contractID); - - wrapper->SetData(converted.get()); - *retval = wrapper; - NS_ADDREF(*retval); - return NS_OK; - -} - nsresult nsComponentManagerImpl::EnumerateCLSIDs(nsIEnumerator** aEnumerator) { @@ -3206,9 +3281,16 @@ nsComponentManagerImpl::EnumerateCLSIDs(nsIEnumerator** aEnumerator) return rv; } - return PL_NewDHashTableEnumerator(&mFactories, - ConvertFactoryEntryToCID, - nsnull, aEnumerator); + PLDHashTableEnumeratorImpl *aEnum; + rv = PL_NewDHashTableEnumerator(&mFactories, + ConvertFactoryEntryToCID, + nsnull, + &aEnum); + if (NS_FAILED(rv)) + return rv; + + *aEnumerator = NS_REINTERPRET_CAST(nsIEnumerator*, aEnum); + return NS_OK; } nsresult @@ -3229,81 +3311,210 @@ nsComponentManagerImpl::EnumerateContractIDs(nsIEnumerator** aEnumerator) if(NS_FAILED(rv)) return rv; } + PLDHashTableEnumeratorImpl *aEnum; + rv = PL_NewDHashTableEnumerator(&mContractIDs, + ConvertContractIDKeyToString, + nsnull, + &aEnum); + if (NS_FAILED(rv)) + return rv; - return PL_NewDHashTableEnumerator(&mContractIDs, - ConvertContractIDKeyToString, - nsnull, aEnumerator); + *aEnumerator = NS_REINTERPRET_CAST(nsIEnumerator*, aEnum); + return NS_OK; } +// nsIComponentRegistrar -nsresult -nsComponentManagerImpl::GetInterface(const nsIID & uuid, void **result) +NS_IMETHODIMP +nsComponentManagerImpl::AutoRegister(nsIFile *aSpec) { - if (uuid.Equals(NS_GET_IID(nsIServiceManager))) - { - *result = NS_STATIC_CAST(nsIServiceManager*, this); - NS_ADDREF_THIS(); // dougt? extra addrefs??? - return NS_OK; - } + if (aSpec == nsnull) + return AutoRegisterImpl(0, aSpec); + + PRBool directory; + aSpec->IsDirectory(&directory); - // fall through to QI as anything QIable is a superset of what canbe - // got via the GetInterface() - return QueryInterface(uuid, result); + if (directory) + return AutoRegisterImpl(0, aSpec, PR_FALSE); + + return AutoRegisterComponent(0, aSpec); } -// Convert a loader type string into an index into the component data -// array. Empty loader types are converted to NATIVE. Returns -1 if -// loader type cannot be determined. -int -nsComponentManagerImpl::GetLoaderType(const char *typeStr) +NS_IMETHODIMP +nsComponentManagerImpl::AutoUnregister(nsIFile *aSpec) { - if (!typeStr || !*typeStr) { - // Empty type strings are NATIVE - return NS_COMPONENT_TYPE_NATIVE; - } + // unregistering a complete directory is not implmeneted yet...FIX + if (aSpec == nsnull) + return NS_ERROR_NOT_IMPLEMENTED; - for (int i=NS_COMPONENT_TYPE_NATIVE; iIsDirectory(&directory); + + if (directory) + return NS_ERROR_NOT_IMPLEMENTED; + + return AutoUnregisterComponent(0, aSpec); } -// Add a loader type if not already known. Return the typeIndex -// if the loader type is either added or already there. -int -nsComponentManagerImpl::AddLoaderType(const char *typeStr) +NS_IMETHODIMP +nsComponentManagerImpl::RegisterFactory(const nsCID & aClass, + const char *aClassName, + const char *aContractID, + nsIFactory *aFactory) { - int typeIndex = GetLoaderType(typeStr); - if (typeIndex >= 0) { - return typeIndex; - } - - // Add the loader type - if (mNLoaderData >= mMaxNLoaderData) { - NS_ASSERTION(mNLoaderData == mMaxNLoaderData, - "Memory corruption. nsComponentManagerImpl::mLoaderData array overrun."); - // Need to increase our loader array - nsLoaderdata *new_mLoaderData = (nsLoaderdata *) PR_Realloc(mLoaderData, (mMaxNLoaderData + NS_LOADER_DATA_ALLOC_STEP) * sizeof(nsLoaderdata)); - if (!new_mLoaderData) - return NS_ERROR_OUT_OF_MEMORY; - mLoaderData = new_mLoaderData; - mMaxNLoaderData += NS_LOADER_DATA_ALLOC_STEP; - } - - typeIndex = mNLoaderData; - mLoaderData[typeIndex].type = PL_strdup(typeStr); - if (!mLoaderData[typeIndex].type) { - // mmh! no memory. return failure. - return NS_ERROR_OUT_OF_MEMORY; - } - mLoaderData[typeIndex].loader = nsnull; - mNLoaderData++; - - return typeIndex; + return RegisterFactory(aClass, + aClassName, + aContractID, + aFactory, + PR_TRUE); } +NS_IMETHODIMP +nsComponentManagerImpl::RegisterFactoryLocation(const nsCID & aClass, + const char *aClassName, + const char *aContractID, + nsIFile *aFile, + const char *loaderStr, + const char *aType) +{ + nsXPIDLCString registryName; + + if (!loaderStr) + { + nsresult rv = RegistryLocationForSpec(aFile, getter_Copies(registryName)); + if (NS_FAILED(rv)) + return rv; + } + + nsresult rv; + rv = RegisterComponentWithType(aClass, + aClassName, + aContractID, + aFile, + (loaderStr ? loaderStr : registryName), + PR_TRUE, + PR_TRUE, + (aType ? aType : nativeComponentType) ); + return rv; +} + +NS_IMETHODIMP +nsComponentManagerImpl::UnregisterFactoryLocation(const nsCID & aClass, + nsIFile *aFile) +{ + return UnregisterComponentSpec(aClass, aFile); +} + +NS_IMETHODIMP +nsComponentManagerImpl::IsCIDRegistered(const nsCID & aClass, + PRBool *_retval) +{ + return IsRegistered(aClass, _retval); +} + +NS_IMETHODIMP +nsComponentManagerImpl::IsContractIDRegistered(const char *aClass, + PRBool *_retval) +{ + nsFactoryEntry *entry = GetFactoryEntry(aClass); + + if (!entry || entry == kNonExistentContractID) + *_retval = PR_FALSE; + else + *_retval = PR_TRUE; + return NS_OK; +} + +NS_IMETHODIMP +nsComponentManagerImpl::EnumerateCIDs(nsISimpleEnumerator **aEnumerator) +{ + NS_ASSERTION(aEnumerator != nsnull, "null ptr"); + + if(!aEnumerator) + return NS_ERROR_NULL_POINTER; + + *aEnumerator = nsnull; + + nsresult rv; + if(!mPrePopulationDone) + { + rv = PlatformPrePopulateRegistry(); + if(NS_FAILED(rv)) + return rv; + } + PLDHashTableEnumeratorImpl *aEnum; + rv = PL_NewDHashTableEnumerator(&mFactories, + ConvertFactoryEntryToCID, + nsnull, + &aEnum); + if (NS_FAILED(rv)) + return rv; + + *aEnumerator = NS_REINTERPRET_CAST(nsISimpleEnumerator*, aEnum); + return NS_OK; +} + +NS_IMETHODIMP +nsComponentManagerImpl::EnumerateContractIDs(nsISimpleEnumerator **aEnumerator) +{ + NS_ASSERTION(aEnumerator != nsnull, "null ptr"); + if(!aEnumerator) + return NS_ERROR_NULL_POINTER; + + *aEnumerator = nsnull; + + nsresult rv; + if(!mPrePopulationDone) + { + rv = PlatformPrePopulateRegistry(); + if(NS_FAILED(rv)) + return rv; + } + + PLDHashTableEnumeratorImpl *aEnum; + rv = PL_NewDHashTableEnumerator(&mContractIDs, + ConvertContractIDKeyToString, + nsnull, + &aEnum); + if (NS_FAILED(rv)) + return rv; + + *aEnumerator = NS_REINTERPRET_CAST(nsISimpleEnumerator*, aEnum); + return NS_OK; +} + +NS_IMETHODIMP +nsComponentManagerImpl::CIDToContractID(const nsCID & aClass, + char **_retval) +{ + return CLSIDToContractID(aClass, + nsnull, + _retval); +} + +NS_IMETHODIMP +nsComponentManagerImpl::ContractIDToCID(const char *aContractID, + nsCID * *_retval) +{ + nsCID aCID; + nsresult rv = ContractIDToClassID(aContractID, &aCID); + if (NS_FAILED(rv)) + return rv; + + // not sure about this... FIX + *_retval = (nsCID*) nsMemory::Alloc(sizeof(nsCID)); + *_retval = &aCID; + + return NS_OK; +} + +// end nsIComponentRegistrar + + + + +//////////////////////////////////////////////////////////////////////////////// +// Static Access Functions //////////////////////////////////////////////////////////////////////////////// NS_COM nsresult @@ -3331,9 +3542,6 @@ NS_GetGlobalComponentManager(nsIComponentManager* *result) return rv; } - - - NS_COM nsresult NS_GetComponentManager(nsIComponentManager* *result) { @@ -3377,3 +3585,23 @@ NS_GetServiceManager(nsIServiceManager* *result) } +NS_COM nsresult +NS_GetComponentRegistrar(nsIComponentRegistrar* *result) +{ + nsresult rv = NS_OK; + + if (nsComponentManagerImpl::gComponentManager == NULL) + { + // XPCOM needs initialization. + rv = NS_InitXPCOM2(nsnull, nsnull, nsnull); + } + + if (NS_FAILED(rv)) + return rv; + + *result = NS_STATIC_CAST(nsIComponentRegistrar*, + nsComponentManagerImpl::gComponentManager); + NS_IF_ADDREF(*result); + return NS_OK; +} + diff --git a/mozilla/xpcom/components/nsComponentManager.h b/mozilla/xpcom/components/nsComponentManager.h index f51c021e0f8..62fe0fb7e5f 100644 --- a/mozilla/xpcom/components/nsComponentManager.h +++ b/mozilla/xpcom/components/nsComponentManager.h @@ -43,6 +43,7 @@ #include "nsIComponentLoader.h" #include "nsNativeComponentLoader.h" #include "nsIComponentManager.h" +#include "nsIComponentRegistrar.h" #include "nsIComponentManagerObsolete.h" #include "nsIServiceManager.h" #include "nsIFactory.h" @@ -84,6 +85,7 @@ extern const char XPCOM_LIB_PREFIX[]; class nsComponentManagerImpl : public nsIComponentManager, public nsIServiceManager, + public nsIComponentRegistrar, public nsSupportsWeakReference, public nsIInterfaceRequestor, public nsIServiceManagerObsolete, @@ -94,7 +96,7 @@ public: NS_DECL_NSIINTERFACEREQUESTOR // Since the nsIComponentManagerObsolete and nsIComponentManager share some of the - // same interface function name, we have to manually define the functions here. + // same interface function names, we have to manually define the functions here. // The only function that is in nsIComponentManagerObsolete and is in nsIComponentManager // is GetClassObjectContractID. // @@ -103,39 +105,27 @@ public: const nsIID &aIID, void **_retval); + NS_DECL_NSICOMPONENTMANAGEROBSOLETE - NS_DECL_NSISERVICEMANAGER + + // Since the nsIComponentManagerObsolete and nsIComponentRegistrar share some of the + // same interface function names, we have to manually define the functions here. + // the only fuction that is shared is UnregisterFactory + NS_IMETHOD AutoRegister(nsIFile *aSpec); + NS_IMETHOD AutoUnregister(nsIFile *aSpec); + NS_IMETHOD RegisterFactory(const nsCID & aClass, const char *aClassName, const char *aContractID, nsIFactory *aFactory); + // NS_IMETHOD UnregisterFactory(const nsCID & aClass, nsIFactory *aFactory); + NS_IMETHOD RegisterFactoryLocation(const nsCID & aClass, const char *aClassName, const char *aContractID, nsIFile *aFile, const char *loaderStr, const char *aType); + NS_IMETHOD UnregisterFactoryLocation(const nsCID & aClass, nsIFile *aFile); + NS_IMETHOD IsCIDRegistered(const nsCID & aClass, PRBool *_retval); + NS_IMETHOD IsContractIDRegistered(const char *aClass, PRBool *_retval); + NS_IMETHOD EnumerateCIDs(nsISimpleEnumerator **_retval); + NS_IMETHOD EnumerateContractIDs(nsISimpleEnumerator **_retval); + NS_IMETHOD CIDToContractID(const nsCID & aClass, char **_retval); + NS_IMETHOD ContractIDToCID(const char *aContractID, nsCID * *_retval); - // nsIServiceManagerObsolete - 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); - - NS_IMETHOD - ReleaseService(const nsCID& aClass, nsISupports* service, - nsIShutdownListener* shutdownListener); - - 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); - - NS_IMETHOD - ReleaseService(const char* aContractID, nsISupports* service, - nsIShutdownListener* shutdownListener); + NS_DECL_NSISERVICEMANAGER + NS_DECL_NSISERVICEMANAGEROBSOLETE // nsComponentManagerImpl methods: nsComponentManagerImpl(); @@ -181,6 +171,10 @@ protected: nsresult HashContractID(const char *acontractID, nsFactoryEntry *fe_ptr); 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); + + void DeleteContractIDEntriesByCID(const nsCID* aClass, const char*registryName); + void DeleteContractIDEntriesByCID(const nsCID* aClass, nsIFactory* factory); + nsresult UnloadLibraries(nsIServiceManager *servmgr, PRInt32 when); // The following functions are the only ones that operate on the persistent @@ -204,7 +198,7 @@ protected: int AddLoaderType(const char *typeStr); private: - nsresult AutoRegisterImpl(PRInt32 when, nsIFile *inDirSpec); + nsresult AutoRegisterImpl(PRInt32 when, nsIFile *inDirSpec, PRBool fileIsCompDir=PR_TRUE); protected: PLDHashTable mFactories; diff --git a/mozilla/xpcom/components/nsGenericFactory.cpp b/mozilla/xpcom/components/nsGenericFactory.cpp index 174752218ca..f7b580e2dd9 100644 --- a/mozilla/xpcom/components/nsGenericFactory.cpp +++ b/mozilla/xpcom/components/nsGenericFactory.cpp @@ -43,7 +43,7 @@ #include "nsCRT.h" #include "nsCOMPtr.h" #include "nsIComponentManager.h" -#include "nsIComponentManagerObsolete.h" +#include "nsIComponentRegistrar.h" nsGenericFactory::nsGenericFactory(nsModuleComponentInfo *info) : mInfo(info) { @@ -358,15 +358,14 @@ nsGenericModule::RegisterSelf(nsIComponentManager *aCompMgr, for (PRUint32 i = 0; i < mComponentCount; i++) { // Register the component only if it has a constructor if (cp->mConstructor) { - // what I want to do here is QI for a Component Registration Manager. Since this - // has not been invented yet, QI to the obsolete manager. Kids, don't do this at home. - nsCOMPtr obsoleteManager = do_QueryInterface(aCompMgr, &rv); - if (obsoleteManager) - rv = obsoleteManager->RegisterComponentWithType(cp->mCID, - cp->mDescription, - cp->mContractID, aPath, - registryLocation, PR_TRUE, - PR_TRUE, componentType); + nsCOMPtr registrar = do_QueryInterface(aCompMgr, &rv); + if (registrar) + rv = registrar->RegisterFactoryLocation(cp->mCID, + cp->mDescription, + cp->mContractID, + aPath, + registryLocation, + componentType); if (NS_FAILED(rv)) { #ifdef DEBUG printf("nsGenericModule %s: unable to register %s component => %x\n", @@ -411,13 +410,10 @@ nsGenericModule::UnregisterSelf(nsIComponentManager* aCompMgr, } // Unregister the component - - // what I want to do here is QI for a Component Registration Manager. Since this - // has not been invented yet, QI to the obsolete manager. Kids, don't do this at home. nsresult rv; - nsCOMPtr obsoleteManager = do_QueryInterface(aCompMgr, &rv); - if (obsoleteManager) - rv = obsoleteManager->UnregisterComponentSpec(cp->mCID, aPath); + nsCOMPtr registrar = do_QueryInterface(aCompMgr, &rv); + if (registrar) + rv = registrar->UnregisterFactoryLocation(cp->mCID, aPath); if (NS_FAILED(rv)) { #ifdef DEBUG printf("nsGenericModule %s: unable to unregister %s component => %x\n", diff --git a/mozilla/xpcom/components/nsIModule.idl b/mozilla/xpcom/components/nsIModule.idl index dce43dd86b0..2850dd391da 100644 --- a/mozilla/xpcom/components/nsIModule.idl +++ b/mozilla/xpcom/components/nsIModule.idl @@ -42,7 +42,7 @@ interface nsIComponentManager; /** * The nsIModule interface. - * @status UNDER_REVIEW + * @status FROZEN */ [scriptable, uuid(7392D032-5371-11d3-994E-00805FD26FEE)] diff --git a/mozilla/xpcom/components/nsIServiceManagerObsolete.h b/mozilla/xpcom/components/nsIServiceManagerObsolete.h index bba513e72b5..607d2e7ace5 100644 --- a/mozilla/xpcom/components/nsIServiceManagerObsolete.h +++ b/mozilla/xpcom/components/nsIServiceManagerObsolete.h @@ -179,6 +179,17 @@ public: static nsresult ShutdownGlobalServiceManager(nsIServiceManager* *result); }; + +#define NS_DECL_NSISERVICEMANAGEROBSOLETE \ + 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);\ + NS_IMETHOD ReleaseService(const nsCID& aClass, nsISupports* service, nsIShutdownListener* shutdownListener);\ + 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);\ + NS_IMETHOD ReleaseService(const char* aContractID, nsISupports* service, nsIShutdownListener* shutdownListener); + //////////////////////////////////////////////////////////////////////////////// #define NS_ISHUTDOWNLISTENER_IID \ diff --git a/mozilla/xpcom/components/nsNativeComponentLoader.cpp b/mozilla/xpcom/components/nsNativeComponentLoader.cpp index 97be1d6956e..6a3ea2e4511 100644 --- a/mozilla/xpcom/components/nsNativeComponentLoader.cpp +++ b/mozilla/xpcom/components/nsNativeComponentLoader.cpp @@ -373,7 +373,6 @@ nsFreeLibrary(nsDll *dll, nsIServiceManager *serviceMgr, PRInt32 when) #endif /* OBSOLETE_MODULE_LOADING */ mobj = nsnull; // Release our reference to the module object - // When shutting down, whether we can unload the dll or not, // we will shutdown the dll to release any memory it has got if (when == nsIComponentManagerObsolete::NS_Shutdown) diff --git a/mozilla/xpcom/ds/nsVoidArray.h b/mozilla/xpcom/ds/nsVoidArray.h index 2559baa3e3b..95d17b11e9e 100644 --- a/mozilla/xpcom/ds/nsVoidArray.h +++ b/mozilla/xpcom/ds/nsVoidArray.h @@ -83,7 +83,7 @@ public: { return nsnull; } - return mImpl->mArray[aIndex]; + return mImpl ? mImpl->mArray[aIndex] : nsnull; } // bounds-checked version @@ -93,7 +93,7 @@ public: { return nsnull; } - return mImpl->mArray[aIndex]; + return mImpl ? mImpl->mArray[aIndex] : nsnull; } void* operator[](PRInt32 aIndex) const { return ElementAt(aIndex); } diff --git a/mozilla/xpcom/glue/nsGenericFactory.cpp b/mozilla/xpcom/glue/nsGenericFactory.cpp index 174752218ca..f7b580e2dd9 100644 --- a/mozilla/xpcom/glue/nsGenericFactory.cpp +++ b/mozilla/xpcom/glue/nsGenericFactory.cpp @@ -43,7 +43,7 @@ #include "nsCRT.h" #include "nsCOMPtr.h" #include "nsIComponentManager.h" -#include "nsIComponentManagerObsolete.h" +#include "nsIComponentRegistrar.h" nsGenericFactory::nsGenericFactory(nsModuleComponentInfo *info) : mInfo(info) { @@ -358,15 +358,14 @@ nsGenericModule::RegisterSelf(nsIComponentManager *aCompMgr, for (PRUint32 i = 0; i < mComponentCount; i++) { // Register the component only if it has a constructor if (cp->mConstructor) { - // what I want to do here is QI for a Component Registration Manager. Since this - // has not been invented yet, QI to the obsolete manager. Kids, don't do this at home. - nsCOMPtr obsoleteManager = do_QueryInterface(aCompMgr, &rv); - if (obsoleteManager) - rv = obsoleteManager->RegisterComponentWithType(cp->mCID, - cp->mDescription, - cp->mContractID, aPath, - registryLocation, PR_TRUE, - PR_TRUE, componentType); + nsCOMPtr registrar = do_QueryInterface(aCompMgr, &rv); + if (registrar) + rv = registrar->RegisterFactoryLocation(cp->mCID, + cp->mDescription, + cp->mContractID, + aPath, + registryLocation, + componentType); if (NS_FAILED(rv)) { #ifdef DEBUG printf("nsGenericModule %s: unable to register %s component => %x\n", @@ -411,13 +410,10 @@ nsGenericModule::UnregisterSelf(nsIComponentManager* aCompMgr, } // Unregister the component - - // what I want to do here is QI for a Component Registration Manager. Since this - // has not been invented yet, QI to the obsolete manager. Kids, don't do this at home. nsresult rv; - nsCOMPtr obsoleteManager = do_QueryInterface(aCompMgr, &rv); - if (obsoleteManager) - rv = obsoleteManager->UnregisterComponentSpec(cp->mCID, aPath); + nsCOMPtr registrar = do_QueryInterface(aCompMgr, &rv); + if (registrar) + rv = registrar->UnregisterFactoryLocation(cp->mCID, aPath); if (NS_FAILED(rv)) { #ifdef DEBUG printf("nsGenericModule %s: unable to unregister %s component => %x\n", diff --git a/mozilla/xpcom/io/MANIFEST b/mozilla/xpcom/io/MANIFEST index 5ba3afd39e7..d714ce3609a 100644 --- a/mozilla/xpcom/io/MANIFEST +++ b/mozilla/xpcom/io/MANIFEST @@ -4,6 +4,7 @@ nsFileSpec.h nsFileSpecStreaming.h nsFileStream.h nsIFileStream.h +nsIFileUtils.h nsIUnicharInputStream.h nsSpecialSystemDirectory.h nsStorageStream.h diff --git a/mozilla/xpcom/io/Makefile.in b/mozilla/xpcom/io/Makefile.in index d62e7ac20ac..c263e37523c 100644 --- a/mozilla/xpcom/io/Makefile.in +++ b/mozilla/xpcom/io/Makefile.in @@ -85,6 +85,7 @@ EXPORTS = \ nsFileSpecStreaming.h \ nsFileStream.h \ nsIFileStream.h \ + nsIFileUtils.h \ nsIUnicharInputStream.h \ nsLinebreakConverter.h \ nsLocalFile.h \ diff --git a/mozilla/xpcom/io/makefile.win b/mozilla/xpcom/io/makefile.win index 91214fe1ab1..d24b6e0ed73 100644 --- a/mozilla/xpcom/io/makefile.win +++ b/mozilla/xpcom/io/makefile.win @@ -39,6 +39,7 @@ EXPORTS = \ nsFileSpecStreaming.h \ nsFileStream.h \ nsIFileStream.h \ + nsIFileUtils.h \ nsIUnicharInputStream.h \ nsLinebreakConverter.h \ nsScriptableInputStream.h \ diff --git a/mozilla/xpcom/io/nsIDirectoryService.idl b/mozilla/xpcom/io/nsIDirectoryService.idl index 5d790cb58b9..53a76310b16 100644 --- a/mozilla/xpcom/io/nsIDirectoryService.idl +++ b/mozilla/xpcom/io/nsIDirectoryService.idl @@ -136,8 +136,8 @@ interface nsIDirectoryService: nsISupports }; %{C++ -#define NS_DIRECTORY_SERVICE_CONTRACTID "@mozilla.org/file/directory_service;1" -#define NS_DIRECTORY_SERVICE_CLASSNAME "nsIFile Directory Service" +#define NS_DIRECTORY_SERVICE_CONTRACTID "@mozilla.org/file/directory_service;1" +#define NS_DIRECTORY_SERVICE_CLASSNAME "nsIFile Directory Service" %} diff --git a/mozilla/xpcom/io/nsIFile.idl b/mozilla/xpcom/io/nsIFile.idl index 02afedbbe5a..dc47d062100 100644 --- a/mozilla/xpcom/io/nsIFile.idl +++ b/mozilla/xpcom/io/nsIFile.idl @@ -1,27 +1,42 @@ -/* -*- Mode: C++; tab-width: 4; 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/ +/* Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 * - * 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 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/ * - * The Original Code is Mozilla Communicator client code, - * released March 31, 1998. + * 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 Initial Developer of the Original Code is Netscape Communications - * Corporation. Portions created by Netscape are - * Copyright (C) 1998-1999 Netscape Communications Corporation. All - * Rights Reserved. + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. * * Contributor(s): * Doug Turner * Christopher Blizzard - */ + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead +` * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + /** @@ -29,7 +44,7 @@ * Strings are not such a way. If you grew up on windows or unix, you * may think they are. Welcome to reality. * - * @status UNDER_REVIEW + * @status FROZEN */ #include "nsISupports.idl" @@ -302,32 +317,7 @@ interface nsIFile : nsISupports %{C++ #define NS_FILE_CONTRACTID "@mozilla.org/file;1" #define NS_FILE_CLASSNAME "File Specification" - -//////////////////////////////////////////////////////////////////////////////// -// Special Directories - -#include "nsIServiceManager.h" -#include "nsIProperties.h" -#include "nsCOMPtr.h" - -#define NS_DIRECTORY_SERVICE_CID {0xf00152d0,0xb40b,0x11d3,{0x8c, 0x9c, 0x00, 0x00, 0x64, 0x65, 0x73, 0x74}} - -inline nsresult -NS_GetSpecialDirectory(const char* specialDirName, nsIFile* *result) -{ - nsresult rv; - static NS_DEFINE_CID(kDirectoryServiceCID, NS_DIRECTORY_SERVICE_CID); - nsCOMPtr serv(do_GetService(kDirectoryServiceCID, &rv)); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr dir; - rv = serv->Get(specialDirName, NS_GET_IID(nsIFile), getter_AddRefs(dir)); - if (NS_FAILED(rv)) return rv; - - *result = NS_STATIC_CAST(nsIFile*, NS_STATIC_CAST(nsISupports*, dir)); - if (*result) - NS_ADDREF(*result); - return NS_OK; -} - +#ifndef MOZILLA_STRICT_API +#include "nsIFileUtils.h" +#endif %} diff --git a/mozilla/xpcom/proxy/tests/proxytests.cpp b/mozilla/xpcom/proxy/tests/proxytests.cpp index 0855584db71..d38f526cf66 100644 --- a/mozilla/xpcom/proxy/tests/proxytests.cpp +++ b/mozilla/xpcom/proxy/tests/proxytests.cpp @@ -40,6 +40,7 @@ #include "nsXPCOM.h" #include "nsIComponentManager.h" +#include "nsIComponentRegistrar.h" #include "nsIServiceManager.h" #include "nsCOMPtr.h" #include "nsSpecialSystemDirectory.h" // For exe dir @@ -496,11 +497,12 @@ main(int argc, char **argv) if (argc > 1) numberOfThreads = atoi(argv[1]); - NS_InitXPCOM2(nsnull, nsnull, nsnull); - nsComponentManager::AutoRegister(nsIComponentManagerObsolete::NS_Startup, - NULL /* default */); - - + nsCOMPtr servMan; + NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + registrar->AutoRegister(nsnull); + static PRThread** threads = (PRThread**) calloc(sizeof(PRThread*), numberOfThreads); static PRThread* aEventThread; diff --git a/mozilla/xpcom/sample/nsSample.js b/mozilla/xpcom/sample/nsSample.js index 989724f11d4..95a4757af2a 100644 --- a/mozilla/xpcom/sample/nsSample.js +++ b/mozilla/xpcom/sample/nsSample.js @@ -65,12 +65,13 @@ var myModule = { throw Components.results.NS_ERROR_FACTORY_REGISTER_AGAIN; } dump("*** Registering sample JS components\n"); - compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentManagerObsolete); - compMgr.registerComponentWithType(this.myCID, - "Sample JS Component", - this.myProgID, fileSpec, - location, true, true, - type); + compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar); + compMgr.registerFactoryLocation(this.myCID, + "Sample JS Component", + this.myProgID, + fileSpec, + location, + type); }, /* @@ -130,3 +131,5 @@ var myModule = { function NSGetModule(compMgr, fileSpec) { return myModule; } + + diff --git a/mozilla/xpcom/sample/nsTestSample.cpp b/mozilla/xpcom/sample/nsTestSample.cpp index 77747f2c79b..2b2df42c376 100644 --- a/mozilla/xpcom/sample/nsTestSample.cpp +++ b/mozilla/xpcom/sample/nsTestSample.cpp @@ -42,9 +42,10 @@ * to be a sample application for using xpcom standalone. */ -#include -#include -#include +#include "nsISample.h" +#include "nsIServiceManager.h" +#include "nsXPIDLString.h" +#include "nsIComponentRegistrar.h" #define NS_SAMPLE_CONTRACTID "@mozilla.org/sample;1" @@ -54,25 +55,18 @@ main(void) nsresult rv; // Initialize XPCOM - rv = NS_InitXPCOM2(nsnull, nsnull, nsnull); + nsCOMPtr servMan; + rv = NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); if (NS_FAILED(rv)) { printf("ERROR: XPCOM intialization error [%x].\n", rv); return -1; } - - // Do Autoreg to make sure our component is registered. The real way of - // doing this is running the xpcom registraion tool, regxpcom, at install - // time to get components registered and not make this call everytime. - // Ignore return value. - // - // Here we use the global component manager. Note that this will cause - // linkage dependency to XPCOM library. We feel that linkage dependency - // to XPCOM is inevitable and this is simpler to code. - // To break free from such dependencies, we can GetService() the component - // manager from the service manager that is returned from NS_InitXPCOM(). - // We feel that linkage dependency to XPCOM library is inevitable. - (void) nsComponentManager::AutoRegister(nsIComponentManagerObsolete::NS_Startup, nsnull); + // register all components in our default component directory + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + registrar->AutoRegister(nsnull); + // Create an instance of our component nsCOMPtr mysample = do_CreateInstance(NS_SAMPLE_CONTRACTID, &rv); diff --git a/mozilla/xpcom/tests/PropertiesTest.cpp b/mozilla/xpcom/tests/PropertiesTest.cpp index dc0a53f4f69..5fa880e8b99 100644 --- a/mozilla/xpcom/tests/PropertiesTest.cpp +++ b/mozilla/xpcom/tests/PropertiesTest.cpp @@ -43,6 +43,7 @@ #include "nsIEventQueueService.h" #include "nsIPersistentProperties2.h" #include "nsIServiceManager.h" +#include "nsIComponentRegistrar.h" #include "nsIURL.h" #include "nsIIOService.h" #include "nsNetCID.h" @@ -69,9 +70,12 @@ main(int argc, char* argv[]) #ifndef XPCOM_STANDALONE nsresult ret; - NS_InitXPCOM2(nsnull, nsnull, nsnull); - nsComponentManager::AutoRegister(nsIComponentManagerObsolete::NS_Startup, - NULL /* default */); + + nsCOMPtr servMan; + NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + registrar->AutoRegister(nsnull); // Create the Event Queue for this thread... nsCOMPtr pEventQService = diff --git a/mozilla/xpcom/tests/RegFactory.cpp b/mozilla/xpcom/tests/RegFactory.cpp index 252312a9ae9..c2f6d9126a8 100644 --- a/mozilla/xpcom/tests/RegFactory.cpp +++ b/mozilla/xpcom/tests/RegFactory.cpp @@ -38,6 +38,7 @@ #include #include "plstr.h" #include "prlink.h" +#include "nsIComponentRegistrar.h" #include "nsIComponentManager.h" #include "nsIServiceManager.h" #include "nsCOMPtr.h" @@ -64,14 +65,14 @@ void print_err(nsresult err) } } -nsresult Register(const char *path) +nsresult Register(nsIComponentRegistrar* register, const char *path) { nsCOMPtr spec; nsresult res = NS_NewFileSpec(getter_AddRefs(spec)); if (NS_FAILED(res)) return res; res = spec->SetNativePath((char *)path); if (NS_FAILED(res)) return res; - res = nsComponentManager::AutoRegisterComponent(nsIComponentManagerObsolete::NS_Startup, spec); + res = register->AutoRegister(spec); return res; } @@ -79,14 +80,14 @@ nsresult Unregister(const char *path) { /* NEEDS IMPLEMENTATION */ #if 0 - nsresult res = nsComponentManager::AutoUnregisterComponent(path); + nsresult res = nsComponentManager::AutoUnregisterComponent(path); return res; #else return NS_ERROR_FAILURE; #endif } -int ProcessArgs(int argc, char *argv[]) +int ProcessArgs(nsIComponentRegistrar* register, int argc, char *argv[]) { int i = 1; nsresult res; @@ -115,7 +116,7 @@ int ProcessArgs(int argc, char *argv[]) cerr << "): " << argv[i] << "\n"; } } else { - res = Register(argv[i]); + res = Register(register, argv[i]); if (NS_SUCCEEDED(res)) { cout << "Successfully registered: " << argv[i] << "\n"; } else { @@ -134,16 +135,20 @@ int main(int argc, char *argv[]) { int ret = 0; + nsCOMPtr servMan; + rv = NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + if (NS_FAILED(rv)) return -1; + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + /* With no arguments, RegFactory will autoregister */ if (argc <= 1) { - nsresult rv = nsComponentManager::AutoRegister( - nsIComponentManagerObsolete::NS_Startup, - NULL /* default location */); - ret = (NS_FAILED(rv)) ? -1 : 0; + rv = registrar->AutoRegister(nsnull); + ret = (NS_FAILED(rv)) ? -1 : 0; } else - ret = ProcessArgs(argc, argv); + ret = ProcessArgs(registrar, argc, argv); return ret; } diff --git a/mozilla/xpcom/tests/TestFactory.cpp b/mozilla/xpcom/tests/TestFactory.cpp index 3441fa39812..5df2a449b0f 100644 --- a/mozilla/xpcom/tests/TestFactory.cpp +++ b/mozilla/xpcom/tests/TestFactory.cpp @@ -40,51 +40,12 @@ #include "TestFactory.h" #include "nsISupports.h" #include "nsIComponentManager.h" +#include "nsIComponentRegistrar.h" #include "nsIServiceManager.h" NS_DEFINE_CID(kTestFactoryCID, NS_TESTFACTORY_CID); NS_DEFINE_CID(kTestLoadedFactoryCID, NS_TESTLOADEDFACTORY_CID); -int main(int argc, char **argv) { - nsresult rv; - - rv = nsComponentManager::AutoRegister(nsIComponentManagerObsolete::NS_Startup, - NULL /* default */); - if (NS_FAILED(rv)) return rv; - - RegisterTestFactories(); - - ITestClass *t = NULL; - nsComponentManager::CreateInstance(kTestFactoryCID, - NULL, - NS_GET_IID(ITestClass), - (void **) &t); - - if (t != NULL) { - t->Test(); - t->Release(); - } else { - cout << "CreateInstance failed\n"; - } - - t = NULL; - - nsComponentManager::CreateInstance(kTestLoadedFactoryCID, - NULL, - NS_GET_IID(ITestClass), - (void **) &t); - - if (t != NULL) { - t->Test(); - t->Release(); - } else { - cout << "Dynamic CreateInstance failed\n"; - } - - nsComponentManager::FreeLibraries(); - - return 0; -} /** * ITestClass implementation @@ -150,19 +111,50 @@ nsresult TestFactory::CreateInstance(nsISupports *aDelegate, return res; } -/** - * TestFactory registration function - */ -extern "C" void RegisterTestFactories() { - nsComponentManager::RegisterFactory(kTestFactoryCID, 0, 0, - new TestFactory(), PR_FALSE); +int main(int argc, char **argv) { + nsresult rv; - // Windows can use persistant registry -#ifndef USE_NSREG - nsComponentManager::RegisterComponent(kTestLoadedFactoryCID, NULL, NULL, - "libtestdynamic"MOZ_DLL_SUFFIX, - PR_FALSE, - PR_TRUE); -#endif + + nsCOMPtr servMan; + rv = NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + if (NS_FAILED(rv)) return -1; + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + + registrar->RegisterFactory(kTestFactoryCID, + nsnull, + nsnull, + new TestFactory()); + + + ITestClass *t = NULL; + nsComponentManager::CreateInstance(kTestFactoryCID, + NULL, + NS_GET_IID(ITestClass), + (void **) &t); + + if (t != NULL) { + t->Test(); + t->Release(); + } else { + cout << "CreateInstance failed\n"; + } + + t = NULL; + + nsComponentManager::CreateInstance(kTestLoadedFactoryCID, + NULL, + NS_GET_IID(ITestClass), + (void **) &t); + + if (t != NULL) { + t->Test(); + t->Release(); + } else { + cout << "Dynamic CreateInstance failed\n"; + } + + return 0; } + diff --git a/mozilla/xpcom/tests/nsIFileEnumerator.cpp b/mozilla/xpcom/tests/nsIFileEnumerator.cpp index a980a41ced4..5f66d739990 100644 --- a/mozilla/xpcom/tests/nsIFileEnumerator.cpp +++ b/mozilla/xpcom/tests/nsIFileEnumerator.cpp @@ -1,6 +1,7 @@ #include "nsILocalFile.h" #include +#include "nsIComponentRegistrar.h" #include "nsIComponentManager.h" #include "nsIServiceManager.h" #include "nsMemory.h" @@ -60,14 +61,16 @@ main(int argc, char* argv[]) nsresult rv; nsCOMPtr topDir; - rv = NS_InitXPCOM2(nsnull, nsnull, nsnull); + nsCOMPtr servMan; + rv = NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); if (NS_FAILED(rv)) return -1; - - nsComponentManager::AutoRegister(nsIComponentManagerObsolete::NS_Startup, NULL); + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + registrar->AutoRegister(nsnull); if (argc > 1 && argv[1] != nsnull) { - char* pathStr = argv[1]; + char* pathStr = argv[1]; NS_NewLocalFile(pathStr, PR_FALSE, getter_AddRefs(topDir)); } diff --git a/mozilla/xpcom/tests/nsIFileTest.cpp b/mozilla/xpcom/tests/nsIFileTest.cpp index d9c3749fa66..e7e92353e17 100644 --- a/mozilla/xpcom/tests/nsIFileTest.cpp +++ b/mozilla/xpcom/tests/nsIFileTest.cpp @@ -3,6 +3,7 @@ #include #include "nsXPCOM.h" #include "nsIComponentManager.h" +#include "nsIComponentRegistrar.h" #include "nsIServiceManager.h" #include "nsIMemory.h" #include "nsXPIDLString.h" @@ -314,11 +315,12 @@ DeletionTest(const char* creationPath, const char* appendPath, PRBool recursive) int main(void) { - NS_InitXPCOM2(nsnull, nsnull, nsnull); - nsComponentManager::AutoRegister(nsIComponentManagerObsolete::NS_Startup, - NULL); - - + nsCOMPtr servMan; + NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + registrar->AutoRegister(nsnull); + #ifdef XP_PC InitTest("c:\\temp\\", "sub1/sub2/"); InitTest("d:\\temp\\", "sub1\\sub2\\"); diff --git a/mozilla/xpcom/tests/windows/TestHelloXPLoop.cpp b/mozilla/xpcom/tests/windows/TestHelloXPLoop.cpp index 3803bc126b0..3844a4a10cf 100644 --- a/mozilla/xpcom/tests/windows/TestHelloXPLoop.cpp +++ b/mozilla/xpcom/tests/windows/TestHelloXPLoop.cpp @@ -40,70 +40,75 @@ void InfoBox(LPSTR text) MessageBox(NULL, text, "XP Event Loop", MB_OK | MB_ICONINFORMATION); } -int WINAPI WinMain(HINSTANCE inst, HINSTANCE prevInstance, LPSTR lpszCmdLine, - int nShowCmd) +int WINAPI WinMain(HINSTANCE inst, + HINSTANCE prevInstance, + LPSTR lpszCmdLine, + int nShowCmd) { char* lpszAppName = "HelloWorld"; HWND wnd; WNDCLASSEX wndclass; int retCode; - nsresult rv; - rv = NS_InitXPCOM2(NULL, NULL, NULL); - { // Needed to scope all nsCOMPtr within XPCOM Init and Shutdown - if(NS_FAILED(rv)) - { - ErrorBox("Failed to initalize xpcom."); - return -1; - } + { // Needed to scope all nsCOMPtr within XPCOM Init and Shutdown + nsresult rv; + nsCOMPtr servMan; + rv = NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + if(NS_FAILED(rv)) + { + ErrorBox("Failed to initalize xpcom."); + return -1; + } - nsComponentManager::AutoRegister(nsIComponentManagerObsolete::NS_Startup, nsnull); + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + registrar->AutoRegister(nsnull); + + nsCOMPtr nativeAppService(do_GetService(kNativeAppCID, &rv)); - nsCOMPtr nativeAppService(do_GetService(kNativeAppCID, &rv)); + if(NS_FAILED(rv)) + { + ErrorBox("Failed to get nativeAppService"); + return -1; + } + wndclass.cbSize = sizeof(wndclass); + wndclass.style = CS_HREDRAW | CS_VREDRAW; + wndclass.lpfnWndProc = WndProc; + wndclass.cbClsExtra = 0; + wndclass.cbWndExtra = 0; + wndclass.hInstance = inst; + wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); + wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); + wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); + wndclass.lpszMenuName = NULL; + wndclass.lpszClassName = lpszAppName; + wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION); - if(NS_FAILED(rv)) - { - ErrorBox("Failed to get nativeAppService"); - return -1; - } - wndclass.cbSize = sizeof(wndclass); - wndclass.style = CS_HREDRAW | CS_VREDRAW; - wndclass.lpfnWndProc = WndProc; - wndclass.cbClsExtra = 0; - wndclass.cbWndExtra = 0; - wndclass.hInstance = inst; - wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); - wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); - wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); - wndclass.lpszMenuName = NULL; - wndclass.lpszClassName = lpszAppName; - wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION); - - RegisterClassEx(&wndclass) ; - - wnd = CreateWindow(lpszAppName, "The Hello World", - WS_OVERLAPPEDWINDOW, - CW_USEDEFAULT, CW_USEDEFAULT, - CW_USEDEFAULT, CW_USEDEFAULT, - NULL, NULL, inst, NULL); - - ShowWindow(wnd, nShowCmd); - UpdateWindow(wnd); - - nsCOMPtr eventLoop; - - if(NS_FAILED(nativeAppService->CreateEventLoop(L"_MainLoop", - nsEventLoopTypes::MainAppLoop, getter_AddRefs(eventLoop)))) - { - ErrorBox("Failed to create event Loop"); - return 0; - } - - eventLoop->Run(nsnull, nsnull, nsnull, &retCode); - eventLoop = nsnull; // Clear out before Shutting down XPCOM - - InfoBox("Hello World app is out of loop"); - } + RegisterClassEx(&wndclass) ; + + wnd = CreateWindow(lpszAppName, "The Hello World", + WS_OVERLAPPEDWINDOW, + CW_USEDEFAULT, CW_USEDEFAULT, + CW_USEDEFAULT, CW_USEDEFAULT, + NULL, NULL, inst, NULL); + + ShowWindow(wnd, nShowCmd); + UpdateWindow(wnd); + + nsCOMPtr eventLoop; + + if(NS_FAILED(nativeAppService->CreateEventLoop(L"_MainLoop", + nsEventLoopTypes::MainAppLoop, getter_AddRefs(eventLoop)))) + { + ErrorBox("Failed to create event Loop"); + return 0; + } + + eventLoop->Run(nsnull, nsnull, nsnull, &retCode); + eventLoop = nsnull; // Clear out before Shutting down XPCOM + + InfoBox("Hello World app is out of loop"); + } NS_ShutdownXPCOM(nsnull); InfoBox("Hello World app is exiting"); return retCode; diff --git a/mozilla/xpcom/tools/registry/regxpcom.cpp b/mozilla/xpcom/tools/registry/regxpcom.cpp index 2baf4d2988d..a839e85e8e1 100644 --- a/mozilla/xpcom/tools/registry/regxpcom.cpp +++ b/mozilla/xpcom/tools/registry/regxpcom.cpp @@ -45,6 +45,7 @@ #include "plstr.h" #include "prlink.h" #include "nsIComponentManager.h" +#include "nsIComponentRegistrar.h" #include "nsIServiceManager.h" #include "nsCOMPtr.h" #include "nsILocalFile.h" @@ -52,7 +53,7 @@ static PRBool gUnreg = PR_FALSE, gSilent = PR_FALSE, gQuiet = PR_FALSE; -nsresult Register(const char *path) +nsresult Register(nsIComponentRegistrar* registrar, const char *path) { nsCOMPtr spec; nsresult rv = nsComponentManager::CreateInstance(NS_LOCAL_FILE_CONTRACTID, @@ -68,11 +69,10 @@ nsresult Register(const char *path) rv = spec->InitWithPath(path); if (NS_FAILED(rv)) return rv; - rv = nsComponentManager::AutoRegisterComponent(nsIComponentManagerObsolete::NS_Startup, spec); - return rv; + return registrar->AutoRegister(spec); } -nsresult Unregister(const char *path) +nsresult Unregister(nsIComponentRegistrar *registrar, const char *path) { nsCOMPtr spec; nsresult rv = nsComponentManager::CreateInstance(NS_LOCAL_FILE_CONTRACTID, @@ -88,8 +88,7 @@ nsresult Unregister(const char *path) rv = spec->InitWithPath(path); if (NS_FAILED(rv)) return rv; - rv = nsComponentManager::AutoUnregisterComponent(nsIComponentManagerObsolete::NS_Startup, spec); - return rv; + return registrar->AutoUnregister(spec); } void ReportSuccess(const char *file) @@ -133,7 +132,7 @@ void ReportError(nsresult err, const char *file) fprintf(stderr, ") %s\n", file); } -int ProcessArgs(int argc, char *argv[]) +int ProcessArgs(nsIComponentRegistrar *registrar, int argc, char *argv[]) { int i = 1, result = 0; nsresult res; @@ -158,9 +157,9 @@ int ProcessArgs(int argc, char *argv[]) } } else { if (gUnreg == PR_TRUE) - res = Unregister(argv[i]); + res = Unregister(registrar, argv[i]); else - res = Register(argv[i]); + res = Register(registrar, argv[i]); if (NS_FAILED(res)) { ReportError(res, argv[i]); result = -1; @@ -183,18 +182,27 @@ int main(int argc, char *argv[]) #endif #endif - NS_InitXPCOM2(nsnull, nsnull, nsnull); - + nsCOMPtr servMan; + nsresult rv = NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + + if (NS_FAILED(rv)) { + printf("Can not initialize XPCOM\n"); + return -1; + } + + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + /* With no arguments, RegFactory will autoregister */ if (argc <= 1) { - nsresult rv = nsComponentManager::AutoRegister( - nsIComponentManagerObsolete::NS_Startup, - NULL /* default location */); - ret = (NS_FAILED(rv)) ? -1 : 0; + rv = registrar->AutoRegister(nsnull); + ret = (NS_FAILED(rv)) ? -1 : 0; } else - ret = ProcessArgs(argc, argv); + { + ret = ProcessArgs(registrar, argc, argv); + } NS_ShutdownXPCOM(NULL); return ret; diff --git a/mozilla/xpfe/appshell/src/nsCloseAllWindows.js b/mozilla/xpfe/appshell/src/nsCloseAllWindows.js index 502718a90e6..d92500a0413 100644 --- a/mozilla/xpfe/appshell/src/nsCloseAllWindows.js +++ b/mozilla/xpfe/appshell/src/nsCloseAllWindows.js @@ -92,15 +92,13 @@ var module = { this.firstTime = false; throw Components.results.NS_ERROR_FACTORY_REGISTER_AGAIN; } - compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentManagerObsolete); - compMgr.registerComponentWithType( this.cid, - "Close All Windows", - this.contractId, - fileSpec, - location, - true, - true, - type ); + compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar); + compMgr.registerFactoryLocation( this.cid, + "Close All Windows", + this.contractId, + fileSpec, + location, + type ); }, // getClassObject: Return this component's factory object. diff --git a/mozilla/xpfe/components/console/jsconsole-clhandler.js b/mozilla/xpfe/components/console/jsconsole-clhandler.js index 0c13211a3ed..a366def11cd 100644 --- a/mozilla/xpfe/components/console/jsconsole-clhandler.js +++ b/mozilla/xpfe/components/console/jsconsole-clhandler.js @@ -58,12 +58,14 @@ jsConsoleHandler.prototype = { /* jsConsoleHandler Module (for XPCOM registration) */ var jsConsoleHandlerModule = { registerSelf: function(compMgr, fileSpec, location, type) { - compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentManagerObsolete); + compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar); - compMgr.registerComponentWithType(JSCONSOLEHANDLER_CID, - 'JS Console Commandline Handler component', - JSCONSOLEHANDLER_CONTRACTID, fileSpec, - location, true, true, type); + compMgr.registerFactoryLocation(JSCONSOLEHANDLER_CID, + 'JS Console Commandline Handler component', + JSCONSOLEHANDLER_CONTRACTID, + fileSpec, + location, + type); var catman = Components.classes["@mozilla.org/categorymanager;1"] .getService(Components.interfaces.nsICategoryManager); catman.addCategoryEntry("command-line-argument-handlers", "jsconsole command line handler", @@ -72,8 +74,8 @@ var jsConsoleHandlerModule = { }, unregisterSelf: function(compMgr, fileSpec, location) { - compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentManagerObsolete); - compMgr.unregisterComponentSpec(JSCONSOLEHANDLER_CID, fileSpec); + compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar); + compMgr.unregisterFactoryLocation(JSCONSOLEHANDLER_CID, fileSpec); var catman = Components.classes["@mozilla.org/categorymanager;1"] .getService(Components.interfaces.nsICategoryManager); catman.deleteCategoryEntry("command-line-argument-handlers", diff --git a/mozilla/xpfe/components/filepicker/src/nsFilePicker.js b/mozilla/xpfe/components/filepicker/src/nsFilePicker.js index eab696dd5cf..95212721ebd 100644 --- a/mozilla/xpfe/components/filepicker/src/nsFilePicker.js +++ b/mozilla/xpfe/components/filepicker/src/nsFilePicker.js @@ -207,11 +207,14 @@ filePickerModule.registerSelf = function (compMgr, fileSpec, location, type) { debug("registering (all right -- a JavaScript module!)"); - compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentManagerObsolete); + compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar); - compMgr.registerComponentWithType(FILEPICKER_CID, "FilePicker JS Component", - FILEPICKER_CONTRACTID, fileSpec, location, - true, true, type); + compMgr.registerFactoryLocation(FILEPICKER_CID, + "FilePicker JS Component", + FILEPICKER_CONTRACTID, + fileSpec, + location, + type); } filePickerModule.getClassObject = diff --git a/mozilla/xpfe/components/filepicker/src/nsFilePicker.js.in b/mozilla/xpfe/components/filepicker/src/nsFilePicker.js.in index eab696dd5cf..95212721ebd 100644 --- a/mozilla/xpfe/components/filepicker/src/nsFilePicker.js.in +++ b/mozilla/xpfe/components/filepicker/src/nsFilePicker.js.in @@ -207,11 +207,14 @@ filePickerModule.registerSelf = function (compMgr, fileSpec, location, type) { debug("registering (all right -- a JavaScript module!)"); - compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentManagerObsolete); + compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar); - compMgr.registerComponentWithType(FILEPICKER_CID, "FilePicker JS Component", - FILEPICKER_CONTRACTID, fileSpec, location, - true, true, type); + compMgr.registerFactoryLocation(FILEPICKER_CID, + "FilePicker JS Component", + FILEPICKER_CONTRACTID, + fileSpec, + location, + type); } filePickerModule.getClassObject = diff --git a/mozilla/xpfe/components/sidebar/src/nsSidebar.js b/mozilla/xpfe/components/sidebar/src/nsSidebar.js index 620e5e49a7d..c26785ac98a 100644 --- a/mozilla/xpfe/components/sidebar/src/nsSidebar.js +++ b/mozilla/xpfe/components/sidebar/src/nsSidebar.js @@ -352,11 +352,14 @@ sidebarModule.registerSelf = function (compMgr, fileSpec, location, type) { debug("registering (all right -- a JavaScript module!)"); - compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentManagerObsolete); + compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar); - compMgr.registerComponentWithType(SIDEBAR_CID, "Sidebar JS Component", - SIDEBAR_CONTRACTID, fileSpec, location, - true, true, type); + compMgr.registerFactoryLocation(SIDEBAR_CID, + "Sidebar JS Component", + SIDEBAR_CONTRACTID, + fileSpec, + location, + type); } sidebarModule.getClassObject = diff --git a/mozilla/xpfe/components/startup/src/nsCloseAllWindows.js b/mozilla/xpfe/components/startup/src/nsCloseAllWindows.js index 502718a90e6..d92500a0413 100644 --- a/mozilla/xpfe/components/startup/src/nsCloseAllWindows.js +++ b/mozilla/xpfe/components/startup/src/nsCloseAllWindows.js @@ -92,15 +92,13 @@ var module = { this.firstTime = false; throw Components.results.NS_ERROR_FACTORY_REGISTER_AGAIN; } - compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentManagerObsolete); - compMgr.registerComponentWithType( this.cid, - "Close All Windows", - this.contractId, - fileSpec, - location, - true, - true, - type ); + compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar); + compMgr.registerFactoryLocation( this.cid, + "Close All Windows", + this.contractId, + fileSpec, + location, + type ); }, // getClassObject: Return this component's factory object. diff --git a/mozilla/xpinstall/src/nsSoftwareUpdate.cpp b/mozilla/xpinstall/src/nsSoftwareUpdate.cpp index 5d0ad5a36bc..2985be7a742 100644 --- a/mozilla/xpinstall/src/nsSoftwareUpdate.cpp +++ b/mozilla/xpinstall/src/nsSoftwareUpdate.cpp @@ -27,6 +27,7 @@ #include "nsIFactory.h" #include "nsISupports.h" #include "nsIComponentManager.h" +#include "nsIComponentRegistrar.h" #include "nsIServiceManager.h" #include "nsICategoryManager.h" #include "nsCOMPtr.h" @@ -437,7 +438,11 @@ nsSoftwareUpdate::StartupTasks( PRBool *needAutoreg ) // is not the actual BuildID, or if we couldn't get the BuildID if ( autoReg || NS_FAILED(rv) || buildID != NS_BUILD_ID ) { - rv = nsComponentManager::AutoRegister(nsIComponentManagerObsolete::NS_Startup,0); + nsCOMPtr servManager; + NS_GetServiceManager(getter_AddRefs(servManager)); + nsCOMPtr registrar = do_QueryInterface(servManager); + NS_ASSERTION(registrar, "No nsIComponentRegistrar from get service. see dougt"); + rv = registrar->AutoRegister(nsnull); if (NS_SUCCEEDED(rv)) { diff --git a/mozilla/xpinstall/standalone/standalone.cpp b/mozilla/xpinstall/standalone/standalone.cpp index 7ba336765d0..93068a5c7cd 100644 --- a/mozilla/xpinstall/standalone/standalone.cpp +++ b/mozilla/xpinstall/standalone/standalone.cpp @@ -97,10 +97,16 @@ main(int argc, char **argv) } - NS_InitXPCOM2(nsnull, nsnull, nsnull); - nsComponentManager::AutoRegister(nsIComponentManagerObsolete::NS_Startup, - nsnull /* default */); - + + nsCOMPtr servMan; + NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + nsCOMPtr registrar = do_QueryInterface(servMan); + if (!registrar) { + NS_ASSERTION(0, "Null nsIComponentRegistrar"); + return rv; + } + registrar->AutoRegister(nsnull); + nsresult rv = nsComponentManager::CreateInstance(kSoftwareUpdateCID, nsnull, diff --git a/mozilla/xpinstall/stub/xpistub.cpp b/mozilla/xpinstall/stub/xpistub.cpp index 6b97a60f014..7ea548fb7af 100644 --- a/mozilla/xpinstall/stub/xpistub.cpp +++ b/mozilla/xpinstall/stub/xpistub.cpp @@ -26,6 +26,7 @@ #include "xpistub.h" #include "nsIComponentManager.h" +#include "nsIComponentRegistrar.h" #include "nsIServiceManager.h" #include "nsCOMPtr.h" #include "nsSpecialSystemDirectory.h" @@ -148,12 +149,13 @@ PR_PUBLIC_API(nsresult) XPI_Init( if (NS_FAILED(rv)) return rv; + nsCOMPtr registrar = do_QueryInterface(gServiceMgr); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + #if defined(XP_UNIX) || defined(XP_MAC) - rv = nsComponentManager::AutoRegister(nsIComponentManagerObsolete::NS_Startup, - compDir); + rv = registrar->AutoRegister(compDir); #else - rv = nsComponentManager::AutoRegister(nsIComponentManagerObsolete::NS_Startup, - nsnull); + rv = registrar->AutoRegister(nsnull); #endif if (NS_FAILED(rv)) return rv;