Changeset 90704 in webkit


Ignore:
Timestamp:
Jul 10, 2011 7:04:32 PM (13 years ago)
Author:
yutak@chromium.org
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:
Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r90701 r90704  
     12011-07-10  Yuta Kitamura  <yutak@chromium.org>
     2
     3        WebSocket: Add useHixie76Protocol flag to WebSocketChannel and WebSocketHandshake
     4        https://bugs.webkit.org/show_bug.cgi?id=64244
     5
     6        Reviewed by Kent Tamura.
     7
     8        Get the value of Settings::useHixie76WebSocketProtocol() and save it in
     9        WebSocketChannel and WebSocketHandshake instances. Obtained flag value
     10        is not used for now.
     11
     12        No behavior change, thus no new tests.
     13
     14        * websockets/WebSocketChannel.cpp:
     15        (WebCore::WebSocketChannel::WebSocketChannel):
     16        WebSocketChannel is always created in context of Document (see
     17        ThreadableWebSocketChannel::create()).
     18        Because m_useHixie76Protocol must be passed to WebSocketHandshake
     19        constructor, WebSocketHandshake instance is allocated dynamically
     20        and stored in OwnPtr.
     21        (WebCore::WebSocketChannel::connect):
     22        (WebCore::WebSocketChannel::fail):
     23        (WebCore::WebSocketChannel::disconnect):
     24        (WebCore::WebSocketChannel::didOpen):
     25        (WebCore::WebSocketChannel::didFail):
     26        (WebCore::WebSocketChannel::processBuffer):
     27        * websockets/WebSocketChannel.h:
     28        * websockets/WebSocketHandshake.cpp:
     29        (WebCore::WebSocketHandshake::WebSocketHandshake):
     30        * websockets/WebSocketHandshake.h:
     31
    1322011-07-10  Tom Hudson  <tomhudson@google.com>
    233
  • trunk/Source/WebCore/websockets/WebSocketChannel.cpp

    r87883 r90704  
    4343#include "ScriptCallStack.h"
    4444#include "ScriptExecutionContext.h"
     45#include "Settings.h"
    4546#include "SocketStreamError.h"
    4647#include "SocketStreamHandle.h"
     
    6263    : m_context(context)
    6364    , m_client(client)
    64     , m_handshake(url, protocol, context)
    6565    , m_buffer(0)
    6666    , m_bufferSize(0)
     
    7474    , m_unhandledBufferedAmount(0)
    7575    , m_identifier(0)
    76 {
    77     if (m_context->isDocument())
    78         if (Page* page = static_cast<Document*>(m_context)->page())
    79             m_identifier = page->progress()->createUniqueIdentifier();
    80 
     76    , m_useHixie76Protocol(true)
     77{
     78    ASSERT(m_context->isDocument());
     79    Document* document = static_cast<Document*>(m_context);
     80    if (Settings* settings = document->settings())
     81        m_useHixie76Protocol = settings->useHixie76WebSocketProtocol();
     82    m_handshake = adoptPtr(new WebSocketHandshake(url, protocol, context, m_useHixie76Protocol));
     83
     84    if (Page* page = document->page())
     85        m_identifier = page->progress()->createUniqueIdentifier();
    8186    if (m_identifier)
    8287        InspectorInstrumentation::didCreateWebSocket(m_context, m_identifier, url, m_context->url());
     
    9398    ASSERT(!m_handle);
    9499    ASSERT(!m_suspended);
    95     m_handshake.reset();
     100    m_handshake->reset();
    96101    ref();
    97     m_handle = SocketStreamHandle::create(m_handshake.url(), this);
     102    m_handle = SocketStreamHandle::create(m_handshake->url(), this);
    98103}
    99104
     
    135140    ASSERT(!m_suspended);
    136141    if (m_context)
    137         m_context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, reason, 0, m_handshake.clientOrigin(), 0);
     142        m_context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, reason, 0, m_handshake->clientOrigin(), 0);
    138143    if (m_handle && !m_closed)
    139144        m_handle->disconnect(); // Will call didClose().
     
    145150    if (m_identifier && m_context)
    146151        InspectorInstrumentation::didCloseWebSocket(m_context, m_identifier);
    147     m_handshake.clearScriptExecutionContext();
     152    m_handshake->clearScriptExecutionContext();
    148153    m_client = 0;
    149154    m_context = 0;
     
    171176        return;
    172177    if (m_identifier)
    173         InspectorInstrumentation::willSendWebSocketHandshakeRequest(m_context, m_identifier, m_handshake.clientHandshakeRequest());
    174     CString handshakeMessage = m_handshake.clientHandshakeMessage();
     178        InspectorInstrumentation::willSendWebSocketHandshakeRequest(m_context, m_identifier, m_handshake->clientHandshakeRequest());
     179    CString handshakeMessage = m_handshake->clientHandshakeMessage();
    175180    if (!handle->send(handshakeMessage.data(), handshakeMessage.length()))
    176181        fail("Failed to send WebSocket handshake.");
     
    242247            message = "WebSocket network error: " + error.localizedDescription();
    243248        String failingURL = error.failingURL();
    244         ASSERT(failingURL.isNull() || m_handshake.url().string() == failingURL);
     249        ASSERT(failingURL.isNull() || m_handshake->url().string() == failingURL);
    245250        if (failingURL.isNull())
    246             failingURL = m_handshake.url().string();
     251            failingURL = m_handshake->url().string();
    247252        m_context->addMessage(OtherMessageSource, NetworkErrorMessageType, ErrorMessageLevel, message, 0, failingURL, 0);
    248253    }
     
    308313    RefPtr<WebSocketChannel> protect(this); // The client can close the channel, potentially removing the last reference.
    309314
    310     if (m_handshake.mode() == WebSocketHandshake::Incomplete) {
    311         int headerLength = m_handshake.readServerHandshake(m_buffer, m_bufferSize);
     315    if (m_handshake->mode() == WebSocketHandshake::Incomplete) {
     316        int headerLength = m_handshake->readServerHandshake(m_buffer, m_bufferSize);
    312317        if (headerLength <= 0)
    313318            return false;
    314         if (m_handshake.mode() == WebSocketHandshake::Connected) {
     319        if (m_handshake->mode() == WebSocketHandshake::Connected) {
    315320            if (m_identifier)
    316                 InspectorInstrumentation::didReceiveWebSocketHandshakeResponse(m_context, m_identifier, m_handshake.serverHandshakeResponse());
    317             if (!m_handshake.serverSetCookie().isEmpty()) {
     321                InspectorInstrumentation::didReceiveWebSocketHandshakeResponse(m_context, m_identifier, m_handshake->serverHandshakeResponse());
     322            if (!m_handshake->serverSetCookie().isEmpty()) {
    318323                if (m_context->isDocument()) {
    319324                    Document* document = static_cast<Document*>(m_context);
    320325                    if (cookiesEnabled(document)) {
    321326                        ExceptionCode ec; // Exception (for sandboxed documents) ignored.
    322                         document->setCookie(m_handshake.serverSetCookie(), ec);
     327                        document->setCookie(m_handshake->serverSetCookie(), ec);
    323328                    }
    324329                }
     
    331336            return m_buffer;
    332337        }
    333         ASSERT(m_handshake.mode() == WebSocketHandshake::Failed);
     338        ASSERT(m_handshake->mode() == WebSocketHandshake::Failed);
    334339        LOG(Network, "WebSocketChannel %p connection failed", this);
    335340        skipBuffer(headerLength);
    336341        m_shouldDiscardReceivedData = true;
    337         fail(m_handshake.failureReason());
    338         return false;
    339     }
    340     if (m_handshake.mode() != WebSocketHandshake::Connected)
     342        fail(m_handshake->failureReason());
     343        return false;
     344    }
     345    if (m_handshake->mode() != WebSocketHandshake::Connected)
    341346        return false;
    342347
  • trunk/Source/WebCore/websockets/WebSocketChannel.h

    r87674 r90704  
    9191        ScriptExecutionContext* m_context;
    9292        WebSocketChannelClient* m_client;
    93         WebSocketHandshake m_handshake;
     93        OwnPtr<WebSocketHandshake> m_handshake;
    9494        RefPtr<SocketStreamHandle> m_handle;
    9595        char* m_buffer;
     
    106106
    107107        unsigned long m_identifier; // m_identifier == 0 means that we could not obtain a valid identifier.
     108
     109        bool m_useHixie76Protocol;
    108110    };
    109111
  • trunk/Source/WebCore/websockets/WebSocketHandshake.cpp

    r87883 r90704  
    160160}
    161161
    162 WebSocketHandshake::WebSocketHandshake(const KURL& url, const String& protocol, ScriptExecutionContext* context)
     162WebSocketHandshake::WebSocketHandshake(const KURL& url, const String& protocol, ScriptExecutionContext* context, bool useHixie76Protocol)
    163163    : m_url(url)
    164164    , m_clientProtocol(protocol)
    165165    , m_secure(m_url.protocolIs("wss"))
    166166    , m_context(context)
     167    , m_useHixie76Protocol(useHixie76Protocol)
    167168    , m_mode(Incomplete)
    168169{
  • trunk/Source/WebCore/websockets/WebSocketHandshake.h

    r87883 r90704  
    4949            Incomplete, Normal, Failed, Connected
    5050        };
    51         WebSocketHandshake(const KURL&, const String& protocol, ScriptExecutionContext*);
     51        WebSocketHandshake(const KURL&, const String& protocol, ScriptExecutionContext*, bool useHixie76Protocol);
    5252        ~WebSocketHandshake();
    5353
     
    9898        bool m_secure;
    9999        ScriptExecutionContext* m_context;
     100        bool m_useHixie76Protocol;
    100101
    101102        Mode m_mode;
Note: See TracChangeset for help on using the changeset viewer.