12011-05-25 Yuta Kitamura <yutak@chromium.org>
2
3 Reviewed by NOBODY (OOPS!).
4
5 WebSocket closing handshake
6 https://bugs.webkit.org/show_bug.cgi?id=35721
7
8 Implement WebSocket closing handshake based on Ian Hickson's
9 WebSocket protocol draft 76.
10
11 Tests: http/tests/websocket/tests/client-close.html
12 http/tests/websocket/tests/server-close.html
13
14 * platform/network/SocketStreamHandleBase.cpp:
15 (WebCore::SocketStreamHandleBase::send):
16 Do not send a message if we are in Closing state.
17 (WebCore::SocketStreamHandleBase::close):
18 Do not disconnect if we have pending data which have not been sent yet.
19 In this case, the actual disconnection will happen in sendPendingData().
20 (WebCore::SocketStreamHandleBase::disconnect):
21 Renamed from close(). Disconnect the connection immediately.
22 (WebCore::SocketStreamHandleBase::sendPendingData):
23 * platform/network/SocketStreamHandleBase.h:
24 * websockets/ThreadableWebSocketChannelClientWrapper.cpp:
25 Add didStartClosingHandshake(). Add a function argument (receiveClosingHandshake)
26 to didClose().
27 (WebCore::ThreadableWebSocketChannelClientWrapper::didStartClosingHandshake):
28 (WebCore::ThreadableWebSocketChannelClientWrapper::didClose):
29 (WebCore::ThreadableWebSocketChannelClientWrapper::didStartClosingHandshakeCallback):
30 (WebCore::ThreadableWebSocketChannelClientWrapper::didCloseCallback):
31 * websockets/ThreadableWebSocketChannelClientWrapper.h:
32 * websockets/WebSocket.cpp:
33 (WebCore::WebSocket::send):
34 (WebCore::WebSocket::close):
35 Fail if close() is attempted before the connection is established.
36 Otherwise, set the state to CLOSING and start the closing handshake.
37 (WebCore::WebSocket::bufferedAmount):
38 If the state is CLOSING, we need to consider buffered data in m_channel and sent after close().
39 (WebCore::WebSocket::didConnect):
40 (WebCore::WebSocket::didReceiveMessage):
41 We need to invoke message event in CLOSING state as well as OPEN state.
42 (WebCore::WebSocket::didReceiveMessageError):
43 (WebCore::WebSocket::didStartClosingHandshake):
44 (WebCore::WebSocket::didClose):
45 * websockets/WebSocket.h:
46 * websockets/WebSocketChannel.cpp:
47 (WebCore::WebSocketChannel::WebSocketChannel):
48 (WebCore::WebSocketChannel::close):
49 Start the closing handshake.
50 (WebCore::WebSocketChannel::disconnect):
51 Disconnect the socket stream, instead of close.
52 (WebCore::WebSocketChannel::didClose):
53 (WebCore::WebSocketChannel::didReceiveData): Ditto.
54 (WebCore::WebSocketChannel::didFail): Ditto.
55 (WebCore::WebSocketChannel::processBuffer):
56 Ditto.
57 Handle 0xFF 0x00 byte sequence, and discard received data once the closing handshake has started.
58 (WebCore::WebSocketChannel::startClosingHandshake):
59 Send 0xFF 0x00 byte sequence.
60 (WebCore::WebSocketChannel::closingTimerFired):
61 Disconnect the socket stream if the closing handshake has timed out.
62 * websockets/WebSocketChannel.h:
63 m_closing is true if "the WebSocket closing handshake has started" (as stated in the protocol
64 specification).
65 * websockets/WebSocketChannelClient.h:
66 (WebCore::WebSocketChannelClient::didStartClosingHandshake): Added.
67 (WebCore::WebSocketChannelClient::didClose): Add receivedClosingHandshake parameter.
68 * websockets/WorkerThreadableWebSocketChannel.cpp:
69 Add receivedClosingHandshake parameter to close(), and add didStartClosingHandshake().
70 (WebCore::WorkerThreadableWebSocketChannel::Peer::close):
71 (WebCore::workerContextDidStartClosingHandshake):
72 (WebCore::WorkerThreadableWebSocketChannel::Peer::didStartClosingHandshake):
73 (WebCore::workerContextDidClose):
74 (WebCore::WorkerThreadableWebSocketChannel::Peer::didClose):
75 * websockets/WorkerThreadableWebSocketChannel.h:
76