Bug 1322938 - Put <dialog> element behind preference. r=smaug draft
authorTim Nguyen <ntim.bugs@gmail.com>
Fri, 23 Dec 2016 13:48:55 +0100
changeset 453434 7b6342c8b8a182f41a82506af502f7a36524bac2
parent 453433 2098f5b8b0eca14941ab5e9f8baeefebe25421c0
child 453435 a9e9d8a54cfac6be1a55a067db9aed1ce29e1bb2
push id39672
push userbmo:ntim.bugs@gmail.com
push dateFri, 23 Dec 2016 12:49:39 +0000
reviewerssmaug
bugs1322938
milestone53.0a1
Bug 1322938 - Put <dialog> element behind preference. r=smaug MozReview-Commit-ID: 3thJ5B7Znwo
dom/html/HTMLDialogElement.cpp
dom/html/HTMLDialogElement.h
dom/tests/mochitest/general/test_interfaces.html
dom/webidl/HTMLDialogElement.webidl
modules/libpref/init/all.js
testing/web-platform/meta/html/dom/interfaces.html.ini
testing/web-platform/meta/html/dom/reflection-misc.html.ini
testing/web-platform/meta/html/semantics/interactive-elements/the-dialog-element/dialog-close.html.ini
testing/web-platform/meta/html/semantics/interactive-elements/the-dialog-element/dialog-open.html.ini
testing/web-platform/meta/html/semantics/interactive-elements/the-dialog-element/dialog-showModal.html.ini
testing/web-platform/meta/html/semantics/interfaces.html.ini
--- a/dom/html/HTMLDialogElement.cpp
+++ b/dom/html/HTMLDialogElement.cpp
@@ -1,28 +1,55 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #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<mozilla::dom::NodeInfo>&& 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 {
 
 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<nsAString>& aReturnValue)
 {
   if (!Open()) {
     return;
   }
   if (aReturnValue.WasPassed()) {
     SetReturnValue(aReturnValue.Value());
--- a/dom/html/HTMLDialogElement.h
+++ b/dom/html/HTMLDialogElement.h
@@ -21,16 +21,18 @@ public:
   explicit HTMLDialogElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo) : nsGenericHTMLElement(aNodeInfo)
   {
   }
 
   NS_IMPL_FROMCONTENT_HTML_WITH_TAG(HTMLDialogElement, dialog)
 
   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)
   {
     SetHTMLBoolAttr(nsGkAtoms::open, aOpen, aError);
   }
 
   void GetReturnValue(nsAString& aReturnValue)
   {
--- a/dom/tests/mochitest/general/test_interfaces.html
+++ b/dom/tests/mochitest/general/test_interfaces.html
@@ -442,17 +442,17 @@ var interfaceNamesInGlobalScope =
     "HTMLContentElement",
 // IMPORTANT: Do not change this list without review from a DOM peer!
     "HTMLDataElement",
 // IMPORTANT: Do not change this list without review from a DOM peer!
     "HTMLDataListElement",
 // IMPORTANT: Do not change this list without review from a DOM peer!
     "HTMLDetailsElement",
 // IMPORTANT: Do not change this list without review from a DOM peer!
-    "HTMLDialogElement",
+    {name: "HTMLDialogElement", disabled: true},
 // IMPORTANT: Do not change this list without review from a DOM peer!
     "HTMLDirectoryElement",
 // IMPORTANT: Do not change this list without review from a DOM peer!
     "HTMLDivElement",
 // IMPORTANT: Do not change this list without review from a DOM peer!
     "HTMLDListElement",
 // IMPORTANT: Do not change this list without review from a DOM peer!
     "HTMLDocument",
--- a/dom/webidl/HTMLDialogElement.webidl
+++ b/dom/webidl/HTMLDialogElement.webidl
@@ -6,16 +6,17 @@
  * The origin of this IDL file is
  * https://html.spec.whatwg.org/multipage/forms.html#the-dialog-element
  *
  * © Copyright 2004-2011 Apple Computer, Inc., Mozilla Foundation, and
  * Opera Software ASA. You are granted a license to use, reproduce
  * and create derivative works of this document.
  */
 
+[Pref="dom.dialog_element.enabled"]
 interface HTMLDialogElement : HTMLElement {
   [SetterThrows] attribute boolean open;
   attribute DOMString returnValue;
 
   void show();
   [Throws] void showModal();
 
   void close(optional DOMString returnValue);
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -5422,16 +5422,19 @@ pref("narrate.filter-voices", true);
 // Whether to allow, on a Linux system that doesn't support the necessary sandboxing
 // features, loading Gecko Media Plugins unsandboxed.  However, EME CDMs will not be
 // loaded without sandboxing even if this pref is changed.
 pref("media.gmp.insecure.allow", false);
 #endif
 
 pref("dom.audiochannel.mutedByDefault", false);
 
+// HTML <dialog> element
+pref("dom.dialog_element.enabled", false);
+
 // Secure Element API
 #ifdef MOZ_SECUREELEMENT
 pref("dom.secureelement.enabled", false);
 #endif
 
 // Allow control characters appear in composition string.
 // When this is false, control characters except
 // CHARACTER TABULATION (horizontal tab) are removed from
@@ -5553,9 +5556,8 @@ pref("dom.storageManager.enabled", false
 // a single web page in a row, all following authentication dialogs will
 // be blocked (automatically canceled) for that page. The counter resets
 // when the page is reloaded. To turn this feature off, just set the limit to 0.
 pref("prompts.authentication_dialog_abuse_limit", 3);
 
 // Enable the Storage management in about:preferences and persistent-storage permission request
 // To enable the DOM implementation, turn on "dom.storageManager.enabled"
 pref("browser.storageManager.enabled", false);
-
--- a/testing/web-platform/meta/html/dom/interfaces.html.ini
+++ b/testing/web-platform/meta/html/dom/interfaces.html.ini
@@ -1,11 +1,11 @@
 [interfaces.html]
   type: testharness
-  prefs: [dom.forms.inputmode:true]
+  prefs: [dom.forms.inputmode:true, dom.dialog_element.enabled:true]
   [Document interface: attribute domain]
     expected: FAIL
 
   [Document interface: attribute cookie]
     expected: FAIL
 
   [Document interface: attribute body]
     expected: FAIL
--- a/testing/web-platform/meta/html/dom/reflection-misc.html.ini
+++ b/testing/web-platform/meta/html/dom/reflection-misc.html.ini
@@ -1,10 +1,11 @@
 [reflection-misc.html]
   type: testharness
+  prefs: [dom.dialog_element.enabled: true]
   [html.tabIndex: setAttribute() to object "3" followed by getAttribute()]
     expected: FAIL
 
   [html.tabIndex: setAttribute() to object "3" followed by IDL get]
     expected: FAIL
 
   [script.tabIndex: setAttribute() to object "3" followed by getAttribute()]
     expected: FAIL
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/meta/html/semantics/interactive-elements/the-dialog-element/dialog-close.html.ini
@@ -0,0 +1,3 @@
+[dialog-close.html]
+  type: testharness
+  prefs: [dom.dialog_element.enabled:true]
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/meta/html/semantics/interactive-elements/the-dialog-element/dialog-open.html.ini
@@ -0,0 +1,3 @@
+[dialog-open.html]
+  type: testharness
+  prefs: [dom.dialog_element.enabled:true]
--- a/testing/web-platform/meta/html/semantics/interactive-elements/the-dialog-element/dialog-showModal.html.ini
+++ b/testing/web-platform/meta/html/semantics/interactive-elements/the-dialog-element/dialog-showModal.html.ini
@@ -1,17 +1,17 @@
 [dialog-showModal.html]
   type: testharness
+  prefs: [dom.dialog_element.enabled:true]
   [dialog element: showModal()]
     expected: FAIL
 
   [when opening multiple dialogs, only the newest one is non-inert]
     expected: FAIL
 
   [opening dialog without focusable children]
     expected: FAIL
 
   [opening dialog with multiple focusable children]
     expected: FAIL
 
   [opening dialog with multiple focusable children, one having the autofocus attribute]
     expected: FAIL
-
--- a/testing/web-platform/meta/html/semantics/interfaces.html.ini
+++ b/testing/web-platform/meta/html/semantics/interfaces.html.ini
@@ -1,10 +1,11 @@
 [interfaces.html]
   type: testharness
+  prefs: [dom.dialog_element.enabled: true]
   [Interfaces for image]
     expected: FAIL
 
   [Interfaces for keygen]
     expected: FAIL
 
   [Interfaces for marquee]
     expected: FAIL