Commit 6167067a authored by Kathleen Brade's avatar Kathleen Brade Committed by Georg Koppen
Browse files

Bug 13548: Create preference to disable MathML.

If the mathml.disabled preference is true, treat <math> and other MathML
elements as generic XML elements.
parent ff90f3d3
Loading
Loading
Loading
Loading
+44 −5
Original line number Diff line number Diff line
@@ -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,8 +166,19 @@ NS_NewElement(Element** aResult,
  }
#endif
  if (ns == kNameSpaceID_MathML) {
    // 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();
    nsRefPtr<mozilla::dom::NodeInfo> 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;
}
+7 −3
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@

#include "nsDataHashtable.h"
#include "nsTArray.h"
#include "nsIObserver.h"

#include "mozilla/StaticPtr.h"

@@ -66,10 +67,11 @@ private:
 *
 */

class nsNameSpaceManager final
class nsNameSpaceManager final : public nsIObserver
{
public:
  virtual ~nsNameSpaceManager() {}
  NS_DECL_ISUPPORTS
  NS_DECL_NSIOBSERVER

  virtual nsresult RegisterNameSpace(const nsAString& aURI,
                                     int32_t& aNameSpaceID);
@@ -80,14 +82,16 @@ public:
  virtual bool HasElementCreator(int32_t aNameSpaceID);

  static nsNameSpaceManager* GetInstance();
  bool mIsMathMLDisabled;
private:
  bool Init();
  nsresult AddNameSpace(const nsAString& aURI, const int32_t aNameSpaceID);
  virtual ~nsNameSpaceManager();

  nsDataHashtable<nsNameSpaceKey,int32_t> mURIToIDTable;
  nsTArray< nsAutoPtr<nsString> > mURIArray;

  static mozilla::StaticAutoPtr<nsNameSpaceManager> sInstance;
  static mozilla::StaticRefPtr<nsNameSpaceManager> sInstance;
};
 
#endif // nsNameSpaceManager_h___