From a52625e8a38045299dfd341486a52795d3add547 Mon Sep 17 00:00:00 2001 From: Ryosuke Niwa Date: Tue, 16 Dec 2014 19:08:54 +0000 Subject: [PATCH] Nested template contents are not cloned by document.importNode https://bugs.webkit.org/show_bug.cgi?id=137619 Reviewed by Andreas Kling. Source/WebCore: The bug was caused by Document.importNode not cloning HTMLTemplateElement's content. Fixed the bug by sharing code between Document::importNode and Node::cloneNode by generalizing Node::cloneNodeInternal, added in r177314, by taking the owner document as an argument. The most of code changes are the result of adding this argument. Document::importNode is the only function in which the actual logic changes. Note that the code to import TEXT_NODE, CDATA_SECTION_NODE, ENTITY_REFERENCE_NODE, PROCESSING_INSTRUCTION_NODE and COMMENT_NODE nodes are identical to that of cloneNode. This patch removes the call to hasValidNamespaceForElements in ELEMENT_NODE but this should not introduce an observable behavior change since all instantiated elements should have a valid namespace in the first place. Because DOCUMENT_NODE and DOCUMENT_TYPE_NODE cannot be imported and DOCUMENT_TYPE_NODE can only appear as a direct child of DOCUMENT_NODE, neither nodes nor unimplemented XPATH_NAMESPACE_NODE and XPATH_NAMESPACE_NODE can appear inside the recursive calls for ELEMENT_NODE and DOCUMENT_FRAGMENT_NODE nodes. While importNode behaves differently from cloneNode for ATTRIBUTE_NODE, namely that it merges all of its child nodes, this behavior isn't present when recursing inside ELEMENT_NODE and DOCUMENT_FRAGMENT_NODE since we are using cloneDataFromElement. Thus there should be no observable behavior changes for DOCUMENT_FRAGMENT_NODE and ELEMENT_NODE nodes either. Test: fast/dom/HTMLTemplateElement/importNode-nested-templates.html * dom/Attr.cpp: (WebCore::Attr::cloneNodeInternal): * dom/Attr.h: * dom/CDATASection.cpp: (WebCore::CDATASection::cloneNodeInternal): * dom/CDATASection.h: * dom/Comment.cpp: (WebCore::Comment::cloneNodeInternal): * dom/Comment.h: * dom/ContainerNode.cpp: (WebCore::ContainerNode::cloneChildNodes): * dom/Document.cpp: (WebCore::Document::importNode): (WebCore::Document::cloneNodeInternal): * dom/Document.h: * dom/DocumentFragment.cpp: (WebCore::DocumentFragment::cloneNodeInternal): * dom/DocumentFragment.h: * dom/DocumentType.cpp: (WebCore::DocumentType::cloneNodeInternal): * dom/DocumentType.h: * dom/Element.cpp: (WebCore::Element::cloneNodeInternal): (WebCore::Element::cloneElementWithChildren): (WebCore::Element::cloneElementWithoutChildren): (WebCore::Element::cloneElementWithoutAttributesAndChildren): * dom/Element.h: * dom/EntityReference.cpp: (WebCore::EntityReference::cloneNodeInternal): * dom/EntityReference.h: * dom/Node.h: (WebCore::Node::cloneNode): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::cloneNodeInternal): * dom/ProcessingInstruction.h: * dom/ShadowRoot.cpp: (WebCore::ShadowRoot::cloneNodeInternal): * dom/ShadowRoot.h: * dom/Text.cpp: (WebCore::Text::cloneNodeInternal): * dom/Text.h: * editing/ApplyStyleCommand.cpp: (WebCore::ApplyStyleCommand::pushDownInlineStyleAroundNode): (WebCore::ApplyStyleCommand::applyInlineStyleChange): * editing/BreakBlockquoteCommand.cpp: (WebCore::BreakBlockquoteCommand::doApply): * editing/InsertParagraphSeparatorCommand.cpp: (WebCore::InsertParagraphSeparatorCommand::cloneHierarchyUnderNewBlock): (WebCore::InsertParagraphSeparatorCommand::doApply): * editing/ModifySelectionListLevel.cpp: (WebCore::IncreaseSelectionListLevelCommand::doApply): * editing/SplitElementCommand.cpp: (WebCore::SplitElementCommand::doApply): * editing/markup.cpp: (WebCore::createFragmentFromText): * html/HTMLKeygenElement.cpp: * html/HTMLScriptElement.cpp: (WebCore::HTMLScriptElement::cloneElementWithoutAttributesAndChildren): * html/HTMLScriptElement.h: * html/HTMLTemplateElement.cpp: (WebCore::HTMLTemplateElement::cloneNodeInternal): * html/HTMLTemplateElement.h: * html/shadow/SliderThumbElement.cpp: (WebCore::SliderThumbElement::cloneElementWithoutAttributesAndChildren): * html/shadow/SliderThumbElement.h: * html/track/WebVTTElement.cpp: (WebCore::WebVTTElement::cloneElementWithoutAttributesAndChildren): * html/track/WebVTTElement.h: * svg/SVGScriptElement.cpp: (WebCore::SVGScriptElement::cloneElementWithoutAttributesAndChildren): * svg/SVGScriptElement.h: * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::buildShadowTree): (WebCore::SVGUseElement::expandUseElementsInShadowTree): LayoutTests: Added a regression test. * fast/dom/HTMLTemplateElement/importNode-nested-templates-expected.txt: Added. * fast/dom/HTMLTemplateElement/importNode-nested-templates.html: Added. Canonical link: https://commits.webkit.org/157579@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@177372 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- LayoutTests/ChangeLog | 12 ++ .../importNode-nested-templates-expected.txt | 22 ++++ .../importNode-nested-templates.html | 36 ++++++ Source/WebCore/ChangeLog | 110 ++++++++++++++++++ Source/WebCore/dom/Attr.cpp | 4 +- Source/WebCore/dom/Attr.h | 2 +- Source/WebCore/dom/CDATASection.cpp | 4 +- Source/WebCore/dom/CDATASection.h | 2 +- Source/WebCore/dom/Comment.cpp | 4 +- Source/WebCore/dom/Comment.h | 2 +- Source/WebCore/dom/ContainerNode.cpp | 5 +- Source/WebCore/dom/Document.cpp | 68 ++--------- Source/WebCore/dom/Document.h | 2 +- Source/WebCore/dom/DocumentFragment.cpp | 4 +- Source/WebCore/dom/DocumentFragment.h | 2 +- Source/WebCore/dom/DocumentType.cpp | 4 +- Source/WebCore/dom/DocumentType.h | 2 +- Source/WebCore/dom/Element.cpp | 18 +-- Source/WebCore/dom/Element.h | 8 +- Source/WebCore/dom/EntityReference.cpp | 4 +- Source/WebCore/dom/EntityReference.h | 2 +- Source/WebCore/dom/Node.h | 4 +- Source/WebCore/dom/ProcessingInstruction.cpp | 4 +- Source/WebCore/dom/ProcessingInstruction.h | 2 +- Source/WebCore/dom/ShadowRoot.cpp | 2 +- Source/WebCore/dom/ShadowRoot.h | 2 +- Source/WebCore/dom/Text.cpp | 4 +- Source/WebCore/dom/Text.h | 2 +- Source/WebCore/editing/ApplyStyleCommand.cpp | 4 +- .../editing/BreakBlockquoteCommand.cpp | 4 +- .../InsertParagraphSeparatorCommand.cpp | 4 +- .../editing/ModifySelectionListLevel.cpp | 2 +- .../WebCore/editing/SplitElementCommand.cpp | 2 +- Source/WebCore/editing/markup.cpp | 2 +- Source/WebCore/html/HTMLKeygenElement.cpp | 4 +- Source/WebCore/html/HTMLScriptElement.cpp | 4 +- Source/WebCore/html/HTMLScriptElement.h | 2 +- Source/WebCore/html/HTMLTemplateElement.cpp | 8 +- Source/WebCore/html/HTMLTemplateElement.h | 2 +- .../html/shadow/SliderThumbElement.cpp | 4 +- .../WebCore/html/shadow/SliderThumbElement.h | 2 +- Source/WebCore/html/track/WebVTTElement.cpp | 4 +- Source/WebCore/html/track/WebVTTElement.h | 2 +- Source/WebCore/svg/SVGScriptElement.cpp | 4 +- Source/WebCore/svg/SVGScriptElement.h | 2 +- Source/WebCore/svg/SVGUseElement.cpp | 4 +- 46 files changed, 266 insertions(+), 131 deletions(-) create mode 100644 LayoutTests/fast/dom/HTMLTemplateElement/importNode-nested-templates-expected.txt create mode 100644 LayoutTests/fast/dom/HTMLTemplateElement/importNode-nested-templates.html diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog index 22a495b055427..1cab148edd975 100644 --- a/LayoutTests/ChangeLog +++ b/LayoutTests/ChangeLog @@ -1,3 +1,15 @@ +2014-12-16 Ryosuke Niwa + + Nested template contents are not cloned by document.importNode + https://bugs.webkit.org/show_bug.cgi?id=137619 + + Reviewed by Andreas Kling. + + Added a regression test. + + * fast/dom/HTMLTemplateElement/importNode-nested-templates-expected.txt: Added. + * fast/dom/HTMLTemplateElement/importNode-nested-templates.html: Added. + 2014-12-16 Alexey Proskuryakov WebKit2 test expectations gardening. diff --git a/LayoutTests/fast/dom/HTMLTemplateElement/importNode-nested-templates-expected.txt b/LayoutTests/fast/dom/HTMLTemplateElement/importNode-nested-templates-expected.txt new file mode 100644 index 0000000000000..35d40dcba52ec --- /dev/null +++ b/LayoutTests/fast/dom/HTMLTemplateElement/importNode-nested-templates-expected.txt @@ -0,0 +1,22 @@ +Test that template contents are cloned when the template element is imported via importNode + +On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". + + +importedOuterTemplate = anotherDocument.importNode(outerTemplate, true) +PASS outerTemplate.ownerDocument is document +PASS importedOuterTemplate.ownerDocument is anotherDocument +PASS importedOuterTemplate.content is not outerTemplate.content +PASS importedOuterTemplate.content.childNodes.length is 1 +innerTemplate = outerTemplate.content.firstChild +importedInnerTemplate = importedOuterTemplate.content.firstChild +PASS importedInnerTemplate.outerHTML is innerTemplate.outerHTML +PASS innerTemplate.ownerDocument is not importedInnerTemplate.ownerDocument +PASS importedInnerTemplate.content is not innerTemplate.content +PASS innerTemplate.content.childNodes.length is 1 +PASS importedInnerTemplate.content.childNodes.length is 1 +PASS innerTemplate.content.firstChild.outerHTML is importedInnerTemplate.content.firstChild.outerHTML +PASS successfullyParsed is true + +TEST COMPLETE + diff --git a/LayoutTests/fast/dom/HTMLTemplateElement/importNode-nested-templates.html b/LayoutTests/fast/dom/HTMLTemplateElement/importNode-nested-templates.html new file mode 100644 index 0000000000000..e9136bf1db725 --- /dev/null +++ b/LayoutTests/fast/dom/HTMLTemplateElement/importNode-nested-templates.html @@ -0,0 +1,36 @@ + + + + + + + + + + diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog index 87191daf56123..c92709f0c5895 100644 --- a/Source/WebCore/ChangeLog +++ b/Source/WebCore/ChangeLog @@ -1,3 +1,113 @@ +2014-12-16 Ryosuke Niwa + + Nested template contents are not cloned by document.importNode + https://bugs.webkit.org/show_bug.cgi?id=137619 + + Reviewed by Andreas Kling. + + The bug was caused by Document.importNode not cloning HTMLTemplateElement's content. + + Fixed the bug by sharing code between Document::importNode and Node::cloneNode by + generalizing Node::cloneNodeInternal, added in r177314, by taking the owner document + as an argument. The most of code changes are the result of adding this argument. + + Document::importNode is the only function in which the actual logic changes. + Note that the code to import TEXT_NODE, CDATA_SECTION_NODE, ENTITY_REFERENCE_NODE, + PROCESSING_INSTRUCTION_NODE and COMMENT_NODE nodes are identical to that of cloneNode. + + This patch removes the call to hasValidNamespaceForElements in ELEMENT_NODE but this + should not introduce an observable behavior change since all instantiated elements + should have a valid namespace in the first place. + + Because DOCUMENT_NODE and DOCUMENT_TYPE_NODE cannot be imported and DOCUMENT_TYPE_NODE + can only appear as a direct child of DOCUMENT_NODE, neither nodes nor unimplemented + XPATH_NAMESPACE_NODE and XPATH_NAMESPACE_NODE can appear inside the recursive calls + for ELEMENT_NODE and DOCUMENT_FRAGMENT_NODE nodes. + + While importNode behaves differently from cloneNode for ATTRIBUTE_NODE, namely that + it merges all of its child nodes, this behavior isn't present when recursing inside + ELEMENT_NODE and DOCUMENT_FRAGMENT_NODE since we are using cloneDataFromElement. + + Thus there should be no observable behavior changes for DOCUMENT_FRAGMENT_NODE and + ELEMENT_NODE nodes either. + + Test: fast/dom/HTMLTemplateElement/importNode-nested-templates.html + + * dom/Attr.cpp: + (WebCore::Attr::cloneNodeInternal): + * dom/Attr.h: + * dom/CDATASection.cpp: + (WebCore::CDATASection::cloneNodeInternal): + * dom/CDATASection.h: + * dom/Comment.cpp: + (WebCore::Comment::cloneNodeInternal): + * dom/Comment.h: + * dom/ContainerNode.cpp: + (WebCore::ContainerNode::cloneChildNodes): + * dom/Document.cpp: + (WebCore::Document::importNode): + (WebCore::Document::cloneNodeInternal): + * dom/Document.h: + * dom/DocumentFragment.cpp: + (WebCore::DocumentFragment::cloneNodeInternal): + * dom/DocumentFragment.h: + * dom/DocumentType.cpp: + (WebCore::DocumentType::cloneNodeInternal): + * dom/DocumentType.h: + * dom/Element.cpp: + (WebCore::Element::cloneNodeInternal): + (WebCore::Element::cloneElementWithChildren): + (WebCore::Element::cloneElementWithoutChildren): + (WebCore::Element::cloneElementWithoutAttributesAndChildren): + * dom/Element.h: + * dom/EntityReference.cpp: + (WebCore::EntityReference::cloneNodeInternal): + * dom/EntityReference.h: + * dom/Node.h: + (WebCore::Node::cloneNode): + * dom/ProcessingInstruction.cpp: + (WebCore::ProcessingInstruction::cloneNodeInternal): + * dom/ProcessingInstruction.h: + * dom/ShadowRoot.cpp: + (WebCore::ShadowRoot::cloneNodeInternal): + * dom/ShadowRoot.h: + * dom/Text.cpp: + (WebCore::Text::cloneNodeInternal): + * dom/Text.h: + * editing/ApplyStyleCommand.cpp: + (WebCore::ApplyStyleCommand::pushDownInlineStyleAroundNode): + (WebCore::ApplyStyleCommand::applyInlineStyleChange): + * editing/BreakBlockquoteCommand.cpp: + (WebCore::BreakBlockquoteCommand::doApply): + * editing/InsertParagraphSeparatorCommand.cpp: + (WebCore::InsertParagraphSeparatorCommand::cloneHierarchyUnderNewBlock): + (WebCore::InsertParagraphSeparatorCommand::doApply): + * editing/ModifySelectionListLevel.cpp: + (WebCore::IncreaseSelectionListLevelCommand::doApply): + * editing/SplitElementCommand.cpp: + (WebCore::SplitElementCommand::doApply): + * editing/markup.cpp: + (WebCore::createFragmentFromText): + * html/HTMLKeygenElement.cpp: + * html/HTMLScriptElement.cpp: + (WebCore::HTMLScriptElement::cloneElementWithoutAttributesAndChildren): + * html/HTMLScriptElement.h: + * html/HTMLTemplateElement.cpp: + (WebCore::HTMLTemplateElement::cloneNodeInternal): + * html/HTMLTemplateElement.h: + * html/shadow/SliderThumbElement.cpp: + (WebCore::SliderThumbElement::cloneElementWithoutAttributesAndChildren): + * html/shadow/SliderThumbElement.h: + * html/track/WebVTTElement.cpp: + (WebCore::WebVTTElement::cloneElementWithoutAttributesAndChildren): + * html/track/WebVTTElement.h: + * svg/SVGScriptElement.cpp: + (WebCore::SVGScriptElement::cloneElementWithoutAttributesAndChildren): + * svg/SVGScriptElement.h: + * svg/SVGUseElement.cpp: + (WebCore::SVGUseElement::buildShadowTree): + (WebCore::SVGUseElement::expandUseElementsInShadowTree): + 2014-12-16 Tibor Meszaros Document.contentType implementation diff --git a/Source/WebCore/dom/Attr.cpp b/Source/WebCore/dom/Attr.cpp index 0706fd6ba6f83..afa6eb3dba80f 100644 --- a/Source/WebCore/dom/Attr.cpp +++ b/Source/WebCore/dom/Attr.cpp @@ -137,9 +137,9 @@ void Attr::setNodeValue(const String& v, ExceptionCode& ec) setValue(v, ec); } -RefPtr Attr::cloneNodeInternal(CloningOperation) +RefPtr Attr::cloneNodeInternal(Document& targetDocument, CloningOperation) { - RefPtr clone = adoptRef(new Attr(document(), qualifiedName(), value())); + RefPtr clone = adoptRef(new Attr(targetDocument, qualifiedName(), value())); cloneChildNodes(clone.get()); return clone.release(); } diff --git a/Source/WebCore/dom/Attr.h b/Source/WebCore/dom/Attr.h index 3254414bbe25f..c7a94f98f0bfb 100644 --- a/Source/WebCore/dom/Attr.h +++ b/Source/WebCore/dom/Attr.h @@ -80,7 +80,7 @@ class Attr final : public ContainerNode { virtual String nodeValue() const override { return value(); } virtual void setNodeValue(const String&, ExceptionCode&) override; - virtual RefPtr cloneNodeInternal(CloningOperation) override; + virtual RefPtr cloneNodeInternal(Document&, CloningOperation) override; virtual bool isAttributeNode() const override { return true; } virtual bool childTypeAllowed(NodeType) const override; diff --git a/Source/WebCore/dom/CDATASection.cpp b/Source/WebCore/dom/CDATASection.cpp index 9f94384dc488e..52b9fafe06df9 100644 --- a/Source/WebCore/dom/CDATASection.cpp +++ b/Source/WebCore/dom/CDATASection.cpp @@ -46,9 +46,9 @@ Node::NodeType CDATASection::nodeType() const return CDATA_SECTION_NODE; } -RefPtr CDATASection::cloneNodeInternal(CloningOperation) +RefPtr CDATASection::cloneNodeInternal(Document& targetDocument, CloningOperation) { - return create(document(), data()); + return create(targetDocument, data()); } bool CDATASection::childTypeAllowed(NodeType) const diff --git a/Source/WebCore/dom/CDATASection.h b/Source/WebCore/dom/CDATASection.h index b38d2065160c3..c78ea8a699b26 100644 --- a/Source/WebCore/dom/CDATASection.h +++ b/Source/WebCore/dom/CDATASection.h @@ -36,7 +36,7 @@ class CDATASection final : public Text { virtual String nodeName() const override; virtual NodeType nodeType() const override; - virtual RefPtr cloneNodeInternal(CloningOperation) override; + virtual RefPtr cloneNodeInternal(Document&, CloningOperation) override; virtual bool childTypeAllowed(NodeType) const override; virtual RefPtr virtualCreate(const String&) override; }; diff --git a/Source/WebCore/dom/Comment.cpp b/Source/WebCore/dom/Comment.cpp index 769434a76ca88..e0fb717c29a49 100644 --- a/Source/WebCore/dom/Comment.cpp +++ b/Source/WebCore/dom/Comment.cpp @@ -51,9 +51,9 @@ Node::NodeType Comment::nodeType() const return COMMENT_NODE; } -RefPtr Comment::cloneNodeInternal(CloningOperation) +RefPtr Comment::cloneNodeInternal(Document& targetDocument, CloningOperation) { - return create(document(), data()); + return create(targetDocument, data()); } bool Comment::childTypeAllowed(NodeType) const diff --git a/Source/WebCore/dom/Comment.h b/Source/WebCore/dom/Comment.h index b1254ba8e1bb8..c692806e1ebeb 100644 --- a/Source/WebCore/dom/Comment.h +++ b/Source/WebCore/dom/Comment.h @@ -37,7 +37,7 @@ class Comment final : public CharacterData { virtual String nodeName() const override; virtual NodeType nodeType() const override; - virtual RefPtr cloneNodeInternal(CloningOperation) override; + virtual RefPtr cloneNodeInternal(Document&, CloningOperation) override; virtual bool childTypeAllowed(NodeType) const override; }; diff --git a/Source/WebCore/dom/ContainerNode.cpp b/Source/WebCore/dom/ContainerNode.cpp index d2e7b87a9a715..e75087e0f33ce 100644 --- a/Source/WebCore/dom/ContainerNode.cpp +++ b/Source/WebCore/dom/ContainerNode.cpp @@ -765,11 +765,12 @@ void ContainerNode::childrenChanged(const ChildChange& change) invalidateNodeListAndCollectionCachesInAncestors(); } -void ContainerNode::cloneChildNodes(ContainerNode *clone) +void ContainerNode::cloneChildNodes(ContainerNode* clone) { ExceptionCode ec = 0; + Document& targetDocument = clone->document(); for (Node* child = firstChild(); child && !ec; child = child->nextSibling()) { - RefPtr clonedChild = child->cloneNodeInternal(CloningOperation::SelfWithTemplateContent); + RefPtr clonedChild = child->cloneNodeInternal(targetDocument, CloningOperation::SelfWithTemplateContent); clone->appendChild(clonedChild, ec); if (!ec && is(child)) diff --git a/Source/WebCore/dom/Document.cpp b/Source/WebCore/dom/Document.cpp index 8ebe4b7aee1a2..c3a6f379b9673 100644 --- a/Source/WebCore/dom/Document.cpp +++ b/Source/WebCore/dom/Document.cpp @@ -923,78 +923,32 @@ RefPtr Document::createCSSStyleDeclaration() RefPtr Document::importNode(Node* importedNode, bool deep, ExceptionCode& ec) { - ec = 0; - if (!importedNode) { ec = NOT_SUPPORTED_ERR; return nullptr; } switch (importedNode->nodeType()) { + case ELEMENT_NODE: case TEXT_NODE: - return createTextNode(importedNode->nodeValue()); case CDATA_SECTION_NODE: - return createCDATASection(importedNode->nodeValue(), ec); case ENTITY_REFERENCE_NODE: - return createEntityReference(importedNode->nodeName(), ec); case PROCESSING_INSTRUCTION_NODE: - return createProcessingInstruction(importedNode->nodeName(), importedNode->nodeValue(), ec); case COMMENT_NODE: - return createComment(importedNode->nodeValue()); - case ELEMENT_NODE: { - Element& oldElement = downcast(*importedNode); - // FIXME: The following check might be unnecessary. Is it possible that - // oldElement has mismatched prefix/namespace? - if (!hasValidNamespaceForElements(oldElement.tagQName())) { - ec = NAMESPACE_ERR; - return nullptr; - } - - RefPtr newElement = createElement(oldElement.tagQName(), false); - newElement->cloneDataFromElement(oldElement); - - if (deep) { - for (Node* oldChild = oldElement.firstChild(); oldChild; oldChild = oldChild->nextSibling()) { - RefPtr newChild = importNode(oldChild, true, ec); - if (ec) - return nullptr; - newElement->appendChild(newChild.release(), ec); - if (ec) - return nullptr; - } - } + case DOCUMENT_FRAGMENT_NODE: + return importedNode->cloneNodeInternal(document(), deep ? CloningOperation::Everything : CloningOperation::OnlySelf); - return newElement.release(); - } case ATTRIBUTE_NODE: + // FIXME: This will "Attr::normalize" child nodes of Attr. return Attr::create(*this, QualifiedName(nullAtom, downcast(*importedNode).name(), nullAtom), downcast(*importedNode).value()); - case DOCUMENT_FRAGMENT_NODE: { - if (importedNode->isShadowRoot()) { - // ShadowRoot nodes should not be explicitly importable. - // Either they are imported along with their host node, or created implicitly. - break; - } - DocumentFragment& oldFragment = downcast(*importedNode); - RefPtr newFragment = createDocumentFragment(); - if (deep) { - for (Node* oldChild = oldFragment.firstChild(); oldChild; oldChild = oldChild->nextSibling()) { - RefPtr newChild = importNode(oldChild, true, ec); - if (ec) - return nullptr; - newFragment->appendChild(newChild.release(), ec); - if (ec) - return nullptr; - } - } - - return newFragment.release(); - } + + case DOCUMENT_NODE: // Can't import a document into another document. + case DOCUMENT_TYPE_NODE: // FIXME: Support cloning a DocumentType node per DOM4. + break; + case ENTITY_NODE: - // FIXME: It should be possible to import these node types, however in DOM3 the DocumentType is readonly, so there isn't much sense in doing that. - // Ability to add these imported nodes to a DocumentType will be considered for addition to a future release of the DOM. - case DOCUMENT_NODE: - case DOCUMENT_TYPE_NODE: case XPATH_NAMESPACE_NODE: + ASSERT_NOT_REACHED(); // These two types of DOM nodes are not implemented. break; } ec = NOT_SUPPORTED_ERR; @@ -3207,7 +3161,7 @@ bool Document::canReplaceChild(Node* newChild, Node* oldChild) return true; } -RefPtr Document::cloneNodeInternal(CloningOperation type) +RefPtr Document::cloneNodeInternal(Document&, CloningOperation type) { RefPtr clone = cloneDocumentWithoutChildren(); clone->cloneDataFromDocument(*this); diff --git a/Source/WebCore/dom/Document.h b/Source/WebCore/dom/Document.h index e53a7d8fd15be..4a7fef24b573f 100644 --- a/Source/WebCore/dom/Document.h +++ b/Source/WebCore/dom/Document.h @@ -1311,7 +1311,7 @@ class Document : public ContainerNode, public TreeScope, public ScriptExecutionC virtual String nodeName() const override final; virtual NodeType nodeType() const override final; virtual bool childTypeAllowed(NodeType) const override final; - virtual RefPtr cloneNodeInternal(CloningOperation) override final; + virtual RefPtr cloneNodeInternal(Document&, CloningOperation) override final; void cloneDataFromDocument(const Document&); virtual void refScriptExecutionContext() override final { ref(); } diff --git a/Source/WebCore/dom/DocumentFragment.cpp b/Source/WebCore/dom/DocumentFragment.cpp index 31870c39ce613..6fe03781dc14e 100644 --- a/Source/WebCore/dom/DocumentFragment.cpp +++ b/Source/WebCore/dom/DocumentFragment.cpp @@ -71,9 +71,9 @@ bool DocumentFragment::childTypeAllowed(NodeType type) const } } -RefPtr DocumentFragment::cloneNodeInternal(CloningOperation type) +RefPtr DocumentFragment::cloneNodeInternal(Document& targetDocument, CloningOperation type) { - RefPtr clone = create(document()); + RefPtr clone = create(targetDocument); switch (type) { case CloningOperation::OnlySelf: case CloningOperation::SelfWithTemplateContent: diff --git a/Source/WebCore/dom/DocumentFragment.h b/Source/WebCore/dom/DocumentFragment.h index a3d9deb403b1e..a9d4e694407bc 100644 --- a/Source/WebCore/dom/DocumentFragment.h +++ b/Source/WebCore/dom/DocumentFragment.h @@ -48,7 +48,7 @@ class DocumentFragment : public ContainerNode { private: virtual NodeType nodeType() const override final; - virtual RefPtr cloneNodeInternal(CloningOperation) override; + virtual RefPtr cloneNodeInternal(Document&, CloningOperation) override; virtual bool childTypeAllowed(NodeType) const override; }; diff --git a/Source/WebCore/dom/DocumentType.cpp b/Source/WebCore/dom/DocumentType.cpp index e4d096d8b2dae..67e3d53843f82 100644 --- a/Source/WebCore/dom/DocumentType.cpp +++ b/Source/WebCore/dom/DocumentType.cpp @@ -51,9 +51,9 @@ Node::NodeType DocumentType::nodeType() const return DOCUMENT_TYPE_NODE; } -RefPtr DocumentType::cloneNodeInternal(CloningOperation) +RefPtr DocumentType::cloneNodeInternal(Document& documentTarget, CloningOperation) { - return create(document(), m_name, m_publicId, m_systemId); + return create(documentTarget, m_name, m_publicId, m_systemId); } } diff --git a/Source/WebCore/dom/DocumentType.h b/Source/WebCore/dom/DocumentType.h index 4c0a16d086ce0..63f9128df8440 100644 --- a/Source/WebCore/dom/DocumentType.h +++ b/Source/WebCore/dom/DocumentType.h @@ -52,7 +52,7 @@ class DocumentType final : public Node { virtual URL baseURI() const override; virtual String nodeName() const override; virtual NodeType nodeType() const override; - virtual RefPtr cloneNodeInternal(CloningOperation) override; + virtual RefPtr cloneNodeInternal(Document&, CloningOperation) override; String m_name; String m_publicId; diff --git a/Source/WebCore/dom/Element.cpp b/Source/WebCore/dom/Element.cpp index 0768c26305fd5..8e22f8802dfd0 100644 --- a/Source/WebCore/dom/Element.cpp +++ b/Source/WebCore/dom/Element.cpp @@ -289,29 +289,29 @@ DEFINE_VIRTUAL_ATTRIBUTE_EVENT_LISTENER(Element, error); DEFINE_VIRTUAL_ATTRIBUTE_EVENT_LISTENER(Element, focus); DEFINE_VIRTUAL_ATTRIBUTE_EVENT_LISTENER(Element, load); -RefPtr Element::cloneNodeInternal(CloningOperation type) +RefPtr Element::cloneNodeInternal(Document& targetDocument, CloningOperation type) { switch (type) { case CloningOperation::OnlySelf: case CloningOperation::SelfWithTemplateContent: - return cloneElementWithoutChildren(); + return cloneElementWithoutChildren(targetDocument); case CloningOperation::Everything: - return cloneElementWithChildren(); + return cloneElementWithChildren(targetDocument); } ASSERT_NOT_REACHED(); return nullptr; } -RefPtr Element::cloneElementWithChildren() +RefPtr Element::cloneElementWithChildren(Document& targetDocument) { - RefPtr clone = cloneElementWithoutChildren(); + RefPtr clone = cloneElementWithoutChildren(targetDocument); cloneChildNodes(clone.get()); return clone.release(); } -RefPtr Element::cloneElementWithoutChildren() +RefPtr Element::cloneElementWithoutChildren(Document& targetDocument) { - RefPtr clone = cloneElementWithoutAttributesAndChildren(); + RefPtr clone = cloneElementWithoutAttributesAndChildren(targetDocument); // This will catch HTML elements in the wrong namespace that are not correctly copied. // This is a sanity check as HTML overloads some of the DOM methods. ASSERT(isHTMLElement() == clone->isHTMLElement()); @@ -320,9 +320,9 @@ RefPtr Element::cloneElementWithoutChildren() return clone.release(); } -RefPtr Element::cloneElementWithoutAttributesAndChildren() +RefPtr Element::cloneElementWithoutAttributesAndChildren(Document& targetDocument) { - return document().createElement(tagQName(), false); + return targetDocument.createElement(tagQName(), false); } RefPtr Element::detachAttribute(unsigned index) diff --git a/Source/WebCore/dom/Element.h b/Source/WebCore/dom/Element.h index a4b0e3bd3afbd..1a7e1ca84c4ca 100644 --- a/Source/WebCore/dom/Element.h +++ b/Source/WebCore/dom/Element.h @@ -267,8 +267,8 @@ class Element : public ContainerNode { virtual String nodeName() const override; - RefPtr cloneElementWithChildren(); - RefPtr cloneElementWithoutChildren(); + RefPtr cloneElementWithChildren(Document&); + RefPtr cloneElementWithoutChildren(Document&); void normalizeAttributes(); String nodeNamePreservingCase() const; @@ -632,8 +632,8 @@ class Element : public ContainerNode { // cloneNode is private so that non-virtual cloneElementWithChildren and cloneElementWithoutChildren // are used instead. - virtual RefPtr cloneNodeInternal(CloningOperation) override; - virtual RefPtr cloneElementWithoutAttributesAndChildren(); + virtual RefPtr cloneNodeInternal(Document&, CloningOperation) override; + virtual RefPtr cloneElementWithoutAttributesAndChildren(Document&); void addShadowRoot(PassRefPtr); void removeShadowRoot(); diff --git a/Source/WebCore/dom/EntityReference.cpp b/Source/WebCore/dom/EntityReference.cpp index bf6a3327c9ac9..88ad6887a7865 100644 --- a/Source/WebCore/dom/EntityReference.cpp +++ b/Source/WebCore/dom/EntityReference.cpp @@ -46,9 +46,9 @@ Node::NodeType EntityReference::nodeType() const return ENTITY_REFERENCE_NODE; } -RefPtr EntityReference::cloneNodeInternal(CloningOperation) +RefPtr EntityReference::cloneNodeInternal(Document& targetDocument, CloningOperation) { - return create(document(), m_entityName); + return create(targetDocument, m_entityName); } } // namespace diff --git a/Source/WebCore/dom/EntityReference.h b/Source/WebCore/dom/EntityReference.h index a56347a8e4948..5e8da8d50b6c2 100644 --- a/Source/WebCore/dom/EntityReference.h +++ b/Source/WebCore/dom/EntityReference.h @@ -35,7 +35,7 @@ class EntityReference final : public ContainerNode { virtual String nodeName() const override; virtual NodeType nodeType() const override; - virtual RefPtr cloneNodeInternal(CloningOperation) override; + virtual RefPtr cloneNodeInternal(Document&, CloningOperation) override; String m_entityName; }; diff --git a/Source/WebCore/dom/Node.h b/Source/WebCore/dom/Node.h index af19de1a4d20a..cc18cd72b62f0 100644 --- a/Source/WebCore/dom/Node.h +++ b/Source/WebCore/dom/Node.h @@ -209,8 +209,8 @@ class Node : public EventTarget, public ScriptWrappable, public TreeShared SelfWithTemplateContent, Everything, }; - virtual RefPtr cloneNodeInternal(CloningOperation) = 0; - RefPtr cloneNode(bool deep) { return cloneNodeInternal(deep ? CloningOperation::Everything : CloningOperation::OnlySelf); } + virtual RefPtr cloneNodeInternal(Document&, CloningOperation) = 0; + RefPtr cloneNode(bool deep) { return cloneNodeInternal(document(), deep ? CloningOperation::Everything : CloningOperation::OnlySelf); } virtual const AtomicString& localName() const; virtual const AtomicString& namespaceURI() const; diff --git a/Source/WebCore/dom/ProcessingInstruction.cpp b/Source/WebCore/dom/ProcessingInstruction.cpp index f0ef9dc163763..ec8fa198d3706 100644 --- a/Source/WebCore/dom/ProcessingInstruction.cpp +++ b/Source/WebCore/dom/ProcessingInstruction.cpp @@ -79,11 +79,11 @@ Node::NodeType ProcessingInstruction::nodeType() const return PROCESSING_INSTRUCTION_NODE; } -RefPtr ProcessingInstruction::cloneNodeInternal(CloningOperation) +RefPtr ProcessingInstruction::cloneNodeInternal(Document& targetDocument, CloningOperation) { // FIXME: Is it a problem that this does not copy m_localHref? // What about other data members? - return create(document(), m_target, data()); + return create(targetDocument, m_target, data()); } void ProcessingInstruction::checkStyleSheet() diff --git a/Source/WebCore/dom/ProcessingInstruction.h b/Source/WebCore/dom/ProcessingInstruction.h index 05b0cfa489cc6..ab82f268a9e9a 100644 --- a/Source/WebCore/dom/ProcessingInstruction.h +++ b/Source/WebCore/dom/ProcessingInstruction.h @@ -58,7 +58,7 @@ class ProcessingInstruction final : public CharacterData, private CachedStyleShe virtual String nodeName() const override; virtual NodeType nodeType() const override; - virtual RefPtr cloneNodeInternal(CloningOperation) override; + virtual RefPtr cloneNodeInternal(Document&, CloningOperation) override; virtual InsertionNotificationRequest insertedInto(ContainerNode&) override; virtual void removedFrom(ContainerNode&) override; diff --git a/Source/WebCore/dom/ShadowRoot.cpp b/Source/WebCore/dom/ShadowRoot.cpp index 67764373ec0fc..ebfa4cac969b4 100644 --- a/Source/WebCore/dom/ShadowRoot.cpp +++ b/Source/WebCore/dom/ShadowRoot.cpp @@ -131,7 +131,7 @@ void ShadowRoot::childrenChanged(const ChildChange& change) invalidateDistribution(); } -RefPtr ShadowRoot::cloneNodeInternal(CloningOperation) +RefPtr ShadowRoot::cloneNodeInternal(Document&, CloningOperation) { return nullptr; // ShadowRoots should never be cloned. } diff --git a/Source/WebCore/dom/ShadowRoot.h b/Source/WebCore/dom/ShadowRoot.h index 5eea892a73f4c..e1f88a6399563 100644 --- a/Source/WebCore/dom/ShadowRoot.h +++ b/Source/WebCore/dom/ShadowRoot.h @@ -76,7 +76,7 @@ class ShadowRoot final : public DocumentFragment, public TreeScope { virtual bool childTypeAllowed(NodeType) const override; virtual void childrenChanged(const ChildChange&) override; - virtual RefPtr cloneNodeInternal(CloningOperation) override; + virtual RefPtr cloneNodeInternal(Document&, CloningOperation) override; // FIXME: This shouldn't happen. https://bugs.webkit.org/show_bug.cgi?id=88834 bool isOrphan() const { return !hostElement(); } diff --git a/Source/WebCore/dom/Text.cpp b/Source/WebCore/dom/Text.cpp index d0f3a7107ccc6..70697a4ae4162 100644 --- a/Source/WebCore/dom/Text.cpp +++ b/Source/WebCore/dom/Text.cpp @@ -169,9 +169,9 @@ Node::NodeType Text::nodeType() const return TEXT_NODE; } -RefPtr Text::cloneNodeInternal(CloningOperation) +RefPtr Text::cloneNodeInternal(Document& targetDocument, CloningOperation) { - return create(document(), data()); + return create(targetDocument, data()); } static bool isSVGShadowText(Text* text) diff --git a/Source/WebCore/dom/Text.h b/Source/WebCore/dom/Text.h index 532bd3c8f3faf..2b3d407af60de 100644 --- a/Source/WebCore/dom/Text.h +++ b/Source/WebCore/dom/Text.h @@ -64,7 +64,7 @@ class Text : public CharacterData { private: virtual String nodeName() const override; virtual NodeType nodeType() const override; - virtual RefPtr cloneNodeInternal(CloningOperation) override; + virtual RefPtr cloneNodeInternal(Document&, CloningOperation) override; virtual bool childTypeAllowed(NodeType) const override; virtual RefPtr virtualCreate(const String&); diff --git a/Source/WebCore/editing/ApplyStyleCommand.cpp b/Source/WebCore/editing/ApplyStyleCommand.cpp index 11178741a7e6e..5ccf92da59d99 100644 --- a/Source/WebCore/editing/ApplyStyleCommand.cpp +++ b/Source/WebCore/editing/ApplyStyleCommand.cpp @@ -1060,7 +1060,7 @@ void ApplyStyleCommand::pushDownInlineStyleAroundNode(EditingStyle* style, Node* continue; if (!child.contains(targetNode) && elementsToPushDown.size()) { for (size_t i = 0; i < elementsToPushDown.size(); i++) { - RefPtr wrapper = elementsToPushDown[i]->cloneElementWithoutChildren(); + RefPtr wrapper = elementsToPushDown[i]->cloneElementWithoutChildren(document()); wrapper->removeAttribute(styleAttr); surroundNodeRangeWithElement(&child, &child, wrapper); } @@ -1504,7 +1504,7 @@ void ApplyStyleCommand::applyInlineStyleChange(PassRefPtr passedStart, Pas surroundNodeRangeWithElement(startNode, endNode, createHTMLElement(document(), supTag)); if (m_styledInlineElement && addStyledElement == AddStyledElement) - surroundNodeRangeWithElement(startNode, endNode, m_styledInlineElement->cloneElementWithoutChildren()); + surroundNodeRangeWithElement(startNode, endNode, m_styledInlineElement->cloneElementWithoutChildren(document())); } float ApplyStyleCommand::computedFontSize(Node* node) diff --git a/Source/WebCore/editing/BreakBlockquoteCommand.cpp b/Source/WebCore/editing/BreakBlockquoteCommand.cpp index 294adb6893780..f6fb4aaff6769 100644 --- a/Source/WebCore/editing/BreakBlockquoteCommand.cpp +++ b/Source/WebCore/editing/BreakBlockquoteCommand.cpp @@ -131,7 +131,7 @@ void BreakBlockquoteCommand::doApply() ancestors.append(node); // Insert a clone of the top blockquote after the break. - RefPtr clonedBlockquote = downcast(*topBlockquote).cloneElementWithoutChildren(); + RefPtr clonedBlockquote = downcast(*topBlockquote).cloneElementWithoutChildren(document()); insertNodeAfter(clonedBlockquote.get(), breakNode.get()); // Clone startNode's ancestors into the cloned blockquote. @@ -140,7 +140,7 @@ void BreakBlockquoteCommand::doApply() // or clonedBlockquote if ancestors is empty). RefPtr clonedAncestor = clonedBlockquote; for (size_t i = ancestors.size(); i != 0; --i) { - RefPtr clonedChild = ancestors[i - 1]->cloneElementWithoutChildren(); + RefPtr clonedChild = ancestors[i - 1]->cloneElementWithoutChildren(document()); // Preserve list item numbering in cloned lists. if (clonedChild->isElementNode() && clonedChild->hasTagName(olTag)) { Node* listChildNode = i > 1 ? ancestors[i - 2].get() : startNode; diff --git a/Source/WebCore/editing/InsertParagraphSeparatorCommand.cpp b/Source/WebCore/editing/InsertParagraphSeparatorCommand.cpp index 606117b88aebe..82ec5349cf51f 100644 --- a/Source/WebCore/editing/InsertParagraphSeparatorCommand.cpp +++ b/Source/WebCore/editing/InsertParagraphSeparatorCommand.cpp @@ -136,7 +136,7 @@ PassRefPtr InsertParagraphSeparatorCommand::cloneHierarchyUnderNewBlock // Make clones of ancestors in between the start node and the start block. RefPtr parent = blockToInsert; for (size_t i = ancestors.size(); i != 0; --i) { - RefPtr child = ancestors[i - 1]->cloneElementWithoutChildren(); + RefPtr child = ancestors[i - 1]->cloneElementWithoutChildren(document()); // It should always be okay to remove id from the cloned elements, since the originals are not deleted. child->removeAttribute(idAttr); appendNode(child, parent); @@ -207,7 +207,7 @@ void InsertParagraphSeparatorCommand::doApply() } else if (shouldUseDefaultParagraphElement(startBlock.get())) blockToInsert = createDefaultParagraphElement(document()); else - blockToInsert = startBlock->cloneElementWithoutChildren(); + blockToInsert = startBlock->cloneElementWithoutChildren(document()); //--------------------------------------------------------------------- // Handle case when position is in the last visible position in its block, diff --git a/Source/WebCore/editing/ModifySelectionListLevel.cpp b/Source/WebCore/editing/ModifySelectionListLevel.cpp index dfce553d530ae..837ab68e6a15d 100644 --- a/Source/WebCore/editing/ModifySelectionListLevel.cpp +++ b/Source/WebCore/editing/ModifySelectionListLevel.cpp @@ -187,7 +187,7 @@ void IncreaseSelectionListLevelCommand::doApply() case InheritedListType: newParent = startListChild->parentElement(); if (newParent) - newParent = newParent->cloneElementWithoutChildren(); + newParent = newParent->cloneElementWithoutChildren(document()); break; case OrderedList: newParent = createOrderedListElement(document()); diff --git a/Source/WebCore/editing/SplitElementCommand.cpp b/Source/WebCore/editing/SplitElementCommand.cpp index 92e3b93052398..09beb851931ee 100644 --- a/Source/WebCore/editing/SplitElementCommand.cpp +++ b/Source/WebCore/editing/SplitElementCommand.cpp @@ -70,7 +70,7 @@ void SplitElementCommand::executeApply() void SplitElementCommand::doApply() { - m_element1 = m_element2->cloneElementWithoutChildren(); + m_element1 = m_element2->cloneElementWithoutChildren(document()); executeApply(); } diff --git a/Source/WebCore/editing/markup.cpp b/Source/WebCore/editing/markup.cpp index 9623c28eed236..e8dd86039bf3c 100644 --- a/Source/WebCore/editing/markup.cpp +++ b/Source/WebCore/editing/markup.cpp @@ -798,7 +798,7 @@ PassRefPtr createFragmentFromText(Range& context, const String fillContainerFromString(fragment.get(), s); } else { if (useClonesOfEnclosingBlock) - element = block->cloneElementWithoutChildren(); + element = block->cloneElementWithoutChildren(document); else element = createDefaultParagraphElement(document); fillContainerFromString(element.get(), s); diff --git a/Source/WebCore/html/HTMLKeygenElement.cpp b/Source/WebCore/html/HTMLKeygenElement.cpp index 86f9a6cb3ac04..d398ead139142 100644 --- a/Source/WebCore/html/HTMLKeygenElement.cpp +++ b/Source/WebCore/html/HTMLKeygenElement.cpp @@ -58,9 +58,9 @@ class KeygenSelectElement final : public HTMLSelectElement { } private: - virtual RefPtr cloneElementWithoutAttributesAndChildren() override + virtual RefPtr cloneElementWithoutAttributesAndChildren(Document& targetDocument) override { - return create(document()); + return create(targetDocument); } }; diff --git a/Source/WebCore/html/HTMLScriptElement.cpp b/Source/WebCore/html/HTMLScriptElement.cpp index a67eb184d779f..6832668bfd23a 100644 --- a/Source/WebCore/html/HTMLScriptElement.cpp +++ b/Source/WebCore/html/HTMLScriptElement.cpp @@ -168,9 +168,9 @@ void HTMLScriptElement::dispatchLoadEvent() dispatchEvent(Event::create(eventNames().loadEvent, false, false)); } -RefPtr HTMLScriptElement::cloneElementWithoutAttributesAndChildren() +RefPtr HTMLScriptElement::cloneElementWithoutAttributesAndChildren(Document& targetDocument) { - return adoptRef(new HTMLScriptElement(tagQName(), document(), false, alreadyStarted())); + return adoptRef(new HTMLScriptElement(tagQName(), targetDocument, false, alreadyStarted())); } } diff --git a/Source/WebCore/html/HTMLScriptElement.h b/Source/WebCore/html/HTMLScriptElement.h index e0ee7b970299f..acf609bf0cb9b 100644 --- a/Source/WebCore/html/HTMLScriptElement.h +++ b/Source/WebCore/html/HTMLScriptElement.h @@ -64,7 +64,7 @@ class HTMLScriptElement final : public HTMLElement, public ScriptElement { virtual void dispatchLoadEvent() override; - virtual RefPtr cloneElementWithoutAttributesAndChildren() override; + virtual RefPtr cloneElementWithoutAttributesAndChildren(Document&) override; }; } //namespace diff --git a/Source/WebCore/html/HTMLTemplateElement.cpp b/Source/WebCore/html/HTMLTemplateElement.cpp index dc752eeeaf7e0..a42016f91af9b 100644 --- a/Source/WebCore/html/HTMLTemplateElement.cpp +++ b/Source/WebCore/html/HTMLTemplateElement.cpp @@ -68,17 +68,17 @@ DocumentFragment* HTMLTemplateElement::content() const return m_content.get(); } -RefPtr HTMLTemplateElement::cloneNodeInternal(CloningOperation type) +RefPtr HTMLTemplateElement::cloneNodeInternal(Document& targetDocument, CloningOperation type) { RefPtr clone; switch (type) { case CloningOperation::OnlySelf: - return cloneElementWithoutChildren(); + return cloneElementWithoutChildren(targetDocument); case CloningOperation::SelfWithTemplateContent: - clone = cloneElementWithoutChildren(); + clone = cloneElementWithoutChildren(targetDocument); break; case CloningOperation::Everything: - clone = cloneElementWithChildren(); + clone = cloneElementWithChildren(targetDocument); break; } if (m_content) diff --git a/Source/WebCore/html/HTMLTemplateElement.h b/Source/WebCore/html/HTMLTemplateElement.h index d96d69ae38942..f79646bc34a2c 100644 --- a/Source/WebCore/html/HTMLTemplateElement.h +++ b/Source/WebCore/html/HTMLTemplateElement.h @@ -50,7 +50,7 @@ class HTMLTemplateElement final : public HTMLElement { private: HTMLTemplateElement(const QualifiedName&, Document&); - virtual RefPtr cloneNodeInternal(CloningOperation) override; + virtual RefPtr cloneNodeInternal(Document&, CloningOperation) override; virtual void didMoveToNewDocument(Document* oldDocument) override; mutable RefPtr m_content; diff --git a/Source/WebCore/html/shadow/SliderThumbElement.cpp b/Source/WebCore/html/shadow/SliderThumbElement.cpp index b4c6ae06e81f4..5470165c9347e 100644 --- a/Source/WebCore/html/shadow/SliderThumbElement.cpp +++ b/Source/WebCore/html/shadow/SliderThumbElement.cpp @@ -598,9 +598,9 @@ const AtomicString& SliderThumbElement::shadowPseudoId() const } } -RefPtr SliderThumbElement::cloneElementWithoutAttributesAndChildren() +RefPtr SliderThumbElement::cloneElementWithoutAttributesAndChildren(Document& targetDocument) { - return create(document()); + return create(targetDocument); } // -------------------------------- diff --git a/Source/WebCore/html/shadow/SliderThumbElement.h b/Source/WebCore/html/shadow/SliderThumbElement.h index 721cec31dafd9..85a6e3dbf6732 100644 --- a/Source/WebCore/html/shadow/SliderThumbElement.h +++ b/Source/WebCore/html/shadow/SliderThumbElement.h @@ -62,7 +62,7 @@ class SliderThumbElement final : public HTMLDivElement { SliderThumbElement(Document&); virtual RenderPtr createElementRenderer(Ref&&) override; - virtual RefPtr cloneElementWithoutAttributesAndChildren() override; + virtual RefPtr cloneElementWithoutAttributesAndChildren(Document&) override; virtual bool isDisabledFormControl() const override; virtual bool matchesReadWritePseudoClass() const override; virtual Element* focusDelegate() override; diff --git a/Source/WebCore/html/track/WebVTTElement.cpp b/Source/WebCore/html/track/WebVTTElement.cpp index a947955dcab89..485acbbdf7045 100644 --- a/Source/WebCore/html/track/WebVTTElement.cpp +++ b/Source/WebCore/html/track/WebVTTElement.cpp @@ -80,9 +80,9 @@ PassRefPtr WebVTTElement::create(WebVTTNodeType nodeType, Documen return adoptRef(new WebVTTElement(nodeType, document)); } -RefPtr WebVTTElement::cloneElementWithoutAttributesAndChildren() +RefPtr WebVTTElement::cloneElementWithoutAttributesAndChildren(Document& targetDocument) { - RefPtr clone = create(static_cast(m_webVTTNodeType), document()); + RefPtr clone = create(static_cast(m_webVTTNodeType), targetDocument); clone->setLanguage(m_language); return clone; } diff --git a/Source/WebCore/html/track/WebVTTElement.h b/Source/WebCore/html/track/WebVTTElement.h index 42a75fa2839ca..15965c8d190c7 100644 --- a/Source/WebCore/html/track/WebVTTElement.h +++ b/Source/WebCore/html/track/WebVTTElement.h @@ -46,7 +46,7 @@ class WebVTTElement final : public Element { static PassRefPtr create(const WebVTTNodeType, Document&); PassRefPtr createEquivalentHTMLElement(Document&); - virtual RefPtr cloneElementWithoutAttributesAndChildren() override; + virtual RefPtr cloneElementWithoutAttributesAndChildren(Document&) override; void setWebVTTNodeType(WebVTTNodeType type) { m_webVTTNodeType = static_cast(type); } WebVTTNodeType webVTTNodeType() const { return static_cast(m_webVTTNodeType); } diff --git a/Source/WebCore/svg/SVGScriptElement.cpp b/Source/WebCore/svg/SVGScriptElement.cpp index b33dbf753fa22..b7fddda029d0c 100644 --- a/Source/WebCore/svg/SVGScriptElement.cpp +++ b/Source/WebCore/svg/SVGScriptElement.cpp @@ -192,9 +192,9 @@ bool SVGScriptElement::hasSourceAttribute() const return hasAttribute(XLinkNames::hrefAttr); } -RefPtr SVGScriptElement::cloneElementWithoutAttributesAndChildren() +RefPtr SVGScriptElement::cloneElementWithoutAttributesAndChildren(Document& targetDocument) { - return adoptRef(new SVGScriptElement(tagQName(), document(), false, alreadyStarted())); + return adoptRef(new SVGScriptElement(tagQName(), targetDocument, false, alreadyStarted())); } #ifndef NDEBUG diff --git a/Source/WebCore/svg/SVGScriptElement.h b/Source/WebCore/svg/SVGScriptElement.h index aac99c61ebd4c..7761e8c0e4842 100644 --- a/Source/WebCore/svg/SVGScriptElement.h +++ b/Source/WebCore/svg/SVGScriptElement.h @@ -65,7 +65,7 @@ class SVGScriptElement final : public SVGElement virtual void dispatchLoadEvent() override { SVGExternalResourcesRequired::dispatchLoadEvent(this); } - virtual RefPtr cloneElementWithoutAttributesAndChildren() override; + virtual RefPtr cloneElementWithoutAttributesAndChildren(Document&) override; virtual bool rendererIsNeeded(const RenderStyle&) override { return false; } // SVGExternalResourcesRequired diff --git a/Source/WebCore/svg/SVGUseElement.cpp b/Source/WebCore/svg/SVGUseElement.cpp index 7ce3addaecc91..cef15bf34033e 100644 --- a/Source/WebCore/svg/SVGUseElement.cpp +++ b/Source/WebCore/svg/SVGUseElement.cpp @@ -685,7 +685,7 @@ void SVGUseElement::buildShadowTree(SVGElement* target, SVGElementInstance* targ if (isDisallowedElement(*target)) return; - RefPtr newChild = static_pointer_cast(targetInstance->correspondingElement()->cloneElementWithChildren()); + RefPtr newChild = static_pointer_cast(targetInstance->correspondingElement()->cloneElementWithChildren(document())); // We don't walk the target tree element-by-element, and clone each element, // but instead use cloneElementWithChildren(). This is an optimization for the common @@ -727,7 +727,7 @@ void SVGUseElement::expandUseElementsInShadowTree(Node* element) transferUseAttributesToReplacedElement(&use, cloneParent.get()); if (target && !isDisallowedElement(*target)) { - RefPtr newChild = target->cloneElementWithChildren(); + RefPtr newChild = target->cloneElementWithChildren(document()); ASSERT(newChild->isSVGElement()); cloneParent->appendChild(newChild.release()); }