Changeset 92116 in webkit


Ignore:
Timestamp:
Aug 1, 2011 4:16:13 AM (13 years ago)
Author:
yutak@chromium.org
Message:

WebSocket: Receive URL and subprotocol in WebSocketChannel::connect()
https://bugs.webkit.org/show_bug.cgi?id=65367

Reviewed by Kent Tamura.

To implement multiple subprotocols support (bug 65247), WebSocket::connect() will need to validate
the value of subprotocols after constructing WebSocketChannel, because the result depends on which
WebSocket protocol is used, which is obtained from WebSocketChannel::useHixie76Protocol(). This
means the subprotocol value will not be available at the time of WebSocketChannel construction.

This change moves URL and subprotocol arguments in WebSocketChannel constructor to
WebSocketChannel::connect(), which allows WebSocket::connect() function to check the subprotocol
value before the actual connection is established.

Relocating URL argument is technically not necessary, but seemed legitimate in terms of functional
correspondence between WebSocket and WebSocketChannel (constructor versus connect()).

No change in behavior, thus no new tests.

  • websockets/ThreadableWebSocketChannel.cpp:

Remove "url" and "protocol" arguments from constructor and add them in connect().
(WebCore::ThreadableWebSocketChannel::create):

  • websockets/ThreadableWebSocketChannel.h:
  • websockets/WebSocket.cpp:

(WebCore::WebSocket::connect):

  • websockets/WebSocketChannel.cpp: Same as ThreadableWebSocketChannel.

(WebCore::WebSocketChannel::WebSocketChannel):
(WebCore::WebSocketChannel::connect):
InspectorInstrumentation::didCreateWebSocket() call was moved to connect() because it needs URL.
This does not change behavior, because connect() is guaranteed to be called immediately after
WebSocketChannel is constructed.

  • websockets/WebSocketChannel.h:

(WebCore::WebSocketChannel::create):

  • websockets/WorkerThreadableWebSocketChannel.cpp: Same as ThreadableWebSocketChannel.

(WebCore::WorkerThreadableWebSocketChannel::WorkerThreadableWebSocketChannel):
(WebCore::WorkerThreadableWebSocketChannel::connect):
(WebCore::WorkerThreadableWebSocketChannel::Peer::Peer):
(WebCore::WorkerThreadableWebSocketChannel::Peer::connect):
(WebCore::WorkerThreadableWebSocketChannel::Bridge::mainThreadCreateWebSocketChannel):
(WebCore::WorkerThreadableWebSocketChannel::Bridge::Bridge):
(WebCore::WorkerThreadableWebSocketChannel::mainThreadConnect):
(WebCore::WorkerThreadableWebSocketChannel::Bridge::connect):

  • websockets/WorkerThreadableWebSocketChannel.h:

(WebCore::WorkerThreadableWebSocketChannel::create):
(WebCore::WorkerThreadableWebSocketChannel::Peer::create):
(WebCore::WorkerThreadableWebSocketChannel::Bridge::create):

