Exemplo n.º 1
0
void MarkupAccumulator::serializeNodesWithNamespaces(Node& targetNode, EChildrenOnly childrenOnly, const Namespaces* namespaces, Vector<QualifiedName>* tagNamesToSkip)
{
    if (tagNamesToSkip) {
        for (size_t i = 0; i < tagNamesToSkip->size(); ++i) {
            if (targetNode.hasTagName(tagNamesToSkip->at(i)))
                return;
        }
    }

    Namespaces namespaceHash;
    if (namespaces)
        namespaceHash = *namespaces;

    if (!childrenOnly)
        appendStartTag(targetNode, &namespaceHash);

    if (!(serializeAsHTMLDocument(targetNode) && elementCannotHaveEndTag(targetNode))) {
        Node* current = isHTMLTemplateElement(targetNode) ? toHTMLTemplateElement(targetNode).content()->firstChild() : targetNode.firstChild();
        for ( ; current; current = current->nextSibling())
            serializeNodesWithNamespaces(*current, IncludeNode, &namespaceHash, tagNamesToSkip);
    }

    if (!childrenOnly)
        appendEndTag(targetNode);
}
Exemplo n.º 2
0
DocumentFragment* createFragmentForInnerOuterHTML(
    const String& markup,
    Element* contextElement,
    ParserContentPolicy parserContentPolicy,
    const char* method,
    ExceptionState& exceptionState) {
  DCHECK(contextElement);
  Document& document = isHTMLTemplateElement(*contextElement)
                           ? contextElement->document().ensureTemplateDocument()
                           : contextElement->document();
  DocumentFragment* fragment = DocumentFragment::create(document);

  if (document.isHTMLDocument()) {
    fragment->parseHTML(markup, contextElement, parserContentPolicy);
    return fragment;
  }

  bool wasValid =
      fragment->parseXML(markup, contextElement, parserContentPolicy);
  if (!wasValid) {
    exceptionState.throwDOMException(SyntaxError,
                                     "The provided markup is invalid XML, and "
                                     "therefore cannot be inserted into an XML "
                                     "document.");
    return nullptr;
  }
  return fragment;
}
Exemplo n.º 3
0
void HTMLConstructionSite::insertTextNode(const String& string, WhitespaceMode whitespaceMode)
{
    HTMLConstructionSiteTask dummyTask(HTMLConstructionSiteTask::Insert);
    dummyTask.parent = currentNode();

    // FIXME: This probably doesn't need to be done both here and in insert(Task).
    if (isHTMLTemplateElement(*dummyTask.parent))
        dummyTask.parent = toHTMLTemplateElement(dummyTask.parent.get())->content();

    // Unclear when parent != case occurs. Somehow we insert text into two separate
    // nodes while processing the same Token. When it happens we have to flush the
    // pending text into the task queue before making more.
    if (!m_pendingText.isEmpty() && (m_pendingText.parent != dummyTask.parent))
        flushPendingText();
    m_pendingText.append(dummyTask.parent, string, whitespaceMode);
}
Exemplo n.º 4
0
    bool traverseTree(Node* rootNode, WillBeHeapVector<RawPtrWillBeMember<Node>, initialNodeVectorSize>* partiallyDependentNodes)
    {
        // To make each minor GC time bounded, we might need to give up
        // traversing at some point for a large DOM tree. That being said,
        // I could not observe the need even in pathological test cases.
        for (Node& node : NodeTraversal::startsAt(rootNode)) {
            if (node.containsWrapper()) {
                if (!node.isV8CollectableDuringMinorGC()) {
                    // This node is not in the new space of V8. This indicates that
                    // the minor GC cannot anyway judge reachability of this DOM tree.
                    // Thus we give up traversing the DOM tree.
                    return false;
                }
                node.clearV8CollectableDuringMinorGC();
                partiallyDependentNodes->append(&node);
            }
            if (ShadowRoot* shadowRoot = node.youngestShadowRoot()) {
                if (!traverseTree(shadowRoot, partiallyDependentNodes))
                    return false;
            } else if (node.isShadowRoot()) {
                if (ShadowRoot* shadowRoot = toShadowRoot(node).olderShadowRoot()) {
                    if (!traverseTree(shadowRoot, partiallyDependentNodes))
                        return false;
                }
            }
            // <template> has a |content| property holding a DOM fragment which we must traverse,
            // just like we do for the shadow trees above.
            if (isHTMLTemplateElement(node)) {
                if (!traverseTree(toHTMLTemplateElement(node).content(), partiallyDependentNodes))
                    return false;
            }

            // Document maintains the list of imported documents through HTMLImportsController.
            if (node.isDocumentNode()) {
                Document& document = toDocument(node);
                HTMLImportsController* controller = document.importsController();
                if (controller && document == controller->master()) {
                    for (unsigned i = 0; i < controller->loaderCount(); ++i) {
                        if (!traverseTree(controller->loaderDocumentAt(i), partiallyDependentNodes))
                            return false;
                    }
                }
            }
        }
        return true;
    }
Exemplo n.º 5
0
static inline void insert(HTMLConstructionSiteTask& task)
{
    if (isHTMLTemplateElement(*task.parent))
        task.parent = toHTMLTemplateElement(task.parent.get())->content();
    task.parent->parserAppendChild(task.child.get());
}
Exemplo n.º 6
0
inline Document& HTMLConstructionSite::ownerDocumentForCurrentNode()
{
    if (isHTMLTemplateElement(*currentNode()))
        return toHTMLTemplateElement(currentElement())->content()->document();
    return currentNode()->document();
}