Skip to content
Permalink
Browse files
2010-03-05 Fumitoshi Ukai <ukai@chromium.org>
        Reviewed by Alexey Proskuryakov.

        WebSocket onmessageerror event handler
        https://bugs.webkit.org/show_bug.cgi?id=35570

        * websocket/tests/error-detect-expected.txt: Added.
        * websocket/tests/error-detect.html: Added.
        * websocket/tests/script-tests/error-detect.js: Added.
        * websocket/tests/unknown-frame-type_wsh.py: Added.
2010-03-05  Fumitoshi Ukai  <ukai@chromium.org>

        Reviewed by Alexey Proskuryakov.

        WebSocket onmessageerror event handler
        https://bugs.webkit.org/show_bug.cgi?id=35570

        Test: websocket/tests/error-detect.html

        * websockets/WebSocket.cpp:
        (WebCore::WebSocketChannel::didConnect): assert scriptExecutionContext.
        (WebCore::WebSocketChannel::didReceiveMessage): assert scriptExecutionContext.
        (WebCore::WebSocket::didReceiveMessageError):
        (WebCore::WebSocket::didClose): assert scriptExecutionContext.
        * websockets/WebSocket.h:
        * websockets/WebSocket.idl: Add onerror event listener
        * websockets/WebSocketChannel.cpp:
        (WebCore::WebSocketChannel::didReceiveData): call didReceiveMessageError if unknown frame tye is detected, or frame length overflowed.
        * websockets/WebSocketChannelClient.h:
        (WebCore::WebSocketChannelClient::didReceiveMessageError):

Canonical link: https://commits.webkit.org/46870@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@55573 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Fumitoshi Ukai committed Mar 5, 2010
1 parent 15191f4 commit 936fca087b407dabfe22e1b15bd848c6e2e5af53
Showing 11 changed files with 125 additions and 6 deletions.
@@ -1,3 +1,15 @@
2010-03-05 Fumitoshi Ukai <ukai@chromium.org>

Reviewed by Alexey Proskuryakov.

WebSocket onmessageerror event handler
https://bugs.webkit.org/show_bug.cgi?id=35570

* websocket/tests/error-detect-expected.txt: Added.
* websocket/tests/error-detect.html: Added.
* websocket/tests/script-tests/error-detect.js: Added.
* websocket/tests/unknown-frame-type_wsh.py: Added.

2010-03-04 Fumitoshi Ukai <ukai@chromium.org>

Reviewed by Alexey Proskuryakov.
@@ -0,0 +1,12 @@
Make sure WebSocket correctly fire error event for unknown frame type.

On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".

WebSocket is open
received:done
WebSocket is closed
PASS errorCount is 255
PASS successfullyParsed is true

TEST COMPLETE

@@ -0,0 +1,13 @@
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<link rel="stylesheet" href="../../fast/js/resources/js-test-style.css">
<script src="../../fast/js/resources/js-test-pre.js"></script>
<script src="../../fast/js/resources/js-test-post-function.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script src="script-tests/error-detect.js"></script>
</body>
</html>
@@ -0,0 +1,29 @@
description("Make sure WebSocket correctly fire error event for unknown frame type.");
if (window.layoutTestController)
layoutTestController.waitUntilDone();

var errorCount = 0;

function finish() {
shouldBe("errorCount", "255");
isSuccessfullyParsed();
if (window.layoutTestController)
layoutTestController.notifyDone();
}

var ws = new WebSocket("ws://127.0.0.1:8880/websocket/tests/unknown-frame-type");
ws.onopen = function () {
debug("WebSocket is open");
};
ws.onmessage = function (evt) {
debug("received:" + evt.data);
};
ws.onerror = function () {
errorCount += 1;
};
ws.onclose = function () {
debug("WebSocket is closed");
finish();
};

var successfullyParsed = true;
@@ -0,0 +1,12 @@
from mod_pywebsocket import msgutil

def web_socket_do_extra_handshake(request):
pass

def web_socket_transfer_data(request):
for i in range(1, 128):
request.connection.write(chr(i) + str(i) + '\xff')
for i in range(128, 256):
msg = str(i)
request.connection.write(chr(i) + chr(len(msg)) + msg)
msgutil.send_message(request, 'done')
@@ -1,3 +1,24 @@
2010-03-05 Fumitoshi Ukai <ukai@chromium.org>

Reviewed by Alexey Proskuryakov.

WebSocket onmessageerror event handler
https://bugs.webkit.org/show_bug.cgi?id=35570

Test: websocket/tests/error-detect.html

