Title: [92759] trunk
Revision
92759
Author
[email protected]
Date
2011-08-10 02:19:51 -0700 (Wed, 10 Aug 2011)

Log Message

WebSocket: Add binaryType attribute
https://bugs.webkit.org/show_bug.cgi?id=65967

Reviewed by Kent Tamura.

Source/WebCore:

Add a new attribute "binaryType" to WebSocket. It controls the data type of MessageEvent
for WebSocket's binary frames.

Tests: http/tests/websocket/tests/hixie76/undefined-attributes.html
       http/tests/websocket/tests/hybi/binary-type.html

* websockets/WebSocket.cpp:
(WebCore::WebSocket::WebSocket):
(WebCore::WebSocket::binaryType):
(WebCore::WebSocket::setBinaryType):
* websockets/WebSocket.h:
* websockets/WebSocket.idl:

LayoutTests:

* http/tests/websocket/tests/hixie76/undefined-attributes-expected.txt: Added.
* http/tests/websocket/tests/hixie76/undefined-attributes.html: Added.
* http/tests/websocket/tests/hybi/binary-type-expected.txt: Added.
* http/tests/websocket/tests/hybi/binary-type.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (92758 => 92759)


--- trunk/LayoutTests/ChangeLog	2011-08-10 09:09:39 UTC (rev 92758)
+++ trunk/LayoutTests/ChangeLog	2011-08-10 09:19:51 UTC (rev 92759)
@@ -1,5 +1,17 @@
 2011-08-10  Yuta Kitamura  <[email protected]>
 
+        WebSocket: Add binaryType attribute
+        https://bugs.webkit.org/show_bug.cgi?id=65967
+
+        Reviewed by Kent Tamura.
+
+        * http/tests/websocket/tests/hixie76/undefined-attributes-expected.txt: Added.
+        * http/tests/websocket/tests/hixie76/undefined-attributes.html: Added.
+        * http/tests/websocket/tests/hybi/binary-type-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/binary-type.html: Added.
+
+2011-08-10  Yuta Kitamura  <[email protected]>
+
         WebSocket: Accept multiple subprotocols
         https://bugs.webkit.org/show_bug.cgi?id=65247
 

Added: trunk/LayoutTests/http/tests/websocket/tests/hixie76/undefined-attributes-expected.txt (0 => 92759)


--- trunk/LayoutTests/http/tests/websocket/tests/hixie76/undefined-attributes-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/websocket/tests/hixie76/undefined-attributes-expected.txt	2011-08-10 09:19:51 UTC (rev 92759)
@@ -0,0 +1,9 @@
+Test WebSocket attributes which should not be defined when hixie-76 protocol is used.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+PASS ws.binaryType is undefined.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/http/tests/websocket/tests/hixie76/undefined-attributes.html (0 => 92759)


--- trunk/LayoutTests/http/tests/websocket/tests/hixie76/undefined-attributes.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/websocket/tests/hixie76/undefined-attributes.html	2011-08-10 09:19:51 UTC (rev 92759)
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<html>
+<head>
+<link rel="stylesheet" href=""
+<script src=""
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/_javascript_">
+description("Test WebSocket attributes which should not be defined when hixie-76 protocol is used.");
+
+var ws = new WebSocket("ws://127.0.0.1:8880/websocket/tests/hixie76/simple");
+
+shouldBeUndefined("ws.binaryType");
+
+var successfullyParsed = true;
+</script>
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/http/tests/websocket/tests/hybi/binary-type-expected.txt (0 => 92759)


--- trunk/LayoutTests/http/tests/websocket/tests/hybi/binary-type-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/websocket/tests/hybi/binary-type-expected.txt	2011-08-10 09:19:51 UTC (rev 92759)
@@ -0,0 +1,14 @@
+Test WebSocket.binaryType attribute.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+PASS ws.binaryType is "blob"
+PASS ws.binaryType is "arraybuffer"
+PASS ws.binaryType is "blob"
+PASS ws.binaryType = 'Blob' threw exception Error: SYNTAX_ERR: DOM Exception 12.
+PASS ws.binaryType = 'ArrayBuffer' threw exception Error: SYNTAX_ERR: DOM Exception 12.
+PASS ws.binaryType = '' threw exception Error: SYNTAX_ERR: DOM Exception 12.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/http/tests/websocket/tests/hybi/binary-type.html (0 => 92759)


--- trunk/LayoutTests/http/tests/websocket/tests/hybi/binary-type.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/websocket/tests/hybi/binary-type.html	2011-08-10 09:19:51 UTC (rev 92759)
@@ -0,0 +1,33 @@
+<!DOCTYPE html>
+<html>
+<head>
+<link rel="stylesheet" href=""
+<script src=""
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script>
+description("Test WebSocket.binaryType attribute.");
+
+if (window.layoutTestController)
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+var ws = new WebSocket("ws://localhost:8880/websocket/tests/hybi/simple");
+shouldBeEqualToString("ws.binaryType", "blob");
+
+ws.binaryType = "arraybuffer";
+shouldBeEqualToString("ws.binaryType", "arraybuffer");
+
+ws.binaryType = "blob";
+shouldBeEqualToString("ws.binaryType", "blob");
+
+shouldThrow("ws.binaryType = 'Blob'", "'Error: SYNTAX_ERR: DOM Exception 12'");
+shouldThrow("ws.binaryType = 'ArrayBuffer'", "'Error: SYNTAX_ERR: DOM Exception 12'");
+shouldThrow("ws.binaryType = ''", "'Error: SYNTAX_ERR: DOM Exception 12'");
+
+var successfullyParsed = true;
+</script>
+<script src=""
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (92758 => 92759)


