Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(236)

Unified Diff: Source/core/dom/Document.cpp

Issue 173303004: Clone template contents in importNode (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Also clone children as normal for template Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/dom/Document.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/Document.cpp
diff --git a/Source/core/dom/Document.cpp b/Source/core/dom/Document.cpp
index bcd3b7e7273f7321c1c128402083d922cdc3e5b2..67e916080f926f4401d4e4b77fe2d13d3d58d4c9 100644
--- a/Source/core/dom/Document.cpp
+++ b/Source/core/dom/Document.cpp
@@ -132,6 +132,7 @@
#include "core/html/HTMLNameCollection.h"
#include "core/html/HTMLScriptElement.h"
#include "core/html/HTMLStyleElement.h"
+#include "core/html/HTMLTemplateElement.h"
#include "core/html/HTMLTitleElement.h"
#include "core/html/PluginDocument.h"
#include "core/html/forms/FormController.h"
@@ -884,6 +885,20 @@ PassRefPtr<Text> Document::createEditingTextNode(const String& text)
return Text::createEditingText(*this, text);
}
+bool Document::importContainerNodeChildren(ContainerNode* oldContainerNode, PassRefPtr<ContainerNode> newContainerNode, ExceptionState& exceptionState)
+{
+ for (Node* oldChild = oldContainerNode->firstChild(); oldChild; oldChild = oldChild->nextSibling()) {
+ RefPtr<Node> newChild = importNode(oldChild, true, exceptionState);
+ if (exceptionState.hadException())
+ return false;
+ newContainerNode->appendChild(newChild.release(), exceptionState);
+ if (exceptionState.hadException())
+ return false;
+ }
+
+ return true;
+}
+
PassRefPtr<Node> Document::importNode(Node* importedNode, bool deep, ExceptionState& exceptionState)
{
if (!importedNode) {
@@ -917,14 +932,11 @@ PassRefPtr<Node> Document::importNode(Node* importedNode, bool deep, ExceptionSt
newElement->cloneDataFromElement(*oldElement);
if (deep) {
- for (Node* oldChild = oldElement->firstChild(); oldChild; oldChild = oldChild->nextSibling()) {
- RefPtr<Node> newChild = importNode(oldChild, true, exceptionState);
- if (exceptionState.hadException())
- return nullptr;
- newElement->appendChild(newChild.release(), exceptionState);
- if (exceptionState.hadException())
- return nullptr;
- }
+ if (!importContainerNodeChildren(oldElement, newElement, exceptionState))
+ return nullptr;
+ if (oldElement->hasTagName(templateTag)
+ && !importContainerNodeChildren(toHTMLTemplateElement(oldElement)->content(), toHTMLTemplateElement(newElement)->content(), exceptionState))
+ return nullptr;
}
return newElement.release();
@@ -940,16 +952,8 @@ PassRefPtr<Node> Document::importNode(Node* importedNode, bool deep, ExceptionSt
}
DocumentFragment* oldFragment = toDocumentFragment(importedNode);
RefPtr<DocumentFragment> newFragment = createDocumentFragment();
- if (deep) {
- for (Node* oldChild = oldFragment->firstChild(); oldChild; oldChild = oldChild->nextSibling()) {
- RefPtr<Node> newChild = importNode(oldChild, true, exceptionState);
- if (exceptionState.hadException())
- return nullptr;
- newFragment->appendChild(newChild.release(), exceptionState);
- if (exceptionState.hadException())
- return nullptr;
- }
- }
+ if (deep && !importContainerNodeChildren(oldFragment, newFragment, exceptionState))
+ return nullptr;
return newFragment.release();
}
« no previous file with comments | « Source/core/dom/Document.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698