diff --git a/dom/html/HTMLButtonElement.cpp b/dom/html/HTMLButtonElement.cpp
index a443676a6f95..b71e15a5be7e 100644
--- a/dom/html/HTMLButtonElement.cpp
+++ b/dom/html/HTMLButtonElement.cpp
@@ -139,7 +139,7 @@ bool HTMLButtonElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
}
if (aAttribute == nsGkAtoms::formmethod) {
- if (StaticPrefs::dom_dialog_element_enabled()) {
+ if (StaticPrefs::dom_dialog_element_enabled() || IsInChromeDocument()) {
return aResult.ParseEnumValue(aValue, kFormMethodTableDialogEnabled,
false);
}
diff --git a/dom/html/HTMLDialogElement.cpp b/dom/html/HTMLDialogElement.cpp
index 09b00d526363..ebfbd4a60d5b 100644
--- a/dom/html/HTMLDialogElement.cpp
+++ b/dom/html/HTMLDialogElement.cpp
@@ -16,11 +16,11 @@ nsGenericHTMLElement* NS_NewHTMLDialogElement(
mozilla::dom::FromParser aFromParser) {
RefPtr nodeInfo(aNodeInfo);
auto* nim = nodeInfo->NodeInfoManager();
- if (!mozilla::dom::HTMLDialogElement::IsDialogEnabled()) {
- return new (nim) mozilla::dom::HTMLUnknownElement(nodeInfo.forget());
+ bool isChromeDocument = nsContentUtils::IsChromeDoc(nodeInfo->GetDocument());
+ if (mozilla::StaticPrefs::dom_dialog_element_enabled() || isChromeDocument) {
+ return new (nim) mozilla::dom::HTMLDialogElement(nodeInfo.forget());
}
-
- return new (nim) mozilla::dom::HTMLDialogElement(nodeInfo.forget());
+ return new (nim) mozilla::dom::HTMLUnknownElement(nodeInfo.forget());
}
namespace mozilla {
@@ -30,8 +30,10 @@ HTMLDialogElement::~HTMLDialogElement() = default;
NS_IMPL_ELEMENT_CLONE(HTMLDialogElement)
-bool HTMLDialogElement::IsDialogEnabled() {
- return StaticPrefs::dom_dialog_element_enabled();
+bool HTMLDialogElement::IsDialogEnabled(JSContext* aCx,
+ JS::Handle aObj) {
+ return StaticPrefs::dom_dialog_element_enabled() ||
+ nsContentUtils::IsSystemCaller(aCx);
}
void HTMLDialogElement::Close(
diff --git a/dom/html/HTMLDialogElement.h b/dom/html/HTMLDialogElement.h
index 8e0b059cba60..430b6b1ce0f6 100644
--- a/dom/html/HTMLDialogElement.h
+++ b/dom/html/HTMLDialogElement.h
@@ -25,7 +25,7 @@ class HTMLDialogElement final : public nsGenericHTMLElement {
nsresult Clone(dom::NodeInfo* aNodeInfo, nsINode** aResult) const override;
- static bool IsDialogEnabled();
+ static bool IsDialogEnabled(JSContext* aCx, JS::Handle aObj);
bool Open() const { return GetBoolAttr(nsGkAtoms::open); }
void SetOpen(bool aOpen, ErrorResult& aError) {
diff --git a/dom/html/HTMLFormElement.cpp b/dom/html/HTMLFormElement.cpp
index 146d5a54f963..411771576eb0 100644
--- a/dom/html/HTMLFormElement.cpp
+++ b/dom/html/HTMLFormElement.cpp
@@ -338,7 +338,7 @@ bool HTMLFormElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
nsAttrValue& aResult) {
if (aNamespaceID == kNameSpaceID_None) {
if (aAttribute == nsGkAtoms::method) {
- if (StaticPrefs::dom_dialog_element_enabled()) {
+ if (StaticPrefs::dom_dialog_element_enabled() || IsInChromeDocument()) {
return aResult.ParseEnumValue(aValue, kFormMethodTableDialogEnabled,
false);
}
diff --git a/dom/html/HTMLInputElement.cpp b/dom/html/HTMLInputElement.cpp
index 004ae1bf4f62..118dc7d592db 100644
--- a/dom/html/HTMLInputElement.cpp
+++ b/dom/html/HTMLInputElement.cpp
@@ -5112,7 +5112,7 @@ bool HTMLInputElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
return ParseAlignValue(aValue, aResult);
}
if (aAttribute == nsGkAtoms::formmethod) {
- if (StaticPrefs::dom_dialog_element_enabled()) {
+ if (StaticPrefs::dom_dialog_element_enabled() || IsInChromeDocument()) {
return aResult.ParseEnumValue(aValue, kFormMethodTableDialogEnabled,
false);
}
diff --git a/dom/webidl/HTMLDialogElement.webidl b/dom/webidl/HTMLDialogElement.webidl
index 38b035f24773..3eb80634ecb1 100644
--- a/dom/webidl/HTMLDialogElement.webidl
+++ b/dom/webidl/HTMLDialogElement.webidl
@@ -11,7 +11,7 @@
* and create derivative works of this document.
*/
-[Pref="dom.dialog_element.enabled",
+[Func="mozilla::dom::HTMLDialogElement::IsDialogEnabled",
Exposed=Window]
interface HTMLDialogElement : HTMLElement {
[HTMLConstructor] constructor();