WebSocket: Add useHixie76Protocol flag to WebSocketChannel and WebSocketHandshake
authoryutak@chromium.org <yutak@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 11 Jul 2011 02:04:32 +0000 (02:04 +0000)
committeryutak@chromium.org <yutak@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 11 Jul 2011 02:04:32 +0000 (02:04 +0000)
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:

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

Source/WebCore/ChangeLog
Source/WebCore/websockets/WebSocketChannel.cpp
Source/WebCore/websockets/WebSocketChannel.h
Source/WebCore/websockets/WebSocketHandshake.cpp
Source/WebCore/websockets/WebSocketHandshake.h

index 9017e7c62a6f5a6c966dbd831709dc360cd6c143..a74932b66c47f393cd22f70e99eac542adfd0a49 100644 (file)
@@ -1,3 +1,34 @@
+2011-07-10  Yuta Kitamura  <yutak@chromium.org>
+
+        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  <tomhudson@google.com>
 
         Reviewed by James Robinson.
index 4ca29d772674b23da913111945c3e76f0575f626..6fb31af03afcc1cea014eea7a38c11fec7f36a29 100644 (file)
@@ -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 @@ const double TCPMaximumSegmentLifetime = 2 * 60.0;
 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 @@ WebSocketChannel::WebSocketChannel(ScriptExecutionContext* context, WebSocketCha
     , 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 @@ void WebSocketChannel::connect()
     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 @@ 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);
+        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 @@ void WebSocketChannel::disconnect()
     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 @@ void WebSocketChannel::didOpen(SocketStreamHandle* handle)
     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 @@ void WebSocketChannel::didFail(SocketStreamHandle* handle, const SocketStreamErr
         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 @@ bool WebSocketChannel::processBuffer()
 
     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 @@ bool WebSocketChannel::processBuffer()
             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;
index 5d572896ccd3212ab63465c155b92be0b26f9c2c..6421feb8ce0435d0449c15d8dd3b83239cac20a8 100644 (file)
@@ -90,7 +90,7 @@ namespace WebCore {
 
         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 @@ namespace WebCore {
         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
index 74e436174603633e025306a604fcd0d3c4322a20..210c30ee6efaa8d5f49805147d482808cb27ae20 100644 (file)
@@ -159,11 +159,12 @@ static void generateExpectedChallengeResponse(uint32_t number1, uint32_t number2
     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;
index 5556eef51471274bd4185993cd86f6330bbe2656..3808e611f60608272aca2ba55898923ab8254062 100644 (file)
@@ -48,7 +48,7 @@ namespace WebCore {
         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 @@ namespace WebCore {
         String m_clientProtocol;
         bool m_secure;
         ScriptExecutionContext* m_context;
+        bool m_useHixie76Protocol;
 
         Mode m_mode;