WebCore:
authordarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 1 Jan 2008 00:18:16 +0000 (00:18 +0000)
committerdarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 1 Jan 2008 00:18:16 +0000 (00:18 +0000)
        Reviewed by Darin.

        Patch for http://bugs.webkit.org/show_bug.cgi?id=14994
        Support for MessageEvent and cross-domain messaging

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

        * DerivedSources.make:
        * WebCore.pro:
        * WebCore.vcproj/WebCore.vcproj:
        * WebCore.xcodeproj/project.pbxproj:
        * WebCoreSources.bkl:
        * bindings/js/JSDOMWindowCustom.cpp:
        (WebCore::JSDOMWindow::customGetOwnPropertySlot): Allow cross-domain access to the
        postMessage function.
        (WebCore::JSDOMWindow::postMessage):
        * bindings/js/JSEventCustom.cpp:
        (WebCore::toJS):
        * dom/Event.cpp:
        (WebCore::Event::isMessageEvent):
        * dom/Event.h:
        * dom/EventNames.h: New event name
        * dom/MessageEvent.cpp: Added.
        * dom/MessageEvent.h: Added.
        * dom/MessageEvent.idl: Added.
        * page/DOMWindow.cpp:
        (WebCore::DOMWindow::postMessage): Added.
        * page/DOMWindow.h:
        * page/DOMWindow.idl:

LayoutTests:

        Reviewed by Darin.

        Test for http://bugs.webkit.org/show_bug.cgi?id=14994
        Support for MessageEvent and cross-domain messaging

        * fast/dom/Window/window-properties-expected.txt:
        * http/tests/messaging: Added.
        * http/tests/messaging/cross-domain-message-send-expected.txt: Added.
        * http/tests/messaging/cross-domain-message-send.html: Added.
        * http/tests/messaging/resources: Added.
        * http/tests/messaging/resources/cross-domain-message-receive.html: Added.

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

22 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/dom/Window/window-properties-expected.txt
LayoutTests/http/tests/messaging/cross-domain-message-send-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/messaging/cross-domain-message-send.html [new file with mode: 0644]
LayoutTests/http/tests/messaging/resources/cross-domain-message-receive.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/DerivedSources.make
WebCore/WebCore.pro
WebCore/WebCore.vcproj/WebCore.vcproj
WebCore/WebCore.xcodeproj/project.pbxproj
WebCore/WebCoreSources.bkl
WebCore/bindings/js/JSDOMWindowCustom.cpp
WebCore/bindings/js/JSEventCustom.cpp
WebCore/dom/Event.cpp
WebCore/dom/Event.h
WebCore/dom/EventNames.h
WebCore/dom/MessageEvent.cpp [new file with mode: 0644]
WebCore/dom/MessageEvent.h [new file with mode: 0644]
WebCore/dom/MessageEvent.idl [new file with mode: 0644]
WebCore/page/DOMWindow.cpp
WebCore/page/DOMWindow.h
WebCore/page/DOMWindow.idl

index 7fb4f67..6586cdc 100644 (file)
@@ -1,3 +1,17 @@
+2007-12-31  Henry Mason  <hmason@mac.com>
+
+        Reviewed by Darin.
+
+        Test for http://bugs.webkit.org/show_bug.cgi?id=14994
+        Support for MessageEvent and cross-domain messaging
+
+        * fast/dom/Window/window-properties-expected.txt:
+        * http/tests/messaging: Added.
+        * http/tests/messaging/cross-domain-message-send-expected.txt: Added.
+        * http/tests/messaging/cross-domain-message-send.html: Added.
+        * http/tests/messaging/resources: Added.
+        * http/tests/messaging/resources/cross-domain-message-receive.html: Added.
+
 2007-12-30  Sam Weinig  <sam@webkit.org>
 
         Reviewed by Oliver Hunt.
