WebSocket: Receive binary message as Blob
https://bugs.webkit.org/show_bug.cgi?id=67115
Reviewed by Kent Tamura.
Source/WebCore:
Make WebSocketChannel be able to receive WebSocket binary messages and deliver them via
didReceiveBinaryData() callback of WebSocketChannelClient.
Tests: http/tests/websocket/tests/hybi/fragmented-binary-frames.html
http/tests/websocket/tests/hybi/receive-blob.html
http/tests/websocket/tests/hybi/workers/receive-blob.html
* bindings/js/JSMessageEventCustom.cpp:
(WebCore::JSMessageEvent::data): Convert Blob to JSValue.
* bindings/v8/custom/V8MessageEventCustom.cpp:
(WebCore::V8MessageEvent::dataAccessorGetter): Convert Blob to v8::Value.
* dom/MessageEvent.cpp:
(WebCore::MessageEvent::MessageEvent):
* dom/MessageEvent.h:
Added DataTypeBlob and Blob-related functions.
(WebCore::MessageEvent::create):
(WebCore::MessageEvent::dataAsBlob):
* websockets/ThreadableWebSocketChannelClientWrapper.cpp:
(WebCore::ThreadableWebSocketChannelClientWrapper::didReceiveBinaryData):
(WebCore::ThreadableWebSocketChannelClientWrapper::didReceiveBinaryDataCallback):
* websockets/ThreadableWebSocketChannelClientWrapper.h:
* websockets/WebSocket.cpp:
(WebCore::WebSocket::didReceiveBinaryData):
If binaryType attribute is "blob", construct a Blob using BlobData filled with the given
binary message.
* websockets/WebSocket.h:
* websockets/WebSocketChannel.cpp:
(WebCore::WebSocketChannel::processFrame):
Create continuousFrameData as OwnPtr<> rather than stack-allocated value so we can easily
pass it to didReceiveBinaryData() callback.
Save the content of a fragmented message even if it is a binary opcode.
* websockets/WebSocketChannelClient.h:
(WebCore::WebSocketChannelClient::didReceiveBinaryData):
* websockets/WorkerThreadableWebSocketChannel.cpp:
(WebCore::workerContextDidReceiveBinaryData):
(WebCore::WorkerThreadableWebSocketChannel::Peer::didReceiveBinaryData):
Pass binaryData as PassOwnPtr<Vector<char> > to deliver the value efficiently (without
copying the content) across threads.
* websockets/WorkerThreadableWebSocketChannel.h:
LayoutTests:
* http/tests/websocket/tests/hybi/binary-frames_wsh.py: Added. Used from receive-blob.html.
* http/tests/websocket/tests/hybi/fragmented-binary-frames-expected.txt: Added.
* http/tests/websocket/tests/hybi/fragmented-binary-frames.html:
Added. The content of this test is almost identical to receive-blob.html.
* http/tests/websocket/tests/hybi/fragmented-binary-frames_wsh.py: Added.
* http/tests/websocket/tests/hybi/receive-blob-expected.txt: Added.
* http/tests/websocket/tests/hybi/receive-blob.html:
Added. It is a bit complicated to validate the content of a Blob, because a Blob must be read
asynchronously. FileReader is used to read a blob as an ArrayBuffer, each byte of which is
compared with the expected result.
* http/tests/websocket/tests/hybi/workers/receive-blob-expected.txt: Added.
* http/tests/websocket/tests/hybi/workers/receive-blob.html: Added.
* http/tests/websocket/tests/hybi/workers/resources/binary-frames_wsh.py:
Added. Same as above binary-frames_wsh.py.
* http/tests/websocket/tests/hybi/workers/resources/receive-blob.js: Added.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@94041 268f45cc-cd09-0410-ab3c-d52691b4dbfc
24 files changed