Beispiel #1
0
void TreeScopeAdopter::moveTreeToNewScope(Node& root) const
{
    ASSERT(needsScopeChange());

    oldScope().guardRef();

    Document& oldDocument = oldScope().document();
    Document& newDocument = newScope().document();
    bool willMoveToNewDocument = oldDocument != newDocument;

    for (Node* node = &root; node; node = NodeTraversal::next(*node, &root)) {
        updateTreeScope(*node);

        if (willMoveToNewDocument)
            moveNodeToNewDocument(*node, oldDocument, newDocument);

        if (!node->isElementNode())
            continue;

        if (ShadowRoot* shadow = node->shadowRoot()) {
            shadow->setParentTreeScope(newScope());
            if (willMoveToNewDocument)
                moveTreeToNewDocument(*shadow, oldDocument, newDocument);
        }
    }

    oldScope().guardDeref();
}
Beispiel #2
0
inline void TreeScopeAdopter::updateTreeScope(Node& node) const
{
    ASSERT(!node.isTreeScope());
    ASSERT(node.treeScope() == oldScope());
#if !ENABLE(OILPAN)
    newScope().guardRef();
    oldScope().guardDeref();
#endif
    node.setTreeScope(m_newScope);
}
void TreeScopeAdopter::moveTreeToNewScope(Node& root) const
{
    ASSERT(needsScopeChange());

#if !ENABLE(OILPAN)
    oldScope().guardRef();
#endif

    // If an element is moved from a document and then eventually back again the collection cache for
    // that element may contain stale data as changes made to it will have updated the DOMTreeVersion
    // of the document it was moved to. By increasing the DOMTreeVersion of the donating document here
    // we ensure that the collection cache will be invalidated as needed when the element is moved back.
    Document& oldDocument = oldScope().document();
    Document& newDocument = newScope().document();
    bool willMoveToNewDocument = oldDocument != newDocument;
    AXObjectCache* axObjectCache = oldDocument.existingAXObjectCache();
    if (willMoveToNewDocument)
        oldDocument.incDOMTreeVersion();

    for (Node& node : NodeTraversal::inclusiveDescendantsOf(root)) {
        updateTreeScope(node);

        if (willMoveToNewDocument) {
            if (axObjectCache)
                axObjectCache->remove(&node);
            moveNodeToNewDocument(node, oldDocument, newDocument);
        } else if (node.hasRareData()) {
            NodeRareData* rareData = node.rareData();
            if (rareData->nodeLists())
                rareData->nodeLists()->adoptTreeScope();
        }

        if (!node.isElementNode())
            continue;

        if (node.hasSyntheticAttrChildNodes()) {
            WillBeHeapVector<RefPtrWillBeMember<Attr>>& attrs = *toElement(node).attrNodeList();
            for (unsigned i = 0; i < attrs.size(); ++i)
                moveTreeToNewScope(*attrs[i]);
        }

        for (ShadowRoot* shadow = node.youngestShadowRoot(); shadow; shadow = shadow->olderShadowRoot()) {
            shadow->setParentTreeScope(newScope());
            if (willMoveToNewDocument)
                moveTreeToNewDocument(*shadow, oldDocument, newDocument);
        }
    }

#if !ENABLE(OILPAN)
    oldScope().guardDeref();
#endif
}
Beispiel #4
0
void TreeScopeAdopter::moveTreeToNewScope(Node& root) const {
  DCHECK(needsScopeChange());

  // If an element is moved from a document and then eventually back again the
  // collection cache for that element may contain stale data as changes made to
  // it will have updated the DOMTreeVersion of the document it was moved to. By
  // increasing the DOMTreeVersion of the donating document here we ensure that
  // the collection cache will be invalidated as needed when the element is
  // moved back.
  Document& oldDocument = oldScope().document();
  Document& newDocument = newScope().document();
  bool willMoveToNewDocument = oldDocument != newDocument;
  if (willMoveToNewDocument)
    oldDocument.incDOMTreeVersion();

  for (Node& node : NodeTraversal::inclusiveDescendantsOf(root)) {
    updateTreeScope(node);

    if (willMoveToNewDocument) {
      moveNodeToNewDocument(node, oldDocument, newDocument);
    } else if (node.hasRareData()) {
      NodeRareData* rareData = node.rareData();
      if (rareData->nodeLists())
        rareData->nodeLists()->adoptTreeScope();
    }

    if (!node.isElementNode())
      continue;
    Element& element = toElement(node);

    if (HeapVector<Member<Attr>>* attrs = element.attrNodeList()) {
      for (const auto& attr : *attrs)
        moveTreeToNewScope(*attr);
    }

    for (ShadowRoot* shadow = element.youngestShadowRoot(); shadow;
         shadow = shadow->olderShadowRoot()) {
      shadow->setParentTreeScope(newScope());
      if (willMoveToNewDocument)
        moveTreeToNewDocument(*shadow, oldDocument, newDocument);
    }
  }
  if (!willMoveToNewDocument)
    return;
  oldDocument.didMoveTreeToNewDocument(root);
}
Beispiel #5
0
inline void TreeScopeAdopter::updateTreeScope(Node& node) const {
  DCHECK(!node.isTreeScope());
  DCHECK(node.treeScope() == oldScope());
  node.setTreeScope(m_newScope);
}