WebCore:
authorweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 9 May 2008 20:14:29 +0000 (20:14 +0000)
committerweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 9 May 2008 20:14:29 +0000 (20:14 +0000)
2008-05-09  Adam Barth  <abarth-webkit@adambarth.com>

        Reviewed by Sam Weinig.

        https://bugs.webkit.org/show_bug.cgi?id=18771

        Make postMessage generate an event on the window instead of the
        document.

        Test: http/tests/messaging/cross-domain-message-event-dispatch.html

        * dom/EventTargetNode.cpp:
        (WebCore::EventTargetNode::dispatchWindowEvent):
        * dom/EventTargetNode.h:
        * page/DOMWindow.cpp:
        (WebCore::DOMWindow::postMessageTimerFired):

LayoutTests:

2008-05-09  Adam Barth  <abarth-webkit@adambarth.com>

        Reviewed by Sam Weinig.

        Update tests to listen for message events on the window instead of
        the document.  Also, added a test that the event is sent to the
        window and not to the document.

        * http/tests/messaging/cross-domain-message-event-dispatch-expected.txt: Added.
        * http/tests/messaging/cross-domain-message-event-dispatch.html: Added.
        * http/tests/messaging/cross-domain-message-send.html:
        * http/tests/messaging/resources/cross-domain-message-receive.html:
        * http/tests/security/cross-frame-access-delete.html:
        * http/tests/security/cross-frame-access-history-put.html:
        * http/tests/security/cross-frame-access-location-put.html:
        * http/tests/security/postMessage/delivery-order.html:
        * http/tests/security/postMessage/invalid-origin-throws-exception.html:
        * http/tests/security/postMessage/javascript-page-still-sends-origin.html:
        * http/tests/security/postMessage/origin-unaffected-by-base-tag.html:
        * http/tests/security/postMessage/origin-unaffected-by-document-domain.html:
        * http/tests/security/postMessage/resources/post-message-listener.html:
        * http/tests/security/postMessage/target-origin.html:
        * http/tests/security/resources/cross-frame-iframe-for-delete-test.html:
        * http/tests/security/resources/cross-frame-iframe-for-history-put-test.html:
        * http/tests/security/resources/cross-frame-iframe-for-location-put-test.html:
        * http/tests/security/xss-eval.html:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@33006 268f45cc-cd09-0410-ab3c-d52691b4dbfc

23 files changed:
LayoutTests/ChangeLog
LayoutTests/http/tests/messaging/cross-domain-message-event-dispatch-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/messaging/cross-domain-message-event-dispatch.html [new file with mode: 0644]
LayoutTests/http/tests/messaging/cross-domain-message-send.html
LayoutTests/http/tests/messaging/resources/cross-domain-message-receive.html
LayoutTests/http/tests/security/cross-frame-access-delete.html
LayoutTests/http/tests/security/cross-frame-access-history-put.html
LayoutTests/http/tests/security/cross-frame-access-location-put.html
LayoutTests/http/tests/security/postMessage/delivery-order.html
LayoutTests/http/tests/security/postMessage/invalid-origin-throws-exception.html
LayoutTests/http/tests/security/postMessage/javascript-page-still-sends-origin.html
LayoutTests/http/tests/security/postMessage/origin-unaffected-by-base-tag.html
LayoutTests/http/tests/security/postMessage/origin-unaffected-by-document-domain.html
LayoutTests/http/tests/security/postMessage/resources/post-message-listener.html
LayoutTests/http/tests/security/postMessage/target-origin.html
LayoutTests/http/tests/security/resources/cross-frame-iframe-for-delete-test.html
LayoutTests/http/tests/security/resources/cross-frame-iframe-for-history-put-test.html
LayoutTests/http/tests/security/resources/cross-frame-iframe-for-location-put-test.html
LayoutTests/http/tests/security/xss-eval.html
WebCore/ChangeLog
WebCore/dom/EventTargetNode.cpp
WebCore/dom/EventTargetNode.h
WebCore/page/DOMWindow.cpp

