commit 5b48b325cf54fe341c9c6c417ecfbb83cc5625be Author: Kathy Brade brade@pearlcrescent.com Date: Thu Mar 5 18:50:59 2015 -0500
Bug 13548: Create preference to disable MathML.
If the mathml.disabled preference is true, treat <math> and other MathML elements as generic XML elements. --- content/base/public/nsNameSpaceManager.h | 11 +++++--- content/base/src/nsNameSpaceManager.cpp | 43 ++++++++++++++++++++++++++++-- 2 files changed, 49 insertions(+), 5 deletions(-)
diff --git a/content/base/public/nsNameSpaceManager.h b/content/base/public/nsNameSpaceManager.h index 7f222a6..24b85f3 100644 --- a/content/base/public/nsNameSpaceManager.h +++ b/content/base/public/nsNameSpaceManager.h @@ -8,6 +8,7 @@
#include "nsDataHashtable.h" #include "nsTArray.h" +#include "nsIObserver.h"
#include "mozilla/StaticPtr.h"
@@ -84,10 +85,13 @@ private: * */
-class nsNameSpaceManager +class nsNameSpaceManager : public nsIObserver { public: - virtual ~nsNameSpaceManager() {} + NS_DECL_ISUPPORTS + NS_DECL_NSIOBSERVER + + virtual ~nsNameSpaceManager();
virtual nsresult RegisterNameSpace(const nsAString& aURI, int32_t& aNameSpaceID); @@ -98,6 +102,7 @@ public: virtual bool HasElementCreator(int32_t aNameSpaceID);
static nsNameSpaceManager* GetInstance(); + bool mIsMathMLDisabled; private: bool Init(); nsresult AddNameSpace(const nsAString& aURI, const int32_t aNameSpaceID); @@ -105,7 +110,7 @@ private: nsDataHashtable<nsNameSpaceKey,int32_t> mURIToIDTable; nsTArray< nsAutoPtr<nsString> > mURIArray;
- static mozilla::StaticAutoPtr<nsNameSpaceManager> sInstance; + static mozilla::StaticRefPtr<nsNameSpaceManager> sInstance; };
#endif // nsNameSpaceManager_h___ diff --git a/content/base/src/nsNameSpaceManager.cpp b/content/base/src/nsNameSpaceManager.cpp index 409e08c..d2a9722 100644 --- a/content/base/src/nsNameSpaceManager.cpp +++ b/content/base/src/nsNameSpaceManager.cpp @@ -20,6 +20,7 @@ #include "mozilla/ClearOnShutdown.h" #include "mozilla/dom/XBLChildrenElement.h" #include "mozilla/dom/Element.h" +#include "mozilla/Preferences.h"
using namespace mozilla; using namespace mozilla::dom; @@ -35,7 +36,14 @@ using namespace mozilla::dom; #define kXULNameSpaceURI "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" #define kSVGNameSpaceURI "http://www.w3.org/2000/svg"
-StaticAutoPtr<nsNameSpaceManager> nsNameSpaceManager::sInstance; +static const char kMathMLDisabledPrefName[] = "mathml.disabled"; + +static const char* kObservedPrefs[] = { + kMathMLDisabledPrefName, + nullptr +}; + +StaticRefPtr<nsNameSpaceManager> nsNameSpaceManager::sInstance;
/* static */ nsNameSpaceManager* nsNameSpaceManager::GetInstance() { @@ -52,6 +60,10 @@ nsNameSpaceManager::GetInstance() { return sInstance; }
+nsNameSpaceManager::~nsNameSpaceManager() { + mozilla::Preferences::RemoveObservers(this, kObservedPrefs); +} + bool nsNameSpaceManager::Init() { nsresult rv; @@ -73,6 +85,9 @@ bool nsNameSpaceManager::Init()
#undef REGISTER_NAMESPACE
+ mozilla::Preferences::AddStrongObservers(this, kObservedPrefs); + mIsMathMLDisabled = mozilla::Preferences::GetBool(kMathMLDisabledPrefName); + return true; }
@@ -151,7 +166,18 @@ NS_NewElement(Element** aResult, } #endif if (ns == kNameSpaceID_MathML) { - return NS_NewMathMLElement(aResult, ni.forget()); + // If the mathml.disabled pref. is true, convert all MathML nodes into + // generic XML nodes by swapping the namespace. + nsNameSpaceManager* nsmgr = nsNameSpaceManager::GetInstance(); + if (nsmgr && !nsmgr->mIsMathMLDisabled) { + return NS_NewMathMLElement(aResult, ni.forget()); + } + + nsNodeInfoManager *niMgr = ni->NodeInfoManager(); + nsCOMPtr<nsINodeInfo> genericXMLNI = niMgr->GetNodeInfo(ni->NameAtom(), + ni->GetPrefixAtom(), kNameSpaceID_XML, + ni->NodeType(), ni->GetExtraName()); + return NS_NewXMLElement(aResult, genericXMLNI.forget()); } if (ns == kNameSpaceID_SVG) { return NS_NewSVGElement(aResult, ni.forget(), aFromParser); @@ -197,3 +223,16 @@ nsresult nsNameSpaceManager::AddNameSpace(const nsAString& aURI,
return NS_OK; } + +// nsISupports +NS_IMPL_ISUPPORTS(nsNameSpaceManager, + nsIObserver) + +// nsIObserver +NS_IMETHODIMP +nsNameSpaceManager::Observe(nsISupports* aObject, const char* aTopic, + const char16_t* aMessage) +{ + mIsMathMLDisabled = mozilla::Preferences::GetBool(kMathMLDisabledPrefName); + return NS_OK; +}
tbb-commits@lists.torproject.org