Title: [107780] trunk/Source/WebCore
Revision
107780
Author
toyos...@chromium.org
Date
2012-02-14 22:39:35 -0800 (Tue, 14 Feb 2012)

Log Message

WebSocketChannel minor refactoring for code manageability
https://bugs.webkit.org/show_bug.cgi?id=78576

Reviewed by Kent Tamura.

Change the first argument type of WebSocketChannel
from ScriptExecutionContext to Document.
WebSocketChannel always assume this ScriptExecutionContext must
inherit Document. Then, it results in many static cast.
It isn't readable and dangerous against future code changes.

* websockets/ThreadableWebSocketChannel.cpp: Pass the first argument for WebSocketChannel as Document.
(WebCore::ThreadableWebSocketChannel::create):
* websockets/WebSocketChannel.cpp: Replace all ScriptExecutionContext* m_context descriptions to Document* m_document.
(WebCore::WebSocketChannel::WebSocketChannel):
(WebCore::WebSocketChannel::connect):
(WebCore::WebSocketChannel::fail):
(WebCore::WebSocketChannel::disconnect):
(WebCore::WebSocketChannel::didOpenSocketStream):
(WebCore::WebSocketChannel::didCloseSocketStream):
(WebCore::WebSocketChannel::didReceiveSocketStreamData):
(WebCore::WebSocketChannel::didFailSocketStream):
(WebCore::WebSocketChannel::processBuffer):
(WebCore::WebSocketChannel::processOutgoingFrameQueue):
* websockets/WebSocketChannel.h: Change the first argument for construction to Document and hold it as Document m_document.
(WebCore):
(WebCore::WebSocketChannel::create):
(WebSocketChannel):
* websockets/WorkerThreadableWebSocketChannel.cpp: Pass the first argument for WebSocketChannel as Document.
(WebCore::WorkerThreadableWebSocketChannel::Peer::Peer):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (107779 => 107780)


--- trunk/Source/WebCore/ChangeLog	2012-02-15 06:00:36 UTC (rev 107779)
+++ trunk/Source/WebCore/ChangeLog	2012-02-15 06:39:35 UTC (rev 107780)
@@ -1,3 +1,36 @@
+2012-02-14  Takashi Toyoshima  <toyos...@chromium.org>
+
+        WebSocketChannel minor refactoring for code manageability
+        https://bugs.webkit.org/show_bug.cgi?id=78576
+
+        Reviewed by Kent Tamura.
+
+        Change the first argument type of WebSocketChannel
+        from ScriptExecutionContext to Document.
+        WebSocketChannel always assume this ScriptExecutionContext must
+        inherit Document. Then, it results in many static cast.
+        It isn't readable and dangerous against future code changes.
+
+        * websockets/ThreadableWebSocketChannel.cpp: Pass the first argument for WebSocketChannel as Document.
+        (WebCore::ThreadableWebSocketChannel::create):
+        * websockets/WebSocketChannel.cpp: Replace all ScriptExecutionContext* m_context descriptions to Document* m_document.
+        (WebCore::WebSocketChannel::WebSocketChannel):
+        (WebCore::WebSocketChannel::connect):
+        (WebCore::WebSocketChannel::fail):
+        (WebCore::WebSocketChannel::disconnect):
+        (WebCore::WebSocketChannel::didOpenSocketStream):
+        (WebCore::WebSocketChannel::didCloseSocketStream):
+        (WebCore::WebSocketChannel::didReceiveSocketStreamData):
+        (WebCore::WebSocketChannel::didFailSocketStream):
+        (WebCore::WebSocketChannel::processBuffer):
+        (WebCore::WebSocketChannel::processOutgoingFrameQueue):
+        * websockets/WebSocketChannel.h: Change the first argument for construction to Document and hold it as Document m_document.
+        (WebCore):
+        (WebCore::WebSocketChannel::create):
+        (WebSocketChannel):
+        * websockets/WorkerThreadableWebSocketChannel.cpp: Pass the first argument for WebSocketChannel as Document.
+        (WebCore::WorkerThreadableWebSocketChannel::Peer::Peer):
+
 2012-02-14  Noel Gordon  <noel.gor...@gmail.com>
 
         Unreviewed, rolling out r107774.