index 5c3005e..bf77dca 100644 (file)
@@ -704,6 +704,8 @@ window.MediaList.prototype [object MediaListPrototype]
 window.MediaList.prototype.appendMedium [function]
 window.MediaList.prototype.deleteMedium [function]
 window.MediaList.prototype.item [function]
+window.MessageEvent [object MessageEventConstructor]
+window.MessageEvent.prototype [printed above as window.Event.prototype]
 window.MouseEvent [object MouseEventConstructor]
 window.MouseEvent.prototype [printed above as window.Event.prototype]
 window.MutationEvent [object MutationEventConstructor]
@@ -1254,6 +1256,7 @@ window.pageYOffset [number]
 window.parent [printed above as window]
 window.personalbar [object BarInfo]
 window.personalbar.visible [boolean]
+window.postMessage [function]
 window.print [function]
 window.prompt [function]
 window.releaseEvents [function]
diff --git a/LayoutTests/http/tests/messaging/cross-domain-message-send-expected.txt b/LayoutTests/http/tests/messaging/cross-domain-message-send-expected.txt
new file mode 100644 (file)
index 0000000..9b83ec4
--- /dev/null
@@ -0,0 +1,2 @@
+
+data: Something uri: http://127.0.0.1:8000/messaging/cross-domain-message-send.html domain: 127.0.0.1
diff --git a/LayoutTests/http/tests/messaging/cross-domain-message-send.html b/LayoutTests/http/tests/messaging/cross-domain-message-send.html
new file mode 100644 (file)
index 0000000..cc541e2
--- /dev/null
@@ -0,0 +1,38 @@
+<!DOCTYPE html>
+
+<html lang="en">
+<head>
+    <title>Cross-Doc Test</title>
+</head>
+<script type="text/javascript" charset="utf-8">
+
+if (window.layoutTestController) {
+    layoutTestController.waitUntilDone();
+    layoutTestController.dumpAsText();
+}
+
+function postIt () {
+    document.getElementById("receiver").contentWindow.postMessage("Something");
+}
+
+function receiver(e) {
+    document.getElementById("result").firstChild.data = e.data;   
+    
+    if (window.layoutTestController) {
+        layoutTestController.notifyDone();
+    }
+}
+
+document.addEventListener('message', receiver, false);
+
+    
+</script>
+<body>
+    
+    <iframe src="http://localhost:8000/messaging/resources/cross-domain-message-receive.html" id="receiver" onload="postIt();"></iframe>
+    
+    <div id="result">waiting...</div>
+    
+    
+</body>
+</html>
diff --git a/LayoutTests/http/tests/messaging/resources/cross-domain-message-receive.html b/LayoutTests/http/tests/messaging/resources/cross-domain-message-receive.html
new file mode 100644 (file)
index 0000000..cbc8a34
--- /dev/null
@@ -0,0 +1,23 @@
+<!DOCTYPE html>
+
+<html lang="en">
+<head>
+    <title>Cross-Doc Test</title>
+</head>
+<script type="text/javascript" charset="utf-8">
+
+function receiver(e) {
+    var result = "";
+    result += "data: " + e.data + "\n";
+    result += "uri: " + e.uri + "\n";
+    result += "domain: " + e.domain + "\n";
+    e.source.postMessage(result);   
+}
+
+document.addEventListener('message', receiver, false);
+
+</script>
+<body>
+    
+</body>
+</html>
index 6542114..ac6ccf9 100644 (file)
@@ -1,3 +1,35 @@
+2007-12-31  Henry Mason  <hmason@mac.com>
+
+        Reviewed by Darin.
+
+        Patch for http://bugs.webkit.org/show_bug.cgi?id=14994
+        Support for MessageEvent and cross-domain messaging
+
+        Test: http/tests/messaging/cross-domain-message-send.html
+
+        * DerivedSources.make:
+        * WebCore.pro:
+        * WebCore.vcproj/WebCore.vcproj:
+        * WebCore.xcodeproj/project.pbxproj:
+        * WebCoreSources.bkl:
+        * bindings/js/JSDOMWindowCustom.cpp:
+        (WebCore::JSDOMWindow::customGetOwnPropertySlot): Allow cross-domain access to the
+        postMessage function.
+        (WebCore::JSDOMWindow::postMessage):
+        * bindings/js/JSEventCustom.cpp:
+        (WebCore::toJS):
+        * dom/Event.cpp:
+        (WebCore::Event::isMessageEvent):
+        * dom/Event.h:
+        * dom/EventNames.h: New event name
+        * dom/MessageEvent.cpp: Added.
+        * dom/MessageEvent.h: Added.
+        * dom/MessageEvent.idl: Added.
+        * page/DOMWindow.cpp:
+        (WebCore::DOMWindow::postMessage): Added.
+        * page/DOMWindow.h:
+        * page/DOMWindow.idl:
+
 2007-12-31  Darin Adler  <darin@apple.com>
 
         Suggested by Antti.
