summaryrefslogtreecommitdiff
path: root/Source/WebCore/websockets/WebSocketChannel.cpp
diff options
context:
space:
mode:
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>2011-08-19 10:16:27 (GMT)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>2011-08-19 10:16:27 (GMT)
commitf7b7ff753be8e84253b2413a9125eebfe0315cd2 (patch)
treeadb69e0ef1529175b7707c76a784c7e0f7d95ea2 /Source/WebCore/websockets/WebSocketChannel.cpp
parente6e56a6f6233f80a95a85603fe5eaa4851406bd3 (diff)
downloadGESWebKit-master.tar.gz
GESWebKit-master.tar.xz
[WebSocket] CloseEvent's code and reason properties support.HEADmaster
https://bugs.webkit.org/show_bug.cgi?id=66362 Patch by Takashi Toyoshima <toyoshim@chromium.org> on 2011-08-19 Reviewed by Kent Tamura. Current WebSocket implementation miss code and reason properties in CloseEvent. This change expose incoming closing frame's code and reason to JavaScript API. Source/WebCore: Tests: http/tests/websocket/tests/hybi/close-code-and-reason.html http/tests/websocket/tests/hybi/workers/close-code-and-reason.html * websockets/CloseEvent.h: (WebCore::CloseEvent::initCloseEvent): (WebCore::CloseEvent::code): (WebCore::CloseEvent::reason): (WebCore::CloseEvent::CloseEvent): * websockets/CloseEvent.idl: Add code and reason properies. * websockets/ThreadableWebSocketChannelClientWrapper.cpp: (WebCore::ThreadableWebSocketChannelClientWrapper::didClose): (WebCore::ThreadableWebSocketChannelClientWrapper::didCloseCallback): * websockets/ThreadableWebSocketChannelClientWrapper.h: * websockets/WebSocket.cpp: (WebCore::WebSocket::didConnect): (WebCore::WebSocket::didClose): * websockets/WebSocket.h: Add implement to handle code and reason. * websockets/WebSocketChannel.cpp: (WebCore::WebSocketChannel::WebSocketChannel): (WebCore::WebSocketChannel::didCloseSocketStream): (WebCore::WebSocketChannel::processFrame): * websockets/WebSocketChannel.h: Add closing frame payload parser. * websockets/WebSocketChannelClient.h: (WebCore::WebSocketChannelClient::didClose): * websockets/WorkerThreadableWebSocketChannel.cpp: (WebCore::workerContextDidClose): (WebCore::WorkerThreadableWebSocketChannel::Peer::didClose): * websockets/WorkerThreadableWebSocketChannel.h: Add implement to handle code and reason. LayoutTests: * http/tests/websocket/tests/hybi/close-code-and-reason-expected.txt: Added. * http/tests/websocket/tests/hybi/close-code-and-reason.html: Added. * http/tests/websocket/tests/hybi/close-code-and-reason_wsh.py: Added. * http/tests/websocket/tests/hybi/workers/close-code-and-reason-expected.txt: Added. * http/tests/websocket/tests/hybi/workers/close-code-and-reason.html: Added. * http/tests/websocket/tests/hybi/workers/resources/close-code-and-reason.js: Added. (postResult): (ws.onopen): (ws.onmessage): (ws.onclose): git-svn-id: http://svn.webkit.org/repository/webkit/trunk@93393 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Diffstat (limited to 'Source/WebCore/websockets/WebSocketChannel.cpp')
-rw-r--r--Source/WebCore/websockets/WebSocketChannel.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/Source/WebCore/websockets/WebSocketChannel.cpp b/Source/WebCore/websockets/WebSocketChannel.cpp
index 9afc74c..ee868ff 100644
--- a/Source/WebCore/websockets/WebSocketChannel.cpp
+++ b/Source/WebCore/websockets/WebSocketChannel.cpp
@@ -98,6 +98,7 @@ WebSocketChannel::WebSocketChannel(ScriptExecutionContext* context, WebSocketCha
, m_identifier(0)
, m_useHixie76Protocol(true)
, m_hasContinuousFrame(false)
+ , m_closeEventCode(CloseEventCodeAbnormalClosure)
{
ASSERT(m_context->isDocument());
Document* document = static_cast<Document*>(m_context);
@@ -246,7 +247,7 @@ void WebSocketChannel::didCloseSocketStream(SocketStreamHandle* handle)
m_context = 0;
m_handle = 0;
if (client)
- client->didClose(m_unhandledBufferedAmount, m_receivedClosingHandshake ? WebSocketChannelClient::ClosingHandshakeComplete : WebSocketChannelClient::ClosingHandshakeIncomplete);
+ client->didClose(m_unhandledBufferedAmount, m_receivedClosingHandshake ? WebSocketChannelClient::ClosingHandshakeComplete : WebSocketChannelClient::ClosingHandshakeIncomplete, m_closeEventCode, m_closeEventReason);
}
deref();
}
@@ -623,7 +624,16 @@ bool WebSocketChannel::processFrame()
break;
case OpCodeClose:
- // FIXME: Handle payload.
+ if (frame.payloadLength >= 2) {
+ unsigned char highByte = static_cast<unsigned char>(frame.payload[0]);
+ unsigned char lowByte = static_cast<unsigned char>(frame.payload[1]);
+ m_closeEventCode = highByte << 8 | lowByte;
+ } else
+ m_closeEventCode = CloseEventCodeNoStatusRcvd;
+ if (frame.payloadLength >= 3)
+ m_closeEventReason = String::fromUTF8(&frame.payload[2], frame.payloadLength - 2);
+ else
+ m_closeEventReason = "";
skipBuffer(frame.frameEnd - m_buffer);
m_receivedClosingHandshake = true;
startClosingHandshake();