Location:
trunk/Source/WebCore
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r92106 r92116  
     12011-08-01  Yuta Kitamura  <yutak@chromium.org>
     2
     3        WebSocket: Receive URL and subprotocol in WebSocketChannel::connect()
     4        https://bugs.webkit.org/show_bug.cgi?id=65367
     5
     6        Reviewed by Kent Tamura.
     7
     8        To implement multiple subprotocols support (bug 65247), WebSocket::connect() will need to validate
     9        the value of subprotocols after constructing WebSocketChannel, because the result depends on which
     10        WebSocket protocol is used, which is obtained from WebSocketChannel::useHixie76Protocol(). This
     11        means the subprotocol value will not be available at the time of WebSocketChannel construction.
     12
     13        This change moves URL and subprotocol arguments in WebSocketChannel constructor to
     14        WebSocketChannel::connect(), which allows WebSocket::connect() function to check the subprotocol
     15        value before the actual connection is established.
     16
     17        Relocating URL argument is technically not necessary, but seemed legitimate in terms of functional
     18        correspondence between WebSocket and WebSocketChannel (constructor versus connect()).
     19
     20        No change in behavior, thus no new tests.
     21
     22        * websockets/ThreadableWebSocketChannel.cpp:
     23        Remove "url" and "protocol" arguments from constructor and add them in connect().
     24        (WebCore::ThreadableWebSocketChannel::create):
     25        * websockets/ThreadableWebSocketChannel.h:
     26        * websockets/WebSocket.cpp:
     27        (WebCore::WebSocket::connect):
     28        * websockets/WebSocketChannel.cpp: Same as ThreadableWebSocketChannel.
     29        (WebCore::WebSocketChannel::WebSocketChannel):
     30        (WebCore::WebSocketChannel::connect):
     31        InspectorInstrumentation::didCreateWebSocket() call was moved to connect() because it needs URL.
     32        This does not change behavior, because connect() is guaranteed to be called immediately after
     33        WebSocketChannel is constructed.
     34        * websockets/WebSocketChannel.h:
     35        (WebCore::WebSocketChannel::create):
     36        * websockets/WorkerThreadableWebSocketChannel.cpp: Same as ThreadableWebSocketChannel.
     37        (WebCore::WorkerThreadableWebSocketChannel::WorkerThreadableWebSocketChannel):
     38        (WebCore::WorkerThreadableWebSocketChannel::connect):
     39        (WebCore::WorkerThreadableWebSocketChannel::Peer::Peer):
     40        (WebCore::WorkerThreadableWebSocketChannel::Peer::connect):
     41        (WebCore::WorkerThreadableWebSocketChannel::Bridge::mainThreadCreateWebSocketChannel):
     42        (WebCore::WorkerThreadableWebSocketChannel::Bridge::Bridge):
     43        (WebCore::WorkerThreadableWebSocketChannel::mainThreadConnect):
     44        (WebCore::WorkerThreadableWebSocketChannel::Bridge::connect):
     45        * websockets/WorkerThreadableWebSocketChannel.h:
     46        (WebCore::WorkerThreadableWebSocketChannel::create):
     47        (WebCore::WorkerThreadableWebSocketChannel::Peer::create):
     48        (WebCore::WorkerThreadableWebSocketChannel::Bridge::create):
     49
    1502011-08-01  Luke Macpherson   <macpherson@chromium.org>
    251
  • trunk/Source/WebCore/websockets/ThreadableWebSocketChannel.cpp

    r52892 r92116  
    5151static const char webSocketChannelMode[] = "webSocketChannelMode";
    5252
    53 PassRefPtr<ThreadableWebSocketChannel> ThreadableWebSocketChannel::create(ScriptExecutionContext* context, WebSocketChannelClient* client, const KURL& url, const String& protocol)
     53PassRefPtr<ThreadableWebSocketChannel> ThreadableWebSocketChannel::create(ScriptExecutionContext* context, WebSocketChannelClient* client)
    5454{
    5555    ASSERT(context);
     
    6262        String mode = webSocketChannelMode;
    6363        mode.append(String::number(runLoop.createUniqueId()));
    64         return WorkerThreadableWebSocketChannel::create(workerContext, client, mode, url, protocol);
     64        return WorkerThreadableWebSocketChannel::create(workerContext, client, mode);
    6565    }
    6666#endif // ENABLE(WORKERS)
    6767
    6868    ASSERT(context->isDocument());
    69     return WebSocketChannel::create(context, client, url, protocol);
     69    return WebSocketChannel::create(context, client);
    7070}
    7171
  • trunk/Source/WebCore/websockets/ThreadableWebSocketChannel.h

    r91919 r92116  
    4848public:
    4949    ThreadableWebSocketChannel() { }
    50     static PassRefPtr<ThreadableWebSocketChannel> create(ScriptExecutionContext*, WebSocketChannelClient*, const KURL&, const String& protocol);
     50    static PassRefPtr<ThreadableWebSocketChannel> create(ScriptExecutionContext*, WebSocketChannelClient*);
    5151
    5252    virtual bool useHixie76Protocol() = 0;
    53     virtual void connect() = 0;
     53    virtual void connect(const KURL&, const String& protocol) = 0;
    5454    virtual bool send(const String& message) = 0;
    5555    virtual unsigned long bufferedAmount() const = 0;
  • trunk/Source/WebCore/websockets/WebSocket.cpp

    r87674 r92116  
    152152    }
    153153
    154     m_channel = ThreadableWebSocketChannel::create(scriptExecutionContext(), this, m_url, m_protocol);
    155     m_channel->connect();
     154    m_channel = ThreadableWebSocketChannel::create(scriptExecutionContext(), this);
     155    // FIXME: Get the value of m_channel->useHixie76Protocol() and validate the value of subprotocol
     156    // if hybi-10 protocol is used.
     157    m_channel->connect(m_url, m_protocol);
    156158    ActiveDOMObject::setPendingActivity(this);
    157159}
  • trunk/Source/WebCore/websockets/WebSocketChannel.cpp

    r92102 r92116  
    8383const WebSocketChannel::OpCode WebSocketChannel::OpCodePong = 0xA;
    8484
    85 WebSocketChannel::WebSocketChannel(ScriptExecutionContext* context, WebSocketChannelClient* client, const KURL& url, const String& protocol)
     85WebSocketChannel::WebSocketChannel(ScriptExecutionContext* context, WebSocketChannelClient* client)
    8686    : m_context(context)
    8787    , m_client(client)
     
    104104    if (Settings* settings = document->settings())
    105105        m_useHixie76Protocol = settings->useHixie76WebSocketProtocol();
    106     m_handshake = adoptPtr(new WebSocketHandshake(url, protocol, context, m_useHixie76Protocol));
    107106
    108107    if (Page* page = document->page())
    109108        m_identifier = page->progress()->createUniqueIdentifier();
    110     if (m_identifier)
    111         InspectorInstrumentation::didCreateWebSocket(m_context, m_identifier, url, m_context->url());
    112109}
    113110
     
    122119}
    123120
    124 void WebSocketChannel::connect()
     121void WebSocketChannel::connect(const KURL& url, const String& protocol)
    125122{
    126123    LOG(Network, "WebSocketChannel %p connect", this);
    127124    ASSERT(!m_handle);
    128125    ASSERT(!m_suspended);
     126    m_handshake = adoptPtr(new WebSocketHandshake(url, protocol, m_context, m_useHixie76Protocol));
    129127    m_handshake->reset();
     128    if (m_identifier)
     129        InspectorInstrumentation::didCreateWebSocket(m_context, m_identifier, url, m_context->url());
    130130    ref();
    131131    m_handle = SocketStreamHandle::create(m_handshake->url(), this);
  • trunk/Source/WebCore/websockets/WebSocketChannel.h

    r92102 r92116  
    5252        WTF_MAKE_FAST_ALLOCATED;
    5353    public:
    54         static PassRefPtr<WebSocketChannel> create(ScriptExecutionContext* context, WebSocketChannelClient* client, const KURL& url, const String& protocol) { return adoptRef(new WebSocketChannel(context, client, url, protocol)); }
     54        static PassRefPtr<WebSocketChannel> create(ScriptExecutionContext* context, WebSocketChannelClient* client) { return adoptRef(new WebSocketChannel(context, client)); }
    5555        virtual ~WebSocketChannel();
    5656
    5757        virtual bool useHixie76Protocol();
    58         virtual void connect();
     58        virtual void connect(const KURL&, const String& protocol);
    5959        virtual bool send(const String& message);
    6060        virtual unsigned long bufferedAmount() const;
     
    8282
    8383    private:
    84         WebSocketChannel(ScriptExecutionContext*, WebSocketChannelClient*, const KURL&, const String& protocol);
     84        WebSocketChannel(ScriptExecutionContext*, WebSocketChannelClient*);
    8585
    8686        bool appendToBuffer(const char* data, size_t len);
  • trunk/Source/WebCore/websockets/WorkerThreadableWebSocketChannel.cpp

    r92068 r92116  
    5050namespace WebCore {
    5151
    52 WorkerThreadableWebSocketChannel::WorkerThreadableWebSocketChannel(WorkerContext* context, WebSocketChannelClient* client, const String& taskMode, const KURL& url, const String& protocol)
     52WorkerThreadableWebSocketChannel::WorkerThreadableWebSocketChannel(WorkerContext* context, WebSocketChannelClient* client, const String& taskMode)
    5353    : m_workerContext(context)
    5454    , m_workerClientWrapper(ThreadableWebSocketChannelClientWrapper::create(client))
    55     , m_bridge(Bridge::create(m_workerClientWrapper, m_workerContext, taskMode, url, protocol))
     55    , m_bridge(Bridge::create(m_workerClientWrapper, m_workerContext, taskMode))
    5656{
    5757}
     
    6969}
    7070
    71 void WorkerThreadableWebSocketChannel::connect()
    72 {
    73     if (m_bridge)
    74         m_bridge->connect();
     71void WorkerThreadableWebSocketChannel::connect(const KURL& url, const String& protocol)
     72{
     73    if (m_bridge)
     74        m_bridge->connect(url, protocol);
    7575}
    7676
     
    121121}
    122122
    123 WorkerThreadableWebSocketChannel::Peer::Peer(PassRefPtr<ThreadableWebSocketChannelClientWrapper> clientWrapper, WorkerLoaderProxy& loaderProxy, ScriptExecutionContext* context, const String& taskMode, const KURL& url, const String& protocol)
     123WorkerThreadableWebSocketChannel::Peer::Peer(PassRefPtr<ThreadableWebSocketChannelClientWrapper> clientWrapper, WorkerLoaderProxy& loaderProxy, ScriptExecutionContext* context, const String& taskMode)
    124124    : m_workerClientWrapper(clientWrapper)
    125125    , m_loaderProxy(loaderProxy)
    126     , m_mainWebSocketChannel(WebSocketChannel::create(context, this, url, protocol))
     126    , m_mainWebSocketChannel(WebSocketChannel::create(context, this))
    127127    , m_taskMode(taskMode)
    128128{
     
    144144}
    145145
    146 void WorkerThreadableWebSocketChannel::Peer::connect()
    147 {
    148     ASSERT(isMainThread());
    149     if (!m_mainWebSocketChannel)
    150         return;
    151     m_mainWebSocketChannel->connect();
     146void WorkerThreadableWebSocketChannel::Peer::connect(const KURL& url, const String& protocol)
     147{
     148    ASSERT(isMainThread());
     149    if (!m_mainWebSocketChannel)
     150        return;
     151    m_mainWebSocketChannel->connect(url, protocol);
    152152}
    153153
     
    280280}
    281281
    282 void WorkerThreadableWebSocketChannel::Bridge::mainThreadCreateWebSocketChannel(ScriptExecutionContext* context, Bridge* thisPtr, PassRefPtr<ThreadableWebSocketChannelClientWrapper> prpClientWrapper, const String& taskMode, const KURL& url, const String& protocol)
     282void WorkerThreadableWebSocketChannel::Bridge::mainThreadCreateWebSocketChannel(ScriptExecutionContext* context, Bridge* thisPtr, PassRefPtr<ThreadableWebSocketChannelClientWrapper> prpClientWrapper, const String& taskMode)
    283283{
    284284    ASSERT(isMainThread());
     
    287287    RefPtr<ThreadableWebSocketChannelClientWrapper> clientWrapper = prpClientWrapper;
    288288
    289     Peer* peer = Peer::create(clientWrapper, thisPtr->m_loaderProxy, context, taskMode, url, protocol);
     289    Peer* peer = Peer::create(clientWrapper, thisPtr->m_loaderProxy, context, taskMode);
    290290    thisPtr->m_loaderProxy.postTaskForModeToWorkerContext(
    291291        createCallbackTask(&Bridge::setWebSocketChannel,
     
    294294}
    295295
    296 WorkerThreadableWebSocketChannel::Bridge::Bridge(PassRefPtr<ThreadableWebSocketChannelClientWrapper> workerClientWrapper, PassRefPtr<WorkerContext> workerContext, const String& taskMode, const KURL& url, const String& protocol)
     296WorkerThreadableWebSocketChannel::Bridge::Bridge(PassRefPtr<ThreadableWebSocketChannelClientWrapper> workerClientWrapper, PassRefPtr<WorkerContext> workerContext, const String& taskMode)
    297297    : m_workerClientWrapper(workerClientWrapper)
    298298    , m_workerContext(workerContext)
     
    305305    m_loaderProxy.postTaskToLoader(
    306306        createCallbackTask(&Bridge::mainThreadCreateWebSocketChannel,
    307                            AllowCrossThreadAccess(this), m_workerClientWrapper, m_taskMode, url, protocol));
     307                           AllowCrossThreadAccess(this), m_workerClientWrapper, m_taskMode));
    308308    waitForMethodCompletion();
    309309    ASSERT(m_peer);
     
    315315}
    316316
    317 void WorkerThreadableWebSocketChannel::mainThreadConnect(ScriptExecutionContext* context, Peer* peer)
    318 {
    319     ASSERT(isMainThread());
    320     ASSERT_UNUSED(context, context->isDocument());
    321     ASSERT(peer);
    322 
    323     peer->connect();
    324 }
    325 
    326 void WorkerThreadableWebSocketChannel::Bridge::connect()
     317void WorkerThreadableWebSocketChannel::mainThreadConnect(ScriptExecutionContext* context, Peer* peer, const KURL& url, const String& protocol)
     318{
     319    ASSERT(isMainThread());
     320    ASSERT_UNUSED(context, context->isDocument());
     321    ASSERT(peer);
     322
     323    peer->connect(url, protocol);
     324}
     325
     326void WorkerThreadableWebSocketChannel::Bridge::connect(const KURL& url, const String& protocol)
    327327{
    328328    ASSERT(m_workerClientWrapper);
    329329    ASSERT(m_peer);
    330     m_loaderProxy.postTaskToLoader(createCallbackTask(&WorkerThreadableWebSocketChannel::mainThreadConnect, AllowCrossThreadAccess(m_peer)));
     330    m_loaderProxy.postTaskToLoader(createCallbackTask(&WorkerThreadableWebSocketChannel::mainThreadConnect, AllowCrossThreadAccess(m_peer), url, protocol));
    331331}
    332332
  • trunk/Source/WebCore/websockets/WorkerThreadableWebSocketChannel.h

    r91919 r92116  
    5555    WTF_MAKE_FAST_ALLOCATED;
    5656public:
    57     static PassRefPtr<ThreadableWebSocketChannel> create(WorkerContext* workerContext, WebSocketChannelClient* client, const String& taskMode, const KURL& url, const String& protocol)
     57    static PassRefPtr<ThreadableWebSocketChannel> create(WorkerContext* workerContext, WebSocketChannelClient* client, const String& taskMode)
    5858    {
    59         return adoptRef(new WorkerThreadableWebSocketChannel(workerContext, client, taskMode, url, protocol));
     59        return adoptRef(new WorkerThreadableWebSocketChannel(workerContext, client, taskMode));
    6060    }
    6161    virtual ~WorkerThreadableWebSocketChannel();
    6262
    6363    virtual bool useHixie76Protocol();
    64     virtual void connect();
     64    virtual void connect(const KURL&, const String& protocol);
    6565    virtual bool send(const String& message);
    6666    virtual unsigned long bufferedAmount() const;
     
    8484        WTF_MAKE_NONCOPYABLE(Peer); WTF_MAKE_FAST_ALLOCATED;
    8585    public:
    86         static Peer* create(PassRefPtr<ThreadableWebSocketChannelClientWrapper> clientWrapper, WorkerLoaderProxy& loaderProxy, ScriptExecutionContext* context, const String& taskMode, const KURL& url, const String& protocol)
     86        static Peer* create(PassRefPtr<ThreadableWebSocketChannelClientWrapper> clientWrapper, WorkerLoaderProxy& loaderProxy, ScriptExecutionContext* context, const String& taskMode)
    8787        {
    88             return new Peer(clientWrapper, loaderProxy, context, taskMode, url, protocol);
     88            return new Peer(clientWrapper, loaderProxy, context, taskMode);
    8989        }
    9090        ~Peer();
    9191
    9292        bool useHixie76Protocol();
    93         void connect();
     93        void connect(const KURL&, const String& protocol);
    9494        void send(const String& message);
    9595        void bufferedAmount();
     
    106106
    107107    private:
    108         Peer(PassRefPtr<ThreadableWebSocketChannelClientWrapper>, WorkerLoaderProxy&, ScriptExecutionContext*, const String& taskMode, const KURL&, const String& protocol);
     108        Peer(PassRefPtr<ThreadableWebSocketChannelClientWrapper>, WorkerLoaderProxy&, ScriptExecutionContext*, const String& taskMode);
    109109
    110110        RefPtr<ThreadableWebSocketChannelClientWrapper> m_workerClientWrapper;
     
    117117    class Bridge : public RefCounted<Bridge> {
    118118    public:
    119         static PassRefPtr<Bridge> create(PassRefPtr<ThreadableWebSocketChannelClientWrapper> workerClientWrapper, PassRefPtr<WorkerContext> workerContext, const String& taskMode, const KURL& url, const String& protocol)
     119        static PassRefPtr<Bridge> create(PassRefPtr<ThreadableWebSocketChannelClientWrapper> workerClientWrapper, PassRefPtr<WorkerContext> workerContext, const String& taskMode)
    120120        {
    121             return adoptRef(new Bridge(workerClientWrapper, workerContext, taskMode, url, protocol));
     121            return adoptRef(new Bridge(workerClientWrapper, workerContext, taskMode));
    122122        }
    123123        ~Bridge();
    124         void connect();
     124        void connect(const KURL&, const String& protocol);
    125125        bool send(const String& message);
    126126        unsigned long bufferedAmount();
     
    135135
    136136    private:
    137         Bridge(PassRefPtr<ThreadableWebSocketChannelClientWrapper>, PassRefPtr<WorkerContext>, const String& taskMode, const KURL&, const String& protocol);
     137        Bridge(PassRefPtr<ThreadableWebSocketChannelClientWrapper>, PassRefPtr<WorkerContext>, const String& taskMode);
    138138
    139139        static void setWebSocketChannel(ScriptExecutionContext*, Bridge* thisPtr, Peer*, PassRefPtr<ThreadableWebSocketChannelClientWrapper>, bool useHixie76Protocol);
    140140
    141141        // Executed on the main thread to create a Peer for this bridge.
    142         static void mainThreadCreateWebSocketChannel(ScriptExecutionContext*, Bridge* thisPtr, PassRefPtr<ThreadableWebSocketChannelClientWrapper>, const String& taskMode, const KURL&, const String& protocol);
     142        static void mainThreadCreateWebSocketChannel(ScriptExecutionContext*, Bridge* thisPtr, PassRefPtr<ThreadableWebSocketChannelClientWrapper>, const String& taskMode);
    143143
    144144        // Executed on the worker context's thread.
     
    155155    };
    156156
    157     WorkerThreadableWebSocketChannel(WorkerContext*, WebSocketChannelClient*, const String& taskMode, const KURL&, const String& protocol);
     157    WorkerThreadableWebSocketChannel(WorkerContext*, WebSocketChannelClient*, const String& taskMode);
    158158
    159     static void mainThreadConnect(ScriptExecutionContext*, Peer*);
     159    static void mainThreadConnect(ScriptExecutionContext*, Peer*, const KURL&, const String& protocol);
    160160    static void mainThreadSend(ScriptExecutionContext*, Peer*, const String& message);
    161161    static void mainThreadBufferedAmount(ScriptExecutionContext*, Peer*);
Note: See TracChangeset for help on using the changeset viewer.