Changeset 92116 in webkit
- Timestamp:
- Aug 1, 2011 4:16:13 AM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r92106 r92116 1 2011-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 1 50 2011-08-01 Luke Macpherson <macpherson@chromium.org> 2 51 -
trunk/Source/WebCore/websockets/ThreadableWebSocketChannel.cpp
r52892 r92116 51 51 static const char webSocketChannelMode[] = "webSocketChannelMode"; 52 52 53 PassRefPtr<ThreadableWebSocketChannel> ThreadableWebSocketChannel::create(ScriptExecutionContext* context, WebSocketChannelClient* client , const KURL& url, const String& protocol)53 PassRefPtr<ThreadableWebSocketChannel> ThreadableWebSocketChannel::create(ScriptExecutionContext* context, WebSocketChannelClient* client) 54 54 { 55 55 ASSERT(context); … … 62 62 String mode = webSocketChannelMode; 63 63 mode.append(String::number(runLoop.createUniqueId())); 64 return WorkerThreadableWebSocketChannel::create(workerContext, client, mode , url, protocol);64 return WorkerThreadableWebSocketChannel::create(workerContext, client, mode); 65 65 } 66 66 #endif // ENABLE(WORKERS) 67 67 68 68 ASSERT(context->isDocument()); 69 return WebSocketChannel::create(context, client , url, protocol);69 return WebSocketChannel::create(context, client); 70 70 } 71 71 -
trunk/Source/WebCore/websockets/ThreadableWebSocketChannel.h
r91919 r92116 48 48 public: 49 49 ThreadableWebSocketChannel() { } 50 static PassRefPtr<ThreadableWebSocketChannel> create(ScriptExecutionContext*, WebSocketChannelClient* , const KURL&, const String& protocol);50 static PassRefPtr<ThreadableWebSocketChannel> create(ScriptExecutionContext*, WebSocketChannelClient*); 51 51 52 52 virtual bool useHixie76Protocol() = 0; 53 virtual void connect( ) = 0;53 virtual void connect(const KURL&, const String& protocol) = 0; 54 54 virtual bool send(const String& message) = 0; 55 55 virtual unsigned long bufferedAmount() const = 0; -
trunk/Source/WebCore/websockets/WebSocket.cpp
r87674 r92116 152 152 } 153 153 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); 156 158 ActiveDOMObject::setPendingActivity(this); 157 159 } -
trunk/Source/WebCore/websockets/WebSocketChannel.cpp
r92102 r92116 83 83 const WebSocketChannel::OpCode WebSocketChannel::OpCodePong = 0xA; 84 84 85 WebSocketChannel::WebSocketChannel(ScriptExecutionContext* context, WebSocketChannelClient* client , const KURL& url, const String& protocol)85 WebSocketChannel::WebSocketChannel(ScriptExecutionContext* context, WebSocketChannelClient* client) 86 86 : m_context(context) 87 87 , m_client(client) … … 104 104 if (Settings* settings = document->settings()) 105 105 m_useHixie76Protocol = settings->useHixie76WebSocketProtocol(); 106 m_handshake = adoptPtr(new WebSocketHandshake(url, protocol, context, m_useHixie76Protocol));107 106 108 107 if (Page* page = document->page()) 109 108 m_identifier = page->progress()->createUniqueIdentifier(); 110 if (m_identifier)111 InspectorInstrumentation::didCreateWebSocket(m_context, m_identifier, url, m_context->url());112 109 } 113 110 … … 122 119 } 123 120 124 void WebSocketChannel::connect( )121 void WebSocketChannel::connect(const KURL& url, const String& protocol) 125 122 { 126 123 LOG(Network, "WebSocketChannel %p connect", this); 127 124 ASSERT(!m_handle); 128 125 ASSERT(!m_suspended); 126 m_handshake = adoptPtr(new WebSocketHandshake(url, protocol, m_context, m_useHixie76Protocol)); 129 127 m_handshake->reset(); 128 if (m_identifier) 129 InspectorInstrumentation::didCreateWebSocket(m_context, m_identifier, url, m_context->url()); 130 130 ref(); 131 131 m_handle = SocketStreamHandle::create(m_handshake->url(), this); -
trunk/Source/WebCore/websockets/WebSocketChannel.h
r92102 r92116 52 52 WTF_MAKE_FAST_ALLOCATED; 53 53 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)); } 55 55 virtual ~WebSocketChannel(); 56 56 57 57 virtual bool useHixie76Protocol(); 58 virtual void connect( );58 virtual void connect(const KURL&, const String& protocol); 59 59 virtual bool send(const String& message); 60 60 virtual unsigned long bufferedAmount() const; … … 82 82 83 83 private: 84 WebSocketChannel(ScriptExecutionContext*, WebSocketChannelClient* , const KURL&, const String& protocol);84 WebSocketChannel(ScriptExecutionContext*, WebSocketChannelClient*); 85 85 86 86 bool appendToBuffer(const char* data, size_t len); -
trunk/Source/WebCore/websockets/WorkerThreadableWebSocketChannel.cpp
r92068 r92116 50 50 namespace WebCore { 51 51 52 WorkerThreadableWebSocketChannel::WorkerThreadableWebSocketChannel(WorkerContext* context, WebSocketChannelClient* client, const String& taskMode , const KURL& url, const String& protocol)52 WorkerThreadableWebSocketChannel::WorkerThreadableWebSocketChannel(WorkerContext* context, WebSocketChannelClient* client, const String& taskMode) 53 53 : m_workerContext(context) 54 54 , 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)) 56 56 { 57 57 } … … 69 69 } 70 70 71 void WorkerThreadableWebSocketChannel::connect( )72 { 73 if (m_bridge) 74 m_bridge->connect( );71 void WorkerThreadableWebSocketChannel::connect(const KURL& url, const String& protocol) 72 { 73 if (m_bridge) 74 m_bridge->connect(url, protocol); 75 75 } 76 76 … … 121 121 } 122 122 123 WorkerThreadableWebSocketChannel::Peer::Peer(PassRefPtr<ThreadableWebSocketChannelClientWrapper> clientWrapper, WorkerLoaderProxy& loaderProxy, ScriptExecutionContext* context, const String& taskMode , const KURL& url, const String& protocol)123 WorkerThreadableWebSocketChannel::Peer::Peer(PassRefPtr<ThreadableWebSocketChannelClientWrapper> clientWrapper, WorkerLoaderProxy& loaderProxy, ScriptExecutionContext* context, const String& taskMode) 124 124 : m_workerClientWrapper(clientWrapper) 125 125 , m_loaderProxy(loaderProxy) 126 , m_mainWebSocketChannel(WebSocketChannel::create(context, this , url, protocol))126 , m_mainWebSocketChannel(WebSocketChannel::create(context, this)) 127 127 , m_taskMode(taskMode) 128 128 { … … 144 144 } 145 145 146 void WorkerThreadableWebSocketChannel::Peer::connect( )147 { 148 ASSERT(isMainThread()); 149 if (!m_mainWebSocketChannel) 150 return; 151 m_mainWebSocketChannel->connect( );146 void 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); 152 152 } 153 153 … … 280 280 } 281 281 282 void WorkerThreadableWebSocketChannel::Bridge::mainThreadCreateWebSocketChannel(ScriptExecutionContext* context, Bridge* thisPtr, PassRefPtr<ThreadableWebSocketChannelClientWrapper> prpClientWrapper, const String& taskMode , const KURL& url, const String& protocol)282 void WorkerThreadableWebSocketChannel::Bridge::mainThreadCreateWebSocketChannel(ScriptExecutionContext* context, Bridge* thisPtr, PassRefPtr<ThreadableWebSocketChannelClientWrapper> prpClientWrapper, const String& taskMode) 283 283 { 284 284 ASSERT(isMainThread()); … … 287 287 RefPtr<ThreadableWebSocketChannelClientWrapper> clientWrapper = prpClientWrapper; 288 288 289 Peer* peer = Peer::create(clientWrapper, thisPtr->m_loaderProxy, context, taskMode , url, protocol);289 Peer* peer = Peer::create(clientWrapper, thisPtr->m_loaderProxy, context, taskMode); 290 290 thisPtr->m_loaderProxy.postTaskForModeToWorkerContext( 291 291 createCallbackTask(&Bridge::setWebSocketChannel, … … 294 294 } 295 295 296 WorkerThreadableWebSocketChannel::Bridge::Bridge(PassRefPtr<ThreadableWebSocketChannelClientWrapper> workerClientWrapper, PassRefPtr<WorkerContext> workerContext, const String& taskMode , const KURL& url, const String& protocol)296 WorkerThreadableWebSocketChannel::Bridge::Bridge(PassRefPtr<ThreadableWebSocketChannelClientWrapper> workerClientWrapper, PassRefPtr<WorkerContext> workerContext, const String& taskMode) 297 297 : m_workerClientWrapper(workerClientWrapper) 298 298 , m_workerContext(workerContext) … … 305 305 m_loaderProxy.postTaskToLoader( 306 306 createCallbackTask(&Bridge::mainThreadCreateWebSocketChannel, 307 AllowCrossThreadAccess(this), m_workerClientWrapper, m_taskMode , url, protocol));307 AllowCrossThreadAccess(this), m_workerClientWrapper, m_taskMode)); 308 308 waitForMethodCompletion(); 309 309 ASSERT(m_peer); … … 315 315 } 316 316 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( )317 void 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 326 void WorkerThreadableWebSocketChannel::Bridge::connect(const KURL& url, const String& protocol) 327 327 { 328 328 ASSERT(m_workerClientWrapper); 329 329 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)); 331 331 } 332 332 -
trunk/Source/WebCore/websockets/WorkerThreadableWebSocketChannel.h
r91919 r92116 55 55 WTF_MAKE_FAST_ALLOCATED; 56 56 public: 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) 58 58 { 59 return adoptRef(new WorkerThreadableWebSocketChannel(workerContext, client, taskMode , url, protocol));59 return adoptRef(new WorkerThreadableWebSocketChannel(workerContext, client, taskMode)); 60 60 } 61 61 virtual ~WorkerThreadableWebSocketChannel(); 62 62 63 63 virtual bool useHixie76Protocol(); 64 virtual void connect( );64 virtual void connect(const KURL&, const String& protocol); 65 65 virtual bool send(const String& message); 66 66 virtual unsigned long bufferedAmount() const; … … 84 84 WTF_MAKE_NONCOPYABLE(Peer); WTF_MAKE_FAST_ALLOCATED; 85 85 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) 87 87 { 88 return new Peer(clientWrapper, loaderProxy, context, taskMode , url, protocol);88 return new Peer(clientWrapper, loaderProxy, context, taskMode); 89 89 } 90 90 ~Peer(); 91 91 92 92 bool useHixie76Protocol(); 93 void connect( );93 void connect(const KURL&, const String& protocol); 94 94 void send(const String& message); 95 95 void bufferedAmount(); … … 106 106 107 107 private: 108 Peer(PassRefPtr<ThreadableWebSocketChannelClientWrapper>, WorkerLoaderProxy&, ScriptExecutionContext*, const String& taskMode , const KURL&, const String& protocol);108 Peer(PassRefPtr<ThreadableWebSocketChannelClientWrapper>, WorkerLoaderProxy&, ScriptExecutionContext*, const String& taskMode); 109 109 110 110 RefPtr<ThreadableWebSocketChannelClientWrapper> m_workerClientWrapper; … … 117 117 class Bridge : public RefCounted<Bridge> { 118 118 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) 120 120 { 121 return adoptRef(new Bridge(workerClientWrapper, workerContext, taskMode , url, protocol));121 return adoptRef(new Bridge(workerClientWrapper, workerContext, taskMode)); 122 122 } 123 123 ~Bridge(); 124 void connect( );124 void connect(const KURL&, const String& protocol); 125 125 bool send(const String& message); 126 126 unsigned long bufferedAmount(); … … 135 135 136 136 private: 137 Bridge(PassRefPtr<ThreadableWebSocketChannelClientWrapper>, PassRefPtr<WorkerContext>, const String& taskMode , const KURL&, const String& protocol);137 Bridge(PassRefPtr<ThreadableWebSocketChannelClientWrapper>, PassRefPtr<WorkerContext>, const String& taskMode); 138 138 139 139 static void setWebSocketChannel(ScriptExecutionContext*, Bridge* thisPtr, Peer*, PassRefPtr<ThreadableWebSocketChannelClientWrapper>, bool useHixie76Protocol); 140 140 141 141 // 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); 143 143 144 144 // Executed on the worker context's thread. … … 155 155 }; 156 156 157 WorkerThreadableWebSocketChannel(WorkerContext*, WebSocketChannelClient*, const String& taskMode , const KURL&, const String& protocol);157 WorkerThreadableWebSocketChannel(WorkerContext*, WebSocketChannelClient*, const String& taskMode); 158 158 159 static void mainThreadConnect(ScriptExecutionContext*, Peer* );159 static void mainThreadConnect(ScriptExecutionContext*, Peer*, const KURL&, const String& protocol); 160 160 static void mainThreadSend(ScriptExecutionContext*, Peer*, const String& message); 161 161 static void mainThreadBufferedAmount(ScriptExecutionContext*, Peer*);
Note: See TracChangeset
for help on using the changeset viewer.