Bug 1465592 - Enable Shadow DOM unconditionally in chrome documents;r=smaug
authorBrian Grinstead <bgrinstead@mozilla.com>
Thu, 20 Sep 2018 18:18:32 +0000
changeset 437487 80ccc40bdd0a725ecbb86d4a891345934b14deab
parent 437486 7b083f358c81e63473537145be12127708c4c550
child 437488 20d5ba6677f5a9167e3cfe1963617c4e05db81f6
push id69689
push userbgrinstead@mozilla.com
push dateThu, 20 Sep 2018 18:19:02 +0000
treeherderautoland@80ccc40bdd0a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1465592
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1465592 - Enable Shadow DOM unconditionally in chrome documents;r=smaug Differential Revision: https://phabricator.services.mozilla.com/D6278
dom/base/Element.cpp
dom/base/nsDocument.cpp
dom/tests/mochitest/webcomponents/test_xul_custom_element.xul
--- a/dom/base/Element.cpp
+++ b/dom/base/Element.cpp
@@ -1177,17 +1177,18 @@ Element::GetShadowRootByMode() const
 // https://dom.spec.whatwg.org/#dom-element-attachshadow
 already_AddRefed<ShadowRoot>
 Element::AttachShadow(const ShadowRootInit& aInit, ErrorResult& aError)
 {
   /**
    * 1. If context object’s namespace is not the HTML namespace,
    *    then throw a "NotSupportedError" DOMException.
    */
-  if (!IsHTMLElement()) {
+  if (!IsHTMLElement() &&
+      !(XRE_IsParentProcess() && IsXULElement() && nsContentUtils::AllowXULXBLForPrincipal(NodePrincipal()))) {
     aError.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
     return nullptr;
   }
 
   /**
    * 2. If context object’s local name is not
    *      a valid custom element name, "article", "aside", "blockquote",
    *      "body", "div", "footer", "h1", "h2", "h3", "h4", "h5", "h6",
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -2158,17 +2158,18 @@ nsDocument::Init()
   NS_ENSURE_TRUE(mNodeInfo, NS_ERROR_OUT_OF_MEMORY);
   MOZ_ASSERT(mNodeInfo->NodeType() == DOCUMENT_NODE,
              "Bad NodeType in aNodeInfo");
 
   NS_ASSERTION(OwnerDoc() == this, "Our nodeinfo is busted!");
 
   // Set this when document is initialized and value stays the same for the
   // lifetime of the document.
-  mIsShadowDOMEnabled = nsContentUtils::IsShadowDOMEnabled();
+  mIsShadowDOMEnabled = nsContentUtils::IsShadowDOMEnabled() ||
+    (XRE_IsParentProcess() && AllowXULXBL());
 
   // If after creation the owner js global is not set for a document
   // we use the default compartment for this document, instead of creating
   // wrapper in some random compartment when the document is exposed to js
   // via some events.
   nsCOMPtr<nsIGlobalObject> global = xpc::NativeGlobal(xpc::PrivilegedJunkScope());
   NS_ENSURE_TRUE(global, NS_ERROR_FAILURE);
   mScopeObject = do_GetWeakReference(global);
--- a/dom/tests/mochitest/webcomponents/test_xul_custom_element.xul
+++ b/dom/tests/mochitest/webcomponents/test_xul_custom_element.xul
@@ -26,16 +26,18 @@
       let range = doc.createRange();
       range.selectNodeContents(doc.firstChild);
       return range.extractContents();
     }
 
     class TestCustomElement extends XULElement {
       constructor() {
         super();
+
+        this.attachShadow({mode: "open"});
       }
 
       connectedCallback() {
         this.textContent = "foo";
       }
     }
 
     customElements.define("test-custom-element", TestCustomElement);
@@ -82,16 +84,17 @@
 
     customElements.setElementCreationCallback(
       "test-custom-element-3", () => customElements.define("test-custom-element-3", TestCustomElement3));
 
     const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
 
     function basicCustomElementCreate() {
       let element = document.createElementNS(XUL_NS, "test-custom-element");
+      ok(element.shadowRoot, "Shadow DOM works even with pref off");
       document.querySelector("#content").appendChild(element);
       is(element.textContent, "foo", "Should have set the textContent");
       ok(element instanceof TestCustomElement, "Should be an instance of TestCustomElement");
 
       let element2 = element.cloneNode(false);
       is(element2.textContent, "", "Shouldn't have cloned the textContent");
       document.querySelector("#content").appendChild(element2);
       is(element2.textContent, "foo", "Should have set the textContent");