2011-05-24 Yuta Kitamura <yutak@chromium.org>
authoryutak@chromium.org <yutak@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 24 May 2011 09:15:49 +0000 (09:15 +0000)
committeryutak@chromium.org <yutak@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 24 May 2011 09:15:49 +0000 (09:15 +0000)
        Reviewed by Kent Tamura.

        WebSocket: Add fail() to WebSocketChannel and its family
        https://bugs.webkit.org/show_bug.cgi?id=61277

        This is the first part of refactoring effort described in bug 61115.
        Existing error reports will be modified to use fail() in a later patch.

        No change in behavior, thus no new tests.

        * websockets/ThreadableWebSocketChannel.h:
        * websockets/WebSocketChannel.cpp:
        (WebCore::WebSocketChannel::fail):
        * websockets/WebSocketChannel.h:
        * websockets/WorkerThreadableWebSocketChannel.cpp:
        (WebCore::WorkerThreadableWebSocketChannel::fail):
        (WebCore::WorkerThreadableWebSocketChannel::Peer::fail):
        (WebCore::WorkerThreadableWebSocketChannel::mainThreadFail):
        (WebCore::WorkerThreadableWebSocketChannel::Bridge::fail):
        * websockets/WorkerThreadableWebSocketChannel.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@87139 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/websockets/ThreadableWebSocketChannel.h
Source/WebCore/websockets/WebSocketChannel.cpp
Source/WebCore/websockets/WebSocketChannel.h
Source/WebCore/websockets/WorkerThreadableWebSocketChannel.cpp
Source/WebCore/websockets/WorkerThreadableWebSocketChannel.h

index ce8f799..4a023c1 100644 (file)
@@ -1,3 +1,26 @@
+2011-05-24  Yuta Kitamura  <yutak@chromium.org>
+
+        Reviewed by Kent Tamura.
+
+        WebSocket: Add fail() to WebSocketChannel and its family
+        https://bugs.webkit.org/show_bug.cgi?id=61277
+
+        This is the first part of refactoring effort described in bug 61115.
+        Existing error reports will be modified to use fail() in a later patch.
+
+        No change in behavior, thus no new tests.
+
+        * websockets/ThreadableWebSocketChannel.h:
+        * websockets/WebSocketChannel.cpp:
+        (WebCore::WebSocketChannel::fail):
+        * websockets/WebSocketChannel.h:
+        * websockets/WorkerThreadableWebSocketChannel.cpp:
+        (WebCore::WorkerThreadableWebSocketChannel::fail):
+        (WebCore::WorkerThreadableWebSocketChannel::Peer::fail):
+        (WebCore::WorkerThreadableWebSocketChannel::mainThreadFail):
+        (WebCore::WorkerThreadableWebSocketChannel::Bridge::fail):
+        * websockets/WorkerThreadableWebSocketChannel.h:
+
 2011-05-24  Andras Becsi  <abecsi@webkit.org>
 
         Reviewed by Csaba Osztrogon√°c.
index 956e0fe..344ec6c 100644 (file)
@@ -53,6 +53,8 @@ public:
     virtual bool send(const String& message) = 0;
     virtual unsigned long bufferedAmount() const = 0;
     virtual void close() = 0;
+    // Log the reason text and close the connection. Will call didClose().
+    virtual void fail(const String& reason) = 0;
     virtual void disconnect() = 0; // Will suppress didClose().
 
     virtual void suspend() = 0;
index c2a7b8c..a31c155 100644 (file)
@@ -121,6 +121,16 @@ void WebSocketChannel::close()
         m_handle->close();  // will call didClose()
 }
 