Modified: trunk/Source/WebCore/websockets/ThreadableWebSocketChannel.cpp (107779 => 107780)


--- trunk/Source/WebCore/websockets/ThreadableWebSocketChannel.cpp	2012-02-15 06:00:36 UTC (rev 107779)
+++ trunk/Source/WebCore/websockets/ThreadableWebSocketChannel.cpp	2012-02-15 06:39:35 UTC (rev 107780)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009 Google Inc.  All rights reserved.
+ * Copyright (C) 2009, 2012 Google Inc.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -34,6 +34,7 @@
 
 #include "ThreadableWebSocketChannel.h"
 
+#include "Document.h"
 #include "PlatformString.h"
 #include "ScriptExecutionContext.h"
 #include "ThreadableWebSocketChannelClientWrapper.h"
@@ -66,7 +67,7 @@
 #endif // ENABLE(WORKERS)
 
     ASSERT(context->isDocument());
-    return WebSocketChannel::create(context, client);
+    return WebSocketChannel::create(static_cast<Document*>(context), client);
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/websockets/WebSocketChannel.cpp (107779 => 107780)


--- trunk/Source/WebCore/websockets/WebSocketChannel.cpp	2012-02-15 06:00:36 UTC (rev 107779)
+++ trunk/Source/WebCore/websockets/WebSocketChannel.cpp	2012-02-15 06:39:35 UTC (rev 107780)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011 Google Inc.  All rights reserved.
+ * Copyright (C) 2011, 2012 Google Inc.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -88,8 +88,8 @@
 const WebSocketChannel::OpCode WebSocketChannel::OpCodePing = 0x9;
 const WebSocketChannel::OpCode WebSocketChannel::OpCodePong = 0xA;
 
-WebSocketChannel::WebSocketChannel(ScriptExecutionContext* context, WebSocketChannelClient* client)
-    : m_context(context)
+WebSocketChannel::WebSocketChannel(Document* document, WebSocketChannelClient* client)
+    : m_document(document)
     , m_client(client)
     , m_buffer(0)
     , m_bufferSize(0)
@@ -110,12 +110,10 @@
     , m_blobLoaderStatus(BlobLoaderNotStarted)
 #endif
 {
-    ASSERT(m_context->isDocument());
-    Document* document = static_cast<Document*>(m_context);
-    if (Settings* settings = document->settings())
+    if (Settings* settings = m_document->settings())
         m_useHixie76Protocol = settings->useHixie76WebSocketProtocol();
 
-    if (Page* page = document->page())
+    if (Page* page = m_document->page())
         m_identifier = page->progress()->createUniqueIdentifier();
 }
 
@@ -134,10 +132,10 @@
     LOG(Network, "WebSocketChannel %p connect", this);
     ASSERT(!m_handle);
     ASSERT(!m_suspended);
-    m_handshake = adoptPtr(new WebSocketHandshake(url, protocol, m_context, m_useHixie76Protocol));
+    m_handshake = adoptPtr(new WebSocketHandshake(url, protocol, m_document, m_useHixie76Protocol));
     m_handshake->reset();
     if (m_identifier)
-        InspectorInstrumentation::didCreateWebSocket(m_context, m_identifier, url, m_context->url());
+        InspectorInstrumentation::didCreateWebSocket(m_document, m_identifier, url, m_document->url());
     ref();
     m_handle = SocketStreamHandle::create(m_handshake->url(), this);
 }
