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

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

Issue 23437003: Implement cloneNode for Document (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Use encoding/setEncoding instead 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
Index: Source/core/dom/Document.cpp
diff --git a/Source/core/dom/Document.cpp b/Source/core/dom/Document.cpp
index bc0bd807493829928565217fc62f1ede6f0538db..00229a3f3b7501ad34aa123a2e588fe756e94ca6 100644
--- a/Source/core/dom/Document.cpp
+++ b/Source/core/dom/Document.cpp
@@ -3089,11 +3089,29 @@ 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());
+ setEncoding(other.encoding());
+ setContextFeatures(other.contextFeatures());
+ setSecurityOrigin(other.securityOrigin());
abarth-chromium 2013/08/30 06:56:42 Shouldn't this be a copy of the security origin?
}
StyleSheetList* Document::styleSheets()

Powered by Google App Engine
This is Rietveld 408576698