+void WebSocketChannel::fail(const String& reason)
+{
+    LOG(Network, "WebSocketChannel %p fail: %s", this, reason.utf8().data());
+    ASSERT(!m_suspended);
+    if (m_context)
+        m_context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, reason, 0, m_handshake.clientOrigin(), 0);
+    if (m_handle)
+        m_handle->close(); // Will call didClose().
+}
+
 void WebSocketChannel::disconnect()
 {
     LOG(Network, "WebSocketChannel %p disconnect", this);
index a39cd0e..cd4bdb8 100644 (file)
@@ -58,7 +58,8 @@ namespace WebCore {
         virtual bool send(const String& message);
         virtual unsigned long bufferedAmount() const;
         virtual void close();
-        virtual void disconnect(); // Will suppress didClose().
+        virtual void fail(const String& reason);
+        virtual void disconnect();
 
         virtual void suspend();
         virtual void resume();
index 5d84495..69fa288 100644 (file)
@@ -88,6 +88,12 @@ void WorkerThreadableWebSocketChannel::close()
         m_bridge->close();
 }
 
+void WorkerThreadableWebSocketChannel::fail(const String& reason)
+{
+    if (m_bridge)
+        m_bridge->fail(reason);
+}
+
 void WorkerThreadableWebSocketChannel::disconnect()
 {
     m_bridge->disconnect();
@@ -171,6 +177,14 @@ void WorkerThreadableWebSocketChannel::Peer::close()
     m_mainWebSocketChannel = 0;
 }
 
+void WorkerThreadableWebSocketChannel::Peer::fail(const String& reason)
+{
+    ASSERT(isMainThread());
+    if (!m_mainWebSocketChannel)
+        return;
+    m_mainWebSocketChannel->fail(reason);
+}
+
 void WorkerThreadableWebSocketChannel::Peer::disconnect()
 {
     ASSERT(isMainThread());
@@ -286,8 +300,7 @@ void WorkerThreadableWebSocketChannel::Bridge::connect()
 {
     ASSERT(m_workerClientWrapper);
     ASSERT(m_peer);
-    m_loaderProxy.postTaskToLoader(
-        createCallbackTask(&WorkerThreadableWebSocketChannel::mainThreadConnect, AllowCrossThreadAccess(m_peer)));
+    m_loaderProxy.postTaskToLoader(createCallbackTask(&WorkerThreadableWebSocketChannel::mainThreadConnect, AllowCrossThreadAccess(m_peer)));
 }
 
 void WorkerThreadableWebSocketChannel::mainThreadSend(ScriptExecutionContext* context, Peer* peer, const String& message)
@@ -305,9 +318,7 @@ bool WorkerThreadableWebSocketChannel::Bridge::send(const String& message)
         return false;
     ASSERT(m_peer);
     setMethodNotCompleted();
-    m_loaderProxy.postTaskToLoader(
-        createCallbackTask(&WorkerThreadableWebSocketChannel::mainThreadSend,
-                           AllowCrossThreadAccess(m_peer), message));
+    m_loaderProxy.postTaskToLoader(createCallbackTask(&WorkerThreadableWebSocketChannel::mainThreadSend, AllowCrossThreadAccess(m_peer), message));
     RefPtr<Bridge> protect(this);
     waitForMethodCompletion();
     ThreadableWebSocketChannelClientWrapper* clientWrapper = m_workerClientWrapper.get();
@@ -329,8 +340,7 @@ unsigned long WorkerThreadableWebSocketChannel::Bridge::bufferedAmount()
         return 0;
     ASSERT(m_peer);
     setMethodNotCompleted();
-    m_loaderProxy.postTaskToLoader(
-        createCallbackTask(&WorkerThreadableWebSocketChannel::mainThreadBufferedAmount, AllowCrossThreadAccess(m_peer)));
+    m_loaderProxy.postTaskToLoader(createCallbackTask(&WorkerThreadableWebSocketChannel::mainThreadBufferedAmount, AllowCrossThreadAccess(m_peer)));
     RefPtr<Bridge> protect(this);
     waitForMethodCompletion();
     ThreadableWebSocketChannelClientWrapper* clientWrapper = m_workerClientWrapper.get();
@@ -351,8 +361,22 @@ void WorkerThreadableWebSocketChannel::mainThreadClose(ScriptExecutionContext* c
 void WorkerThreadableWebSocketChannel::Bridge::close()
 {
     ASSERT(m_peer);
-    m_loaderProxy.postTaskToLoader(
-        createCallbackTask(&WorkerThreadableWebSocketChannel::mainThreadClose, AllowCrossThreadAccess(m_peer)));
+    m_loaderProxy.postTaskToLoader(createCallbackTask(&WorkerThreadableWebSocketChannel::mainThreadClose, AllowCrossThreadAccess(m_peer)));
+}
+
+void WorkerThreadableWebSocketChannel::mainThreadFail(ScriptExecutionContext* context, Peer* peer, const String& reason)
+{
+    ASSERT(isMainThread());
+    ASSERT_UNUSED(context, context->isDocument());
+    ASSERT(peer);
+
+    peer->fail(reason);
+}
+
+void WorkerThreadableWebSocketChannel::Bridge::fail(const String& reason)
+{
+    ASSERT(m_peer);
+    m_loaderProxy.postTaskToLoader(createCallbackTask(&WorkerThreadableWebSocketChannel::mainThreadFail, AllowCrossThreadAccess(m_peer), reason));
 }
 
 void WorkerThreadableWebSocketChannel::mainThreadDestroy(ScriptExecutionContext* context, Peer* peer)
@@ -370,8 +394,7 @@ void WorkerThreadableWebSocketChannel::Bridge::disconnect()
     if (m_peer) {
         Peer* peer = m_peer;
         m_peer = 0;
-        m_loaderProxy.postTaskToLoader(
-            createCallbackTask(&mainThreadDestroy, AllowCrossThreadAccess(peer)));
+        m_loaderProxy.postTaskToLoader(createCallbackTask(&mainThreadDestroy, AllowCrossThreadAccess(peer)));
     }
     m_workerContext = 0;
 }
@@ -388,8 +411,7 @@ void WorkerThreadableWebSocketChannel::mainThreadSuspend(ScriptExecutionContext*
 void WorkerThreadableWebSocketChannel::Bridge::suspend()
 {
     ASSERT(m_peer);
-    m_loaderProxy.postTaskToLoader(
-        createCallbackTask(&WorkerThreadableWebSocketChannel::mainThreadSuspend, AllowCrossThreadAccess(m_peer)));
+    m_loaderProxy.postTaskToLoader(createCallbackTask(&WorkerThreadableWebSocketChannel::mainThreadSuspend, AllowCrossThreadAccess(m_peer)));
 }
 
 void WorkerThreadableWebSocketChannel::mainThreadResume(ScriptExecutionContext* context, Peer* peer)
@@ -404,8 +426,7 @@ void WorkerThreadableWebSocketChannel::mainThreadResume(ScriptExecutionContext*
 void WorkerThreadableWebSocketChannel::Bridge::resume()
 {
     ASSERT(m_peer);
-    m_loaderProxy.postTaskToLoader(
-        createCallbackTask(&WorkerThreadableWebSocketChannel::mainThreadResume, AllowCrossThreadAccess(m_peer)));
+    m_loaderProxy.postTaskToLoader(createCallbackTask(&WorkerThreadableWebSocketChannel::mainThreadResume, AllowCrossThreadAccess(m_peer)));
 }
 
 void WorkerThreadableWebSocketChannel::Bridge::clearClientWrapper()
index 9f0b01a..6e09786 100644 (file)
@@ -64,6 +64,7 @@ public:
     virtual bool send(const String& message);
     virtual unsigned long bufferedAmount() const;
     virtual void close();
+    virtual void fail(const String& reason);
     virtual void disconnect(); // Will suppress didClose().
     virtual void suspend();
     virtual void resume();
@@ -91,6 +92,7 @@ private:
         void send(const String& message);
         void bufferedAmount();
         void close();
+        void fail(const String& reason);
         void disconnect();
         void suspend();
         void resume();
@@ -120,6 +122,7 @@ private:
         bool send(const String& message);
         unsigned long bufferedAmount();
         void close();
+        void fail(const String& reason);
         void disconnect();
         void suspend();
         void resume();
@@ -154,6 +157,7 @@ private:
     static void mainThreadSend(ScriptExecutionContext*, Peer*, const String& message);
     static void mainThreadBufferedAmount(ScriptExecutionContext*, Peer*);
     static void mainThreadClose(ScriptExecutionContext*, Peer*);
+    static void mainThreadFail(ScriptExecutionContext*, Peer*, const String& reason);
     static void mainThreadDestroy(ScriptExecutionContext*, Peer*);
     static void mainThreadSuspend(ScriptExecutionContext*, Peer*);
     static void mainThreadResume(ScriptExecutionContext*, Peer*);