Index: Source/core/dom/Document.cpp |
diff --git a/Source/core/dom/Document.cpp b/Source/core/dom/Document.cpp |
index a8c4b570081df7616853c961040b1b1b14286b59..6eb84ed559b2c48db749be06cf29025a23be20be 100644 |
--- a/Source/core/dom/Document.cpp |
+++ b/Source/core/dom/Document.cpp |
@@ -3103,11 +3103,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()->isolatedCopy()); |
} |
StyleSheetList* Document::styleSheets() |