Title: [90704] trunk/Source/WebCore
Revision
90704
Author
[email protected]
Date
2011-07-10 19:04:32 -0700 (Sun, 10 Jul 2011)

Log Message

WebSocket: Add useHixie76Protocol flag to WebSocketChannel and WebSocketHandshake
https://bugs.webkit.org/show_bug.cgi?id=64244

Reviewed by Kent Tamura.

Get the value of Settings::useHixie76WebSocketProtocol() and save it in
WebSocketChannel and WebSocketHandshake instances. Obtained flag value
is not used for now.

No behavior change, thus no new tests.

* websockets/WebSocketChannel.cpp:
(WebCore::WebSocketChannel::WebSocketChannel):
WebSocketChannel is always created in context of Document (see
ThreadableWebSocketChannel::create()).
Because m_useHixie76Protocol must be passed to WebSocketHandshake
constructor, WebSocketHandshake instance is allocated dynamically
and stored in OwnPtr.
(WebCore::WebSocketChannel::connect):
(WebCore::WebSocketChannel::fail):
(WebCore::WebSocketChannel::disconnect):
(WebCore::WebSocketChannel::didOpen):
(WebCore::WebSocketChannel::didFail):
(WebCore::WebSocketChannel::processBuffer):
* websockets/WebSocketChannel.h:
* websockets/WebSocketHandshake.cpp:
(WebCore::WebSocketHandshake::WebSocketHandshake):
* websockets/WebSocketHandshake.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (90703 => 90704)


--- trunk/Source/WebCore/ChangeLog	2011-07-11 02:03:35 UTC (rev 90703)
+++ trunk/Source/WebCore/ChangeLog	2011-07-11 02:04:32 UTC (rev 90704)
@@ -1,3 +1,34 @@
+2011-07-10  Yuta Kitamura  <[email protected]>
+
+        WebSocket: Add useHixie76Protocol flag to WebSocketChannel and WebSocketHandshake
+        https://bugs.webkit.org/show_bug.cgi?id=64244
+
+        Reviewed by Kent Tamura.
+
+        Get the value of Settings::useHixie76WebSocketProtocol() and save it in
+        WebSocketChannel and WebSocketHandshake instances. Obtained flag value
+        is not used for now.
+
+        No behavior change, thus no new tests.
+
+        * websockets/WebSocketChannel.cpp:
+        (WebCore::WebSocketChannel::WebSocketChannel):
+        WebSocketChannel is always created in context of Document (see
+        ThreadableWebSocketChannel::create()).
+        Because m_useHixie76Protocol must be passed to WebSocketHandshake
+        constructor, WebSocketHandshake instance is allocated dynamically
+        and stored in OwnPtr.
+        (WebCore::WebSocketChannel::connect):
+        (WebCore::WebSocketChannel::fail):
+        (WebCore::WebSocketChannel::disconnect):
+        (WebCore::WebSocketChannel::didOpen):
+        (WebCore::WebSocketChannel::didFail):
+        (WebCore::WebSocketChannel::processBuffer):
+        * websockets/WebSocketChannel.h:
+        * websockets/WebSocketHandshake.cpp:
+        (WebCore::WebSocketHandshake::WebSocketHandshake):
+        * websockets/WebSocketHandshake.h:
+
 2011-07-10  Tom Hudson  <[email protected]>
 
         Reviewed by James Robinson.

Modified: trunk/Source/WebCore/websockets/WebSocketChannel.cpp (90703 => 90704)


--- trunk/Source/WebCore/websockets/WebSocketChannel.cpp	2011-07-11 02:03:35 UTC (rev 90703)
+++ trunk/Source/WebCore/websockets/WebSocketChannel.cpp	2011-07-11 02:04:32 UTC (rev 90704)
@@ -42,6 +42,7 @@
 #include "ProgressTracker.h"
 #include "ScriptCallStack.h"
 #include "ScriptExecutionContext.h"
+#include "Settings.h"
 #include "SocketStreamError.h"
 #include "SocketStreamHandle.h"
 #include "WebSocketChannelClient.h"
@@ -61,7 +62,6 @@
 WebSocketChannel::WebSocketChannel(ScriptExecutionContext* context, WebSocketChannelClient* client, const KURL& url, const String& protocol)
     : m_context(context)
     , m_client(client)
