Bug 568691 part A - register static and binary components using data tables rather than programmatic nsIComponentRegistrar methods. This part contains the important needs-review bits of the change: part B contains the mechanical changes to each module in order to actually get a working build. Part C will contain changes necessary to register JS components from .manifest files
authorBenjamin Smedberg <benjamin@smedbergs.us>
Thu, 10 Jun 2010 14:11:11 -0400
changeset 46997 1e41bf320ea0cd5fa6a03892b87d59278ee8754c
parent 46996 fe832b3737249f2a95948816594a5ccd19b962c8
child 46998 08410c390aa9dab36ece64f908d391b8bc9cfc6e
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs568691
milestone1.9.3a6pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 568691 part A - register static and binary components using data tables rather than programmatic nsIComponentRegistrar methods. This part contains the important needs-review bits of the change: part B contains the mechanical changes to each module in order to actually get a working build. Part C will contain changes necessary to register JS components from .manifest files
config/nsStaticComponents.h
content/base/src/nsContentUtils.cpp
content/html/content/public/nsHTMLMediaElement.h
content/html/content/src/nsHTMLMediaElement.cpp
dom/src/json/nsJSON.cpp
dom/src/json/nsJSON.h
dom/src/jsurl/nsJSProtocolHandler.cpp
dom/src/jsurl/nsJSProtocolHandler.h
dom/src/storage/nsDOMStorage.cpp
dom/src/storage/nsDOMStorage.h
dom/src/threads/nsDOMThreadService.cpp
ipc/glue/ScopedXREEmbed.cpp
js/src/xpconnect/idl/Makefile.in
js/src/xpconnect/idl/xpcIJSGetFactory.idl
js/src/xpconnect/loader/mozJSComponentLoader.cpp
js/src/xpconnect/loader/mozJSComponentLoader.h
js/src/xpconnect/loader/mozJSLoaderConstructors.h
js/src/xpconnect/shell/xpcshell.cpp
js/src/xpconnect/src/nsXPConnect.cpp
js/src/xpconnect/src/xpcexception.cpp
js/src/xpconnect/src/xpcjsid.cpp
js/src/xpconnect/src/xpcmodule.cpp
js/src/xpconnect/src/xpcmodule.h
js/src/xpconnect/src/xpcprivate.h
js/src/xpconnect/src/xpcvariant.cpp
js/src/xpconnect/tests/TestXPC.cpp
layout/build/nsContentDLF.cpp
layout/build/nsContentDLF.h
layout/build/nsLayoutModule.cpp
layout/build/nsLayoutStatics.cpp
layout/svg/base/src/nsSVGUtils.cpp
layout/tools/layout-debug/src/nsDebugFactory.cpp
toolkit/crashreporter/test/nsTestCrasher.cpp
toolkit/library/dlldeps-xul.cpp
toolkit/library/nsStaticXULComponents.cpp
toolkit/mozapps/extensions/amInstallTrigger.cpp
toolkit/system/windowsproxy/nsWindowsSystemProxySettings.cpp
toolkit/xre/nsAppRunner.cpp
toolkit/xre/nsEmbedFunctions.cpp
toolkit/xre/nsXREDirProvider.cpp
xpcom/base/nsAgg.h
xpcom/base/nsConsoleService.cpp
xpcom/base/nsDebugImpl.cpp
xpcom/base/nsDebugImpl.h
xpcom/base/nsErrorService.cpp
xpcom/base/nsErrorService.h
xpcom/base/nsMemoryImpl.h
xpcom/build/XPCOM.h
xpcom/build/XPCOMModule.inc
xpcom/build/dlldeps.cpp
xpcom/build/nsXPCOM.h
xpcom/build/nsXPCOMPrivate.h
xpcom/build/nsXPComInit.cpp
xpcom/build/nsXULAppAPI.h
xpcom/components/GenericFactory.cpp
xpcom/components/GenericFactory.h
xpcom/components/Makefile.in
xpcom/components/Module.h
xpcom/components/ModuleLoader.h
xpcom/components/ModuleUtils.h
xpcom/components/nsCategoryManager.cpp
xpcom/components/nsCategoryManager.h
xpcom/components/nsComponentManager.cpp
xpcom/components/nsComponentManager.h
xpcom/components/nsICategoryManager.idl
xpcom/components/nsIClassInfo.idl
xpcom/components/nsIComponentManagerObsolete.idl
xpcom/components/nsIComponentRegistrar.idl
xpcom/components/nsIModule.idl
xpcom/components/nsIServiceManager.idl
xpcom/components/nsIServiceManagerObsolete.h
xpcom/components/nsModule.h
xpcom/components/nsNativeComponentLoader.cpp
xpcom/components/nsNativeComponentLoader.h
xpcom/components/nsObsoleteModuleLoading.h
xpcom/components/nsServiceManagerObsolete.cpp
xpcom/components/nsStaticComponentLoader.cpp
xpcom/components/nsStaticComponentLoader.h
xpcom/ds/nsArray.cpp
xpcom/ds/nsArray.h
xpcom/ds/nsByteBuffer.cpp
xpcom/ds/nsByteBuffer.h
xpcom/ds/nsObserverService.cpp
xpcom/ds/nsObserverService.h
xpcom/ds/nsPersistentProperties.cpp
xpcom/ds/nsPersistentProperties.h
xpcom/ds/nsRecyclingAllocator.h
xpcom/ds/nsSupportsArray.cpp
xpcom/ds/nsSupportsArray.h
xpcom/ds/nsWindowsRegKey.cpp
xpcom/ds/nsWindowsRegKey.h
xpcom/glue/Makefile.in
xpcom/glue/nsClassInfoImpl.cpp
xpcom/glue/nsGenericFactory.cpp
xpcom/glue/nsGenericFactory.h
xpcom/glue/nsIClassInfoImpl.h
xpcom/glue/nsID.h
xpcom/glue/nsIGenericFactory.h
xpcom/glue/nsInterfaceHashtable.h
xpcom/glue/objs.mk
xpcom/glue/standalone/nsXPCOMGlue.cpp
xpcom/io/nsBinaryStream.cpp
xpcom/io/nsDirectoryService.cpp
xpcom/io/nsDirectoryService.h
xpcom/io/nsDirectoryServiceAtomList.h
xpcom/io/nsDirectoryServiceDefs.h
xpcom/io/nsFastLoadService.cpp
xpcom/io/nsFastLoadService.h
xpcom/io/nsLocalFileOSX.h
xpcom/io/nsLocalFileOSX.mm
xpcom/io/nsLocalFileUnix.h
xpcom/io/nsLocalFileWin.cpp
xpcom/io/nsLocalFileWin.h
xpcom/io/nsMultiplexInputStream.cpp
xpcom/io/nsMultiplexInputStream.h
xpcom/io/nsPipe.h
xpcom/io/nsPipe3.cpp
xpcom/io/nsScriptableInputStream.cpp
xpcom/io/nsScriptableInputStream.h
xpcom/io/nsStringStream.cpp
xpcom/proxy/src/nsProxyEventPrivate.h
xpcom/proxy/src/nsProxyObjectManager.cpp
xpcom/proxy/tests/proxy-create-threadsafety.cpp
xpcom/proxy/tests/proxytests.cpp
xpcom/reflect/xptinfo/src/Makefile.in
xpcom/reflect/xptinfo/src/xptiInterfaceInfoManager.cpp
xpcom/reflect/xptinfo/src/xptiMisc.cpp
xpcom/reflect/xptinfo/src/xptiprivate.h
xpcom/sample/nsSample.cpp
xpcom/sample/nsSampleModule.cpp
xpcom/sample/program/nsTestSample.cpp
xpcom/stub/nsXPComStub.cpp
xpcom/tests/Makefile.in
xpcom/tests/TestFactory.cpp
xpcom/tests/TestFactory.h
xpcom/tests/TestRacingServiceManager.cpp
xpcom/tests/TestRegistrationOrder.cpp
xpcom/tests/TestServMgr.cpp
xpcom/tests/dynamic/Makefile.in
xpcom/tests/dynamic/TestDynamic.cpp
xpcom/tests/nsIFileEnumerator.cpp
xpcom/tests/services/Makefile.in
xpcom/tests/services/MyService.cpp
xpcom/tests/services/MyService.h
xpcom/threads/nsEnvironment.cpp
xpcom/threads/nsEnvironment.h
xpcom/threads/nsThreadManager.cpp
xpcom/threads/nsThreadPool.cpp
xpfe/appshell/src/nsAppShellFactory.cpp
xpfe/appshell/src/nsChromeTreeOwner.cpp
xpfe/appshell/src/nsContentTreeOwner.cpp
xpfe/components/build/nsModule.cpp
xpfe/components/windowds/nsWindowDataSource.cpp
--- a/config/nsStaticComponents.h
+++ b/config/nsStaticComponents.h
@@ -33,15 +33,16 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef nsStaticComponents_h__
 #define nsStaticComponents_h__
 
+#include "mozilla/Module.h"
+
 // These symbols are provided by nsStaticComponents.cpp, and also by other
 // static component providers such as nsStaticXULComponents (libxul).
 
-extern nsStaticModuleInfo const *const kPStaticModules;
-extern PRUint32 const kStaticModuleCount;
+extern mozilla::Module const *const *const kPStaticModules;
 
 #endif
--- a/content/base/src/nsContentUtils.cpp
+++ b/content/base/src/nsContentUtils.cpp
@@ -201,16 +201,17 @@ static NS_DEFINE_CID(kXTFServiceCID, NS_
 #include "jsregexp.h"
 #include "jstypedarray.h"
 #include "xpcprivate.h"
 #include "nsScriptSecurityManager.h"
 #include "nsIChannelPolicy.h"
 #include "nsChannelPolicy.h"
 #include "nsIContentSecurityPolicy.h"
 #include "nsContentDLF.h"
+#include "nsHTMLMediaElement.h"
 
 using namespace mozilla::dom;
 
 const char kLoadAsData[] = "loadAsData";
 
 static const char kJSStackContractID[] = "@mozilla.org/js/xpc/ContextStack;1";
 static NS_DEFINE_CID(kParserServiceCID, NS_PARSERSERVICE_CID);
 static NS_DEFINE_CID(kCParserCID, NS_PARSER_CID);
@@ -6079,16 +6080,29 @@ nsIContentUtils::FindInternalContentView
   if (NS_SUCCEEDED(rv)) {
     docFactory = do_GetService(contractID);
     if (docFactory && aLoaderType) {
       *aLoaderType = contractID.EqualsLiteral(CONTENT_DLF_CONTRACTID) ? TYPE_CONTENT : TYPE_UNKNOWN;
     }   
     return docFactory.forget();
   }
 
+  if (nsHTMLMediaElement::IsOggEnabled()) {
+    for (int i = 0; i < NS_ARRAY_LENGTH(nsHTMLMediaElement::gOggTypes); ++i) {
+      const char* type = nsHTMLMediaElement::gOggTypes[i];
+      if (!strcmp(aType, type)) {
+        docFactory = do_GetService("@mozilla.org/content/document-loader-factory;1");
+        if (docFactory && aLoaderType) {
+          *aLoaderType = TYPE_CONTENT;
+        }
+        return docFactory.forget();
+      }
+    }
+  }
+
   if (AVAILABLE == pluginEnabled) {
     docFactory = do_GetService(PLUGIN_DLF_CONTRACTID);
     if (docFactory && aLoaderType) {
       *aLoaderType = TYPE_PLUGIN;
     }
     return docFactory.forget();
   }
 
--- a/content/html/content/public/nsHTMLMediaElement.h
+++ b/content/html/content/public/nsHTMLMediaElement.h
@@ -233,36 +233,42 @@ public:
   void UpdateMediaSize(nsIntSize size);
 
   // Returns the CanPlayStatus indicating if we can handle this
   // MIME type. The MIME type should not include the codecs parameter.
   // If it returns anything other than CANPLAY_NO then it also
   // returns a null-terminated list of supported codecs
   // in *aSupportedCodecs. This list should not be freed, it is static data.
   static CanPlayStatus CanHandleMediaType(const char* aMIMEType,
-                                          const char*** aSupportedCodecs);
+                                          char const *const ** aSupportedCodecs);
 
   // Returns the CanPlayStatus indicating if we can handle the
   // full MIME type including the optional codecs parameter.
   static CanPlayStatus GetCanPlay(const nsAString& aType);
 
   // Returns true if we should handle this MIME type when it appears
   // as an <object> or as a toplevel page. If, in practice, our support
   // for the type is more limited than appears in the wild, we should return
   // false here even if CanHandleMediaType would return true.
   static PRBool ShouldHandleMediaType(const char* aMIMEType);
 
-  /**
-   * Initialize data for available media types
-   */
-  static void InitMediaTypes();
-  /**
-   * Shutdown data for available media types
-   */
-  static void ShutdownMediaTypes();
+  static bool IsOggEnabled();
+  static bool IsOggType(const nsACString& aType);
+  static const char gOggTypes[3][16];
+  static char const *const gOggCodecs[3];
+
+  static bool IsWaveEnabled();
+  static bool IsWaveType(const nsACString& aType);
+  static const char gWaveTypes[4][16];
+  static char const *const gWaveCodecs[2];
+
+  static bool IsWebMEnabled();
+  static bool IsWebMType(const nsACString& aType);
+  static const char gWebMTypes[2][17];
+  static char const *const gWebMCodecs[4];
 
   /**
    * Called when a child source element is added to this media element. This
    * may queue a load() task if appropriate.
    */
   void NotifyAddedSource();
 
   /**
--- a/content/html/content/src/nsHTMLMediaElement.cpp
+++ b/content/html/content/src/nsHTMLMediaElement.cpp
@@ -1183,112 +1183,118 @@ void nsHTMLMediaElement::UnbindFromTree(
   if (!mPaused && mNetworkState != nsIDOMHTMLMediaElement::NETWORK_EMPTY)
     Pause();
   nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent);
 }
 
 #ifdef MOZ_OGG
 // See http://www.rfc-editor.org/rfc/rfc5334.txt for the definitions
 // of Ogg media types and codec types
-static const char gOggTypes[][16] = {
+const char nsHTMLMediaElement::gOggTypes[3][16] = {
   "video/ogg",
   "audio/ogg",
   "application/ogg"
 };
 
-static const char* gOggCodecs[] = {
+char const *const nsHTMLMediaElement::gOggCodecs[3] = {
   "vorbis",
   "theora",
   nsnull
 };
 
-static PRBool IsOggEnabled()
+bool
+nsHTMLMediaElement::IsOggEnabled()
 {
   return nsContentUtils::GetBoolPref("media.ogg.enabled");
 }
 
-static PRBool IsOggType(const nsACString& aType)
+bool
+nsHTMLMediaElement::IsOggType(const nsACString& aType)
 {
   if (!IsOggEnabled())
     return PR_FALSE;
   for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(gOggTypes); ++i) {
     if (aType.EqualsASCII(gOggTypes[i]))
       return PR_TRUE;
   }
   return PR_FALSE;
 }
 #endif
 
 #ifdef MOZ_WAVE
 // See http://www.rfc-editor.org/rfc/rfc2361.txt for the definitions
 // of WAVE media types and codec types. However, the audio/vnd.wave
 // MIME type described there is not used.
-static const char gWaveTypes[][16] = {
+const char nsHTMLMediaElement::gWaveTypes[4][16] = {
   "audio/x-wav",
   "audio/wav",
   "audio/wave",
   "audio/x-pn-wav"
 };
 
-static const char* gWaveCodecs[] = {
+char const *const nsHTMLMediaElement::gWaveCodecs[2] = {
   "1", // Microsoft PCM Format
   nsnull
 };
 
-static PRBool IsWaveEnabled()
+bool
+nsHTMLMediaElement::IsWaveEnabled()
 {
   return nsContentUtils::GetBoolPref("media.wave.enabled");
 }
 
-static PRBool IsWaveType(const nsACString& aType)
+bool
+nsHTMLMediaElement::IsWaveType(const nsACString& aType)
 {
   if (!IsWaveEnabled())
     return PR_FALSE;
   for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(gWaveTypes); ++i) {
     if (aType.EqualsASCII(gWaveTypes[i]))
       return PR_TRUE;
   }
   return PR_FALSE;
 }
 #endif
 
 #ifdef MOZ_WEBM
-static const char gWebMTypes[][17] = {
+const char nsHTMLMediaElement::gWebMTypes[2][17] = {
   "video/webm",
   "audio/webm"
 };
 
-static const char* gWebMCodecs[] = {
+char const *const nsHTMLMediaElement::gWebMCodecs[4] = {
   "vp8",
   "vp8.0",
   "vorbis",
   nsnull
 };
 
-static PRBool IsWebMEnabled()
+bool
+nsHTMLMediaElement::IsWebMEnabled()
 {
   return nsContentUtils::GetBoolPref("media.webm.enabled");
 }
 
-static PRBool IsWebMType(const nsACString& aType)
+bool
+nsHTMLMediaElement::IsWebMType(const nsACString& aType)
 {
   if (!IsWebMEnabled())
     return PR_FALSE;
   for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(gWebMTypes); ++i) {
     if (aType.EqualsASCII(gWebMTypes[i]))
       return PR_TRUE;
   }
   return PR_FALSE;
 }
 #endif
 
 /* static */
 nsHTMLMediaElement::CanPlayStatus 
 nsHTMLMediaElement::CanHandleMediaType(const char* aMIMEType,
-                                       const char*** aCodecList)
+                                       char const *const ** aCodecList)
 {
 #ifdef MOZ_OGG
   if (IsOggType(nsDependentCString(aMIMEType))) {
     *aCodecList = gOggCodecs;
     return CANPLAY_MAYBE;
   }
 #endif
 #ifdef MOZ_WAVE
@@ -1321,17 +1327,17 @@ PRBool nsHTMLMediaElement::ShouldHandleM
   // Wave codecs actually in use in the wild that we don't support, and
   // we should allow those to be handled by plugins or helper apps.
   // Furthermore people can play Wave files on most platforms by other
   // means.
   return PR_FALSE;
 }
 
 static PRBool
-CodecListContains(const char** aCodecs, const nsAString& aCodec)
+CodecListContains(char const *const * aCodecs, const nsAString& aCodec)
 {
   for (PRInt32 i = 0; aCodecs[i]; ++i) {
     if (aCodec.EqualsASCII(aCodecs[i]))
       return PR_TRUE;
   }
   return PR_FALSE;
 }
 
@@ -1341,17 +1347,17 @@ nsHTMLMediaElement::GetCanPlay(const nsA
 {
   nsContentTypeParser parser(aType);
   nsAutoString mimeType;
   nsresult rv = parser.GetType(mimeType);
   if (NS_FAILED(rv))
     return CANPLAY_NO;
 
   NS_ConvertUTF16toUTF8 mimeTypeUTF8(mimeType);
-  const char** supportedCodecs;
+  char const *const * supportedCodecs;
   CanPlayStatus status = CanHandleMediaType(mimeTypeUTF8.get(),
                                             &supportedCodecs);
   if (status == CANPLAY_NO)
     return CANPLAY_NO;
 
   nsAutoString codecs;
   rv = parser.GetParameter("codecs", codecs);
   if (NS_FAILED(rv)) {
@@ -1387,67 +1393,16 @@ nsHTMLMediaElement::CanPlayType(const ns
   case CANPLAY_NO: aResult.AssignLiteral(""); break;
   case CANPLAY_YES: aResult.AssignLiteral("probably"); break;
   default:
   case CANPLAY_MAYBE: aResult.AssignLiteral("maybe"); break;
   }
   return NS_OK;
 }
 
-/* static */
-void nsHTMLMediaElement::InitMediaTypes()
-{
-  nsresult rv;
-  nsCOMPtr<nsICategoryManager> catMan(do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv));
-  if (NS_SUCCEEDED(rv)) {
-#ifdef MOZ_OGG
-    if (IsOggEnabled()) {
-      for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(gOggTypes); i++) {
-        catMan->AddCategoryEntry("Gecko-Content-Viewers", gOggTypes[i],
-                                 "@mozilla.org/content/document-loader-factory;1",
-                                 PR_FALSE, PR_TRUE, nsnull);
-      }
-    }
-#endif
-#ifdef MOZ_WEBM
-    if (IsWebMEnabled()) {
-      for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(gWebMTypes); i++) {
-        catMan->AddCategoryEntry("Gecko-Content-Viewers", gWebMTypes[i],
-                                 "@mozilla.org/content/document-loader-factory;1",
-                                 PR_FALSE, PR_TRUE, nsnull);
-      }
-    }
-#endif
-  }
-}
-
-/* static */
-void nsHTMLMediaElement::ShutdownMediaTypes()
-{
-  nsresult rv;
-  nsCOMPtr<nsICategoryManager> catMan(do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv));
-  if (NS_SUCCEEDED(rv)) {
-#ifdef MOZ_OGG
-    for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(gOggTypes); i++) {
-      catMan->DeleteCategoryEntry("Gecko-Content-Viewers", gOggTypes[i], PR_FALSE);
-    }
-#endif
-#ifdef MOZ_WAVE
-    for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(gWaveTypes); i++) {
-      catMan->DeleteCategoryEntry("Gecko-Content-Viewers", gWaveTypes[i], PR_FALSE);
-    }
-#endif
-#ifdef MOZ_WEBM
-    for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(gWebMTypes); i++) {
-      catMan->DeleteCategoryEntry("Gecko-Content-Viewers", gWebMTypes[i], PR_FALSE);
-    }
-#endif
-  }
-}
-
 already_AddRefed<nsMediaDecoder>
 nsHTMLMediaElement::CreateDecoder(const nsACString& aType)
 {
 #ifdef MOZ_OGG
   if (IsOggType(aType)) {
     nsRefPtr<nsOggDecoder> decoder = new nsOggDecoder();
     if (decoder && decoder->Init(this)) {
       return decoder.forget().get();
--- a/dom/src/json/nsJSON.cpp
+++ b/dom/src/json/nsJSON.cpp
@@ -509,17 +509,17 @@ nsJSON::DecodeInternal(nsIInputStream *a
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = cc->SetReturnValueWasSet(PR_TRUE);
   NS_ENSURE_SUCCESS(rv, rv);
 
   return NS_OK;
 }
 
-NS_IMETHODIMP
+nsresult
 NS_NewJSON(nsISupports* aOuter, REFNSIID aIID, void** aResult)
 {
   nsJSON* json = new nsJSON();
   if (!json)
     return NS_ERROR_OUT_OF_MEMORY;
 
   NS_ADDREF(json);
   *aResult = json;
--- a/dom/src/json/nsJSON.h
+++ b/dom/src/json/nsJSON.h
@@ -87,17 +87,17 @@ public:
 protected:
   nsresult EncodeInternal(nsJSONWriter *writer);
   nsresult DecodeInternal(nsIInputStream *aStream,
                           PRInt32 aContentLength,
                           PRBool aNeedsConverter);
   nsCOMPtr<nsIURI> mURI;
 };
 
-NS_IMETHODIMP
+nsresult
 NS_NewJSON(nsISupports* aOuter, REFNSIID aIID, void** aResult);
 
 class nsJSONListener : public nsIStreamListener
 {
 public:
   nsJSONListener(JSContext *cx, jsval *rootVal, PRBool needsConverter);
   virtual ~nsJSONListener();
 
--- a/dom/src/jsurl/nsJSProtocolHandler.cpp
+++ b/dom/src/jsurl/nsJSProtocolHandler.cpp
@@ -43,17 +43,16 @@
 #include "nsDOMError.h"
 #include "nsXPIDLString.h"
 #include "nsReadableUtils.h"
 #include "nsJSProtocolHandler.h"
 #include "nsStringStream.h"
 #include "nsNetUtil.h"
 
 #include "nsIComponentManager.h"
-#include "nsIGenericFactory.h"
 #include "nsIServiceManager.h"
 #include "nsIURI.h"
 #include "nsIScriptContext.h"
 #include "nsIScriptGlobalObject.h"
 #include "nsIScriptGlobalObjectOwner.h"
 #include "nsIPrincipal.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsIInterfaceRequestor.h"
@@ -1123,17 +1122,17 @@ nsJSProtocolHandler::Init()
 }
 
 nsJSProtocolHandler::~nsJSProtocolHandler()
 {
 }
 
 NS_IMPL_ISUPPORTS1(nsJSProtocolHandler, nsIProtocolHandler)
 
-NS_METHOD
+nsresult
 nsJSProtocolHandler::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
 {
     if (aOuter)
         return NS_ERROR_NO_AGGREGATION;
 
     nsJSProtocolHandler* ph = new nsJSProtocolHandler();
     if (!ph)
         return NS_ERROR_OUT_OF_MEMORY;
--- a/dom/src/jsurl/nsJSProtocolHandler.h
+++ b/dom/src/jsurl/nsJSProtocolHandler.h
@@ -72,17 +72,17 @@ public:
 
     // nsIProtocolHandler methods:
     NS_DECL_NSIPROTOCOLHANDLER
 
     // nsJSProtocolHandler methods:
     nsJSProtocolHandler();
     virtual ~nsJSProtocolHandler();
 
-    static NS_METHOD
+    static nsresult
     Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
 
     nsresult Init();
 
 protected:
 
     nsresult EnsureUTF8Spec(const nsAFlatCString &aSpec, const char *aCharset, 
                             nsACString &aUTF8Spec);
--- a/dom/src/storage/nsDOMStorage.cpp
+++ b/dom/src/storage/nsDOMStorage.cpp
@@ -525,27 +525,27 @@ NS_IMPL_CYCLE_COLLECTING_ADDREF_AMBIGUOU
 NS_IMPL_CYCLE_COLLECTING_RELEASE_AMBIGUOUS(nsDOMStorage, nsIDOMStorageObsolete)
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDOMStorage)
   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMStorageObsolete)
   NS_INTERFACE_MAP_ENTRY(nsIDOMStorageObsolete)
   NS_INTERFACE_MAP_ENTRY(nsPIDOMStorage)
   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(StorageObsolete)
 NS_INTERFACE_MAP_END
 
-NS_IMETHODIMP
+nsresult
 NS_NewDOMStorage(nsISupports* aOuter, REFNSIID aIID, void** aResult)
 {
   nsDOMStorage* storage = new nsDOMStorage();
   if (!storage)
     return NS_ERROR_OUT_OF_MEMORY;
 
   return storage->QueryInterface(aIID, aResult);
 }
 
-NS_IMETHODIMP
+nsresult
 NS_NewDOMStorage2(nsISupports* aOuter, REFNSIID aIID, void** aResult)
 {
   nsDOMStorage2* storage = new nsDOMStorage2();
   if (!storage)
     return NS_ERROR_OUT_OF_MEMORY;
 
   return storage->QueryInterface(aIID, aResult);
 }
--- a/dom/src/storage/nsDOMStorage.h
+++ b/dom/src/storage/nsDOMStorage.h
@@ -486,20 +486,20 @@ public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIDOMSTORAGEEVENTOBSOLETE
   NS_FORWARD_NSIDOMEVENT(nsDOMEvent::)
 
 protected:
   nsString mDomain;
 };
 
-NS_IMETHODIMP
+nsresult
 NS_NewDOMStorage(nsISupports* aOuter, REFNSIID aIID, void** aResult);
 
-NS_IMETHODIMP
+nsresult
 NS_NewDOMStorage2(nsISupports* aOuter, REFNSIID aIID, void** aResult);
 
 nsresult
 NS_NewDOMStorageList(nsIDOMStorageList** aResult);
 
 PRUint32
 GetOfflinePermission(const nsACString &aDomain);
 
--- a/dom/src/threads/nsDOMThreadService.cpp
+++ b/dom/src/threads/nsDOMThreadService.cpp
@@ -44,17 +44,16 @@
 // Interfaces
 #include "nsIComponentManager.h"
 #include "nsIConsoleService.h"
 #include "nsIDocument.h"
 #include "nsIDOMDocument.h"
 #include "nsIDOMNavigator.h"
 #include "nsIDOMWindowInternal.h"
 #include "nsIEventTarget.h"
-#include "nsIGenericFactory.h"
 #include "nsIJSContextStack.h"
 #include "nsIJSRuntimeService.h"
 #include "nsIObserverService.h"
 #include "nsIScriptError.h"
 #include "nsIScriptGlobalObject.h"
 #include "nsIServiceManager.h"
 #include "nsISupportsPriority.h"
 #include "nsIThreadPool.h"
--- a/ipc/glue/ScopedXREEmbed.cpp
+++ b/ipc/glue/ScopedXREEmbed.cpp
@@ -81,17 +81,17 @@ ScopedXREEmbed::Start()
   nsCOMPtr<nsIFile> parent;
   rv = localFile->GetParent(getter_AddRefs(parent));
   if (NS_FAILED(rv))
     return;
 
   localFile = do_QueryInterface(parent);
   NS_ENSURE_TRUE(localFile,);
 
-  rv = XRE_InitEmbedding(localFile, localFile, nsnull, nsnull, 0);
+  rv = XRE_InitEmbedding2(localFile, localFile, nsnull);
   if (NS_FAILED(rv))
     return;
 
   mShouldKillEmbedding = true;
 }
 
 void
 ScopedXREEmbed::Stop()
--- a/js/src/xpconnect/idl/Makefile.in
+++ b/js/src/xpconnect/idl/Makefile.in
@@ -60,16 +60,17 @@ XPIDLSRCS	= \
 		nsIXPConnect.idl \
 		nsIXPCSecurityManager.idl \
 		nsIXPCScriptable.idl \
 		nsIScriptError.idl \
 		nsIXPCScriptNotify.idl \
 		nsIScriptableInterfaces.idl \
 		XPCIDispatch.idl \
 		xpcIJSWeakReference.idl \
+		xpcIJSGetFactory.idl \
 		$(NULL)
 
 ifdef XPC_IDISPATCH_SUPPORT
 XPIDLSRCS	+= \
 		nsIDispatchSupport.idl \
 		nsIActiveXSecurityPolicy.idl \
 		$(NULL)
 endif
new file mode 100644
--- /dev/null
+++ b/js/src/xpconnect/idl/xpcIJSGetFactory.idl
@@ -0,0 +1,50 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla 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/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Mozilla Firefox.
+ *
+ * The Initial Developer of the Original Code is
+ * the Mozilla Foundation <http://www.mozilla.org>.
+ * Portions created by the Initial Developer are Copyright (C) 2010
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * 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 MPL, 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 MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#include "nsISupports.idl"
+
+interface nsIFactory;
+
+/**
+ * Every JS module exports a single NSGetFactory symbol which is converted into this
+ * functional interface type.
+ */
+[scriptable, function, uuid(3FE0C205-D75B-4CAC-9347-D2B855050143)]
+interface xpcIJSGetFactory : nsISupports
+{
+  nsIFactory get(in nsCIDRef aCID);
+};
--- a/js/src/xpconnect/loader/mozJSComponentLoader.cpp
+++ b/js/src/xpconnect/loader/mozJSComponentLoader.cpp
@@ -48,20 +48,18 @@
 #include <stdarg.h>
 
 #include "prlog.h"
 
 #include "nsCOMPtr.h"
 #include "nsAutoPtr.h"
 #include "nsICategoryManager.h"
 #include "nsIComponentManager.h"
-#include "nsIComponentManagerObsolete.h"
-#include "nsIGenericFactory.h"
+#include "mozilla/Module.h"
 #include "nsILocalFile.h"
-#include "nsIModule.h"
 #include "nsIServiceManager.h"
 #include "nsISupports.h"
 #include "mozJSComponentLoader.h"
 #include "nsIJSRuntimeService.h"
 #include "nsIJSContextStack.h"
 #include "nsIXPConnect.h"
 #include "nsCRT.h"
 #include "nsMemory.h"
@@ -569,17 +567,17 @@ mozJSComponentLoader::~mozJSComponentLoa
 
     sSelf = nsnull;
 }
 
 mozJSComponentLoader*
 mozJSComponentLoader::sSelf;
 
 NS_IMPL_ISUPPORTS3(mozJSComponentLoader,
-                   nsIModuleLoader,
+                   mozilla::ModuleLoader,
                    xpcIJSModuleLoader,
                    nsIObserver)
  
 nsresult
 mozJSComponentLoader::ReallyInit()
 {
     NS_TIME_FUNCTION;
 
@@ -655,173 +653,154 @@ mozJSComponentLoader::ReallyInit()
 #ifdef DEBUG_shaver_off
     fprintf(stderr, "mJCL: ReallyInit success!\n");
 #endif
     mInitialized = PR_TRUE;
 
     return NS_OK;
 }
 
-NS_IMETHODIMP
-mozJSComponentLoader::LoadModule(nsILocalFile* aComponentFile,
-                                 nsIModule* *aResult)
+const mozilla::Module*
+mozJSComponentLoader::LoadModule(nsILocalFile* aComponentFile)
 {
     nsresult rv;
 
 #ifdef NS_FUNCTION_TIMER
     nsAutoString path__(NS_LITERAL_STRING("N/A"));
     aComponentFile->GetPath(path__);
     NS_TIME_FUNCTION_FMT("%s (line %d) (file: %s)", MOZ_FUNCTION_NAME,
                          __LINE__, nsPromiseFlatCString(NS_LossyConvertUTF16toASCII(path__)).BeginReading());
 #endif
 
     nsCAutoString leafName;
     aComponentFile->GetNativeLeafName(leafName);
     if (!StringTail(leafName, 3).LowerCaseEqualsLiteral(".js"))
-        return NS_ERROR_INVALID_ARG;
+        return NULL;
 
     if (!mInitialized) {
         rv = ReallyInit();
         if (NS_FAILED(rv))
-            return rv;
+            return NULL;
     }
 
     nsCOMPtr<nsIHashable> lfhash(do_QueryInterface(aComponentFile));
     if (!lfhash) {
         NS_ERROR("nsLocalFile not implementing nsIHashable");
-        return NS_NOINTERFACE;
+        return NULL;
     }
 
     ModuleEntry* mod;
-    if (mModules.Get(lfhash, &mod)) {
-        NS_ASSERTION(mod->module, "Bad hashtable data!");
-        NS_ADDREF(*aResult = mod->module);
-        return NS_OK;
-    }
+    if (mModules.Get(lfhash, &mod))
+        return mod;
 
     nsAutoPtr<ModuleEntry> entry(new ModuleEntry);
     if (!entry)
-        return NS_ERROR_OUT_OF_MEMORY;
+        return NULL;
 
     rv = GlobalForLocation(aComponentFile, &entry->global, &entry->location,
                            nsnull);
     if (NS_FAILED(rv)) {
 #ifdef DEBUG_shaver
         fprintf(stderr, "GlobalForLocation failed!\n");
 #endif
-        return rv;
+        return NULL;
     }
 
     nsCOMPtr<nsIXPConnect> xpc = do_GetService(kXPConnectServiceContractID,
                                                &rv);
     if (NS_FAILED(rv))
-        return rv;
+        return NULL;
 
     nsCOMPtr<nsIComponentManager> cm;
     rv = NS_GetComponentManager(getter_AddRefs(cm));
     if (NS_FAILED(rv))
-        return rv;
+        return NULL;
 
     JSCLContextHelper cx(this);
 
     JSObject* cm_jsobj;
     nsCOMPtr<nsIXPConnectJSObjectHolder> cm_holder;
     rv = xpc->WrapNative(cx, entry->global, cm, 
                          NS_GET_IID(nsIComponentManager),
                          getter_AddRefs(cm_holder));
 
     if (NS_FAILED(rv)) {
 #ifdef DEBUG_shaver
         fprintf(stderr, "WrapNative(%p,%p,nsIComponentManager) failed: %x\n",
                 (void *)(JSContext*)cx, (void *)mCompMgr, rv);
 #endif
-        return rv;
+        return NULL;
     }
 
     rv = cm_holder->GetJSObject(&cm_jsobj);
     if (NS_FAILED(rv)) {
 #ifdef DEBUG_shaver
         fprintf(stderr, "GetJSObject of ComponentManager failed\n");
 #endif
-        return rv;
+        return NULL;
     }
 
     JSObject* file_jsobj;
     nsCOMPtr<nsIXPConnectJSObjectHolder> file_holder;
     rv = xpc->WrapNative(cx, entry->global, aComponentFile, 
                          NS_GET_IID(nsIFile),
                          getter_AddRefs(file_holder));
 
     if (NS_FAILED(rv)) {
-        return rv;
+        return NULL;
     }
 
     rv = file_holder->GetJSObject(&file_jsobj);
     if (NS_FAILED(rv)) {
-        return rv;
+        return NULL;
     }
 
     JSCLAutoErrorReporterSetter aers(cx, mozJSLoaderErrorReporter);
 
-    jsval argv[2], retval, NSGetModule_val;
+    jsval argv[2], retval, NSGetFactory_val;
 
-    if (!JS_GetProperty(cx, entry->global, "NSGetModule", &NSGetModule_val) ||
-        JSVAL_IS_VOID(NSGetModule_val)) {
-        return NS_ERROR_FAILURE;
+    if (!JS_GetProperty(cx, entry->global, "NSGetFactory", &NSGetFactory_val) ||
+        JSVAL_IS_VOID(NSGetFactory_val)) {
+        return NULL;
     }
 
-    if (JS_TypeOfValue(cx, NSGetModule_val) != JSTYPE_FUNCTION) {
+    if (JS_TypeOfValue(cx, NSGetFactory_val) != JSTYPE_FUNCTION) {
         nsCAutoString path;
         aComponentFile->GetNativePath(path);
 
-        JS_ReportError(cx, "%s has NSGetModule property that is not a function",
+        JS_ReportError(cx, "%s has NSGetFactory property that is not a function",
                        path.get());
-        return NS_ERROR_FAILURE;
+        return NULL;
     }
     
-    argv[0] = OBJECT_TO_JSVAL(cm_jsobj);
-    argv[1] = OBJECT_TO_JSVAL(file_jsobj);
-    if (!JS_CallFunctionValue(cx, entry->global, NSGetModule_val,
-                              2, argv, &retval)) {
-        return NS_ERROR_FAILURE;
+    JSObject *jsGetFactoryObj;
+    if (!JS_ValueToObject(cx, retval, &jsGetFactoryObj) ||
+        !jsGetFactoryObj) {
+        /* XXX report error properly */
+        return NULL;
     }
 
-#ifdef DEBUG_shaver_off
-    JSString *s = JS_ValueToString(cx, retval);
-    fprintf(stderr, "mJCL: %s::NSGetModule returned %s\n",
-            registryLocation, JS_GetStringBytes(s));
-#endif
-
-    JSObject *jsModuleObj;
-    if (!JS_ValueToObject(cx, retval, &jsModuleObj) ||
-        !jsModuleObj) {
-        /* XXX report error properly */
-        return NS_ERROR_FAILURE;
-    }
-
-    rv = xpc->WrapJS(cx, jsModuleObj,
-                     NS_GET_IID(nsIModule), getter_AddRefs(entry->module));
+    rv = xpc->WrapJS(cx, jsGetFactoryObj,
+                     NS_GET_IID(xpcIJSGetFactory), getter_AddRefs(entry->getfactory));
     if (NS_FAILED(rv)) {
         /* XXX report error properly */
 #ifdef DEBUG
         fprintf(stderr, "mJCL: couldn't get nsIModule from jsval\n");
 #endif
-        return rv;
+        return NULL;
     }
 
     // Cache this module for later
     if (!mModules.Put(lfhash, entry))
-        return NS_ERROR_OUT_OF_MEMORY;
-
-    NS_ADDREF(*aResult = entry->module);
+        return NULL;
 
     // The hash owns the ModuleEntry now, forget about it
     entry.forget();
 
-    return NS_OK;
+    return entry;
 }
 
 // Some stack based classes for cleaning up on early return
 #ifdef HAVE_PR_MEMMAP
 class FileAutoCloser
 {
  public:
     explicit FileAutoCloser(PRFileDesc *file) : mFile(file) {}
--- a/js/src/xpconnect/loader/mozJSComponentLoader.h
+++ b/js/src/xpconnect/loader/mozJSComponentLoader.h
@@ -34,43 +34,42 @@
  * 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 MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "plhash.h"
 #include "jsapi.h"
-#include "nsIModuleLoader.h"
+#include "mozilla/ModuleLoader.h"
 #include "nsIJSRuntimeService.h"
 #include "nsIJSContextStack.h"
 #include "nsISupports.h"
 #include "nsIXPConnect.h"
-#include "nsIModule.h"
 #include "nsIFile.h"
 #include "nsAutoPtr.h"
 #include "nsIFastLoadService.h"
 #include "nsIObjectInputStream.h"
 #include "nsIObjectOutputStream.h"
 #include "nsITimer.h"
 #include "nsIObserver.h"
 #include "xpcIJSModuleLoader.h"
 #include "nsClassHashtable.h"
 #include "nsDataHashtable.h"
 #ifndef XPCONNECT_STANDALONE
 #include "nsIPrincipal.h"
 #endif
+#include "xpcIJSGetFactory.h"
 
 /* 6bd13476-1dd2-11b2-bbef-f0ccb5fa64b6 (thanks, mozbot) */
 
 #define MOZJSCOMPONENTLOADER_CID \
   {0x6bd13476, 0x1dd2, 0x11b2, \
     { 0xbb, 0xef, 0xf0, 0xcc, 0xb5, 0xfa, 0x64, 0xb6 }}
 #define MOZJSCOMPONENTLOADER_CONTRACTID "@mozilla.org/moz/jsloader;1"
-#define MOZJSCOMPONENTLOADER_TYPE_NAME "text/javascript"
 
 // nsIFastLoadFileIO implementation for component fastload
 class nsXPCFastLoadIO : public nsIFastLoadFileIO
 {
  public:
     NS_DECL_ISUPPORTS
     NS_DECL_NSIFASTLOADFILEIO
 
@@ -84,30 +83,32 @@ class nsXPCFastLoadIO : public nsIFastLo
 
     nsCOMPtr<nsIFile> mFile;
     nsCOMPtr<nsIInputStream> mInputStream;
     nsCOMPtr<nsIOutputStream> mOutputStream;
     bool mTruncateOutputFile;
 };
 
 
-class mozJSComponentLoader : public nsIModuleLoader,
+class mozJSComponentLoader : public mozilla::ModuleLoader,
                              public xpcIJSModuleLoader,
                              public nsIObserver
 {
     friend class JSCLContextHelper;
  public:
     NS_DECL_ISUPPORTS
-    NS_DECL_NSIMODULELOADER
     NS_DECL_XPCIJSMODULELOADER
     NS_DECL_NSIOBSERVER
 
     mozJSComponentLoader();
     virtual ~mozJSComponentLoader();
 
+    // ModuleLoader
+    const mozilla::Module* LoadModule(nsILocalFile* aFile);
+
  protected:
     static mozJSComponentLoader* sSelf;
 
     nsresult ReallyInit();
     void UnloadModules();
 
     nsresult GlobalForLocation(nsILocalFile *aComponent,
                                JSObject **aGlobal,
@@ -132,38 +133,42 @@ class mozJSComponentLoader : public nsIM
     nsCOMPtr<nsIObjectOutputStream> mFastLoadOutput;
     nsCOMPtr<nsITimer> mFastLoadTimer;
 #ifndef XPCONNECT_STANDALONE
     nsCOMPtr<nsIPrincipal> mSystemPrincipal;
 #endif
     JSRuntime *mRuntime;
     JSContext *mContext;
 
-    class ModuleEntry
+    class ModuleEntry : public mozilla::Module
     {
     public:
-        ModuleEntry() {
+        ModuleEntry() : mozilla::Module() {
+            
             global = nsnull;
             location = nsnull;
         }
 
         ~ModuleEntry() {
-            module = nsnull;
+            getfactory = NULL;
 
             if (global) {
                 JSAutoRequest ar(sSelf->mContext);
                 JS_ClearScope(sSelf->mContext, global);
                 JS_RemoveRoot(sSelf->mContext, &global);
             }
 
             if (location)
                 NS_Free(location);
         }
 
-        nsCOMPtr<nsIModule>  module;
+        static already_AddRefed<nsIFactory> GetFactory(const mozilla::Module& module,
+                                                       const mozilla::Module::CIDEntry& entry);
+
+        nsCOMPtr<xpcIJSGetFactory> getfactory;
         JSObject            *global;
         char                *location;
     };
 
     friend class ModuleEntry;
 
     nsClassHashtable<nsHashableHashKey, ModuleEntry> mModules;
     nsClassHashtable<nsHashableHashKey, ModuleEntry> mImports;
--- a/js/src/xpconnect/loader/mozJSLoaderConstructors.h
+++ b/js/src/xpconnect/loader/mozJSLoaderConstructors.h
@@ -40,62 +40,22 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifdef XPCONNECT_STANDALONE
 #define NO_SUBSCRIPT_LOADER
 #endif
 
-#include "nsIGenericFactory.h"
+#include "mozilla/ModuleUtils.h"
 #include "nsICategoryManager.h"
 #include "mozJSComponentLoader.h"
 
 #ifndef NO_SUBSCRIPT_LOADER
 #include "mozJSSubScriptLoader.h"
 const char mozJSSubScriptLoadContractID[] = "@mozilla.org/moz/jssubscript-loader;1";
 #endif
 
-static NS_METHOD
-RegisterJSLoader(nsIComponentManager *aCompMgr, nsIFile *aPath,
-                 const char *registryLocation, const char *componentType,
-                 const nsModuleComponentInfo *info)
-{
-    nsresult rv;
-    nsCOMPtr<nsICategoryManager> catman =
-        do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
-    if (NS_FAILED(rv)) return rv;
-    nsXPIDLCString previous;
-    return catman->AddCategoryEntry("module-loader",
-                                    MOZJSCOMPONENTLOADER_TYPE_NAME,
-                                    MOZJSCOMPONENTLOADER_CONTRACTID,
-                                    PR_TRUE, PR_TRUE, getter_Copies(previous));
-}
-
-static NS_METHOD
-UnregisterJSLoader(nsIComponentManager *aCompMgr, nsIFile *aPath,
-                   const char *registryLocation,
-                   const nsModuleComponentInfo *info)
-{
-    nsresult rv;
-    nsCOMPtr<nsICategoryManager> catman =
-        do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
-    if (NS_FAILED(rv)) return rv;
-    nsXPIDLCString jsLoader;
-    rv = catman->GetCategoryEntry("module-loader",
-                                  MOZJSCOMPONENTLOADER_TYPE_NAME,
-                                  getter_Copies(jsLoader));
-    if (NS_FAILED(rv)) return rv;
-
-    // only unregister if we're the current JS component loader
-    if (!strcmp(jsLoader, MOZJSCOMPONENTLOADER_CONTRACTID)) {
-        return catman->DeleteCategoryEntry("module-loader",
-                                           MOZJSCOMPONENTLOADER_TYPE_NAME,
-                                           PR_TRUE);
-    }
-    return NS_OK;
-}
-
 NS_GENERIC_FACTORY_CONSTRUCTOR(mozJSComponentLoader)
 
 #ifndef NO_SUBSCRIPT_LOADER
 NS_GENERIC_FACTORY_CONSTRUCTOR(mozJSSubScriptLoader)
 #endif
--- a/js/src/xpconnect/shell/xpcshell.cpp
+++ b/js/src/xpconnect/shell/xpcshell.cpp
@@ -68,17 +68,16 @@
 #include "nsILocalFile.h"
 #include "nsDirectoryServiceDefs.h"
 #include "nsAppDirectoryServiceDefs.h"
 #include "nscore.h"
 #include "nsArrayEnumerator.h"
 #include "nsCOMArray.h"
 #include "nsDirectoryServiceUtils.h"
 #include "nsMemory.h"
-#include "nsIGenericFactory.h"
 #include "nsISupportsImpl.h"
 #include "nsIJSRuntimeService.h"
 #include "nsCOMPtr.h"
 #include "nsAutoPtr.h"
 #include "nsIXPCSecurityManager.h"
 #ifdef XP_MACOSX
 #include "xpcshellMacUtils.h"
 #endif
@@ -1768,22 +1767,16 @@ main(int argc, char **argv)
 
     {
         nsCOMPtr<nsIServiceManager> servMan;
         rv = NS_InitXPCOM2(getter_AddRefs(servMan), appDir, &dirprovider);
         if (NS_FAILED(rv)) {
             printf("NS_InitXPCOM2 failed!\n");
             return 1;
         }
-        {
-            nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servMan);
-            NS_ASSERTION(registrar, "Null nsIComponentRegistrar");
-            if (registrar)
-                registrar->AutoRegister(nsnull);
-        }
 
         nsCOMPtr<nsIJSRuntimeService> rtsvc = do_GetService("@mozilla.org/js/xpc/RuntimeService;1");
         // get the JSRuntime from the runtime svc
         if (!rtsvc) {
             printf("failed to get nsJSRuntimeService!\n");
             return 1;
         }
 
--- a/js/src/xpconnect/src/nsXPConnect.cpp
+++ b/js/src/xpconnect/src/nsXPConnect.cpp
@@ -1065,18 +1065,17 @@ nsXPConnect::InitClasses(JSContext * aJS
     NS_ASSERTION(aGlobalJSObj, "bad param");
 
     // Nest frame chain save/restore in request created by XPCCallContext.
     XPCCallContext ccx(NATIVE_CALLER, aJSContext);
     if(!ccx.IsValid())
         return UnexpectedFailure(NS_ERROR_FAILURE);
     SaveFrame sf(aJSContext);
 
-    if(!xpc_InitJSxIDClassObjects())
-        return UnexpectedFailure(NS_ERROR_FAILURE);
+    xpc_InitJSxIDClassObjects();
 
     if(!xpc_InitWrappedNativeJSOps())
         return UnexpectedFailure(NS_ERROR_FAILURE);
 
     XPCWrappedNativeScope* scope =
         XPCWrappedNativeScope::GetNewOrUsed(ccx, aGlobalJSObj);
 
     if(!scope)
--- a/js/src/xpconnect/src/xpcexception.cpp
+++ b/js/src/xpconnect/src/xpcexception.cpp
@@ -114,16 +114,17 @@ nsXPCException::IterateNSResults(nsresul
 PRUint32
 nsXPCException::GetNSResultCount()
 {
     return RESULT_COUNT;
 }
 
 /***************************************************************************/
 
+NS_IMPL_CLASSINFO(nsXPCException, NULL, nsIClassInfo::DOM_OBJECT)
 NS_INTERFACE_MAP_BEGIN(nsXPCException)
   NS_INTERFACE_MAP_ENTRY(nsIException)
   NS_INTERFACE_MAP_ENTRY(nsIXPCException)
   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIException)
   NS_IMPL_QUERY_CLASSINFO(nsXPCException)
 NS_INTERFACE_MAP_END_THREADSAFE
 
 NS_IMPL_THREADSAFE_ADDREF(nsXPCException)
--- a/js/src/xpconnect/src/xpcjsid.cpp
+++ b/js/src/xpconnect/src/xpcjsid.cpp
@@ -282,78 +282,28 @@ NS_METHOD GetSharedScriptableHelperForJS
     return NS_OK;
 }
 
 /******************************************************/
 
 static JSBool gClassObjectsWereInited = JS_FALSE;
 
 NS_DECL_CI_INTERFACE_GETTER(nsJSIID)
-// Can't make this static. http://bugzilla.mozilla.org/show_bug.cgi?id=81436
-nsIClassInfo* NS_CLASSINFO_NAME(nsJSIID);
-
-static const nsModuleComponentInfo CI_nsJSIID =
-    {"JSIID",
-     {0x26ecb8d0, 0x35c9, 0x11d5, { 0x90, 0xb2, 0x0, 0x10, 0xa4, 0xe7, 0x3d, 0x9a }},
-     nsnull, nsnull, nsnull,nsnull, nsnull,
-     NS_CI_INTERFACE_GETTER_NAME(nsJSIID),
-     GetSharedScriptableHelperForJSIID,
-     &NS_CLASSINFO_NAME(nsJSIID), nsIClassInfo::THREADSAFE};
+NS_IMPL_CLASSINFO(nsJSIID, GetSharedScriptableHelperForJSIID, nsIClassInfo::THREADSAFE)
 
 NS_DECL_CI_INTERFACE_GETTER(nsJSCID)
-// Can't make this static. http://bugzilla.mozilla.org/show_bug.cgi?id=81436
-nsIClassInfo* NS_CLASSINFO_NAME(nsJSCID);
-
-static const nsModuleComponentInfo CI_nsJSCID =
-    {"JSCID",
-     {0x9255b5b0, 0x35cf, 0x11d5, { 0x90, 0xb2, 0x0, 0x10, 0xa4, 0xe7, 0x3d, 0x9a }},
-     nsnull, nsnull, nsnull,nsnull, nsnull,
-     NS_CI_INTERFACE_GETTER_NAME(nsJSCID), nsnull,
-     &NS_CLASSINFO_NAME(nsJSCID), nsIClassInfo::THREADSAFE};
-
-JSBool xpc_InitJSxIDClassObjects()
-{
-    if(gClassObjectsWereInited)
-        return JS_TRUE;
-
-    nsresult rv = NS_OK;
+NS_IMPL_CLASSINFO(nsJSCID, NULL, nsIClassInfo::THREADSAFE)
 
-    if(!NS_CLASSINFO_NAME(nsJSIID))
-    {
-        nsCOMPtr<nsIGenericFactory> factory;
-        rv = NS_NewGenericFactory(getter_AddRefs(factory), &CI_nsJSIID);
-        if(NS_FAILED(rv))
-            goto return_failure;
-        rv = factory->QueryInterface(NS_GET_IID(nsIClassInfo),
-                                     (void**)&NS_CLASSINFO_NAME(nsJSIID));
-        if(NS_FAILED(rv))
-            goto return_failure;
+void xpc_InitJSxIDClassObjects()
+{
+    if(!gClassObjectsWereInited) {
+        gSharedScriptableHelperForJSIID = new SharedScriptableHelperForJSIID();
+        NS_ADDREF(gSharedScriptableHelperForJSIID);
     }
-
-    if(!NS_CLASSINFO_NAME(nsJSCID))
-    {
-        nsCOMPtr<nsIGenericFactory> factory;
-        rv = NS_NewGenericFactory(getter_AddRefs(factory), &CI_nsJSCID);
-        if(NS_FAILED(rv))
-            goto return_failure;
-        rv = factory->QueryInterface(NS_GET_IID(nsIClassInfo),
-                                     (void**)&NS_CLASSINFO_NAME(nsJSCID));
-        if(NS_FAILED(rv))
-            goto return_failure;
-    }
-
-    gSharedScriptableHelperForJSIID = new SharedScriptableHelperForJSIID();
-    if(!gSharedScriptableHelperForJSIID)
-        goto return_failure;
-    NS_ADDREF(gSharedScriptableHelperForJSIID);
-
     gClassObjectsWereInited = JS_TRUE;
-    return JS_TRUE;
-return_failure:
-    return JS_FALSE;
 }
 
 void xpc_DestroyJSxIDClassObjects()
 {
     NS_IF_RELEASE(NS_CLASSINFO_NAME(nsJSIID));
     NS_IF_RELEASE(NS_CLASSINFO_NAME(nsJSCID));
     NS_IF_RELEASE(gSharedScriptableHelperForJSIID);
 
--- a/js/src/xpconnect/src/xpcmodule.cpp
+++ b/js/src/xpconnect/src/xpcmodule.cpp
@@ -33,55 +33,36 @@
  * use your version of this file under the terms of the MPL, 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 MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
-/* Module level methods. */
-
-#ifdef XPCONNECT_STANDALONE
-#define NO_SUBSCRIPT_LOADER
-#endif
-
-#include "xpcmodule.h"
+#include "xpcprivate.h"
 
 nsresult
-xpcModuleCtor(nsIModule* self)
+xpcModuleCtor()
 {
     nsXPConnect::InitStatics();
     nsXPCException::InitStatics();
     XPCWrappedNativeScope::InitStatics();
     XPCPerThreadData::InitStatics();
 
 #ifdef XPC_IDISPATCH_SUPPORT
     XPCIDispatchExtension::InitStatics();
 #endif
 
     return NS_OK;
 }
 
 void
-xpcModuleDtor(nsIModule*)
+xpcModuleDtor()
 {
     // Release our singletons
     nsXPConnect::ReleaseXPConnectSingleton();
     xpc_DestroyJSxIDClassObjects();
 #ifdef XPC_IDISPATCH_SUPPORT
     nsDispatchSupport::FreeSingleton();
     XPCIDispatchClassInfo::FreeSingleton();
 #endif
 }
-
-#ifdef XPCONNECT_STANDALONE
-
-/* Module implementation for the xpconnect library. */
-
-XPCONNECT_FACTORIES
-
-static const nsModuleComponentInfo components[] = {
-  XPCONNECT_COMPONENTS
-};
-
-NS_IMPL_NSGETMODULE_WITH_CTOR_DTOR(xpconnect, components, xpcModuleCtor, xpcModuleDtor)
-#endif
--- a/js/src/xpconnect/src/xpcmodule.h
+++ b/js/src/xpconnect/src/xpcmodule.h
@@ -1,9 +1,9 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  *
  * ***** BEGIN LICENSE BLOCK *****
  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  *
  * The contents of this file are subject to the Mozilla 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/MPL/
@@ -33,23 +33,18 @@
  * use your version of this file under the terms of the MPL, 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 MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
-#ifndef xpcmodule_h___
-#define xpcmodule_h___
-
 #include "xpcprivate.h"
-#ifdef MOZ_JSLOADER
 #include "mozJSLoaderConstructors.h"
-#endif
 
 /* Module implementation for the xpconnect library. */
 
 // {DC524540-487E-4501-9AC7-AAA784B17C1C}
 #define XPCVARIANT_CID                                                        \
     {0xdc524540, 0x487e, 0x4501,                                              \
       { 0x9a, 0xc7, 0xaa, 0xa7, 0x84, 0xb1, 0x7c, 0x1c } }
 
@@ -57,181 +52,70 @@
 #define XPC_JSCONTEXT_STACK_ITERATOR_CONTRACTID                               \
     "@mozilla.org/js/xpc/ContextStackIterator;1"
 
 // {FE4F7592-C1FC-4662-AC83-538841318803}
 #define SCRIPTABLE_INTERFACES_CID                                             \
     {0xfe4f7592, 0xc1fc, 0x4662,                                              \
       { 0xac, 0x83, 0x53, 0x88, 0x41, 0x31, 0x88, 0x3 } }
 
-
-#define XPCONNECT_GENERAL_FACTORIES                                           \
-  NS_DECL_CLASSINFO(XPCVariant)                                               \
-  NS_DECL_CLASSINFO(nsXPCException)                                           \
-                                                                              \
-  NS_GENERIC_FACTORY_CONSTRUCTOR(nsJSID)                                      \
-  NS_GENERIC_FACTORY_CONSTRUCTOR(nsXPCException)                              \
-  NS_GENERIC_FACTORY_CONSTRUCTOR(nsXPCJSContextStackIterator)                 \
-  NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIXPConnect,                      \
-                                           nsXPConnect::GetSingleton)         \
-  NS_GENERIC_FACTORY_CONSTRUCTOR(nsScriptError)                               \
-  NS_GENERIC_FACTORY_CONSTRUCTOR(nsXPCComponents_Interfaces)
-
+NS_GENERIC_FACTORY_CONSTRUCTOR(nsJSID)
+NS_GENERIC_FACTORY_CONSTRUCTOR(nsXPCException)
+NS_GENERIC_FACTORY_CONSTRUCTOR(nsXPCJSContextStackIterator)
+NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIXPConnect,
+                                         nsXPConnect::GetSingleton)
+NS_GENERIC_FACTORY_CONSTRUCTOR(nsScriptError)
+NS_GENERIC_FACTORY_CONSTRUCTOR(nsXPCComponents_Interfaces)
 
 #ifdef XPC_IDISPATCH_SUPPORT
-
-#define XPCONNECT_FACTORIES                                                   \
-  NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIDispatchSupport,                \
-                                           nsDispatchSupport::GetSingleton)   \
-  XPCONNECT_GENERAL_FACTORIES
-
-#else
-
-#define XPCONNECT_FACTORIES XPCONNECT_GENERAL_FACTORIES
-
+NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIDispatchSupport,
+                                         nsDispatchSupport::GetSingleton)
 #endif // XPC_IDISPATCH_SUPPORT
 
-
-#ifdef XPCONNECT_STANDALONE
-#define NO_SUBSCRIPT_LOADER
+NS_DEFINE_NAMED_CID(NS_JS_ID_CID);
+NS_DEFINE_NAMED_CID(NS_XPCONNECT_CID);
+NS_DEFINE_NAMED_CID(NS_XPCEXCEPTION_CID);
+NS_DEFINE_NAMED_CID(NS_SCRIPTERROR_CID);
+NS_DEFINE_NAMED_CID(SCRIPTABLE_INTERFACES_CID);
+NS_DEFINE_NAMED_CID(XPCVARIANT_CID);
+NS_DEFINE_NAMED_CID(NS_XPC_JSCONTEXT_STACK_ITERATOR_CID);
+NS_DEFINE_NAMED_CID(MOZJSCOMPONENTLOADER_CID);
+NS_DEFINE_NAMED_CID(MOZ_JSSUBSCRIPTLOADER_CID);
+#ifdef XPC_IDISPATCH_SUPPORT
+NS_DEFINE_NAMED_CID(NS_IDISPATCH_SUPPORT_CID);
+#define XPCIDISPATCH_CIDS \
+  { &kNS_IDISPATCH_SUPPORT_CID, false, NULL, nsIDispatchSupportConstructor },
+#define XPCIDISPATCH_CONTRACTS \
+  { NS_IDISPATCH_SUPPORT_CONTRACTID, &kNS_IDISPATCH_SUPPORT_CID },
+#else
+#define XPCIDISPATCH_CIDS
+#define XPCIDISPATCH_CONTRACTS
 #endif
 
+#define XPCONNECT_CIDENTRIES \
+  { &kNS_JS_ID_CID, false, NULL,  nsJSIDConstructor }, \
+  { &kNS_XPCONNECT_CID, false, NULL,  nsIXPConnectConstructor }, \
+  { &kNS_XPCEXCEPTION_CID, false, NULL, nsXPCExceptionConstructor }, \
+  { &kNS_SCRIPTERROR_CID, false, NULL, nsScriptErrorConstructor }, \
+  { &kSCRIPTABLE_INTERFACES_CID, false, NULL, nsXPCComponents_InterfacesConstructor }, \
+  { &kNS_XPC_JSCONTEXT_STACK_ITERATOR_CID, false, NULL, nsXPCJSContextStackIteratorConstructor }, \
+  { &kMOZJSCOMPONENTLOADER_CID, false, NULL, mozJSComponentLoaderConstructor }, \
+  { &kMOZ_JSSUBSCRIPTLOADER_CID, false, NULL, mozJSSubScriptLoaderConstructor }, \
+  XPCIDISPATCH_CIDS
 
-#define XPCONNECT_GENERAL_COMPONENTS                                          \
-  {                                                                           \
-    nsnull,                                                                   \
-    NS_JS_ID_CID,                                                             \
-    XPC_ID_CONTRACTID,                                                        \
-    nsJSIDConstructor                                                         \
-  },                                                                          \
-  {                                                                           \
-    nsnull,                                                                   \
-    NS_XPCONNECT_CID,                                                         \
-    XPC_XPCONNECT_CONTRACTID,                                                 \
-    nsIXPConnectConstructor                                                   \
-  },                                                                          \
-  {                                                                           \
-    nsnull,                                                                   \
-    NS_XPC_THREAD_JSCONTEXT_STACK_CID,                                        \
-    XPC_CONTEXT_STACK_CONTRACTID,                                             \
-    nsIXPConnectConstructor                                                   \
-  },                                                                          \
-  {                                                                           \
-    nsnull,                                                                   \
-    NS_XPCEXCEPTION_CID,                                                      \
-    XPC_EXCEPTION_CONTRACTID,                                                 \
-    nsXPCExceptionConstructor,                                                \
-    nsnull,                                                                   \
-    nsnull,                                                                   \
-    nsnull,                                                                   \
-    NS_CI_INTERFACE_GETTER_NAME(nsXPCException),                              \
-    nsnull,                                                                   \
-    &NS_CLASSINFO_NAME(nsXPCException),                                       \
-    nsIClassInfo::DOM_OBJECT                                                  \
-  },                                                                          \
-  {                                                                           \
-    nsnull,                                                                   \
-    NS_JS_RUNTIME_SERVICE_CID,                                                \
-    XPC_RUNTIME_CONTRACTID,                                                   \
-    nsIXPConnectConstructor                                                   \
-  },                                                                          \
-  {                                                                           \
-    NS_SCRIPTERROR_CLASSNAME,                                                 \
-    NS_SCRIPTERROR_CID,                                                       \
-    NS_SCRIPTERROR_CONTRACTID,                                                \
-    nsScriptErrorConstructor                                                  \
-  },                                                                          \
-  {                                                                           \
-    nsnull,                                                                   \
-    SCRIPTABLE_INTERFACES_CID,                                                \
-    NS_SCRIPTABLE_INTERFACES_CONTRACTID,                                      \
-    nsXPCComponents_InterfacesConstructor,                                    \
-    nsnull,                                                                   \
-    nsnull,                                                                   \
-    nsnull,                                                                   \
-    nsnull,                                                                   \
-    nsnull,                                                                   \
-    nsnull,                                                                   \
-    nsIClassInfo::THREADSAFE                                                  \
-  },                                                                          \
-  {                                                                           \
-    nsnull,                                                                   \
-    XPCVARIANT_CID,                                                           \
-    XPCVARIANT_CONTRACTID,                                                    \
-    nsnull,                                                                   \
-    nsnull,                                                                   \
-    nsnull,                                                                   \
-    nsnull,                                                                   \
-    NS_CI_INTERFACE_GETTER_NAME(XPCVariant),                                  \
-    nsnull,                                                                   \
-    &NS_CLASSINFO_NAME(XPCVariant)                                            \
-  },                                                                          \
-  {                                                                           \
-    nsnull,                                                                   \
-    NS_XPC_JSCONTEXT_STACK_ITERATOR_CID,                                      \
-    XPC_JSCONTEXT_STACK_ITERATOR_CONTRACTID,                                  \
-    nsXPCJSContextStackIteratorConstructor                                    \
-  }
+#define XPCONNECT_CONTRACTS \
+  { XPC_ID_CONTRACTID, &kNS_JS_ID_CID }, \
+  { XPC_XPCONNECT_CONTRACTID, &kNS_XPCONNECT_CID }, \
+  { XPC_CONTEXT_STACK_CONTRACTID, &kNS_XPCONNECT_CID }, \
+  { XPC_RUNTIME_CONTRACTID, &kNS_XPCONNECT_CID }, \
+  { XPC_EXCEPTION_CONTRACTID, &kNS_XPCEXCEPTION_CID }, \
+  { NS_SCRIPTERROR_CONTRACTID, &kNS_SCRIPTERROR_CID }, \
+  { NS_SCRIPTABLE_INTERFACES_CONTRACTID, &kSCRIPTABLE_INTERFACES_CID }, \
+  { XPC_JSCONTEXT_STACK_ITERATOR_CONTRACTID, &kNS_XPC_JSCONTEXT_STACK_ITERATOR_CID }, \
+  { MOZJSCOMPONENTLOADER_CONTRACTID, &kMOZJSCOMPONENTLOADER_CID }, \
+  { mozJSSubScriptLoadContractID, &kMOZ_JSSUBSCRIPTLOADER_CID }, \
+  XPCIDISPATCH_CONTRACTS
 
-// jsloader stuff
-#ifdef MOZ_JSLOADER
-
-#define XPCONNECT_LOADER_COMPONENTS                                           \
-  {                                                                           \
-    "JS component loader",                                                    \
-    MOZJSCOMPONENTLOADER_CID,                                                 \
-    MOZJSCOMPONENTLOADER_CONTRACTID,                                          \
-    mozJSComponentLoaderConstructor,                                          \
-    RegisterJSLoader,                                                         \
-    UnregisterJSLoader                                                        \
-  },                                                                          \
-  XPCONNECT_SUBSCRIPT_LOADER_COMPONENTS
-
-#ifdef NO_SUBSCRIPT_LOADER
-
-#define XPCONNECT_SUBSCRIPT_LOADER_COMPONENTS
-
-#else
-
-#define XPCONNECT_SUBSCRIPT_LOADER_COMPONENTS                                 \
-  {                                                                           \
-    "JS subscript loader",                                                    \
-    MOZ_JSSUBSCRIPTLOADER_CID,                                                \
-    mozJSSubScriptLoadContractID,                                             \
-    mozJSSubScriptLoaderConstructor                                           \
-  },
-
-#endif // NO_SUBSCRIPT_LOADER
-
-#else
+#define XPCONNECT_CATEGORIES \
+  { "module-loader", "js", MOZJSCOMPONENTLOADER_CONTRACTID },
 
-#define XPCONNECT_LOADER_COMPONENTS
-
-#endif // MOZ_JSLOADER
-
-
-#ifdef XPC_IDISPATCH_SUPPORT
-
-#define XPCONNECT_IDISPATCH_COMPONENTS                                        \
-  {                                                                           \
-    nsnull,                                                                   \
-    NS_IDISPATCH_SUPPORT_CID,                                                 \
-    NS_IDISPATCH_SUPPORT_CONTRACTID,                                          \
-    nsIDispatchSupportConstructor                                             \
-  },
-
-#else
-
-#define XPCONNECT_IDISPATCH_COMPONENTS
-
-#endif // XPC_IDISPATCH_SUPPORT
-
-
-#define XPCONNECT_COMPONENTS                                                  \
-  XPCONNECT_LOADER_COMPONENTS                                                 \
-  XPCONNECT_IDISPATCH_COMPONENTS                                              \
-  XPCONNECT_GENERAL_COMPONENTS
-
-extern nsresult xpcModuleCtor(nsIModule* self);
-extern void xpcModuleDtor(nsIModule*);
-
-#endif /* xpcmodule_h___ */
-
+nsresult xpcModuleCtor();
+void xpcModuleDtor();
--- a/js/src/xpconnect/src/xpcprivate.h
+++ b/js/src/xpconnect/src/xpcprivate.h
@@ -64,27 +64,25 @@
 #include "nsCycleCollectionParticipant.h"
 #include "nsCycleCollector.h"
 #include "nsISupports.h"
 #include "nsIServiceManager.h"
 #include "nsIClassInfoImpl.h"
 #include "nsIComponentManager.h"
 #include "nsIComponentRegistrar.h"
 #include "nsISupportsPrimitives.h"
-#include "nsIGenericFactory.h"
 #include "nsMemory.h"
 #include "nsIXPConnect.h"
 #include "nsIInterfaceInfo.h"
 #include "nsIInterfaceInfoManager.h"
 #include "nsIXPCScriptable.h"
 #include "nsIXPCSecurityManager.h"
 #include "nsIJSRuntimeService.h"
 #include "nsWeakReference.h"
 #include "nsCOMPtr.h"
-#include "nsIModule.h"
 #include "nsAutoLock.h"
 #include "nsXPTCUtils.h"
 #include "xptinfo.h"
 #include "xpcforwards.h"
 #include "xpclog.h"
 #include "xpccomponents.h"
 #include "xpcexception.h"
 #include "xpcjsid.h"
@@ -411,24 +409,16 @@ private:
 // We have a general rule internally that getters that return addref'd interface
 // pointer generally do so using an 'out' parm. When interface pointers are
 // returned as function call result values they are not addref'd. Exceptions
 // to this rule are noted explicitly.
 
 const PRBool OBJ_IS_GLOBAL = PR_TRUE;
 const PRBool OBJ_IS_NOT_GLOBAL = PR_FALSE;
 
-#define NS_JS_RUNTIME_SERVICE_CID \
-{0xb5e65b52, 0x1dd1, 0x11b2, \
-    { 0xae, 0x8f, 0xf0, 0x92, 0x8e, 0xd8, 0x84, 0x82 }}
-
-#define NS_XPC_THREAD_JSCONTEXT_STACK_CID  \
-{ 0xff8c4d10, 0x3194, 0x11d3, \
-    { 0x98, 0x85, 0x0, 0x60, 0x8, 0x96, 0x24, 0x22 } }
-
 class nsXPConnect : public nsIXPConnect,
                     public nsIThreadObserver,
                     public nsSupportsWeakReference,
                     public nsCycleCollectionJSRuntime,
                     public nsCycleCollectionParticipant,
                     public nsIJSRuntimeService,
                     public nsIThreadJSContextStack
 {
@@ -3271,17 +3261,17 @@ private:
 };
 
 /***************************************************************************/
 /*
 * nsJSID implements nsIJSID. It is also used by nsJSIID and nsJSCID as a
 * member (as a hidden implementaion detail) to which they delegate many calls.
 */
 
-extern JSBool xpc_InitJSxIDClassObjects();
+extern void xpc_InitJSxIDClassObjects();
 extern void xpc_DestroyJSxIDClassObjects();
 
 
 class nsJSID : public nsIJSID
 {
 public:
     NS_DEFINE_STATIC_CID_ACCESSOR(NS_JS_ID_CID)
 
--- a/js/src/xpconnect/src/xpcvariant.cpp
+++ b/js/src/xpconnect/src/xpcvariant.cpp
@@ -39,16 +39,17 @@
  * ***** END LICENSE BLOCK ***** */
 
 /* nsIVariant implementation for xpconnect. */
 
 #include "xpcprivate.h"
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(XPCVariant)
 
+NS_IMPL_CLASSINFO(XPCVariant, NULL, 0)
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(XPCVariant)
   NS_INTERFACE_MAP_ENTRY(XPCVariant)
   NS_INTERFACE_MAP_ENTRY(nsIVariant)
   NS_INTERFACE_MAP_ENTRY(nsISupports)
   NS_IMPL_QUERY_CLASSINFO(XPCVariant)
 NS_INTERFACE_MAP_END
 NS_IMPL_CI_INTERFACE_GETTER2(XPCVariant, XPCVariant, nsIVariant)
 
--- a/js/src/xpconnect/tests/TestXPC.cpp
+++ b/js/src/xpconnect/tests/TestXPC.cpp
@@ -774,20 +774,16 @@ int main()
     JSObject *glob;
     nsresult rv;
 
     gErrFile = stderr;
     gOutFile = stdout;
     {
         nsCOMPtr<nsIServiceManager> servMan;
         NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull);
-        nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servMan);
-        NS_ASSERTION(registrar, "Null nsIComponentRegistrar");
-        if(registrar)
-            registrar->AutoRegister(nsnull);
     
         // get the JSRuntime from the runtime svc, if possible
         nsCOMPtr<nsIJSRuntimeService> rtsvc =
                  do_GetService("@mozilla.org/js/xpc/RuntimeService;1", &rv);
         if(NS_FAILED(rv) || NS_FAILED(rtsvc->GetRuntime(&rt)) || !rt)
             DIE("FAILED to get a JSRuntime");
 
         jscontext = JS_NewContext(rt, 8192);
--- a/layout/build/nsContentDLF.cpp
+++ b/layout/build/nsContentDLF.cpp
@@ -511,131 +511,14 @@ nsContentDLF::CreateXULDocument(const ch
     rv = docv->LoadStart(doc);
     *aDocViewer = docv;
     NS_IF_ADDREF(*aDocViewer);
   }
    
   return rv;
 }
 
-static nsresult
-RegisterTypes(nsICategoryManager* aCatMgr,
-              const char* const* aTypes,
-              PRBool aPersist = PR_TRUE)
-{
-  nsresult rv = NS_OK;
-  while (*aTypes) {
-    const char* contentType = *aTypes++;
-#ifdef NOISY_REGISTRY
-    printf("Register %s => %s\n", contractid, aPath);
-#endif
-    // add the MIME types layout can handle to the handlers category.
-    // this allows users of layout's viewers (the docshell for example)
-    // to query the types of viewers layout can create.
-    rv = aCatMgr->AddCategoryEntry("Gecko-Content-Viewers", contentType,
-                                   CONTENT_DLF_CONTRACTID,
-                                   aPersist, PR_TRUE, nsnull);
-    if (NS_FAILED(rv)) break;
-  }
-  return rv;
-}
-
-static nsresult UnregisterTypes(nsICategoryManager* aCatMgr,
-                                const char* const* aTypes)
-{
-  nsresult rv = NS_OK;
-  while (*aTypes) {
-    const char* contentType = *aTypes++;
-    rv = aCatMgr->DeleteCategoryEntry("Gecko-Content-Viewers", contentType, PR_TRUE);
-    if (NS_FAILED(rv)) break;
-  }
-  return rv;
-
-}
-
-#ifdef MOZ_SVG
-NS_IMETHODIMP
-nsContentDLF::RegisterSVG()
-{
-  nsresult rv;
-  nsCOMPtr<nsICategoryManager> catmgr(do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv));
-  if (NS_FAILED(rv)) return rv;
-
-  return RegisterTypes(catmgr, gSVGTypes, PR_FALSE);
-}
-
-NS_IMETHODIMP
-nsContentDLF::UnregisterSVG()
-{
-  nsresult rv;
-  nsCOMPtr<nsICategoryManager> catmgr(do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv));
-  if (NS_FAILED(rv)) return rv;
-
-  return UnregisterTypes(catmgr, gSVGTypes);
-}
-#endif
-
-NS_IMETHODIMP
-nsContentDLF::RegisterDocumentFactories(nsIComponentManager* aCompMgr,
-                                        nsIFile* aPath,
-                                        const char *aLocation,
-                                        const char *aType,
-                                        const nsModuleComponentInfo* aInfo)
-{
-  NS_TIME_FUNCTION;
-
-  nsresult rv;
-
-  nsCOMPtr<nsICategoryManager> catmgr(do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv));
-  if (NS_FAILED(rv)) return rv;
-
-  do {
-    rv = RegisterTypes(catmgr, gHTMLTypes);
-    if (NS_FAILED(rv))
-      break;
-    rv = RegisterTypes(catmgr, gXMLTypes);
-    if (NS_FAILED(rv))
-      break;
-    rv = RegisterTypes(catmgr, gXULTypes);
-    if (NS_FAILED(rv))
-      break;
-  } while (PR_FALSE);
-  return rv;
-}
-
-NS_IMETHODIMP
-nsContentDLF::UnregisterDocumentFactories(nsIComponentManager* aCompMgr,
-                                          nsIFile* aPath,
-                                          const char* aRegistryLocation,
-                                          const nsModuleComponentInfo* aInfo)
-{
-  NS_TIME_FUNCTION;
-
-  nsresult rv;
-  nsCOMPtr<nsICategoryManager> catmgr(do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv));
-  if (NS_FAILED(rv)) return rv;
-
-  do {
-    rv = UnregisterTypes(catmgr, gHTMLTypes);
-    if (NS_FAILED(rv))
-      break;
-    rv = UnregisterTypes(catmgr, gXMLTypes);
-    if (NS_FAILED(rv))
-      break;
-#ifdef MOZ_SVG
-    rv = UnregisterTypes(catmgr, gSVGTypes);
-    if (NS_FAILED(rv))
-      break;
-#endif
-    rv = UnregisterTypes(catmgr, gXULTypes);
-    if (NS_FAILED(rv))
-      break;
-  } while (PR_FALSE);
-
-  return rv;
-}
-
 PRBool nsContentDLF::IsImageContentType(const char* aContentType) {
   nsCOMPtr<imgILoader> loader(do_GetService("@mozilla.org/image/loader;1"));
   PRBool isDecoderAvailable = PR_FALSE;
   loader->SupportImageWithMimeType(aContentType, &isDecoderAvailable);
   return isDecoderAvailable;
 }
--- a/layout/build/nsContentDLF.h
+++ b/layout/build/nsContentDLF.h
@@ -36,26 +36,25 @@
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef nsContentDLF_h__
 #define nsContentDLF_h__
 
 #include "nsIDocumentLoaderFactory.h"
 #include "nsIDocumentViewer.h"
 #include "nsIDocument.h"
+#include "nsMimeTypes.h"
 
 class nsIChannel;
-class nsIComponentManager;
 class nsIContentViewer;
 class nsIDocumentViewer;
 class nsIFile;
 class nsIInputStream;
 class nsILoadGroup;
 class nsIStreamListener;
-struct nsModuleComponentInfo;
 
 #define CONTENT_DLF_CONTRACTID "@mozilla.org/content/document-loader-factory;1"
 #define PLUGIN_DLF_CONTRACTID "@mozilla.org/content/plugin/document-loader-factory;1"
 
 class nsContentDLF : public nsIDocumentLoaderFactory
 {
 public:
   nsContentDLF();
@@ -78,36 +77,68 @@ public:
                              nsIChannel* aChannel,
                              nsILoadGroup* aLoadGroup,
                              const char* aContentType,
                              nsISupports* aContainer,
                              nsISupports* aExtraInfo,
                              nsIStreamListener** aDocListener,
                              nsIContentViewer** aDocViewer);
 
-#ifdef MOZ_SVG
-  static NS_IMETHODIMP RegisterSVG();
-  static NS_IMETHODIMP UnregisterSVG();
-#endif
-
-  static NS_IMETHODIMP
-  RegisterDocumentFactories(nsIComponentManager* aCompMgr,
-                            nsIFile* aPath,
-                            const char *aLocation,
-                            const char *aType,
-                            const nsModuleComponentInfo* aInfo);
-
-  static NS_IMETHODIMP
-  UnregisterDocumentFactories(nsIComponentManager* aCompMgr,
-                              nsIFile* aPath,
-                              const char* aRegistryLocation,
-                              const nsModuleComponentInfo* aInfo);
-
 private:
   static nsresult EnsureUAStyleSheet();
   static PRBool IsImageContentType(const char* aContentType);
 };
 
 nsresult
 NS_NewContentDocumentLoaderFactory(nsIDocumentLoaderFactory** aResult);
 
+#ifdef MOZ_VIEW_SOURCE
+#define CONTENTDLF_VIEWSOURCE_CATEGORIES \
+    { "Gecko-Content-Viewers", VIEWSOURCE_CONTENT_TYPE, "@mozilla.org/content/document-loader-factory;1" },
+#else
+#define CONTENTDLF_VIEWSOURCE_CATEGORIES
+#endif
+
+#ifdef MOZ_MATHML
+#define CONTENTDLF_MATHML_CATEGORIES \
+    { "Gecko-Content-Viewers", APPLICATION_MATHML_XML, "@mozilla.org/content/document-loader-factory;1" },
+#else
+#define CONTENTDLF_MATHML_CATEGORIES
+#endif
+
+#ifdef MOZ_SVG
+#define CONTENTDLF_SVG_CATEGORIES \
+    { "Gecko-Content-Viewers", IMAGE_SVG_XML, "@mozilla.org/content/document-loader-factory;1" },
+#else
+#define CONTENTDLF_SVG_CATEGORIES
 #endif
 
+#ifdef MOZ_WEBM
+#define CONTENTDLF_WEBM_CATEGORIES \
+    { "Gecko-Content-Viewers", VIDEO_WEBM, "@mozilla.org/content/document-loader-factory;1" }, \
+    { "Gecko-Content-Viewers", AUDIO_WEBM, "@mozilla.org/content/document-loader-factory;1" },
+#else
+#define CONTENTDLF_WEBM_CATEGORIES
+#endif
+
+#define CONTENTDLF_CATEGORIES \
+    { "Gecko-Content-Viewers", TEXT_HTML, "@mozilla.org/content/document-loader-factory;1" }, \
+    { "Gecko-Content-Viewers", TEXT_PLAIN, "@mozilla.org/content/document-loader-factory;1" }, \
+    { "Gecko-Content-Viewers", TEXT_CSS, "@mozilla.org/content/document-loader-factory;1" }, \
+    { "Gecko-Content-Viewers", TEXT_JAVASCRIPT, "@mozilla.org/content/document-loader-factory;1" }, \
+    { "Gecko-Content-Viewers", TEXT_ECMASCRIPT, "@mozilla.org/content/document-loader-factory;1" }, \
+    { "Gecko-Content-Viewers", APPLICATION_JAVASCRIPT, "@mozilla.org/content/document-loader-factory;1" }, \
+    { "Gecko-Content-Viewers", APPLICATION_ECMASCRIPT, "@mozilla.org/content/document-loader-factory;1" }, \
+    { "Gecko-Content-Viewers", APPLICATION_XJAVASCRIPT, "@mozilla.org/content/document-loader-factory;1" }, \
+    { "Gecko-Content-Viewers", APPLICATION_XHTML_XML, "@mozilla.org/content/document-loader-factory;1" }, \
+    { "Gecko-Content-Viewers", TEXT_XML, "@mozilla.org/content/document-loader-factory;1" }, \
+    { "Gecko-Content-Viewers", APPLICATION_XML, "@mozilla.org/content/document-loader-factory;1" }, \
+    { "Gecko-Content-Viewers", APPLICATION_RDF_XML, "@mozilla.org/content/document-loader-factory;1" }, \
+    { "Gecko-Content-Viewers", TEXT_RDF, "@mozilla.org/content/document-loader-factory;1" }, \
+    { "Gecko-Content-Viewers", TEXT_XUL, "@mozilla.org/content/document-loader-factory;1" }, \
+    { "Gecko-Content-Viewers", APPLICATION_CACHED_XUL, "@mozilla.org/content/document-loader-factory;1" }, \
+    CONTENTDLF_VIEWSOURCE_CATEGORIES \
+    CONTENTDLF_MATHML_CATEGORIES \
+    CONTENTDLF_SVG_CATEGORIES \
+    CONTENTDLF_WEBM_CATEGORIES
+
+#endif
+
--- a/layout/build/nsLayoutModule.cpp
+++ b/layout/build/nsLayoutModule.cpp
@@ -32,43 +32,42 @@
  * 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 MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "xpcmodule.h"
+#include "mozilla/ModuleUtils.h"
 #include "nsLayoutStatics.h"
 #include "nsContentCID.h"
 #include "nsContentDLF.h"
 #include "nsContentPolicyUtils.h"
 #include "nsDataDocumentContentPolicy.h"
 #include "nsNoDataProtocolContentPolicy.h"
 #include "nsDOMCID.h"
 #include "nsHTMLContentSerializer.h"
 #include "nsHTMLParts.h"
 #include "nsGenericHTMLElement.h"
-#include "nsICategoryManager.h"
 #include "nsIComponentManager.h"
 #include "nsIContentIterator.h"
 #include "nsIContentSerializer.h"
 #include "nsIController.h"
 #include "nsIControllers.h"
 #include "nsIDOMDOMImplementation.h"
 #include "nsIDOMEventGroup.h"
 #include "nsIDOMRange.h"
 #include "nsIDocument.h"
 #include "nsIDocumentEncoder.h"
 #include "nsIDocumentViewer.h"
 #include "nsIEventListenerManager.h"
 #include "nsIFactory.h"
 #include "nsFrameSelection.h"
 #include "nsIFrameUtil.h"
-#include "nsIGenericFactory.h"
 #include "nsIFragmentContentSink.h"
 #include "nsHTMLStyleSheet.h"
 #include "nsIHTMLToTextSink.h"
 #include "nsILayoutDebugger.h"
 #include "nsINameSpaceManager.h"
 #include "nsINodeInfo.h"
 #include "nsIObserver.h"
 #include "nsIObserverService.h"
@@ -156,17 +155,17 @@
 { 0x4f5e62b8, 0xd659, 0x4156, { 0x84, 0xfc, 0x2f, 0x60, 0x99, 0x40, 0x03, 0x69 }}
 
 static NS_DEFINE_CID(kEditorCommandTableCID, NS_EDITORCOMMANDTABLE_CID);
 
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsPlaintextEditor)
 
 // Constructor of a controller which is set up to use, internally, a
 // singleton command-table pre-filled with editor commands.
-static NS_METHOD
+static nsresult
 nsEditorControllerConstructor(nsISupports *aOuter, REFNSIID aIID,
                                             void **aResult)
 {
   nsresult rv;
   nsCOMPtr<nsIController> controller = do_CreateInstance("@mozilla.org/embedcomp/base-command-controller;1", &rv);
   if (NS_FAILED(rv)) return rv;
 
   nsCOMPtr<nsIControllerCommandTable> editorCommandTable = do_GetService(kEditorCommandTableCID, &rv);
@@ -181,17 +180,17 @@ nsEditorControllerConstructor(nsISupport
   rv = controllerContext->Init(editorCommandTable);
   if (NS_FAILED(rv)) return rv;
   
   return controller->QueryInterface(aIID, aResult);
 }
 
 
 // Constructor for a command-table pref-filled with editor commands
-static NS_METHOD
+static nsresult
 nsEditorCommandTableConstructor(nsISupports *aOuter, REFNSIID aIID,
                                             void **aResult)
 {
   nsresult rv;
   nsCOMPtr<nsIControllerCommandTable> commandTable =
       do_CreateInstance(NS_CONTROLLERCOMMANDTABLE_CONTRACTID, &rv);
   if (NS_FAILED(rv)) return rv;
   
@@ -258,20 +257,20 @@ static NS_DEFINE_CID(kWindowCommandTable
 #include "inDOMUtils.h"
 #endif /* MOZ_NO_INSPECTOR_APIS */
 
 #ifdef MOZ_XUL
 #include "nsIXULDocument.h"
 #include "nsIXULPrototypeCache.h"
 #include "nsIXULSortService.h"
 
-NS_IMETHODIMP
+nsresult
 NS_NewXULContentBuilder(nsISupports* aOuter, REFNSIID aIID, void** aResult);
 
-NS_IMETHODIMP
+nsresult
 NS_NewXULTreeBuilder(nsISupports* aOuter, REFNSIID aIID, void** aResult);
 #endif
 
 static void Shutdown();
 
 #ifdef MOZ_XTF
 #include "nsIXTFService.h"
 #include "nsIXMLContentBuilder.h"
@@ -338,30 +337,35 @@ LayoutShutdownObserver::Observe(nsISuppo
 //-----------------------------------------------------------------------------
 
 static PRBool gInitialized = PR_FALSE;
 
 // Perform our one-time intialization for this module
 
 // static
 nsresult
-Initialize(nsIModule* aSelf)
+Initialize()
 {
-  NS_PRECONDITION(!gInitialized, "module already initialized");
   if (gInitialized) {
-    return NS_OK;
+    NS_ERROR("Recursive layout module initialization");
+    return NS_ERROR_FAILURE;
   }
 
   NS_ASSERTION(sizeof(PtrBits) == sizeof(void *),
                "Eeek! You'll need to adjust the size of PtrBits to the size "
                "of a pointer on your platform.");
 
   gInitialized = PR_TRUE;
 
-  nsresult rv = nsLayoutStatics::Initialize();
+  nsresult rv;
+  rv = xpcModuleCtor();
+  if (NS_FAILED(rv))
+    return rv;
+
+  rv = nsLayoutStatics::Initialize();
   if (NS_FAILED(rv)) {
     Shutdown();
     return rv;
   }
 
   // Add our shutdown observer.
   nsCOMPtr<nsIObserverService> observerService =
     mozilla::services::GetObserverService();
@@ -434,20 +438,20 @@ nsresult NS_NewHTMLCopyTextEncoder(nsIDo
 nsresult NS_NewTextEncoder(nsIDocumentEncoder** aResult);
 nsresult NS_NewXBLService(nsIXBLService** aResult);
 nsresult NS_NewContentPolicy(nsIContentPolicy** aResult);
 nsresult NS_NewDOMEventGroup(nsIDOMEventGroup** aResult);
 
 nsresult NS_NewEventListenerService(nsIEventListenerService** aResult);
 nsresult NS_NewGlobalMessageManager(nsIChromeFrameMessageManager** aResult);
 
-NS_IMETHODIMP NS_NewXULControllers(nsISupports* aOuter, REFNSIID aIID, void** aResult);
+nsresult NS_NewXULControllers(nsISupports* aOuter, REFNSIID aIID, void** aResult);
 
 #define MAKE_CTOR(ctor_, iface_, func_)                   \
-static NS_IMETHODIMP                                      \
+static nsresult                                           \
 ctor_(nsISupports* aOuter, REFNSIID aIID, void** aResult) \
 {                                                         \
   *aResult = nsnull;                                      \
   if (aOuter)                                             \
     return NS_ERROR_NO_AGGREGATION;                       \
   iface_* inst;                                           \
   nsresult rv = func_(&inst);                             \
   if (NS_SUCCEEDED(rv)) {                                 \
@@ -554,17 +558,17 @@ MAKE_CTOR(CreateCanvasRenderingContextWe
 
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsStyleSheetService, Init)
 
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsJSURI)
 
 // views are not refcounted, so this is the same as
 // NS_GENERIC_FACTORY_CONSTRUCTOR without the NS_ADDREF/NS_RELEASE
 #define NS_GENERIC_FACTORY_CONSTRUCTOR_NOREFS(_InstanceClass)                 \
-static NS_IMETHODIMP                                                          \
+static nsresult                                                               \
 _InstanceClass##Constructor(nsISupports *aOuter, REFNSIID aIID,               \
                             void **aResult)                                   \
 {                                                                             \
     nsresult rv;                                                              \
                                                                               \
     _InstanceClass * inst;                                                    \
                                                                               \
     *aResult = NULL;                                                          \
@@ -580,257 +584,79 @@ static NS_IMETHODIMP                    
     }                                                                         \
     rv = inst->QueryInterface(aIID, aResult);                                 \
                                                                               \
     return rv;                                                                \
 }                                                                             \
 
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsViewManager)
 
-static NS_IMETHODIMP
+static nsresult
 CreateHTMLImgElement(nsISupports* aOuter, REFNSIID aIID, void** aResult)
 {
   *aResult = nsnull;
   if (aOuter)
     return NS_ERROR_NO_AGGREGATION;
   // Note! NS_NewHTMLImageElement is special cased to handle a null nodeinfo
   nsIContent* inst = NS_NewHTMLImageElement(nsnull);
   nsresult rv = NS_ERROR_OUT_OF_MEMORY;
   if (inst) {
     NS_ADDREF(inst);
     rv = inst->QueryInterface(aIID, aResult);
     NS_RELEASE(inst);
   }
   return rv;
 }
 
-static NS_IMETHODIMP
-RegisterHTMLImgElement(nsIComponentManager *aCompMgr,
-                       nsIFile* aPath,
-                       const char* aRegistryLocation,
-                       const char* aComponentType,
-                       const nsModuleComponentInfo* aInfo)
-{
-  nsCOMPtr<nsICategoryManager> catman =
-    do_GetService(NS_CATEGORYMANAGER_CONTRACTID);
-
-  if (!catman)
-    return NS_ERROR_FAILURE;
-
-  nsXPIDLCString previous;
-  nsresult rv = catman->AddCategoryEntry(JAVASCRIPT_GLOBAL_CONSTRUCTOR_CATEGORY,
-                                         "Image", NS_HTMLIMGELEMENT_CONTRACTID,
-                                         PR_TRUE, PR_TRUE, getter_Copies(previous));
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  return catman->AddCategoryEntry(JAVASCRIPT_GLOBAL_CONSTRUCTOR_PROTO_ALIAS_CATEGORY,
-                                  "Image", "HTMLImageElement",
-                                  PR_TRUE, PR_TRUE, getter_Copies(previous));
-}
-
-static NS_IMETHODIMP
-UnregisterHTMLImgElement(nsIComponentManager* aCompMgr,
-                         nsIFile* aPath,
-                         const char* aRegistryLocation,
-                         const nsModuleComponentInfo* aInfo)
-{
-  // XXX remove category entry
-  return NS_OK;
-}
-
-static NS_IMETHODIMP
+static nsresult
 CreateHTMLOptionElement(nsISupports* aOuter, REFNSIID aIID, void** aResult)
 {
   *aResult = nsnull;
   if (aOuter)
     return NS_ERROR_NO_AGGREGATION;
   // Note! NS_NewHTMLOptionElement is special cased to handle a null nodeinfo
   nsIContent* inst = NS_NewHTMLOptionElement(nsnull);
   nsresult rv = NS_ERROR_OUT_OF_MEMORY;
   if (inst) {
     NS_ADDREF(inst);
     rv = inst->QueryInterface(aIID, aResult);
     NS_RELEASE(inst);
   }
   return rv;
 }
 
-static NS_IMETHODIMP
-RegisterHTMLOptionElement(nsIComponentManager *aCompMgr,
-                          nsIFile* aPath,
-                          const char* aRegistryLocation,
-                          const char* aComponentType,
-                          const nsModuleComponentInfo* aInfo)
-{
-  nsCOMPtr<nsICategoryManager> catman =
-    do_GetService(NS_CATEGORYMANAGER_CONTRACTID);
-
-  if (!catman)
-    return NS_ERROR_FAILURE;
-
-  nsXPIDLCString previous;
-  nsresult rv = catman->AddCategoryEntry(JAVASCRIPT_GLOBAL_CONSTRUCTOR_CATEGORY,
-                                         "Option", NS_HTMLOPTIONELEMENT_CONTRACTID,
-                                         PR_TRUE, PR_TRUE, getter_Copies(previous));
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  return catman->AddCategoryEntry(JAVASCRIPT_GLOBAL_CONSTRUCTOR_PROTO_ALIAS_CATEGORY,
-                                  "Option", "HTMLOptionElement",
-                                  PR_TRUE, PR_TRUE, getter_Copies(previous));
-}
-
-static NS_IMETHODIMP
-UnregisterHTMLOptionElement(nsIComponentManager* aCompMgr,
-                            nsIFile* aPath,
-                            const char* aRegistryLocation,
-                            const nsModuleComponentInfo* aInfo)
-{
-  // XXX remove category entry
-  return NS_OK;
-}
-
 #ifdef MOZ_MEDIA
-static NS_IMETHODIMP
+static nsresult
 CreateHTMLAudioElement(nsISupports* aOuter, REFNSIID aIID, void** aResult)
 {
   *aResult = nsnull;
   if (aOuter)
     return NS_ERROR_NO_AGGREGATION;
   // Note! NS_NewHTMLAudioElement is special cased to handle a null nodeinfo
   nsCOMPtr<nsIContent> inst(NS_NewHTMLAudioElement(nsnull));
   return inst ? inst->QueryInterface(aIID, aResult) : NS_ERROR_OUT_OF_MEMORY;
 }
-
-static NS_IMETHODIMP
-RegisterHTMLAudioElement(nsIComponentManager *aCompMgr,
-                         nsIFile* aPath,
-                         const char* aRegistryLocation,
-                         const char* aComponentType,
-                         const nsModuleComponentInfo* aInfo)
-{
-  nsCOMPtr<nsICategoryManager> catman =
-    do_GetService(NS_CATEGORYMANAGER_CONTRACTID);
-
-  if (!catman)
-    return NS_ERROR_FAILURE;
-
-  nsXPIDLCString previous;
-  nsresult rv = catman->AddCategoryEntry(JAVASCRIPT_GLOBAL_CONSTRUCTOR_CATEGORY,
-                                         "Audio", NS_HTMLAUDIOELEMENT_CONTRACTID,
-                                         PR_TRUE, PR_TRUE, getter_Copies(previous));
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  return catman->AddCategoryEntry(JAVASCRIPT_GLOBAL_CONSTRUCTOR_PROTO_ALIAS_CATEGORY,
-                                  "Audio", "HTMLAudioElement",
-                                  PR_TRUE, PR_TRUE, getter_Copies(previous));
-}
-
-static NS_IMETHODIMP
-UnregisterHTMLAudioElement(nsIComponentManager* aCompMgr,
-                           nsIFile* aPath,
-                           const char* aRegistryLocation,
-                           const nsModuleComponentInfo* aInfo)
-{
-  // XXX remove category entry
-  return NS_OK;
-}
 #endif
 
-static NS_METHOD
-RegisterDataDocumentContentPolicy(nsIComponentManager *aCompMgr,
-                                  nsIFile* aPath,
-                                  const char* aRegistryLocation,
-                                  const char* aComponentType,
-                                  const nsModuleComponentInfo* aInfo)
-{
-  nsresult rv;
-  nsCOMPtr<nsICategoryManager> catman =
-    do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  nsXPIDLCString previous;
-  return catman->AddCategoryEntry("content-policy",
-                                  NS_DATADOCUMENTCONTENTPOLICY_CONTRACTID,
-                                  NS_DATADOCUMENTCONTENTPOLICY_CONTRACTID,
-                                  PR_TRUE, PR_TRUE, getter_Copies(previous));
-}
-
-static NS_METHOD
-UnregisterDataDocumentContentPolicy(nsIComponentManager *aCompMgr,
-                                    nsIFile *aPath,
-                                    const char *registryLocation,
-                                    const nsModuleComponentInfo *info)
-{
-  nsresult rv;
-  nsCOMPtr<nsICategoryManager> catman =
-    do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  
-  return catman->DeleteCategoryEntry("content-policy",
-                                     NS_DATADOCUMENTCONTENTPOLICY_CONTRACTID,
-                                     PR_TRUE);
-}
-
-static NS_METHOD
-RegisterNoDataProtocolContentPolicy(nsIComponentManager *aCompMgr,
-                                    nsIFile* aPath,
-                                    const char* aRegistryLocation,
-                                    const char* aComponentType,
-                                    const nsModuleComponentInfo* aInfo)
-{
-  nsresult rv;
-  nsCOMPtr<nsICategoryManager> catman =
-    do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  nsXPIDLCString previous;
-  return catman->AddCategoryEntry("content-policy",
-                                  NS_NODATAPROTOCOLCONTENTPOLICY_CONTRACTID,
-                                  NS_NODATAPROTOCOLCONTENTPOLICY_CONTRACTID,
-                                  PR_TRUE, PR_TRUE, getter_Copies(previous));
-}
-
-static NS_METHOD
-UnregisterNoDataProtocolContentPolicy(nsIComponentManager *aCompMgr,
-                                      nsIFile *aPath,
-                                      const char *registryLocation,
-                                      const nsModuleComponentInfo *info)
-{
-  nsresult rv;
-  nsCOMPtr<nsICategoryManager> catman =
-    do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  
-  return catman->DeleteCategoryEntry("content-policy",
-                                     NS_NODATAPROTOCOLCONTENTPOLICY_CONTRACTID,
-                                     PR_TRUE);
-}
-
-static NS_METHOD
+static nsresult
 CreateWindowCommandTableConstructor(nsISupports *aOuter,
                                     REFNSIID aIID, void **aResult)
 {
   nsresult rv;
   nsCOMPtr<nsIControllerCommandTable> commandTable =
       do_CreateInstance(NS_CONTROLLERCOMMANDTABLE_CONTRACTID, &rv);
   if (NS_FAILED(rv)) return rv;
 
   rv = nsWindowCommandRegistration::RegisterWindowCommands(commandTable);
   if (NS_FAILED(rv)) return rv;
 
   return commandTable->QueryInterface(aIID, aResult);
 }
 
-static NS_METHOD
+static nsresult
 CreateWindowControllerWithSingletonCommandTable(nsISupports *aOuter,
                                       REFNSIID aIID, void **aResult)
 {
   nsresult rv;
   nsCOMPtr<nsIController> controller =
        do_CreateInstance("@mozilla.org/embedcomp/base-command-controller;1", &rv);
 
  if (NS_FAILED(rv)) return rv;
@@ -858,962 +684,479 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsBaseDOM
 
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsGeolocation, Init)
 
 #define NS_GEOLOCATION_SERVICE_CID \
   { 0x404d02a, 0x1CA, 0xAAAB, { 0x47, 0x62, 0x94, 0x4b, 0x1b, 0xf2, 0xf7, 0xb5 } }
 
 NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsGeolocationService, nsGeolocationService::GetGeolocationService)
 
-static NS_METHOD
-CSPServiceRegistration(nsIComponentManager *aCompMgr,
-                       nsIFile *aPath,
-                       const char *registryLocation,
-                       const char *componentType,
-                       const nsModuleComponentInfo *info)
-{
-  nsresult rv;
-  nsCOMPtr<nsIServiceManager> servman = do_QueryInterface((nsISupports*)aCompMgr, &rv);
-  if (NS_FAILED(rv))
-    return rv;
-
-  nsCOMPtr<nsICategoryManager> catman;
-  rv = servman->GetServiceByContractID(NS_CATEGORYMANAGER_CONTRACTID,
-                                       NS_GET_IID(nsICategoryManager),
-                                       getter_AddRefs(catman));
-  if (NS_FAILED(rv))
-    return rv;
-  
-  nsXPIDLCString previous;
-  rv = catman->AddCategoryEntry("content-policy",
-                                "CSPService",
-                                CSPSERVICE_CONTRACTID,
-                                PR_TRUE,
-                                PR_TRUE,
-                                getter_Copies(previous));
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  rv = catman->AddCategoryEntry("net-channel-event-sinks",
-                                "CSPService",
-                                CSPSERVICE_CONTRACTID,
-                                PR_TRUE,
-                                PR_TRUE,
-                                getter_Copies(previous));
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  return rv;
-}
-
-static NS_METHOD
-CSPServiceUnregistration(nsIComponentManager *aCompMgr,
-                         nsIFile *aPath,
-                         const char *registryLocation,
-                         const nsModuleComponentInfo *info){
-  nsresult rv;
-
-  nsCOMPtr<nsIServiceManager> servman = do_QueryInterface((nsISupports*)aCompMgr, &rv);
-  if (NS_FAILED(rv)) return rv;
-
-  nsCOMPtr<nsICategoryManager> catman;
-  rv = servman->GetServiceByContractID(NS_CATEGORYMANAGER_CONTRACTID,
-                                       NS_GET_IID(nsICategoryManager),
-                                       getter_AddRefs(catman));
-  if (NS_FAILED(rv)) return rv;
-
-  rv = catman->DeleteCategoryEntry("content-policy",
-                                   "CSPService",
-                                   PR_TRUE);
-
-  rv = catman->DeleteCategoryEntry("net-channel-event-sinks",
-                                   "CSPService",
-                                   PR_TRUE);
-
-  return rv;
-}
-
 NS_GENERIC_FACTORY_CONSTRUCTOR(CSPService)
 
-XPCONNECT_FACTORIES
-
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsPrincipal)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsSecurityNameSet)
 NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsSystemPrincipal,
     nsScriptSecurityManager::SystemPrincipalSingletonConstructor)
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsNullPrincipal, Init)
 
-NS_DECL_CLASSINFO(nsPrincipal)
-NS_DECL_CLASSINFO(nsSystemPrincipal)
-NS_DECL_CLASSINFO(nsNullPrincipal)
-
-static NS_IMETHODIMP
+static nsresult
 Construct_nsIScriptSecurityManager(nsISupports *aOuter, REFNSIID aIID, 
                                    void **aResult)
 {
     if (!aResult)
         return NS_ERROR_NULL_POINTER;
     *aResult = nsnull;
     if (aOuter)
         return NS_ERROR_NO_AGGREGATION;
     nsScriptSecurityManager *obj = nsScriptSecurityManager::GetScriptSecurityManager();
     if (!obj) 
         return NS_ERROR_OUT_OF_MEMORY;
     if (NS_FAILED(obj->QueryInterface(aIID, aResult)))
         return NS_ERROR_FAILURE;
     return NS_OK;
 }
 
-static NS_METHOD 
-RegisterSecurityNameSet(nsIComponentManager *aCompMgr,
-                        nsIFile *aPath,
-                        const char *registryLocation,
-                        const char *componentType,
-                        const nsModuleComponentInfo *info)
-{
-    nsresult rv = NS_OK;
-
-    nsCOMPtr<nsICategoryManager> catman =
-        do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
-
-    if (NS_FAILED(rv))
-        return rv;
-
-    nsXPIDLCString previous;
-    rv = catman->AddCategoryEntry(JAVASCRIPT_GLOBAL_STATIC_NAMESET_CATEGORY,
-                                  "PrivilegeManager",
-                                  NS_SECURITYNAMESET_CONTRACTID,
-                                  PR_TRUE, PR_TRUE, getter_Copies(previous));
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    rv = catman->AddCategoryEntry("app-startup", "Script Security Manager",
-                                  "service," NS_SCRIPTSECURITYMANAGER_CONTRACTID,
-                                  PR_TRUE, PR_TRUE,
-                                  getter_Copies(previous));
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    return rv;
-}
-
-// The list of components we register
-static const nsModuleComponentInfo gLayoutComponents[] = {
 #ifdef DEBUG
-  { "Frame utility",
-    NS_FRAME_UTIL_CID,
-    nsnull,
-    CreateNewFrameUtil },
-  { "Layout debugger",
-    NS_LAYOUT_DEBUGGER_CID,
-    nsnull,
-    CreateNewLayoutDebugger },
+NS_DEFINE_NAMED_CID(NS_FRAME_UTIL_CID);
+NS_DEFINE_NAMED_CID(NS_LAYOUT_DEBUGGER_CID);
+#endif
+NS_DEFINE_NAMED_CID(NS_FRAMETRAVERSAL_CID);
+NS_DEFINE_NAMED_CID(NS_PRESSHELL_CID);
+NS_DEFINE_NAMED_CID(NS_BOXOBJECT_CID);
+#ifdef MOZ_XUL
+NS_DEFINE_NAMED_CID(NS_LISTBOXOBJECT_CID);
+NS_DEFINE_NAMED_CID(NS_MENUBOXOBJECT_CID);
+NS_DEFINE_NAMED_CID(NS_POPUPBOXOBJECT_CID);
+NS_DEFINE_NAMED_CID(NS_CONTAINERBOXOBJECT_CID);
+NS_DEFINE_NAMED_CID(NS_SCROLLBOXOBJECT_CID);
+NS_DEFINE_NAMED_CID(NS_TREEBOXOBJECT_CID);
+#endif // MOZ_XUL
+#ifndef MOZ_NO_INSPECTOR_APIS
+#ifdef MOZ_XUL
+NS_DEFINE_NAMED_CID(IN_DOMVIEW_CID);
+#endif
+NS_DEFINE_NAMED_CID(IN_DEEPTREEWALKER_CID);
+NS_DEFINE_NAMED_CID(IN_FLASHER_CID);
+NS_DEFINE_NAMED_CID(IN_CSSVALUESEARCH_CID);
+NS_DEFINE_NAMED_CID(IN_DOMUTILS_CID);
+#endif // MOZ_NO_INSPECTOR_APIS
+NS_DEFINE_NAMED_CID(NS_NAMESPACEMANAGER_CID);
+NS_DEFINE_NAMED_CID(NS_EVENTLISTENERMANAGER_CID);
+NS_DEFINE_NAMED_CID(NS_DOMEVENTGROUP_CID);
+NS_DEFINE_NAMED_CID(NS_DOCUMENT_VIEWER_CID);
+NS_DEFINE_NAMED_CID(NS_HTMLDOCUMENT_CID);
+NS_DEFINE_NAMED_CID(NS_DOM_IMPLEMENTATION_CID);
+NS_DEFINE_NAMED_CID(NS_XMLDOCUMENT_CID);
+#ifdef MOZ_SVG
+NS_DEFINE_NAMED_CID(NS_SVGDOCUMENT_CID);
+#endif
+NS_DEFINE_NAMED_CID(NS_IMAGEDOCUMENT_CID);
+NS_DEFINE_NAMED_CID(NS_DOMSELECTION_CID);
+NS_DEFINE_NAMED_CID(NS_FRAMESELECTION_CID);
+NS_DEFINE_NAMED_CID(NS_RANGE_CID);
+NS_DEFINE_NAMED_CID(NS_RANGEUTILS_CID);
+NS_DEFINE_NAMED_CID(NS_CONTENTITERATOR_CID);
+NS_DEFINE_NAMED_CID(NS_PRECONTENTITERATOR_CID);
+NS_DEFINE_NAMED_CID(NS_SUBTREEITERATOR_CID);
+NS_DEFINE_NAMED_CID(NS_HTMLIMAGEELEMENT_CID);
+NS_DEFINE_NAMED_CID(NS_HTMLOPTIONELEMENT_CID);
+#ifdef MOZ_MEDIA
+NS_DEFINE_NAMED_CID(NS_HTMLAUDIOELEMENT_CID);
 #endif
+NS_DEFINE_NAMED_CID(NS_CANVASRENDERINGCONTEXT2D_CID);
+NS_DEFINE_NAMED_CID(NS_CANVASRENDERINGCONTEXTWEBGL_CID);
+NS_DEFINE_NAMED_CID(NS_TEXT_ENCODER_CID);
+NS_DEFINE_NAMED_CID(NS_HTMLCOPY_TEXT_ENCODER_CID);
+NS_DEFINE_NAMED_CID(NS_XMLCONTENTSERIALIZER_CID);
+NS_DEFINE_NAMED_CID(NS_XHTMLCONTENTSERIALIZER_CID);
+NS_DEFINE_NAMED_CID(NS_HTMLCONTENTSERIALIZER_CID);
+NS_DEFINE_NAMED_CID(NS_PLAINTEXTSERIALIZER_CID);
+NS_DEFINE_NAMED_CID(NS_HTMLFRAGMENTSINK_CID);
+NS_DEFINE_NAMED_CID(NS_HTMLFRAGMENTSINK2_CID);
+NS_DEFINE_NAMED_CID(NS_HTMLPARANOIDFRAGMENTSINK_CID);
+NS_DEFINE_NAMED_CID(MOZ_SANITIZINGHTMLSERIALIZER_CID);
+NS_DEFINE_NAMED_CID(NS_XMLFRAGMENTSINK_CID);
+NS_DEFINE_NAMED_CID(NS_XMLFRAGMENTSINK2_CID);
+NS_DEFINE_NAMED_CID(NS_XHTMLPARANOIDFRAGMENTSINK_CID);
+NS_DEFINE_NAMED_CID(NS_XBLSERVICE_CID);
+NS_DEFINE_NAMED_CID(NS_CONTENTPOLICY_CID);
+NS_DEFINE_NAMED_CID(NS_DATADOCUMENTCONTENTPOLICY_CID);
+NS_DEFINE_NAMED_CID(NS_NODATAPROTOCOLCONTENTPOLICY_CID);
+NS_DEFINE_NAMED_CID(NS_XULCONTROLLERS_CID);
+#ifdef MOZ_XUL
+NS_DEFINE_NAMED_CID(NS_XULSORTSERVICE_CID);
+NS_DEFINE_NAMED_CID(NS_XULTEMPLATEBUILDER_CID);
+NS_DEFINE_NAMED_CID(NS_XULTREEBUILDER_CID);
+NS_DEFINE_NAMED_CID(NS_XULPOPUPMANAGER_CID);
+NS_DEFINE_NAMED_CID(NS_XULDOCUMENT_CID);
+NS_DEFINE_NAMED_CID(NS_XULPROTOTYPECACHE_CID);
+#endif
+#ifdef MOZ_XTF
+NS_DEFINE_NAMED_CID(NS_XTFSERVICE_CID);
+NS_DEFINE_NAMED_CID(NS_XMLCONTENTBUILDER_CID);
+#endif
+NS_DEFINE_NAMED_CID(NS_CONTENT_DOCUMENT_LOADER_FACTORY_CID);
+NS_DEFINE_NAMED_CID(NS_WYCIWYGPROTOCOLHANDLER_CID);
+NS_DEFINE_NAMED_CID(NS_SYNCLOADDOMSERVICE_CID);
+NS_DEFINE_NAMED_CID(NS_DOM_SCRIPT_OBJECT_FACTORY_CID);
+NS_DEFINE_NAMED_CID(NS_BASE_DOM_EXCEPTION_CID);
+NS_DEFINE_NAMED_CID(NS_JSPROTOCOLHANDLER_CID);
+NS_DEFINE_NAMED_CID(NS_JSURI_CID);
+NS_DEFINE_NAMED_CID(NS_WINDOWCOMMANDTABLE_CID);
+NS_DEFINE_NAMED_CID(NS_WINDOWCONTROLLER_CID);
+NS_DEFINE_NAMED_CID(NS_VIEW_MANAGER_CID);
+NS_DEFINE_NAMED_CID(NS_PLUGINDOCLOADERFACTORY_CID);
+NS_DEFINE_NAMED_CID(NS_PLUGINDOCUMENT_CID);
+#ifdef MOZ_MEDIA
+NS_DEFINE_NAMED_CID(NS_VIDEODOCUMENT_CID);
+#endif
+NS_DEFINE_NAMED_CID(NS_STYLESHEETSERVICE_CID);
+NS_DEFINE_NAMED_CID(TRANSFORMIIX_XSLT_PROCESSOR_CID);
+NS_DEFINE_NAMED_CID(TRANSFORMIIX_XPATH_EVALUATOR_CID);
+NS_DEFINE_NAMED_CID(TRANSFORMIIX_XPATH1_SCHEME_CID);
+NS_DEFINE_NAMED_CID(TRANSFORMIIX_NODESET_CID);
+NS_DEFINE_NAMED_CID(NS_XMLSERIALIZER_CID);
+NS_DEFINE_NAMED_CID(NS_FILEREADER_CID);
+NS_DEFINE_NAMED_CID(NS_FORMDATA_CID);
+NS_DEFINE_NAMED_CID(NS_FILEDATAPROTOCOLHANDLER_CID);
+NS_DEFINE_NAMED_CID(NS_XMLHTTPREQUEST_CID);
+NS_DEFINE_NAMED_CID(NS_DOMPARSER_CID);
+NS_DEFINE_NAMED_CID(NS_DOMSTORAGE_CID);
+NS_DEFINE_NAMED_CID(NS_DOMSTORAGE2_CID);
+NS_DEFINE_NAMED_CID(NS_DOMSTORAGEMANAGER_CID);
+NS_DEFINE_NAMED_CID(NS_DOMJSON_CID);
+NS_DEFINE_NAMED_CID(NS_TEXTEDITOR_CID);
+#ifndef MOZILLA_PLAINTEXT_EDITOR_ONLY
+#ifdef ENABLE_EDITOR_API_LOG
+NS_DEFINE_NAMED_CID(NS_HTMLEDITOR_CID);
+#else
+NS_DEFINE_NAMED_CID(NS_HTMLEDITOR_CID);
+#endif
+#endif
+NS_DEFINE_NAMED_CID(NS_EDITORCONTROLLER_CID);
+NS_DEFINE_NAMED_CID(NS_EDITORCOMMANDTABLE_CID);
+#ifndef MOZILLA_PLAINTEXT_EDITOR_ONLY
+NS_DEFINE_NAMED_CID(NS_TEXTSERVICESDOCUMENT_CID);
+#endif
+NS_DEFINE_NAMED_CID(NS_GEOLOCATION_SERVICE_CID);
+NS_DEFINE_NAMED_CID(NS_GEOLOCATION_CID);
+NS_DEFINE_NAMED_CID(NS_FOCUSMANAGER_CID);
+NS_DEFINE_NAMED_CID(NS_ICONTENTUTILS_CID);
+NS_DEFINE_NAMED_CID(CSPSERVICE_CID);
+NS_DEFINE_NAMED_CID(NS_EVENTLISTENERSERVICE_CID);
+NS_DEFINE_NAMED_CID(NSCHANNELPOLICY_CID);
+NS_DEFINE_NAMED_CID(NS_SCRIPTSECURITYMANAGER_CID);
+NS_DEFINE_NAMED_CID(NS_PRINCIPAL_CID);
+NS_DEFINE_NAMED_CID(NS_SYSTEMPRINCIPAL_CID);
+NS_DEFINE_NAMED_CID(NS_NULLPRINCIPAL_CID);
+NS_DEFINE_NAMED_CID(NS_SECURITYNAMESET_CID);
 
-  { "Frame Traversal",
-    NS_FRAMETRAVERSAL_CID,
-    nsnull,
-    CreateNewFrameTraversal },
-
-  // XXX ick
-  { "Presentation shell",
-    NS_PRESSHELL_CID,
-    nsnull,
-    CreateNewPresShell },
-
-  // XXX end ick
-
-  { "Box Object",
-    NS_BOXOBJECT_CID,
-    "@mozilla.org/layout/xul-boxobject;1",
-    CreateNewBoxObject },
-
+static const mozilla::Module::CIDEntry kLayoutCIDs[] = {
+  XPCONNECT_CIDENTRIES
+#ifdef DEBUG
+  { &kNS_FRAME_UTIL_CID, false, NULL, CreateNewFrameUtil },
+  { &kNS_LAYOUT_DEBUGGER_CID, false, NULL, CreateNewLayoutDebugger },
+#endif
+  { &kNS_FRAMETRAVERSAL_CID, false, NULL, CreateNewFrameTraversal },
+  { &kNS_PRESSHELL_CID, false, NULL, CreateNewPresShell },
+  { &kNS_BOXOBJECT_CID, false, NULL, CreateNewBoxObject },
 #ifdef MOZ_XUL
-  { "XUL Listbox Box Object",
-    NS_LISTBOXOBJECT_CID,
-    "@mozilla.org/layout/xul-boxobject-listbox;1",
-    CreateNewListBoxObject },
-
-  { "XUL Menu Box Object",
-    NS_MENUBOXOBJECT_CID,
-    "@mozilla.org/layout/xul-boxobject-menu;1",
-    CreateNewMenuBoxObject },
-
-  { "XUL Popup Box Object",
-    NS_POPUPBOXOBJECT_CID,
-    "@mozilla.org/layout/xul-boxobject-popup;1",
-    CreateNewPopupBoxObject },
-
-  { "Container Box Object",
-    NS_CONTAINERBOXOBJECT_CID,
-    "@mozilla.org/layout/xul-boxobject-container;1",
-    CreateNewContainerBoxObject },
-
-  { "XUL ScrollBox Object",
-    NS_SCROLLBOXOBJECT_CID,
-    "@mozilla.org/layout/xul-boxobject-scrollbox;1",
-    CreateNewScrollBoxObject },
-
-  { "XUL Tree Box Object",
-    NS_TREEBOXOBJECT_CID,
-    "@mozilla.org/layout/xul-boxobject-tree;1",
-    CreateNewTreeBoxObject },
-
+  { &kNS_LISTBOXOBJECT_CID, false, NULL, CreateNewListBoxObject },
+  { &kNS_MENUBOXOBJECT_CID, false, NULL, CreateNewMenuBoxObject },
+  { &kNS_POPUPBOXOBJECT_CID, false, NULL, CreateNewPopupBoxObject },
+  { &kNS_CONTAINERBOXOBJECT_CID, false, NULL, CreateNewContainerBoxObject },
+  { &kNS_SCROLLBOXOBJECT_CID, false, NULL, CreateNewScrollBoxObject },
+  { &kNS_TREEBOXOBJECT_CID, false, NULL, CreateNewTreeBoxObject },
 #endif // MOZ_XUL
-
 #ifndef MOZ_NO_INSPECTOR_APIS
 #ifdef MOZ_XUL
-  { "DOM View",
-    IN_DOMVIEW_CID, 
-    "@mozilla.org/inspector/dom-view;1",
-    inDOMViewConstructor },
-#endif
-
-  { "Deep Tree Walker", 
-    IN_DEEPTREEWALKER_CID, 
-    "@mozilla.org/inspector/deep-tree-walker;1",
-    inDeepTreeWalkerConstructor },
-
-  { "Flasher", 
-    IN_FLASHER_CID, 
-    "@mozilla.org/inspector/flasher;1", 
-    inFlasherConstructor },
-
-  { "CSS Value Search", 
-    IN_CSSVALUESEARCH_CID, 
-    "@mozilla.org/inspector/search;1?type=cssvalue", 
-    inCSSValueSearchConstructor },
-
-  { "DOM Utils", 
-    IN_DOMUTILS_CID, 
-    "@mozilla.org/inspector/dom-utils;1", 
-    inDOMUtilsConstructor },
-
-
-#endif // MOZ_NO_INSPECTOR_APIS
-
-  { "Namespace manager",
-    NS_NAMESPACEMANAGER_CID,
-    NS_NAMESPACEMANAGER_CONTRACTID,
-    CreateNameSpaceManager },
-
-  { "Event listener manager",
-    NS_EVENTLISTENERMANAGER_CID,
-    nsnull,
-    CreateEventListenerManager },
-
-  { "DOM Event group",
-    NS_DOMEVENTGROUP_CID,
-    nsnull,
-    CreateDOMEventGroup },
-
-  { "Document Viewer",
-    NS_DOCUMENT_VIEWER_CID,
-    nsnull,
-    CreateDocumentViewer },
-
-  { "HTML document",
-    NS_HTMLDOCUMENT_CID,
-    nsnull,
-    CreateHTMLDocument },
-
-  { "DOM implementation",
-    NS_DOM_IMPLEMENTATION_CID,
-    nsnull,
-    CreateDOMImplementation },
-
-
-  { "XML document",
-    NS_XMLDOCUMENT_CID,
-    "@mozilla.org/xml/xml-document;1",
-    CreateXMLDocument },
-
-#ifdef MOZ_SVG
-  { "SVG document",
-    NS_SVGDOCUMENT_CID,
-    "@mozilla.org/svg/svg-document;1",
-    CreateSVGDocument },
+  { &kIN_DOMVIEW_CID, false, NULL, inDOMViewConstructor },
 #endif
-
-  { "Image document",
-    NS_IMAGEDOCUMENT_CID,
-    nsnull,
-    CreateImageDocument },
-
-  { "Dom selection",
-    NS_DOMSELECTION_CID,
-    "@mozilla.org/content/dom-selection;1",
-    CreateDOMSelection },
-
-  { "Frame selection",
-    NS_FRAMESELECTION_CID,
-    nsnull,
-    CreateSelection },
-
-  { "Range",
-    NS_RANGE_CID,
-    "@mozilla.org/content/range;1",
-    CreateRange },
-
-  { "Range Utils",
-    NS_RANGEUTILS_CID,
-    "@mozilla.org/content/range-utils;1",
-    CreateRangeUtils },
-
-  { "Content iterator",
-    NS_CONTENTITERATOR_CID,
-    "@mozilla.org/content/post-content-iterator;1",
-    CreateContentIterator },
-
-  { "Pre Content iterator",
-    NS_PRECONTENTITERATOR_CID,
-    "@mozilla.org/content/pre-content-iterator;1",
-    CreatePreContentIterator },
-
-  { "Subtree iterator",
-    NS_SUBTREEITERATOR_CID,
-    "@mozilla.org/content/subtree-content-iterator;1",
-    CreateSubtreeIterator },
-
-  // Needed to support "new Option;", "new Image;" and "new Audio;" in JavaScript
-  { "HTML img element",
-    NS_HTMLIMAGEELEMENT_CID,
-    NS_HTMLIMGELEMENT_CONTRACTID,
-    CreateHTMLImgElement,
-    RegisterHTMLImgElement, 
-    UnregisterHTMLImgElement },
-
-  { "HTML option element",
-    NS_HTMLOPTIONELEMENT_CID,
-    NS_HTMLOPTIONELEMENT_CONTRACTID,
-    CreateHTMLOptionElement,
-    RegisterHTMLOptionElement,
-    UnregisterHTMLOptionElement },
-
-#ifdef MOZ_MEDIA
-  { "HTML audio element",
-    NS_HTMLAUDIOELEMENT_CID,
-    NS_HTMLAUDIOELEMENT_CONTRACTID,
-    CreateHTMLAudioElement,
-    RegisterHTMLAudioElement,
-    UnregisterHTMLAudioElement },
+  { &kIN_DEEPTREEWALKER_CID, false, NULL, inDeepTreeWalkerConstructor },
+  { &kIN_FLASHER_CID, false, NULL, inFlasherConstructor },
+  { &kIN_CSSVALUESEARCH_CID, false, NULL, inCSSValueSearchConstructor },
+  { &kIN_DOMUTILS_CID, false, NULL, inDOMUtilsConstructor },
+#endif // MOZ_NO_INSPECTOR_APIS
+  { &kNS_NAMESPACEMANAGER_CID, false, NULL, CreateNameSpaceManager },
+  { &kNS_EVENTLISTENERMANAGER_CID, false, NULL, CreateEventListenerManager },
+  { &kNS_DOMEVENTGROUP_CID, false, NULL, CreateDOMEventGroup },
+  { &kNS_DOCUMENT_VIEWER_CID, false, NULL, CreateDocumentViewer },
+  { &kNS_HTMLDOCUMENT_CID, false, NULL, CreateHTMLDocument },
+  { &kNS_DOM_IMPLEMENTATION_CID, false, NULL, CreateDOMImplementation },
+  { &kNS_XMLDOCUMENT_CID, false, NULL, CreateXMLDocument },
+#ifdef MOZ_SVG
+  { &kNS_SVGDOCUMENT_CID, false, NULL, CreateSVGDocument },
 #endif
-
-  { "Canvas 2D Rendering Context",
-    NS_CANVASRENDERINGCONTEXT2D_CID,
-    "@mozilla.org/content/canvas-rendering-context;1?id=2d",
-    CreateCanvasRenderingContext2D },
-  { "Canvas WebGL Rendering Context",
-    NS_CANVASRENDERINGCONTEXTWEBGL_CID,
-    "@mozilla.org/content/canvas-rendering-context;1?id=moz-webgl",
-    CreateCanvasRenderingContextWebGL },
-  { "Canvas WebGL Rendering Context",
-    NS_CANVASRENDERINGCONTEXTWEBGL_CID,
-    "@mozilla.org/content/canvas-rendering-context;1?id=experimental-webgl",
-    CreateCanvasRenderingContextWebGL },
-
-
-  { "XML document encoder",
-    NS_TEXT_ENCODER_CID,
-    NS_DOC_ENCODER_CONTRACTID_BASE "text/xml",
-    CreateTextEncoder },
-
-  { "XML document encoder",
-    NS_TEXT_ENCODER_CID,
-    NS_DOC_ENCODER_CONTRACTID_BASE "application/xml",
-    CreateTextEncoder },
-
-  { "XHTML document encoder",
-    NS_TEXT_ENCODER_CID,
-    NS_DOC_ENCODER_CONTRACTID_BASE "application/xhtml+xml",
-    CreateTextEncoder },
-
-#ifdef MOZ_SVG
-  { "SVG document encoder",
-    NS_TEXT_ENCODER_CID,
-    NS_DOC_ENCODER_CONTRACTID_BASE "image/svg+xml",
-    CreateTextEncoder },
-#endif
-
-  { "HTML document encoder",
-    NS_TEXT_ENCODER_CID,
-    NS_DOC_ENCODER_CONTRACTID_BASE "text/html",
-    CreateTextEncoder },
-
-  { "Plaintext document encoder",
-    NS_TEXT_ENCODER_CID,
-    NS_DOC_ENCODER_CONTRACTID_BASE "text/plain",
-    CreateTextEncoder },
-
-  { "HTML copy encoder",
-    NS_HTMLCOPY_TEXT_ENCODER_CID,
-    NS_HTMLCOPY_ENCODER_CONTRACTID,
-    CreateHTMLCopyTextEncoder },
-
-  { "XML content serializer",
-    NS_XMLCONTENTSERIALIZER_CID,
-    NS_CONTENTSERIALIZER_CONTRACTID_PREFIX "text/xml",
-    CreateXMLContentSerializer },
-
-  { "XML content serializer",
-    NS_XMLCONTENTSERIALIZER_CID,
-    NS_CONTENTSERIALIZER_CONTRACTID_PREFIX "application/xml",
-    CreateXMLContentSerializer },
-
-  { "XHTML content serializer",
-    NS_XHTMLCONTENTSERIALIZER_CID,
-    NS_CONTENTSERIALIZER_CONTRACTID_PREFIX "application/xhtml+xml",
-    CreateXHTMLContentSerializer },
-
-#ifdef MOZ_SVG
-  { "SVG content serializer",
-    NS_XMLCONTENTSERIALIZER_CID,
-    NS_CONTENTSERIALIZER_CONTRACTID_PREFIX "image/svg+xml",
-    CreateXMLContentSerializer },
+  { &kNS_IMAGEDOCUMENT_CID, false, NULL, CreateImageDocument },
+  { &kNS_DOMSELECTION_CID, false, NULL, CreateDOMSelection },
+  { &kNS_FRAMESELECTION_CID, false, NULL, CreateSelection },
+  { &kNS_RANGE_CID, false, NULL, CreateRange },
+  { &kNS_RANGEUTILS_CID, false, NULL, CreateRangeUtils },
+  { &kNS_CONTENTITERATOR_CID, false, NULL, CreateContentIterator },
+  { &kNS_PRECONTENTITERATOR_CID, false, NULL, CreatePreContentIterator },
+  { &kNS_SUBTREEITERATOR_CID, false, NULL, CreateSubtreeIterator },
+  { &kNS_HTMLIMAGEELEMENT_CID, false, NULL, CreateHTMLImgElement },
+  { &kNS_HTMLOPTIONELEMENT_CID, false, NULL, CreateHTMLOptionElement },
+#ifdef MOZ_MEDIA
+  { &kNS_HTMLAUDIOELEMENT_CID, false, NULL, CreateHTMLAudioElement },
 #endif
-
-  { "HTML content serializer",
-    NS_HTMLCONTENTSERIALIZER_CID,
-    NS_CONTENTSERIALIZER_CONTRACTID_PREFIX "text/html",
-    CreateHTMLContentSerializer },
-
-  { "XUL content serializer",
-    NS_XMLCONTENTSERIALIZER_CID,
-    NS_CONTENTSERIALIZER_CONTRACTID_PREFIX "application/vnd.mozilla.xul+xml",
-    CreateXMLContentSerializer },
-
-  { "plaintext content serializer",
-    NS_PLAINTEXTSERIALIZER_CID,
-    NS_CONTENTSERIALIZER_CONTRACTID_PREFIX "text/plain",
-    CreatePlainTextSerializer },
-
-  { "plaintext sink",
-    NS_PLAINTEXTSERIALIZER_CID,
-    NS_PLAINTEXTSINK_CONTRACTID,
-    CreatePlainTextSerializer },
-
-  { "html fragment sink",
-    NS_HTMLFRAGMENTSINK_CID,
-    NS_HTMLFRAGMENTSINK_CONTRACTID,
-    CreateHTMLFragmentSink },
-
-  { "html fragment sink 2",
-    NS_HTMLFRAGMENTSINK2_CID,
-    NS_HTMLFRAGMENTSINK2_CONTRACTID,
-    CreateHTMLFragmentSink2 },
-
-  { "html paranoid fragment sink",
-    NS_HTMLPARANOIDFRAGMENTSINK_CID,
-    NS_HTMLPARANOIDFRAGMENTSINK_CONTRACTID,
-    CreateHTMLParanoidFragmentSink },
-
-  { "HTML sanitizing content serializer",
-    MOZ_SANITIZINGHTMLSERIALIZER_CID,
-    MOZ_SANITIZINGHTMLSERIALIZER_CONTRACTID,
-    CreateSanitizingHTMLSerializer },
-
-  { "xml fragment sink",
-    NS_XMLFRAGMENTSINK_CID,
-    NS_XMLFRAGMENTSINK_CONTRACTID,
-    CreateXMLFragmentSink },
-
-  { "xml fragment sink 2",
-    NS_XMLFRAGMENTSINK2_CID,
-    NS_XMLFRAGMENTSINK2_CONTRACTID,
-    CreateXMLFragmentSink2 },
-
-  { "xhtml paranoid fragment sink",
-    NS_XHTMLPARANOIDFRAGMENTSINK_CID,
-    NS_XHTMLPARANOIDFRAGMENTSINK_CONTRACTID,
-    CreateXHTMLParanoidFragmentSink },
-
-  { "XBL Service",
-    NS_XBLSERVICE_CID,
-    "@mozilla.org/xbl;1",
-    CreateXBLService },
-
-  { "Content policy service",
-    NS_CONTENTPOLICY_CID,
-    NS_CONTENTPOLICY_CONTRACTID,
-    CreateContentPolicy },
-
-  { "Data document content policy",
-    NS_DATADOCUMENTCONTENTPOLICY_CID,
-    NS_DATADOCUMENTCONTENTPOLICY_CONTRACTID,
-    nsDataDocumentContentPolicyConstructor,
-    RegisterDataDocumentContentPolicy,
-    UnregisterDataDocumentContentPolicy },
-
-  { "No data protocol content policy",
-    NS_NODATAPROTOCOLCONTENTPOLICY_CID,
-    NS_NODATAPROTOCOLCONTENTPOLICY_CONTRACTID,
-    nsNoDataProtocolContentPolicyConstructor,
-    RegisterNoDataProtocolContentPolicy,
-    UnregisterNoDataProtocolContentPolicy },
-
-  { "XUL Controllers",
-    NS_XULCONTROLLERS_CID,
-    "@mozilla.org/xul/xul-controllers;1",
-    NS_NewXULControllers },
-
+  { &kNS_CANVASRENDERINGCONTEXT2D_CID, false, NULL, CreateCanvasRenderingContext2D },
+  { &kNS_CANVASRENDERINGCONTEXTWEBGL_CID, false, NULL, CreateCanvasRenderingContextWebGL },
+  { &kNS_TEXT_ENCODER_CID, false, NULL, CreateTextEncoder },
+  { &kNS_HTMLCOPY_TEXT_ENCODER_CID, false, NULL, CreateHTMLCopyTextEncoder },
+  { &kNS_XMLCONTENTSERIALIZER_CID, false, NULL, CreateXMLContentSerializer },
+  { &kNS_HTMLCONTENTSERIALIZER_CID, false, NULL, CreateHTMLContentSerializer },
+  { &kNS_XHTMLCONTENTSERIALIZER_CID, false, NULL, CreateXHTMLContentSerializer },
+  { &kNS_PLAINTEXTSERIALIZER_CID, false, NULL, CreatePlainTextSerializer },
+  { &kNS_HTMLFRAGMENTSINK_CID, false, NULL, CreateHTMLFragmentSink },
+  { &kNS_HTMLFRAGMENTSINK2_CID, false, NULL, CreateHTMLFragmentSink2 },
+  { &kNS_HTMLPARANOIDFRAGMENTSINK_CID, false, NULL, CreateHTMLParanoidFragmentSink },
+  { &kMOZ_SANITIZINGHTMLSERIALIZER_CID, false, NULL, CreateSanitizingHTMLSerializer },
+  { &kNS_XMLFRAGMENTSINK_CID, false, NULL, CreateXMLFragmentSink },
+  { &kNS_XMLFRAGMENTSINK2_CID, false, NULL, CreateXMLFragmentSink2 },
+  { &kNS_XHTMLPARANOIDFRAGMENTSINK_CID, false, NULL, CreateXHTMLParanoidFragmentSink },
+  { &kNS_XBLSERVICE_CID, false, NULL, CreateXBLService },
+  { &kNS_CONTENTPOLICY_CID, false, NULL, CreateContentPolicy },
+  { &kNS_DATADOCUMENTCONTENTPOLICY_CID, false, NULL, nsDataDocumentContentPolicyConstructor },
+  { &kNS_NODATAPROTOCOLCONTENTPOLICY_CID, false, NULL, nsNoDataProtocolContentPolicyConstructor },
+  { &kNS_XULCONTROLLERS_CID, false, NULL, NS_NewXULControllers },
 #ifdef MOZ_XUL
-  { "XUL Sort Service",
-    NS_XULSORTSERVICE_CID,
-    "@mozilla.org/xul/xul-sort-service;1",
-    CreateXULSortService },
-
-  { "XUL Template Builder",
-    NS_XULTEMPLATEBUILDER_CID,
-    "@mozilla.org/xul/xul-template-builder;1",
-    NS_NewXULContentBuilder },
-
-  { "XUL Tree Builder",
-    NS_XULTREEBUILDER_CID,
-    "@mozilla.org/xul/xul-tree-builder;1",
-    NS_NewXULTreeBuilder },
-
-  { "XUL Popup Manager",
-    NS_XULPOPUPMANAGER_CID,
-    "@mozilla.org/xul/xul-popup-manager;1",
-    CreateXULPopupManager },
-
-  { "XUL Document",
-    NS_XULDOCUMENT_CID,
-    "@mozilla.org/xul/xul-document;1",
-    CreateXULDocument },
-
-  { "XUL Prototype Cache",
-    NS_XULPROTOTYPECACHE_CID,
-    "@mozilla.org/xul/xul-prototype-cache;1",
-    NS_NewXULPrototypeCache },
-
+  { &kNS_XULSORTSERVICE_CID, false, NULL, CreateXULSortService },
+  { &kNS_XULTEMPLATEBUILDER_CID, false, NULL, NS_NewXULContentBuilder },
+  { &kNS_XULTREEBUILDER_CID, false, NULL, NS_NewXULTreeBuilder },
+  { &kNS_XULPOPUPMANAGER_CID, false, NULL, CreateXULPopupManager },
+  { &kNS_XULDOCUMENT_CID, false, NULL, CreateXULDocument },
+  { &kNS_XULPROTOTYPECACHE_CID, false, NULL, NS_NewXULPrototypeCache },
 #endif
-
 #ifdef MOZ_XTF
-  { "XTF Service",
-    NS_XTFSERVICE_CID,
-    NS_XTFSERVICE_CONTRACTID,
-    CreateXTFService },
-
-  { "XML Content Builder",
-    NS_XMLCONTENTBUILDER_CID,
-    NS_XMLCONTENTBUILDER_CONTRACTID,
-    CreateXMLContentBuilder },
+  { &kNS_XTFSERVICE_CID, false, NULL, CreateXTFService },
+  { &kNS_XMLCONTENTBUILDER_CID, false, NULL, CreateXMLContentBuilder },
 #endif
-
-  { "Document Loader Factory",
-    NS_CONTENT_DOCUMENT_LOADER_FACTORY_CID,
-    CONTENT_DLF_CONTRACTID,
-    CreateContentDLF,
-    nsContentDLF::RegisterDocumentFactories,
-    nsContentDLF::UnregisterDocumentFactories },
-
-  { "Wyciwyg Handler",
-    NS_WYCIWYGPROTOCOLHANDLER_CID,
-    NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "wyciwyg",
-    nsWyciwygProtocolHandlerConstructor },
-
-  { "SyncLoad DOM Service",
-    NS_SYNCLOADDOMSERVICE_CID,
-    NS_SYNCLOADDOMSERVICE_CONTRACTID,
-    nsSyncLoadServiceConstructor },
-
-  // DOM objects
-  { "Script Object Factory",
-    NS_DOM_SCRIPT_OBJECT_FACTORY_CID,
-    nsnull,
-    nsDOMScriptObjectFactoryConstructor
-  },
-  { "Base DOM Exception",
-    NS_BASE_DOM_EXCEPTION_CID,
-    nsnull,
-    nsBaseDOMExceptionConstructor
-  },
-  { "JavaScript Protocol Handler",
-    NS_JSPROTOCOLHANDLER_CID,
-    NS_JSPROTOCOLHANDLER_CONTRACTID,
-    nsJSProtocolHandler::Create },
-  { "JavaScript URI",
-    NS_JSURI_CID,
-    nsnull,
-    nsJSURIConstructor },
-  { "Window Command Table",
-    NS_WINDOWCOMMANDTABLE_CID,
-    "",
-    CreateWindowCommandTableConstructor
-  },
-  { "Window Command Controller",
-    NS_WINDOWCONTROLLER_CID,
-    NS_WINDOWCONTROLLER_CONTRACTID,
-    CreateWindowControllerWithSingletonCommandTable
-  },
-
-  // view stuff
-  { "View Manager", NS_VIEW_MANAGER_CID, "@mozilla.org/view-manager;1",
-    nsViewManagerConstructor },
-
-  { "Plugin Document Loader Factory",
-    NS_PLUGINDOCLOADERFACTORY_CID,
-    PLUGIN_DLF_CONTRACTID,
-    CreateContentDLF },
-
-  { "Plugin Document",
-    NS_PLUGINDOCUMENT_CID,
-    nsnull,
-    CreatePluginDocument },
-
+  { &kNS_CONTENT_DOCUMENT_LOADER_FACTORY_CID, false, NULL },
+  { &kNS_WYCIWYGPROTOCOLHANDLER_CID, false, NULL, nsWyciwygProtocolHandlerConstructor },
+  { &kNS_SYNCLOADDOMSERVICE_CID, false, NULL, nsSyncLoadServiceConstructor },
+  { &kNS_DOM_SCRIPT_OBJECT_FACTORY_CID, false, NULL, nsDOMScriptObjectFactoryConstructor },
+  { &kNS_BASE_DOM_EXCEPTION_CID, false, NULL, nsBaseDOMExceptionConstructor },
+  { &kNS_JSPROTOCOLHANDLER_CID, false, NULL, nsJSProtocolHandler::Create },
+  { &kNS_JSURI_CID, false, NULL, nsJSURIConstructor },
+  { &kNS_WINDOWCOMMANDTABLE_CID, false, NULL, CreateWindowCommandTableConstructor },
+  { &kNS_WINDOWCONTROLLER_CID, false, NULL, CreateWindowControllerWithSingletonCommandTable },
+  { &kNS_VIEW_MANAGER_CID, false, NULL, nsViewManagerConstructor },
+  { &kNS_PLUGINDOCLOADERFACTORY_CID, false, NULL, CreateContentDLF },
+  { &kNS_PLUGINDOCUMENT_CID, false, NULL, CreatePluginDocument },
 #ifdef MOZ_MEDIA
-  { "Video Document",
-    NS_VIDEODOCUMENT_CID,
-    nsnull,
-    CreateVideoDocument },
+  { &kNS_VIDEODOCUMENT_CID, false, NULL, CreateVideoDocument },
 #endif
-
-  { "Style sheet service",
-    NS_STYLESHEETSERVICE_CID,
-    NS_STYLESHEETSERVICE_CONTRACTID,
-    nsStyleSheetServiceConstructor },
-
-  // transformiix
-
-  { "XSLTProcessor",
-    TRANSFORMIIX_XSLT_PROCESSOR_CID,
-    TRANSFORMIIX_XSLT_PROCESSOR_CONTRACTID,
-    txMozillaXSLTProcessorConstructor },
-
-  { "XPathEvaluator",
-    TRANSFORMIIX_XPATH_EVALUATOR_CID,
-    NS_XPATH_EVALUATOR_CONTRACTID,
-    nsXPathEvaluatorConstructor },
-
-  { "XPath1 XPointer Scheme Processor",
-    TRANSFORMIIX_XPATH1_SCHEME_CID,
-    NS_XPOINTER_SCHEME_PROCESSOR_BASE "xpath1",
-    nsXPath1SchemeProcessorConstructor },
-
-  { "Transformiix NodeSet",
-    TRANSFORMIIX_NODESET_CID,
-    TRANSFORMIIX_NODESET_CONTRACTID,
-    txNodeSetAdaptorConstructor },
-
-  { "XML Serializer",
-    NS_XMLSERIALIZER_CID,
-    NS_XMLSERIALIZER_CONTRACTID,
-    nsDOMSerializerConstructor },
-
-  { "FileReader",
-    NS_FILEREADER_CID,
-    NS_FILEREADER_CONTRACTID,
-    nsDOMFileReaderConstructor },
-
-  { "FormData",
-    NS_FORMDATA_CID,
-    NS_FORMDATA_CONTRACTID,
-    nsFormDataConstructor },
-
-  { "FileData Protocol Handler",
-    NS_FILEDATAPROTOCOLHANDLER_CID,
-    NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX FILEDATA_SCHEME,
-    nsFileDataProtocolHandlerConstructor },
-
-  { "XMLHttpRequest",
-    NS_XMLHTTPREQUEST_CID,
-    NS_XMLHTTPREQUEST_CONTRACTID,
-    nsXMLHttpRequestConstructor },
-
-  { "DOM Parser",
-    NS_DOMPARSER_CID,
-    NS_DOMPARSER_CONTRACTID,
-    nsDOMParserConstructor },
-
-  { "DOM Storage",
-    NS_DOMSTORAGE_CID,
-    "@mozilla.org/dom/storage;1",
-    NS_NewDOMStorage },
-
-  { "DOM Storage 2",
-    NS_DOMSTORAGE2_CID,
-    "@mozilla.org/dom/storage;2",
-    NS_NewDOMStorage2 },
-
-  { "DOM Storage Manager",
-    NS_DOMSTORAGEMANAGER_CID,
-    "@mozilla.org/dom/storagemanager;1",
-    nsDOMStorageManagerConstructor },
-
-  { "DOM JSON",
-    NS_DOMJSON_CID,
-    "@mozilla.org/dom/json;1",
-    NS_NewJSON },
-
-  { "Text Editor",
-    NS_TEXTEDITOR_CID,
-    "@mozilla.org/editor/texteditor;1",
-    nsPlaintextEditorConstructor },
-
+  { &kNS_STYLESHEETSERVICE_CID, false, NULL, nsStyleSheetServiceConstructor },
+  { &kTRANSFORMIIX_XSLT_PROCESSOR_CID, false, NULL, txMozillaXSLTProcessorConstructor },
+  { &kTRANSFORMIIX_XPATH_EVALUATOR_CID, false, NULL, nsXPathEvaluatorConstructor },
+  { &kTRANSFORMIIX_XPATH1_SCHEME_CID, false, NULL, nsXPath1SchemeProcessorConstructor },
+  { &kTRANSFORMIIX_NODESET_CID, false, NULL, txNodeSetAdaptorConstructor },
+  { &kNS_XMLSERIALIZER_CID, false, NULL, nsDOMSerializerConstructor },
+  { &kNS_FILEREADER_CID, false, NULL, nsDOMFileReaderConstructor },
+  { &kNS_FORMDATA_CID, false, NULL, nsFormDataConstructor },
+  { &kNS_FILEDATAPROTOCOLHANDLER_CID, false, NULL, nsFileDataProtocolHandlerConstructor },
+  { &kNS_XMLHTTPREQUEST_CID, false, NULL, nsXMLHttpRequestConstructor },
+  { &kNS_DOMPARSER_CID, false, NULL, nsDOMParserConstructor },
+  { &kNS_DOMSTORAGE_CID, false, NULL, NS_NewDOMStorage },
+  { &kNS_DOMSTORAGE2_CID, false, NULL, NS_NewDOMStorage2 },
+  { &kNS_DOMSTORAGEMANAGER_CID, false, NULL, nsDOMStorageManagerConstructor },
+  { &kNS_DOMJSON_CID, false, NULL, NS_NewJSON },
+  { &kNS_TEXTEDITOR_CID, false, NULL, nsPlaintextEditorConstructor },
 #ifndef MOZILLA_PLAINTEXT_EDITOR_ONLY
 #ifdef ENABLE_EDITOR_API_LOG
-    { "HTML Editor",
-      NS_HTMLEDITOR_CID,
-      "@mozilla.org/editor/htmleditor;1",
-      nsHTMLEditorLogConstructor },
+  { &kNS_HTMLEDITOR_CID, false, NULL, nsHTMLEditorLogConstructor },
 #else
-    { "HTML Editor",
-      NS_HTMLEDITOR_CID,
-      "@mozilla.org/editor/htmleditor;1",
-      nsHTMLEditorConstructor },
+  { &kNS_HTMLEDITOR_CID, false, NULL, nsHTMLEditorConstructor },
 #endif
 #endif
-
-    { "Editor Controller",
-      NS_EDITORCONTROLLER_CID,
-      "@mozilla.org/editor/editorcontroller;1",
-      nsEditorControllerConstructor },
-
-    { "Editor Command Table",
-      NS_EDITORCOMMANDTABLE_CID,
-      "",   // no point in using a contract ID
-      nsEditorCommandTableConstructor },
-
+  { &kNS_EDITORCONTROLLER_CID, false, NULL, nsEditorControllerConstructor },
+  { &kNS_EDITORCOMMANDTABLE_CID, false, NULL, nsEditorCommandTableConstructor },
 #ifndef MOZILLA_PLAINTEXT_EDITOR_ONLY
-    { NULL,
-      NS_TEXTSERVICESDOCUMENT_CID,
-      "@mozilla.org/textservices/textservicesdocument;1",
-      nsTextServicesDocumentConstructor },
+  { &kNS_TEXTSERVICESDOCUMENT_CID, false, NULL, nsTextServicesDocumentConstructor },
 #endif
-
-    { "Geolocation Service",
-      NS_GEOLOCATION_SERVICE_CID,
-      "@mozilla.org/geolocation/service;1",
-      nsGeolocationServiceConstructor },
-
-    { "Geolocation",
-      NS_GEOLOCATION_CID,
-      "@mozilla.org/geolocation;1",
-      nsGeolocationConstructor },
-
-    { "Focus Manager",
-      NS_FOCUSMANAGER_CID,
-      "@mozilla.org/focus-manager;1",
-      CreateFocusManager },
-
-    { "Content Utils",
-      NS_ICONTENTUTILS_CID,
-      "@mozilla.org/content/contentutils;1",
-      nsIContentUtilsConstructor },
-
-    { "Content Security Policy Service",
-      CSPSERVICE_CID,
-      CSPSERVICE_CONTRACTID,
-      CSPServiceConstructor,
-      CSPServiceRegistration,
-      CSPServiceUnregistration },
-
-    { "Event Listener Service",
-      NS_EVENTLISTENERSERVICE_CID,
-      NS_EVENTLISTENERSERVICE_CONTRACTID,
-      CreateEventListenerService },
-
-    { "Global Message Manager",
-      NS_GLOBALMESSAGEMANAGER_CID,
-      NS_GLOBALMESSAGEMANAGER_CONTRACTID,
-      CreateGlobalMessageManager },
-
-    { "Channel Policy",
-      NSCHANNELPOLICY_CID,
-      NSCHANNELPOLICY_CONTRACTID,
-      nsChannelPolicyConstructor }
-};
-
-static nsModuleInfo const kLayoutModuleInfo = {
-    NS_MODULEINFO_VERSION,
-    "nsLayoutModule",
-    gLayoutComponents,
-    (sizeof(gLayoutComponents) / sizeof(gLayoutComponents[0])),
-    Initialize,
-    nsnull
+  { &kNS_GEOLOCATION_SERVICE_CID, false, NULL, nsGeolocationServiceConstructor },
+  { &kNS_GEOLOCATION_CID, false, NULL, nsGeolocationConstructor },
+  { &kNS_FOCUSMANAGER_CID, false, NULL, CreateFocusManager },
+  { &kNS_ICONTENTUTILS_CID, false, NULL, nsIContentUtilsConstructor },
+  { &kCSPSERVICE_CID, false, NULL, CSPServiceConstructor },
+  { &kNS_EVENTLISTENERSERVICE_CID, false, NULL, CreateEventListenerService },
+  { &kNSCHANNELPOLICY_CID, false, NULL, nsChannelPolicyConstructor },
+  { &kNS_SCRIPTSECURITYMANAGER_CID, false, NULL, Construct_nsIScriptSecurityManager },
+  { &kNS_PRINCIPAL_CID, false, NULL, nsPrincipalConstructor },
+  { &kNS_SYSTEMPRINCIPAL_CID, false, NULL, nsSystemPrincipalConstructor },
+  { &kNS_NULLPRINCIPAL_CID, false, NULL, nsNullPrincipalConstructor },
+  { &kNS_SECURITYNAMESET_CID, false, NULL, nsSecurityNameSetConstructor },
+  { NULL }
 };
 
-static const nsModuleComponentInfo gXPConnectComponents[] = {
-    XPCONNECT_COMPONENTS,
-
-    { NS_SCRIPTSECURITYMANAGER_CLASSNAME, 
-      NS_SCRIPTSECURITYMANAGER_CID, 
-      NS_SCRIPTSECURITYMANAGER_CONTRACTID,
-      Construct_nsIScriptSecurityManager,
-      RegisterSecurityNameSet,
-      nsnull,
-      nsnull,
-      nsnull,
-      nsnull,
-      nsnull,
-      nsIClassInfo::MAIN_THREAD_ONLY
-    },
-
-    { NS_SCRIPTSECURITYMANAGER_CLASSNAME,
-      NS_SCRIPTSECURITYMANAGER_CID,
-      NS_GLOBAL_CHANNELEVENTSINK_CONTRACTID,
-      Construct_nsIScriptSecurityManager,
-      RegisterSecurityNameSet,
-      nsnull,
-      nsnull,
-      nsnull,
-      nsnull,
-      nsnull,
-      nsIClassInfo::MAIN_THREAD_ONLY
-    },
-
-
-
-    { NS_PRINCIPAL_CLASSNAME, 
-      NS_PRINCIPAL_CID, 
-      NS_PRINCIPAL_CONTRACTID,
-      nsPrincipalConstructor,
-      nsnull,
-      nsnull,
-      nsnull,
-      NS_CI_INTERFACE_GETTER_NAME(nsPrincipal),
-      nsnull,
-      &NS_CLASSINFO_NAME(nsPrincipal),
-      nsIClassInfo::MAIN_THREAD_ONLY | nsIClassInfo::EAGER_CLASSINFO
-    },
-
-    { NS_SYSTEMPRINCIPAL_CLASSNAME, 
-      NS_SYSTEMPRINCIPAL_CID, 
-      NS_SYSTEMPRINCIPAL_CONTRACTID,
-      nsSystemPrincipalConstructor,
-      nsnull,
-      nsnull,
-      nsnull,
-      NS_CI_INTERFACE_GETTER_NAME(nsSystemPrincipal),
-      nsnull,
-      &NS_CLASSINFO_NAME(nsSystemPrincipal),
-      nsIClassInfo::SINGLETON | nsIClassInfo::MAIN_THREAD_ONLY |
-      nsIClassInfo::EAGER_CLASSINFO
-    },
-
-    { NS_NULLPRINCIPAL_CLASSNAME, 
-      NS_NULLPRINCIPAL_CID, 
-      NS_NULLPRINCIPAL_CONTRACTID,
-      nsNullPrincipalConstructor,
-      nsnull,
-      nsnull,
-      nsnull,
-      NS_CI_INTERFACE_GETTER_NAME(nsNullPrincipal),
-      nsnull,
-      &NS_CLASSINFO_NAME(nsNullPrincipal),
-      nsIClassInfo::MAIN_THREAD_ONLY | nsIClassInfo::EAGER_CLASSINFO
-    },
-
-    { "Security Script Name Set",
-      NS_SECURITYNAMESET_CID,
-      NS_SECURITYNAMESET_CONTRACTID,
-      nsSecurityNameSetConstructor,
-      nsnull,
-      nsnull,
-      nsnull,
-      nsnull,
-      nsnull,
-      nsnull,
-      nsIClassInfo::MAIN_THREAD_ONLY
-    }
+static const mozilla::Module::ContractIDEntry kLayoutContracts[] = {
+  XPCONNECT_CONTRACTS
+  { "@mozilla.org/layout/xul-boxobject;1", &kNS_BOXOBJECT_CID },
+#ifdef MOZ_XUL
+  { "@mozilla.org/layout/xul-boxobject-listbox;1", &kNS_LISTBOXOBJECT_CID },
+  { "@mozilla.org/layout/xul-boxobject-menu;1", &kNS_MENUBOXOBJECT_CID },
+  { "@mozilla.org/layout/xul-boxobject-popup;1", &kNS_POPUPBOXOBJECT_CID },
+  { "@mozilla.org/layout/xul-boxobject-container;1", &kNS_CONTAINERBOXOBJECT_CID },
+  { "@mozilla.org/layout/xul-boxobject-scrollbox;1", &kNS_SCROLLBOXOBJECT_CID },
+  { "@mozilla.org/layout/xul-boxobject-tree;1", &kNS_TREEBOXOBJECT_CID },
+#endif // MOZ_XUL
+#ifndef MOZ_NO_INSPECTOR_APIS
+#ifdef MOZ_XUL
+  { "@mozilla.org/inspector/dom-view;1", &kIN_DOMVIEW_CID },
+#endif
+  { "@mozilla.org/inspector/deep-tree-walker;1", &kIN_DEEPTREEWALKER_CID },
+  { "@mozilla.org/inspector/flasher;1", &kIN_FLASHER_CID },
+  { "@mozilla.org/inspector/search;1?type=cssvalue", &kIN_CSSVALUESEARCH_CID },
+  { "@mozilla.org/inspector/dom-utils;1", &kIN_DOMUTILS_CID },
+#endif // MOZ_NO_INSPECTOR_APIS
+  { NS_NAMESPACEMANAGER_CONTRACTID, &kNS_NAMESPACEMANAGER_CID },
+  { "@mozilla.org/xml/xml-document;1", &kNS_XMLDOCUMENT_CID },
+#ifdef MOZ_SVG
+  { "@mozilla.org/svg/svg-document;1", &kNS_SVGDOCUMENT_CID },
+#endif
+  { "@mozilla.org/content/dom-selection;1", &kNS_DOMSELECTION_CID },
+  { "@mozilla.org/content/range;1", &kNS_RANGE_CID },
+  { "@mozilla.org/content/range-utils;1", &kNS_RANGEUTILS_CID },
+  { "@mozilla.org/content/post-content-iterator;1", &kNS_CONTENTITERATOR_CID },
+  { "@mozilla.org/content/pre-content-iterator;1", &kNS_PRECONTENTITERATOR_CID },
+  { "@mozilla.org/content/subtree-content-iterator;1", &kNS_SUBTREEITERATOR_CID },
+  { NS_HTMLIMGELEMENT_CONTRACTID, &kNS_HTMLIMAGEELEMENT_CID },
+  { NS_HTMLOPTIONELEMENT_CONTRACTID, &kNS_HTMLOPTIONELEMENT_CID },
+#ifdef MOZ_MEDIA
+  { NS_HTMLAUDIOELEMENT_CONTRACTID, &kNS_HTMLAUDIOELEMENT_CID },
+#endif
+  { "@mozilla.org/content/canvas-rendering-context;1?id=2d", &kNS_CANVASRENDERINGCONTEXT2D_CID },
+  { "@mozilla.org/content/canvas-rendering-context;1?id=moz-webgl", &kNS_CANVASRENDERINGCONTEXTWEBGL_CID },
+  { "@mozilla.org/content/canvas-rendering-context;1?id=experimental-webgl", &kNS_CANVASRENDERINGCONTEXTWEBGL_CID },
+  { NS_DOC_ENCODER_CONTRACTID_BASE "text/xml", &kNS_TEXT_ENCODER_CID },
+  { NS_DOC_ENCODER_CONTRACTID_BASE "application/xml", &kNS_TEXT_ENCODER_CID },
+  { NS_DOC_ENCODER_CONTRACTID_BASE "application/xhtml+xml", &kNS_TEXT_ENCODER_CID },
+#ifdef MOZ_SVG
+  { NS_DOC_ENCODER_CONTRACTID_BASE "image/svg+xml", &kNS_TEXT_ENCODER_CID },
+#endif
+  { NS_DOC_ENCODER_CONTRACTID_BASE "text/html", &kNS_TEXT_ENCODER_CID },
+  { NS_DOC_ENCODER_CONTRACTID_BASE "text/plain", &kNS_TEXT_ENCODER_CID },
+  { NS_HTMLCOPY_ENCODER_CONTRACTID, &kNS_HTMLCOPY_TEXT_ENCODER_CID },
+  { NS_CONTENTSERIALIZER_CONTRACTID_PREFIX "text/xml", &kNS_XMLCONTENTSERIALIZER_CID },
+  { NS_CONTENTSERIALIZER_CONTRACTID_PREFIX "application/xml", &kNS_XMLCONTENTSERIALIZER_CID },
+  { NS_CONTENTSERIALIZER_CONTRACTID_PREFIX "application/xhtml+xml", &kNS_XHTMLCONTENTSERIALIZER_CID },
+#ifdef MOZ_SVG
+  { NS_CONTENTSERIALIZER_CONTRACTID_PREFIX "image/svg+xml", &kNS_XMLCONTENTSERIALIZER_CID },
+#endif
+  { NS_CONTENTSERIALIZER_CONTRACTID_PREFIX "text/html", &kNS_HTMLCONTENTSERIALIZER_CID },
+  { NS_CONTENTSERIALIZER_CONTRACTID_PREFIX "application/vnd.mozilla.xul+xml", &kNS_XMLCONTENTSERIALIZER_CID },
+  { NS_CONTENTSERIALIZER_CONTRACTID_PREFIX "text/plain", &kNS_PLAINTEXTSERIALIZER_CID },
+  { NS_PLAINTEXTSINK_CONTRACTID, &kNS_PLAINTEXTSERIALIZER_CID },
+  { NS_HTMLFRAGMENTSINK_CONTRACTID, &kNS_HTMLFRAGMENTSINK_CID },
+  { NS_HTMLFRAGMENTSINK2_CONTRACTID, &kNS_HTMLFRAGMENTSINK2_CID },
+  { NS_HTMLPARANOIDFRAGMENTSINK_CONTRACTID, &kNS_HTMLPARANOIDFRAGMENTSINK_CID },
+  { MOZ_SANITIZINGHTMLSERIALIZER_CONTRACTID, &kMOZ_SANITIZINGHTMLSERIALIZER_CID },
+  { NS_XMLFRAGMENTSINK_CONTRACTID, &kNS_XMLFRAGMENTSINK_CID },
+  { NS_XMLFRAGMENTSINK2_CONTRACTID, &kNS_XMLFRAGMENTSINK2_CID },
+  { NS_XHTMLPARANOIDFRAGMENTSINK_CONTRACTID, &kNS_XHTMLPARANOIDFRAGMENTSINK_CID },
+  { "@mozilla.org/xbl;1", &kNS_XBLSERVICE_CID },
+  { NS_CONTENTPOLICY_CONTRACTID, &kNS_CONTENTPOLICY_CID },
+  { NS_DATADOCUMENTCONTENTPOLICY_CONTRACTID, &kNS_DATADOCUMENTCONTENTPOLICY_CID },
+  { NS_NODATAPROTOCOLCONTENTPOLICY_CONTRACTID, &kNS_NODATAPROTOCOLCONTENTPOLICY_CID },
+  { "@mozilla.org/xul/xul-controllers;1", &kNS_XULCONTROLLERS_CID },
+#ifdef MOZ_XUL
+  { "@mozilla.org/xul/xul-sort-service;1", &kNS_XULSORTSERVICE_CID },
+  { "@mozilla.org/xul/xul-template-builder;1", &kNS_XULTEMPLATEBUILDER_CID },
+  { "@mozilla.org/xul/xul-tree-builder;1", &kNS_XULTREEBUILDER_CID },
+  { "@mozilla.org/xul/xul-popup-manager;1", &kNS_XULPOPUPMANAGER_CID },
+  { "@mozilla.org/xul/xul-document;1", &kNS_XULDOCUMENT_CID },
+  { "@mozilla.org/xul/xul-prototype-cache;1", &kNS_XULPROTOTYPECACHE_CID },
+#endif
+#ifdef MOZ_XTF
+  { NS_XTFSERVICE_CONTRACTID, &kNS_XTFSERVICE_CID },
+  { NS_XMLCONTENTBUILDER_CONTRACTID, &kNS_XMLCONTENTBUILDER_CID },
+#endif
+  { CONTENT_DLF_CONTRACTID, &kNS_CONTENT_DOCUMENT_LOADER_FACTORY_CID },
+  { NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "wyciwyg", &kNS_WYCIWYGPROTOCOLHANDLER_CID },
+  { NS_SYNCLOADDOMSERVICE_CONTRACTID, &kNS_SYNCLOADDOMSERVICE_CID },
+  { NS_JSPROTOCOLHANDLER_CONTRACTID, &kNS_JSPROTOCOLHANDLER_CID },
+  { NS_WINDOWCONTROLLER_CONTRACTID, &kNS_WINDOWCONTROLLER_CID },
+  { "@mozilla.org/view-manager;1", &kNS_VIEW_MANAGER_CID },
+  { PLUGIN_DLF_CONTRACTID, &kNS_PLUGINDOCLOADERFACTORY_CID },
+  { NS_STYLESHEETSERVICE_CONTRACTID, &kNS_STYLESHEETSERVICE_CID },
+  { TRANSFORMIIX_XSLT_PROCESSOR_CONTRACTID, &kTRANSFORMIIX_XSLT_PROCESSOR_CID },
+  { NS_XPATH_EVALUATOR_CONTRACTID, &kTRANSFORMIIX_XPATH_EVALUATOR_CID },
+  { NS_XPOINTER_SCHEME_PROCESSOR_BASE "xpath1", &kTRANSFORMIIX_XPATH1_SCHEME_CID },
+  { TRANSFORMIIX_NODESET_CONTRACTID, &kTRANSFORMIIX_NODESET_CID },
+  { NS_XMLSERIALIZER_CONTRACTID, &kNS_XMLSERIALIZER_CID },
+  { NS_FILEREADER_CONTRACTID, &kNS_FILEREADER_CID },
+  { NS_FORMDATA_CONTRACTID, &kNS_FORMDATA_CID },
+  { NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX FILEDATA_SCHEME, &kNS_FILEDATAPROTOCOLHANDLER_CID },
+  { NS_XMLHTTPREQUEST_CONTRACTID, &kNS_XMLHTTPREQUEST_CID },
+  { NS_DOMPARSER_CONTRACTID, &kNS_DOMPARSER_CID },
+  { "@mozilla.org/dom/storage;1", &kNS_DOMSTORAGE_CID },
+  { "@mozilla.org/dom/storage;2", &kNS_DOMSTORAGE2_CID },
+  { "@mozilla.org/dom/storagemanager;1", &kNS_DOMSTORAGEMANAGER_CID },
+  { "@mozilla.org/dom/json;1", &kNS_DOMJSON_CID },
+  { "@mozilla.org/editor/texteditor;1", &kNS_TEXTEDITOR_CID },
+#ifndef MOZILLA_PLAINTEXT_EDITOR_ONLY
+#ifdef ENABLE_EDITOR_API_LOG
+  { "@mozilla.org/editor/htmleditor;1", &kNS_HTMLEDITOR_CID },
+#else
+  { "@mozilla.org/editor/htmleditor;1", &kNS_HTMLEDITOR_CID },
+#endif
+#endif
+  { "@mozilla.org/editor/editorcontroller;1", &kNS_EDITORCONTROLLER_CID },
+  { "", &kNS_EDITORCOMMANDTABLE_CID },
+#ifndef MOZILLA_PLAINTEXT_EDITOR_ONLY
+  { "@mozilla.org/textservices/textservicesdocument;1", &kNS_TEXTSERVICESDOCUMENT_CID },
+#endif
+  { "@mozilla.org/geolocation/service;1", &kNS_GEOLOCATION_SERVICE_CID },
+  { "@mozilla.org/geolocation;1", &kNS_GEOLOCATION_CID },
+  { "@mozilla.org/focus-manager;1", &kNS_FOCUSMANAGER_CID },
+  { "@mozilla.org/content/contentutils;1", &kNS_ICONTENTUTILS_CID },
+  { CSPSERVICE_CONTRACTID, &kCSPSERVICE_CID },
+  { NS_EVENTLISTENERSERVICE_CONTRACTID, &kNS_EVENTLISTENERSERVICE_CID },
+  { NSCHANNELPOLICY_CONTRACTID, &kNSCHANNELPOLICY_CID },
+  { NS_SCRIPTSECURITYMANAGER_CONTRACTID, &kNS_SCRIPTSECURITYMANAGER_CID },
+  { NS_GLOBAL_CHANNELEVENTSINK_CONTRACTID, &kNS_SCRIPTSECURITYMANAGER_CID },
+  { NS_PRINCIPAL_CONTRACTID, &kNS_PRINCIPAL_CID },
+  { NS_SYSTEMPRINCIPAL_CONTRACTID, &kNS_SYSTEMPRINCIPAL_CID },
+  { NS_NULLPRINCIPAL_CONTRACTID, &kNS_NULLPRINCIPAL_CID },
+  { NS_SECURITYNAMESET_CONTRACTID, &kNS_SECURITYNAMESET_CID },
+  { NULL }
 };
 
-void
-XPConnectModuleDtor(nsIModule *self)
+static const mozilla::Module::CategoryEntry kLayoutCategories[] = {
+  XPCONNECT_CATEGORIES
+  { JAVASCRIPT_GLOBAL_CONSTRUCTOR_CATEGORY, "Image", NS_HTMLIMGELEMENT_CONTRACTID },
+  { JAVASCRIPT_GLOBAL_CONSTRUCTOR_PROTO_ALIAS_CATEGORY, "Image", "HTMLImageElement" },
+  { JAVASCRIPT_GLOBAL_CONSTRUCTOR_CATEGORY, "Option", NS_HTMLOPTIONELEMENT_CONTRACTID },
+  { JAVASCRIPT_GLOBAL_CONSTRUCTOR_PROTO_ALIAS_CATEGORY, "Option", "HTMLOptionElement" },
+#ifdef MOZ_MEDIA
+  { JAVASCRIPT_GLOBAL_CONSTRUCTOR_CATEGORY, "Audio", NS_HTMLAUDIOELEMENT_CONTRACTID },
+  { JAVASCRIPT_GLOBAL_CONSTRUCTOR_PROTO_ALIAS_CATEGORY, "Audio", "HTMLAudioElement" },
+#endif
+  { "content-policy", NS_DATADOCUMENTCONTENTPOLICY_CONTRACTID, NS_DATADOCUMENTCONTENTPOLICY_CONTRACTID },
+  { "content-policy", NS_NODATAPROTOCOLCONTENTPOLICY_CONTRACTID, NS_NODATAPROTOCOLCONTENTPOLICY_CONTRACTID },
+  { "content-policy", "CSPService", CSPSERVICE_CONTRACTID },
+  { "net-channel-event-sinks", "CSPService", CSPSERVICE_CONTRACTID },
+  { JAVASCRIPT_GLOBAL_STATIC_NAMESET_CATEGORY, "PrivilegeManager", NS_SECURITYNAMESET_CONTRACTID },
+  { "app-startup", "Script Security Manager", "service," NS_SCRIPTSECURITYMANAGER_CONTRACTID },
+  CONTENTDLF_CATEGORIES
+  { NULL }
+};
+
+static void
+LayoutModuleDtor()
 {
-  xpcModuleDtor(self);
+  xpcModuleDtor();
 
   nsScriptSecurityManager::Shutdown();
 }
 
-static nsModuleInfo const kXPConnectModuleInfo = {
-    NS_MODULEINFO_VERSION,
-    "XPConnectModule",
-    gXPConnectComponents,
-    (sizeof(gXPConnectComponents) / sizeof(gXPConnectComponents[0])),
-    xpcModuleCtor,
-    XPConnectModuleDtor
+static const mozilla::Module kLayoutModule = {
+  mozilla::Module::kVersion,
+  kLayoutCIDs,
+  kLayoutContracts,
+  kLayoutCategories,
+  NULL,
+  Initialize,
+  LayoutModuleDtor
 };
-
-// XPConnect is initialized early, because it has an XPCOM component loader.
-// Initializing nsLayoutStatics at that point leads to recursive initialization,
-// because it instantiates a bunch of other components. To get around that we
-// use two nsGenericModules, each with their own initialiser. nsLayoutStatics is
-// initialized for the module for layout components, but not for the module for
-// XPConnect components. nsLayoutModule forwards to the two nsGenericModules.
-class nsLayoutModule : public nsIModule
-{
-public:
-  nsLayoutModule(nsIModule *aXPConnectModule, nsIModule *aLayoutModule)
-    : mXPConnectModule(aXPConnectModule),
-      mLayoutModule(aLayoutModule)
-  {
-  }
-
-  NS_DECL_ISUPPORTS
-
-  // nsIModule
-  NS_SCRIPTABLE NS_IMETHOD GetClassObject(nsIComponentManager *aCompMgr,
-                                          const nsCID & aClass,
-                                          const nsIID & aIID,
-                                          void **aResult NS_OUTPARAM)
-  {
-    nsresult rv = mXPConnectModule->GetClassObject(aCompMgr, aClass, aIID,
-                                                   aResult);
-    if (rv == NS_ERROR_FACTORY_NOT_REGISTERED) {
-      rv = mLayoutModule->GetClassObject(aCompMgr, aClass, aIID, aResult);
-    }
-    return rv;
-  }
-  NS_SCRIPTABLE NS_IMETHOD RegisterSelf(nsIComponentManager *aCompMgr,
-                                        nsIFile *aLocation,
-                                        const char *aLoaderStr,
-                                        const char *aType)
-  {
-    nsresult rv = mXPConnectModule->RegisterSelf(aCompMgr, aLocation,
-                                                 aLoaderStr, aType);
-    if (NS_SUCCEEDED(rv)) {
-      rv = mLayoutModule->RegisterSelf(aCompMgr, aLocation, aLoaderStr, aType);
-    }
-    return rv;
-  }
-  NS_SCRIPTABLE NS_IMETHOD UnregisterSelf(nsIComponentManager *aCompMgr,
-                                          nsIFile *aLocation,
-                                          const char *aLoaderStr)
-  {
-    nsresult rv = mXPConnectModule->UnregisterSelf(aCompMgr, aLocation,
-                                                   aLoaderStr);
-    if (NS_SUCCEEDED(rv)) {
-      rv = mLayoutModule->UnregisterSelf(aCompMgr, aLocation, aLoaderStr);
-    }
-    return rv;
-  }
-  NS_SCRIPTABLE NS_IMETHOD CanUnload(nsIComponentManager *aCompMgr,
-                                     PRBool *aResult NS_OUTPARAM)
-  {
-    nsresult rv = mXPConnectModule->CanUnload(aCompMgr, aResult);
-    if (NS_SUCCEEDED(rv)) {
-      rv = mLayoutModule->CanUnload(aCompMgr, aResult);
-    }
-    return rv;
-  }
-
-private:
-  nsCOMPtr<nsIModule> mXPConnectModule;
-  nsCOMPtr<nsIModule> mLayoutModule;
-};
-
-NS_IMPL_ISUPPORTS1(nsLayoutModule, nsIModule)
-
-NSGETMODULE_ENTRY_POINT(nsLayoutModule)(nsIComponentManager *aServMgr,
-                                        nsIFile *aLocation,
-                                        nsIModule **aResult)
-{
-    nsCOMPtr<nsIModule> xpconnectModule;
-    nsresult rv = NS_NewGenericModule2(&kXPConnectModuleInfo,
-                                       getter_AddRefs(xpconnectModule));
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    nsCOMPtr<nsIModule> layoutModule;
-    rv = NS_NewGenericModule2(&kLayoutModuleInfo, getter_AddRefs(layoutModule));
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    NS_ADDREF(*aResult = new nsLayoutModule(xpconnectModule, layoutModule));
-
-    return NS_OK;
-}
+  
+NSMODULE_DEFN(nsLayoutModule) = &kLayoutModule;
--- a/layout/build/nsLayoutStatics.cpp
+++ b/layout/build/nsLayoutStatics.cpp
@@ -216,21 +216,16 @@ nsLayoutStatics::Initialize()
 #endif
 
 #endif
 
 #ifdef MOZ_MATHML
   nsMathMLOperators::AddRefTable();
 #endif
 
-#ifdef MOZ_SVG
-  if (NS_SVGEnabled())
-    nsContentDLF::RegisterSVG();
-#endif
-
 #ifndef MOZILLA_PLAINTEXT_EDITOR_ONLY
   nsEditProperty::RegisterAtoms();
   nsTextServicesDocument::RegisterAtoms();
 #endif
 
 #ifdef DEBUG
   nsFrame::DisplayReflowStartup();
 #endif
@@ -269,20 +264,16 @@ nsLayoutStatics::Initialize()
 #endif
 
   rv = nsFocusManager::Init();
   if (NS_FAILED(rv)) {
     NS_ERROR("Could not initialize nsFocusManager");
     return rv;
   }
 
-#ifdef MOZ_MEDIA
-  nsHTMLMediaElement::InitMediaTypes();
-#endif
-
 #ifdef MOZ_SYDNEYAUDIO
   nsAudioStream::InitLibrary();
 #endif
 
   nsContentSink::InitializeStatics();
   nsHtml5Module::InitializeStatics();
   nsIPresShell::InitializeStatics();
 
@@ -366,19 +357,16 @@ nsLayoutStatics::Shutdown()
 
 #ifndef MOZILLA_PLAINTEXT_EDITOR_ONLY
   nsHTMLEditor::Shutdown();
   nsTextServicesDocument::Shutdown();
 #endif
 
   nsDOMThreadService::Shutdown();
 
-#ifdef MOZ_MEDIA
-  nsHTMLMediaElement::ShutdownMediaTypes();
-#endif
 #ifdef MOZ_SYDNEYAUDIO
   nsAudioStream::ShutdownLibrary();
 #endif
 
   nsXMLHttpRequest::ShutdownACCache();
   
   nsIPresShell::ReleaseStatics();
 
--- a/layout/svg/base/src/nsSVGUtils.cpp
+++ b/layout/svg/base/src/nsSVGUtils.cpp
@@ -180,21 +180,16 @@ static const char SMIL_PREF_STR[] = "svg
 static int
 SVGPrefChanged(const char *aPref, void *aClosure)
 {
   PRBool prefVal = nsContentUtils::GetBoolPref(SVG_PREF_STR);
   if (prefVal == gSVGEnabled)
     return 0;
 
   gSVGEnabled = prefVal;
-  if (gSVGEnabled)
-    nsContentDLF::RegisterSVG();
-  else
-    nsContentDLF::UnregisterSVG();
-
   return 0;
 }
 
 PRBool
 NS_SVGEnabled()
 {
   static PRBool sInitialized = PR_FALSE;
   
--- a/layout/tools/layout-debug/src/nsDebugFactory.cpp
+++ b/layout/tools/layout-debug/src/nsDebugFactory.cpp
@@ -32,75 +32,51 @@
  * 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 MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nscore.h"
 #include "nsLayoutDebugCIID.h"
+#include "mozilla/ModuleUtils.h"
 #include "nsIFactory.h"
 #include "nsISupports.h"
 #include "nsRegressionTester.h"
 #include "nsLayoutDebuggingTools.h"
 #include "nsLayoutDebugCLH.h"
-#include "nsIGenericFactory.h"
-#include "nsICategoryManager.h"
 #include "nsIServiceManager.h"
 
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsRegressionTester)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsLayoutDebuggingTools)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsLayoutDebugCLH)
 
-static NS_METHOD
-RegisterCommandLineHandlers(nsIComponentManager* compMgr, nsIFile* path,
-                            const char *location, const char *type,
-                            const nsModuleComponentInfo *info)
-{
-  nsresult rv;
-  nsCOMPtr<nsICategoryManager> catMan (do_GetService(NS_CATEGORYMANAGER_CONTRACTID));
-  NS_ENSURE_TRUE(catMan, NS_ERROR_FAILURE);
-
-  rv = catMan->AddCategoryEntry("command-line-handler", "m-layoutdebug",
-                                "@mozilla.org/commandlinehandler/general-startup;1?type=layoutdebug",
-                                PR_TRUE, PR_TRUE, nsnull);
-  if (NS_FAILED(rv))
-    return NS_ERROR_FAILURE;
-
-  return NS_OK;
-}
-
-static NS_METHOD
-UnregisterCommandLineHandlers(nsIComponentManager* compMgr, nsIFile *path,
-                              const char *location,
-                              const nsModuleComponentInfo *info)
-{
-  nsCOMPtr<nsICategoryManager> catMan (do_GetService(NS_CATEGORYMANAGER_CONTRACTID));
-  NS_ENSURE_TRUE(catMan, NS_ERROR_FAILURE);
+NS_DEFINE_NAMED_CID(NS_REGRESSION_TESTER_CID);
+NS_DEFINE_NAMED_CID(NS_LAYOUT_DEBUGGINGTOOLS_CID);
+NS_DEFINE_NAMED_CID(NS_LAYOUTDEBUGCLH_CID);
 
-  catMan->DeleteCategoryEntry("command-line-handler", "m-layoutdebug",
-                              PR_TRUE);
-
-  return NS_OK;
-}
-
-static const nsModuleComponentInfo components[] =
-{
-  { "nsRegressionTester",
-    NS_REGRESSION_TESTER_CID,
-    "@mozilla.org/layout-debug/regressiontester;1",
-    nsRegressionTesterConstructor 
-  },
-  { "nsLayoutDebuggingTools",
-    NS_LAYOUT_DEBUGGINGTOOLS_CID,
-    NS_LAYOUT_DEBUGGINGTOOLS_CONTRACTID,
-    nsLayoutDebuggingToolsConstructor
-  },
-  { "LayoutDebug Startup Handler",
-    NS_LAYOUTDEBUGCLH_CID,
-    "@mozilla.org/commandlinehandler/general-startup;1?type=layoutdebug",
-    nsLayoutDebugCLHConstructor,
-    RegisterCommandLineHandlers,
-    UnregisterCommandLineHandlers
-  }
+static const mozilla::Module::CIDEntry kLayoutDebugCIDs[] = {
+  { &kNS_REGRESSION_TESTER_CID, false, NULL, nsRegressionTesterConstructor },
+  { &kNS_LAYOUT_DEBUGGINGTOOLS_CID, false, NULL, nsLayoutDebuggingToolsConstructor },
+  { &kNS_LAYOUTDEBUGCLH_CID, false, NULL, nsLayoutDebugCLHConstructor },
+  { NULL }
 };
 
-NS_IMPL_NSGETMODULE(nsLayoutDebugModule, components)
+static const mozilla::Module::ContractIDEntry kLayoutDebugContracts[] = {
+  { "@mozilla.org/layout-debug/regressiontester;1", &kNS_REGRESSION_TESTER_CID },
+  { NS_LAYOUT_DEBUGGINGTOOLS_CONTRACTID, &kNS_LAYOUT_DEBUGGINGTOOLS_CID },
+  { "@mozilla.org/commandlinehandler/general-startup;1?type=layoutdebug", &kNS_LAYOUTDEBUGCLH_CID },
+  { NULL }
+};
+
+static const mozilla::Module::CategoryEntry kLayoutDebugCategories[] = {
+  { "command-line-handler", "m-layoutdebug", "@mozilla.org/commandlinehandler/general-startup;1?type=layoutdebug" },
+  { NULL }
+};
+
+static const mozilla::Module kLayoutDebugModule = {
+  mozilla::Module::kVersion,
+  kLayoutDebugCIDs,
+  kLayoutDebugContracts,
+  kLayoutDebugCategories
+};
+
+NSMODULE_DEFN(nsLayoutDebugModule) = &kLayoutDebugModule;
--- a/toolkit/crashreporter/test/nsTestCrasher.cpp
+++ b/toolkit/crashreporter/test/nsTestCrasher.cpp
@@ -1,13 +1,13 @@
 #include "nsServiceManagerUtils.h"
 #include "nsIComponentManager.h"
-#include "nsIGenericFactory.h"
 #include "nsITestCrasher.h"
 #include "nsXULAppAPI.h"
+#include "mozilla/ModuleUtils.h"
 
 class nsTestCrasher : public nsITestCrasher
 {
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSITESTCRASHER
 
   nsTestCrasher() {}
@@ -77,18 +77,27 @@ NS_IMETHODIMP nsTestCrasher::LockDir(nsI
   return XRE_LockProfileDirectory(directory, _retval);
 }
 
 // 54afce51-38d7-4df0-9750-2f90f9ffbca2
 #define NS_TESTCRASHER_CID \
 { 0x54afce51, 0x38d7, 0x4df0, {0x97, 0x50, 0x2f, 0x90, 0xf9, 0xff, 0xbc, 0xa2} }
 
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsTestCrasher)
+NS_DEFINE_NAMED_CID(NS_TESTCRASHER_CID);
 
-static const nsModuleComponentInfo components[] = {
-    { "Test Crasher",
-      NS_TESTCRASHER_CID,
-      "@mozilla.org/testcrasher;1",
-      nsTestCrasherConstructor
-    }
+static const mozilla::Module::CIDEntry kTestCrasherCIDs[] = {
+  { &kNS_TESTCRASHER_CID, false, NULL, nsTestCrasherConstructor },
+  { NULL }
 };
 
-NS_IMPL_NSGETMODULE(nsTestCrasherModule, components)
+static const mozilla::Module::ContractIDEntry kTestCrasherContracts[] = {
+  { "@mozilla.org/testcrasher;1", &kNS_TESTCRASHER_CID },
+  { NULL }
+};
+
+static const mozilla::Module kTestCrasherModule = {
+  mozilla::Module::kVersion,
+  kTestCrasherCIDs,
+  kTestCrasherContracts
+};
+
+NSMODULE_DEFN(nsTestCrasherModule) = &kTestCrasherModule;
--- a/toolkit/library/dlldeps-xul.cpp
+++ b/toolkit/library/dlldeps-xul.cpp
@@ -36,19 +36,18 @@
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsXULAppAPI.h"
 
 void xxxNeverCalledXUL()
 {
   XRE_main(0, nsnull, nsnull);
   XRE_GetFileFromPath(nsnull, nsnull);
-  XRE_GetStaticComponents(nsnull, nsnull);
   XRE_LockProfileDirectory(nsnull, nsnull);
-  XRE_InitEmbedding(nsnull, nsnull, nsnull, nsnull, 0);
+  XRE_InitEmbedding2(nsnull, nsnull, nsnull);
   XRE_NotifyProfile();
   XRE_TermEmbedding();
   XRE_CreateAppData(nsnull, nsnull);
   XRE_ParseAppData(nsnull, nsnull);
   XRE_FreeAppData(nsnull);
   XRE_ChildProcessTypeToString(GeckoProcessType_Default);
   XRE_StringToChildProcessType("");
   XRE_GetProcessType();
--- a/toolkit/library/nsStaticXULComponents.cpp
+++ b/toolkit/library/nsStaticXULComponents.cpp
@@ -35,22 +35,22 @@
  * 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 MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #define XPCOM_TRANSLATE_NSGM_ENTRY_POINT 1
 
-#include "nsIGenericFactory.h"
+#include "mozilla/Module.h"
 #include "nsXPCOM.h"
 #include "nsStaticComponents.h"
 #include "nsMemory.h"
 
-#define NSGETMODULE(_name) _name##_NSGetModule
+// #define NSGETMODULE(_name) _name##_NSGetModule
 
 #ifdef MOZ_AUTH_EXTENSION
 #define AUTH_MODULE    MODULE(nsAuthModule)
 #else
 #define AUTH_MODULE
 #endif
 
 #ifdef MOZ_PERMISSIONS
@@ -271,25 +271,25 @@
     LAYOUT_DEBUG_MODULE                      \
     UNIXPROXY_MODULE                         \
     OSXPROXY_MODULE                          \
     WINDOWSPROXY_MODULE                      \
     JSCTYPES_MODULE                          \
     /* end of list */
 
 #define MODULE(_name) \
-NSGETMODULE_ENTRY_POINT(_name) (nsIComponentManager*, nsIFile*, nsIModule**);
+  NSMODULE_DECL(_name);
 
 XUL_MODULES
 
 #undef MODULE
 
-#define MODULE(_name) { #_name, NSGETMODULE(_name) },
+#define MODULE(_name) \
+    NSMODULE_NAME(_name),
 
-/**
- * The nsStaticModuleInfo
- */
-static nsStaticModuleInfo const gStaticModuleInfo[] = {
-    XUL_MODULES
+static const mozilla::Module *const kStaticModules[] = {
+  XUL_MODULES
+  NULL
 };
 
-nsStaticModuleInfo const *const kPStaticModules = gStaticModuleInfo;
-PRUint32 const kStaticModuleCount = NS_ARRAY_LENGTH(gStaticModuleInfo);
+#undef MODULE
+
+mozilla::Module const *const *const kPStaticModules = kStaticModules;
--- a/toolkit/mozapps/extensions/amInstallTrigger.cpp
+++ b/toolkit/mozapps/extensions/amInstallTrigger.cpp
@@ -32,30 +32,29 @@
  * 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 MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "amInstallTrigger.h"
 #include "nsIClassInfoImpl.h"
-#include "nsIGenericFactory.h"
 #include "nsIComponentManager.h"
-#include "nsIComponentRegistrar.h"
 #include "nsICategoryManager.h"
 #include "nsServiceManagerUtils.h"
 #include "nsXPIDLString.h"
 #include "nsIScriptNameSpaceManager.h"
 #include "nsDOMJSUtils.h"
 #include "nsIXPConnect.h"
 #include "nsContentUtils.h"
 #include "nsIDocument.h"
 #include "nsIDOMDocument.h"
 #include "nsNetUtil.h"
 #include "nsIScriptSecurityManager.h"
+#include "mozilla/ModuleUtils.h"
 
 //
 // Helper function for URI verification
 //
 static nsresult
 CheckLoadURIFromScript(JSContext *aCx, const nsACString& aUriStr)
 {
   nsresult rv;
@@ -77,16 +76,17 @@ CheckLoadURIFromScript(JSContext *aCx, c
   NS_ENSURE_SUCCESS(rv, rv);
 
   // are we allowed to load this one?
   rv = secman->CheckLoadURIWithPrincipal(principal, uri,
                   nsIScriptSecurityManager::DISALLOW_INHERIT_PRINCIPAL);
   return rv;
 }
 
+NS_IMPL_CLASSINFO(amInstallTrigger, NULL, nsIClassInfo::DOM_OBJECT)
 NS_IMPL_ISUPPORTS1_CI(amInstallTrigger, amIInstallTrigger)
 
 amInstallTrigger::amInstallTrigger()
 {
   mManager = do_GetService("@mozilla.org/addons/integration;1");
 }
 
 amInstallTrigger::~amInstallTrigger()
@@ -345,54 +345,35 @@ amInstallTrigger::StartSoftwareUpdate(co
                                           window, referer, uris.Elements(),
                                           hashes.Elements(), names.Elements(),
                                           icons.Elements(), nsnull, 1, _retval);
 
   NS_Free(const_cast<PRUnichar*>(uris[0]));
   return rv;
 }
 
-NS_DECL_CLASSINFO(amInstallTrigger)
-
 NS_GENERIC_FACTORY_CONSTRUCTOR(amInstallTrigger)
 
-static NS_METHOD
-RegisterInstallTrigger(nsIComponentManager *aCompMgr,
-                       nsIFile *aPath,
-                       const char *aRegistryLocation,
-                       const char *aComponentType,
-                       const nsModuleComponentInfo *aInfo)
-{
-  nsresult rv = NS_OK;
-
-  nsCOMPtr<nsICategoryManager> catman = 
-    do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  nsXPIDLCString previous;
-  rv = catman->AddCategoryEntry(JAVASCRIPT_GLOBAL_PROPERTY_CATEGORY,
-                                "InstallTrigger",
-                                AM_INSTALLTRIGGER_CONTRACTID,
-                                PR_TRUE, PR_TRUE, getter_Copies(previous));
-  NS_ENSURE_SUCCESS(rv, rv);
+NS_DEFINE_NAMED_CID(AM_InstallTrigger_CID);
 
-  return NS_OK;
-}
-
+static const mozilla::Module::CIDEntry kInstallTriggerCIDs[] = {
+  { &kAM_InstallTrigger_CID, false, NULL, amInstallTriggerConstructor },
+  { NULL }
+};
 
-// The list of components we register
-static const nsModuleComponentInfo components[] =
-{
-    { "InstallTrigger Component",
-       AM_InstallTrigger_CID,
-       AM_INSTALLTRIGGER_CONTRACTID,
-       amInstallTriggerConstructor,
-       RegisterInstallTrigger,
-       nsnull, // unregister
-       nsnull, // factory destructor
-       NS_CI_INTERFACE_GETTER_NAME(amInstallTrigger),
-       nsnull, // language helper
-       &NS_CLASSINFO_NAME(amInstallTrigger),
-       nsIClassInfo::DOM_OBJECT // flags
-    }
+static const mozilla::Module::ContractIDEntry kInstallTriggerContracts[] = {
+  { AM_INSTALLTRIGGER_CONTRACTID, &kAM_InstallTrigger_CID },
+  { NULL }
 };
 
-NS_IMPL_NSGETMODULE(AddonsModule, components)
+static const mozilla::Module::CategoryEntry kInstallTriggerCategories[] = {
+  { JAVASCRIPT_GLOBAL_PROPERTY_CATEGORY, "InstallTrigger", AM_INSTALLTRIGGER_CONTRACTID },
+  { NULL }
+};
+
+static const mozilla::Module kInstallTriggerModule = {
+  mozilla::Module::kVersion,
+  kInstallTriggerCIDs,
+  kInstallTriggerContracts,
+  kInstallTriggerCategories
+};
+
+NSMODULE_DEFN(AddonsModule) = &kInstallTriggerModule;
--- a/toolkit/system/windowsproxy/nsWindowsSystemProxySettings.cpp
+++ b/toolkit/system/windowsproxy/nsWindowsSystemProxySettings.cpp
@@ -36,18 +36,18 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include <windows.h>
 #include "nsIWindowsRegKey.h"
 
 #include "nsISystemProxySettings.h"
-#include "nsIGenericFactory.h"
 #include "nsIServiceManager.h"
+#include "mozilla/ModuleUtils.h"
 #include "nsPrintfCString.h"
 #include "nsNetUtil.h"
 #include "nsISupportsPrimitives.h"
 #include "nsIURI.h"
 
 class nsWindowsSystemProxySettings : public nsISystemProxySettings
 {
 public:
@@ -304,17 +304,27 @@ nsWindowsSystemProxySettings::GetProxyFo
     return NS_OK;
 }
 
 #define NS_WINDOWSSYSTEMPROXYSERVICE_CID  /* 4e22d3ea-aaa2-436e-ada4-9247de57d367 */\
     { 0x4e22d3ea, 0xaaa2, 0x436e, \
         {0xad, 0xa4, 0x92, 0x47, 0xde, 0x57, 0xd3, 0x67 } }
 
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsWindowsSystemProxySettings, Init)
+NS_DEFINE_NAMED_CID(NS_WINDOWSSYSTEMPROXYSERVICE_CID);
 
-static const nsModuleComponentInfo components[] = {
-    { "Windows System Proxy Settings Service",
-        NS_WINDOWSSYSTEMPROXYSERVICE_CID,
-        NS_SYSTEMPROXYSETTINGS_CONTRACTID,
-        nsWindowsSystemProxySettingsConstructor }
+static const mozilla::Module::CIDEntry kSysProxyCIDs[] = {
+    { &kNS_WINDOWSSYSTEMPROXYSERVICE_CID, false, NULL, nsWindowsSystemProxySettingsConstructor },
+    { NULL }
 };
 
-NS_IMPL_NSGETMODULE(nsWindowsProxyModule, components)
+static const mozilla::Module::ContractIDEntry kSysProxyContracts[] = {
+    { NS_SYSTEMPROXYSETTINGS_CONTRACTID, &kNS_WINDOWSSYSTEMPROXYSERVICE_CID },
+    { NULL }
+};
+
+static const mozilla::Module kSysProxyModule = {
+    mozilla::Module::kVersion,
+    kSysProxyCIDs,
+    kSysProxyContracts
+};
+
+NSMODULE_DEFN(nsWindowsProxyModule) = &kSysProxyModule;
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -79,17 +79,17 @@
 #include "nsIChromeRegistry.h"
 #include "nsICommandLineRunner.h"
 #include "nsIComponentManager.h"
 #include "nsIComponentRegistrar.h"
 #include "nsIContentHandler.h"
 #include "nsIDialogParamBlock.h"
 #include "nsIDOMWindow.h"
 #include "nsIFastLoadService.h" // for PLATFORM_FASL_SUFFIX
-#include "nsIGenericFactory.h"
+#include "mozilla/ModuleUtils.h"
 #include "nsIIOService2.h"
 #include "nsIObserverService.h"
 #include "nsINativeAppSupport.h"
 #include "nsIProcess.h"
 #include "nsIProfileUnlocker.h"
 #include "nsIPromptService.h"
 #include "nsIServiceManager.h"
 #include "nsIStringBundle.h"
@@ -1002,18 +1002,18 @@ NS_IMETHODIMP
 nsXULAppInfo::SetSubmitReports(PRBool aEnabled)
 {
   return CrashReporter::SetSubmitReports(aEnabled);
 }
 
 #endif
 
 static const nsXULAppInfo kAppInfo;
-static NS_METHOD AppInfoConstructor(nsISupports* aOuter,
-                                    REFNSIID aIID, void **aResult)
+static nsresult AppInfoConstructor(nsISupports* aOuter,
+                                   REFNSIID aIID, void **aResult)
 {
   NS_ENSURE_NO_AGGREGATION(aOuter);
 
   return const_cast<nsXULAppInfo*>(&kAppInfo)->
     QueryInterface(aIID, aResult);
 }
 
 PRBool gLogConsoleErrors
@@ -1044,26 +1044,29 @@ PRBool gLogConsoleErrors
 class ScopedXPCOMStartup
 {
 public:
   ScopedXPCOMStartup() :
     mServiceManager(nsnull) { }
   ~ScopedXPCOMStartup();
 
   nsresult Initialize();
-  nsresult DoAutoreg();
-  nsresult RegisterProfileService();
   nsresult SetWindowCreator(nsINativeAppSupport* native);
 
+  static nsresult CreateAppSupport(nsISupports* aOuter, REFNSIID aIID, void** aResult);
+
 private:
   nsIServiceManager* mServiceManager;
+  static nsINativeAppSupport* gNativeAppSupport;
 };
 
 ScopedXPCOMStartup::~ScopedXPCOMStartup()
 {
+  NS_RELEASE(gNativeAppSupport);
+
   if (mServiceManager) {
 #ifdef XP_MACOSX
     // On OS X, we need a pool to catch cocoa objects that are autoreleased
     // during teardown.
     mozilla::MacAutoreleasePool pool;
 #endif
 
     nsCOMPtr<nsIAppStartup> appStartup (do_GetService(NS_APPSTARTUP_CONTRACTID));
@@ -1082,128 +1085,96 @@ ScopedXPCOMStartup::~ScopedXPCOMStartup(
 #endif
   }
 }
 
 // {95d89e3e-a169-41a3-8e56-719978e15b12}
 #define APPINFO_CID \
   { 0x95d89e3e, 0xa169, 0x41a3, { 0x8e, 0x56, 0x71, 0x99, 0x78, 0xe1, 0x5b, 0x12 } }
 
-static const nsModuleComponentInfo kComponents[] =
+// {0C4A446C-EE82-41f2-8D04-D366D2C7A7D4}
+static const nsCID kNativeAppSupportCID =
+  { 0xc4a446c, 0xee82, 0x41f2, { 0x8d, 0x4, 0xd3, 0x66, 0xd2, 0xc7, 0xa7, 0xd4 } };
+
+// {5F5E59CE-27BC-47eb-9D1F-B09CA9049836}
+static const nsCID kProfileServiceCID =
+  { 0x5f5e59ce, 0x27bc, 0x47eb, { 0x9d, 0x1f, 0xb0, 0x9c, 0xa9, 0x4, 0x98, 0x36 } };
+
+static already_AddRefed<nsIFactory>
+ProfileServiceFactoryConstructor(const mozilla::Module& module, const mozilla::Module::CIDEntry& entry)
 {
-  {
-    "nsXULAppInfo",
-    APPINFO_CID,
-    XULAPPINFO_SERVICE_CONTRACTID,
-    AppInfoConstructor
-  },
-  {
-    "nsXULAppInfo",
-    APPINFO_CID,
-    XULRUNTIME_SERVICE_CONTRACTID,
-    AppInfoConstructor
-  }
-#ifdef MOZ_CRASHREPORTER
-,
-  {
-    "nsXULAppInfo",
-    APPINFO_CID,
-    NS_CRASHREPORTER_CONTRACTID,
-    AppInfoConstructor
-  }
-#endif
+  nsCOMPtr<nsIFactory> factory;
+  NS_NewToolkitProfileFactory(getter_AddRefs(factory));
+  return factory.forget();
+}
+
+NS_DEFINE_NAMED_CID(APPINFO_CID);
+
+static const mozilla::Module::CIDEntry kXRECIDs[] = {
+  { &kAPPINFO_CID, false, NULL, AppInfoConstructor },
+  { &kProfileServiceCID, false, ProfileServiceFactoryConstructor, NULL },
+  { &kNativeAppSupportCID, false, NULL, ScopedXPCOMStartup::CreateAppSupport },
+  { NULL }
 };
 
-NS_IMPL_NSGETMODULE(Apprunner, kComponents)
+static const mozilla::Module::ContractIDEntry kXREContracts[] = {
+  { XULAPPINFO_SERVICE_CONTRACTID, &kAPPINFO_CID },
+  { XULRUNTIME_SERVICE_CONTRACTID, &kAPPINFO_CID },
+  { NS_CRASHREPORTER_CONTRACTID, &kAPPINFO_CID },
+  { NS_PROFILESERVICE_CONTRACTID, &kProfileServiceCID },
+  { NS_NATIVEAPPSUPPORT_CONTRACTID, &kNativeAppSupportCID },
+  { NULL }
+};
+
+static const mozilla::Module kXREModule = {
+  mozilla::Module::kVersion,
+  kXRECIDs,
+  kXREContracts
+};
+
+NSMODULE_DEFN(Apprunner) = &kXREModule;
 
 #if !defined(_BUILD_STATIC_BIN) && !defined(MOZ_ENABLE_LIBXUL)
-static nsStaticModuleInfo const kXREStaticModules[] =
+static mozilla::Module const *const kXREStaticModules[] =
 {
-  {
-    "Apprunner",
-    Apprunner_NSGetModule
-  }
+  Apprunner_NSModule,
+  NULL
 };
 
-nsStaticModuleInfo const *const kPStaticModules = kXREStaticModules;
-PRUint32 const kStaticModuleCount = NS_ARRAY_LENGTH(kXREStaticModules);
+mozilla::Module const *const *const kPStaticModules = kXREStaticModule;
 #endif
 
 nsresult
 ScopedXPCOMStartup::Initialize()
 {
   NS_ASSERTION(gDirServiceProvider, "Should not get here!");
 
   nsresult rv;
 #ifdef MOZ_OMNIJAR
   nsCOMPtr<nsILocalFile> lf;
   rv = XRE_GetBinaryPath(gArgv[0], getter_AddRefs(lf));
   if (NS_SUCCEEDED(rv))
     mozilla::SetOmnijar(lf);
 #endif
 
-  rv = NS_InitXPCOM3(&mServiceManager, gDirServiceProvider->GetAppDir(),
-                     gDirServiceProvider,
-                     kPStaticModules, kStaticModuleCount);
+  rv = NS_InitXPCOM2(&mServiceManager, gDirServiceProvider->GetAppDir(),
+                     gDirServiceProvider);
   if (NS_FAILED(rv)) {
     NS_ERROR("Couldn't start xpcom!");
     mServiceManager = nsnull;
   }
   else {
     nsCOMPtr<nsIComponentRegistrar> reg =
       do_QueryInterface(mServiceManager);
     NS_ASSERTION(reg, "Service Manager doesn't QI to Registrar.");
   }
 
   return rv;
 }
 
-// {0C4A446C-EE82-41f2-8D04-D366D2C7A7D4}
-static const nsCID kNativeAppSupportCID =
-  { 0xc4a446c, 0xee82, 0x41f2, { 0x8d, 0x4, 0xd3, 0x66, 0xd2, 0xc7, 0xa7, 0xd4 } };
-
-// {5F5E59CE-27BC-47eb-9D1F-B09CA9049836}
-static const nsCID kProfileServiceCID =
-  { 0x5f5e59ce, 0x27bc, 0x47eb, { 0x9d, 0x1f, 0xb0, 0x9c, 0xa9, 0x4, 0x98, 0x36 } };
-
-nsresult
-ScopedXPCOMStartup::RegisterProfileService()
-{
-  NS_ASSERTION(mServiceManager, "Not initialized!");
-
-  nsCOMPtr<nsIFactory> factory;
-  NS_NewToolkitProfileFactory(getter_AddRefs(factory));
-  if (!factory) return NS_ERROR_OUT_OF_MEMORY;
-
-  nsCOMPtr<nsIComponentRegistrar> reg (do_QueryInterface(mServiceManager));
-  if (!reg) return NS_ERROR_NO_INTERFACE;
-
-  return reg->RegisterFactory(kProfileServiceCID,
-                              "Toolkit Profile Service",
-                              NS_PROFILESERVICE_CONTRACTID,
-                              factory);
-}
-
-nsresult
-ScopedXPCOMStartup::DoAutoreg()
-{
-#ifdef DEBUG
-  // _Always_ autoreg if we're in a debug build, under the assumption
-  // that people are busily modifying components and will be angry if
-  // their changes aren't noticed.
-  nsCOMPtr<nsIComponentRegistrar> registrar
-    (do_QueryInterface(mServiceManager));
-  NS_ASSERTION(registrar, "Where's the component registrar?");
-
-  registrar->AutoRegister(nsnull);
-#endif
-
-  return NS_OK;
-}
-
 /**
  * This is a little factory class that serves as a singleton-service-factory
  * for the nativeappsupport object.
  */
 class nsSingletonFactory : public nsIFactory
 {
 public:
   NS_DECL_ISUPPORTS
@@ -1244,30 +1215,17 @@ nsSingletonFactory::LockFactory(PRBool)
  * Set our windowcreator on the WindowWatcher service.
  */
 nsresult
 ScopedXPCOMStartup::SetWindowCreator(nsINativeAppSupport* native)
 {
   NS_TIME_FUNCTION;
   nsresult rv;
 
-  nsCOMPtr<nsIComponentRegistrar> registrar
-    (do_QueryInterface(mServiceManager));
-  NS_ASSERTION(registrar, "Where's the component registrar?");
-
-  nsCOMPtr<nsIFactory> nativeFactory = new nsSingletonFactory(native);
-  NS_ENSURE_TRUE(nativeFactory, NS_ERROR_OUT_OF_MEMORY);
-
-  rv = registrar->RegisterFactory(kNativeAppSupportCID,
-                                  "Native App Support",
-                                  NS_NATIVEAPPSUPPORT_CONTRACTID,
-                                  nativeFactory);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  NS_TIME_FUNCTION_MARK("RegisterFactory done");
+  NS_IF_ADDREF(gNativeAppSupport = native);
 
   // Inform the chrome registry about OS accessibility
   nsCOMPtr<nsIToolkitChromeRegistry> cr =
     mozilla::services::GetToolkitChromeRegistryService();
   NS_TIME_FUNCTION_MARK("Got ToolkitChromeRegistry service");
 
   if (cr)
     cr->CheckForOSAccessibility();
@@ -1283,16 +1241,30 @@ ScopedXPCOMStartup::SetWindowCreator(nsI
     (do_GetService(NS_WINDOWWATCHER_CONTRACTID, &rv));
   NS_ENSURE_SUCCESS(rv, rv);
   
   NS_TIME_FUNCTION_MARK("Got WindowWatcher service");
 
   return wwatch->SetWindowCreator(creator);
 }
 
+/* static */ nsresult
+ScopedXPCOMStartup::CreateAppSupport(nsISupports* aOuter, REFNSIID aIID, void** aResult)
+{
+  if (aOuter)
+    return NS_ERROR_NO_AGGREGATION;
+
+  if (!gNativeAppSupport)
+    return NS_ERROR_NOT_INITIALIZED;
+
+  return gNativeAppSupport->QueryInterface(aIID, aResult);
+}
+
+nsINativeAppSupport* ScopedXPCOMStartup::gNativeAppSupport;
+
 /**
  * A helper class which calls NS_LogInit/NS_LogTerm in its scope.
  */
 class ScopedLogging
 {
 public:
   ScopedLogging() { NS_LogInit(); }
   ~ScopedLogging() { NS_LogTerm(); }
@@ -1302,17 +1274,16 @@ static void DumpArbitraryHelp()
 {
   nsresult rv;
 
   ScopedLogging log;
 
   {
     ScopedXPCOMStartup xpcom;
     xpcom.Initialize();
-    xpcom.DoAutoreg();
 
     nsCOMPtr<nsICommandLineRunner> cmdline
       (do_CreateInstance("@mozilla.org/toolkit/command-line;1"));
     if (!cmdline)
       return;
 
     nsCString text;
     rv = cmdline->GetHelpText(text);
@@ -1822,18 +1793,17 @@ ProfileLockedDialog(nsILocalFile* aProfi
                     nsINativeAppSupport* aNative, nsIProfileLock* *aResult)
 {
   nsresult rv;
 
   ScopedXPCOMStartup xpcom;
   rv = xpcom.Initialize();
   NS_ENSURE_SUCCESS(rv, rv);
 
-  rv = xpcom.DoAutoreg();
-  rv |= xpcom.SetWindowCreator(aNative);
+  rv = xpcom.SetWindowCreator(aNative);
   NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
 
   { //extra scoping is needed so we release these components before xpcom shutdown
     nsCOMPtr<nsIStringBundleService> sbs =
       mozilla::services::GetStringBundleService();
     NS_ENSURE_TRUE(sbs, NS_ERROR_FAILURE);
 
     nsCOMPtr<nsIStringBundle> sb;
@@ -1896,18 +1866,17 @@ static nsresult
 ProfileMissingDialog(nsINativeAppSupport* aNative)
 {
   nsresult rv;
 
   ScopedXPCOMStartup xpcom;
   rv = xpcom.Initialize();
   NS_ENSURE_SUCCESS(rv, rv);
 
-  rv = xpcom.DoAutoreg();
-  rv |= xpcom.SetWindowCreator(aNative);
+  rv = xpcom.SetWindowCreator(aNative);
   NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
 
   { //extra scoping is needed so we release these components before xpcom shutdown
     nsCOMPtr<nsIStringBundleService> sbs =
       mozilla::services::GetStringBundleService();
     NS_ENSURE_TRUE(sbs, NS_ERROR_FAILURE);
   
     nsCOMPtr<nsIStringBundle> sb;
@@ -1952,19 +1921,17 @@ ShowProfileManager(nsIToolkitProfileServ
   PRUnichar* profileNamePtr;
   nsCAutoString profileName;
 
   {
     ScopedXPCOMStartup xpcom;
     rv = xpcom.Initialize();
     NS_ENSURE_SUCCESS(rv, rv);
 
-    rv = xpcom.DoAutoreg();
-    rv |= xpcom.RegisterProfileService();
-    rv |= xpcom.SetWindowCreator(aNative);
+    rv = xpcom.SetWindowCreator(aNative);
     NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
 
 #ifdef XP_MACOSX
     CommandLineServiceMac::SetupMacCommandLine(gRestartArgc, gRestartArgv, PR_TRUE);
 #endif
 
 #ifdef XP_WIN
     // we don't have to wait here because profile manager window will pump
@@ -2044,19 +2011,16 @@ ImportProfiles(nsIToolkitProfileService*
 
   SaveToEnv("XRE_IMPORT_PROFILES=1");
 
   // try to import old-style profiles
   { // scope XPCOM
     ScopedXPCOMStartup xpcom;
     rv = xpcom.Initialize();
     if (NS_SUCCEEDED(rv)) {
-      xpcom.DoAutoreg();
-      xpcom.RegisterProfileService();
-
 #ifdef XP_MACOSX
       CommandLineServiceMac::SetupMacCommandLine(gRestartArgc, gRestartArgv, PR_TRUE);
 #endif
 
       nsCOMPtr<nsIProfileMigrator> migrator
         (do_GetService(NS_PROFILEMIGRATOR_CONTRACTID));
       if (migrator) {
         migrator->Import();
@@ -3364,18 +3328,16 @@ XRE_main(int argc, char* argv[], const n
     // own risk. Useful for debugging or for tinderboxes where child 
     // processes can be problematic.
     {
       // Start the real application
       ScopedXPCOMStartup xpcom;
       rv = xpcom.Initialize();
       NS_TIME_FUNCTION_MARK("ScopedXPCOMStartup: Initialize");
       NS_ENSURE_SUCCESS(rv, 1); 
-      rv = xpcom.DoAutoreg();
-      NS_TIME_FUNCTION_MARK("ScopedXPCOMStartup: DoAutoreg");
 
 
 #ifdef NS_FUNCTION_TIMER
       // initialize some common services, so we don't pay the cost for these at odd times later on;
       // SetWindowCreator -> ChromeRegistry -> IOService -> SocketTransportService -> (nspr wspm init), Prefs
       {
         nsCOMPtr<nsISupports> comp;
 
@@ -3394,19 +3356,17 @@ XRE_main(int argc, char* argv[], const n
         comp = do_GetService("@mozilla.org/chrome/chrome-registry;1");
         NS_TIME_FUNCTION_MARK("Chrome Registry Service");
 
         comp = do_GetService("@mozilla.org/focus-event-suppressor-service;1");
         NS_TIME_FUNCTION_MARK("Focus Event Suppressor Service");
       }
 #endif
 
-      rv |= xpcom.RegisterProfileService();
-      NS_TIME_FUNCTION_MARK("ScopedXPCOMStartup: RegisterProfileService");
-      rv |= xpcom.SetWindowCreator(nativeApp);
+      rv = xpcom.SetWindowCreator(nativeApp);
       NS_TIME_FUNCTION_MARK("ScopedXPCOMStartup: SetWindowCreator");
       NS_ENSURE_SUCCESS(rv, 1);
 
       NS_TIME_FUNCTION_MARK("ScopedXPCOMStartup: Done");
 
 #ifdef MOZ_CRASHREPORTER
       // tell the crash reporter to also send the release channel
       nsCOMPtr<nsIPrefService> prefs = do_GetService("@mozilla.org/preferences-service;1", &rv);
--- a/toolkit/xre/nsEmbedFunctions.cpp
+++ b/toolkit/xre/nsEmbedFunctions.cpp
@@ -63,17 +63,16 @@
 #include <process.h>
 #endif
 
 #include "nsAppDirectoryServiceDefs.h"
 #include "nsAppRunner.h"
 #include "nsAutoRef.h"
 #include "nsDirectoryServiceDefs.h"
 #include "nsExceptionHandler.h"
-#include "nsStaticComponents.h"
 #include "nsString.h"
 #include "nsThreadUtils.h"
 #include "nsWidgetsCID.h"
 #include "nsXREDirProvider.h"
 
 #ifdef MOZ_IPC
 #include "nsX11ErrorHandler.h"
 #include "base/at_exit.h"
@@ -110,47 +109,36 @@ using mozilla::startup::sChildProcessTyp
 #endif
 
 static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID);
 
 #ifdef XP_WIN
 static const PRUnichar kShellLibraryName[] =  L"shell32.dll";
 #endif
 
-void
-XRE_GetStaticComponents(nsStaticModuleInfo const **aStaticComponents,
-                        PRUint32 *aComponentCount)
-{
-  *aStaticComponents = kPStaticModules;
-  *aComponentCount = kStaticModuleCount;
-}
-
 nsresult
 XRE_LockProfileDirectory(nsILocalFile* aDirectory,
                          nsISupports* *aLockObject)
 {
   nsCOMPtr<nsIProfileLock> lock;
 
   nsresult rv = NS_LockProfilePath(aDirectory, nsnull, nsnull,
                                    getter_AddRefs(lock));
   if (NS_SUCCEEDED(rv))
     NS_ADDREF(*aLockObject = lock);
 
   return rv;
 }
 
-static nsStaticModuleInfo *sCombined;
 static PRInt32 sInitCounter;
 
 nsresult
-XRE_InitEmbedding(nsILocalFile *aLibXULDirectory,
-                  nsILocalFile *aAppDirectory,
-                  nsIDirectoryServiceProvider *aAppDirProvider,
-                  nsStaticModuleInfo const *aStaticComponents,
-                  PRUint32 aStaticComponentCount)
+XRE_InitEmbedding2(nsILocalFile *aLibXULDirectory,
+		   nsILocalFile *aAppDirectory,
+		   nsIDirectoryServiceProvider *aAppDirProvider)
 {
   // Initialize some globals to make nsXREDirProvider happy
   static char* kNullCommandLine[] = { nsnull };
   gArgv = kNullCommandLine;
   gArgc = 0;
 
   NS_ENSURE_ARG(aLibXULDirectory);
 
@@ -166,30 +154,17 @@ XRE_InitEmbedding(nsILocalFile *aLibXULD
   if (!gDirServiceProvider)
     return NS_ERROR_OUT_OF_MEMORY;
 
   rv = gDirServiceProvider->Initialize(aAppDirectory, aLibXULDirectory,
                                        aAppDirProvider);
   if (NS_FAILED(rv))
     return rv;
 
-  // Combine the toolkit static components and the app components.
-  PRUint32 combinedCount = kStaticModuleCount + aStaticComponentCount;
-
-  sCombined = new nsStaticModuleInfo[combinedCount];
-  if (!sCombined)
-    return NS_ERROR_OUT_OF_MEMORY;
-
-  memcpy(sCombined, kPStaticModules,
-         sizeof(nsStaticModuleInfo) * kStaticModuleCount);
-  memcpy(sCombined + kStaticModuleCount, aStaticComponents,
-         sizeof(nsStaticModuleInfo) * aStaticComponentCount);
-
-  rv = NS_InitXPCOM3(nsnull, aAppDirectory, gDirServiceProvider,
-                     sCombined, combinedCount);
+  rv = NS_InitXPCOM2(nsnull, aAppDirectory, gDirServiceProvider);
   if (NS_FAILED(rv))
     return rv;
 
   // We do not need to autoregister components here. The CheckCompatibility()
   // bits in nsAppRunner.cpp check for an invalidation flag in
   // compatibility.ini.
   // If the app wants to autoregister every time (for instance, if it's debug),
   // it can do so after we return from this function.
@@ -217,17 +192,16 @@ XRE_TermEmbedding()
   if (--sInitCounter != 0)
     return;
 
   NS_ASSERTION(gDirServiceProvider,
                "XRE_TermEmbedding without XRE_InitEmbedding");
 
   gDirServiceProvider->DoShutdown();
   NS_ShutdownXPCOM(nsnull);
-  delete [] sCombined;
   delete gDirServiceProvider;
 }
 
 const char*
 XRE_ChildProcessTypeToString(GeckoProcessType aProcessType)
 {
   return (aProcessType < GeckoProcessType_End) ?
     kGeckoProcessTypeString[aProcessType] : nsnull;
--- a/toolkit/xre/nsXREDirProvider.cpp
+++ b/toolkit/xre/nsXREDirProvider.cpp
@@ -651,28 +651,30 @@ nsXREDirProvider::GetFilesInternal(const
     LoadBundleDirectories();
     LoadDirsIntoArray(mAppBundleDirectories,
                       kAppendNothing, directories);
     LoadDirsIntoArray(mExtensionDirectories,
                       kAppendNothing, directories);
 
     rv = NS_NewArrayEnumerator(aResult, directories);
   }
+#if 0
   else if (!strcmp(aProperty, NS_XPCOM_COMPONENT_DIR_LIST)) {
     static const char *const kAppendCompDir[] = { "components", nsnull };
     nsCOMArray<nsIFile> directories;
 
     LoadBundleDirectories();
     LoadDirsIntoArray(mAppBundleDirectories,
                       kAppendCompDir, directories);
     LoadDirsIntoArray(mExtensionDirectories,
                       kAppendCompDir, directories);
 
     rv = NS_NewArrayEnumerator(aResult, directories);
   }
+#endif
   else if (!strcmp(aProperty, NS_APP_PREFS_DEFAULTS_DIR_LIST)) {
     nsCOMArray<nsIFile> directories;
 
     LoadBundleDirectories();
 
     LoadAppDirIntoArray(mXULAppDir, kAppendPrefDir, directories);
     LoadDirsIntoArray(mAppBundleDirectories,
                       kAppendPrefDir, directories);
--- a/xpcom/base/nsAgg.h
+++ b/xpcom/base/nsAgg.h
@@ -307,17 +307,17 @@ nsresult                                
     nsISupports *s = static_cast<nsISupports*>(p);                          \
     NS_ASSERTION(CheckForRightISupports(s),                                 \
                  "not the nsISupports pointer we expect");                  \
     _class *tmp = static_cast<_class*>(Downcast(s));                        \
     if (!tmp->IsPartOfAggregated())                                         \
         NS_IMPL_CYCLE_COLLECTION_DESCRIBE(_class, tmp->mRefCnt.get())
 
 #define NS_GENERIC_AGGREGATED_CONSTRUCTOR(_InstanceClass)                   \
-static NS_METHOD                                                            \
+static nsresult                                                             \
 _InstanceClass##Constructor(nsISupports *aOuter, REFNSIID aIID,             \
                             void **aResult)                                 \
 {                                                                           \
     *aResult = nsnull;                                                      \
                                                                             \
     NS_ENSURE_PROPER_AGGREGATION(aOuter, aIID);                             \
                                                                             \
     _InstanceClass* inst = new _InstanceClass(aOuter);                      \
@@ -330,17 +330,17 @@ static NS_METHOD                        
     if (NS_FAILED(rv)) {                                                    \
         delete inst;                                                        \
     }                                                                       \
                                                                             \
     return rv;                                                              \
 }                                                                           \
 
 #define NS_GENERIC_AGGREGATED_CONSTRUCTOR_INIT(_InstanceClass, _InitMethod) \
-static NS_METHOD                                                            \
+static nsresult                                                             \
 _InstanceClass##Constructor(nsISupports *aOuter, REFNSIID aIID,             \
                             void **aResult)                                 \
 {                                                                           \
     *aResult = nsnull;                                                      \
                                                                             \
     NS_ENSURE_PROPER_AGGREGATION(aOuter, aIID);                             \
                                                                             \
     _InstanceClass* inst = new _InstanceClass(aOuter);                      \
--- a/xpcom/base/nsConsoleService.cpp
+++ b/xpcom/base/nsConsoleService.cpp
@@ -50,16 +50,17 @@
 #include "nsThreadUtils.h"
 
 #include "nsConsoleService.h"
 #include "nsConsoleMessage.h"
 #include "nsIClassInfoImpl.h"
 
 NS_IMPL_THREADSAFE_ADDREF(nsConsoleService)
 NS_IMPL_THREADSAFE_RELEASE(nsConsoleService)
+NS_IMPL_CLASSINFO(nsConsoleService, NULL, nsIClassInfo::THREADSAFE | nsIClassInfo::SINGLETON)
 NS_IMPL_QUERY_INTERFACE1_CI(nsConsoleService, nsIConsoleService)
 NS_IMPL_CI_INTERFACE_GETTER1(nsConsoleService, nsIConsoleService)
 
 nsConsoleService::nsConsoleService()
     : mMessages(nsnull), mCurrent(0), mFull(PR_FALSE), mListening(PR_FALSE), mLock(nsnull)
 {
     // XXX grab this from a pref!
     // hm, but worry about circularity, bc we want to be able to report
--- a/xpcom/base/nsDebugImpl.cpp
+++ b/xpcom/base/nsDebugImpl.cpp
@@ -495,17 +495,17 @@ Break(const char *aMsg)
    RealBreak();
 #else
    // don't know how to break on this platform
 #endif
 }
 
 static const nsDebugImpl kImpl;
 
-NS_METHOD
+nsresult
 nsDebugImpl::Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr)
 {
   NS_ENSURE_NO_AGGREGATION(outer);
 
   return const_cast<nsDebugImpl*>(&kImpl)->
     QueryInterface(aIID, aInstancePtr);
 }
 
--- a/xpcom/base/nsDebugImpl.h
+++ b/xpcom/base/nsDebugImpl.h
@@ -39,17 +39,17 @@
 
 class nsDebugImpl : public nsIDebug2
 {
 public:
     NS_DECL_ISUPPORTS
     NS_DECL_NSIDEBUG
     NS_DECL_NSIDEBUG2
     
-    static NS_METHOD Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr);
+    static nsresult Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr);
 };
 
 
 #define NS_DEBUG_CONTRACTID "@mozilla.org/xpcom/debug;1"
 #define NS_DEBUG_CLASSNAME  "nsDebug Interface"
 #define NS_DEBUG_CID                                 \
 { /* a80b1fb3-aaf6-4852-b678-c27eb7a518af */         \
   0xa80b1fb3,                                        \
--- a/xpcom/base/nsErrorService.cpp
+++ b/xpcom/base/nsErrorService.cpp
@@ -88,17 +88,17 @@ nsInt2StrHashtable::Remove(PRUint32 key)
     NS_Free(oldValue);
   return NS_OK;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 
 NS_IMPL_ISUPPORTS1(nsErrorService, nsIErrorService)
 
-NS_METHOD
+nsresult
 nsErrorService::Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr)
 {
     NS_ENSURE_NO_AGGREGATION(outer);
     nsErrorService* serv = new nsErrorService();
     if (serv == nsnull)
         return NS_ERROR_OUT_OF_MEMORY;
     NS_ADDREF(serv);
     nsresult rv = serv->QueryInterface(aIID, aInstancePtr);
--- a/xpcom/base/nsErrorService.h
+++ b/xpcom/base/nsErrorService.h
@@ -57,17 +57,17 @@ protected:
 class nsErrorService : public nsIErrorService
 {
 public:
     NS_DECL_ISUPPORTS
     NS_DECL_NSIERRORSERVICE
 
     nsErrorService() {}
 
-    static NS_METHOD
+    static nsresult
     Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr);
 
 private:
     ~nsErrorService() {}
 
 protected:
     nsInt2StrHashtable mErrorStringBundleURLMap;
     nsInt2StrHashtable mErrorStringBundleKeyMap;
--- a/xpcom/base/nsMemoryImpl.h
+++ b/xpcom/base/nsMemoryImpl.h
@@ -51,18 +51,18 @@ class nsMemoryImpl : public nsIMemory
 public:
     // We don't use the generic macros because we are a special static object
     NS_IMETHOD QueryInterface(REFNSIID aIID, void** aResult);
     NS_IMETHOD_(nsrefcnt) AddRef(void) { return 1; }
     NS_IMETHOD_(nsrefcnt) Release(void) { return 1; }
 
     NS_DECL_NSIMEMORY
 
-    static NS_METHOD Create(nsISupports* outer,
-                            const nsIID& aIID, void **aResult);
+    static nsresult Create(nsISupports* outer,
+                           const nsIID& aIID, void **aResult);
 
     NS_HIDDEN_(nsresult) FlushMemory(const PRUnichar* aReason, PRBool aImmediate);
     NS_HIDDEN_(nsresult) RunFlushers(const PRUnichar* aReason);
 
 protected:
     struct FlushEvent : public nsIRunnable {
         NS_DECL_ISUPPORTS_INHERITED
         NS_DECL_NSIRUNNABLE
--- a/xpcom/build/XPCOM.h
+++ b/xpcom/build/XPCOM.h
@@ -57,17 +57,16 @@
 
 #include "nsIArray.h"
 #include "nsIAtom.h"
 #include "nsIAtomService.h"
 #include "nsICategoryManager.h"
 #include "nsIClassInfo.h"
 #include "nsICollection.h"
 #include "nsIComponentManager.h"
-#include "nsIComponentRegistrar.h"
 #include "nsIConsoleListener.h"
 #include "nsIConsoleMessage.h"
 #include "nsIConsoleService.h"
 #include "nsIDebug.h"
 #include "nsIDirectoryEnumerator.h"
 #include "nsIEnumerator.h"
 #include "nsIEnvironment.h"
 #include "nsIErrorService.h"
@@ -80,18 +79,16 @@
 #include "nsIFile.h"
 #include "nsIHashable.h"
 #include "nsIINIParser.h"
 #include "nsIInputStream.h"
 #include "nsIInterfaceRequestor.h"
 #include "nsILineInputStream.h"
 #include "nsIMemory.h"
 #include "nsIMemoryReporter.h"
-#include "nsIModule.h"
-#include "nsIModuleLoader.h"
 #include "nsIMutable.h"
 #include "nsIObserver.h"
 #include "nsIObserverService.h"
 #include "nsIOutputStream.h"
 #include "nsIProcess.h"
 #include "nsIProgrammingLanguage.h"
 #include "nsIProperties.h"
 #include "nsIPropertyBag2.h"
@@ -168,17 +165,17 @@
 #include "nsArrayEnumerator.h"
 #include "nsArrayUtils.h"
 #include "nsAutoLock.h"
 #include "nsCRTGlue.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsDeque.h"
 #include "nsEnumeratorUtils.h"
 #include "nsIClassInfoImpl.h"
-#include "nsIGenericFactory.h"
+#include "mozilla/ModuleUtils.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsINIParser.h"
 #include "nsProxyRelease.h"
 #include "nsTObserverArray.h"
 #include "nsTextFormatter.h"
 #include "nsThreadUtils.h"
 #include "nsVersionComparator.h"
 #include "nsXPTCUtils.h"
new file mode 100644
--- /dev/null
+++ b/xpcom/build/XPCOMModule.inc
@@ -0,0 +1,89 @@
+    COMPONENT(MEMORY, nsMemoryImpl::Create)
+    COMPONENT(DEBUG,  nsDebugImpl::Create)
+    COMPONENT(ERRORSERVICE, nsErrorService::Create)
+
+    COMPONENT(CATEGORYMANAGER, nsCategoryManager::Create)
+
+    COMPONENT(BYTEBUFFER, ByteBufferImpl::Create)
+    COMPONENT(SCRIPTABLEINPUTSTREAM, nsScriptableInputStream::Create)
+    COMPONENT(BINARYINPUTSTREAM, nsBinaryInputStreamConstructor)
+    COMPONENT(BINARYOUTPUTSTREAM, nsBinaryOutputStreamConstructor)
+    COMPONENT(STORAGESTREAM, nsStorageStreamConstructor)
+    COMPONENT(VERSIONCOMPARATOR, nsVersionComparatorImplConstructor)
+    COMPONENT(PIPE, nsPipeConstructor)
+
+    COMPONENT(PROPERTIES, nsPropertiesConstructor)
+
+    COMPONENT(PERSISTENTPROPERTIES, nsPersistentProperties::Create)
+
+    COMPONENT(SUPPORTSARRAY, nsSupportsArray::Create)
+    COMPONENT(ARRAY, nsArrayConstructor)
+    COMPONENT(CONSOLESERVICE, nsConsoleServiceConstructor)
+    COMPONENT(EXCEPTIONSERVICE, nsExceptionServiceConstructor)
+    COMPONENT(ATOMSERVICE, nsAtomServiceConstructor)
+#ifdef MOZ_TIMELINE
+    COMPONENT(TIMELINESERVICE, nsTimelineServiceConstructor)
+#endif
+    COMPONENT(OBSERVERSERVICE, nsObserverService::Create)
+
+    COMPONENT(XPCOMPROXY, nsProxyObjectManager::Create)
+
+    COMPONENT(TIMER, nsTimerImplConstructor)
+
+#define COMPONENT_SUPPORTS(TYPE, Type)                                         \
+  COMPONENT(SUPPORTS_##TYPE, nsSupports##Type##ImplConstructor)
+
+    COMPONENT_SUPPORTS(ID, ID)
+    COMPONENT_SUPPORTS(STRING, String)
+    COMPONENT_SUPPORTS(CSTRING, CString)
+    COMPONENT_SUPPORTS(PRBOOL, PRBool)
+    COMPONENT_SUPPORTS(PRUINT8, PRUint8)
+    COMPONENT_SUPPORTS(PRUINT16, PRUint16)
+    COMPONENT_SUPPORTS(PRUINT32, PRUint32)
+    COMPONENT_SUPPORTS(PRUINT64, PRUint64)
+    COMPONENT_SUPPORTS(PRTIME, PRTime)
+    COMPONENT_SUPPORTS(CHAR, Char)
+    COMPONENT_SUPPORTS(PRINT16, PRInt16)
+    COMPONENT_SUPPORTS(PRINT32, PRInt32)
+    COMPONENT_SUPPORTS(PRINT64, PRInt64)
+    COMPONENT_SUPPORTS(FLOAT, Float)
+    COMPONENT_SUPPORTS(DOUBLE, Double)
+    COMPONENT_SUPPORTS(VOID, Void)
+    COMPONENT_SUPPORTS(INTERFACE_POINTER, InterfacePointer)
+
+#undef COMPONENT_SUPPORTS
+    COMPONENT(LOCAL_FILE, nsLocalFile::nsLocalFileConstructor)
+    COMPONENT(DIRECTORY_SERVICE, nsDirectoryService::Create)
+    COMPONENT(PROCESS, nsProcessConstructor)
+    COMPONENT(ENVIRONMENT, nsEnvironment::Create)
+
+    COMPONENT(THREADMANAGER, nsThreadManagerGetSingleton)
+    COMPONENT(THREADPOOL, nsThreadPoolConstructor)
+
+    COMPONENT(STRINGINPUTSTREAM, nsStringInputStreamConstructor)
+    COMPONENT(MULTIPLEXINPUTSTREAM, nsMultiplexInputStreamConstructor)
+
+#ifndef MOZ_NO_FAST_LOAD
+    COMPONENT(FASTLOADSERVICE, nsFastLoadService::Create)
+#endif
+
+    COMPONENT(VARIANT, nsVariantConstructor)
+    COMPONENT(INTERFACEINFOMANAGER_SERVICE, nsXPTIInterfaceInfoManagerGetSingleton)
+
+    COMPONENT(RECYCLINGALLOCATOR, nsRecyclingAllocatorImplConstructor)
+
+    COMPONENT(HASH_PROPERTY_BAG, nsHashPropertyBagConstructor)
+
+    COMPONENT(UUID_GENERATOR, nsUUIDGeneratorConstructor)
+
+#if defined(XP_WIN)
+    COMPONENT(WINDOWSREGKEY, nsWindowsRegKeyConstructor)
+#endif
+
+#ifdef XP_MACOSX
+    COMPONENT(MACUTILSIMPL, nsMacUtilsImplConstructor)
+#endif
+
+    COMPONENT(SYSTEMINFO, nsSystemInfoConstructor)
+    COMPONENT(MEMORY_REPORTER_MANAGER, nsMemoryReporterManagerConstructor)
+    COMPONENT(IOUTIL, nsIOUtilConstructor)
--- a/xpcom/build/dlldeps.cpp
+++ b/xpcom/build/dlldeps.cpp
@@ -40,16 +40,17 @@
 
 #ifdef XP_WIN
 #include <windows.h>
 #include "nsWindowsRegKey.h"
 #ifdef DEBUG
 #include "pure.h"
 #endif
 #endif
+#include "nsXULAppAPI.h"
 #include "nsXPCOMGlue.h"
 #include "nsVoidArray.h"
 #include "nsTArray.h"
 #include "nsIAtom.h"
 #include "nsFixedSizeAllocator.h"
 #include "nsRecyclingAllocator.h"
 #include "nsDeque.h"
 #include "nsTraceRefcnt.h"
@@ -61,17 +62,16 @@
 #include "nsString.h"
 #include "nsPrintfCString.h"
 #include "nsSupportsArray.h"
 #include "nsArrayEnumerator.h"
 #include "nsProxyRelease.h"
 #include "xpt_xdr.h"
 #include "xptcall.h"
 #include "nsILocalFile.h"
-#include "nsIGenericFactory.h"
 #include "nsIPipe.h"
 #include "nsStreamUtils.h"
 #include "nsWeakReference.h"
 #include "nsTextFormatter.h"
 #include "nsIStorageStream.h"
 #include "nsStringStream.h"
 #include "nsLinebreakConverter.h"
 #include "nsIBinaryInputStream.h"
@@ -173,18 +173,16 @@ void XXXNeverCalled()
     nsTraceRefcntImpl::DumpStatistics();
     NS_NewEmptyEnumerator(nsnull);
     NS_QuickSort(nsnull, 0, 0, nsnull, nsnull);
     nsString();
     NS_ProxyRelease(nsnull, nsnull, PR_FALSE);
     XPT_DoString(nsnull, nsnull, nsnull);
     XPT_DoHeader(nsnull, nsnull, nsnull);
     NS_InvokeByIndex(nsnull, 0, 0, nsnull);
-    NS_NewGenericFactory(nsnull, nsnull);
-    NS_NewGenericModule2(nsnull, nsnull);
     NS_GetWeakReference(nsnull);
     nsCOMPtr<nsISupports> dummyFoo(do_GetInterface(nsnull));
     NS_NewStorageStream(0,0, nsnull);
     nsString foo;
     nsPrintfCString bar("");
     nsLinebreakConverter::ConvertStringLineBreaks(foo, 
     nsLinebreakConverter::eLinebreakAny, nsLinebreakConverter::eLinebreakContent);
     NS_NewLocalFile(EmptyString(), PR_FALSE, nsnull);
@@ -223,18 +221,16 @@ void XXXNeverCalled()
     NS_CopyNativeToUnicode(str2, str1);
     NS_CopyUnicodeToNative(str1, str2);
     {
       nsID id;
       CallCreateInstance(id, nsnull, id, nsnull);
       CallCreateInstance("", nsnull, id, nsnull);
       CallGetClassObject(id, id, nsnull);
       CallGetClassObject("", id, nsnull);
-
-      nsServiceManager::GetGlobalServiceManager(nsnull);
     }
     NS_NewInterfaceRequestorAggregation(nsnull, nsnull, nsnull);
     NS_NewHashPropertyBag(nsnull);
     nsDependentString depstring;
     depstring.Rebind(nsnull, PRUint32(0));
     nsDependentCString depcstring;
     depcstring.Rebind(nsnull, PRUint32(0));
     // nsStringAPI
@@ -304,9 +300,11 @@ void XXXNeverCalled()
     CondVar theCondVar(theMutex, "dummy3");
     TimeStamp theTimeStamp = TimeStamp::Now();
     TimeDuration theTimeDuration = TimeDuration::FromMilliseconds(0);
 
     NS_WildCardValid((const char *)nsnull);
     NS_WildCardValid((const PRUnichar *)nsnull);
     NS_WildCardMatch((const char *)nsnull, (const char *)nsnull, PR_FALSE);
     NS_WildCardMatch((const PRUnichar *)nsnull, (const PRUnichar *)nsnull, PR_FALSE);
+    XRE_AddStaticComponent(NULL);
+    XRE_AddComponentLocation(NULL);
 }
--- a/xpcom/build/nsXPCOM.h
+++ b/xpcom/build/nsXPCOM.h
@@ -37,17 +37,16 @@
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef nsXPCOM_h__
 #define nsXPCOM_h__
 
 /* Map frozen functions to private symbol names if not using strict API. */
 #ifdef MOZILLA_INTERNAL_API
 # define NS_InitXPCOM2               NS_InitXPCOM2_P
-# define NS_InitXPCOM3               NS_InitXPCOM3_P
 # define NS_ShutdownXPCOM            NS_ShutdownXPCOM_P
 # define NS_GetServiceManager        NS_GetServiceManager_P
 # define NS_GetComponentManager      NS_GetComponentManager_P
 # define NS_GetComponentRegistrar    NS_GetComponentRegistrar_P
 # define NS_GetMemoryManager         NS_GetMemoryManager_P
 # define NS_NewLocalFile             NS_NewLocalFile_P
 # define NS_NewNativeLocalFile       NS_NewNativeLocalFile_P
 # define NS_GetDebug                 NS_GetDebug_P
@@ -92,25 +91,21 @@ DECL_CLASS(nsIServiceManager);
 DECL_CLASS(nsIFile);
 DECL_CLASS(nsILocalFile);
 DECL_CLASS(nsIDirectoryServiceProvider);
 DECL_CLASS(nsIMemory);
 DECL_CLASS(nsIDebug);
 DECL_CLASS(nsITraceRefcnt);
 DECL_STRUCT(nsPurpleBufferEntry);
 
-/**
- * Every XPCOM component implements this function signature, which is the
- * only entrypoint XPCOM uses to the function.
- *
- * @status FROZEN
- */
-typedef nsresult (*nsGetModuleProc)(nsIComponentManager *aCompMgr,
-                                    nsIFile* location,
-                                    nsIModule** return_cobj);
+#ifdef __cplusplus
+namespace mozilla {
+struct Module;
+}
+#endif
 
 /**
  * Initialises XPCOM. You must call one of the NS_InitXPCOM methods
  * before proceeding to use xpcom. The one exception is that you may
  * call NS_NewLocalFile to create a nsIFile.
  * 
  * @status FROZEN
  *
@@ -142,75 +137,16 @@ typedef nsresult (*nsGetModuleProc)(nsIC
  *         initialisation.
  */
 XPCOM_API(nsresult)
 NS_InitXPCOM2(nsIServiceManager* *result, 
               nsIFile* binDirectory,
               nsIDirectoryServiceProvider* appFileLocationProvider);
 
 /**
- * Some clients of XPCOM have statically linked components (not dynamically
- * loaded component DLLs), which can be passed to NS_InitXPCOM3 using this
- * structure.
- *
- * @status FROZEN
- */
-typedef struct nsStaticModuleInfo {
-  const char      *name;
-  nsGetModuleProc  getModule;
-} nsStaticModuleInfo;
-
-/**
- * Initialises XPCOM with static components. You must call one of the
- * NS_InitXPCOM methods before proceeding to use xpcom. The one
- * exception is that you may call NS_NewLocalFile to create a nsIFile.
- * 
- * @status FROZEN
- *
- * @note Use <CODE>NS_NewLocalFile</CODE> or <CODE>NS_NewNativeLocalFile</CODE> 
- *       to create the file object you supply as the bin directory path in this
- *       call. The function may be safely called before the rest of XPCOM or 
- *       embedding has been initialised.
- *
- * @param result           The service manager.  You may pass null.
- *
- * @param binDirectory     The directory containing the component
- *                         registry and runtime libraries;
- *                         or use <CODE>nsnull</CODE> to use the working
- *                         directory.
- *
- * @param appFileLocationProvider The object to be used by Gecko that specifies
- *                         to Gecko where to find profiles, the component
- *                         registry preferences and so on; or use
- *                         <CODE>nsnull</CODE> for the default behaviour.
- *
- * @param staticComponents An array of static components. Passing null causes
- *                         default (builtin) components to be registered, if
- *                         present.
- * @param componentCount   Number of elements in staticComponents
- *
- * @see NS_NewLocalFile
- * @see nsILocalFile
- * @see nsIDirectoryServiceProvider
- * @see XRE_GetStaticComponents
- *
- * @return NS_OK for success;
- *         NS_ERROR_NOT_INITIALIZED if static globals were not initialized,
- *         which can happen if XPCOM is reloaded, but did not completly
- *         shutdown. Other error codes indicate a failure during
- *         initialisation.
- */
-XPCOM_API(nsresult)
-NS_InitXPCOM3(nsIServiceManager* *result, 
-              nsIFile* binDirectory,
-              nsIDirectoryServiceProvider* appFileLocationProvider,
-              nsStaticModuleInfo const *staticComponents,
-              PRUint32 componentCount);
-
-/**
  * Shutdown XPCOM. You must call this method after you are finished
  * using xpcom. 
  *
  * @status FROZEN
  *
  * @param servMgr           The service manager which was returned by NS_InitXPCOM.
  *                          This will release servMgr.  You may pass null.
  *
@@ -243,21 +179,22 @@ NS_GetServiceManager(nsIServiceManager* 
  *
  * @return NS_OK for success;
  *         other error codes indicate a failure during initialisation.
  *
  */
 XPCOM_API(nsresult)
 NS_GetComponentManager(nsIComponentManager* *result);
 
+
 /**
  * Public Method to access to the component registration manager.
- * 
+ *
  * @status FROZEN
- * @param result Interface pointer to the service 
+ * @param result Interface pointer to the service
  *
  * @return NS_OK for success;
  *         other error codes indicate a failure during initialisation.
  *
  */
 XPCOM_API(nsresult)
 NS_GetComponentRegistrar(nsIComponentRegistrar* *result);
 
--- a/xpcom/build/nsXPCOMPrivate.h
+++ b/xpcom/build/nsXPCOMPrivate.h
@@ -57,17 +57,16 @@ class nsIComponentLoader;
 /**
  * During this shutdown notification all module loaders must unload XPCOM
  * modules.
  */
 #define NS_XPCOM_SHUTDOWN_LOADERS_OBSERVER_ID "xpcom-shutdown-loaders"
 
 // PUBLIC
 typedef nsresult   (* InitFunc)(nsIServiceManager* *result, nsIFile* binDirectory, nsIDirectoryServiceProvider* appFileLocationProvider);
-typedef nsresult   (* Init3Func)(nsIServiceManager* *result, nsIFile* binDirectory, nsIDirectoryServiceProvider* appFileLocationProvider, nsStaticModuleInfo const *staticComponents, PRUint32 componentCount);
 typedef nsresult   (* ShutdownFunc)(nsIServiceManager* servMgr);
 typedef nsresult   (* GetServiceManagerFunc)(nsIServiceManager* *result);
 typedef nsresult   (* GetComponentManagerFunc)(nsIComponentManager* *result);
 typedef nsresult   (* GetComponentRegistrarFunc)(nsIComponentRegistrar* *result);
 typedef nsresult   (* GetMemoryManagerFunc)(nsIMemory* *result);
 typedef nsresult   (* NewLocalFileFunc)(const nsAString &path, PRBool followLinks, nsILocalFile* *result);
 typedef nsresult   (* NewNativeLocalFileFunc)(const nsACString &path, PRBool followLinks, nsILocalFile* *result);
 
@@ -170,17 +169,17 @@ typedef struct XPCOMFunctions{
     // Added for Mozilla 1.8
     AllocFunc allocFunc;
     ReallocFunc reallocFunc;
     FreeFunc freeFunc;
     StringContainerInit2Func stringContainerInit2;
     CStringContainerInit2Func cstringContainerInit2;
     StringGetMutableDataFunc stringGetMutableData;
     CStringGetMutableDataFunc cstringGetMutableData;
-    Init3Func init3;
+    void* init3; // obsolete
 
     // Added for Mozilla 1.9
     DebugBreakFunc debugBreakFunc;
     xpcomVoidFunc logInitFunc;
     xpcomVoidFunc logTermFunc;
     LogAddRefFunc logAddRefFunc;
     LogReleaseFunc logReleaseFunc;
     LogCtorFunc logCtorFunc;
--- a/xpcom/build/nsXPComInit.cpp
+++ b/xpcom/build/nsXPComInit.cpp
@@ -70,17 +70,16 @@
 #include "nsINIParserImpl.h"
 #include "nsSupportsPrimitives.h"
 #include "nsConsoleService.h"
 #include "nsExceptionService.h"
 
 #include "nsComponentManager.h"
 #include "nsCategoryManagerUtils.h"
 #include "nsIServiceManager.h"
-#include "nsGenericFactory.h"
 
 #include "nsThreadManager.h"
 #include "nsThreadPool.h"
 
 #include "nsIProxyObjectManager.h"
 #include "nsProxyEventPrivate.h"  // access to the impl of nsProxyObjectManager for the generic factory registration.
 
 #include "xptinfo.h"
@@ -102,18 +101,17 @@
 #endif
 #include "nsDirectoryService.h"
 #include "nsDirectoryServiceDefs.h"
 #include "nsCategoryManager.h"
 #include "nsICategoryManager.h"
 #include "nsMultiplexInputStream.h"
 
 #include "nsStringStream.h"
-extern NS_METHOD nsStringInputStreamConstructor(nsISupports *, REFNSIID, void **);
-NS_DECL_CLASSINFO(nsStringInputStream)
+extern nsresult nsStringInputStreamConstructor(nsISupports *, REFNSIID, void **);
 
 #include "nsFastLoadService.h"
 
 #include "nsAtomService.h"
 #include "nsAtomTable.h"
 #include "nsTraceRefcnt.h"
 #include "nsTimelineService.h"
 
@@ -172,44 +170,18 @@ static BrowserProcessSubThread* sIOThrea
 // here rather than in nsIRegistry.h
 extern nsresult NS_RegistryGetFactory(nsIFactory** aFactory);
 extern nsresult NS_CategoryManagerGetFactory( nsIFactory** );
 
 #ifdef DEBUG
 extern void _FreeAutoLockStatics();
 #endif
 
-static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
-static NS_DEFINE_CID(kMemoryCID, NS_MEMORY_CID);
-static NS_DEFINE_CID(kINIParserFactoryCID, NS_INIPARSERFACTORY_CID);
-static NS_DEFINE_CID(kSimpleUnicharStreamFactoryCID, NS_SIMPLE_UNICHAR_STREAM_FACTORY_CID);
-
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsProcess)
 
-#define NS_ENVIRONMENT_CLASSNAME "Environment Service"
-
-// ds/nsISupportsPrimitives
-#define NS_SUPPORTS_ID_CLASSNAME "Supports ID"
-#define NS_SUPPORTS_CSTRING_CLASSNAME "Supports String"
-#define NS_SUPPORTS_STRING_CLASSNAME "Supports WString"
-#define NS_SUPPORTS_PRBOOL_CLASSNAME "Supports PRBool"
-#define NS_SUPPORTS_PRUINT8_CLASSNAME "Supports PRUint8"
-#define NS_SUPPORTS_PRUINT16_CLASSNAME "Supports PRUint16"
-#define NS_SUPPORTS_PRUINT32_CLASSNAME "Supports PRUint32"
-#define NS_SUPPORTS_PRUINT64_CLASSNAME "Supports PRUint64"
-#define NS_SUPPORTS_PRTIME_CLASSNAME "Supports PRTime"
-#define NS_SUPPORTS_CHAR_CLASSNAME "Supports Char"
-#define NS_SUPPORTS_PRINT16_CLASSNAME "Supports PRInt16"
-#define NS_SUPPORTS_PRINT32_CLASSNAME "Supports PRInt32"
-#define NS_SUPPORTS_PRINT64_CLASSNAME "Supports PRInt64"
-#define NS_SUPPORTS_FLOAT_CLASSNAME "Supports float"
-#define NS_SUPPORTS_DOUBLE_CLASSNAME "Supports double"
-#define NS_SUPPORTS_VOID_CLASSNAME "Supports void"
-#define NS_SUPPORTS_INTERFACE_POINTER_CLASSNAME "Supports interface pointer"
-
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsIDImpl)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsStringImpl)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsCStringImpl)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRBoolImpl)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRUint8Impl)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRUint16Impl)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRUint32Impl)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRUint64Impl)
@@ -219,17 +191,16 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupport
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRInt32Impl)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRInt64Impl)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsFloatImpl)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsDoubleImpl)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsVoidImpl)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsInterfacePointerImpl)
 
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsConsoleService, Init)
-NS_DECL_CLASSINFO(nsConsoleService)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsAtomService)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsExceptionService)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsTimerImpl)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsBinaryOutputStream)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsBinaryInputStream)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsStorageStream)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsVersionComparatorImpl)
 
@@ -252,193 +223,93 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsMacUtil
 #endif
 
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsSystemInfo, Init)
 
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsMemoryReporterManager, Init)
 
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsIOUtil)
 
-static NS_METHOD
+static nsresult
 nsThreadManagerGetSingleton(nsISupports* outer,
                             const nsIID& aIID,
                             void* *aInstancePtr)
 {
     NS_ASSERTION(aInstancePtr, "null outptr");
     NS_ENSURE_TRUE(!outer, NS_ERROR_NO_AGGREGATION);
 
     return nsThreadManager::get()->QueryInterface(aIID, aInstancePtr);
 }
-NS_DECL_CLASSINFO(nsThreadManager)
 
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsThreadPool)
-NS_DECL_CLASSINFO(nsThreadPool)
 
-static NS_METHOD
+static nsresult
 nsXPTIInterfaceInfoManagerGetSingleton(nsISupports* outer,
                                        const nsIID& aIID,
                                        void* *aInstancePtr)
 {
     NS_ASSERTION(aInstancePtr, "null outptr");
     NS_ENSURE_TRUE(!outer, NS_ERROR_NO_AGGREGATION);
 
     nsCOMPtr<nsIInterfaceInfoManager> iim
         (xptiInterfaceInfoManager::GetSingleton());
     if (!iim)
         return NS_ERROR_FAILURE;
 
     return iim->QueryInterface(aIID, aInstancePtr);
 }
 
-
-static nsresult
-RegisterGenericFactory(nsIComponentRegistrar* registrar,
-                       const nsModuleComponentInfo *info)
-{
-    nsresult rv;
-    nsIGenericFactory* fact;
-    rv = NS_NewGenericFactory(&fact, info);
-    if (NS_FAILED(rv)) return rv;
-
-    rv = registrar->RegisterFactory(info->mCID, 
-                                    info->mDescription,
-                                    info->mContractID, 
-                                    fact);
-    NS_RELEASE(fact);
-    return rv;
-}
-
-
 nsComponentManagerImpl* nsComponentManagerImpl::gComponentManager = NULL;
 PRBool gXPCOMShuttingDown = PR_FALSE;
 
-// For each class that wishes to support nsIClassInfo, add a line like this
-// NS_DECL_CLASSINFO(nsMyClass)
-
-#define COMPONENT(NAME, Ctor)                                                  \
- { NS_##NAME##_CLASSNAME, NS_##NAME##_CID, NS_##NAME##_CONTRACTID, Ctor }
-
-#define COMPONENT_CI(NAME, Ctor, Class)                                        \
- { NS_##NAME##_CLASSNAME, NS_##NAME##_CID, NS_##NAME##_CONTRACTID, Ctor,       \
-   NULL, NULL, NULL, NS_CI_INTERFACE_GETTER_NAME(Class), NULL,                 \
-   &NS_CLASSINFO_NAME(Class) }
-
-#define COMPONENT_CI_FLAGS(NAME, Ctor, Class, Flags)                           \
- { NS_##NAME##_CLASSNAME, NS_##NAME##_CID, NS_##NAME##_CONTRACTID, Ctor,       \
-   NULL, NULL, NULL, NS_CI_INTERFACE_GETTER_NAME(Class), NULL,                 \
-   &NS_CLASSINFO_NAME(Class), Flags }
-
-static const nsModuleComponentInfo components[] = {
-    COMPONENT(MEMORY, nsMemoryImpl::Create),
-    COMPONENT(DEBUG,  nsDebugImpl::Create),
-#define NS_ERRORSERVICE_CLASSNAME NS_ERRORSERVICE_NAME
-    COMPONENT(ERRORSERVICE, nsErrorService::Create),
-
-    COMPONENT(BYTEBUFFER, ByteBufferImpl::Create),
-    COMPONENT(SCRIPTABLEINPUTSTREAM, nsScriptableInputStream::Create),
-    COMPONENT(BINARYINPUTSTREAM, nsBinaryInputStreamConstructor),
-    COMPONENT(BINARYOUTPUTSTREAM, nsBinaryOutputStreamConstructor),
-    COMPONENT(STORAGESTREAM, nsStorageStreamConstructor),
-    COMPONENT(VERSIONCOMPARATOR, nsVersionComparatorImplConstructor),
-    COMPONENT(PIPE, nsPipeConstructor),
-
-#define NS_PROPERTIES_CLASSNAME  "Properties"
-    COMPONENT(PROPERTIES, nsPropertiesConstructor),
+static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
+static NS_DEFINE_CID(kINIParserFactoryCID, NS_INIPARSERFACTORY_CID);
+static NS_DEFINE_CID(kSimpleUnicharStreamFactoryCID, NS_SIMPLE_UNICHAR_STREAM_FACTORY_CID);
 
 #define NS_PERSISTENTPROPERTIES_CID NS_IPERSISTENTPROPERTIES_CID /* sigh */
-    COMPONENT(PERSISTENTPROPERTIES, nsPersistentProperties::Create),
-
-    COMPONENT(SUPPORTSARRAY, nsSupportsArray::Create),
-    COMPONENT(ARRAY, nsArrayConstructor),
-    COMPONENT_CI_FLAGS(CONSOLESERVICE, nsConsoleServiceConstructor,
-                       nsConsoleService,
-                       nsIClassInfo::THREADSAFE | nsIClassInfo::SINGLETON),
-    COMPONENT(EXCEPTIONSERVICE, nsExceptionServiceConstructor),
-    COMPONENT(ATOMSERVICE, nsAtomServiceConstructor),
-#ifdef MOZ_TIMELINE
-    COMPONENT(TIMELINESERVICE, nsTimelineServiceConstructor),
-#endif
-    COMPONENT(OBSERVERSERVICE, nsObserverService::Create),
-    COMPONENT(GENERICFACTORY, nsGenericFactory::Create),
-
 #define NS_XPCOMPROXY_CID NS_PROXYEVENT_MANAGER_CID
-    COMPONENT(XPCOMPROXY, nsProxyObjectManager::Create),
-
-    COMPONENT(TIMER, nsTimerImplConstructor),
-
-#define COMPONENT_SUPPORTS(TYPE, Type)                                         \
-  COMPONENT(SUPPORTS_##TYPE, nsSupports##Type##ImplConstructor)
-
-    COMPONENT_SUPPORTS(ID, ID),
-    COMPONENT_SUPPORTS(STRING, String),
-    COMPONENT_SUPPORTS(CSTRING, CString),
-    COMPONENT_SUPPORTS(PRBOOL, PRBool),
-    COMPONENT_SUPPORTS(PRUINT8, PRUint8),
-    COMPONENT_SUPPORTS(PRUINT16, PRUint16),
-    COMPONENT_SUPPORTS(PRUINT32, PRUint32),
-    COMPONENT_SUPPORTS(PRUINT64, PRUint64),
-    COMPONENT_SUPPORTS(PRTIME, PRTime),
-    COMPONENT_SUPPORTS(CHAR, Char),
-    COMPONENT_SUPPORTS(PRINT16, PRInt16),
-    COMPONENT_SUPPORTS(PRINT32, PRInt32),
-    COMPONENT_SUPPORTS(PRINT64, PRInt64),
-    COMPONENT_SUPPORTS(FLOAT, Float),
-    COMPONENT_SUPPORTS(DOUBLE, Double),
-    COMPONENT_SUPPORTS(VOID, Void),
-    COMPONENT_SUPPORTS(INTERFACE_POINTER, InterfacePointer),
 
-#undef COMPONENT_SUPPORTS
-#define NS_LOCAL_FILE_CLASSNAME "Local File Specification"
-    COMPONENT(LOCAL_FILE, nsLocalFile::nsLocalFileConstructor),
-#define NS_DIRECTORY_SERVICE_CLASSNAME  "nsIFile Directory Service"
-    COMPONENT(DIRECTORY_SERVICE, nsDirectoryService::Create),
-    COMPONENT(PROCESS, nsProcessConstructor),
-    COMPONENT(ENVIRONMENT, nsEnvironment::Create),
-
-    COMPONENT_CI_FLAGS(THREADMANAGER, nsThreadManagerGetSingleton,
-                       nsThreadManager,
-                       nsIClassInfo::THREADSAFE | nsIClassInfo::SINGLETON),
-    COMPONENT_CI_FLAGS(THREADPOOL, nsThreadPoolConstructor,
-                       nsThreadPool, nsIClassInfo::THREADSAFE),
-
-    COMPONENT_CI_FLAGS(STRINGINPUTSTREAM, nsStringInputStreamConstructor,
-                       nsStringInputStream, nsIClassInfo::THREADSAFE),
-    COMPONENT(MULTIPLEXINPUTSTREAM, nsMultiplexInputStreamConstructor),
-
-#ifndef MOZ_NO_FAST_LOAD
-    COMPONENT(FASTLOADSERVICE, nsFastLoadService::Create),
-#endif
+static already_AddRefed<nsIFactory>
+CreateINIParserFactory(const mozilla::Module& module,
+                       const mozilla::Module::CIDEntry& entry)
+{
+    nsIFactory* f = new nsINIParserFactory();
+    f->AddRef();
+    return f;
+}
 
-    COMPONENT(VARIANT, nsVariantConstructor),
-    COMPONENT(INTERFACEINFOMANAGER_SERVICE, nsXPTIInterfaceInfoManagerGetSingleton),
-
-    COMPONENT(RECYCLINGALLOCATOR, nsRecyclingAllocatorImplConstructor),
-
-#define NS_HASH_PROPERTY_BAG_CLASSNAME "Hashtable Property Bag"
-    COMPONENT(HASH_PROPERTY_BAG, nsHashPropertyBagConstructor),
-
-    COMPONENT(UUID_GENERATOR, nsUUIDGeneratorConstructor),
+static already_AddRefed<nsIFactory>
+CreateUnicharStreamFactory(const mozilla::Module& module,
+                           const mozilla::Module::CIDEntry& entry)
+{
+    return nsSimpleUnicharStreamFactory::GetInstance();
+}
 
-#if defined(XP_WIN)
-    COMPONENT(WINDOWSREGKEY, nsWindowsRegKeyConstructor),
-#endif
-
-#ifdef XP_MACOSX
-    COMPONENT(MACUTILSIMPL, nsMacUtilsImplConstructor),
-#endif
-
-    COMPONENT(SYSTEMINFO, nsSystemInfoConstructor),
-#define NS_MEMORY_REPORTER_MANAGER_CLASSNAME "Memory Reporter Manager"
-    COMPONENT(MEMORY_REPORTER_MANAGER, nsMemoryReporterManagerConstructor),
-    COMPONENT(IOUTIL, nsIOUtilConstructor),
-};
-
+#define COMPONENT(NAME, Ctor) static NS_DEFINE_CID(kNS_##NAME##_CID, NS_##NAME##_CID);
+#include "XPCOMModule.inc"
 #undef COMPONENT
 
-const int components_length = sizeof(components) / sizeof(components[0]);
+#define COMPONENT(NAME, Ctor) { &kNS_##NAME##_CID, false, NULL, Ctor },
+const mozilla::Module::CIDEntry kXPCOMCIDEntries[] = {
+    { &kComponentManagerCID, true, NULL, nsComponentManagerImpl::Create },
+    { &kINIParserFactoryCID, false, CreateINIParserFactory },
+    { &kSimpleUnicharStreamFactoryCID, false, CreateUnicharStreamFactory },
+#include "XPCOMModule.inc"
+    { NULL }
+};
+#undef COMPONENT
+
+#define COMPONENT(NAME, Ctor) { NS_##NAME##_CONTRACTID, &kNS_##NAME##_CID },
+const mozilla::Module::ContractIDEntry kXPCOMContracts[] = {
+#include "XPCOMModule.inc"
+    { NULL }
+};
+#undef COMPONENT
+
+const mozilla::Module kXPCOMModule = { mozilla::Module::kVersion, kXPCOMCIDEntries, kXPCOMContracts };
 
 // gDebug will be freed during shutdown.
 static nsIDebug* gDebug = nsnull;
 
 EXPORT_XPCOM_API(nsresult)
 NS_GetDebug(nsIDebug** result)
 {
     return nsDebugImpl::Create(nsnull, 
@@ -453,45 +324,28 @@ NS_GetTraceRefcnt(nsITraceRefcnt** resul
                                      NS_GET_IID(nsITraceRefcnt), 
                                      (void**) result);
 }
 
 EXPORT_XPCOM_API(nsresult)
 NS_InitXPCOM(nsIServiceManager* *result,
                              nsIFile* binDirectory)
 {
-    return NS_InitXPCOM3(result, binDirectory, nsnull, nsnull, 0);
+    return NS_InitXPCOM2(result, binDirectory, nsnull);
 }
 
 EXPORT_XPCOM_API(nsresult)
 NS_InitXPCOM2(nsIServiceManager* *result,
-                              nsIFile* binDirectory,
-                              nsIDirectoryServiceProvider* appFileLocationProvider)
-{
-    return NS_InitXPCOM3(result, binDirectory, appFileLocationProvider, nsnull, 0);
-}
-
-EXPORT_XPCOM_API(nsresult)
-NS_InitXPCOM3(nsIServiceManager* *result,
-                              nsIFile* binDirectory,
-                              nsIDirectoryServiceProvider* appFileLocationProvider,
-                              nsStaticModuleInfo const *staticComponents,
-                              PRUint32 componentCount)
+              nsIFile* binDirectory,
+              nsIDirectoryServiceProvider* appFileLocationProvider)
 {
     NS_TIME_FUNCTION;
 
     nsresult rv = NS_OK;
 
-#ifdef MOZ_ENABLE_LIBXUL
-    if (!staticComponents) {
-        staticComponents = kPStaticModules;
-        componentCount = kStaticModuleCount;
-    }
-#endif
-
      // We are not shutting down
     gXPCOMShuttingDown = PR_FALSE;
 
     NS_TIME_FUNCTION_MARK("Next: log init");
 
     NS_LogInit();
 
 #ifdef MOZ_IPC
@@ -619,101 +473,46 @@ NS_InitXPCOM3(nsIServiceManager* *result
     NS_TIME_FUNCTION_MARK("Next: component manager init");
 
     // Create the Component/Service Manager
     nsComponentManagerImpl *compMgr = new nsComponentManagerImpl();
     if (compMgr == NULL)
         return NS_ERROR_OUT_OF_MEMORY;
     NS_ADDREF(compMgr);
     
-    rv = compMgr->Init(staticComponents, componentCount);
+    rv = compMgr->Init();
     if (NS_FAILED(rv))
     {
         NS_RELEASE(compMgr);
         return rv;
     }
 
     nsComponentManagerImpl::gComponentManager = compMgr;
 
     if (result) {
         nsIServiceManager *serviceManager =
             static_cast<nsIServiceManager*>(compMgr);
 
         NS_ADDREF(*result = serviceManager);
     }
 
-    nsCOMPtr<nsIMemory> memory;
-    NS_GetMemoryManager(getter_AddRefs(memory));
-    rv = compMgr->RegisterService(kMemoryCID, memory);
-    if (NS_FAILED(rv)) return rv;
-
-    rv = compMgr->RegisterService(kComponentManagerCID, static_cast<nsIComponentManager*>(compMgr));
-    if (NS_FAILED(rv)) return rv;
-
     NS_TIME_FUNCTION_MARK("Next: cycle collector startup");
 
     rv = nsCycleCollector_startup();
     if (NS_FAILED(rv)) return rv;
 
-    // 2. Register the global services with the component manager so that
-    //    clients can create new objects.
-
-    // Category Manager
-    {
-      NS_TIME_FUNCTION_MARK("Next: category manager factory init");
-
-      nsCOMPtr<nsIFactory> categoryManagerFactory;
-      if ( NS_FAILED(rv = NS_CategoryManagerGetFactory(getter_AddRefs(categoryManagerFactory))) )
-        return rv;
-
-      NS_DEFINE_CID(kCategoryManagerCID, NS_CATEGORYMANAGER_CID);
-
-      rv = compMgr->RegisterFactory(kCategoryManagerCID,
-                                    NS_CATEGORYMANAGER_CLASSNAME,
-                                    NS_CATEGORYMANAGER_CONTRACTID,
-                                    categoryManagerFactory,
-                                    PR_TRUE);
-      if ( NS_FAILED(rv) ) return rv;
-    }
-
-    nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(
-        static_cast<nsIComponentManager*>(compMgr), &rv);
-    if (registrar) {
-        for (int i = 0; i < components_length; i++)
-            RegisterGenericFactory(registrar, &components[i]);
-
-        nsCOMPtr<nsIFactory> iniParserFactory(new nsINIParserFactory());
-        if (iniParserFactory)
-            registrar->RegisterFactory(kINIParserFactoryCID, 
-                                       "nsINIParserFactory",
-                                       NS_INIPARSERFACTORY_CONTRACTID, 
-                                       iniParserFactory);
-
-        registrar->
-          RegisterFactory(kSimpleUnicharStreamFactoryCID,
-                          "nsSimpleUnicharStreamFactory",
-                          NS_SIMPLE_UNICHAR_STREAM_FACTORY_CONTRACTID,
-                          nsSimpleUnicharStreamFactory::GetInstance());
-    }
-
     NS_TIME_FUNCTION_MARK("Next: interface info manager init");
 
     // The iimanager constructor searches and registers XPT files.
     nsIInterfaceInfoManager* iim =
         xptiInterfaceInfoManager::GetSingleton();
 
-    NS_TIME_FUNCTION_MARK("Next: try to load compreg.dat");
-
+    NS_TIME_FUNCTION_MARK("Next: try to register core/application components");
     // "Re-register the world" if compreg.dat doesn't exist
-    rv = nsComponentManagerImpl::gComponentManager->ReadPersistentRegistry();
-    if (NS_FAILED(rv)) {
-        NS_TIME_FUNCTION_MARK("Next: try to register all components (compreg.dat not found)");
-
-        nsComponentManagerImpl::gComponentManager->AutoRegister(nsnull);
-    }
+    // XXXTODO
 
     NS_TIME_FUNCTION_MARK("Next: register category providers");
 
     // After autoreg, but before we actually instantiate any components,
     // add any services listed in the "xpcom-directory-providers" category
     // to the directory service.
     nsDirectoryService::gService->RegisterCategoryProviders();
 
@@ -894,16 +693,17 @@ ShutdownXPCOM(nsIServiceManager* servMgr
     // Finally, release the component manager last because it unloads the
     // libraries:
     if (nsComponentManagerImpl::gComponentManager) {
       nsrefcnt cnt;
       NS_RELEASE2(nsComponentManagerImpl::gComponentManager, cnt);
       NS_ASSERTION(cnt == 0, "Component Manager being held past XPCOM shutdown.");
     }
     nsComponentManagerImpl::gComponentManager = nsnull;
+    nsCategoryManager::Destroy();
 
 #ifdef DEBUG
     // FIXME BUG 456272: this should disappear
     _FreeAutoLockStatics();
 #endif
 
     ShutdownSpecialSystemDirectory();
 
--- a/xpcom/build/nsXULAppAPI.h
+++ b/xpcom/build/nsXULAppAPI.h
@@ -300,21 +300,20 @@ XRE_API(nsresult,
  * @param argv0   The value passed as argv[0] of main(). This value is only
  *                used on *nix, and only when other methods of determining
  *                the binary path have failed.
  */
 XRE_API(nsresult,
         XRE_GetBinaryPath, (const char *argv0, nsILocalFile* *aResult))
 
 /**
- * Get the static components built in to libxul.
+ * Get the static module built in to libxul.
  */
-XRE_API(void,
-        XRE_GetStaticComponents, (nsStaticModuleInfo const **aStaticComponents,
-                                  PRUint32 *aComponentCount))
+XRE_API(const mozilla::Module*,
+        XRE_GetStaticModule, ())
 
 /**
  * Lock a profile directory using platform-specific semantics.
  *
  * @param aDirectory  The profile directory to lock.
  * @param aLockObject An opaque lock object. The directory will remain locked
  *                    as long as the XPCOM reference is held.
  */
@@ -329,36 +328,47 @@ XRE_API(nsresult,
  *                           was found.
  * @param aAppDirectory      The directory in which the application components
  *                           and resources can be found. This will map to
  *                           the NS_OS_CURRENT_PROCESS_DIR directory service
  *                           key.
  * @param aAppDirProvider    A directory provider for the application. This
  *                           provider will be aggregated by a libxul provider
  *                           which will provide the base required GRE keys.
- * @param aStaticComponents  Static components provided by the embedding
- *                           application. This should *not* include the
- *                           components from XRE_GetStaticComponents. May be
- *                           null if there are no static components.
- * @param aStaticComponentCount the number of static components in
- *                           aStaticComponents
  *
  * @note This function must be called from the "main" thread.
  *
  * @note At the present time, this function may only be called once in
  * a given process. Use XRE_TermEmbedding to clean up and free
  * resources allocated by XRE_InitEmbedding.
  */
 
 XRE_API(nsresult,
-        XRE_InitEmbedding, (nsILocalFile *aLibXULDirectory,
-                            nsILocalFile *aAppDirectory,
-                            nsIDirectoryServiceProvider *aAppDirProvider,
-                            nsStaticModuleInfo const *aStaticComponents,
-                            PRUint32 aStaticComponentCount))
+        XRE_InitEmbedding2, (nsILocalFile *aLibXULDirectory,
+                             nsILocalFile *aAppDirectory,
+                             nsIDirectoryServiceProvider *aAppDirProvider))
+
+/**
+ * Register static XPCOM component information.
+ * This method may be called at any time before or after XRE_main or
+ * XRE_InitEmbedding.
+ */
+XRE_API(nsresult,
+        XRE_AddStaticComponent, (const mozilla::Module* aComponent))
+/**
+ * Register XPCOM components found in an array of files/directories.
+ * This method may be called at any time before or after XRE_main or
+ * XRE_InitEmbedding.
+ *
+ * @param aFiles An array of files or directories.
+ * @param aFileCount the number of items in the aFiles array.
+ * @note appdir/components is registered automatically.
+ */
+XRE_API(nsresult,
+        XRE_AddComponentLocation, (nsILocalFile* aLocation))
 
 /**
  * Fire notifications to inform the toolkit about a new profile. This
  * method should be called after XRE_InitEmbedding if the embedder
  * wishes to run with a profile. Normally the embedder should call
  * XRE_LockProfileDirectory to lock the directory before calling this
  * method.
  *
new file mode 100644
--- /dev/null
+++ b/xpcom/components/GenericFactory.cpp
@@ -0,0 +1,58 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla 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/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Mozilla Firefox.
+ *
+ * The Initial Developer of the Original Code is
+ * the Mozilla Foundation <http://www.mozilla.org>.
+ * Portions created by the Initial Developer are Copyright (C) 2010
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * 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 MPL, 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 MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#include "mozilla/GenericFactory.h"
+
+namespace mozilla {
+
+NS_IMPL_THREADSAFE_ISUPPORTS1(GenericFactory, nsIFactory)
+
+NS_IMETHODIMP
+GenericFactory::CreateInstance(nsISupports* aOuter, REFNSIID aIID,
+			       void** aResult)
+{
+  return mCtor(aOuter, aIID, aResult);
+}
+
+NS_IMETHODIMP
+GenericFactory::LockFactory(PRBool aLock)
+{
+  NS_ERROR("Vestigial method, never called!");
+  return NS_ERROR_FAILURE;
+}
+
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/xpcom/components/GenericFactory.h
@@ -0,0 +1,69 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla 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/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Mozilla Firefox.
+ *
+ * The Initial Developer of the Original Code is
+ * the Mozilla Foundation <http://www.mozilla.org>.
+ * Portions created by the Initial Developer are Copyright (C) 2010
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * 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 MPL, 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 MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#ifndef mozilla_GenericFactory_h
+#define mozilla_GenericFactory_h
+
+#include "mozilla/Module.h"
+
+namespace mozilla {
+
+/**
+ * A generic factory which uses a constructor function to create instances.
+ * This class is intended solely for internal use by the component manager.
+ */
+class GenericFactory : public nsIFactory
+{
+public:
+  typedef Module::ConstructorProc ConstructorProc;
+
+  NS_DECL_ISUPPORTS
+  NS_DECL_NSIFACTORY
+
+  GenericFactory(ConstructorProc ctor)
+    : mCtor(ctor)
+  {
+    NS_ASSERTION(mCtor, "GenericFactory with no constructor");
+  }
+
+private:
+  ConstructorProc mCtor;
+};
+
+} // namespace mozilla
+
+#endif // mozilla_GenericFactory_h
--- a/xpcom/components/Makefile.in
+++ b/xpcom/components/Makefile.in
@@ -43,58 +43,54 @@ VPATH		= @srcdir@
 include $(DEPTH)/config/autoconf.mk
 
 MODULE		= xpcom
 XPIDL_MODULE	= xpcom_components
 LIBRARY_NAME	= xpcomcomponents_s
 GRE_MODULE	= 1
 MOZILLA_INTERNAL_API = 1
 
+EXPORTS_NAMESPACES = mozilla
+
+EXPORTS	= \
+  nsCategoryManagerUtils.h \
+  $(NULL)
+
+EXPORTS_mozilla = \
+  GenericFactory.h \
+  Module.h \
+  ModuleLoader.h \
+  ModuleUtils.h \
+  $(NULL)
 
 CPPSRCS		= \
 		nsCategoryManager.cpp \
 		nsComponentManager.cpp \
 		nsNativeComponentLoader.cpp \
-		nsStaticComponentLoader.cpp \
-		nsServiceManagerObsolete.cpp \
-		$(NULL)
-
-EXPORTS		= \
-		nsCategoryManagerUtils.h \
-		nsIServiceManagerObsolete.h \
-		nsModule.h \
-		nsObsoleteModuleLoading.h \
-		$(NULL)
-
-XPIDLSRCS	= \
-		nsIModuleLoader.idl \
-		nsIComponentManagerObsolete.idl \
+		GenericFactory.cpp \
 		$(NULL)
 
 SDK_XPIDLSRCS	= \
 		nsIClassInfo.idl	      \
 		nsIComponentRegistrar.idl     \
-		nsIFactory.idl		      \
-		nsIModule.idl		      \
+		nsIFactory.idl                \
 		nsIServiceManager.idl	      \
 		nsIComponentManager.idl       \
 		nsICategoryManager.idl        \
 		$(NULL)
 
-EXPORTS		:= $(addprefix $(srcdir)/, $(EXPORTS))
-
 LOCAL_INCLUDES	= \
 	-I$(srcdir)/../reflect/xptinfo/src \
 	-I$(srcdir)/../base \
 	-I$(srcdir)/../thread \
 	-I$(srcdir)/../ds \
 	-I$(srcdir)/../build \
 	-I.. \
 	$(NULL)
 
 # we don't want the shared lib, but we want to force the creation of a static lib.
 FORCE_STATIC_LIB = 1
 
 # Force use of PIC
 FORCE_USE_PIC	= 1
 include $(topsrcdir)/config/rules.mk
 
-DEFINES	+= -D_IMPL_NS_COM
+DEFINES	+= -D_IMPL_NS_COM -DNAKED_DLL_SUFFIX=\"$(patsubst .%,%,$(DLL_SUFFIX))\"
new file mode 100644
--- /dev/null
+++ b/xpcom/components/Module.h
@@ -0,0 +1,147 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla 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/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Mozilla Firefox.
+ *
+ * The Initial Developer of the Original Code is
+ * the Mozilla Foundation <http://www.mozilla.org>.
+ * Portions created by the Initial Developer are Copyright (C) 2010
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * 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 MPL, 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 MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#ifndef mozilla_Module_h
+#define mozilla_Module_h
+
+#include "nscore.h"
+#include "nsID.h"
+#include "nsIFactory.h"
+#include "nsCOMPtr.h" // for already_AddRefed
+
+namespace mozilla {
+
+/**
+ * A module implements one or more XPCOM components. This structure is used
+ * for both binary and script modules, but the registration members
+ * (cids/contractids/categoryentries) are unused for modules which are loaded
+ * via a module loader.
+ */
+struct Module
+{
+  static const int kVersion = 1;
+
+  struct CIDEntry;
+
+  typedef already_AddRefed<nsIFactory> (*GetFactoryProc)
+    (const Module& module, const CIDEntry& entry);
+
+  typedef nsresult (*ConstructorProc)(nsISupports* aOuter,
+                                      const nsIID& aIID,
+                                      void** aResult);
+
+  typedef nsresult (*LoadedFunc)();
+  typedef void (*UnloadedFunc)();
+
+  /**
+   * The constructor callback is an implementation detail of the default binary
+   * loader and may be null.
+   */
+  struct CIDEntry
+  {
+    const nsCID* cid;
+    bool service;
+    GetFactoryProc getfactory;
+    ConstructorProc constructor;
+  };
+
+  struct ContractIDEntry
+  {
+    const char* contractid;
+    nsID const * cid;
+  };
+
+  struct CategoryEntry
+  {
+    const char* category;
+    const char* entry;
+    const char* value;
+  };
+
+  /**
+   * Binary compatibility check, should be kModuleVersion.
+   */
+  unsigned int mVersion;
+
+  /**
+   * An array of CIDs (class IDs) implemented by this module. The final entry
+   * should be { NULL, false }
+   */
+  const CIDEntry* mCIDs;
+
+  /**
+   * An array of mappings from contractid to CID. The final entry should
+   * be { NULL, NULL }
+   */
+  const ContractIDEntry* mContractIDs;
+
+  /**
+   * An array of category manager entries. The final entry should be
+   * { NULL, NULL, NULL }
+   */
+  const CategoryEntry* mCategoryEntries;
+
+  /**
+   * When the component manager tries to get the factory for a CID, it first
+   * checks for this module-level getfactory callback. If this function is
+   * not implemented, it checks the CIDEntry getfactory callback. If that is
+   * also NULL, a generic factory is generated using the CIDEntry constructor
+   * callback which must be non-NULL.
+   */
+  GetFactoryProc getfactory;
+
+  /**
+   * Optional Function which are called when this module is loaded and
+   * at shutdown. These are not C++ constructor/destructors to avoid
+   * calling them too early in startup or too late in shutdown.
+   */
+  LoadedFunc loaded;
+  UnloadedFunc unloaded;
+};
+
+} // namespace
+
+#if defined(XPCOM_TRANSLATE_NSGM_ENTRY_POINT)
+#  define NSMODULE_NAME(_name) _name##_NSModule
+#  define NSMODULE_DECL(_name) extern mozilla::Module const *const NSMODULE_NAME(_name)
+#  define NSMODULE_DEFN(_name) NSMODULE_DECL(_name)
+#else
+#  define NSMODULE_NAME(_name) NSModule
+#  define NSMODULE_DEFN(_name) extern "C" NS_EXPORT mozilla::Module const *const NSModule
+#endif
+
+#endif // mozilla_Module_h
new file mode 100644
--- /dev/null
+++ b/xpcom/components/ModuleLoader.h
@@ -0,0 +1,75 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla 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/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Mozilla XPCOM.
+ *
+ * The Initial Developer of the Original Code is
+ * Benjamin Smedberg <benjamin@smedbergs.us>
+ *
+ * Portions created by the Initial Developer are Copyright (C) 2005
+ * the Mozilla Foundation <http://www.mozilla.org/>. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * 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 MPL, 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 MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#ifndef mozilla_ModuleLoader_h
+#define mozilla_ModuleLoader_h
+
+#include "nsISupports.h"
+#include "mozilla/Module.h"
+
+#define MOZILLA_MODULELOADER_PSEUDO_IID \
+{ 0xD951A8CE, 0x6E9F, 0x464F, \
+  { 0x8A, 0xC8, 0x14, 0x61, 0xC0, 0xD3, 0x63, 0xC8 } }
+
+namespace mozilla {
+
+/**
+ * Module loaders are responsible for loading a component file. The static
+ * component loader is special and does not use this abstract interface.
+ *
+ * @note Implementations of this interface should be threadsafe,
+ *       methods may be called from any thread.
+ */
+class ModuleLoader : public nsISupports
+{
+public:
+  NS_DECLARE_STATIC_IID_ACCESSOR(MOZILLA_MODULELOADER_PSEUDO_IID)
+
+  /**
+   * Return the module for a specified file. The loader should cache
+   * the module and return the same module in future calls. The Module
+   * should either be statically or permanently allocated, it will not
+   * be freed.
+   */
+  virtual const Module* LoadModule(nsILocalFile* aFile) = 0;
+};
+NS_DEFINE_STATIC_IID_ACCESSOR(ModuleLoader, MOZILLA_MODULELOADER_PSEUDO_IID)
+
+} // namespace mozilla
+
+#endif // mozilla_ModuleLoader_h
new file mode 100644
--- /dev/null
+++ b/xpcom/components/ModuleUtils.h
@@ -0,0 +1,130 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla 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/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ * Netscape Communications Corporation.
+ * Portions created by the Initial Developer are Copyright (C) 1998
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Benjamin Smedberg <benjamin@smedbergs.us>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either of 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 MPL, 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 MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#ifndef mozilla_GenericModule_h
+#define mozilla_GenericModule_h
+
+#include "mozilla/Module.h"
+
+#define NS_GENERIC_FACTORY_CONSTRUCTOR(_InstanceClass)                        \
+static nsresult                                                               \
+_InstanceClass##Constructor(nsISupports *aOuter, REFNSIID aIID,               \
+                            void **aResult)                                   \
+{                                                                             \
+    nsresult rv;                                                              \
+                                                                              \
+    _InstanceClass * inst;                                                    \
+                                                                              \
+    *aResult = NULL;                                                          \
+    if (NULL != aOuter) {                                                     \
+        rv = NS_ERROR_NO_AGGREGATION;                                         \
+        return rv;                                                            \
+    }                                                                         \
+                                                                              \
+    NS_NEWXPCOM(inst, _InstanceClass);                                        \
+    if (NULL == inst) {                                                       \
+        rv = NS_ERROR_OUT_OF_MEMORY;                                          \
+        return rv;                                                            \
+    }                                                                         \
+    NS_ADDREF(inst);                                                          \
+    rv = inst->QueryInterface(aIID, aResult);                                 \
+    NS_RELEASE(inst);                                                         \
+                                                                              \
+    return rv;                                                                \
+}
+
+#define NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(_InstanceClass, _InitMethod)      \
+static nsresult                                                               \
+_InstanceClass##Constructor(nsISupports *aOuter, REFNSIID aIID,               \
+                            void **aResult)                                   \
+{                                                                             \
+    nsresult rv;                                                              \
+                                                                              \
+    _InstanceClass * inst;                                                    \
+                                                                              \
+    *aResult = NULL;                                                          \
+    if (NULL != aOuter) {                                                     \
+        rv = NS_ERROR_NO_AGGREGATION;                                         \
+        return rv;                                                            \
+    }                                                                         \
+                                                                              \
+    NS_NEWXPCOM(inst, _InstanceClass);                                        \
+    if (NULL == inst) {                                                       \
+        rv = NS_ERROR_OUT_OF_MEMORY;                                          \
+        return rv;                                                            \
+    }                                                                         \
+    NS_ADDREF(inst);                                                          \
+    rv = inst->_InitMethod();                                                 \
+    if(NS_SUCCEEDED(rv)) {                                                    \
+        rv = inst->QueryInterface(aIID, aResult);                             \
+    }                                                                         \
+    NS_RELEASE(inst);                                                         \
+                                                                              \
+    return rv;                                                                \
+}
+
+// 'Constructor' that uses an existing getter function that gets a singleton.
+// NOTE: assumes that getter does an AddRef - so additional AddRef is not done.
+#define NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(_InstanceClass, _GetterProc) \
+static nsresult                                                               \
+_InstanceClass##Constructor(nsISupports *aOuter, REFNSIID aIID,               \
+                            void **aResult)                                   \
+{                                                                             \
+    nsresult rv;                                                              \
+                                                                              \
+    _InstanceClass * inst;                                                    \
+                                                                              \
+    *aResult = NULL;                                                          \
+    if (NULL != aOuter) {                                                     \
+        rv = NS_ERROR_NO_AGGREGATION;                                         \
+        return rv;                                                            \
+    }                                                                         \
+                                                                              \
+    inst = _GetterProc();                                                     \
+    if (NULL == inst) {                                                       \
+        rv = NS_ERROR_OUT_OF_MEMORY;                                          \
+        return rv;                                                            \
+    }                                                                         \
+    /* NS_ADDREF(inst); */                                                    \
+    rv = inst->QueryInterface(aIID, aResult);                                 \
+    NS_RELEASE(inst);                                                         \
+                                                                              \
+    return rv;                                                                \
+}
+
+#endif // mozilla_GenericModule_h
--- a/xpcom/components/nsCategoryManager.cpp
+++ b/xpcom/components/nsCategoryManager.cpp
@@ -46,16 +46,17 @@
 #include "prprf.h"
 #include "prlock.h"
 #include "nsCOMPtr.h"
 #include "nsTHashtable.h"
 #include "nsClassHashtable.h"
 #include "nsIFactory.h"
 #include "nsIStringEnumerator.h"
 #include "nsSupportsPrimitives.h"
+#include "nsComponentManagerUtils.h"
 #include "nsServiceManagerUtils.h"
 #include "nsIObserver.h"
 #include "nsIObserverService.h"
 #include "nsReadableUtils.h"
 #include "nsCRT.h"
 #include "nsQuickSort.h"
 #include "nsEnumeratorUtils.h"
 #include "nsIProxyObjectManager.h"
@@ -198,17 +199,17 @@ private:
     enumfunc_createenumerator(CategoryLeaf* aLeaf, void* userArg);
 };
 
 
 PLDHashOperator
 EntryEnumerator::enumfunc_createenumerator(CategoryLeaf* aLeaf, void* userArg)
 {
   EntryEnumerator* mythis = static_cast<EntryEnumerator*>(userArg);
-  if (aLeaf->nonpValue)
+  if (aLeaf->value)
     mythis->mArray[mythis->mCount++] = aLeaf->GetKey();
 
   return PL_DHASH_NEXT;
 }
 
 EntryEnumerator*
 EntryEnumerator::Create(nsTHashtable<CategoryLeaf>& aTable)
 {
@@ -266,107 +267,70 @@ CategoryNode::GetLeaf(const char* aEntry
                       char** _retval)
 {
   MutexAutoLock lock(mLock);
   nsresult rv = NS_ERROR_NOT_AVAILABLE;
   CategoryLeaf* ent =
     mTable.GetEntry(aEntryName);
 
   // we only want the non-persistent value
-  if (ent && ent->nonpValue) {
-    *_retval = NS_strdup(ent->nonpValue);
+  if (ent && ent->value) {
+    *_retval = NS_strdup(ent->value);
     if (*_retval)
       rv = NS_OK;
   }
 
   return rv;
 }
 
 NS_METHOD
 CategoryNode::AddLeaf(const char* aEntryName,
                       const char* aValue,
-                      PRBool aPersist,
-                      PRBool aReplace,
                       char** _retval,
                       PLArenaPool* aArena)
 {
   MutexAutoLock lock(mLock);
   CategoryLeaf* leaf = 
     mTable.GetEntry(aEntryName);
 
   nsresult rv = NS_OK;
-  if (leaf) {
-    //if the entry was found, aReplace must be specified
-    if (!aReplace && (leaf->nonpValue || (aPersist && leaf->pValue )))
-      rv = NS_ERROR_INVALID_ARG;
-  } else {
+  if (!leaf) {
     const char* arenaEntryName = ArenaStrdup(aEntryName, aArena);
     if (!arenaEntryName) {
       rv = NS_ERROR_OUT_OF_MEMORY;
     } else {
       leaf = mTable.PutEntry(arenaEntryName);
       if (!leaf)
         rv = NS_ERROR_OUT_OF_MEMORY;
     }
   }
 
   if (NS_SUCCEEDED(rv)) {
     const char* arenaValue = ArenaStrdup(aValue, aArena);
     if (!arenaValue) {
       rv = NS_ERROR_OUT_OF_MEMORY;
     } else {
       if (_retval) {
-        const char *toDup = leaf->nonpValue ? leaf->nonpValue : leaf->pValue;
-        if (toDup) {
-          *_retval = ToNewCString(nsDependentCString(toDup));
+        if (leaf->value) {
+          *_retval = ToNewCString(nsDependentCString(leaf->value));
           if (!*_retval)
             return NS_ERROR_OUT_OF_MEMORY;
         }
         else {
           *_retval = nsnull;
         }
       }
 
-      leaf->nonpValue = arenaValue;
-      if (aPersist)
-        leaf->pValue = arenaValue;
+      leaf->value = arenaValue;
     }
   }
     
   return rv;
 }
 
-NS_METHOD
-CategoryNode::DeleteLeaf(const char* aEntryName,
-                         PRBool aDontPersist)
-{
-  // we don't throw any errors, because it normally doesn't matter
-  // and it makes JS a lot cleaner
-  MutexAutoLock lock(mLock);
-
-  if (aDontPersist) {
-    // we can just remove the entire hash entry without introspection
-    mTable.RemoveEntry(aEntryName);
-  } else {
-    // if we are keeping the persistent value, we need to look at
-    // the contents of the current entry
-    CategoryLeaf* leaf = mTable.GetEntry(aEntryName);
-    if (leaf) {
-      if (leaf->pValue) {
-        leaf->nonpValue = nsnull;
-      } else {
-        // if there is no persistent value, just remove the entry
-        mTable.RawRemoveEntry(leaf);
-      }
-    }
-  }
-
-  return NS_OK;
-}
-
 NS_METHOD 
 CategoryNode::Enumerate(nsISimpleEnumerator **_retval)
 {
   NS_ENSURE_ARG_POINTER(_retval);
 
   MutexAutoLock lock(mLock);
   EntryEnumerator* enumObj = EntryEnumerator::Create(mTable);
 
@@ -387,46 +351,30 @@ struct persistent_userstruct {
 PLDHashOperator
 enumfunc_pentries(CategoryLeaf* aLeaf, void* userArg)
 {
   persistent_userstruct* args =
     static_cast<persistent_userstruct*>(userArg);
 
   PLDHashOperator status = PL_DHASH_NEXT;
 
-  if (aLeaf->pValue) {
+  if (aLeaf->value) {
     if (PR_fprintf(args->fd,
                    "%s,%s,%s\n",
                    args->categoryName,
                    aLeaf->GetKey(),
-                   aLeaf->pValue) == (PRUint32) -1) {
+                   aLeaf->value) == (PRUint32) -1) {
       args->success = PR_FALSE;
       status = PL_DHASH_STOP;
     }
   }
 
   return status;
 }
 
-PRBool
-CategoryNode::WritePersistentEntries(PRFileDesc* fd, const char* aCategoryName)
-{
-  persistent_userstruct args = {
-    fd,
-    aCategoryName,
-    PR_TRUE
-  };
-
-  MutexAutoLock lock(mLock);
-  mTable.EnumerateEntries(enumfunc_pentries, &args);
-
-  return args.success;
-}
-
-
 //
 // CategoryEnumerator class
 //
 
 class CategoryEnumerator
   : public BaseStringEnumerator
 {
 public:
@@ -469,35 +417,63 @@ CategoryEnumerator::enumfunc_createenume
   return PL_DHASH_NEXT;
 }
 
 
 //
 // nsCategoryManager implementations
 //
 
-NS_IMPL_THREADSAFE_ISUPPORTS1(nsCategoryManager, nsICategoryManager)
+NS_IMPL_QUERY_INTERFACE1(nsCategoryManager, nsICategoryManager)
 
-nsCategoryManager*
-nsCategoryManager::Create()
+NS_IMETHODIMP_(nsrefcnt)
+nsCategoryManager::AddRef()
+{
+  return 2;
+}
+
+NS_IMETHODIMP_(nsrefcnt)
+nsCategoryManager::Release()
 {
-  nsCategoryManager* manager = new nsCategoryManager();
-  
-  if (!manager)
-    return nsnull;
+  return 1;
+}
+
+nsCategoryManager* nsCategoryManager::gCategoryManager;
+
+/* static */ nsCategoryManager*
+nsCategoryManager::GetSingleton()
+{
+  if (!gCategoryManager)
+    gCategoryManager = new nsCategoryManager();
+  return gCategoryManager;
+}
 
-  PL_INIT_ARENA_POOL(&(manager->mArena), "CategoryManagerArena",
-                     NS_CATEGORYMANAGER_ARENA_SIZE); // this never fails
+/* static */ void
+nsCategoryManager::Destroy()
+{
+  delete gCategoryManager;
+}
+
+nsresult
+nsCategoryManager::Create(nsISupports* aOuter, REFNSIID aIID, void** aResult)
+{
+  if (aOuter)
+    return NS_ERROR_NO_AGGREGATION;
 
-  if (!manager->mTable.Init()) {
-    delete manager;
-    return nsnull;
-  }
+  return GetSingleton()->QueryInterface(aIID, aResult);
+}
 
-  return manager;
+nsCategoryManager::nsCategoryManager()
+  : mLock("nsCategoryManager")
+  , mSuppressNotifications(PR_FALSE)
+{
+  PL_INIT_ARENA_POOL(&mArena, "CategoryManagerArena",
+                     NS_CATEGORYMANAGER_ARENA_SIZE);
+
+  mTable.Init();
 }
 
 nsCategoryManager::~nsCategoryManager()
 {
   // the hashtable contains entries that must be deleted before the arena is
   // destroyed, or else you will have PRLocks undestroyed and other Really
   // Bad Stuff (TM)
   mTable.Clear();
@@ -573,28 +549,21 @@ nsCategoryManager::GetCategoryEntry( con
 
   if (category) {
     status = category->GetLeaf(aEntryName, _retval);
   }
 
   return status;
 }
 
-NS_IMETHODIMP
-nsCategoryManager::AddCategoryEntry( const char *aCategoryName,
-                                     const char *aEntryName,
-                                     const char *aValue,
-                                     PRBool aPersist,
-                                     PRBool aReplace,
-                                     char **_retval )
+void
+nsCategoryManager::AddCategoryEntry(const char *aCategoryName,
+                                    const char *aEntryName,
+                                    const char *aValue)
 {
-  NS_ENSURE_ARG_POINTER(aCategoryName);
-  NS_ENSURE_ARG_POINTER(aEntryName);
-  NS_ENSURE_ARG_POINTER(aValue);
-
   // Before we can insert a new entry, we'll need to
   //  find the |CategoryNode| to put it in...
   CategoryNode* category;
   {
     MutexAutoLock lock(mLock);
     category = get_category(aCategoryName);
 
     if (!category) {
@@ -602,101 +571,36 @@ nsCategoryManager::AddCategoryEntry( con
       category = CategoryNode::Create(&mArena);
         
       char* categoryName = ArenaStrdup(aCategoryName, &mArena);
       mTable.Put(categoryName, category);
     }
   }
 
   if (!category)
-    return NS_ERROR_OUT_OF_MEMORY;
+    return;
 
   // We will need the return value of AddLeaf even if the called doesn't want it
   char *oldEntry = nsnull;
 
   nsresult rv = category->AddLeaf(aEntryName,
                                   aValue,
-                                  aPersist,
-                                  aReplace,
                                   &oldEntry,
                                   &mArena);
 
   if (NS_SUCCEEDED(rv)) {
     if (oldEntry) {
       NotifyObservers(NS_XPCOM_CATEGORY_ENTRY_REMOVED_OBSERVER_ID,
                       aCategoryName, oldEntry);
     }
     NotifyObservers(NS_XPCOM_CATEGORY_ENTRY_ADDED_OBSERVER_ID,
                     aCategoryName, aEntryName);
 
-    if (_retval)
-      *_retval = oldEntry;
-    else if (oldEntry)
-      nsMemory::Free(oldEntry);
-  }
-
-  return rv;
-}
-
-NS_IMETHODIMP
-nsCategoryManager::DeleteCategoryEntry( const char *aCategoryName,
-                                        const char *aEntryName,
-                                        PRBool aDontPersist)
-{
-  NS_ENSURE_ARG_POINTER(aCategoryName);
-  NS_ENSURE_ARG_POINTER(aEntryName);
-
-  /*
-    Note: no errors are reported since failure to delete
-    probably won't hurt you, and returning errors seriously
-    inconveniences JS clients
-  */
-
-  CategoryNode* category;
-  {
-    MutexAutoLock lock(mLock);
-    category = get_category(aCategoryName);
+    NS_Free(oldEntry);
   }
-
-  if (!category)
-    return NS_OK;
-
-  nsresult rv = category->DeleteLeaf(aEntryName,
-                                     aDontPersist);
-
-  if (NS_SUCCEEDED(rv)) {
-    NotifyObservers(NS_XPCOM_CATEGORY_ENTRY_REMOVED_OBSERVER_ID,
-                    aCategoryName, aEntryName);
-  }
-
-  return rv;
-}
-
-NS_IMETHODIMP
-nsCategoryManager::DeleteCategory( const char *aCategoryName )
-{
-  NS_ENSURE_ARG_POINTER(aCategoryName);
-
-  // the categories are arena-allocated, so we don't
-  // actually delete them. We just remove all of the
-  // leaf nodes.
-
-  CategoryNode* category;
-  {
-    MutexAutoLock lock(mLock);
-    category = get_category(aCategoryName);
-  }
-
-  if (category) {
-    category->Clear();
-    NotifyObservers(NS_XPCOM_CATEGORY_CLEARED_OBSERVER_ID,
-                    aCategoryName, nsnull);
-  }
-
-  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsCategoryManager::EnumerateCategory( const char *aCategoryName,
                                       nsISimpleEnumerator **_retval )
 {
   NS_ENSURE_ARG_POINTER(aCategoryName);
   NS_ENSURE_ARG_POINTER(_retval);
@@ -730,120 +634,23 @@ nsCategoryManager::EnumerateCategories(n
   return NS_OK;
 }
 
 struct writecat_struct {
   PRFileDesc* fd;
   PRBool      success;
 };
 
-PLDHashOperator
-enumfunc_categories(const char* aKey, CategoryNode* aCategory, void* userArg)
-{
-  writecat_struct* args = static_cast<writecat_struct*>(userArg);
-
-  PLDHashOperator result = PL_DHASH_NEXT;
-
-  if (!aCategory->WritePersistentEntries(args->fd, aKey)) {
-    args->success = PR_FALSE;
-    result = PL_DHASH_STOP;
-  }
-
-  return result;
-}
-
-NS_METHOD
-nsCategoryManager::WriteCategoryManagerToRegistry(PRFileDesc* fd)
-{
-  writecat_struct args = {
-    fd,
-    PR_TRUE
-  };
-
-  MutexAutoLock lock(mLock);
-  mTable.EnumerateRead(enumfunc_categories, &args);
-
-  if (!args.success) {
-    return NS_ERROR_UNEXPECTED;
-  }
-
-  return NS_OK;
-}
-
 NS_METHOD
 nsCategoryManager::SuppressNotifications(PRBool aSuppress)
 {
   mSuppressNotifications = aSuppress;
   return NS_OK;
 }
 
-class nsCategoryManagerFactory : public nsIFactory
-   {
-     public:
-       nsCategoryManagerFactory() { }
-
-       NS_DECL_ISUPPORTS
-       NS_DECL_NSIFACTORY
-   };
-
-NS_IMPL_ISUPPORTS1(nsCategoryManagerFactory, nsIFactory)
-
-NS_IMETHODIMP
-nsCategoryManagerFactory::CreateInstance( nsISupports* aOuter, const nsIID& aIID, void** aResult )
-  {
-    NS_ENSURE_ARG_POINTER(aResult);
-
-    *aResult = 0;
-
-    nsresult status = NS_OK;
-    if ( aOuter )
-      status = NS_ERROR_NO_AGGREGATION;
-    else
-      {
-        nsCategoryManager* raw_category_manager = nsCategoryManager::Create();
-        nsCOMPtr<nsICategoryManager> new_category_manager = raw_category_manager;
-        if ( new_category_manager )
-              status = new_category_manager->QueryInterface(aIID, aResult);
-        else
-          status = NS_ERROR_OUT_OF_MEMORY;
-      }
-
-    return status;
-  }
-
-NS_IMETHODIMP
-nsCategoryManagerFactory::LockFactory( PRBool )
-  {
-      // Not implemented...
-    return NS_OK;
-  }
-
-nsresult
-NS_CategoryManagerGetFactory( nsIFactory** aFactory )
-  {
-    // assert(aFactory);
-
-    nsresult status;
-
-    *aFactory = 0;
-    nsIFactory* new_factory = static_cast<nsIFactory*>(new nsCategoryManagerFactory);
-    if (new_factory)
-      {
-        *aFactory = new_factory;
-        NS_ADDREF(*aFactory);
-        status = NS_OK;
-      }
-    else
-      status = NS_ERROR_OUT_OF_MEMORY;
-
-    return status;
-  }
-
-
-
 /*
  * CreateServicesFromCategory()
  *
  * Given a category, this convenience functions enumerates the category and 
  * creates a service of every CID or ContractID registered under the category.
  * If observerTopic is non null and the service implements nsIObserver,
  * this will attempt to notify the observer with the origin, observerTopic string
  * as parameter.
--- a/xpcom/components/nsCategoryManager.h
+++ b/xpcom/components/nsCategoryManager.h
@@ -60,59 +60,45 @@
  * the same, except when aPersist==PR_FALSE. The strings are permanently arena-
  * allocated, and will never go away.
  */
 class CategoryLeaf : public nsDepCharHashKey
 {
 public:
   CategoryLeaf(const char* aKey)
     : nsDepCharHashKey(aKey),
-      pValue(nsnull),
-      nonpValue(nsnull) { }
-  const char* pValue;
-  const char* nonpValue;
+      value(NULL) { }
+  const char* value;
 };
 
 
 /**
  * CategoryNode keeps a hashtable of its entries.
  * the CategoryNode itself is permanently allocated in
  * the arena.
  */
 class CategoryNode
 {
 public:
   NS_METHOD GetLeaf(const char* aEntryName,
                     char** _retval);
 
   NS_METHOD AddLeaf(const char* aEntryName,
                     const char* aValue,
-                    PRBool aPersist,
-                    PRBool aReplace,
                     char** _retval,
                     PLArenaPool* aArena);
 
-  NS_METHOD DeleteLeaf(const char* aEntryName,
-                       PRBool aDontPersist);
-
-  void Clear() {
-    mozilla::MutexAutoLock lock(mLock);
-    mTable.Clear();
-  }
-
   PRUint32 Count() {
     mozilla::MutexAutoLock lock(mLock);
     PRUint32 tCount = mTable.Count();
     return tCount;
   }
 
   NS_METHOD Enumerate(nsISimpleEnumerator** _retval);
 
-  PRBool WritePersistentEntries(PRFileDesc* fd, const char* aCategoryName);
-
   // CategoryNode is arena-allocated, with the strings
   static CategoryNode* Create(PLArenaPool* aArena);
   ~CategoryNode();
   void operator delete(void*) { }
 
 private:
   CategoryNode()
     : mLock("CategoryLeaf")
@@ -133,37 +119,35 @@ private:
 class nsCategoryManager
   : public nsICategoryManager
 {
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSICATEGORYMANAGER
 
   /**
-   * Write the categories to the XPCOM persistent registry.
-   * This is to be used by nsComponentManagerImpl (and NO ONE ELSE).
-   */
-  NS_METHOD WriteCategoryManagerToRegistry(PRFileDesc* fd);
-
-  /**
    * Suppress or unsuppress notifications of category changes to the
    * observer service. This is to be used by nsComponentManagerImpl
    * on startup while reading the stored category list.
    */
   NS_METHOD SuppressNotifications(PRBool aSuppress);
 
-  nsCategoryManager()
-    : mLock("nsCategoryManager")
-    , mSuppressNotifications(PR_FALSE)
-  { }
+  void AddCategoryEntry(const char* aCategory,
+                        const char* aKey,
+                        const char* aValue);
+
+  static nsresult Create(nsISupports* aOuter, REFNSIID aIID, void** aResult);
+
+  static nsCategoryManager* GetSingleton();
+  static void Destroy();
 
 private:
-  friend class nsCategoryManagerFactory;
-  static nsCategoryManager* Create();
+  static nsCategoryManager* gCategoryManager;
 
+  nsCategoryManager();
   ~nsCategoryManager();
 
   CategoryNode* get_category(const char* aName);
   void NotifyObservers(const char* aTopic,
                        const char* aCategoryName,
                        const char* aEntryName);
 
   PLArenaPool mArena;
--- a/xpcom/components/nsComponentManager.cpp
+++ b/xpcom/components/nsComponentManager.cpp
@@ -54,48 +54,53 @@
 // Arena used by component manager for storing contractid string, dll
 // location strings and small objects
 // CAUTION: Arena align mask needs to be defined before including plarena.h
 //          currently from nsComponentManager.h
 #define PL_ARENA_CONST_ALIGN_MASK 7
 #define NS_CM_BLOCK_SIZE (1024 * 8)
 
 #include "nsAutoLock.h"
+#include "nsCategoryManager.h"
 #include "nsCOMPtr.h"
 #include "nsComponentManager.h"
 #include "nsDirectoryService.h"
 #include "nsDirectoryServiceDefs.h"
 #include "nsCategoryManager.h"
 #include "nsCategoryManagerUtils.h"
 #include "nsIEnumerator.h"
 #include "xptiprivate.h"
 #include "nsIConsoleService.h"
-#include "nsIModule.h"
 #include "nsIObserverService.h"
 #include "nsISimpleEnumerator.h"
 #include "nsIStringEnumerator.h"
 #include "nsXPCOM.h"
 #include "nsXPCOMPrivate.h"
 #include "nsISupportsPrimitives.h"
 #include "nsIClassInfo.h"
 #include "nsLocalFile.h"
 #include "nsReadableUtils.h"
+#include "nsStaticComponents.h"
 #include "nsString.h"
 #include "nsXPIDLString.h"
 #include "prcmon.h"
 #include "xptinfo.h" // this after nsISupports, to pick up IID so that xpt stuff doesn't try to define it itself...
 #include "nsThreadUtils.h"
 #include "prthread.h"
 #include "private/pprthred.h"
 #include "nsTArray.h"
 #include "prio.h"
 #include "mozilla/FunctionTimer.h"
 
 #include "nsInt64.h"
 #include "nsManifestLineReader.h"
+#include "mozilla/GenericFactory.h"
+#include "nsSupportsPrimitives.h"
+#include "nsArrayEnumerator.h"
+#include "nsStringEnumerator.h"
 
 #include NEW_H     // for placement new
 
 
 #ifdef XP_BEOS
 #include <FindDirectory.h>
 #include <Path.h>
 #endif
@@ -238,1231 +243,428 @@ ArenaStrndup(const char *s, PRUint32 len
 }
 
 char*
 ArenaStrdup(const char *s, PLArenaPool *arena)
 {
     return ArenaStrndup(s, strlen(s), arena);
 }
 
-////////////////////////////////////////////////////////////////////////////////
-// Hashtable Callbacks
-////////////////////////////////////////////////////////////////////////////////
-
-PRBool
-nsFactoryEntry_Destroy(nsHashKey *aKey, void *aData, void* closure);
-
-static PLDHashNumber
-factory_HashKey(PLDHashTable *aTable, const void *aKey)
-{
-    const nsCID *cidp = reinterpret_cast<const nsCID*>(aKey);
-
-    return cidp->m0;
-}
-
-static PRBool
-factory_MatchEntry(PLDHashTable *aTable, const PLDHashEntryHdr *aHdr,
-                   const void *aKey)
-{
-    const nsFactoryTableEntry* entry =
-        static_cast<const nsFactoryTableEntry*>(aHdr);
-    const nsCID *cidp = reinterpret_cast<const nsCID*>(aKey);
-
-    return (entry->mFactoryEntry->mCid).Equals(*cidp);
-}
-
-static void
-factory_ClearEntry(PLDHashTable *aTable, PLDHashEntryHdr *aHdr)
-{
-    nsFactoryTableEntry* entry = static_cast<nsFactoryTableEntry*>(aHdr);
-    // nsFactoryEntry is arena allocated. So we don't delete it.
-    // We call the destructor by hand.
-    entry->mFactoryEntry->~nsFactoryEntry();
-    PL_DHashClearEntryStub(aTable, aHdr);
-}
-
-static const PLDHashTableOps factory_DHashTableOps = {
-    PL_DHashAllocTable,
-    PL_DHashFreeTable,
-    factory_HashKey,
-    factory_MatchEntry,
-    PL_DHashMoveEntryStub,
-    factory_ClearEntry,
-    PL_DHashFinalizeStub,
-};
-
-static void
-contractID_ClearEntry(PLDHashTable *aTable, PLDHashEntryHdr *aHdr)
-{
-    nsContractIDTableEntry* entry = static_cast<nsContractIDTableEntry*>(aHdr);
-    if (entry->mFactoryEntry->mLoaderType == NS_LOADER_TYPE_INVALID &&
-        entry->mFactoryEntry->mCid.Equals(kEmptyCID)) {
-        // this object is owned by the hash.
-        // nsFactoryEntry is arena allocated. So we don't delete it.
-        // We call the destructor by hand.
-        entry->mFactoryEntry->~nsFactoryEntry();
-    }
-
-    // contractIDs are arena allocated. No need to free them.
-
-    PL_DHashClearEntryStub(aTable, aHdr);
-}
-
-static const PLDHashTableOps contractID_DHashTableOps = {
-    PL_DHashAllocTable,
-    PL_DHashFreeTable,
-    PL_DHashStringKey,
-    PL_DHashMatchStringKey,
-    PL_DHashMoveEntryStub,
-    contractID_ClearEntry,
-    PL_DHashFinalizeStub,
-};
-
-////////////////////////////////////////////////////////////////////////////////
-// 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
-
-    PLDHashTableEnumeratorImpl(PLDHashTable *table,
-                               EnumeratorConverter converter,
-                               void *converterData);
-    PRInt32 Count() { return mCount; }
-private:
-    PLDHashTableEnumeratorImpl(); /* no implementation */
-
-    ~PLDHashTableEnumeratorImpl();
-    void ReleaseElements();
-
-    nsTArray<nsISupports*> mElements;
-    PRInt32                mCount, mCurrent;
-    PRMonitor*             mMonitor;
-
-    struct Closure {
-        PRBool                        succeeded;
-        EnumeratorConverter           converter;
-        void                          *data;
-        PLDHashTableEnumeratorImpl    *impl;
-    };
-
-    static PLDHashOperator Enumerator(PLDHashTable *table,
-                                      PLDHashEntryHdr *hdr,
-                                      PRUint32 number,
-                                      void *data);
-};
-
-// static
-PLDHashOperator
-PLDHashTableEnumeratorImpl::Enumerator(PLDHashTable *table,
-                                       PLDHashEntryHdr *hdr,
-                                       PRUint32 number,
-                                       void *data)
-{
-    Closure *c = 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);
-
-    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()
-{
-    ReleaseElements();
-
-    // Destroy the Lock
-    if (mMonitor)
-        nsAutoMonitor::DestroyMonitor(mMonitor);
-}
-
-void
-PLDHashTableEnumeratorImpl::ReleaseElements()
-{
-    for (PRInt32 i = 0; i < mCount; i++) {
-        NS_IF_RELEASE(mElements[i]);
-    }
-}
-
-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;
-
-    NS_ADDREF(impl);
-
-    if (impl->Count() == -1) {
-        // conversion failed
-        NS_RELEASE(impl);
-        return NS_ERROR_FAILURE;
-    }
-
-    *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 = mElements[mCurrent];
-    if (*retval)
-        NS_ADDREF(*retval);
-
-    return NS_OK;
-}
-
-NS_IMETHODIMP
-PLDHashTableEnumeratorImpl::IsDone()
-{
-    if (!mCount || (mCurrent == mCount))
-        return NS_OK;
-
-    return NS_ENUMERATOR_FALSE;
-}
-
-NS_IMETHODIMP
-PLDHashTableEnumeratorImpl::HasMoreElements(PRBool *_retval)
-{
-    if (!mCount || (mCurrent >= mCount - 1))
-        *_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<nsISupportsID> wrapper;
-
-    nsComponentManagerImpl *cm = static_cast<nsComponentManagerImpl *>(data);
-
-    rv = cm->CreateInstanceByContractID(NS_SUPPORTS_ID_CONTRACTID, nsnull,
-           NS_GET_IID(nsISupportsID), getter_AddRefs(wrapper));
-
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    const nsFactoryTableEntry *entry =
-        reinterpret_cast<const nsFactoryTableEntry *>(hdr);
-    if (entry) {
-        nsFactoryEntry *fe = entry->mFactoryEntry;
-
-        wrapper->SetData(&fe->mCid);
-        *retval = wrapper;
-        NS_ADDREF(*retval);
-        return NS_OK;
-    }
-    *retval = nsnull;
-
-    return rv;
-}
-
-static NS_IMETHODIMP
-ConvertContractIDKeyToString(PLDHashTable *table,
-                             const PLDHashEntryHdr *hdr,
-                             void *data, nsISupports **retval)
-{
-    nsresult rv;
-    nsCOMPtr<nsISupportsCString> wrapper;
-
-    nsComponentManagerImpl *cm = static_cast<nsComponentManagerImpl *>(data);
-
-    rv = cm->CreateInstanceByContractID(NS_SUPPORTS_CSTRING_CONTRACTID, nsnull,
-                NS_GET_IID(nsISupportsCString), getter_AddRefs(wrapper));
-
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    const nsContractIDTableEntry *entry =
-        reinterpret_cast<const nsContractIDTableEntry *>(hdr);
-
-    wrapper->SetData(nsDependentCString(entry->mContractID,
-                                        entry->mContractIDLen));
-    *retval = wrapper;
-    NS_ADDREF(*retval);
-    return NS_OK;
-}
-
 // this is safe to call during InitXPCOM
-static nsresult GetLocationFromDirectoryService(const char* prop,
-                                                nsIFile** aDirectory)
+static already_AddRefed<nsILocalFile>
+GetLocationFromDirectoryService(const char* prop, const char *const * append)
 {
     nsCOMPtr<nsIProperties> directoryService;
     nsDirectoryService::Create(nsnull,
                                NS_GET_IID(nsIProperties),
                                getter_AddRefs(directoryService));
 
     if (!directoryService)
-        return NS_ERROR_FAILURE;
+        return NULL;
 
-    return directoryService->Get(prop,
-                                 NS_GET_IID(nsIFile),
-                                 (void**)aDirectory);
+    nsCOMPtr<nsILocalFile> file;
+    nsresult rv = directoryService->Get(prop,
+                                        NS_GET_IID(nsILocalFile),
+                                        getter_AddRefs(file));
+    if (NS_FAILED(rv))
+        return NULL;
+
+    while (append && *append) {
+        file->AppendNative(nsDependentCString(*append));
+        ++append;
+    }
+    return file.forget();
 }
 
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsComponentManagerImpl
 ////////////////////////////////////////////////////////////////////////////////
 
+nsresult
+nsComponentManagerImpl::Create(nsISupports* aOuter, REFNSIID aIID, void** aResult)
+{
+    if (aOuter)
+        return NS_ERROR_NO_AGGREGATION;
+
+    if (!gComponentManager)
+        return NS_ERROR_FAILURE;
+
+    return gComponentManager->QueryInterface(aIID, aResult);
+}
 
 nsComponentManagerImpl::nsComponentManagerImpl()
-    :
-    mMon(NULL),
-    mShuttingDown(NS_SHUTDOWN_NEVERHAPPENED),
-    mLoaderData(4),
-    mRegistryDirty(PR_FALSE)
+    : mMon(NULL)
+    , mStatus(NOT_INITIALIZED)
 {
-    mFactories.ops = nsnull;
-    mContractIDs.ops = nsnull;
 }
 
 #define CONTRACTID_HASHTABLE_INITIAL_SIZE	2048
-#define AUTOREGENTRY_HASHTABLE_INITIAL_SIZE	256
+
+nsTArray<const mozilla::Module*>* nsComponentManagerImpl::sStaticModules;
+
+/* static */ void
+nsComponentManagerImpl::InitializeStaticModules()
+{
+    if (sStaticModules)
+        return;
 
-nsresult nsComponentManagerImpl::Init(nsStaticModuleInfo const *aStaticModules,
-                                      PRUint32 aStaticModuleCount)
+    sStaticModules = new nsTArray<const mozilla::Module*>;
+    for (const mozilla::Module *const *staticModules = kPStaticModules;
+         *staticModules; ++staticModules)
+        sStaticModules->AppendElement(*staticModules);
+}
+
+nsCOMArray<nsILocalFile>* nsComponentManagerImpl::sModuleLocations;
+
+/* static */ void
+nsComponentManagerImpl::InitializeModuleLocations()
+{
+    if (sModuleLocations)
+        return;
+
+    sModuleLocations = new nsCOMArray<nsILocalFile>;
+}
+
+nsresult nsComponentManagerImpl::Init()
 {
     NS_TIME_FUNCTION;
 
-    PR_ASSERT(mShuttingDown != NS_SHUTDOWN_INPROGRESS);
-    if (mShuttingDown == NS_SHUTDOWN_INPROGRESS)
-        return NS_ERROR_FAILURE;
-
-    mShuttingDown = NS_SHUTDOWN_NEVERHAPPENED;
+    PR_ASSERT(NOT_INITIALIZED == mStatus);
 
     if (nsComponentManagerLog == nsnull)
     {
         nsComponentManagerLog = PR_NewLogModule("nsComponentManager");
     }
 
     // Initialize our arena
     NS_TIME_FUNCTION_MARK("Next: init component manager arena");
     PL_INIT_ARENA_POOL(&mArena, "ComponentManagerArena", NS_CM_BLOCK_SIZE);
 
-    if (!mFactories.ops) {
-        if (!PL_DHashTableInit(&mFactories, &factory_DHashTableOps,
-                               0, sizeof(nsFactoryTableEntry),
-                               1024)) {
-            mFactories.ops = nsnull;
-            return NS_ERROR_OUT_OF_MEMORY;
-        }
-
-        // Minimum alpha uses k=2 because nsFactoryTableEntry saves two
-        // words compared to what a chained hash table requires.
-        PL_DHashTableSetAlphaBounds(&mFactories,
-                                    0.875,
-                                    PL_DHASH_MIN_ALPHA(&mFactories, 2));
-    }
+    mFactories.Init(CONTRACTID_HASHTABLE_INITIAL_SIZE);
+    mContractIDs.Init(CONTRACTID_HASHTABLE_INITIAL_SIZE);
 
-    if (!mContractIDs.ops) {
-        if (!PL_DHashTableInit(&mContractIDs, &contractID_DHashTableOps,
-                               0, sizeof(nsContractIDTableEntry),
-                               CONTRACTID_HASHTABLE_INITIAL_SIZE)) {
-            mContractIDs.ops = nsnull;
-            return NS_ERROR_OUT_OF_MEMORY;
-        }
-
-        // Minimum alpha uses k=1 because nsContractIDTableEntry saves one
-        // word compared to what a chained hash table requires.
-#if 0
-        PL_DHashTableSetAlphaBounds(&mContractIDs,
-                                    0.875,
-                                    PL_DHASH_MIN_ALPHA(&mContractIDs, 1));
-#endif
-    }
-
-    if (!mAutoRegEntries.Init(AUTOREGENTRY_HASHTABLE_INITIAL_SIZE))
+    mMon = nsAutoMonitor::NewMonitor("nsComponentManagerImpl");
+    if (mMon == nsnull)
         return NS_ERROR_OUT_OF_MEMORY;
 
-    if (mMon == nsnull) {
-        mMon = nsAutoMonitor::NewMonitor("nsComponentManagerImpl");
-        if (mMon == nsnull)
-            return NS_ERROR_OUT_OF_MEMORY;
-    }
+    static const char *const kComponents[] = { "components", NULL };
 
-    GetLocationFromDirectoryService(NS_XPCOM_COMPONENT_DIR, getter_AddRefs(mComponentsDir));
-    if (!mComponentsDir)
-        return NS_ERROR_OUT_OF_MEMORY;
-
-    nsCAutoString componentDescriptor;
-    nsresult rv = mComponentsDir->GetNativePath(componentDescriptor);
-    if (NS_FAILED(rv))
-        return rv;
-
-    mComponentsOffset = componentDescriptor.Length();
+    nsCOMPtr<nsILocalFile> greComponents =
+        GetLocationFromDirectoryService(NS_GRE_DIR, kComponents);
 
-    GetLocationFromDirectoryService(NS_GRE_COMPONENT_DIR, getter_AddRefs(mGREComponentsDir));
-    if (mGREComponentsDir) {
-        nsresult rv = mGREComponentsDir->GetNativePath(componentDescriptor);
-        if (NS_FAILED(rv)) {
-            NS_WARNING("No GRE component manager");
-            return rv;
-        }
-        mGREComponentsOffset = componentDescriptor.Length();
-    }
+    nsCOMPtr<nsILocalFile> appComponents =
+        GetLocationFromDirectoryService(NS_XPCOM_CURRENT_PROCESS_DIR, kComponents);
+    InitializeStaticModules();
+    InitializeModuleLocations();
 
-    GetLocationFromDirectoryService(NS_XPCOM_COMPONENT_REGISTRY_FILE,
-                                    getter_AddRefs(mRegistryFile));
-
-    if(!mRegistryFile) {
-        NS_WARNING("No Component Registry file was found in the directory service");
-        return NS_ERROR_FAILURE;
-    }
+    PRBool equals = PR_FALSE;
+    appComponents->Equals(greComponents, &equals);
+    if (!equals)
+        sModuleLocations->InsertObjectAt(greComponents, 0);
+    sModuleLocations->InsertObjectAt(appComponents, 0);
 
     PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG,
            ("nsComponentManager: Initialized."));
 
     NS_TIME_FUNCTION_MARK("Next: init native module loader");
-    rv = mNativeModuleLoader.Init();
+    nsresult rv = mNativeModuleLoader.Init();
     if (NS_FAILED(rv))
         return rv;
 
-    NS_TIME_FUNCTION_MARK("Next: init static module loader");
-    rv = mStaticModuleLoader.Init(aStaticModules, aStaticModuleCount);
-    if (NS_FAILED(rv))
-        return rv;
+    nsCategoryManager::GetSingleton()->SuppressNotifications(true);
+
+    RegisterModule(&kXPCOMModule, NULL);
+
+    for (PRUint32 i = 0; i < sStaticModules->Length(); ++i)
+        RegisterModule((*sStaticModules)[i], NULL);
+
+    for (PRInt32 i = 0; i < sModuleLocations->Count(); ++i)
+        RegisterLocation((*sModuleLocations)[i]);
+
+    nsCategoryManager::GetSingleton()->SuppressNotifications(false);
+
+    mStatus = NORMAL;
 
     return NS_OK;
 }
 
+void
+nsComponentManagerImpl::RegisterModule(const mozilla::Module* aModule,
+                                       nsILocalFile* aFile)
+{
+    nsAutoMonitor mon(mMon);
+
+    KnownModule* m = new KnownModule(aModule, aFile);
+    mKnownModules.AppendElement(m);
+
+    if (aModule->mCIDs) {
+        const mozilla::Module::CIDEntry* entry;
+        for (entry = aModule->mCIDs; entry->cid; ++entry)
+            RegisterCIDEntry(entry, m);
+    }
+
+    if (aModule->mContractIDs) {
+        const mozilla::Module::ContractIDEntry* entry;
+        for (entry = aModule->mContractIDs; entry->contractid; ++entry)
+            RegisterContractID(entry);
+        NS_ASSERTION(!entry->cid, "Incorrectly terminated contract list");
+    }
+            
+    if (aModule->mCategoryEntries) {
+        const mozilla::Module::CategoryEntry* entry;
+        for (entry = aModule->mCategoryEntries; entry->category; ++entry)
+            nsCategoryManager::GetSingleton()->
+                AddCategoryEntry(entry->category,
+                                 entry->entry,
+                                 entry->value);
+    }
+};
+
+void
+nsComponentManagerImpl::RegisterCIDEntry(const mozilla::Module::CIDEntry* aEntry,
+                                         KnownModule* aModule)
+{
+    PR_ASSERT_CURRENT_THREAD_IN_MONITOR(mMon);
+
+    nsFactoryEntry* f = mFactories.Get(*aEntry->cid);
+    if (f) {
+        NS_ERROR("Re-registering a CID?");
+        // XXX REPORT ERROR, we don't override CIDs
+        return;
+    }
+
+    f = new nsFactoryEntry(aEntry, aModule);
+    mFactories.Put(*aEntry->cid, f);
+}
+
+void
+nsComponentManagerImpl::RegisterContractID(const mozilla::Module::ContractIDEntry* aEntry)
+{
+    PR_ASSERT_CURRENT_THREAD_IN_MONITOR(mMon);
+
+    nsFactoryEntry* f = mFactories.Get(*aEntry->cid);
+    if (!f) {
+        NS_ERROR("No CID found when attempting to map contract ID");
+        // XXX REPORT ERROR, CID isn't registered
+        return;
+    }
+
+    mContractIDs.Put(nsDependentCString(aEntry->contractid), f);
+}
+
+void
+nsComponentManagerImpl::RegisterLocation(nsILocalFile* aLocation)
+{
+    PRBool directory = PR_FALSE;
+    aLocation->IsDirectory(&directory);
+    if (directory)
+        RegisterDirectory(aLocation);
+    else
+        RegisterFile(aLocation);
+}
+
+void
+nsComponentManagerImpl::RegisterDirectory(nsILocalFile* aDirectory)
+{
+    nsCOMPtr<nsISimpleEnumerator> entries;
+    aDirectory->GetDirectoryEntries(getter_AddRefs(entries));
+    if (!entries)
+        return;
+
+    PRBool more;
+    while (NS_SUCCEEDED(entries->HasMoreElements(&more)) && more) {
+        nsCOMPtr<nsISupports> supp;
+        entries->GetNext(getter_AddRefs(supp));
+        nsCOMPtr<nsILocalFile> f = do_QueryInterface(supp);
+        if (!f)
+            continue;
+
+        RegisterFile(f);
+    }
+}
+
+void
+nsComponentManagerImpl::RegisterFile(nsILocalFile* aFile)
+{
+    nsCString extension;
+    aFile->GetNativePath(extension);
+
+    PRInt32 dotPos = extension.RFindChar('.');
+    if (kNotFound == dotPos)
+        return;
+
+    extension.Cut(0, dotPos + 1);
+    if (extension.LowerCaseEqualsLiteral(NAKED_DLL_SUFFIX)) {
+        const mozilla::Module* m = mNativeModuleLoader.LoadModule(aFile);
+        if (!m)
+            return;
+        RegisterModule(m, aFile);
+    }
+    else if (extension.EqualsLiteral("xpt")) {
+        xptiInterfaceInfoManager::GetSingleton()
+            ->RegisterFile(aFile,
+                           xptiInterfaceInfoManager::XPT);
+    }
+    else if (extension.EqualsLiteral("jar")) {
+        xptiInterfaceInfoManager::GetSingleton()
+            ->RegisterFile(aFile,
+                           xptiInterfaceInfoManager::ZIP);
+    }
+}
+
+bool
+nsComponentManagerImpl::KnownModule::Load()
+{
+    if (mFailed)
+        return false;
+    if (!mModule) {
+        mModule = mLoader->LoadModule(mFile);
+        if (!mModule) {
+            mFailed = true;
+            return false;
+        }
+    }
+    if (!mLoaded) {
+        if (mModule->loaded) {
+            nsresult rv = mModule->loaded();
+            if (NS_FAILED(rv)) {
+                mFailed = true;
+                return rv;
+            }
+        }
+        mLoaded = true;
+    }
+    return true;
+}
+
 nsresult nsComponentManagerImpl::Shutdown(void)
 {
     NS_TIME_FUNCTION;
 
-    PR_ASSERT(mShuttingDown == NS_SHUTDOWN_NEVERHAPPENED);
-    if (mShuttingDown != NS_SHUTDOWN_NEVERHAPPENED)
-        return NS_ERROR_FAILURE;
+    PR_ASSERT(NORMAL == mStatus);
 
-    mShuttingDown = NS_SHUTDOWN_INPROGRESS;
+    mStatus = SHUTDOWN_IN_PROGRESS;
 
     // Shutdown the component manager
     PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG, ("nsComponentManager: Beginning Shutdown."));
 
-    // Write out our component data file.
-    if (mRegistryDirty) {
-        nsresult rv = WritePersistentRegistry();
-        if (NS_FAILED(rv)) {
-            PR_LOG(nsComponentManagerLog, PR_LOG_ERROR, ("nsComponentManager: Could not write out persistent registry."));
-#ifdef DEBUG
-            printf("Could not write out persistent registry!\n");
-#endif
-        }
-    }
-
-    mAutoRegEntries.Clear();
-
     // Release all cached factories
-    if (mContractIDs.ops) {
-        PL_DHashTableFinish(&mContractIDs);
-        mContractIDs.ops = nsnull;
-    }
-    if (mFactories.ops) {
-        PL_DHashTableFinish(&mFactories);
-        mFactories.ops = nsnull;
-    }
+    mContractIDs.Clear();
+    mFactories.Clear(); // XXX release the objects, don't just clear
 
     mLoaderData.Clear();
 
-    // Free staticm modules
-    mStaticModuleLoader.ReleaseModules();
-
     // Unload libraries
     mNativeModuleLoader.UnloadLibraries();
 
     // delete arena for strings and small objects
     PL_FinishArenaPool(&mArena);
 
-    mComponentsDir = 0;
-
-    mCategoryManager = 0;
-
-    mShuttingDown = NS_SHUTDOWN_COMPLETE;
+    mStatus = SHUTDOWN_COMPLETE;
 
     PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG, ("nsComponentManager: Shutdown complete."));
 
     return NS_OK;
 }
 
 nsComponentManagerImpl::~nsComponentManagerImpl()
 {
     PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG, ("nsComponentManager: Beginning destruction."));
 
-    if (mShuttingDown != NS_SHUTDOWN_COMPLETE)
+    if (SHUTDOWN_COMPLETE != mStatus)
         Shutdown();
 
     if (mMon) {
         nsAutoMonitor::DestroyMonitor(mMon);
     }
     PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG, ("nsComponentManager: Destroyed."));
 }
 
-NS_IMPL_THREADSAFE_ISUPPORTS7(nsComponentManagerImpl,
+NS_IMPL_THREADSAFE_ISUPPORTS5(nsComponentManagerImpl,
                               nsIComponentManager,
                               nsIServiceManager,
+                              nsIComponentRegistrar,
                               nsISupportsWeakReference,
-                              nsIInterfaceRequestor,
-                              nsIComponentRegistrar,
-                              nsIServiceManagerObsolete,
-                              nsIComponentManagerObsolete)
+                              nsIInterfaceRequestor)
 
 
 nsresult
 nsComponentManagerImpl::GetInterface(const nsIID & uuid, void **result)
 {
     NS_WARNING("This isn't supported");
     // fall through to QI as anything QIable is a superset of what can be
     // got via the GetInterface()
     return  QueryInterface(uuid, result);
 }
 
-////////////////////////////////////////////////////////////////////////////////
-// nsComponentManagerImpl: Platform methods
-////////////////////////////////////////////////////////////////////////////////
-
-#define PERSISTENT_REGISTRY_VERSION_MINOR 5
-#define PERSISTENT_REGISTRY_VERSION_MAJOR 0
-
-static
-PRBool ReadSectionHeader(nsManifestLineReader& reader, const char *token)
-{
-    while (1)
-    {
-        if (*reader.LinePtr() == '[')
-        {
-            char* p = reader.LinePtr() + (reader.LineLength() - 1);
-            if (*p != ']')
-                break;
-            *p = 0;
-
-            char* values[1];
-            int lengths[1];
-            if (2 != reader.ParseLine(values, lengths, 1))
-                break;
-
-            // ignore the leading '['
-            if (0 != PL_strcmp(values[0]+1, token))
-                break;
-
-            return PR_TRUE;
-        }
-
-        if (!reader.NextLine())
-            break;
-    }
-    return PR_FALSE;
-}
-
-nsresult
-nsComponentManagerImpl::ReadPersistentRegistry()
-{
-    NS_TIME_FUNCTION;
-
-    NS_ASSERTION(mComponentsDir, "nsComponentManager not initialized.");
-
-    nsresult rv;
-
-    // populate Category Manager. need to get this early so that we don't get
-    // skipped by 'goto out'
-    mCategoryManager = do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
-    if (NS_FAILED(rv))
-        return rv;
-
-    nsAutoMonitor mon(mMon);
-    nsManifestLineReader reader;
-
-    PRFileDesc* fd = nsnull;
-
-    // Set From Init
-    if (!mRegistryFile) {
-        return NS_ERROR_FILE_NOT_FOUND;
-    }
-
-    nsCOMPtr<nsIFile> file;
-    mRegistryFile->Clone(getter_AddRefs(file));
-    if (!file)
-        return NS_ERROR_OUT_OF_MEMORY;
-
-    nsCOMPtr<nsILocalFile> localFile(do_QueryInterface(file));
-
-    rv = localFile->OpenNSPRFileDesc(PR_RDONLY, 0444, &fd);
-    if (NS_FAILED(rv))
-        return rv;
-
-    PRInt64 fileSize;
-    rv = localFile->GetFileSize(&fileSize);
-    if (NS_FAILED(rv))
-    {
-        PR_Close(fd);
-        return rv;
-    }
-
-    PRInt32 flen = nsInt64(fileSize);
-    if (flen == 0)
-    {
-        PR_Close(fd);
-        NS_WARNING("Persistent Registry Empty!");
-        return NS_OK; // ERROR CONDITION
-    }
-
-    char* registry = new char[flen+1];
-    if (!registry)
-        goto out;
-
-    if (flen > PR_Read(fd, registry, flen))
-    {
-        rv = NS_ERROR_FAILURE;
-        goto out;
-    }
-    registry[flen] = '\0';
-
-    reader.Init(registry, flen);
-
-    if (ReadSectionHeader(reader, "HEADER"))
-        goto out;
-
-    if (!reader.NextLine())
-        goto out;
-
-    char* values[6];
-    int lengths[6];
-
-    // VersionLiteral,major,minor
-    if (3 != reader.ParseLine(values, lengths, 3))
-        goto out;
-
-    // VersionLiteral
-    if (!nsDependentCString(values[0], lengths[0]).EqualsLiteral("Version"))
-        goto out;
-
-    // major
-    if (PERSISTENT_REGISTRY_VERSION_MAJOR != atoi(values[1]))
-        goto out;
-
-    // minor
-    if (PERSISTENT_REGISTRY_VERSION_MINOR != atoi(values[2]))
-        goto out;
-
-    if (ReadSectionHeader(reader, "COMPONENTS"))
-        goto out;
-
-    while (1)
-    {
-        if (!reader.NextLine())
-            break;
-
-        //name,last_modification_date[,optionaldata]
-        int parts = reader.ParseLine(values, lengths, 3);
-        if (2 != parts)
-            break;
-
-        PRInt64 a = nsCRT::atoll(values[1]);
-
-        nsCOMPtr<nsILocalFile> lf;
-        rv = FileForRegistryLocation(nsDependentCString(values[0], lengths[0]),
-                                     getter_AddRefs(lf));
-        if (NS_FAILED(rv))
-            continue;
-
-        nsCOMPtr<nsIHashable> lfhash(do_QueryInterface(lf));
-        if (!lf) {
-            NS_ERROR("nsLocalFile does not implement nsIHashable");
-            continue;
-        }
-
-        mAutoRegEntries.Put(lfhash, a);
-    }
-
-    if (ReadSectionHeader(reader, "CLASSIDS"))
-        goto out;
-
-    while (1)
-    {
-        if (!reader.NextLine())
-            break;
-
-        // cid,contract_id,type,class_name,inproc_server
-        if (5 != reader.ParseLine(values, lengths, 5))
-            break;
-
-        nsCID aClass;
-        if (!aClass.Parse(values[0]))
-            continue;
-
-        LoaderType loadertype = AddLoaderType(values[2]);
-        if (loadertype == NS_LOADER_TYPE_INVALID) {
-            NS_ERROR("Could not create LoaderType");
-            continue;
-        }
-
-        void *mem;
-        PL_ARENA_ALLOCATE(mem, &mArena, sizeof(nsFactoryEntry));
-        if (!mem) {
-            rv = NS_ERROR_OUT_OF_MEMORY;
-            goto out;
-        }
-
-        nsFactoryEntry *entry =
-            new (mem) nsFactoryEntry(aClass, loadertype, values[4]);
-
-        if (!entry->mLocationKey) {
-            rv = NS_ERROR_OUT_OF_MEMORY;
-            goto out;
-        }
-
-        nsFactoryTableEntry* factoryTableEntry =
-            static_cast<nsFactoryTableEntry*>
-                       (PL_DHashTableOperate(&mFactories,
-                                                &aClass,
-                                                PL_DHASH_ADD));
-
-        if (!factoryTableEntry) {
-            rv = NS_ERROR_OUT_OF_MEMORY;
-            goto out;
-        }
-
-        factoryTableEntry->mFactoryEntry = entry;
-    }
-
-    if (ReadSectionHeader(reader, "CONTRACTIDS"))
-        goto out;
-
-    while (1)
-    {
-        if (!reader.NextLine())
-            break;
-
-        //contractID,cid
-        if (2 != reader.ParseLine(values, lengths, 2))
-            break;
-
-        nsCID aClass;
-        if (!aClass.Parse(values[1]))
-            continue;
-
-
-        //need to find the location for this cid.
-        nsFactoryEntry *cidEntry = GetFactoryEntry(aClass);
-        if (!cidEntry || cidEntry->mLoaderType == NS_LOADER_TYPE_INVALID)
-            continue; //what should we really do?
-
-        nsContractIDTableEntry* contractIDTableEntry =
-                static_cast<nsContractIDTableEntry*>
-                           (PL_DHashTableOperate(&mContractIDs,
-                                                    values[0],
-                                                    PL_DHASH_ADD));
-        if (!contractIDTableEntry) {
-            continue;
-        }
-
-        if (!contractIDTableEntry->mContractID) {
-            char *contractID = ArenaStrndup(values[0], lengths[0], &mArena);
-            if (!contractID) {
-                rv = NS_ERROR_OUT_OF_MEMORY;
-                goto out; 
-            }
-            contractIDTableEntry->mContractID = contractID;
-            contractIDTableEntry->mContractIDLen = lengths[0];
-        }
-
-        contractIDTableEntry->mFactoryEntry = cidEntry;
-    }
-
-    if (ReadSectionHeader(reader, "CATEGORIES"))
-        goto out;
-
-    mCategoryManager->SuppressNotifications(PR_TRUE);
-
-    while (1)
-    {
-        if (!reader.NextLine())
-            break;
-
-        //type,name,value
-        if (3 != reader.ParseLine(values, lengths, 3))
-            break;
-
-        mCategoryManager->AddCategoryEntry(values[0],
-                                           values[1],
-                                           values[2],
-                                           PR_TRUE,
-                                           PR_TRUE,
-                                           0);
-    }
-
-    mCategoryManager->SuppressNotifications(PR_FALSE);
-
-    mRegistryDirty = PR_FALSE;
-out:
-    if (fd)
-        PR_Close(fd);
-
-    if (registry)
-        delete [] registry;
-
-    return rv;
-}
-
-struct PersistentWriterArgs
-{
-    PRFileDesc *mFD;
-    nsTArray<nsLoaderdata> *mLoaderData;
-};
-
-static PLDHashOperator
-ContractIDWriter(PLDHashTable *table,
-                 PLDHashEntryHdr *hdr,
-                 PRUint32 number,
-                 void *arg)
-{
-    char *contractID   = ((nsContractIDTableEntry*)hdr)->mContractID;
-    nsFactoryEntry *factoryEntry = ((nsContractIDTableEntry*)hdr)->mFactoryEntry;
-
-    // for now, we only save out the top most parent.
-    while (factoryEntry->mParent)
-        factoryEntry = factoryEntry->mParent;
-
-    if (factoryEntry->mLoaderType == NS_LOADER_TYPE_INVALID)
-        return PL_DHASH_NEXT;
-
-    PRFileDesc* fd = ((PersistentWriterArgs*)arg)->mFD;
-
-    char cidString[UID_STRING_LENGTH];
-    GetIDString(factoryEntry->mCid, cidString);
-    PR_fprintf(fd, "%s,%s\n", contractID, cidString); // what if this fails?
-    return PL_DHASH_NEXT;
-}
-
-static PLDHashOperator
-ClassIDWriter(PLDHashTable *table,
-              PLDHashEntryHdr *hdr,
-              PRUint32 number,
-              void *arg)
-{
-    nsFactoryEntry *factoryEntry = ((nsFactoryTableEntry*)hdr)->mFactoryEntry;
-    PRFileDesc* fd = ((PersistentWriterArgs*)arg)->mFD;
-    nsTArray<nsLoaderdata> *loaderData = ((PersistentWriterArgs*)arg)->mLoaderData;
-
-    // for now, we only save out the top most parent.
-    while (factoryEntry->mParent)
-        factoryEntry = factoryEntry->mParent;
-
-    if (factoryEntry->mLoaderType == NS_LOADER_TYPE_INVALID) {
-        return PL_DHASH_NEXT;
-    }
-
-    char cidString[UID_STRING_LENGTH];
-    GetIDString(factoryEntry->mCid, cidString);
-
-    char *contractID = nsnull, *className = nsnull;
-
-    nsCOMPtr<nsIClassInfo> classInfo = do_QueryInterface(factoryEntry->mFactory);
-    if (classInfo)
-    {
-        classInfo->GetContractID(&contractID);
-        classInfo->GetClassDescription(&className);
-    }
-
-    const char *loaderName;
-    switch (factoryEntry->mLoaderType) {
-    case NS_LOADER_TYPE_STATIC:
-        loaderName = staticComponentType;
-        break;
-
-    case NS_LOADER_TYPE_NATIVE:
-        loaderName = nativeComponentType;
-        break;
-
-    default:
-        loaderName = loaderData->ElementAt(factoryEntry->mLoaderType).type.get();
-    }
-
-    const char* location = factoryEntry->mLocationKey;
-
-    // cid,contract_id,type,class_name,inproc_server
-    PR_fprintf(fd,
-               "%s,%s,%s,%s,%s\n",
-               cidString,
-               (contractID ? contractID : ""),
-               (loaderName ? loaderName : ""),
-               (className  ? className  : ""),
-               (location   ? location   : ""));
-
-    if (contractID)
-        NS_Free(contractID);
-    if (className)
-        NS_Free(className);
-
-    return PL_DHASH_NEXT;
-}
-
-static PLDHashOperator
-AutoRegEntryWriter(nsIHashable *aKey, PRInt64 &aTimestamp, void* aClosure)
-{
-    PRFileDesc* fd = (PRFileDesc*) aClosure;
-
-    nsCOMPtr<nsILocalFile> lf(do_QueryInterface(aKey));
-
-    nsCAutoString location;
-    nsComponentManagerImpl::gComponentManager->
-        RegistryLocationForFile(lf, location);
-
-    PR_fprintf(fd, "%s,%lld\n", location.get(), (PRInt64) aTimestamp);
-
-    return PL_DHASH_NEXT;
-}
-
-nsresult
-nsComponentManagerImpl::WritePersistentRegistry()
-{
-    if (!mRegistryFile)
-        return NS_ERROR_FAILURE;  // this should have been set by Init().
-
-    NS_TIME_FUNCTION;
-
-    nsCOMPtr<nsIFile> file;
-    mRegistryFile->Clone(getter_AddRefs(file));
-    if (!file)
-        return NS_ERROR_OUT_OF_MEMORY;
-
-    nsCOMPtr<nsILocalFile> localFile(do_QueryInterface(file));
-
-    nsCAutoString originalLeafName;
-    localFile->GetNativeLeafName(originalLeafName);
-
-    nsCAutoString leafName;
-    leafName.Assign(originalLeafName + NS_LITERAL_CSTRING(".tmp"));
-
-    localFile->SetNativeLeafName(leafName);
-
-    PRFileDesc* fd = nsnull;
-    // Owner and group can setup components, everyone else should be able to see but not poison them.
-    nsresult rv = localFile->OpenNSPRFileDesc(PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE, 0664, &fd);
-    if (NS_FAILED(rv))
-        return rv;
-
-    if (PR_fprintf(fd, "Generated File. Do not edit.\n") == (PRUint32) -1) {
-        rv = NS_ERROR_UNEXPECTED;
-        goto out;
-    }
-
-    if (PR_fprintf(fd, "\n[HEADER]\nVersion,%d,%d\n",
-                   PERSISTENT_REGISTRY_VERSION_MAJOR,
-                   PERSISTENT_REGISTRY_VERSION_MINOR) == (PRUint32) -1) {
-        rv = NS_ERROR_UNEXPECTED;
-        goto out;
-    }
-
-    if (PR_fprintf(fd, "\n[COMPONENTS]\n") == (PRUint32) -1) {
-        rv = NS_ERROR_UNEXPECTED;
-        goto out;
-    }
-
-    mAutoRegEntries.Enumerate(AutoRegEntryWriter, (void*)fd);
-
-    PersistentWriterArgs args;
-    args.mFD = fd;
-    args.mLoaderData = &mLoaderData;
-
-    if (PR_fprintf(fd, "\n[CLASSIDS]\n") == (PRUint32) -1) {
-        rv = NS_ERROR_UNEXPECTED;
-        goto out;
-    }
-
-
-    PL_DHashTableEnumerate(&mFactories, ClassIDWriter, (void*)&args);
-
-    if (PR_fprintf(fd, "\n[CONTRACTIDS]\n") == (PRUint32) -1) {
-        rv = NS_ERROR_UNEXPECTED;
-        goto out;
-    }
-
-
-    PL_DHashTableEnumerate(&mContractIDs, ContractIDWriter, (void*)&args);
-
-    if (PR_fprintf(fd, "\n[CATEGORIES]\n") == (PRUint32) -1) {
-        rv = NS_ERROR_UNEXPECTED;
-        goto out;
-    }
-
-    NS_ASSERTION(mCategoryManager, "nsComponentManager used initialized");
-
-    rv = mCategoryManager->WriteCategoryManagerToRegistry(fd);
-
-out:
-    PR_Close(fd);
-
-    // don't create the file is there was a problem????
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    if (!mRegistryFile)
-        return NS_ERROR_NOT_INITIALIZED;
-
-    PRBool exists;
-    if(NS_FAILED(mRegistryFile->Exists(&exists)))
-        return PR_FALSE;
-
-    if(exists && NS_FAILED(mRegistryFile->Remove(PR_FALSE)))
-        return PR_FALSE;
-
-    nsCOMPtr<nsIFile> parent;
-    mRegistryFile->GetParent(getter_AddRefs(parent));
-
-    rv = localFile->MoveToNative(parent, originalLeafName);
-    mRegistryDirty = PR_FALSE;
-
-    return rv;
-}
-
-
-////////////////////////////////////////////////////////////////////////////////
-// Hash Functions
-////////////////////////////////////////////////////////////////////////////////
-nsresult
-nsComponentManagerImpl::HashContractID(const char *aContractID,
-                                       PRUint32 aContractIDLen,
-                                       nsFactoryEntry *fe)
-{
-    if(!aContractID || !aContractIDLen)
-        return NS_ERROR_NULL_POINTER;
-
-    NS_ABORT_IF_FALSE(PR_InMonitor(mMon), "called from outside mMon");
-
-    nsContractIDTableEntry* contractIDTableEntry =
-        static_cast<nsContractIDTableEntry*>
-                   (PL_DHashTableOperate(&mContractIDs, aContractID,
-                                            PL_DHASH_ADD));
-    if (!contractIDTableEntry)
-        return NS_ERROR_OUT_OF_MEMORY;
-
-    NS_ASSERTION(!contractIDTableEntry->mContractID || !strcmp(contractIDTableEntry->mContractID, aContractID), "contractid conflict");
-
-    if (!contractIDTableEntry->mContractID) {
-        char *contractID = ArenaStrndup(aContractID, aContractIDLen, &mArena);
-        if (!contractID)
-            return NS_ERROR_OUT_OF_MEMORY;
-
-        contractIDTableEntry->mContractID = contractID;
-        contractIDTableEntry->mContractIDLen = aContractIDLen;
-    }
-
-    contractIDTableEntry->mFactoryEntry = fe;
-
-    return NS_OK;
-}
-
 nsFactoryEntry *
 nsComponentManagerImpl::GetFactoryEntry(const char *aContractID,
                                         PRUint32 aContractIDLen)
 {
-    nsFactoryEntry *fe = nsnull;
-    {
-        nsAutoMonitor mon(mMon);
-
-        nsContractIDTableEntry* contractIDTableEntry =
-            static_cast<nsContractIDTableEntry*>
-                       (PL_DHashTableOperate(&mContractIDs, aContractID,
-                                                PL_DHASH_LOOKUP));
-
-
-        if (PL_DHASH_ENTRY_IS_BUSY(contractIDTableEntry)) {
-            fe = contractIDTableEntry->mFactoryEntry;
-        }
-    }   //exit monitor
-
-    return fe;
+    nsAutoMonitor mon(mMon);
+    return mContractIDs.Get(nsDependentCString(aContractID, aContractIDLen));
 }
 
 
 nsFactoryEntry *
 nsComponentManagerImpl::GetFactoryEntry(const nsCID &aClass)
 {
-    nsFactoryEntry *entry = nsnull;
-    {
-        nsAutoMonitor mon(mMon);
-
-        nsFactoryTableEntry* factoryTableEntry =
-            static_cast<nsFactoryTableEntry*>
-                       (PL_DHashTableOperate(&mFactories, &aClass,
-                                                PL_DHASH_LOOKUP));
-
-        if (PL_DHASH_ENTRY_IS_BUSY(factoryTableEntry)) {
-            entry = factoryTableEntry->mFactoryEntry;
-        }
-    }   // exit monitor
-
-    return entry;
+    nsAutoMonitor mon(mMon);
+    return mFactories.Get(aClass);
 }
 
+already_AddRefed<nsIFactory>
+nsComponentManagerImpl::FindFactory(const nsCID& aClass)
+{
+    nsFactoryEntry* e = GetFactoryEntry(aClass);
+    if (!e)
+        return NULL;
 
-/**
- * FindFactory()
- *
- * Given a classID, this finds the factory for this CID by first searching the
- * local CID<->factory mapping. Next it searches for a Dll that implements
- * this classID and calls LoadFactory() to create the factory.
- *
- * Again, no attempt is made at storing the factory.
- */
-NS_IMETHODIMP
-nsComponentManagerImpl::FindFactory(const nsCID &aClass,
-                                    nsIFactory **aFactory)
-{
-    PR_ASSERT(aFactory != nsnull);
-
-    nsFactoryEntry *entry = GetFactoryEntry(aClass);
-
-    if (!entry)
-        return NS_ERROR_FACTORY_NOT_REGISTERED;
-
-    return entry->GetFactory(aFactory);
+    return e->GetFactory();
 }
 
-
-nsresult
+already_AddRefed<nsIFactory>
 nsComponentManagerImpl::FindFactory(const char *contractID,
-                                    PRUint32 aContractIDLen,
-                                    nsIFactory **aFactory)
+                                    PRUint32 aContractIDLen)
 {
-    PR_ASSERT(aFactory != nsnull);
-
     nsFactoryEntry *entry = GetFactoryEntry(contractID, aContractIDLen);
+    if (!entry)
+        return NULL;
 
-    if (!entry)
-        return NS_ERROR_FACTORY_NOT_REGISTERED;
-
-    return entry->GetFactory(aFactory);
+    return entry->GetFactory();
 }
 
 /**
  * GetClassObject()
  *
  * Given a classID, this finds the singleton ClassObject that implements the CID.
  * Returns an interface of type aIID off the singleton classobject.
  */
 NS_IMETHODIMP
 nsComponentManagerImpl::GetClassObject(const nsCID &aClass, const nsIID &aIID,
                                        void **aResult)
 {
     nsresult rv;
 
-    nsCOMPtr<nsIFactory> factory;
-
 #ifdef PR_LOGGING
     if (PR_LOG_TEST(nsComponentManagerLog, PR_LOG_DEBUG))
     {
         char *buf = aClass.ToString();
         PR_LogPrint("nsComponentManager: GetClassObject(%s)", buf);
         if (buf)
             NS_Free(buf);
     }
 #endif
 
     PR_ASSERT(aResult != nsnull);
 
-    rv = FindFactory(aClass, getter_AddRefs(factory));
-    if (NS_FAILED(rv)) return rv;
+    nsCOMPtr<nsIFactory> factory = FindFactory(aClass);
+    if (!factory)
+        return NS_ERROR_FACTORY_NOT_REGISTERED;
 
     rv = factory->QueryInterface(aIID, aResult);
 
     PR_LOG(nsComponentManagerLog, PR_LOG_WARNING,
            ("\t\tGetClassObject() %s", NS_SUCCEEDED(rv) ? "succeeded" : "FAILED"));
 
     return rv;
 }
@@ -1473,101 +675,37 @@ nsComponentManagerImpl::GetClassObjectBy
                                                    const nsIID &aIID,
                                                    void **aResult)
 {
     NS_ENSURE_ARG_POINTER(aResult);
     NS_ENSURE_ARG_POINTER(contractID);
 
     nsresult rv;
 
-    nsCOMPtr<nsIFactory> factory;
 
 #ifdef PR_LOGGING
     if (PR_LOG_TEST(nsComponentManagerLog, PR_LOG_DEBUG))
     {
         PR_LogPrint("nsComponentManager: GetClassObject(%s)", contractID);
     }
 #endif
 
-    rv = FindFactory(contractID, strlen(contractID), getter_AddRefs(factory));
-    if (NS_FAILED(rv)) return rv;
+    nsCOMPtr<nsIFactory> factory = FindFactory(contractID, strlen(contractID));
+    if (!factory)
+        return NS_ERROR_FACTORY_NOT_REGISTERED;
 
     rv = factory->QueryInterface(aIID, aResult);
 
     PR_LOG(nsComponentManagerLog, PR_LOG_WARNING,
            ("\t\tGetClassObject() %s", NS_SUCCEEDED(rv) ? "succeeded" : "FAILED"));
 
     return rv;
 }
 
 /**
- * ContractIDToClassID()
- *
- * Mapping function from a ContractID to a classID. Directly talks to the registry.
- *
- */
-NS_IMETHODIMP
-nsComponentManagerImpl::ContractIDToClassID(const char *aContractID, nsCID *aClass)
-{
-    NS_ENSURE_ARG_POINTER(aContractID);
-    NS_ENSURE_ARG_POINTER(aClass);
-
-    nsresult rv = NS_ERROR_FACTORY_NOT_REGISTERED;
-
-    nsFactoryEntry *fe = GetFactoryEntry(aContractID, strlen(aContractID));
-    if (fe) {
-        *aClass = fe->mCid;
-        rv = NS_OK;
-    }
-#ifdef PR_LOGGING
-    if (PR_LOG_TEST(nsComponentManagerLog, PR_LOG_WARNING)) {
-        char *buf = 0;
-        if (NS_SUCCEEDED(rv))
-            buf = aClass->ToString();
-        PR_LOG(nsComponentManagerLog, PR_LOG_WARNING,
-               ("nsComponentManager: ContractIDToClassID(%s)->%s", aContractID,
-                NS_SUCCEEDED(rv) ? buf : "[FAILED]"));
-        if (buf)
-            NS_Free(buf);
-    }
-#endif
-    return rv;
-}
-
-/**
- * CLSIDToContractID()
- *
- * Translates a classID to a {ContractID, Class Name}. Does direct registry
- * access to do the translation.
- *
- * NOTE: Since this isn't heavily used, we aren't caching this.
- */
-NS_IMETHODIMP
-nsComponentManagerImpl::CLSIDToContractID(const nsCID &aClass,
-                                          char* *aClassName,
-                                          char* *aContractID)
-{
-    NS_WARNING("Need to implement CLSIDToContractID");
-
-    nsresult rv = NS_ERROR_FACTORY_NOT_REGISTERED;
-#ifdef PR_LOGGING
-    if (PR_LOG_TEST(nsComponentManagerLog, PR_LOG_WARNING))
-    {
-        char *buf = aClass.ToString();
-        PR_LOG(nsComponentManagerLog, PR_LOG_WARNING,
-               ("nsComponentManager: CLSIDToContractID(%s)->%s", buf,
-                NS_SUCCEEDED(rv) ? *aContractID : "[FAILED]"));
-        if (buf)
-            NS_Free(buf);
-    }
-#endif
-    return rv;
-}
-
-/**
  * CreateInstance()
  *
  * Create an instance of an object that implements an interface and belongs
  * to the implementation aClass using the factory. The factory is immediately
  * released and not held onto for any longer.
  */
 NS_IMETHODIMP
 nsComponentManagerImpl::CreateInstance(const nsCID &aClass,
@@ -1609,27 +747,25 @@ nsComponentManagerImpl::CreateInstance(c
         cid.Adopt(aClass.ToString());
         nsCAutoString message;
         message = NS_LITERAL_CSTRING("You are calling CreateInstance \"") +
                   cid + NS_LITERAL_CSTRING("\" when a service for this CID already exists!");
         NS_ERROR(message.get());
     }
 #endif
 
-    nsIFactory *factory = nsnull;
-    nsresult rv = entry->GetFactory(&factory);
-
-    if (NS_SUCCEEDED(rv))
+    nsresult rv;
+    nsCOMPtr<nsIFactory> factory = entry->GetFactory();
+    if (factory)
     {
         rv = factory->CreateInstance(aDelegate, aIID, aResult);
         if (NS_SUCCEEDED(rv) && !*aResult) {
             NS_ERROR("Factory did not return an object but returned success!");
             rv = NS_ERROR_SERVICE_NOT_FOUND;
         }
-        NS_RELEASE(factory);
     }
     else
     {
         // Translate error values
         rv = NS_ERROR_FACTORY_NOT_REGISTERED;
     }
 
 #ifdef PR_LOGGING
@@ -1698,94 +834,59 @@ nsComponentManagerImpl::CreateInstanceBy
           NS_LITERAL_CSTRING("You are calling CreateInstance \"") +
           nsDependentCString(aContractID) +
           NS_LITERAL_CSTRING("\" when a service for this CID already exists! "
             "Add it to abusedContracts to track down the service consumer.");
         NS_ERROR(message.get());
     }
 #endif
 
-    nsIFactory *factory = nsnull;
-    nsresult rv = entry->GetFactory(&factory);
-
-    if (NS_SUCCEEDED(rv))
+    nsresult rv;
+    nsCOMPtr<nsIFactory> factory = entry->GetFactory();
+    if (factory)
     {
 
         rv = factory->CreateInstance(aDelegate, aIID, aResult);
         if (NS_SUCCEEDED(rv) && !*aResult) {
             NS_ERROR("Factory did not return an object but returned success!");
             rv = NS_ERROR_SERVICE_NOT_FOUND;
         }
-        NS_RELEASE(factory);
     }
     else
     {
         // Translate error values
         rv = NS_ERROR_FACTORY_NOT_REGISTERED;
     }
 
     PR_LOG(nsComponentManagerLog, PR_LOG_WARNING,
            ("nsComponentManager: CreateInstanceByContractID(%s) %s", aContractID,
             NS_SUCCEEDED(rv) ? "succeeded" : "FAILED"));
 
     return rv;
 }
 
-// Service Manager Impl
-static
-PLDHashOperator
-FreeServiceFactoryEntryEnumerate(PLDHashTable *aTable,
-                                 PLDHashEntryHdr *aHdr,
-                                 PRUint32 aNumber,
-                                 void *aData)
+static PLDHashOperator
+FreeFactoryEntries(const nsID& aCID,
+                   nsFactoryEntry* aEntry,
+                   void* arg)
 {
-    nsFactoryTableEntry* entry = static_cast<nsFactoryTableEntry*>(aHdr);
-
-    if (!entry->mFactoryEntry)
-        return PL_DHASH_NEXT;
-
-    nsFactoryEntry* factoryEntry = entry->mFactoryEntry;
-    factoryEntry->mServiceObject = nsnull;
-    return PL_DHASH_NEXT;
-}
-
-static
-PLDHashOperator
-FreeServiceContractIDEntryEnumerate(PLDHashTable *aTable,
-                                    PLDHashEntryHdr *aHdr,
-                                    PRUint32 aNumber,
-                                    void *aData)
-{
-    nsContractIDTableEntry* entry = static_cast<nsContractIDTableEntry*>(aHdr);
-
-    if (!entry->mFactoryEntry)
-        return PL_DHASH_NEXT;
-
-    nsFactoryEntry* factoryEntry = entry->mFactoryEntry;
-    factoryEntry->mServiceObject = nsnull;
+    aEntry->mFactory = NULL;
+    aEntry->mServiceObject = NULL;
     return PL_DHASH_NEXT;
 }
 
 nsresult
 nsComponentManagerImpl::FreeServices()
 {
     NS_ASSERTION(gXPCOMShuttingDown, "Must be shutting down in order to free all services");
 
     if (!gXPCOMShuttingDown)
         return NS_ERROR_FAILURE;
 
-    if (mContractIDs.ops) {
-        PL_DHashTableEnumerate(&mContractIDs, FreeServiceContractIDEntryEnumerate, nsnull);
-    }
-
-
-    if (mFactories.ops) {
-        PL_DHashTableEnumerate(&mFactories, FreeServiceFactoryEntryEnumerate, nsnull);
-    }
-
+    mFactories.EnumerateRead(FreeFactoryEntries, NULL);
     return NS_OK;
 }
 
 // This should only ever be called within the monitor!
 nsComponentManagerImpl::PendingServiceInfo*
 nsComponentManagerImpl::AddPendingService(const nsCID& aServiceCID,
                                           PRThread* aThread)
 {
@@ -1842,27 +943,21 @@ nsComponentManagerImpl::GetService(const
         fprintf(stderr, "Getting service on shutdown. Denied.\n"
                "         CID: %s\n         IID: %s\n", cid.get(), iid.get());
 #endif /* SHOW_DENIED_ON_SHUTDOWN */
         return NS_ERROR_UNEXPECTED;
     }
 
     nsAutoMonitor mon(mMon);
 
-    nsFactoryEntry* entry = nsnull;
-    nsFactoryTableEntry* factoryTableEntry =
-        static_cast<nsFactoryTableEntry*>
-                   (PL_DHashTableOperate(&mFactories, &aClass,
-                                            PL_DHASH_LOOKUP));
+    nsFactoryEntry* entry = mFactories.Get(aClass);
+    if (!entry)
+        return NS_ERROR_FACTORY_NOT_REGISTERED;
 
-    if (PL_DHASH_ENTRY_IS_BUSY(factoryTableEntry)) {
-        entry = factoryTableEntry->mFactoryEntry;
-    }
-
-    if (entry && entry->mServiceObject) {
+    if (entry->mServiceObject) {
         nsCOMPtr<nsISupports> supports = entry->mServiceObject;
         mon.Exit();
         return supports->QueryInterface(aIID, result);
     }
 
     // We only care about time when we create the service.
     COMPMGR_TIME_FUNCTION_CID(aClass);
 
@@ -1890,35 +985,22 @@ nsComponentManagerImpl::GetService(const
         // pending.
         if (!NS_ProcessNextEvent(currentThread, PR_FALSE)) {
             PR_Sleep(PR_INTERVAL_NO_WAIT);
         }
 
         mon.Enter();
     }
 
-    if (currentThread) {
-        // If we have a currentThread then we must have waited on another thread
-        // to create the service. Grab it now if that succeeded.
-        if (!entry) {
-            factoryTableEntry = static_cast<nsFactoryTableEntry*>
-                (PL_DHashTableOperate(&mFactories, &aClass, PL_DHASH_LOOKUP));
-
-            if (PL_DHASH_ENTRY_IS_BUSY(factoryTableEntry)) {
-                entry = factoryTableEntry->mFactoryEntry;
-            }
-        }
-
-        // It's still possible that the other thread failed to create the
-        // service so we're not guaranteed to have an entry or service yet.
-        if (entry && entry->mServiceObject) {
-            nsCOMPtr<nsISupports> supports = entry->mServiceObject;
-            mon.Exit();
-            return supports->QueryInterface(aIID, result);
-        }
+    // It's still possible that the other thread failed to create the
+    // service so we're not guaranteed to have an entry or service yet.
+    if (entry->mServiceObject) {
+        nsCOMPtr<nsISupports> supports = entry->mServiceObject;
+        mon.Exit();
+        return supports->QueryInterface(aIID, result);
     }
 
 #ifdef DEBUG
     PendingServiceInfo* newInfo =
 #endif
     AddPendingService(aClass, currentPRThread);
     NS_ASSERTION(newInfo, "Failed to add info to the array!");
 
@@ -1937,154 +1019,29 @@ nsComponentManagerImpl::GetService(const
     NS_ASSERTION(pendingPRThread == currentPRThread,
                  "Pending service array has been changed!");
 #endif
     RemovePendingService(aClass);
 
     if (NS_FAILED(rv))
         return rv;
 
-    if (!entry) { // second hash lookup for GetService
-        nsFactoryTableEntry* factoryTableEntry =
-            static_cast<nsFactoryTableEntry*>
-                       (PL_DHashTableOperate(&mFactories, &aClass,
-                                                PL_DHASH_LOOKUP));
-        if (PL_DHASH_ENTRY_IS_BUSY(factoryTableEntry)) {
-            entry = factoryTableEntry->mFactoryEntry;
-        }
-        NS_ASSERTION(entry, "we should have a factory entry since CI succeeded - we should not get here");
-        if (!entry) return NS_ERROR_FAILURE;
-    }
-
     NS_ASSERTION(!entry->mServiceObject, "Created two instances of a service!");
 
     entry->mServiceObject = service;
     *result = service.get();
     if (!*result) {
         NS_ERROR("Factory did not return an object but returned success!");
         return NS_ERROR_SERVICE_NOT_FOUND;
     }
     NS_ADDREF(static_cast<nsISupports*>((*result)));
     return rv;
 }
 
 NS_IMETHODIMP
-nsComponentManagerImpl::RegisterService(const nsCID& aClass, nsISupports* aService)
-{
-    CO