Bug 1423583: Fix IsInSameAnonymousTree in Shadow DOM. r?smaug draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Thu, 07 Dec 2017 20:04:25 +0100
changeset 709241 2c22ff1a7e70aa9cdc26bad9533d3ef8f396f897
parent 709185 3b129283c725e758856779ae64b9229d4f82d3eb
child 743357 52a14836ec9540dafd3115e9f0cd7a6d747a39eb
push id92573
push userbmo:emilio@crisal.io
push dateThu, 07 Dec 2017 19:08:21 +0000
reviewerssmaug
bugs1423583
milestone59.0a1
Bug 1423583: Fix IsInSameAnonymousTree in Shadow DOM. r?smaug MozReview-Commit-ID: 1EnQ7G1drfC
dom/base/nsContentUtils.cpp
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -5450,24 +5450,28 @@ nsContentUtils::IsInSameAnonymousTree(co
      * nodes in the same anonymous subtree as it will have a null
      * bindingParent.
      *
      * XXXbz strictly speaking, that's not true for attribute nodes.
      */
     return aContent->GetBindingParent() == nullptr;
   }
 
-  const nsIContent* nodeAsContent = static_cast<const nsIContent*>(aNode);
-
-  // For nodes in a shadow tree, it is insufficient to simply compare
-  // the binding parent because a node may host multiple ShadowRoots,
-  // thus nodes in different shadow tree may have the same binding parent.
-  if (aNode->IsInShadowTree()) {
-    return nodeAsContent->GetContainingShadow() ==
-      aContent->GetContainingShadow();
+  const nsIContent* nodeAsContent = aNode->AsContent();
+
+  // NOTE(emilio): This check below is not technically required right now, since
+  // there are no multiple shadow roots per element anymore, but will be if we
+  // ever move Shadow DOM outside of XBL.
+  if (aNode->IsInShadowTree() || aContent->IsInShadowTree()) {
+    // FIXME(emilio): We can't early return here because we propagate the
+    // containing shadow across native anonymous subtrees... It's not clear what
+    // the right thing to do here is of course, should we just clear it out?
+    if (nodeAsContent->GetContainingShadow() != aContent->GetContainingShadow()) {
+      return false;
+    }
   }
 
   return nodeAsContent->GetBindingParent() == aContent->GetBindingParent();
 }
 
 /* static */
 void
 nsContentUtils::NotifyInstalledMenuKeyboardListener(bool aInstalling)