index 76105ef..16cb612 100644 (file)
@@ -133,6 +133,7 @@ all : \
     DOMHTMLTitleElement.h \
     DOMHTMLUListElement.h \
     DOMKeyboardEvent.h \
+    DOMMessageEvent.h \
     DOMMediaList.h \
     DOMMouseEvent.h \
     DOMMutationEvent.h \
@@ -415,6 +416,7 @@ all : \
     JSLocation.lut.h \
     JSMediaError.h \
     JSMediaList.h \
+    JSMessageEvent.h \
     JSMouseEvent.h \
     JSMutationEvent.h \
     JSNamedNodeMap.h \
index 4cde788..7b90d4c 100644 (file)
@@ -281,6 +281,7 @@ IDL_BINDINGS += \
 #    dom/EventListener.idl \
 #    dom/EventTarget.idl \
     dom/KeyboardEvent.idl \
+    dom/MessageEvent.idl \
     dom/MouseEvent.idl \
     dom/MutationEvent.idl \
     dom/NamedNodeMap.idl \
@@ -498,6 +499,7 @@ SOURCES += \
     dom/ExceptionCode.cpp \
     dom/KeyboardEvent.cpp \
     dom/MappedAttribute.cpp \
+    dom/MessageEvent.cpp \
     dom/MouseEvent.cpp \
     dom/MouseRelatedEvent.cpp \
     dom/MutationEvent.cpp \
index e7172c2..24a8efe 100644 (file)
                                RelativePath="$(WebKitOutputDir)\obj\$(ProjectName)\DerivedSources\JSMediaList.h"\r
                                >\r
                        </File>\r
+                       <File\r
+                               RelativePath="$(WebKitOutputDir)\obj\$(ProjectName)\DerivedSources\JSMessageEvent.cpp"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="$(WebKitOutputDir)\obj\$(ProjectName)\DerivedSources\JSMessageEvent.h"\r
+                               >\r
+                       </File>\r
                        <File\r
                                RelativePath="$(WebKitOutputDir)\obj\$(ProjectName)\DerivedSources\JSMouseEvent.cpp"\r
                                >\r
                                RelativePath="..\dom\MappedAttributeEntry.h"\r
                                >\r
                        </File>\r
+                       <File\r
+                               RelativePath="..\dom\MessageEvent.cpp"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\dom\MessageEvent.h"\r
+                               >\r
+                       </File>\r
                        <File\r
                                RelativePath="..\dom\MouseEvent.cpp"\r
                                >\r
index 8507898..70015f6 100644 (file)
                65DF323E09D1DE65000BE325 /* JSCanvasRenderingContext2D.h in Headers */ = {isa = PBXBuildFile; fileRef = 65DF323809D1DE65000BE325 /* JSCanvasRenderingContext2D.h */; };
                65DF326109D1E199000BE325 /* UserAgentStyleSheetsData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 656581AF09D14EE6000E61D7 /* UserAgentStyleSheetsData.cpp */; };
                65FEA86909833ADE00BED4AB /* Page.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 65FEA86809833ADE00BED4AB /* Page.cpp */; };