--- trunk/Source/WebCore/ChangeLog	2011-08-10 09:09:39 UTC (rev 92758)
+++ trunk/Source/WebCore/ChangeLog	2011-08-10 09:19:51 UTC (rev 92759)
@@ -1,5 +1,25 @@
 2011-08-10  Yuta Kitamura  <[email protected]>
 
+        WebSocket: Add binaryType attribute
+        https://bugs.webkit.org/show_bug.cgi?id=65967
+
+        Reviewed by Kent Tamura.
+
+        Add a new attribute "binaryType" to WebSocket. It controls the data type of MessageEvent
+        for WebSocket's binary frames.
+
+        Tests: http/tests/websocket/tests/hixie76/undefined-attributes.html
+               http/tests/websocket/tests/hybi/binary-type.html
+
+        * websockets/WebSocket.cpp:
+        (WebCore::WebSocket::WebSocket):
+        (WebCore::WebSocket::binaryType):
+        (WebCore::WebSocket::setBinaryType):
+        * websockets/WebSocket.h:
+        * websockets/WebSocket.idl:
+
+2011-08-10  Yuta Kitamura  <[email protected]>
+
         WebSocket: Accept multiple subprotocols
         https://bugs.webkit.org/show_bug.cgi?id=65247
 

Modified: trunk/Source/WebCore/websockets/WebSocket.cpp (92758 => 92759)


--- trunk/Source/WebCore/websockets/WebSocket.cpp	2011-08-10 09:09:39 UTC (rev 92758)
+++ trunk/Source/WebCore/websockets/WebSocket.cpp	2011-08-10 09:19:51 UTC (rev 92759)
@@ -135,6 +135,7 @@
     : ActiveDOMObject(context, this)
     , m_state(CONNECTING)
     , m_bufferedAmountAfterClose(0)
+    , m_binaryType(BinaryTypeBlob)
 {
 }
 
@@ -291,6 +292,36 @@
     return m_bufferedAmountAfterClose;
 }
 
+String WebSocket::binaryType() const
+{
+    if (m_channel->useHixie76Protocol())
+        return String();
+    switch (m_binaryType) {
+    case BinaryTypeBlob:
+        return "blob";
+    case BinaryTypeArrayBuffer:
+        return "arraybuffer";
+    }
+    ASSERT_NOT_REACHED();
+    return String();
+}
+
+void WebSocket::setBinaryType(const String& binaryType, ExceptionCode& ec)
+{
+    if (m_channel->useHixie76Protocol())
+        return;
+    if (binaryType == "blob") {
+        m_binaryType = BinaryTypeBlob;
+        return;
+    }
+    if (binaryType == "arraybuffer") {
+        m_binaryType = BinaryTypeArrayBuffer;
+        return;
+    }
+    ec = SYNTAX_ERR;
+    return;
+}
+
 ScriptExecutionContext* WebSocket::scriptExecutionContext() const
 {
     return ActiveDOMObject::scriptExecutionContext();

Modified: trunk/Source/WebCore/websockets/WebSocket.h (92758 => 92759)


--- trunk/Source/WebCore/websockets/WebSocket.h	2011-08-10 09:09:39 UTC (rev 92758)
+++ trunk/Source/WebCore/websockets/WebSocket.h	2011-08-10 09:19:51 UTC (rev 92759)
@@ -74,6 +74,9 @@
         State readyState() const;
         unsigned long bufferedAmount() const;
 
+        String binaryType() const;
+        void setBinaryType(const String& binaryType, ExceptionCode&);
+
         DEFINE_ATTRIBUTE_EVENT_LISTENER(open);
         DEFINE_ATTRIBUTE_EVENT_LISTENER(message);
         DEFINE_ATTRIBUTE_EVENT_LISTENER(error);
@@ -107,12 +110,18 @@
         virtual EventTargetData* eventTargetData();
         virtual EventTargetData* ensureEventTargetData();
 
+        enum BinaryType {
+            BinaryTypeBlob,
+            BinaryTypeArrayBuffer
+        };
+
         RefPtr<ThreadableWebSocketChannel> m_channel;
 
         State m_state;
         KURL m_url;
         EventTargetData m_eventTargetData;
         unsigned long m_bufferedAmountAfterClose;
+        BinaryType m_binaryType;
     };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/websockets/WebSocket.idl (92758 => 92759)


--- trunk/Source/WebCore/websockets/WebSocket.idl	2011-08-10 09:09:39 UTC (rev 92758)
+++ trunk/Source/WebCore/websockets/WebSocket.idl	2011-08-10 09:19:51 UTC (rev 92759)
@@ -58,6 +58,9 @@
         attribute EventListener onerror;
         attribute EventListener onclose;
 
+        attribute [ConvertNullStringTo=Undefined] DOMString binaryType
+            setter raises(DOMException);
+
         [RequiresAllArguments] boolean send(in DOMString data) raises(DOMException);
         void close();
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to