From b91b0c37eb6cab1e179252692ad7e7a60606efa3 Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Tue, 7 Jan 2020 09:10:56 -0500 Subject: Bug 1322938 - Put element behind preference. Tag #1343 --- dom/html/HTMLDialogElement.cpp | 29 ++++++++++++++++++++++++++++- dom/html/HTMLDialogElement.h | 2 ++ 2 files changed, 30 insertions(+), 1 deletion(-) (limited to 'dom/html') diff --git a/dom/html/HTMLDialogElement.cpp b/dom/html/HTMLDialogElement.cpp index 1f65b602f..48666628e 100644 --- a/dom/html/HTMLDialogElement.cpp +++ b/dom/html/HTMLDialogElement.cpp @@ -6,8 +6,20 @@ #include "mozilla/dom/HTMLDialogElement.h" #include "mozilla/dom/HTMLDialogElementBinding.h" +#include "mozilla/dom/HTMLUnknownElement.h" +#include "mozilla/Preferences.h" -NS_IMPL_NS_NEW_HTML_ELEMENT(Dialog) +// Expand NS_IMPL_NS_NEW_HTML_ELEMENT(Dialog) with pref check +nsGenericHTMLElement* +NS_NewHTMLDialogElement(already_AddRefed&& aNodeInfo, + mozilla::dom::FromParser aFromParser) +{ + if (!mozilla::dom::HTMLDialogElement::IsDialogEnabled()) { + return new mozilla::dom::HTMLUnknownElement(aNodeInfo); + } + + return new mozilla::dom::HTMLDialogElement(aNodeInfo); +} namespace mozilla { namespace dom { @@ -18,6 +30,21 @@ HTMLDialogElement::~HTMLDialogElement() NS_IMPL_ELEMENT_CLONE(HTMLDialogElement) +bool +HTMLDialogElement::IsDialogEnabled() +{ + static bool isDialogEnabled = false; + static bool added = false; + + if (!added) { + Preferences::AddBoolVarCache(&isDialogEnabled, + "dom.dialog_element.enabled"); + added = true; + } + + return isDialogEnabled; +} + void HTMLDialogElement::Close(const mozilla::dom::Optional& aReturnValue) { diff --git a/dom/html/HTMLDialogElement.h b/dom/html/HTMLDialogElement.h index 2222cd2f7..efa319f3c 100644 --- a/dom/html/HTMLDialogElement.h +++ b/dom/html/HTMLDialogElement.h @@ -26,6 +26,8 @@ public: virtual nsresult Clone(mozilla::dom::NodeInfo* aNodeInfo, nsINode** aResult) const override; + static bool IsDialogEnabled(); + bool Open() const { return GetBoolAttr(nsGkAtoms::open); } void SetOpen(bool aOpen, ErrorResult& aError) { -- cgit v1.2.3