+               75793E830D0CE0B3007FC0AC /* MessageEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 75793E800D0CE0B3007FC0AC /* MessageEvent.cpp */; };
+               75793E840D0CE0B3007FC0AC /* MessageEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 75793E810D0CE0B3007FC0AC /* MessageEvent.h */; };
+               75793E850D0CE0B3007FC0AC /* MessageEvent.idl in Resources */ = {isa = PBXBuildFile; fileRef = 75793E820D0CE0B3007FC0AC /* MessageEvent.idl */; };
+               75793EC80D0CE72D007FC0AC /* JSMessageEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 75793EC60D0CE72D007FC0AC /* JSMessageEvent.cpp */; };
+               75793EC90D0CE72D007FC0AC /* JSMessageEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 75793EC70D0CE72D007FC0AC /* JSMessageEvent.h */; };
+               75793ED30D0CE85B007FC0AC /* DOMMessageEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 75793ED00D0CE85B007FC0AC /* DOMMessageEvent.h */; };
+               75793ED40D0CE85B007FC0AC /* DOMMessageEvent.mm in Sources */ = {isa = PBXBuildFile; fileRef = 75793ED10D0CE85B007FC0AC /* DOMMessageEvent.mm */; };
+               75793ED50D0CE85B007FC0AC /* DOMMessageEventInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 75793ED20D0CE85B007FC0AC /* DOMMessageEventInternal.h */; };
                7E6FEED80898582300C44C3F /* WebCoreScriptDebugger.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E6FEED60898582300C44C3F /* WebCoreScriptDebugger.h */; settings = {ATTRIBUTES = (Private, ); }; };
                7E6FEED90898582300C44C3F /* WebCoreScriptDebugger.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7E6FEED70898582300C44C3F /* WebCoreScriptDebugger.mm */; };
                85004D940ACEEAEF00C438F6 /* DOMSVGDefsElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 85004D880ACEEAEF00C438F6 /* DOMSVGDefsElement.h */; };
                65DF323809D1DE65000BE325 /* JSCanvasRenderingContext2D.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = JSCanvasRenderingContext2D.h; sourceTree = "<group>"; };
                65F80697054D9F86008BF776 /* BlockExceptions.mm */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = BlockExceptions.mm; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
                65FEA86809833ADE00BED4AB /* Page.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = Page.cpp; sourceTree = "<group>"; };
+               75793E800D0CE0B3007FC0AC /* MessageEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = MessageEvent.cpp; path = dom/MessageEvent.cpp; sourceTree = SOURCE_ROOT; };
+               75793E810D0CE0B3007FC0AC /* MessageEvent.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = MessageEvent.h; path = dom/MessageEvent.h; sourceTree = SOURCE_ROOT; };
+               75793E820D0CE0B3007FC0AC /* MessageEvent.idl */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; name = MessageEvent.idl; path = dom/MessageEvent.idl; sourceTree = SOURCE_ROOT; };
+               75793EC60D0CE72D007FC0AC /* JSMessageEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = JSMessageEvent.cpp; sourceTree = "<group>"; };
+               75793EC70D0CE72D007FC0AC /* JSMessageEvent.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = JSMessageEvent.h; sourceTree = "<group>"; };
+               75793ED00D0CE85B007FC0AC /* DOMMessageEvent.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = DOMMessageEvent.h; sourceTree = "<group>"; };
+               75793ED10D0CE85B007FC0AC /* DOMMessageEvent.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = DOMMessageEvent.mm; sourceTree = "<group>"; };
+               75793ED20D0CE85B007FC0AC /* DOMMessageEventInternal.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = DOMMessageEventInternal.h; sourceTree = "<group>"; };
                7E6FEED60898582300C44C3F /* WebCoreScriptDebugger.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = WebCoreScriptDebugger.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
                7E6FEED70898582300C44C3F /* WebCoreScriptDebugger.mm */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebCoreScriptDebugger.mm; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
                84B2B1F7056BEF3A00D2B771 /* WebCoreKeyGenerator.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = WebCoreKeyGenerator.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
                                85DF343F0AAFC0ED00E59AE3 /* DOMKeyboardEventPrivate.h */,
                                85FF31580AAFBFCB00374F38 /* DOMKeyboardEvent.h */,
                                85FF31590AAFBFCB00374F38 /* DOMKeyboardEvent.mm */,