index f10e097..56e8f4a 100644 (file)
@@ -1,3 +1,30 @@
+2008-05-09  Adam Barth  <abarth-webkit@adambarth.com>
+
+        Reviewed by Sam Weinig.
+
+        Update tests to listen for message events on the window instead of
+        the document.  Also, added a test that the event is sent to the
+        window and not to the document.
+
+        * http/tests/messaging/cross-domain-message-event-dispatch-expected.txt: Added.
+        * http/tests/messaging/cross-domain-message-event-dispatch.html: Added.
+        * http/tests/messaging/cross-domain-message-send.html:
+        * http/tests/messaging/resources/cross-domain-message-receive.html:
+        * http/tests/security/cross-frame-access-delete.html:
+        * http/tests/security/cross-frame-access-history-put.html:
+        * http/tests/security/cross-frame-access-location-put.html:
+        * http/tests/security/postMessage/delivery-order.html:
+        * http/tests/security/postMessage/invalid-origin-throws-exception.html:
+        * http/tests/security/postMessage/javascript-page-still-sends-origin.html:
+        * http/tests/security/postMessage/origin-unaffected-by-base-tag.html:
+        * http/tests/security/postMessage/origin-unaffected-by-document-domain.html:
+        * http/tests/security/postMessage/resources/post-message-listener.html:
+        * http/tests/security/postMessage/target-origin.html:
+        * http/tests/security/resources/cross-frame-iframe-for-delete-test.html:
+        * http/tests/security/resources/cross-frame-iframe-for-history-put-test.html:
+        * http/tests/security/resources/cross-frame-iframe-for-location-put-test.html:
+        * http/tests/security/xss-eval.html:
+
 2008-05-08  Dan Bernstein  <mitz@apple.com>
 
         Reviewed by Mark Rowe.
diff --git a/LayoutTests/http/tests/messaging/cross-domain-message-event-dispatch-expected.txt b/LayoutTests/http/tests/messaging/cross-domain-message-event-dispatch-expected.txt
new file mode 100644 (file)
index 0000000..ca69533
--- /dev/null
@@ -0,0 +1,11 @@
+waiting...
+Test begins
+Events queued
+Capture phase: Message1
+Bubble phase: Message1
+Capture phase: Message2
+Bubble phase: Message2
+Capture phase: Message3
+Bubble phase: Message3
+setTimeout1
+setTimeout2
diff --git a/LayoutTests/http/tests/messaging/cross-domain-message-event-dispatch.html b/LayoutTests/http/tests/messaging/cross-domain-message-event-dispatch.html
new file mode 100644 (file)
index 0000000..e8baf9e
--- /dev/null
@@ -0,0 +1,54 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script>
+if (window.layoutTestController) {
+    layoutTestController.waitUntilDone();
+    layoutTestController.dumpAsText();
+}
+
+function log(msg) {
+    var div = document.createElement("div");
+    div.appendChild(document.createTextNode(msg));
+    document.getElementById("result").appendChild(div);
+}
+
+function done() {
+    if (window.layoutTestController)
+        layoutTestController.notifyDone();
+}
+
+window.onload = function () {
+    log("Test begins");
+
+    // The setTimeout handlers will get called after the
+    // event listeners, because setTimeout has a minimum wait time
+    // of 10ms while postMessage has no minimum wait time.
+    postMessage("Message1", "*");
+    setTimeout("log('setTimeout1')", 0);
+    postMessage("Message2", "*");
+    setTimeout("log('setTimeout2')", 0);
+    postMessage("Message3", "*");
+    setTimeout(done, 0);
+    log("Events queued");
+}
+
+addEventListener("message", function (e) {
+        log("Capture phase: " + e.data);
+    }, true);
+addEventListener("message", function (e) {
+        log("Bubble phase: " + e.data);
+    }, false);
+
+document.addEventListener("message", function (e) {
+        log("FAIL: Capture phase (document): " + e.data);
+    }, true);
+document.addEventListener("message", function (e) {
+        log("FAIL: Bubble phase (document): " + e.data);
+    }, false);
+</script>
+</head>
+<body>
+<div id="result">waiting...</div>
+</body>
+</html>
index 8c19cbc..4cc6aad 100644 (file)
@@ -23,7 +23,7 @@ function receiver(e) {
     }
 }
 
