Bug 458300 - Merge nsINameSpaceManager and NameSpaceManagerImpl. r=jst
authorReuben Morais <reuben.morais@gmail.com>
Thu, 27 Feb 2014 20:04:46 -0300
changeset 171454 5837f5e79047a3f4c67c6c8586f91f47180f6ae8
parent 171453 2a3ff17ca99e0e4de3efd18bbcd6ee189fe5f1e3
child 171455 1b5ee8c5491ab694293b5c5cacefd118e8076884
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersjst
bugs458300
milestone30.0a1
Bug 458300 - Merge nsINameSpaceManager and NameSpaceManagerImpl. r=jst
accessible/src/generic/DocAccessible.cpp
accessible/src/windows/sdn/sdnAccessible.cpp
content/base/public/nsContentUtils.h
content/base/public/nsINameSpaceManager.h
content/base/src/nsContentUtils.cpp
content/base/src/nsNameSpaceManager.cpp
layout/build/nsLayoutModule.cpp
layout/build/nsLayoutStatics.cpp
layout/inspector/inDOMView.cpp
--- a/accessible/src/generic/DocAccessible.cpp
+++ b/accessible/src/generic/DocAccessible.cpp
@@ -390,18 +390,17 @@ DocAccessible::GetDocType(nsAString& aDo
 
   return NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
 DocAccessible::GetNameSpaceURIForID(int16_t aNameSpaceID, nsAString& aNameSpaceURI)
 {
   if (mDocumentNode) {
-    nsCOMPtr<nsINameSpaceManager> nameSpaceManager =
-        do_GetService(NS_NAMESPACEMANAGER_CONTRACTID);
+    nsNameSpaceManager* nameSpaceManager = nsNameSpaceManager::GetInstance();
     if (nameSpaceManager)
       return nameSpaceManager->GetNameSpaceURI(aNameSpaceID, aNameSpaceURI);
   }
   return NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
 DocAccessible::GetWindowHandle(void** aWindow)
--- a/accessible/src/windows/sdn/sdnAccessible.cpp
+++ b/accessible/src/windows/sdn/sdnAccessible.cpp
@@ -9,16 +9,17 @@
 
 #include "DocAccessibleWrap.h"
 
 #include "nsAttrName.h"
 #include "nsCoreUtils.h"
 #include "nsIAccessibleTypes.h"
 #include "nsIDOMHTMLElement.h"
 #include "nsIDOMCSSStyleDeclaration.h"
+#include "nsNameSpaceManager.h"
 #include "nsServiceManagerUtils.h"
 #include "nsWinUtils.h"
 
 #include "nsAutoPtr.h"
 
 #include "mozilla/dom/Element.h"
 
 using namespace mozilla;
@@ -171,18 +172,17 @@ sdnAccessible::get_attributesForNames(un
 
   if (IsDefunct())
     return CO_E_OBJNOTCONNECTED;
 
   if (!mNode->IsElement())
     return S_FALSE;
 
   nsCOMPtr<nsIDOMElement> domElement(do_QueryInterface(mNode));
-  nsCOMPtr<nsINameSpaceManager> nameSpaceManager =
-    do_GetService(NS_NAMESPACEMANAGER_CONTRACTID);
+  nsNameSpaceManager* nameSpaceManager = nsNameSpaceManager::GetInstance();
 
   int32_t index = 0;
   for (index = 0; index < aMaxAttribs; index++) {
     aAttribValues[index] = nullptr;
     if (aAttribNames[index]) {
       nsAutoString attributeValue, nameSpaceURI;
       nsAutoString attributeName(nsDependentString(
         static_cast<const wchar_t*>(aAttribNames[index])));
--- a/content/base/public/nsContentUtils.h
+++ b/content/base/public/nsContentUtils.h
@@ -63,17 +63,17 @@ class nsIDragSession;
 class nsIEditor;
 class nsIFragmentContentSink;
 class nsIFrame;
 class nsIImageLoadingContent;
 class nsIInterfaceRequestor;
 class nsIIOService;
 class nsIJSRuntimeService;
 class nsILineBreaker;
-class nsINameSpaceManager;
+class nsNameSpaceManager;
 class nsINodeInfo;
 class nsIObserver;
 class nsIParser;
 class nsIParserService;
 class nsIPresShell;
 class nsIPrincipal;
 class nsIRunnable;
 class nsIScriptContext;
@@ -446,17 +446,17 @@ public:
   static nsIDocument* GetDocumentFromContext();
 
   // Check if a node is in the document prolog, i.e. before the document
   // element.
   static bool InProlog(nsINode *aNode);
 
   static nsIParserService* GetParserService();
 
-  static nsINameSpaceManager* NameSpaceManager()
+  static nsNameSpaceManager* NameSpaceManager()
   {
     return sNameSpaceManager;
   }
 
   static nsIIOService* GetIOService()
   {
     return sIOService;
   }
@@ -2150,17 +2150,17 @@ private:
                                       const nsString* aClasses);
 
   static nsIXPConnect *sXPConnect;
 
   static nsIScriptSecurityManager *sSecurityManager;
 
   static nsIParserService *sParserService;
 
-  static nsINameSpaceManager *sNameSpaceManager;
+  static nsNameSpaceManager *sNameSpaceManager;
 
   static nsIIOService *sIOService;
 
   static bool sImgLoaderInitialized;
   static void InitImgLoader();
 
   // The following four members are initialized lazily
   static imgLoader* sImgLoader;
--- a/content/base/public/nsINameSpaceManager.h
+++ b/content/base/public/nsINameSpaceManager.h
@@ -1,17 +1,20 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsINameSpaceManager_h___
 #define nsINameSpaceManager_h___
 
-#include "nsISupports.h"
+#include "nsDataHashtable.h"
+#include "nsTArray.h"
+
+#include "mozilla/StaticPtr.h"
 
 class nsIAtom;
 class nsAString;
 
 #define kNameSpaceID_Unknown -1
 // 0 is special at C++, so use a static const int32_t for
 // kNameSpaceID_None to keep if from being cast to pointers
 // Note that the XBL cache assumes (and asserts) that it can treat a
@@ -23,50 +26,86 @@ static const int32_t kNameSpaceID_None =
 #define kNameSpaceID_XLink    4
 #define kNameSpaceID_XSLT     5
 #define kNameSpaceID_XBL      6
 #define kNameSpaceID_MathML   7
 #define kNameSpaceID_RDF      8
 #define kNameSpaceID_XUL      9
 #define kNameSpaceID_SVG      10
 #define kNameSpaceID_LastBuiltin          10 // last 'built-in' namespace
- 
-#define NS_NAMESPACEMANAGER_CONTRACTID "@mozilla.org/content/namespacemanager;1"
+
+class nsNameSpaceKey : public PLDHashEntryHdr
+{
+public:
+  typedef const nsAString* KeyType;
+  typedef const nsAString* KeyTypePointer;
+
+  nsNameSpaceKey(KeyTypePointer aKey) : mKey(aKey)
+  {
+  }
+  nsNameSpaceKey(const nsNameSpaceKey& toCopy) : mKey(toCopy.mKey)
+  {
+  }
 
-#define NS_INAMESPACEMANAGER_IID \
-  { 0xd74e83e6, 0xf932, 0x4289, \
-    { 0xac, 0x95, 0x9e, 0x10, 0x24, 0x30, 0x88, 0xd6 } }
+  KeyType GetKey() const
+  {
+    return mKey;
+  }
+  bool KeyEquals(KeyType aKey) const
+  {
+    return mKey->Equals(*aKey);
+  }
 
+  static KeyTypePointer KeyToPointer(KeyType aKey)
+  {
+    return aKey;
+  }
+  static PLDHashNumber HashKey(KeyTypePointer aKey) {
+    return mozilla::HashString(*aKey);
+  }
+
+  enum {
+    ALLOW_MEMMOVE = true
+  };
+
+private:
+  const nsAString* mKey;
+};
+ 
 /**
  * The Name Space Manager tracks the association between a NameSpace
  * URI and the int32_t runtime id. Mappings between NameSpaces and 
  * NameSpace prefixes are managed by nsINameSpaces.
  *
  * All NameSpace URIs are stored in a global table so that IDs are
  * consistent accross the app. NameSpace IDs are only consistent at runtime
  * ie: they are not guaranteed to be consistent accross app sessions.
  *
- * The nsINameSpaceManager needs to have a live reference for as long as
+ * The nsNameSpaceManager needs to have a live reference for as long as
  * the NameSpace IDs are needed.
  *
  */
 
-class nsINameSpaceManager : public nsISupports
+class nsNameSpaceManager
 {
 public:
-  NS_DECLARE_STATIC_IID_ACCESSOR(NS_INAMESPACEMANAGER_IID)
+  virtual ~nsNameSpaceManager() {}
 
   virtual nsresult RegisterNameSpace(const nsAString& aURI,
-                                     int32_t& aNameSpaceID) = 0;
+                                     int32_t& aNameSpaceID);
+
+  virtual nsresult GetNameSpaceURI(int32_t aNameSpaceID, nsAString& aURI);
+  virtual int32_t GetNameSpaceID(const nsAString& aURI);
+
+  virtual bool HasElementCreator(int32_t aNameSpaceID);
 
-  virtual nsresult GetNameSpaceURI(int32_t aNameSpaceID, nsAString& aURI) = 0;
-  virtual int32_t GetNameSpaceID(const nsAString& aURI) = 0;
+  static nsNameSpaceManager* GetInstance();
+private:
+  bool Init();
+  nsresult AddNameSpace(const nsAString& aURI, const int32_t aNameSpaceID);
 
-  virtual bool HasElementCreator(int32_t aNameSpaceID) = 0;
+  nsDataHashtable<nsNameSpaceKey,int32_t> mURIToIDTable;
+  nsTArray< nsAutoPtr<nsString> > mURIArray;
+
+  static mozilla::StaticAutoPtr<nsNameSpaceManager> sInstance;
 };
  
-NS_DEFINE_STATIC_IID_ACCESSOR(nsINameSpaceManager, NS_INAMESPACEMANAGER_IID)
-
-nsresult NS_GetNameSpaceManager(nsINameSpaceManager** aInstancePtrResult);
-
-void NS_NameSpaceManagerShutdown();
-
 #endif // nsINameSpaceManager_h___
--- a/content/base/src/nsContentUtils.cpp
+++ b/content/base/src/nsContentUtils.cpp
@@ -191,17 +191,17 @@ using namespace mozilla::layers;
 using namespace mozilla::widget;
 using namespace mozilla;
 
 const char kLoadAsData[] = "loadAsData";
 
 nsIXPConnect *nsContentUtils::sXPConnect;
 nsIScriptSecurityManager *nsContentUtils::sSecurityManager;
 nsIParserService *nsContentUtils::sParserService = nullptr;
-nsINameSpaceManager *nsContentUtils::sNameSpaceManager;
+nsNameSpaceManager *nsContentUtils::sNameSpaceManager;
 nsIIOService *nsContentUtils::sIOService;
 imgLoader *nsContentUtils::sImgLoader;
 imgLoader *nsContentUtils::sPrivateImgLoader;
 imgICache *nsContentUtils::sImgCache;
 imgICache *nsContentUtils::sPrivateImgCache;
 nsIConsoleService *nsContentUtils::sConsoleService;
 nsDataHashtable<nsISupportsHashKey, EventNameMapping>* nsContentUtils::sAtomEventTable = nullptr;
 nsDataHashtable<nsStringHashKey, EventNameMapping>* nsContentUtils::sStringEventTable = nullptr;
@@ -366,30 +366,30 @@ nsresult
 nsContentUtils::Init()
 {
   if (sInitialized) {
     NS_WARNING("Init() called twice");
 
     return NS_OK;
   }
 
-  nsresult rv = NS_GetNameSpaceManager(&sNameSpaceManager);
-  NS_ENSURE_SUCCESS(rv, rv);
+  sNameSpaceManager = nsNameSpaceManager::GetInstance();
+  NS_ENSURE_TRUE(sNameSpaceManager, NS_ERROR_OUT_OF_MEMORY);
 
   sXPConnect = nsXPConnect::XPConnect();
 
   sSecurityManager = nsScriptSecurityManager::GetScriptSecurityManager();
   if(!sSecurityManager)
     return NS_ERROR_FAILURE;
   NS_ADDREF(sSecurityManager);
 
   // Getting the first context can trigger GC, so do this non-lazily.
   sXPConnect->InitSafeJSContext();
 
-  rv = CallGetService(NS_IOSERVICE_CONTRACTID, &sIOService);
+  nsresult rv = CallGetService(NS_IOSERVICE_CONTRACTID, &sIOService);
   if (NS_FAILED(rv)) {
     // This makes life easier, but we can live without it.
 
     sIOService = nullptr;
   }
 
   rv = CallGetService(NS_LBRK_CONTRACTID, &sLineBreaker);
   NS_ENSURE_SUCCESS(rv, rv);
@@ -1453,17 +1453,16 @@ nsContentUtils::Shutdown()
   uint32_t i;
   for (i = 0; i < PropertiesFile_COUNT; ++i)
     NS_IF_RELEASE(sStringBundles[i]);
 
   NS_IF_RELEASE(sStringBundleService);
   NS_IF_RELEASE(sConsoleService);
   sXPConnect = nullptr;
   NS_IF_RELEASE(sSecurityManager);
-  NS_IF_RELEASE(sNameSpaceManager);
   NS_IF_RELEASE(sParserService);
   NS_IF_RELEASE(sIOService);
   NS_IF_RELEASE(sLineBreaker);
   NS_IF_RELEASE(sWordBreaker);
   NS_IF_RELEASE(sImgLoader);
   NS_IF_RELEASE(sPrivateImgLoader);
   NS_IF_RELEASE(sImgCache);
   NS_IF_RELEASE(sPrivateImgCache);
--- a/content/base/src/nsNameSpaceManager.cpp
+++ b/content/base/src/nsNameSpaceManager.cpp
@@ -8,21 +8,20 @@
  * between namespace IDs and namespace URIs.
  */
 
 #include "nscore.h"
 #include "nsINameSpaceManager.h"
 #include "nsAutoPtr.h"
 #include "nsINodeInfo.h"
 #include "nsCOMArray.h"
-#include "nsTArray.h"
 #include "nsContentCreatorFunctions.h"
-#include "nsDataHashtable.h"
 #include "nsString.h"
 #include "nsINodeInfo.h"
+#include "mozilla/ClearOnShutdown.h"
 #include "mozilla/dom/XBLChildrenElement.h"
 #include "mozilla/dom/Element.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 #define kXMLNSNameSpaceURI "http://www.w3.org/2000/xmlns/"
 #define kXMLNameSpaceURI "http://www.w3.org/XML/1998/namespace"
@@ -30,113 +29,60 @@ using namespace mozilla::dom;
 #define kXLinkNameSpaceURI "http://www.w3.org/1999/xlink"
 #define kXSLTNameSpaceURI "http://www.w3.org/1999/XSL/Transform"
 #define kXBLNameSpaceURI "http://www.mozilla.org/xbl"
 #define kMathMLNameSpaceURI "http://www.w3.org/1998/Math/MathML"
 #define kRDFNameSpaceURI "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
 #define kXULNameSpaceURI "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
 #define kSVGNameSpaceURI "http://www.w3.org/2000/svg"
 
-class nsNameSpaceKey : public PLDHashEntryHdr
-{
-public:
-  typedef const nsAString* KeyType;
-  typedef const nsAString* KeyTypePointer;
-
-  nsNameSpaceKey(KeyTypePointer aKey) : mKey(aKey)
-  {
-  }
-  nsNameSpaceKey(const nsNameSpaceKey& toCopy) : mKey(toCopy.mKey)
-  {
-  }
+StaticAutoPtr<nsNameSpaceManager> nsNameSpaceManager::sInstance;
 
-  KeyType GetKey() const
-  {
-    return mKey;
-  }
-  bool KeyEquals(KeyType aKey) const
-  {
-    return mKey->Equals(*aKey);
-  }
-
-  static KeyTypePointer KeyToPointer(KeyType aKey)
-  {
-    return aKey;
-  }
-  static PLDHashNumber HashKey(KeyTypePointer aKey) {
-    return HashString(*aKey);
+/* static */ nsNameSpaceManager*
+nsNameSpaceManager::GetInstance() {
+  if (!sInstance) {
+    sInstance = new nsNameSpaceManager();
+    if (sInstance->Init()) {
+      ClearOnShutdown(&sInstance);
+    } else {
+      delete sInstance;
+      sInstance = nullptr;
+    }
   }
 
-  enum { 
-    ALLOW_MEMMOVE = true
-  };
-
-private:
-  const nsAString* mKey;
-};
-
-class NameSpaceManagerImpl : public nsINameSpaceManager {
-public:
-  NameSpaceManagerImpl()
-    : mURIToIDTable(32)
-  {
-  }
-  virtual ~NameSpaceManagerImpl()
-  {
-  }
-
-  NS_DECL_ISUPPORTS
+  return sInstance;
+}
 
-  nsresult Init();
-
-  nsresult RegisterNameSpace(const nsAString& aURI,  int32_t& aNameSpaceID);
-
-  nsresult GetNameSpaceURI(int32_t aNameSpaceID, nsAString& aURI);
-  int32_t GetNameSpaceID(const nsAString& aURI);
-
-  bool HasElementCreator(int32_t aNameSpaceID);
-
-private:
-  nsresult AddNameSpace(const nsAString& aURI, const int32_t aNameSpaceID);
-
-  nsDataHashtable<nsNameSpaceKey,int32_t> mURIToIDTable;
-  nsTArray< nsAutoPtr<nsString> > mURIArray;
-};
-
-static NameSpaceManagerImpl* sNameSpaceManager = nullptr;
-
-NS_IMPL_ISUPPORTS1(NameSpaceManagerImpl, nsINameSpaceManager)
-
-nsresult NameSpaceManagerImpl::Init()
+bool nsNameSpaceManager::Init()
 {
   nsresult rv;
 #define REGISTER_NAMESPACE(uri, id) \
   rv = AddNameSpace(NS_LITERAL_STRING(uri), id); \
-  NS_ENSURE_SUCCESS(rv, rv)
+  NS_ENSURE_SUCCESS(rv, false)
 
   // Need to be ordered according to ID.
   REGISTER_NAMESPACE(kXMLNSNameSpaceURI, kNameSpaceID_XMLNS);
   REGISTER_NAMESPACE(kXMLNameSpaceURI, kNameSpaceID_XML);
   REGISTER_NAMESPACE(kXHTMLNameSpaceURI, kNameSpaceID_XHTML);
   REGISTER_NAMESPACE(kXLinkNameSpaceURI, kNameSpaceID_XLink);
   REGISTER_NAMESPACE(kXSLTNameSpaceURI, kNameSpaceID_XSLT);
   REGISTER_NAMESPACE(kXBLNameSpaceURI, kNameSpaceID_XBL);
   REGISTER_NAMESPACE(kMathMLNameSpaceURI, kNameSpaceID_MathML);
   REGISTER_NAMESPACE(kRDFNameSpaceURI, kNameSpaceID_RDF);
   REGISTER_NAMESPACE(kXULNameSpaceURI, kNameSpaceID_XUL);
   REGISTER_NAMESPACE(kSVGNameSpaceURI, kNameSpaceID_SVG);
 
 #undef REGISTER_NAMESPACE
 
-  return NS_OK;
+  return true;
 }
 
 nsresult
-NameSpaceManagerImpl::RegisterNameSpace(const nsAString& aURI, 
-                                        int32_t& aNameSpaceID)
+nsNameSpaceManager::RegisterNameSpace(const nsAString& aURI,
+                                      int32_t& aNameSpaceID)
 {
   if (aURI.IsEmpty()) {
     aNameSpaceID = kNameSpaceID_None; // xmlns="", see bug 75700 for details
 
     return NS_OK;
   }
 
   nsresult rv = NS_OK;
@@ -150,34 +96,34 @@ NameSpaceManagerImpl::RegisterNameSpace(
   }
 
   NS_POSTCONDITION(aNameSpaceID >= -1, "Bogus namespace ID");
   
   return rv;
 }
 
 nsresult
-NameSpaceManagerImpl::GetNameSpaceURI(int32_t aNameSpaceID, nsAString& aURI)
+nsNameSpaceManager::GetNameSpaceURI(int32_t aNameSpaceID, nsAString& aURI)
 {
   NS_PRECONDITION(aNameSpaceID >= 0, "Bogus namespace ID");
   
   int32_t index = aNameSpaceID - 1; // id is index + 1
   if (index < 0 || index >= int32_t(mURIArray.Length())) {
     aURI.Truncate();
 
     return NS_ERROR_ILLEGAL_VALUE;
   }
 
   aURI = *mURIArray.ElementAt(index);
 
   return NS_OK;
 }
 
 int32_t
-NameSpaceManagerImpl::GetNameSpaceID(const nsAString& aURI)
+nsNameSpaceManager::GetNameSpaceID(const nsAString& aURI)
 {
   if (aURI.IsEmpty()) {
     return kNameSpaceID_None; // xmlns="", see bug 75700 for details
   }
 
   int32_t nameSpaceID;
 
   if (mURIToIDTable.Get(&aURI, &nameSpaceID)) {
@@ -211,29 +157,29 @@ NS_NewElement(Element** aResult,
     NS_ADDREF(*aResult = new XBLChildrenElement(aNodeInfo));
     return NS_OK;
   }
 
   return NS_NewXMLElement(aResult, aNodeInfo);
 }
 
 bool
-NameSpaceManagerImpl::HasElementCreator(int32_t aNameSpaceID)
+nsNameSpaceManager::HasElementCreator(int32_t aNameSpaceID)
 {
   return aNameSpaceID == kNameSpaceID_XHTML ||
 #ifdef MOZ_XUL
          aNameSpaceID == kNameSpaceID_XUL ||
 #endif
          aNameSpaceID == kNameSpaceID_MathML ||
          aNameSpaceID == kNameSpaceID_SVG ||
          false;
 }
 
-nsresult NameSpaceManagerImpl::AddNameSpace(const nsAString& aURI,
-                                            const int32_t aNameSpaceID)
+nsresult nsNameSpaceManager::AddNameSpace(const nsAString& aURI,
+                                          const int32_t aNameSpaceID)
 {
   if (aNameSpaceID < 0) {
     // We've wrapped...  Can't do anything else here; just bail.
     return NS_ERROR_OUT_OF_MEMORY;
   }
   
   NS_ASSERTION(aNameSpaceID - 1 == (int32_t) mURIArray.Length(),
                "BAD! AddNameSpace not called in right order!");
@@ -243,37 +189,8 @@ nsresult NameSpaceManagerImpl::AddNameSp
     delete uri;
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   mURIToIDTable.Put(uri, aNameSpaceID);
 
   return NS_OK;
 }
-
-nsresult
-NS_GetNameSpaceManager(nsINameSpaceManager** aInstancePtrResult)
-{
-  NS_ENSURE_ARG_POINTER(aInstancePtrResult);
-
-  if (!sNameSpaceManager) {
-    nsCOMPtr<NameSpaceManagerImpl> manager = new NameSpaceManagerImpl();
-    if (manager) {
-      nsresult rv = manager->Init();
-      if (NS_SUCCEEDED(rv)) {
-        manager.swap(sNameSpaceManager);
-      }
-    }
-  }
-
-  *aInstancePtrResult = sNameSpaceManager;
-  NS_ENSURE_TRUE(sNameSpaceManager, NS_ERROR_OUT_OF_MEMORY);
-
-  NS_ADDREF(*aInstancePtrResult);
-
-  return NS_OK;
-}
-
-void
-NS_NameSpaceManagerShutdown()
-{
-  NS_IF_RELEASE(sNameSpaceManager);
-}
--- a/layout/build/nsLayoutModule.cpp
+++ b/layout/build/nsLayoutModule.cpp
@@ -24,17 +24,16 @@
 #include "nsIControllers.h"
 #include "nsIDOMDOMImplementation.h"
 #include "nsIDocument.h"
 #include "nsIDocumentEncoder.h"
 #include "nsIFactory.h"
 #include "nsIFrameUtil.h"
 #include "nsHTMLStyleSheet.h"
 #include "nsILayoutDebugger.h"
-#include "nsINameSpaceManager.h"
 #include "nsINodeInfo.h"
 #include "nsIObserver.h"
 #include "nsIObserverService.h"
 #include "nsIScriptNameSpaceManager.h"
 #include "nsISelection.h"
 #include "nsCaret.h"
 #include "nsPlainTextSerializer.h"
 #include "nsXMLContentSerializer.h"
@@ -540,17 +539,16 @@ MAKE_CTOR(CreateNewContainerBoxObject,  
 #ifdef MOZ_XUL
 NS_GENERIC_FACTORY_CONSTRUCTOR(inDOMView)
 #endif
 NS_GENERIC_FACTORY_CONSTRUCTOR(inDeepTreeWalker)
 NS_GENERIC_FACTORY_CONSTRUCTOR(inFlasher)
 NS_GENERIC_FACTORY_CONSTRUCTOR(inCSSValueSearch)
 NS_GENERIC_FACTORY_CONSTRUCTOR(inDOMUtils)
 
-MAKE_CTOR(CreateNameSpaceManager,         nsINameSpaceManager,         NS_GetNameSpaceManager)
 MAKE_CTOR2(CreateContentViewer,           nsIContentViewer,            NS_NewContentViewer)
 MAKE_CTOR(CreateHTMLDocument,             nsIDocument,                 NS_NewHTMLDocument)
 MAKE_CTOR(CreateXMLDocument,              nsIDocument,                 NS_NewXMLDocument)
 MAKE_CTOR(CreateSVGDocument,              nsIDocument,                 NS_NewSVGDocument)
 MAKE_CTOR(CreateImageDocument,            nsIDocument,                 NS_NewImageDocument)
 MAKE_CTOR(CreateDOMBlob,                  nsISupports,                 nsDOMMultipartFile::NewBlob)
 MAKE_CTOR(CreateDOMFile,                  nsISupports,                 nsDOMMultipartFile::NewFile)
 MAKE_CTOR(CreateDOMSelection,             nsISelection,                NS_NewDomSelection)
@@ -689,17 +687,16 @@ NS_DEFINE_NAMED_CID(NS_TREEBOXOBJECT_CID
 #endif // MOZ_XUL
 #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);
-NS_DEFINE_NAMED_CID(NS_NAMESPACEMANAGER_CID);
 NS_DEFINE_NAMED_CID(NS_CONTENT_VIEWER_CID);
 NS_DEFINE_NAMED_CID(NS_HTMLDOCUMENT_CID);
 NS_DEFINE_NAMED_CID(NS_XMLDOCUMENT_CID);
 NS_DEFINE_NAMED_CID(NS_SVGDOCUMENT_CID);
 NS_DEFINE_NAMED_CID(NS_IMAGEDOCUMENT_CID);
 NS_DEFINE_NAMED_CID(NS_DOMMULTIPARTBLOB_CID);
 NS_DEFINE_NAMED_CID(NS_DOMMULTIPARTFILE_CID);
 NS_DEFINE_NAMED_CID(NS_DOMSELECTION_CID);
@@ -976,17 +973,16 @@ static const mozilla::Module::CIDEntry k
 #endif // MOZ_XUL
 #ifdef MOZ_XUL
   { &kIN_DOMVIEW_CID, false, nullptr, inDOMViewConstructor },
 #endif
   { &kIN_DEEPTREEWALKER_CID, false, nullptr, inDeepTreeWalkerConstructor },
   { &kIN_FLASHER_CID, false, nullptr, inFlasherConstructor },
   { &kIN_CSSVALUESEARCH_CID, false, nullptr, inCSSValueSearchConstructor },
   { &kIN_DOMUTILS_CID, false, nullptr, inDOMUtilsConstructor },
-  { &kNS_NAMESPACEMANAGER_CID, false, nullptr, CreateNameSpaceManager },
   { &kNS_CONTENT_VIEWER_CID, false, nullptr, CreateContentViewer },
   { &kNS_HTMLDOCUMENT_CID, false, nullptr, CreateHTMLDocument },
   { &kNS_XMLDOCUMENT_CID, false, nullptr, CreateXMLDocument },
   { &kNS_SVGDOCUMENT_CID, false, nullptr, CreateSVGDocument },
   { &kNS_IMAGEDOCUMENT_CID, false, nullptr, CreateImageDocument },
   { &kNS_DOMMULTIPARTBLOB_CID, false, nullptr, CreateDOMBlob },
   { &kNS_DOMMULTIPARTFILE_CID, false, nullptr, CreateDOMFile },
   { &kNS_DOMSELECTION_CID, false, nullptr, CreateDOMSelection },
@@ -1128,17 +1124,16 @@ static const mozilla::Module::ContractID
 #endif // MOZ_XUL
 #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 },
-  { NS_NAMESPACEMANAGER_CONTRACTID, &kNS_NAMESPACEMANAGER_CID },
   { "@mozilla.org/xml/xml-document;1", &kNS_XMLDOCUMENT_CID },
   { "@mozilla.org/svg/svg-document;1", &kNS_SVGDOCUMENT_CID },
   { NS_DOMMULTIPARTBLOB_CONTRACTID, &kNS_DOMMULTIPARTBLOB_CID },
   { NS_DOMMULTIPARTFILE_CONTRACTID, &kNS_DOMMULTIPARTFILE_CID },
   { "@mozilla.org/content/dom-selection;1", &kNS_DOMSELECTION_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 },
--- a/layout/build/nsLayoutStatics.cpp
+++ b/layout/build/nsLayoutStatics.cpp
@@ -342,17 +342,16 @@ nsLayoutStatics::Shutdown()
 
   mozilla::css::ErrorReporter::ReleaseGlobals();
 
   nsTextFragment::Shutdown();
 
   nsAttrValue::Shutdown();
   nsContentUtils::Shutdown();
   nsLayoutStylesheetCache::Shutdown();
-  NS_NameSpaceManagerShutdown();
 
   ShutdownJSEnvironment();
   nsGlobalWindow::ShutDown();
   nsDOMClassInfo::ShutDown();
   nsListControlFrame::Shutdown();
   nsEditorEventListener::ShutDown();
   nsXBLService::Shutdown();
   nsAutoCopyListener::Shutdown();
--- a/layout/inspector/inDOMView.cpp
+++ b/layout/inspector/inDOMView.cpp
@@ -647,18 +647,17 @@ inDOMView::AttributeChanged(nsIDocument*
 
   nsCOMPtr<nsIMutationObserver> kungFuDeathGrip(this);
   
   // get the dom attribute node, if there is any
   nsCOMPtr<nsIDOMElement> el(do_QueryInterface(aElement));
   nsCOMPtr<nsIDOMAttr> domAttr;
   nsDependentAtomString attrStr(aAttribute);
   if (aNameSpaceID) {
-    nsCOMPtr<nsINameSpaceManager> nsm =
-      do_GetService(NS_NAMESPACEMANAGER_CONTRACTID);
+    nsNameSpaceManager* nsm = nsNameSpaceManager::GetInstance();
     if (!nsm) {
       // we can't find out which attribute we want :(
       return;
     }
     nsString attrNS;
     nsresult rv = nsm->GetNameSpaceURI(aNameSpaceID, attrNS);
     if (NS_FAILED(rv)) {
       return;