Backed out changeset 92e24ee719b8
authorBen Turner <bent.mozilla@gmail.com>
Thu, 09 Oct 2008 22:13:30 -0700
changeset 20240 7c126606e7af93f14665afe527f0a9854c339fe8
parent 20238 92e24ee719b84021eb107886afdbb5e56022522b
child 20241 94f75be179884e7abee76d3887926913e8d02f70
push idunknown
push userunknown
push dateunknown
milestone1.9.1b2pre
backs out92e24ee719b84021eb107886afdbb5e56022522b
Backed out changeset 92e24ee719b8
content/base/public/nsINameSpaceManager.h
content/base/src/nsNameSpaceManager.cpp
--- a/content/base/public/nsINameSpaceManager.h
+++ b/content/base/public/nsINameSpaceManager.h
@@ -35,18 +35,16 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef nsINameSpaceManager_h___
 #define nsINameSpaceManager_h___
 
 #include "nsISupports.h"
 #include "nsStringGlue.h"
-#include "nsDataHashtable.h"
-#include "nsVoidArray.h"
 
 class nsIAtom;
 class nsString;
 
 #define kNameSpaceID_Unknown -1
 // 0 is special at C++, so use a static const PRInt32 for
 // kNameSpaceID_None to keep if from being cast to pointers
 static const PRInt32 kNameSpaceID_None = 0;
@@ -78,74 +76,28 @@ static const PRInt32 kNameSpaceID_None =
  * 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 NameSpace IDs are needed.
  *
  */
 
-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)
-  {
-  }
-
-  KeyType GetKey() const
-  {
-    return mKey;
-  }
-  PRBool KeyEquals(KeyType aKey) const
-  {
-    return mKey->Equals(*aKey);
-  }
-
-  static KeyTypePointer KeyToPointer(KeyType aKey)
-  {
-    return aKey;
-  }
-  static PLDHashNumber HashKey(KeyTypePointer aKey) {
-    return HashString(*aKey);
-  }
-
-  enum { 
-    ALLOW_MEMMOVE = PR_TRUE
-  };
-
-private:
-  const nsAString* mKey;
-};
-
-
 class nsINameSpaceManager : public nsISupports
 {
 public:
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_INAMESPACEMANAGER_IID)
-  NS_DECL_ISUPPORTS
-  nsresult RegisterNameSpace(const nsAString& aURI,
-                             PRInt32& aNameSpaceID);
 
-  nsresult GetNameSpaceURI(PRInt32 aNameSpaceID, nsAString& aURI);
-  PRInt32 GetNameSpaceID(const nsAString& aURI);
+  virtual nsresult RegisterNameSpace(const nsAString& aURI,
+                                     PRInt32& aNameSpaceID) = 0;
 
-  PRBool HasElementCreator(PRInt32 aNameSpaceID);
+  virtual nsresult GetNameSpaceURI(PRInt32 aNameSpaceID, nsAString& aURI) = 0;
+  virtual PRInt32 GetNameSpaceID(const nsAString& aURI) = 0;
 
-  nsresult Init();  
-private:
-  nsresult AddNameSpace(const nsAString& aURI, const PRInt32 aNameSpaceID);
-
-  nsDataHashtable<nsNameSpaceKey,PRInt32> mURIToIDTable;
-  nsStringArray mURIArray;
+  virtual PRBool HasElementCreator(PRInt32 aNameSpaceID) = 0;
 };
  
 NS_DEFINE_STATIC_IID_ACCESSOR(nsINameSpaceManager, NS_INAMESPACEMANAGER_IID)
 
 nsresult NS_GetNameSpaceManager(nsINameSpaceManager** aInstancePtrResult);
 
 void NS_NameSpaceManagerShutdown();
 
--- a/content/base/src/nsNameSpaceManager.cpp
+++ b/content/base/src/nsNameSpaceManager.cpp
@@ -41,16 +41,17 @@
  */
 
 #include "nscore.h"
 #include "nsINameSpaceManager.h"
 #include "nsAutoPtr.h"
 #include "nsINodeInfo.h"
 #include "nsCOMArray.h"
 #include "nsContentCreatorFunctions.h"
+#include "nsDataHashtable.h"
 #include "nsString.h"
 
 #ifdef MOZ_XTF
 #include "nsIServiceManager.h"
 #include "nsIXTFService.h"
 #include "nsContentUtils.h"
 static NS_DEFINE_CID(kXTFServiceCID, NS_XTFSERVICE_CID);
 #endif
@@ -66,21 +67,83 @@ PRBool NS_SVGEnabled();
 #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"
 #define kXMLEventsNameSpaceURI "http://www.w3.org/2001/xml-events"
 
-static nsINameSpaceManager* sNameSpaceManager = nsnull;
+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)
+  {
+  }
+
+  KeyType GetKey() const
+  {
+    return mKey;
+  }
+  PRBool KeyEquals(KeyType aKey) const
+  {
+    return mKey->Equals(*aKey);
+  }
+
+  static KeyTypePointer KeyToPointer(KeyType aKey)
+  {
+    return aKey;
+  }
+  static PLDHashNumber HashKey(KeyTypePointer aKey) {
+    return HashString(*aKey);
+  }
+
+  enum { 
+    ALLOW_MEMMOVE = PR_TRUE
+  };
 