* websockets/WebSocket.cpp:
(WebCore::WebSocketChannel::didConnect): assert scriptExecutionContext.
(WebCore::WebSocketChannel::didReceiveMessage): assert scriptExecutionContext.
(WebCore::WebSocket::didReceiveMessageError):
(WebCore::WebSocket::didClose): assert scriptExecutionContext.
* websockets/WebSocket.h:
* websockets/WebSocket.idl: Add onerror event listener
* websockets/WebSocketChannel.cpp:
(WebCore::WebSocketChannel::didReceiveData): call didReceiveMessageError if unknown frame tye is detected, or frame length overflowed.
* websockets/WebSocketChannelClient.h:
(WebCore::WebSocketChannelClient::didReceiveMessageError):

2010-03-04 Garret Kelly <gdk@chromium.org>

Reviewed by Darin Fisher.
@@ -227,29 +227,41 @@ void WebSocket::stop()
void WebSocket::didConnect()
{
LOG(Network, "WebSocket %p didConnect", this);
if (m_state != CONNECTING || !scriptExecutionContext()) {
if (m_state != CONNECTING) {
didClose(0);
return;
}
ASSERT(scriptExecutionContext());
m_state = OPEN;
dispatchEvent(Event::create(eventNames().openEvent, false, false));
}

void WebSocket::didReceiveMessage(const String& msg)
{
LOG(Network, "WebSocket %p didReceiveMessage %s", this, msg.utf8().data());
if (m_state != OPEN || !scriptExecutionContext())
if (m_state != OPEN)
return;
ASSERT(scriptExecutionContext());
RefPtr<MessageEvent> evt = MessageEvent::create();
evt->initMessageEvent(eventNames().messageEvent, false, false, SerializedScriptValue::create(msg), "", "", 0, 0);
dispatchEvent(evt);
}

void WebSocket::didReceiveMessageError()
{
LOG(Network, "WebSocket %p didReceiveErrorMessage", this);
if (m_state != OPEN)
return;
ASSERT(scriptExecutionContext());
dispatchEvent(Event::create(eventNames().errorEvent, false, false));
}

void WebSocket::didClose(unsigned long unhandledBufferedAmount)
{
LOG(Network, "WebSocket %p didClose", this);
m_state = CLOSED;
m_bufferedAmountAfterClose += unhandledBufferedAmount;
ASSERT(scriptExecutionContext());
dispatchEvent(Event::create(eventNames().closeEvent, false, false));
m_channel = 0;
if (hasPendingActivity())
@@ -76,6 +76,7 @@ namespace WebCore {

DEFINE_ATTRIBUTE_EVENT_LISTENER(open);
DEFINE_ATTRIBUTE_EVENT_LISTENER(message);
DEFINE_ATTRIBUTE_EVENT_LISTENER(error);
DEFINE_ATTRIBUTE_EVENT_LISTENER(close);

// EventTarget
@@ -91,6 +92,7 @@ namespace WebCore {
// WebSocketChannelClient
virtual void didConnect();
virtual void didReceiveMessage(const String& message);
virtual void didReceiveMessageError();
virtual void didClose(unsigned long unhandledBufferedAmount);

private:
@@ -101,10 +103,6 @@ namespace WebCore {
virtual EventTargetData* eventTargetData();
virtual EventTargetData* ensureEventTargetData();

void dispatchOpenEvent(Event*);
void dispatchMessageEvent(Event*);
void dispatchCloseEvent(Event*);

RefPtr<ThreadableWebSocketChannel> m_channel;

State m_state;
@@ -49,6 +49,7 @@ module websockets {
// networking
attribute EventListener onopen;
attribute EventListener onmessage;
attribute EventListener onerror;
attribute EventListener onclose;

[Custom] boolean send(in DOMString data)
@@ -199,6 +199,9 @@ void WebSocketChannel::didReceiveData(SocketStreamHandle* handle, const char* da
while (p < end) {
if (length > std::numeric_limits<int>::max() / 128) {
LOG(Network, "frame length overflow %d", length);
m_client->didReceiveMessageError();
if (!m_client)
return;
handle->close();
return;
}
@@ -211,6 +214,9 @@ void WebSocketChannel::didReceiveData(SocketStreamHandle* handle, const char* da
if (p + length < end) {
p += length;
nextFrame = p;
m_client->didReceiveMessageError();
if (!m_client)
return;
} else
break;
} else {
@@ -220,6 +226,8 @@ void WebSocketChannel::didReceiveData(SocketStreamHandle* handle, const char* da
if (p < end && *p == '\xff') {
if (frameByte == 0x00)
m_client->didReceiveMessage(String::fromUTF8(msgStart, p - msgStart));
else
m_client->didReceiveMessageError();
if (!m_client)
return;
++p;
@@ -40,6 +40,7 @@ namespace WebCore {
virtual ~WebSocketChannelClient() { }
virtual void didConnect() { }
virtual void didReceiveMessage(const String&) { }
virtual void didReceiveMessageError() { }
virtual void didClose(unsigned long /* unhandledBufferedAmount */) { }

protected:

0 comments on commit 936fca0

Please sign in to comment.