-document.addEventListener('message', receiver, false);
+addEventListener('message', receiver, false);
 
     
 </script>
index a8c9ed5..976ff6d 100644 (file)
@@ -13,7 +13,7 @@ function receiver(e) {
     e.source.postMessage(result, "*");   
 }
 
-document.addEventListener('message', receiver, false);
+addEventListener('message', receiver, false);
 
 </script>
 <body>
index dbaaeb1..7af0c63 100644 (file)
@@ -13,7 +13,7 @@
             if (e.data == "setValuesComplete")
                 deleteTest();
         }
-        document.addEventListener('message', receiver, false);
+        addEventListener('message', receiver, false);
 
         deleteTest = function()
         {
index b6f3739..755a32b 100644 (file)
@@ -28,7 +28,7 @@
             if (e.data == "storedOldValuesComplete")
                 setTest();
         }
-        document.addEventListener('message', receiver, false);
+        addEventListener('message', receiver, false);
 
         setTest = function()
         {
index 1a02bc8..23bafa9 100644 (file)
@@ -28,7 +28,7 @@
             if (e.data == "storedOldValuesComplete")
                 setTest();
         }
-        document.addEventListener('message', receiver, false);
+        addEventListener('message', receiver, false);
 
         setTest = function()
         {
index d01d6dc..f193f58 100644 (file)
@@ -8,7 +8,7 @@ if (window.layoutTestController) {
     layoutTestController.waitUntilDone();
 }
 
-document.addEventListener('message', recv, false);
+addEventListener('message', recv, false);
 
 function test() {
     var iframe = document.getElementById('child');
index c2b68f3..3594dc2 100644 (file)
@@ -8,7 +8,7 @@ if (window.layoutTestController) {
     layoutTestController.waitUntilDone();
 }
  
-document.addEventListener("message", recv, false);
+addEventListener("message", recv, false);
 
 function tryPostMessage(origin) {
   try {
index 3936331..ef9e439 100644 (file)
@@ -16,7 +16,7 @@ function recv(e) {
         layoutTestController.notifyDone();
 }
 
-document.addEventListener("message", recv, false);
+addEventListener("message", recv, false);
 
 </script>
 <base href="http://www.example.com/">
index b163829..ca61fbe 100644 (file)
@@ -8,7 +8,7 @@ if (window.layoutTestController) {
     layoutTestController.waitUntilDone();
 }
 
-document.addEventListener("message", recv, false);
+addEventListener("message", recv, false);
 
 function test() {
     var iframe = document.getElementById('child');
index 308c143..e2055b1 100644 (file)
@@ -8,7 +8,7 @@ if (window.layoutTestController) {
     layoutTestController.waitUntilDone();
 }
 
-document.addEventListener("message", recv, false);
+addEventListener("message", recv, false);
 
 function test() {
     var iframe = document.getElementById('child');
index c93760e..ac3c4f3 100644 (file)
@@ -8,7 +8,7 @@ function recv(e) {
     top.postMessage(msg, '*');
 }
 
-document.addEventListener("message", recv, false);
+addEventListener("message", recv, false);
 </script>
 </body>
 </html>
index b7d0a44..5e2d597 100644 (file)
@@ -8,7 +8,7 @@ if (window.layoutTestController) {
     layoutTestController.waitUntilDone();
 }
 
-document.addEventListener("message", recv, false);
+addEventListener("message", recv, false);
 
 function tryPostMessage(win, origin) {
     try {
index e754a4f..91b182d 100644 (file)
@@ -7,7 +7,7 @@
             if (e.data == "deletingValuesComplete")
                 setCheck();
         }
-        document.addEventListener('message', receiver, false);
+        addEventListener('message', receiver, false);
 
         window.onload = function()
         {
index dcb4f17..a8a5dcc 100644 (file)
@@ -14,7 +14,7 @@
             if (e.data == "settingValuesComplete")
                 setCheck();
         }
-        document.addEventListener('message', receiver, false);
+        addEventListener('message', receiver, false);
 
         window.onload = function()
         {
index aa97aec..300804d 100644 (file)
@@ -13,7 +13,7 @@
             if (e.data == "settingValuesComplete")
                 setCheck();
         }
-        document.addEventListener('message', receiver, false);
+        addEventListener('message', receiver, false);
 
         window.onload = function()
         {
index 96dc2ea..5627282 100644 (file)
@@ -25,7 +25,7 @@ function shouldBe(aDescription, a, b)
     }
 }
 
-document.addEventListener("message", function()
+addEventListener("message", function()
 {
     shouldBe("eval.call(frames[0], 'document')", (function() { try { return eval.call(frames[0], 'document'); } catch(e) { return e.name; } })(), "EvalError");
 
index 86dadaf..ffa1fff 100644 (file)
@@ -1,3 +1,20 @@
+2008-05-09  Adam Barth  <abarth-webkit@adambarth.com>
+
+        Reviewed by Sam Weinig.
+
+        https://bugs.webkit.org/show_bug.cgi?id=18771
+
+        Make postMessage generate an event on the window instead of the
+        document.
+
+        Test: http/tests/messaging/cross-domain-message-event-dispatch.html
+
+        * dom/EventTargetNode.cpp:
+        (WebCore::EventTargetNode::dispatchWindowEvent):
+        * dom/EventTargetNode.h:
+        * page/DOMWindow.cpp:
+        (WebCore::DOMWindow::postMessageTimerFired):
+
 2008-05-09  Tor Arne Vestbø  <tavestbo@trolltech.com>
 
         Reviewed by Simon.
index 9bccc03..3c118cf 100644 (file)
@@ -136,15 +136,21 @@ bool EventTargetNode::dispatchSubtreeModifiedEvent()
                                                true,false,0,String(),String(),String(),0),ec,true);
 }
 
-void EventTargetNode::dispatchWindowEvent(const AtomicString &eventType, bool canBubbleArg, bool cancelableArg)
+void EventTargetNode::dispatchWindowEvent(PassRefPtr<Event> e)
 {
     ASSERT(!eventDispatchForbidden());
-    ExceptionCode ec = 0;
-    RefPtr<Event> evt = new Event(eventType, canBubbleArg, cancelableArg);
+    RefPtr<Event> evt(e);
     RefPtr<Document> doc = document();
     evt->setTarget(doc);
     doc->handleWindowEvent(evt.get(), true);
     doc->handleWindowEvent(evt.get(), false);
+}
+
+void EventTargetNode::dispatchWindowEvent(const AtomicString& eventType, bool canBubbleArg, bool cancelableArg)
+{
+    ASSERT(!eventDispatchForbidden());
+    RefPtr<Document> doc = document();
+    dispatchWindowEvent(new Event(eventType, canBubbleArg, cancelableArg));
     
     if (eventType == loadEvent) {
         // For onload events, send a separate load event to the enclosing frame only.
@@ -154,6 +160,7 @@ void EventTargetNode::dispatchWindowEvent(const AtomicString &eventType, bool ca
         if (ownerElement) {
             RefPtr<Event> ownerEvent = new Event(eventType, false, cancelableArg);
             ownerEvent->setTarget(ownerElement);
+            ExceptionCode ec = 0;
             ownerElement->dispatchGenericEvent(ownerElement, ownerEvent.release(), ec, true);
         }
     }
index c76a8f9..2f4b60a 100644 (file)
@@ -52,6 +52,7 @@ public:
     EventListener* getHTMLEventListener(const AtomicString& eventType);
 
     bool dispatchSubtreeModifiedEvent();
+    void dispatchWindowEvent(PassRefPtr<Event>);
     void dispatchWindowEvent(const AtomicString& eventType, bool canBubble, bool cancelable);
     bool dispatchUIEvent(const AtomicString& eventType, int detail = 0, PassRefPtr<Event> underlyingEvent = 0);
     bool dispatchKeyEvent(const PlatformKeyboardEvent&);
index 777d40a..d18be2e 100644 (file)
@@ -395,8 +395,7 @@ void DOMWindow::postMessageTimerFired(PostMessageTimer* t)
         }
     }
 
-    ExceptionCode ec;
-    document()->dispatchEvent(timer->event(), ec, true);
+    document()->dispatchWindowEvent(timer->event());
 }
 #endif