-    , m_handshake(url, protocol, context)
     , m_buffer(0)
     , m_bufferSize(0)
     , m_resumeTimer(this, &WebSocketChannel::resumeTimerFired)
@@ -73,11 +73,16 @@
     , m_shouldDiscardReceivedData(false)
     , m_unhandledBufferedAmount(0)
     , m_identifier(0)
+    , m_useHixie76Protocol(true)
 {
-    if (m_context->isDocument())
-        if (Page* page = static_cast<Document*>(m_context)->page())
-            m_identifier = page->progress()->createUniqueIdentifier();
+    ASSERT(m_context->isDocument());
+    Document* document = static_cast<Document*>(m_context);
+    if (Settings* settings = document->settings())
+        m_useHixie76Protocol = settings->useHixie76WebSocketProtocol();
+    m_handshake = adoptPtr(new WebSocketHandshake(url, protocol, context, m_useHixie76Protocol));
 
+    if (Page* page = document->page())
+        m_identifier = page->progress()->createUniqueIdentifier();
     if (m_identifier)
         InspectorInstrumentation::didCreateWebSocket(m_context, m_identifier, url, m_context->url());
 }
@@ -92,9 +97,9 @@
     LOG(Network, "WebSocketChannel %p connect", this);
     ASSERT(!m_handle);
     ASSERT(!m_suspended);
-    m_handshake.reset();
+    m_handshake->reset();
     ref();
-    m_handle = SocketStreamHandle::create(m_handshake.url(), this);
+    m_handle = SocketStreamHandle::create(m_handshake->url(), this);
 }
 
 bool WebSocketChannel::send(const String& msg)
@@ -134,7 +139,7 @@
     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);
+        m_context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, reason, 0, m_handshake->clientOrigin(), 0);
     if (m_handle && !m_closed)
         m_handle->disconnect(); // Will call didClose().
 }
@@ -144,7 +149,7 @@
     LOG(Network, "WebSocketChannel %p disconnect", this);
     if (m_identifier && m_context)
         InspectorInstrumentation::didCloseWebSocket(m_context, m_identifier);
-    m_handshake.clearScriptExecutionContext();
+    m_handshake->clearScriptExecutionContext();
     m_client = 0;
     m_context = 0;
     if (m_handle)
@@ -170,8 +175,8 @@
     if (!m_context)
         return;
     if (m_identifier)
-        InspectorInstrumentation::willSendWebSocketHandshakeRequest(m_context, m_identifier, m_handshake.clientHandshakeRequest());
-    CString handshakeMessage = m_handshake.clientHandshakeMessage();
+        InspectorInstrumentation::willSendWebSocketHandshakeRequest(m_context, m_identifier, m_handshake->clientHandshakeRequest());
+    CString handshakeMessage = m_handshake->clientHandshakeMessage();
     if (!handle->send(handshakeMessage.data(), handshakeMessage.length()))
         fail("Failed to send WebSocket handshake.");
 }
@@ -241,9 +246,9 @@
         else
             message = "WebSocket network error: " + error.localizedDescription();
         String failingURL = error.failingURL();
-        ASSERT(failingURL.isNull() || m_handshake.url().string() == failingURL);
+        ASSERT(failingURL.isNull() || m_handshake->url().string() == failingURL);
         if (failingURL.isNull())
-            failingURL = m_handshake.url().string();
+            failingURL = m_handshake->url().string();
         m_context->addMessage(OtherMessageSource, NetworkErrorMessageType, ErrorMessageLevel, message, 0, failingURL, 0);
     }
     m_shouldDiscardReceivedData = true;
@@ -307,19 +312,19 @@
 
     RefPtr<WebSocketChannel> protect(this); // The client can close the channel, potentially removing the last reference.
 