+                               75793ED00D0CE85B007FC0AC /* DOMMessageEvent.h */,
+                               75793ED10D0CE85B007FC0AC /* DOMMessageEvent.mm */,
+                               75793ED20D0CE85B007FC0AC /* DOMMessageEventInternal.h */,
                                857E0B2B0AB043FC0036E447 /* DOMMouseEventPrivate.h */,
                                857E0B230AB043460036E447 /* DOMMouseEvent.h */,
                                857E0B240AB043460036E447 /* DOMMouseEvent.mm */,
                                14E8378D09F85D4F00B85AE4 /* JSEvent.h */,
                                A86629CE09DA2B47009633A5 /* JSKeyboardEvent.cpp */,
                                A86629CD09DA2B47009633A5 /* JSKeyboardEvent.h */,
+                               75793EC60D0CE72D007FC0AC /* JSMessageEvent.cpp */,
+                               75793EC70D0CE72D007FC0AC /* JSMessageEvent.h */,
                                A86629CC09DA2B47009633A5 /* JSMouseEvent.cpp */,
                                A86629CB09DA2B47009633A5 /* JSMouseEvent.h */,
                                65DF31E709D1CC60000BE325 /* JSMutationEvent.cpp */,
                                A8C4A7F409D563270003AC8D /* MappedAttribute.cpp */,
                                A8C4A7F309D563270003AC8D /* MappedAttribute.h */,
                                A8C4A84B09D5649D0003AC8D /* MappedAttributeEntry.h */,
+                               75793E800D0CE0B3007FC0AC /* MessageEvent.cpp */,
+                               75793E810D0CE0B3007FC0AC /* MessageEvent.h */,
+                               75793E820D0CE0B3007FC0AC /* MessageEvent.idl */,
                                85031B2F0A44EFC700F992E0 /* MouseEvent.cpp */,
                                85031B300A44EFC700F992E0 /* MouseEvent.h */,
                                141B94E509EC4223000E9413 /* MouseEvent.idl */,
                                B2D19A490CEF9DC1000E033B /* SVGCSSFontFace.h in Headers */,
                                BCA379150D163E5500B793D6 /* JSLocation.h in Headers */,
                                BCA3793F0D1647E000B793D6 /* JSLocation.lut.h in Headers */,
+                               75793E840D0CE0B3007FC0AC /* MessageEvent.h in Headers */,
+                               75793EC90D0CE72D007FC0AC /* JSMessageEvent.h in Headers */,
+                               75793ED30D0CE85B007FC0AC /* DOMMessageEvent.h in Headers */,
+                               75793ED50D0CE85B007FC0AC /* DOMMessageEventInternal.h in Headers */,
                                BC7FA6210D1F0CBD00DB22A9 /* DynamicNodeList.h in Headers */,
                                BC7FA62D0D1F0EFF00DB22A9 /* StaticNodeList.h in Headers */,
                                BC7FA6810D1F167900DB22A9 /* SelectorNodeList.h in Headers */,
                                B25599680D00D8BA00BB825C /* WKSpecularLightingFilter.cikernel in Resources */,
                                B255996B0D00D8BA00BB825C /* WKSpotLightFilter.cikernel in Resources */,
                                B255996E0D00D8BA00BB825C /* WKTableTransferFilter.cikernel in Resources */,
