Bug 1076784 - Don't remove binding when shadow root host is removed from tree. r=smaug
authorWilliam Chen <wchen@mozilla.com>
Fri, 03 Oct 2014 18:32:05 -0700
changeset 208797 099906f74b62e32dda1273823d9de076abf19158
parent 208796 8340783e3145a8c8e6d7d363905066f7e4235d6d
child 208798 bd8f5d90d58e1607444eb79106c9002254e02394
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewerssmaug
bugs1076784
milestone35.0a1
Bug 1076784 - Don't remove binding when shadow root host is removed from tree. r=smaug
content/base/src/Element.cpp
content/base/src/nsGenericDOMDataNode.cpp
layout/reftests/webcomponents/reftest.list
layout/reftests/webcomponents/remove-append-shadow-host-1-ref.html
layout/reftests/webcomponents/remove-append-shadow-host-1.html
--- a/content/base/src/Element.cpp
+++ b/content/base/src/Element.cpp
@@ -1484,17 +1484,19 @@ Element::UnbindFromTree(bool aDeep, bool
 
     // Begin keeping track of our subtree root.
     SetSubtreeRootPointer(aNullParent ? this : mParent->SubtreeRoot());
   }
 
   if (document) {
     // Notify XBL- & nsIAnonymousContentCreator-generated
     // anonymous content that the document is changing.
-    if (HasFlag(NODE_MAY_BE_IN_BINDING_MNGR)) {
+    // Unlike XBL, bindings for web components shadow DOM
+    // do not get uninstalled.
+    if (HasFlag(NODE_MAY_BE_IN_BINDING_MNGR) && !GetShadowRoot()) {
       nsContentUtils::AddScriptRunner(
         new RemoveFromBindingManagerRunnable(document->BindingManager(), this,
                                              document));
     }
 
     document->ClearBoxObjectFor(this);
 
     if (GetCustomElementData()) {
--- a/content/base/src/nsGenericDOMDataNode.cpp
+++ b/content/base/src/nsGenericDOMDataNode.cpp
@@ -581,19 +581,21 @@ nsGenericDOMDataNode::UnbindFromTree(boo
 
   if (aNullParent || !mParent->IsInShadowTree()) {
     UnsetFlags(NODE_IS_IN_SHADOW_TREE);
 
     // Begin keeping track of our subtree root.
     SetSubtreeRootPointer(aNullParent ? this : mParent->SubtreeRoot());
   }
 
-  if (document) {
+  if (document && !GetContainingShadow()) {
     // Notify XBL- & nsIAnonymousContentCreator-generated
     // anonymous content that the document is changing.
+    // Unlike XBL, bindings for web components shadow DOM
+    // do not get uninstalled.
     if (HasFlag(NODE_MAY_BE_IN_BINDING_MNGR)) {
       nsContentUtils::AddScriptRunner(
         new RemoveFromBindingManagerRunnable(document->BindingManager(), this,
                                              document));
     }
   }
 
   nsDataSlots *slots = GetExistingDataSlots();
--- a/layout/reftests/webcomponents/reftest.list
+++ b/layout/reftests/webcomponents/reftest.list
@@ -11,8 +11,9 @@ pref(dom.webcomponents.enabled,true) == 
 pref(dom.webcomponents.enabled,true) == remove-insertion-point-1.html remove-insertion-point-1-ref.html
 pref(dom.webcomponents.enabled,true) == nested-insertion-point-1.html nested-insertion-point-1-ref.html
 pref(dom.webcomponents.enabled,true) == basic-shadow-element-1.html basic-shadow-element-1-ref.html
 pref(dom.webcomponents.enabled,true) == nested-shadow-element-1.html nested-shadow-element-1-ref.html
 pref(dom.webcomponents.enabled,true) == update-dist-node-descendants-1.html update-dist-node-descendants-1-ref.html
 pref(dom.webcomponents.enabled,true) random-if(B2G&&browserIsRemote) == input-transition-1.html input-transition-1-ref.html # Failure on B2G emulator due to Bug 1018381
 pref(dom.webcomponents.enabled,true) == dynamic-insertion-point-distribution-1.html dynamic-insertion-point-distribution-1-ref.html
 pref(dom.webcomponents.enabled,true) == dynamic-insertion-point-distribution-2.html dynamic-insertion-point-distribution-2-ref.html
+pref(dom.webcomponents.enabled,true) == remove-append-shadow-host-1.html remove-append-shadow-host-1-ref.html
new file mode 100644
--- /dev/null
+++ b/layout/reftests/webcomponents/remove-append-shadow-host-1-ref.html
@@ -0,0 +1,6 @@
+<!DOCTYPE html>
+<html>
+  <body>
+    <div>inside shadow DOM</div>
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/webcomponents/remove-append-shadow-host-1.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html>
+  <head>
+  </head>
+  <body>
+    <div id="container"><div id="host"></div></div>
+    <script>
+      var host = document.getElementById("host");
+      var root = host.createShadowRoot();
+      root.innerHTML = 'inside shadow DOM';
+
+      var container = document.getElementById("container");
+      container.removeChild(host);
+      container.appendChild(host);
+    </script>
+  </body>
+</html>