-    if (m_handshake.mode() == WebSocketHandshake::Incomplete) {
-        int headerLength = m_handshake.readServerHandshake(m_buffer, m_bufferSize);
+    if (m_handshake->mode() == WebSocketHandshake::Incomplete) {
+        int headerLength = m_handshake->readServerHandshake(m_buffer, m_bufferSize);
         if (headerLength <= 0)
             return false;
-        if (m_handshake.mode() == WebSocketHandshake::Connected) {
+        if (m_handshake->mode() == WebSocketHandshake::Connected) {
             if (m_identifier)
-                InspectorInstrumentation::didReceiveWebSocketHandshakeResponse(m_context, m_identifier, m_handshake.serverHandshakeResponse());
-            if (!m_handshake.serverSetCookie().isEmpty()) {
+                InspectorInstrumentation::didReceiveWebSocketHandshakeResponse(m_context, 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);
+                        document->setCookie(m_handshake->serverSetCookie(), ec);
                     }
                 }
             }
@@ -330,14 +335,14 @@
             LOG(Network, "remaining in read buf %lu", static_cast<unsigned long>(m_bufferSize));
             return m_buffer;
         }
-        ASSERT(m_handshake.mode() == WebSocketHandshake::Failed);
+        ASSERT(m_handshake->mode() == WebSocketHandshake::Failed);
         LOG(Network, "WebSocketChannel %p connection failed", this);
         skipBuffer(headerLength);
         m_shouldDiscardReceivedData = true;
-        fail(m_handshake.failureReason());
+        fail(m_handshake->failureReason());
         return false;
     }
-    if (m_handshake.mode() != WebSocketHandshake::Connected)
+    if (m_handshake->mode() != WebSocketHandshake::Connected)
         return false;
 
     const char* nextFrame = m_buffer;

Modified: trunk/Source/WebCore/websockets/WebSocketChannel.h (90703 => 90704)


--- trunk/Source/WebCore/websockets/WebSocketChannel.h	2011-07-11 02:03:35 UTC (rev 90703)
+++ trunk/Source/WebCore/websockets/WebSocketChannel.h	2011-07-11 02:04:32 UTC (rev 90704)
@@ -90,7 +90,7 @@
 
         ScriptExecutionContext* m_context;
         WebSocketChannelClient* m_client;
-        WebSocketHandshake m_handshake;
+        OwnPtr<WebSocketHandshake> m_handshake;
         RefPtr<SocketStreamHandle> m_handle;
         char* m_buffer;
         size_t m_bufferSize;
@@ -105,6 +105,8 @@
         unsigned long m_unhandledBufferedAmount;
 
         unsigned long m_identifier; // m_identifier == 0 means that we could not obtain a valid identifier.
+
+        bool m_useHixie76Protocol;
     };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/websockets/WebSocketHandshake.cpp (90703 => 90704)


--- trunk/Source/WebCore/websockets/WebSocketHandshake.cpp	2011-07-11 02:03:35 UTC (rev 90703)
+++ trunk/Source/WebCore/websockets/WebSocketHandshake.cpp	2011-07-11 02:04:32 UTC (rev 90704)
@@ -159,11 +159,12 @@
     memcpy(expectedChallenge, digest.data(), 16);
 }
 
-WebSocketHandshake::WebSocketHandshake(const KURL& url, const String& protocol, ScriptExecutionContext* context)
+WebSocketHandshake::WebSocketHandshake(const KURL& url, const String& protocol, ScriptExecutionContext* context, bool useHixie76Protocol)
     : m_url(url)
     , m_clientProtocol(protocol)
     , m_secure(m_url.protocolIs("wss"))
     , m_context(context)
+    , m_useHixie76Protocol(useHixie76Protocol)
     , m_mode(Incomplete)
 {
     uint32_t number1;

Modified: trunk/Source/WebCore/websockets/WebSocketHandshake.h (90703 => 90704)


--- trunk/Source/WebCore/websockets/WebSocketHandshake.h	2011-07-11 02:03:35 UTC (rev 90703)
+++ trunk/Source/WebCore/websockets/WebSocketHandshake.h	2011-07-11 02:04:32 UTC (rev 90704)
@@ -48,7 +48,7 @@
         enum Mode {
             Incomplete, Normal, Failed, Connected
         };
-        WebSocketHandshake(const KURL&, const String& protocol, ScriptExecutionContext*);
+        WebSocketHandshake(const KURL&, const String& protocol, ScriptExecutionContext*, bool useHixie76Protocol);
         ~WebSocketHandshake();
 
         const KURL& url() const;
@@ -97,6 +97,7 @@
         String m_clientProtocol;
         bool m_secure;
         ScriptExecutionContext* m_context;
+        bool m_useHixie76Protocol;
 
         Mode m_mode;
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to