+                               75793E850D0CE0B3007FC0AC /* MessageEvent.idl in Resources */,
                                46F9D5DD0B0D60170028EE36 /* aliasCursor.png in Resources */,
                                46D4F2490AF97E810035385A /* cellCursor.png in Resources */,
                                B2AFFC900D00A5DF0030074D /* character-sets.txt in Resources */,
                                93309DF7099E64920056E581 /* markup.cpp in Sources */,
                                93309E1D099E64920056E581 /* visible_units.cpp in Sources */,
                                BCA379140D163E5500B793D6 /* JSLocation.cpp in Sources */,
+                               75793E830D0CE0B3007FC0AC /* MessageEvent.cpp in Sources */,
+                               75793EC80D0CE72D007FC0AC /* JSMessageEvent.cpp in Sources */,
+                               75793ED40D0CE85B007FC0AC /* DOMMessageEvent.mm in Sources */,
                                B2A1F2AA0CEF0ABF00442F6A /* SVGFontElement.cpp in Sources */,
                                B2A1F2AD0CEF0ABF00442F6A /* SVGGlyphElement.cpp in Sources */,
                                B2A1F2B00CEF0ABF00442F6A /* SVGMissingGlyphElement.cpp in Sources */,
index 13d5c9a..a26c322 100644 (file)
@@ -245,6 +245,7 @@ This file contains the list of files needed to build WebCore.
         DerivedSources/WebCore/JSHistory.cpp
         DerivedSources/WebCore/JSKeyboardEvent.cpp
         DerivedSources/WebCore/JSMediaList.cpp
+        DerivedSources/WebCore/JSMessageEvent.cpp
         DerivedSources/WebCore/JSMouseEvent.cpp
         DerivedSources/WebCore/JSMutationEvent.cpp
         DerivedSources/WebCore/JSNamedNodeMap.cpp
@@ -313,6 +314,7 @@ This file contains the list of files needed to build WebCore.
         dom/ExceptionCode.cpp
         dom/KeyboardEvent.cpp
         dom/MappedAttribute.cpp
+        dom/MessageEvent.cpp
         dom/MouseEvent.cpp
         dom/MouseRelatedEvent.cpp
         dom/MutationEvent.cpp
index 50dd00f..790f699 100644 (file)
 #include "config.h"
 #include "JSDOMWindow.h"
 
-#include "kjs_window.h"
+#include "Document.h"
 #include "DOMWindow.h"