@@ -228,8 +226,8 @@
 {
     LOG(Network, "WebSocketChannel %p fail: %s", this, reason.utf8().data());
     ASSERT(!m_suspended);
-    if (m_context)
-        m_context->addConsoleMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, reason, m_handshake->clientOrigin());
+    if (m_document)
+        m_document->addConsoleMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, reason, m_handshake->clientOrigin());
     if (!m_useHixie76Protocol) {
         // Hybi-10 specification explicitly states we must not continue to handle incoming data
         // once the WebSocket connection is failed (section 7.1.7).
@@ -247,12 +245,12 @@
 void WebSocketChannel::disconnect()
 {
     LOG(Network, "WebSocketChannel %p disconnect", this);
-    if (m_identifier && m_context)
-        InspectorInstrumentation::didCloseWebSocket(m_context, m_identifier);
+    if (m_identifier && m_document)
+        InspectorInstrumentation::didCloseWebSocket(m_document, m_identifier);
     if (m_handshake)
         m_handshake->clearScriptExecutionContext();
     m_client = 0;
-    m_context = 0;
+    m_document = 0;
     if (m_handle)
         m_handle->disconnect();
 }
@@ -273,10 +271,10 @@
 {
     LOG(Network, "WebSocketChannel %p didOpenSocketStream", this);
     ASSERT(handle == m_handle);
-    if (!m_context)
+    if (!m_document)
         return;
     if (m_identifier)
-        InspectorInstrumentation::willSendWebSocketHandshakeRequest(m_context, m_identifier, m_handshake->clientHandshakeRequest());
+        InspectorInstrumentation::willSendWebSocketHandshakeRequest(m_document, m_identifier, m_handshake->clientHandshakeRequest());
     CString handshakeMessage = m_handshake->clientHandshakeMessage();
     if (!handle->send(handshakeMessage.data(), handshakeMessage.length()))
         fail("Failed to send WebSocket handshake.");
@@ -285,8 +283,8 @@
 void WebSocketChannel::didCloseSocketStream(SocketStreamHandle* handle)
 {
     LOG(Network, "WebSocketChannel %p didCloseSocketStream", this);
-    if (m_identifier && m_context)
-        InspectorInstrumentation::didCloseWebSocket(m_context, m_identifier);
+    if (m_identifier && m_document)
+        InspectorInstrumentation::didCloseWebSocket(m_document, m_identifier);
     ASSERT_UNUSED(handle, handle == m_handle || !m_handle);
     m_closed = true;
     if (m_closingTimer.isActive())
@@ -299,7 +297,7 @@
             return;
         WebSocketChannelClient* client = m_client;
         m_client = 0;
-        m_context = 0;
+        m_document = 0;
         m_handle = 0;
         if (client)
             client->didClose(m_unhandledBufferedAmount, m_receivedClosingHandshake ? WebSocketChannelClient::ClosingHandshakeComplete : WebSocketChannelClient::ClosingHandshakeIncomplete, m_closeEventCode, m_closeEventReason);
@@ -312,7 +310,7 @@
     LOG(Network, "WebSocketChannel %p didReceiveSocketStreamData %d", this, len);
     RefPtr<WebSocketChannel> protect(this); // The client can close the channel, potentially removing the last reference.
     ASSERT(handle == m_handle);
-    if (!m_context) {
+    if (!m_document) {
         return;
     }
     if (len <= 0) {
@@ -346,7 +344,7 @@
 {
     LOG(Network, "WebSocketChannel %p didFailSocketStream", this);
     ASSERT(handle == m_handle || !m_handle);
-    if (m_context) {
+    if (m_document) {
         String message;
         if (error.isNull())
             message = "WebSocket network error";
@@ -358,7 +356,7 @@
         ASSERT(failingURL.isNull() || m_handshake->url().string() == failingURL);
         if (failingURL.isNull())
             failingURL = m_handshake->url().string();
-        m_context->addConsoleMessage(NetworkMessageSource, LogMessageType, ErrorMessageLevel, message, failingURL);
+        m_document->addConsoleMessage(NetworkMessageSource, LogMessageType, ErrorMessageLevel, message, failingURL);
     }
     m_shouldDiscardReceivedData = true;
     handle->disconnect();
@@ -464,14 +462,11 @@
             return false;
         if (m_handshake->mode() == WebSocketHandshake::Connected) {
             if (m_identifier)
-                InspectorInstrumentation::didReceiveWebSocketHandshakeResponse(m_context, m_identifier, m_handshake->serverHandshakeResponse());
+                InspectorInstrumentation::didReceiveWebSocketHandshakeResponse(m_document, m_identifier, m_handshake->serverHandshakeResponse());
             if (!m_handshake->serverSetCookie().isEmpty()) {
-                if (m_context->isDocument()) {
-                    Document* document = static_cast<Document*>(m_context);
-                    if (cookiesEnabled(document)) {
-                        ExceptionCode ec; // Exception (for sandboxed documents) ignored.
-                        document->setCookie(m_handshake->serverSetCookie(), ec);
-                    }
+                if (cookiesEnabled(m_document)) {
+                    ExceptionCode ec; // Exception (for sandboxed documents) ignored.
+                    m_document->setCookie(m_handshake->serverSetCookie(), ec);
                 }
             }
             // FIXME: handle set-cookie2.
@@ -922,7 +917,7 @@
                 ASSERT(!m_blobLoader);
                 m_blobLoader = adoptPtr(new FileReaderLoader(FileReaderLoader::ReadAsArrayBuffer, this));
                 m_blobLoaderStatus = BlobLoaderStarted;
-                m_blobLoader->start(m_context, frame->blobData.get());
+                m_blobLoader->start(m_document, frame->blobData.get());
                 m_outgoingFrameQueue.prepend(frame.release());
                 return;
 

Modified: trunk/Source/WebCore/websockets/WebSocketChannel.h (107779 => 107780)


--- trunk/Source/WebCore/websockets/WebSocketChannel.h	2012-02-15 06:00:36 UTC (rev 107779)
+++ trunk/Source/WebCore/websockets/WebSocketChannel.h	2012-02-15 06:39:35 UTC (rev 107780)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011 Google Inc.  All rights reserved.
+ * Copyright (C) 2011, 2012 Google Inc.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -46,8 +46,8 @@
 namespace WebCore {
 
 class Blob;
+class Document;
 class FileReaderLoader;
-class ScriptExecutionContext;
 class SocketStreamHandle;
 class SocketStreamError;
 class WebSocketChannelClient;
@@ -59,7 +59,7 @@
 {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    static PassRefPtr<WebSocketChannel> create(ScriptExecutionContext* context, WebSocketChannelClient* client) { return adoptRef(new WebSocketChannel(context, client)); }
+    static PassRefPtr<WebSocketChannel> create(Document* document, WebSocketChannelClient* client) { return adoptRef(new WebSocketChannel(document, client)); }
     virtual ~WebSocketChannel();
 
     bool send(const char* data, int length);
@@ -119,7 +119,7 @@
     virtual void derefThreadableWebSocketChannel() { deref(); }
 
 private:
-    WebSocketChannel(ScriptExecutionContext*, WebSocketChannelClient*);
+    WebSocketChannel(Document*, WebSocketChannelClient*);
 
     bool appendToBuffer(const char* data, size_t len);
     void skipBuffer(size_t len);
@@ -220,7 +220,7 @@
     };
 #endif
 
-    ScriptExecutionContext* m_context;
+    Document* m_document;
     WebSocketChannelClient* m_client;
     OwnPtr<WebSocketHandshake> m_handshake;
     RefPtr<SocketStreamHandle> m_handle;

Modified: trunk/Source/WebCore/websockets/WorkerThreadableWebSocketChannel.cpp (107779 => 107780)


--- trunk/Source/WebCore/websockets/WorkerThreadableWebSocketChannel.cpp	2012-02-15 06:00:36 UTC (rev 107779)
+++ trunk/Source/WebCore/websockets/WorkerThreadableWebSocketChannel.cpp	2012-02-15 06:39:35 UTC (rev 107780)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011 Google Inc.  All rights reserved.
+ * Copyright (C) 2011, 2012 Google Inc.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -36,6 +36,7 @@
 
 #include "Blob.h"
 #include "CrossThreadTask.h"
+#include "Document.h"
 #include "PlatformString.h"
 #include "ScriptExecutionContext.h"
 #include "ThreadableWebSocketChannelClientWrapper.h"
@@ -151,7 +152,7 @@
 WorkerThreadableWebSocketChannel::Peer::Peer(PassRefPtr<ThreadableWebSocketChannelClientWrapper> clientWrapper, WorkerLoaderProxy& loaderProxy, ScriptExecutionContext* context, const String& taskMode)
     : m_workerClientWrapper(clientWrapper)
     , m_loaderProxy(loaderProxy)
-    , m_mainWebSocketChannel(WebSocketChannel::create(context, this))
+    , m_mainWebSocketChannel(WebSocketChannel::create(static_cast<Document*>(context), this))
     , m_taskMode(taskMode)
 {
     ASSERT(isMainThread());
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to