Bug 1473631: Part 12 - Replace pref observers with callbacks in nsNameSpaceManager. r?njn draft
authorKris Maglione <maglione.k@gmail.com>
Thu, 05 Jul 2018 15:07:12 -0700
changeset 818484 7eaf4ebeebf6e3df7d14ad59b7b7632abac9d1ae
parent 818483 5d1d3a69c397bda43b55a428e84b8226bffcb1fc
child 818485 b2050037df161dbd696f7e88f4d649f7f7d6692b
push id116269
push usermaglione.k@gmail.com
push dateSat, 14 Jul 2018 02:18:47 +0000
reviewersnjn
bugs1473631
milestone63.0a1
Bug 1473631: Part 12 - Replace pref observers with callbacks in nsNameSpaceManager. r?njn MozReview-Commit-ID: 1RxEYL5LKjy
dom/base/nsNameSpaceManager.cpp
dom/base/nsNameSpaceManager.h
--- a/dom/base/nsNameSpaceManager.cpp
+++ b/dom/base/nsNameSpaceManager.cpp
@@ -58,20 +58,21 @@ bool nsNameSpaceManager::Init()
 #define REGISTER_NAMESPACE(uri, id) \
   rv = AddNameSpace(dont_AddRef(uri), id); \
   NS_ENSURE_SUCCESS(rv, false)
 
 #define REGISTER_DISABLED_NAMESPACE(uri, id) \
   rv = AddDisabledNameSpace(dont_AddRef(uri), id); \
   NS_ENSURE_SUCCESS(rv, false)
 
-  mozilla::Preferences::AddStrongObservers(this, kObservedPrefs);
-  mMathMLDisabled = mozilla::Preferences::GetBool(kPrefMathMLDisabled);
-  mSVGDisabled = mozilla::Preferences::GetBool(kPrefSVGDisabled);
+  mozilla::Preferences::RegisterCallbacks(
+    PREF_CHANGE_METHOD(nsNameSpaceManager::PrefChanged),
+    kObservedPrefs, this);
 
+  PrefChanged(nullptr);
 
   // Need to be ordered according to ID.
   MOZ_ASSERT(mURIArray.IsEmpty());
   REGISTER_NAMESPACE(nsGkAtoms::_empty, kNameSpaceID_None);
   REGISTER_NAMESPACE(nsGkAtoms::nsuri_xmlns, kNameSpaceID_XMLNS);
   REGISTER_NAMESPACE(nsGkAtoms::nsuri_xml, kNameSpaceID_XML);
   REGISTER_NAMESPACE(nsGkAtoms::nsuri_xhtml, kNameSpaceID_XHTML);
   REGISTER_NAMESPACE(nsGkAtoms::nsuri_xlink, kNameSpaceID_XLink);
@@ -269,20 +270,16 @@ nsNameSpaceManager::AddDisabledNameSpace
   MOZ_ASSERT(aNameSpaceID == (int32_t) mURIArray.Length());
   mURIArray.AppendElement(uri.forget());
   mDisabledURIToIDTable.Put(mURIArray.LastElement(), aNameSpaceID);
 
   return NS_OK;
 }
 
 // nsISupports
-NS_IMPL_ISUPPORTS(nsNameSpaceManager,
-                  nsIObserver)
+NS_IMPL_ISUPPORTS0(nsNameSpaceManager)
 
-// nsIObserver
-NS_IMETHODIMP
-nsNameSpaceManager::Observe(nsISupports* aObject, const char* aTopic,
-                            const char16_t* aMessage)
+void
+nsNameSpaceManager::PrefChanged(const char* aPref)
 {
   mMathMLDisabled = mozilla::Preferences::GetBool(kPrefMathMLDisabled);
   mSVGDisabled = mozilla::Preferences::GetBool(kPrefSVGDisabled);
-  return NS_OK;
 }
--- a/dom/base/nsNameSpaceManager.h
+++ b/dom/base/nsNameSpaceManager.h
@@ -6,17 +6,16 @@
 
 #ifndef nsNameSpaceManager_h___
 #define nsNameSpaceManager_h___
 
 #include "nsDataHashtable.h"
 #include "nsHashKeys.h"
 #include "nsAtom.h"
 #include "nsIDocument.h"
-#include "nsIObserver.h"
 #include "nsStringFwd.h"
 #include "nsTArray.h"
 
 #include "mozilla/StaticPtr.h"
 
 /**
  * The Name Space Manager tracks the association between a NameSpace
  * URI and the int32_t runtime id. Mappings between NameSpaces and
@@ -26,21 +25,20 @@
  * consistent accross the app. NameSpace IDs are only consistent at runtime
  * ie: they are not guaranteed to be consistent accross app sessions.
  *
  * The nsNameSpaceManager needs to have a live reference for as long as
  * the NameSpace IDs are needed.
  *
  */
 
-class nsNameSpaceManager final : public nsIObserver
+class nsNameSpaceManager final : public nsISupports
 {
 public:
   NS_DECL_ISUPPORTS
-  NS_DECL_NSIOBSERVER
   virtual nsresult RegisterNameSpace(const nsAString& aURI,
                                      int32_t& aNameSpaceID);
   nsresult RegisterNameSpace(already_AddRefed<nsAtom> aURI,
                              int32_t& aNameSpaceID);
 
   virtual nsresult GetNameSpaceURI(int32_t aNameSpaceID, nsAString& aURI);
 
   // Returns the atom for the namespace URI associated with the given ID. The
@@ -62,16 +60,18 @@ public:
 
   bool HasElementCreator(int32_t aNameSpaceID);
 
   static nsNameSpaceManager* GetInstance();
   bool mMathMLDisabled;
   bool mSVGDisabled;
 
 private:
+  void PrefChanged(const char* aPref);
+
   bool Init();
   nsresult AddNameSpace(already_AddRefed<nsAtom> aURI, const int32_t aNameSpaceID);
   nsresult AddDisabledNameSpace(already_AddRefed<nsAtom> aURI, const int32_t aNameSpaceID);
   ~nsNameSpaceManager() {};
 
   nsDataHashtable<nsRefPtrHashKey<nsAtom>, int32_t> mURIToIDTable;
   nsDataHashtable<nsRefPtrHashKey<nsAtom>, int32_t> mDisabledURIToIDTable;
   nsTArray<RefPtr<nsAtom>> mURIArray;