+#include "ExceptionCode.h"
+#include "kjs_window.h"
+#include "kjs/object.h"
+#include "kjs/value.h"
 
 namespace WebCore {
 
@@ -70,7 +74,8 @@ bool JSDOMWindow::customGetOwnPropertySlot(KJS::ExecState* exec, const KJS::Iden
             if (entry->attr & KJS::Function) {
                 if (entry->value.functionValue == &JSDOMWindowPrototypeFunctionFocus::create
                     || entry->value.functionValue == &JSDOMWindowPrototypeFunctionBlur::create
-                    || entry->value.functionValue == &JSDOMWindowPrototypeFunctionClose::create)
+                    || entry->value.functionValue == &JSDOMWindowPrototypeFunctionClose::create
+                    || entry->value.functionValue == &JSDOMWindowPrototypeFunctionPostMessage::create)
                         slot.setStaticEntry(this, entry, KJS::staticFunctionGetter);
                 else {
                     if (!allowsAccessFrom(exec))
@@ -108,4 +113,21 @@ bool JSDOMWindow::customPut(KJS::ExecState* exec, const KJS::Identifier& propert
     return false;
 }
 
+KJS::JSValue* JSDOMWindow::postMessage(KJS::ExecState* exec, const KJS::List& args)
+{
+    DOMWindow* window = impl();
+    
+    DOMWindow* source = static_cast<JSDOMWindow*>(exec->dynamicGlobalObject())->impl();
+    String domain = source->document()->securityOrigin()->domain();
+    String uri = source->document()->documentURI();
+    String message = args[0]->toString(exec);
+    
+    if (exec->hadException())
+        return KJS::jsUndefined();
+    
+    window->postMessage(message, domain, uri, source);
+    
+    return KJS::jsUndefined();
+}
+
 } // namespace WebCore
index 3629293..6a55636 100644 (file)
@@ -32,6 +32,7 @@
 #include "Clipboard.h"
 #include "Event.h"
 #include "JSKeyboardEvent.h"
+#include "JSMessageEvent.h"
 #include "JSMouseEvent.h"
 #include "JSMutationEvent.h"
 #include "JSOverflowEvent.h"
@@ -40,6 +41,7 @@
 #include "JSUIEvent.h"
 #include "JSWheelEvent.h"
 #include "KeyboardEvent.h"
+#include "MessageEvent.h"
 #include "MouseEvent.h"
 #include "MutationEvent.h"
 #include "OverflowEvent.h"
@@ -84,6 +86,8 @@ JSValue* toJS(ExecState* exec, Event* event)
         ret = new JSMutationEvent(exec, static_cast<MutationEvent*>(event));
     else if (event->isOverflowEvent())
         ret = new JSOverflowEvent(exec, static_cast<OverflowEvent*>(event));
+    else if (event->isMessageEvent())
+        ret = new JSMessageEvent(exec, static_cast<MessageEvent*>(event));
     else if (event->isProgressEvent())
         ret = new JSProgressEvent(exec, static_cast<ProgressEvent*>(event));
     else
index 2399be6..acf86d7 100644 (file)
@@ -110,6 +110,11 @@ bool Event::isWheelEvent() const
     return false;
 }
 
+bool Event::isMessageEvent() const
+{
+    return false;
+}
+
 bool Event::isBeforeTextInsertedEvent() const
 {
     return false;
index a16a8c0..da20780 100644 (file)
@@ -106,6 +106,7 @@ namespace WebCore {
         virtual bool isTextEvent() const;
         virtual bool isDragEvent() const; // a subset of mouse events
         virtual bool isClipboardEvent() const;
+        virtual bool isMessageEvent() const;
         virtual bool isWheelEvent() const;
         virtual bool isBeforeTextInsertedEvent() const;
         virtual bool isOverflowEvent() const;
index 31f3cf8..843fb16 100644 (file)
@@ -54,6 +54,7 @@ namespace WebCore { namespace EventNames {
     macro(keypress) \
     macro(keyup) \
     macro(load) \
+    macro(message) \
     macro(mousedown) \
     macro(mousemove) \
     macro(mouseout) \
diff --git a/WebCore/dom/MessageEvent.cpp b/WebCore/dom/MessageEvent.cpp
new file mode 100644 (file)
index 0000000..863b133
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2007 Henry Mason (hmason@mac.com)
+ * Copyright (C) 2003, 2005, 2006, 2007 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ *
+ */
+
+#include "config.h"
+
+#include "DOMWindow.h"
+#include "EventNames.h"
+#include "MessageEvent.h"
+
+namespace WebCore {
+
+using namespace EventNames;
+
+MessageEvent::MessageEvent()
+{
+}
+
+MessageEvent::MessageEvent(const String& data, const String& domain, const String& uri, DOMWindow* source)
+    : Event(messageEvent, true, true)
+    , m_data(data)
+    , m_domain(domain)
+    , m_uri(uri)
+    , m_source(source)
+{
+}
+
+MessageEvent::~MessageEvent()
+{
+}
+
+void MessageEvent::initMessageEvent(const AtomicString& type, bool canBubble, bool cancelable, const String& data, const String& domain, const String& uri, DOMWindow* source)
+{
+    if (dispatched())
+        return;
+        
+    initEvent(type, canBubble, cancelable);
+    
+    m_data = data;
+    m_domain = domain;
+    m_uri = uri;
+    m_source = source;
+}
+
+bool MessageEvent::isMessageEvent() const 
+{
+    return true;
+}
+
+} // namespace WebCore
diff --git a/WebCore/dom/MessageEvent.h b/WebCore/dom/MessageEvent.h
new file mode 100644 (file)
index 0000000..c7fc53d
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2007 Henry Mason (hmason@mac.com)
+ * Copyright (C) 2003, 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ *
+ */
+
+#ifndef MessageEvent_h
+#define MessageEvent_h
+
+#include "Event.h"
+
+namespace WebCore {
+
+    class DOMWindow;
+
+    class MessageEvent : public Event {
+    public:
+        MessageEvent();
+        MessageEvent(const String& data, const String& domain, const String& uri, DOMWindow* source);
+        virtual ~MessageEvent();
+
+        void initMessageEvent(const AtomicString& type, bool canBubble, bool cancelable, const String& data, const String& domain, const String& uri, DOMWindow* source);
+        
+        const String& data() const { return m_data; }
+        const String& domain() const { return m_domain; }
+        const String& uri() const { return m_uri; }
+        DOMWindow* source() const { return m_source.get(); }
+        
+        virtual bool isMessageEvent() const;
+
+    private:    
+        String m_data;
+        String m_domain;
+        String m_uri;
+        RefPtr<DOMWindow> m_source;
+    };
+
+} // namespace WebCore
+
+#endif // MessageEvent_h
diff --git a/WebCore/dom/MessageEvent.idl b/WebCore/dom/MessageEvent.idl
new file mode 100644 (file)
index 0000000..bbb71c8
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2007 Henry Mason <hmason@mac.com>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ *
+ */
+
+module events {
+
+    interface [GenerateConstructor] MessageEvent : Event {
+
+        readonly attribute DOMString data;
+        readonly attribute DOMString domain;
+        readonly attribute DOMString uri;
+        readonly attribute DOMWindow source;
+        
+        void initMessageEvent(in DOMString typeArg, in boolean canBubbleArg, in boolean cancelableArg, in DOMString dataArg, in DOMString domainArg, in DOMString uriArg, in DOMWindow sourceArg);
+
+    };
+
+}
index 919ae0b..10f31cf 100644 (file)
@@ -41,6 +41,7 @@
 #include "FrameTree.h"
 #include "FrameView.h"
 #include "History.h"
+#include "MessageEvent.h"
 #include "Page.h"
 #include "PlatformScreen.h"
 #include "PlatformString.h"
@@ -219,6 +220,12 @@ Console* DOMWindow::console() const
     return m_console.get();
 }
 
+void DOMWindow::postMessage(const String& message, const String& domain, const String& uri, DOMWindow* source) const
+{
+   ExceptionCode ec;
+   document()->dispatchEvent(new MessageEvent(message, domain, uri, source), ec, true);
+}
+
 DOMSelection* DOMWindow::getSelection()
 {
     if (!m_selection)
index 9a536b4..09a1e14 100644 (file)
@@ -141,6 +141,8 @@ namespace WebCore {
 #endif
 
         Console* console() const;
+        
+        void postMessage(const String& message, const String& domain, const String& uri, DOMWindow* source) const;
 
         void scrollBy(int x, int y) const;
         void scrollTo(int x, int y) const;
index d1af267..5334552 100644 (file)
@@ -125,6 +125,9 @@ module window {
 
                  attribute [Replaceable] Console console;
 
+        // cross-document messaging
+        [DoNotCheckDomainSecurity, Custom] void postMessage(in DOMString message);
+
 #if defined(LANGUAGE_JAVASCRIPT)
         // Global constructors
         attribute StyleSheetConstructor StyleSheet;
@@ -240,6 +243,7 @@ module window {
         attribute HTMLUListElementConstructor HTMLUListElement;
 
         attribute EventConstructor Event;
+        attribute MessageEventConstructor MessageEvent;
         attribute KeyboardEventConstructor KeyboardEvent;
         attribute MouseEventConstructor MouseEvent;
         attribute MutationEventConstructor MutationEvent;