Exemplo n.º 1
0
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
}
Exemplo n.º 2
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);
}
Exemplo n.º 3
0
// FIXME: Do we ever change tree scopes except between documents?
void TreeScopeAdopter::moveTreeToNewScope(Node* root) const
{
    ASSERT(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 = m_oldScope.documentScope();
    Document& newDocument = m_newScope.documentScope();
    bool willMoveToNewDocument = &oldDocument != &newDocument;
    if (willMoveToNewDocument) {
        oldDocument.incrementReferencingNodeCount();
        oldDocument.incDOMTreeVersion();
    }

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

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

        if (!is<Element>(*node))
            continue;

        if (node->hasSyntheticAttrChildNodes()) {
            const Vector<RefPtr<Attr>>& attrs = downcast<Element>(*node).attrNodeList();
            for (unsigned i = 0; i < attrs.size(); ++i)
                moveTreeToNewScope(attrs[i].get());
        }

        if (ShadowRoot* shadow = node->shadowRoot()) {
            shadow->setParentTreeScope(&m_newScope);
            if (willMoveToNewDocument)
                moveShadowTreeToNewDocument(shadow, &oldDocument, &newDocument);
        }
    }

    if (willMoveToNewDocument)
        oldDocument.decrementReferencingNodeCount();
}
Exemplo n.º 4
0
void TreeScopeAdopter::moveTreeToNewScope(Node* root) const
{
    ASSERT(needsScopeChange());

    m_oldScope->guardRef();

    // 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 = m_oldScope->documentScope();
    Document* newDocument = m_newScope->documentScope();
    bool willMoveToNewDocument = oldDocument != newDocument;
    if (oldDocument && willMoveToNewDocument)
        oldDocument->incDOMTreeVersion();

    for (Node* node = root; node; node = NodeTraversal::next(node, 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;

        if (node->hasSyntheticAttrChildNodes()) {
            const Vector<RefPtr<Attr> >& attrs = toElement(node)->attrNodeList();
            for (unsigned i = 0; i < attrs.size(); ++i)
                moveTreeToNewScope(attrs[i].get());
        }

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

    m_oldScope->guardDeref();
}