Title: [87863] trunk
Revision
87863
Author
infe...@chromium.org
Date
2011-06-01 16:13:53 -0700 (Wed, 01 Jun 2011)

Log Message

2011-06-01  Abhishek Arya  <infe...@chromium.org>

        Reviewed by Alexey Proskuryakov.

        Fix setting of document.body
        https://bugs.webkit.org/show_bug.cgi?id=60831

        1. Only allowing setting to an element if it has a body tag.
        2. If element is from another document, import it.

        Test: fast/dom/document-set-body.html

        * dom/Document.cpp:
        (WebCore::Document::setBody):
2011-06-01  Abhishek Arya  <infe...@chromium.org>

        Reviewed by Alexey Proskuryakov.

        Tests setting document.body to non body elements, elements in other
        documents.
        https://bugs.webkit.org/show_bug.cgi?id=60831

        * fast/dom/document-set-body-expected.txt: Added.
        * fast/dom/document-set-body.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (87862 => 87863)


--- trunk/LayoutTests/ChangeLog	2011-06-01 23:03:40 UTC (rev 87862)
+++ trunk/LayoutTests/ChangeLog	2011-06-01 23:13:53 UTC (rev 87863)
@@ -1,3 +1,14 @@
+2011-06-01  Abhishek Arya  <infe...@chromium.org>
+
+        Reviewed by Alexey Proskuryakov.
+
+        Tests setting document.body to non body elements, elements in other
+        documents.
+        https://bugs.webkit.org/show_bug.cgi?id=60831
+
+        * fast/dom/document-set-body-expected.txt: Added.
+        * fast/dom/document-set-body.html: Added.
+
 2011-06-01  Adam Barth  <aba...@webkit.org>
 
         Add Windows baseline for this new test.

Added: trunk/LayoutTests/fast/dom/document-set-body-expected.txt (0 => 87863)


--- trunk/LayoutTests/fast/dom/document-set-body-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/document-set-body-expected.txt	2011-06-01 23:13:53 UTC (rev 87863)
@@ -0,0 +1,11 @@
+Tests setting document.body
+
+PASS document1.body = iframe1 threw exception Error: HIERARCHY_REQUEST_ERR: DOM Exception 3.
+PASS iframe1.parentNode is document.body
+PASS document1.body = document1.createElement('iframe') threw exception Error: HIERARCHY_REQUEST_ERR: DOM Exception 3.
+PASS document1.body != document.body is true
+PASS document1.body is body1
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/dom/document-set-body.html (0 => 87863)


--- trunk/LayoutTests/fast/dom/document-set-body.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/document-set-body.html	2011-06-01 23:13:53 UTC (rev 87863)
@@ -0,0 +1,31 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href=""
+<script src=""
+</head>
+<body>
+<p>Tests setting document.body</p>
+<div id="console"></div>
+<script>
+iframe1 = document.createElement('iframe');
+document.body.appendChild(iframe1);
+document1 = iframe1.contentDocument.implementation.createHTMLDocument("document");
+
+shouldThrow("document1.body = iframe1", "'Error: HIERARCHY_REQUEST_ERR: DOM Exception 3'");
+shouldBe("iframe1.parentNode", "document.body");
+
+shouldThrow("document1.body = document1.createElement('iframe')", "'Error: HIERARCHY_REQUEST_ERR: DOM Exception 3'");
+
+document1.body = document.body;
+shouldBeTrue("document1.body != document.body");
+
+body1 = document1.createElement('body');
+document1.body = body1;
+shouldBe("document1.body", "body1")
+
+var successfullyParsed = true;
+</script>
+<script src=""
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (87862 => 87863)


--- trunk/Source/WebCore/ChangeLog	2011-06-01 23:03:40 UTC (rev 87862)
+++ trunk/Source/WebCore/ChangeLog	2011-06-01 23:13:53 UTC (rev 87863)
@@ -1,3 +1,18 @@
+2011-06-01  Abhishek Arya  <infe...@chromium.org>
+
+        Reviewed by Alexey Proskuryakov.
+
+        Fix setting of document.body
+        https://bugs.webkit.org/show_bug.cgi?id=60831
+
+        1. Only allowing setting to an element if it has a body tag.
+        2. If element is from another document, import it.
+
+        Test: fast/dom/document-set-body.html
+
+        * dom/Document.cpp:
+        (WebCore::Document::setBody):
+
 2011-06-01  Chris Fleizach  <cfleiz...@apple.com>
 
         Reviewed by Darin Adler.

Modified: trunk/Source/WebCore/dom/Document.cpp (87862 => 87863)


--- trunk/Source/WebCore/dom/Document.cpp	2011-06-01 23:03:40 UTC (rev 87862)
+++ trunk/Source/WebCore/dom/Document.cpp	2011-06-01 23:13:53 UTC (rev 87863)
@@ -2031,11 +2031,21 @@
 
 void Document::setBody(PassRefPtr<HTMLElement> newBody, ExceptionCode& ec)
 {
-    if (!newBody || !documentElement()) { 
+    ec = 0;
+
+    if (!newBody || !documentElement() || !newBody->hasTagName(bodyTag)) { 
         ec = HIERARCHY_REQUEST_ERR;
         return;
     }
 
+    if (newBody->document() && newBody->document() != this) {
+        RefPtr<Node> node = importNode(newBody.get(), true, ec);
+        if (ec)
+            return;
+        
+        newBody = toHTMLElement(node.get());
+    }
+
     HTMLElement* b = body();
     if (!b)
         documentElement()->appendChild(newBody, ec);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to