Changeset 189906 in webkit


Ignore:
Timestamp:
Sep 16, 2015 11:12:06 PM (9 years ago)
Author:
rniwa@webkit.org
Message:

removeShadow shouldn't call ChildNodeRemovalNotifier with the shadow host as the removal point
https://bugs.webkit.org/show_bug.cgi?id=149244

Reviewed by Antti Koivisto.

Since a shadow host is in a different tree than nodes in its shadow tree, it's incorrect to call
removedFrom with the shadow host as the removal point. This causes HTMLSlotElement::removedFrom
which will be added in the bug 149241 to call methods on a wrong ShadowRoot.

We still keep the ad-hoc behavior of using the shadow host as the insertion/removal point when
calling insertedInto and removedFrom on the shadow root itself to update the InDocument node flag.
We may want to re-visit this design in the future.

No new tests since I couldn't quite create a reduction. However, tests I'm adding in the bug 149241
will crash without this change.

I separated this patch from the bug 149241 to isolate the high-risk code change here.

  • dom/Element.cpp:

(WebCore::Element::addShadowRoot): Call insertedInto on ShadowRoot, and then call it on all its
children separately with the insertion point set to the shadow root since insertedInto relies on
insertion point's inDocument flag to be true when the shadow host is in the document.
(WebCore::Element::removeShadowRoot): Ditto in the reverse order.

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r189905 r189906  
     12015-09-16  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        removeShadow shouldn't call ChildNodeRemovalNotifier with the shadow host as the removal point
     4        https://bugs.webkit.org/show_bug.cgi?id=149244
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Since a shadow host is in a different tree than nodes in its shadow tree, it's incorrect to call
     9        removedFrom with the shadow host as the removal point. This causes HTMLSlotElement::removedFrom
     10        which will be added in the bug 149241 to call methods on a wrong ShadowRoot.
     11
     12        We still keep the ad-hoc behavior of using the shadow host as the insertion/removal point when
     13        calling insertedInto and removedFrom on the shadow root itself to update the InDocument node flag.
     14        We may want to re-visit this design in the future.
     15
     16        No new tests since I couldn't quite create a reduction. However, tests I'm adding in the bug 149241
     17        will crash without this change.
     18
     19        I separated this patch from the bug 149241 to isolate the high-risk code change here.
     20
     21        * dom/Element.cpp:
     22        (WebCore::Element::addShadowRoot): Call insertedInto on ShadowRoot, and then call it on all its
     23        children separately with the insertion point set to the shadow root since insertedInto relies on
     24        insertion point's inDocument flag to be true when the shadow host is in the document.
     25        (WebCore::Element::removeShadowRoot): Ditto in the reverse order.
     26
    1272015-09-16  Gyuyoung Kim  <gyuyoung.kim@webkit.org>
    228
  • trunk/Source/WebCore/dom/Element.cpp

    r189896 r189906  
    16161616    shadowRoot.setParentTreeScope(&treeScope());
    16171617
    1618     NodeVector postInsertionNotificationTargets;
    1619     notifyChildNodeInserted(*this, shadowRoot, postInsertionNotificationTargets);
    1620 
    1621     for (auto& target : postInsertionNotificationTargets)
    1622         target->finishedInsertingSubtree();
     1618    auto shadowRootInsertionResult = shadowRoot.insertedInto(*this);
     1619    ASSERT_UNUSED(shadowRootInsertionResult, shadowRootInsertionResult == InsertionDone);
     1620    if (auto* firstChild = shadowRoot.firstChild()) {
     1621        NodeVector postInsertionNotificationTargets;
     1622        {
     1623            NoEventDispatchAssertion assertNoEventDispatch;
     1624            for (auto* child = firstChild; child; child = child->nextSibling())
     1625                notifyChildNodeInserted(shadowRoot, *child, postInsertionNotificationTargets);
     1626        }
     1627
     1628        for (auto& target : postInsertionNotificationTargets)
     1629            target->finishedInsertingSubtree();
     1630    }
    16231631
    16241632    resetNeedsNodeRenderingTraversalSlowPath();
     
    16471655    oldRoot->setParentTreeScope(&document());
    16481656
    1649     notifyChildNodeRemoved(*this, *oldRoot);
     1657    {
     1658        NoEventDispatchAssertion assertNoEventDispatch;
     1659        for (auto* child = oldRoot->firstChild(); child; child = child->nextSibling())
     1660            notifyChildNodeRemoved(*oldRoot, *child);
     1661    }
     1662
     1663    oldRoot->removedFrom(*this);
    16501664}
    16511665
Note: See TracChangeset for help on using the changeset viewer.