-NS_IMPL_ISUPPORTS1(nsINameSpaceManager, nsINameSpaceManager)
+private:
+  const nsAString* mKey;
+};
+
+class NameSpaceManagerImpl : public nsINameSpaceManager {
+public:
+  virtual ~NameSpaceManagerImpl()
+  {
+  }
+
+  NS_DECL_ISUPPORTS
+
+  nsresult Init();
+
+  nsresult RegisterNameSpace(const nsAString& aURI,  PRInt32& aNameSpaceID);
 
-nsresult nsINameSpaceManager::Init()
+  nsresult GetNameSpaceURI(PRInt32 aNameSpaceID, nsAString& aURI);
+  PRInt32 GetNameSpaceID(const nsAString& aURI);
+
+  PRBool HasElementCreator(PRInt32 aNameSpaceID);
+
+private:
+  nsresult AddNameSpace(const nsAString& aURI, const PRInt32 aNameSpaceID);
+
+  nsDataHashtable<nsNameSpaceKey,PRInt32> mURIToIDTable;
+  nsStringArray mURIArray;
+};
+
+static NameSpaceManagerImpl* sNameSpaceManager = nsnull;
+
+NS_IMPL_ISUPPORTS1(NameSpaceManagerImpl, nsINameSpaceManager)
+
+nsresult NameSpaceManagerImpl::Init()
 {
   nsresult rv = mURIToIDTable.Init(32);
   NS_ENSURE_SUCCESS(rv, rv);
 
 #define REGISTER_NAMESPACE(uri, id) \
   rv = AddNameSpace(NS_LITERAL_STRING(uri), id); \
   NS_ENSURE_SUCCESS(rv, rv)
 
@@ -98,18 +161,18 @@ nsresult nsINameSpaceManager::Init()
   REGISTER_NAMESPACE(kXMLEventsNameSpaceURI, kNameSpaceID_XMLEvents);
 
 #undef REGISTER_NAMESPACE
 
   return NS_OK;
 }
 
 nsresult
-nsINameSpaceManager::RegisterNameSpace(const nsAString& aURI, 
-                                       PRInt32& aNameSpaceID)
+NameSpaceManagerImpl::RegisterNameSpace(const nsAString& aURI, 
+                                        PRInt32& aNameSpaceID)
 {
   if (aURI.IsEmpty()) {
     aNameSpaceID = kNameSpaceID_None; // xmlns="", see bug 75700 for details
 
     return NS_OK;
   }
 
   nsresult rv = NS_OK;
@@ -123,34 +186,34 @@ nsINameSpaceManager::RegisterNameSpace(c
   }
 
   NS_POSTCONDITION(aNameSpaceID >= -1, "Bogus namespace ID");
   
   return rv;
 }
 
 nsresult
-nsINameSpaceManager::GetNameSpaceURI(PRInt32 aNameSpaceID, nsAString& aURI)
+NameSpaceManagerImpl::GetNameSpaceURI(PRInt32 aNameSpaceID, nsAString& aURI)
 {
   NS_PRECONDITION(aNameSpaceID >= 0, "Bogus namespace ID");
   
   PRInt32 index = aNameSpaceID - 1; // id is index + 1
   if (index < 0 || index >= mURIArray.Count()) {
     aURI.Truncate();
 
     return NS_ERROR_ILLEGAL_VALUE;
   }
 
   mURIArray.StringAt(index, aURI);
 
   return NS_OK;
 }
 
 PRInt32
-nsINameSpaceManager::GetNameSpaceID(const nsAString& aURI)
+NameSpaceManagerImpl::GetNameSpaceID(const nsAString& aURI)
 {
   if (aURI.IsEmpty()) {
     return kNameSpaceID_None; // xmlns="", see bug 75700 for details
   }
 
   PRInt32 nameSpaceID;
 
   if (mURIToIDTable.Get(&aURI, &nameSpaceID)) {
@@ -194,34 +257,34 @@ NS_NewElement(nsIContent** aResult, PRIn
         NS_SUCCEEDED(xtfService->CreateElement(aResult, aNodeInfo)))
       return NS_OK;
   }
 #endif
   return NS_NewXMLElement(aResult, aNodeInfo);
 }
 
 PRBool
-nsINameSpaceManager::HasElementCreator(PRInt32 aNameSpaceID)
+NameSpaceManagerImpl::HasElementCreator(PRInt32 aNameSpaceID)
 {
   return aNameSpaceID == kNameSpaceID_XHTML ||
 #ifdef MOZ_XUL
          aNameSpaceID == kNameSpaceID_XUL ||
 #endif
 #ifdef MOZ_MATHML
          aNameSpaceID == kNameSpaceID_MathML ||
 #endif
 #ifdef MOZ_SVG
          aNameSpaceID == kNameSpaceID_SVG ||
 #endif
          aNameSpaceID == kNameSpaceID_XMLEvents ||
-    PR_FALSE;
+         PR_FALSE;
 }
 
-nsresult nsINameSpaceManager::AddNameSpace(const nsAString& aURI,
-                                           const PRInt32 aNameSpaceID)
+nsresult NameSpaceManagerImpl::AddNameSpace(const nsAString& aURI,
+                                            const PRInt32 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 == mURIArray.Count(),
                "BAD! AddNameSpace not called in right order!");
@@ -241,17 +304,17 @@ nsresult nsINameSpaceManager::AddNameSpa
 }
 
 nsresult
 NS_GetNameSpaceManager(nsINameSpaceManager** aInstancePtrResult)
 {
   NS_ENSURE_ARG_POINTER(aInstancePtrResult);
 
   if (!sNameSpaceManager) {
-    nsCOMPtr<nsINameSpaceManager> manager = new nsINameSpaceManager();
+    nsCOMPtr<NameSpaceManagerImpl> manager = new NameSpaceManagerImpl();
     if (manager) {
       nsresult rv = manager->Init();
       if (NS_SUCCEEDED(rv)) {
         manager.swap(sNameSpaceManager);
       }
     }
   }