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

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

Issue 23437003: Implement cloneNode for Document (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 4 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') | Source/core/html/HTMLDocument.h » ('j') | 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 3a9216003d3c4c679c0e648ce5703314be7db56b..3a37618ee68bc1ad58126b20aa223970df8009e4 100644
--- a/Source/core/dom/Document.cpp
+++ b/Source/core/dom/Document.cpp
@@ -3090,11 +3090,30 @@ bool Document::canReplaceChild(Node* newChild, Node* oldChild)
return true;
}
-PassRefPtr<Node> Document::cloneNode(bool /*deep*/)
+PassRefPtr<Node> Document::cloneNode(bool deep)
{
- // Spec says cloning Document nodes is "implementation dependent"
- // so we do not support it...
- return 0;
+ RefPtr<Document> clone = cloneDocumentWithoutChildren();
+ clone->cloneDataFromDocument(*this);
+ if (deep)
+ cloneChildNodes(clone.get());
+ return clone.release();
+}
+
+PassRefPtr<Document> Document::cloneDocumentWithoutChildren()
+{
+ DocumentInit init(url());
+ if (isXHTMLDocument())
+ return createXHTML(init.withRegistrationContext(registrationContext()));
+ return create(init);
+}
+
+void Document::cloneDataFromDocument(const Document& other)
+{
+ setCompatibilityMode(other.compatibilityMode());
+ setSecurityOrigin(other.securityOrigin());
abarth-chromium 2013/08/26 21:04:55 You should make a copy of the security origin. Th
+ setContextFeatures(other.contextFeatures());
+
+ setDecoder(TextResourceDecoder::create(other.suggestedMIMEType(), other.encoding()));
abarth-chromium 2013/08/26 21:04:55 This doesn't make a lot of sense... There is no t
jamesr 2013/08/26 21:07:51 Have you tested that the exposed encoding on the n
}
StyleSheetList* Document::styleSheets()
« no previous file with comments | « Source/core/dom/Document.h ('k') | Source/core/html/HTMLDocument.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698