Commit 9ac0ede4 authored by yhirano@chromium.org's avatar yhirano@chromium.org

[WebSocket] Make subprotocol and extensions live in WebSocket

Currently WebSocketChannel has methods subprotocol and extensions.
But they can be available only after the connection is established and
they don't change once set. Futhermore, there is didConnect notification
in WebSocketChannelClient.
This CL removes subprotocol and extensions from WebSocketChannel and
add them as WebSocketChannelClient::didConnect parameters.

BUG=384238
R=tyoshino

Review URL: https://codereview.chromium.org/334873002

git-svn-id: svn://svn.chromium.org/blink/trunk@176115 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 0b144341
...@@ -124,28 +124,6 @@ bool MainThreadWebSocketChannel::connect(const KURL& url, const String& protocol ...@@ -124,28 +124,6 @@ bool MainThreadWebSocketChannel::connect(const KURL& url, const String& protocol
return true; return true;
} }
String MainThreadWebSocketChannel::subprotocol()
{
WTF_LOG(Network, "MainThreadWebSocketChannel %p subprotocol()", this);
if (!m_handshake || m_handshake->mode() != WebSocketHandshake::Connected)
return "";
String serverProtocol = m_handshake->serverWebSocketProtocol();
if (serverProtocol.isNull())
return "";
return serverProtocol;
}
String MainThreadWebSocketChannel::extensions()
{
WTF_LOG(Network, "MainThreadWebSocketChannel %p extensions()", this);
if (!m_handshake || m_handshake->mode() != WebSocketHandshake::Connected)
return "";
String extensions = m_handshake->acceptedExtensions();
if (extensions.isNull())
return "";
return extensions;
}
WebSocketChannel::SendResult MainThreadWebSocketChannel::send(const String& message) WebSocketChannel::SendResult MainThreadWebSocketChannel::send(const String& message)
{ {
WTF_LOG(Network, "MainThreadWebSocketChannel %p send() Sending String '%s'", this, message.utf8().data()); WTF_LOG(Network, "MainThreadWebSocketChannel %p send() Sending String '%s'", this, message.utf8().data());
...@@ -484,7 +462,9 @@ bool MainThreadWebSocketChannel::processOneItemFromBuffer() ...@@ -484,7 +462,9 @@ bool MainThreadWebSocketChannel::processOneItemFromBuffer()
WTF_LOG(Network, "MainThreadWebSocketChannel %p Connected", this); WTF_LOG(Network, "MainThreadWebSocketChannel %p Connected", this);
skipBuffer(headerLength); skipBuffer(headerLength);
m_client->didConnect(); String subprotocol = m_handshake->serverWebSocketProtocol();
String extensions = m_handshake->acceptedExtensions();
m_client->didConnect(subprotocol.isNull() ? "" : subprotocol, extensions.isNull() ? "" : extensions);
WTF_LOG(Network, "MainThreadWebSocketChannel %p %lu bytes remaining in m_buffer", this, static_cast<unsigned long>(m_buffer.size())); WTF_LOG(Network, "MainThreadWebSocketChannel %p %lu bytes remaining in m_buffer", this, static_cast<unsigned long>(m_buffer.size()));
return !m_buffer.isEmpty(); return !m_buffer.isEmpty();
} }
......
...@@ -71,8 +71,6 @@ public: ...@@ -71,8 +71,6 @@ public:
// WebSocketChannel functions. // WebSocketChannel functions.
virtual bool connect(const KURL&, const String& protocol) OVERRIDE; virtual bool connect(const KURL&, const String& protocol) OVERRIDE;
virtual String subprotocol() OVERRIDE;
virtual String extensions() OVERRIDE;
virtual WebSocketChannel::SendResult send(const String& message) OVERRIDE; virtual WebSocketChannel::SendResult send(const String& message) OVERRIDE;
virtual WebSocketChannel::SendResult send(const ArrayBuffer&, unsigned byteOffset, unsigned byteLength) OVERRIDE; virtual WebSocketChannel::SendResult send(const ArrayBuffer&, unsigned byteOffset, unsigned byteLength) OVERRIDE;
virtual WebSocketChannel::SendResult send(PassRefPtr<BlobDataHandle>) OVERRIDE; virtual WebSocketChannel::SendResult send(PassRefPtr<BlobDataHandle>) OVERRIDE;
......
...@@ -170,18 +170,6 @@ bool NewWebSocketChannelImpl::connect(const KURL& url, const String& protocol) ...@@ -170,18 +170,6 @@ bool NewWebSocketChannelImpl::connect(const KURL& url, const String& protocol)
return true; return true;
} }
String NewWebSocketChannelImpl::subprotocol()
{
WTF_LOG(Network, "NewWebSocketChannelImpl %p subprotocol()", this);
return m_subprotocol;
}
String NewWebSocketChannelImpl::extensions()
{
WTF_LOG(Network, "NewWebSocketChannelImpl %p extensions()", this);
return m_extensions;
}
WebSocketChannel::SendResult NewWebSocketChannelImpl::send(const String& message) WebSocketChannel::SendResult NewWebSocketChannelImpl::send(const String& message)
{ {
WTF_LOG(Network, "NewWebSocketChannelImpl %p sendText(%s)", this, message.utf8().data()); WTF_LOG(Network, "NewWebSocketChannelImpl %p sendText(%s)", this, message.utf8().data());
...@@ -418,9 +406,7 @@ void NewWebSocketChannelImpl::didConnect(WebSocketHandle* handle, bool fail, con ...@@ -418,9 +406,7 @@ void NewWebSocketChannelImpl::didConnect(WebSocketHandle* handle, bool fail, con
// failAsError may delete this object. // failAsError may delete this object.
return; return;
} }
m_subprotocol = selectedProtocol; m_client->didConnect(selectedProtocol, extensions);
m_extensions = extensions;
m_client->didConnect();
} }
void NewWebSocketChannelImpl::didStartOpeningHandshake(WebSocketHandle* handle, const blink::WebSocketHandshakeRequestInfo& request) void NewWebSocketChannelImpl::didStartOpeningHandshake(WebSocketHandle* handle, const blink::WebSocketHandshakeRequestInfo& request)
......
...@@ -78,8 +78,6 @@ public: ...@@ -78,8 +78,6 @@ public:
// WebSocketChannel functions. // WebSocketChannel functions.
virtual bool connect(const KURL&, const String& protocol) OVERRIDE; virtual bool connect(const KURL&, const String& protocol) OVERRIDE;
virtual String subprotocol() OVERRIDE;
virtual String extensions() OVERRIDE;
virtual WebSocketChannel::SendResult send(const String& message) OVERRIDE; virtual WebSocketChannel::SendResult send(const String& message) OVERRIDE;
virtual WebSocketChannel::SendResult send(const ArrayBuffer&, unsigned byteOffset, unsigned byteLength) OVERRIDE; virtual WebSocketChannel::SendResult send(const ArrayBuffer&, unsigned byteOffset, unsigned byteLength) OVERRIDE;
virtual WebSocketChannel::SendResult send(PassRefPtr<BlobDataHandle>) OVERRIDE; virtual WebSocketChannel::SendResult send(PassRefPtr<BlobDataHandle>) OVERRIDE;
...@@ -170,8 +168,6 @@ private: ...@@ -170,8 +168,6 @@ private:
int64_t m_receivedDataSizeForFlowControl; int64_t m_receivedDataSizeForFlowControl;
unsigned long m_bufferedAmount; unsigned long m_bufferedAmount;
size_t m_sentSizeOfTopMessage; size_t m_sentSizeOfTopMessage;
String m_subprotocol;
String m_extensions;
String m_sourceURLAtConstruction; String m_sourceURLAtConstruction;
unsigned m_lineNumberAtConstruction; unsigned m_lineNumberAtConstruction;
......
...@@ -54,40 +54,14 @@ PassRefPtrWillBeRawPtr<ThreadableWebSocketChannelClientWrapper> ThreadableWebSoc ...@@ -54,40 +54,14 @@ PassRefPtrWillBeRawPtr<ThreadableWebSocketChannelClientWrapper> ThreadableWebSoc
return adoptRefWillBeNoop(new ThreadableWebSocketChannelClientWrapper(client)); return adoptRefWillBeNoop(new ThreadableWebSocketChannelClientWrapper(client));
} }
String ThreadableWebSocketChannelClientWrapper::subprotocol() const
{
if (m_subprotocol.isEmpty())
return emptyString();
return String(m_subprotocol);
}
void ThreadableWebSocketChannelClientWrapper::setSubprotocol(const String& subprotocol)
{
m_subprotocol.clear();
append(m_subprotocol, subprotocol);
}
String ThreadableWebSocketChannelClientWrapper::extensions() const
{
if (m_extensions.isEmpty())
return emptyString();
return String(m_extensions);
}
void ThreadableWebSocketChannelClientWrapper::setExtensions(const String& extensions)
{
m_extensions.clear();
append(m_extensions, extensions);
}
void ThreadableWebSocketChannelClientWrapper::clearClient() void ThreadableWebSocketChannelClientWrapper::clearClient()
{ {
m_client = 0; m_client = 0;
} }
void ThreadableWebSocketChannelClientWrapper::didConnect() void ThreadableWebSocketChannelClientWrapper::didConnect(const String& subprotocol, const String& extensions)
{ {
m_pendingTasks.append(createCallbackTask(&didConnectCallback, this)); m_pendingTasks.append(createCallbackTask(&didConnectCallback, this, subprotocol, extensions));
if (!m_suspended) if (!m_suspended)
processPendingTasks(); processPendingTasks();
} }
...@@ -155,11 +129,11 @@ void ThreadableWebSocketChannelClientWrapper::processPendingTasks() ...@@ -155,11 +129,11 @@ void ThreadableWebSocketChannelClientWrapper::processPendingTasks()
(*iter)->performTask(0); (*iter)->performTask(0);
} }
void ThreadableWebSocketChannelClientWrapper::didConnectCallback(ExecutionContext* context, PassRefPtrWillBeRawPtr<ThreadableWebSocketChannelClientWrapper> wrapper) void ThreadableWebSocketChannelClientWrapper::didConnectCallback(ExecutionContext* context, PassRefPtrWillBeRawPtr<ThreadableWebSocketChannelClientWrapper> wrapper, const String& subprotocol, const String& extensions)
{ {
ASSERT_UNUSED(context, !context); ASSERT_UNUSED(context, !context);
if (wrapper->m_client) if (wrapper->m_client)
wrapper->m_client->didConnect(); wrapper->m_client->didConnect(subprotocol, extensions);
} }
void ThreadableWebSocketChannelClientWrapper::didReceiveMessageCallback(ExecutionContext* context, PassRefPtrWillBeRawPtr<ThreadableWebSocketChannelClientWrapper> wrapper, const String& message) void ThreadableWebSocketChannelClientWrapper::didReceiveMessageCallback(ExecutionContext* context, PassRefPtrWillBeRawPtr<ThreadableWebSocketChannelClientWrapper> wrapper, const String& message)
......
...@@ -50,15 +50,9 @@ public: ...@@ -50,15 +50,9 @@ public:
static PassRefPtrWillBeRawPtr<ThreadableWebSocketChannelClientWrapper> create(WebSocketChannelClient*); static PassRefPtrWillBeRawPtr<ThreadableWebSocketChannelClientWrapper> create(WebSocketChannelClient*);
~ThreadableWebSocketChannelClientWrapper(); ~ThreadableWebSocketChannelClientWrapper();
// Subprotocol and extensions will be available when didConnect() callback is invoked.
String subprotocol() const;
void setSubprotocol(const String&);
String extensions() const;
void setExtensions(const String&);
void clearClient(); void clearClient();
void didConnect(); void didConnect(const String& subprotocol, const String& extensions);
void didReceiveMessage(const String& message); void didReceiveMessage(const String& message);
void didReceiveBinaryData(PassOwnPtr<Vector<char> >); void didReceiveBinaryData(PassOwnPtr<Vector<char> >);
void didUpdateBufferedAmount(unsigned long bufferedAmount); void didUpdateBufferedAmount(unsigned long bufferedAmount);
...@@ -76,7 +70,7 @@ private: ...@@ -76,7 +70,7 @@ private:
void processPendingTasks(); void processPendingTasks();
static void didConnectCallback(ExecutionContext*, PassRefPtrWillBeRawPtr<ThreadableWebSocketChannelClientWrapper>); static void didConnectCallback(ExecutionContext*, PassRefPtrWillBeRawPtr<ThreadableWebSocketChannelClientWrapper>, const String& subprotocol, const String& extensions);
static void didReceiveMessageCallback(ExecutionContext*, PassRefPtrWillBeRawPtr<ThreadableWebSocketChannelClientWrapper>, const String& message); static void didReceiveMessageCallback(ExecutionContext*, PassRefPtrWillBeRawPtr<ThreadableWebSocketChannelClientWrapper>, const String& message);
static void didReceiveBinaryDataCallback(ExecutionContext*, PassRefPtrWillBeRawPtr<ThreadableWebSocketChannelClientWrapper>, PassOwnPtr<Vector<char> >); static void didReceiveBinaryDataCallback(ExecutionContext*, PassRefPtrWillBeRawPtr<ThreadableWebSocketChannelClientWrapper>, PassOwnPtr<Vector<char> >);
static void didUpdateBufferedAmountCallback(ExecutionContext*, PassRefPtrWillBeRawPtr<ThreadableWebSocketChannelClientWrapper>, unsigned long bufferedAmount); static void didUpdateBufferedAmountCallback(ExecutionContext*, PassRefPtrWillBeRawPtr<ThreadableWebSocketChannelClientWrapper>, unsigned long bufferedAmount);
...@@ -85,9 +79,6 @@ private: ...@@ -85,9 +79,6 @@ private:
static void didReceiveMessageErrorCallback(ExecutionContext*, PassRefPtrWillBeRawPtr<ThreadableWebSocketChannelClientWrapper>); static void didReceiveMessageErrorCallback(ExecutionContext*, PassRefPtrWillBeRawPtr<ThreadableWebSocketChannelClientWrapper>);
WebSocketChannelClient* m_client; WebSocketChannelClient* m_client;
// ThreadSafeRefCounted must not have String member variables.
Vector<UChar> m_subprotocol;
Vector<UChar> m_extensions;
bool m_suspended; bool m_suspended;
Vector<OwnPtr<ExecutionContextTask> > m_pendingTasks; Vector<OwnPtr<ExecutionContextTask> > m_pendingTasks;
}; };
......
...@@ -585,14 +585,14 @@ void WebSocket::stop() ...@@ -585,14 +585,14 @@ void WebSocket::stop()
m_state = CLOSED; m_state = CLOSED;
} }
void WebSocket::didConnect() void WebSocket::didConnect(const String& subprotocol, const String& extensions)
{ {
WTF_LOG(Network, "WebSocket %p didConnect()", this); WTF_LOG(Network, "WebSocket %p didConnect()", this);
if (m_state != CONNECTING) if (m_state != CONNECTING)
return; return;
m_state = OPEN; m_state = OPEN;
m_subprotocol = m_channel->subprotocol(); m_subprotocol = subprotocol;
m_extensions = m_channel->extensions(); m_extensions = extensions;
m_eventQueue->dispatch(Event::create(EventTypeNames::open)); m_eventQueue->dispatch(Event::create(EventTypeNames::open));
} }
......
...@@ -116,7 +116,7 @@ public: ...@@ -116,7 +116,7 @@ public:
virtual void stop() OVERRIDE; virtual void stop() OVERRIDE;
// WebSocketChannelClient functions. // WebSocketChannelClient functions.
virtual void didConnect() OVERRIDE; virtual void didConnect(const String& subprotocol, const String& extensions) OVERRIDE;
virtual void didReceiveMessage(const String& message) OVERRIDE; virtual void didReceiveMessage(const String& message) OVERRIDE;
virtual void didReceiveBinaryData(PassOwnPtr<Vector<char> >) OVERRIDE; virtual void didReceiveBinaryData(PassOwnPtr<Vector<char> >) OVERRIDE;
virtual void didReceiveMessageError() OVERRIDE; virtual void didReceiveMessageError() OVERRIDE;
......
...@@ -81,8 +81,6 @@ public: ...@@ -81,8 +81,6 @@ public:
}; };
virtual bool connect(const KURL&, const String& protocol) = 0; virtual bool connect(const KURL&, const String& protocol) = 0;
virtual String subprotocol() = 0; // Will be available after didConnect() callback is invoked.
virtual String extensions() = 0; // Will be available after didConnect() callback is invoked.
virtual SendResult send(const String& message) = 0; virtual SendResult send(const String& message) = 0;
virtual SendResult send(const ArrayBuffer&, unsigned byteOffset, unsigned byteLength) = 0; virtual SendResult send(const ArrayBuffer&, unsigned byteOffset, unsigned byteLength) = 0;
virtual SendResult send(PassRefPtr<BlobDataHandle>) = 0; virtual SendResult send(PassRefPtr<BlobDataHandle>) = 0;
......
...@@ -40,7 +40,7 @@ namespace WebCore { ...@@ -40,7 +40,7 @@ namespace WebCore {
class WebSocketChannelClient { class WebSocketChannelClient {
public: public:
virtual ~WebSocketChannelClient() { } virtual ~WebSocketChannelClient() { }
virtual void didConnect() { } virtual void didConnect(const String& subprotocol, const String& extensions) { }
virtual void didReceiveMessage(const String&) { } virtual void didReceiveMessage(const String&) { }
virtual void didReceiveBinaryData(PassOwnPtr<Vector<char> >) { } virtual void didReceiveBinaryData(PassOwnPtr<Vector<char> >) { }
virtual void didReceiveMessageError() { } virtual void didReceiveMessageError() { }
......
...@@ -46,8 +46,6 @@ public: ...@@ -46,8 +46,6 @@ public:
} }
MOCK_METHOD2(connect, bool(const KURL&, const String&)); MOCK_METHOD2(connect, bool(const KURL&, const String&));
MOCK_METHOD0(subprotocol, String());
MOCK_METHOD0(extensions, String());
MOCK_METHOD1(send, SendResult(const String&)); MOCK_METHOD1(send, SendResult(const String&));
MOCK_METHOD3(send, SendResult(const ArrayBuffer&, unsigned, unsigned)); MOCK_METHOD3(send, SendResult(const ArrayBuffer&, unsigned, unsigned));
MOCK_METHOD1(send, SendResult(PassRefPtr<BlobDataHandle>)); MOCK_METHOD1(send, SendResult(PassRefPtr<BlobDataHandle>));
...@@ -271,15 +269,13 @@ TEST_F(WebSocketTest, connectSuccess) ...@@ -271,15 +269,13 @@ TEST_F(WebSocketTest, connectSuccess)
{ {
InSequence s; InSequence s;
EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String("aa, bb"))).WillOnce(Return(true)); EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String("aa, bb"))).WillOnce(Return(true));
EXPECT_CALL(channel(), subprotocol()).WillOnce(Return(String("bb")));
EXPECT_CALL(channel(), extensions()).WillOnce(Return(String("cc")));
} }
m_websocket->connect("ws://example.com/", subprotocols, m_exceptionState); m_websocket->connect("ws://example.com/", subprotocols, m_exceptionState);
EXPECT_FALSE(m_exceptionState.hadException()); EXPECT_FALSE(m_exceptionState.hadException());
EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState());
m_websocket->didConnect(); m_websocket->didConnect("bb", "cc");
EXPECT_EQ(WebSocket::OPEN, m_websocket->readyState()); EXPECT_EQ(WebSocket::OPEN, m_websocket->readyState());
EXPECT_EQ("bb", m_websocket->protocol()); EXPECT_EQ("bb", m_websocket->protocol());
...@@ -369,8 +365,6 @@ TEST_F(WebSocketTest, close) ...@@ -369,8 +365,6 @@ TEST_F(WebSocketTest, close)
{ {
InSequence s; InSequence s;
EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String())).WillOnce(Return(true)); EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String())).WillOnce(Return(true));
EXPECT_CALL(channel(), subprotocol()).WillOnce(Return(String()));
EXPECT_CALL(channel(), extensions()).WillOnce(Return(String()));
EXPECT_CALL(channel(), close(3005, String("bye"))); EXPECT_CALL(channel(), close(3005, String("bye")));
} }
m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState); m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState);
...@@ -378,7 +372,7 @@ TEST_F(WebSocketTest, close) ...@@ -378,7 +372,7 @@ TEST_F(WebSocketTest, close)
EXPECT_FALSE(m_exceptionState.hadException()); EXPECT_FALSE(m_exceptionState.hadException());
EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState());
m_websocket->didConnect(); m_websocket->didConnect("", "");
EXPECT_EQ(WebSocket::OPEN, m_websocket->readyState()); EXPECT_EQ(WebSocket::OPEN, m_websocket->readyState());
m_websocket->close(3005, "bye", m_exceptionState); m_websocket->close(3005, "bye", m_exceptionState);
...@@ -391,8 +385,6 @@ TEST_F(WebSocketTest, closeWithoutReason) ...@@ -391,8 +385,6 @@ TEST_F(WebSocketTest, closeWithoutReason)
{ {
InSequence s; InSequence s;
EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String())).WillOnce(Return(true)); EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String())).WillOnce(Return(true));
EXPECT_CALL(channel(), subprotocol()).WillOnce(Return(String()));
EXPECT_CALL(channel(), extensions()).WillOnce(Return(String()));
EXPECT_CALL(channel(), close(3005, String())); EXPECT_CALL(channel(), close(3005, String()));
} }
m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState); m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState);
...@@ -400,7 +392,7 @@ TEST_F(WebSocketTest, closeWithoutReason) ...@@ -400,7 +392,7 @@ TEST_F(WebSocketTest, closeWithoutReason)
EXPECT_FALSE(m_exceptionState.hadException()); EXPECT_FALSE(m_exceptionState.hadException());
EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState());
m_websocket->didConnect(); m_websocket->didConnect("", "");
EXPECT_EQ(WebSocket::OPEN, m_websocket->readyState()); EXPECT_EQ(WebSocket::OPEN, m_websocket->readyState());
m_websocket->close(3005, m_exceptionState); m_websocket->close(3005, m_exceptionState);
...@@ -413,8 +405,6 @@ TEST_F(WebSocketTest, closeWithoutCodeAndReason) ...@@ -413,8 +405,6 @@ TEST_F(WebSocketTest, closeWithoutCodeAndReason)
{ {
InSequence s; InSequence s;
EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String())).WillOnce(Return(true)); EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String())).WillOnce(Return(true));
EXPECT_CALL(channel(), subprotocol()).WillOnce(Return(String()));
EXPECT_CALL(channel(), extensions()).WillOnce(Return(String()));
EXPECT_CALL(channel(), close(-1, String())); EXPECT_CALL(channel(), close(-1, String()));
} }
m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState); m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState);
...@@ -422,7 +412,7 @@ TEST_F(WebSocketTest, closeWithoutCodeAndReason) ...@@ -422,7 +412,7 @@ TEST_F(WebSocketTest, closeWithoutCodeAndReason)
EXPECT_FALSE(m_exceptionState.hadException()); EXPECT_FALSE(m_exceptionState.hadException());
EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState());
m_websocket->didConnect(); m_websocket->didConnect("", "");
EXPECT_EQ(WebSocket::OPEN, m_websocket->readyState()); EXPECT_EQ(WebSocket::OPEN, m_websocket->readyState());
m_websocket->close(m_exceptionState); m_websocket->close(m_exceptionState);
...@@ -435,8 +425,6 @@ TEST_F(WebSocketTest, closeWhenClosing) ...@@ -435,8 +425,6 @@ TEST_F(WebSocketTest, closeWhenClosing)
{ {
InSequence s; InSequence s;
EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String())).WillOnce(Return(true)); EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String())).WillOnce(Return(true));
EXPECT_CALL(channel(), subprotocol()).WillOnce(Return(String()));
EXPECT_CALL(channel(), extensions()).WillOnce(Return(String()));
EXPECT_CALL(channel(), close(-1, String())); EXPECT_CALL(channel(), close(-1, String()));
} }
m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState); m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState);
...@@ -444,7 +432,7 @@ TEST_F(WebSocketTest, closeWhenClosing) ...@@ -444,7 +432,7 @@ TEST_F(WebSocketTest, closeWhenClosing)
EXPECT_FALSE(m_exceptionState.hadException()); EXPECT_FALSE(m_exceptionState.hadException());
EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState());
m_websocket->didConnect(); m_websocket->didConnect("", "");
EXPECT_EQ(WebSocket::OPEN, m_websocket->readyState()); EXPECT_EQ(WebSocket::OPEN, m_websocket->readyState());
m_websocket->close(m_exceptionState); m_websocket->close(m_exceptionState);
EXPECT_FALSE(m_exceptionState.hadException()); EXPECT_FALSE(m_exceptionState.hadException());
...@@ -461,8 +449,6 @@ TEST_F(WebSocketTest, closeWhenClosed) ...@@ -461,8 +449,6 @@ TEST_F(WebSocketTest, closeWhenClosed)
{ {
InSequence s; InSequence s;
EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String())).WillOnce(Return(true)); EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String())).WillOnce(Return(true));
EXPECT_CALL(channel(), subprotocol()).WillOnce(Return(String()));
EXPECT_CALL(channel(), extensions()).WillOnce(Return(String()));
EXPECT_CALL(channel(), close(-1, String())); EXPECT_CALL(channel(), close(-1, String()));
EXPECT_CALL(channel(), disconnect()); EXPECT_CALL(channel(), disconnect());
} }
...@@ -471,7 +457,7 @@ TEST_F(WebSocketTest, closeWhenClosed) ...@@ -471,7 +457,7 @@ TEST_F(WebSocketTest, closeWhenClosed)
EXPECT_FALSE(m_exceptionState.hadException()); EXPECT_FALSE(m_exceptionState.hadException());
EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState());
m_websocket->didConnect(); m_websocket->didConnect("", "");
EXPECT_EQ(WebSocket::OPEN, m_websocket->readyState()); EXPECT_EQ(WebSocket::OPEN, m_websocket->readyState());
m_websocket->close(m_exceptionState); m_websocket->close(m_exceptionState);
EXPECT_FALSE(m_exceptionState.hadException()); EXPECT_FALSE(m_exceptionState.hadException());
...@@ -551,15 +537,13 @@ TEST_F(WebSocketTest, sendStringSuccess) ...@@ -551,15 +537,13 @@ TEST_F(WebSocketTest, sendStringSuccess)
{ {
InSequence s; InSequence s;
EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String())).WillOnce(Return(true)); EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String())).WillOnce(Return(true));
EXPECT_CALL(channel(), subprotocol()).WillOnce(Return(String()));
EXPECT_CALL(channel(), extensions()).WillOnce(Return(String()));
EXPECT_CALL(channel(), send(String("hello"))).WillOnce(Return(WebSocketChannel::SendSuccess)); EXPECT_CALL(channel(), send(String("hello"))).WillOnce(Return(WebSocketChannel::SendSuccess));
} }
m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState); m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState);
EXPECT_FALSE(m_exceptionState.hadException()); EXPECT_FALSE(m_exceptionState.hadException());
m_websocket->didConnect(); m_websocket->didConnect("", "");
m_websocket->send("hello", m_exceptionState); m_websocket->send("hello", m_exceptionState);
EXPECT_FALSE(m_exceptionState.hadException()); EXPECT_FALSE(m_exceptionState.hadException());
...@@ -571,15 +555,13 @@ TEST_F(WebSocketTest, sendStringFail) ...@@ -571,15 +555,13 @@ TEST_F(WebSocketTest, sendStringFail)
{ {
InSequence s; InSequence s;
EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String())).WillOnce(Return(true)); EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String())).WillOnce(Return(true));
EXPECT_CALL(channel(), subprotocol()).WillOnce(Return(String()));
EXPECT_CALL(channel(), extensions()).WillOnce(Return(String()));
EXPECT_CALL(channel(), send(String("hello"))).WillOnce(Return(WebSocketChannel::SendFail)); EXPECT_CALL(channel(), send(String("hello"))).WillOnce(Return(WebSocketChannel::SendFail));
} }
m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState); m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState);
EXPECT_FALSE(m_exceptionState.hadException()); EXPECT_FALSE(m_exceptionState.hadException());
m_websocket->didConnect(); m_websocket->didConnect("", "");
m_websocket->send("hello", m_exceptionState); m_websocket->send("hello", m_exceptionState);
EXPECT_FALSE(m_exceptionState.hadException()); EXPECT_FALSE(m_exceptionState.hadException());
...@@ -591,15 +573,13 @@ TEST_F(WebSocketTest, sendStringInvalidMessage) ...@@ -591,15 +573,13 @@ TEST_F(WebSocketTest, sendStringInvalidMessage)
{ {
InSequence s; InSequence s;
EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String())).WillOnce(Return(true)); EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String())).WillOnce(Return(true));
EXPECT_CALL(channel(), subprotocol()).WillOnce(Return(String()));
EXPECT_CALL(channel(), extensions()).WillOnce(Return(String()));
EXPECT_CALL(channel(), send(String("hello"))).WillOnce(Return(WebSocketChannel::InvalidMessage)); EXPECT_CALL(channel(), send(String("hello"))).WillOnce(Return(WebSocketChannel::InvalidMessage));
} }
m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState); m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState);
EXPECT_FALSE(m_exceptionState.hadException()); EXPECT_FALSE(m_exceptionState.hadException());
m_websocket->didConnect(); m_websocket->didConnect("", "");
m_websocket->send("hello", m_exceptionState); m_websocket->send("hello", m_exceptionState);
EXPECT_TRUE(m_exceptionState.hadException()); EXPECT_TRUE(m_exceptionState.hadException());
...@@ -677,15 +657,13 @@ TEST_F(WebSocketTest, sendArrayBufferSuccess) ...@@ -677,15 +657,13 @@ TEST_F(WebSocketTest, sendArrayBufferSuccess)
{ {
InSequence s; InSequence s;
EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String())).WillOnce(Return(true)); EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String())).WillOnce(Return(true));
EXPECT_CALL(channel(), subprotocol()).WillOnce(Return(String()));
EXPECT_CALL(channel(), extensions()).WillOnce(Return(String()));
EXPECT_CALL(channel(), send(Ref(*view->buffer()), 0, 8)).WillOnce(Return(WebSocketChannel::SendSuccess)); EXPECT_CALL(channel(), send(Ref(*view->buffer()), 0, 8)).WillOnce(Return(WebSocketChannel::SendSuccess));
} }
m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState); m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState);
EXPECT_FALSE(m_exceptionState.hadException()); EXPECT_FALSE(m_exceptionState.hadException());
m_websocket->didConnect(); m_websocket->didConnect("", "");
m_websocket->send(view->buffer().get(), m_exceptionState); m_websocket->send(view->buffer().get(), m_exceptionState);
EXPECT_FALSE(m_exceptionState.hadException()); EXPECT_FALSE(m_exceptionState.hadException());
...@@ -698,15 +676,13 @@ TEST_F(WebSocketTest, sendArrayBufferFail) ...@@ -698,15 +676,13 @@ TEST_F(WebSocketTest, sendArrayBufferFail)
{ {
InSequence s; InSequence s;
EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String())).WillOnce(Return(true)); EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String())).WillOnce(Return(true));
EXPECT_CALL(channel(), subprotocol()).WillOnce(Return(String()));
EXPECT_CALL(channel(), extensions()).WillOnce(Return(String()));
EXPECT_CALL(channel(), send(Ref(*view->buffer()), 0, 8)).WillOnce(Return(WebSocketChannel::SendFail)); EXPECT_CALL(channel(), send(Ref(*view->buffer()), 0, 8)).WillOnce(Return(WebSocketChannel::SendFail));
} }
m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState); m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState);
EXPECT_FALSE(m_exceptionState.hadException()); EXPECT_FALSE(m_exceptionState.hadException());
m_websocket->didConnect(); m_websocket->didConnect("", "");
m_websocket->send(view->buffer().get(), m_exceptionState); m_websocket->send(view->buffer().get(), m_exceptionState);
EXPECT_FALSE(m_exceptionState.hadException()); EXPECT_FALSE(m_exceptionState.hadException());
...@@ -719,15 +695,13 @@ TEST_F(WebSocketTest, sendArrayBufferInvalidMessage) ...@@ -719,15 +695,13 @@ TEST_F(WebSocketTest, sendArrayBufferInvalidMessage)
{ {
InSequence s; InSequence s;
EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String())).WillOnce(Return(true)); EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String())).WillOnce(Return(true));
EXPECT_CALL(channel(), subprotocol()).WillOnce(Return(String()));
EXPECT_CALL(channel(), extensions()).WillOnce(Return(String()));
EXPECT_CALL(channel(), send(Ref(*view->buffer()), 0, 8)).WillOnce(Return(WebSocketChannel::InvalidMessage)); EXPECT_CALL(channel(), send(Ref(*view->buffer()), 0, 8)).WillOnce(Return(WebSocketChannel::InvalidMessage));
} }
m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState); m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState);
EXPECT_FALSE(m_exceptionState.hadException()); EXPECT_FALSE(m_exceptionState.hadException());
m_websocket->didConnect(); m_websocket->didConnect("", "");
m_websocket->send(view->buffer().get(), m_exceptionState); m_websocket->send(view->buffer().get(), m_exceptionState);
EXPECT_TRUE(m_exceptionState.hadException()); EXPECT_TRUE(m_exceptionState.hadException());
......
...@@ -143,16 +143,6 @@ bool WorkerThreadableWebSocketChannel::connect(const KURL& url, const String& pr ...@@ -143,16 +143,6 @@ bool WorkerThreadableWebSocketChannel::connect(const KURL& url, const String& pr
return false; return false;
} }
String WorkerThreadableWebSocketChannel::subprotocol()
{
return m_workerClientWrapper->subprotocol();
}
String WorkerThreadableWebSocketChannel::extensions()
{
return m_workerClientWrapper->extensions();
}
WebSocketChannel::SendResult WorkerThreadableWebSocketChannel::send(const String& message) WebSocketChannel::SendResult WorkerThreadableWebSocketChannel::send(const String& message)
{ {
if (!m_bridge) if (!m_bridge)
...@@ -377,15 +367,13 @@ void WorkerThreadableWebSocketChannel::Peer::resume() ...@@ -377,15 +367,13 @@ void WorkerThreadableWebSocketChannel::Peer::resume()
static void workerGlobalScopeDidConnect(ExecutionContext* context, PassRefPtrWillBeRawPtr<ThreadableWebSocketChannelClientWrapper> workerClientWrapper, const String& subprotocol, const String& extensions) static void workerGlobalScopeDidConnect(ExecutionContext* context, PassRefPtrWillBeRawPtr<ThreadableWebSocketChannelClientWrapper> workerClientWrapper, const String& subprotocol, const String& extensions)
{ {
ASSERT_UNUSED(context, context->isWorkerGlobalScope()); ASSERT_UNUSED(context, context->isWorkerGlobalScope());
workerClientWrapper->setSubprotocol(subprotocol); workerClientWrapper->didConnect(subprotocol, extensions);
workerClientWrapper->setExtensions(extensions);
workerClientWrapper->didConnect();
} }
void WorkerThreadableWebSocketChannel::Peer::didConnect() void WorkerThreadableWebSocketChannel::Peer::didConnect(const String& subprotocol, const String& extensions)
{ {
ASSERT(isMainThread()); ASSERT(isMainThread());
m_loaderProxy.postTaskToWorkerGlobalScope(createCallbackTask(&workerGlobalScopeDidConnect, m_workerClientWrapper.get(), m_mainWebSocketChannel->subprotocol(), m_mainWebSocketChannel->extensions())); m_loaderProxy.postTaskToWorkerGlobalScope(createCallbackTask(&workerGlobalScopeDidConnect, m_workerClientWrapper.get(), subprotocol, extensions));
} }
static void workerGlobalScopeDidReceiveMessage(ExecutionContext* context, PassRefPtrWillBeRawPtr<ThreadableWebSocketChannelClientWrapper> workerClientWrapper, const String& message) static void workerGlobalScopeDidReceiveMessage(ExecutionContext* context, PassRefPtrWillBeRawPtr<ThreadableWebSocketChannelClientWrapper> workerClientWrapper, const String& message)
......
...@@ -73,8 +73,6 @@ public: ...@@ -73,8 +73,6 @@ public:
// WebSocketChannel functions. // WebSocketChannel functions.
virtual bool connect(const KURL&, const String& protocol) OVERRIDE; virtual bool connect(const KURL&, const String& protocol) OVERRIDE;
virtual String subprotocol() OVERRIDE;
virtual String extensions() OVERRIDE;
virtual WebSocketChannel::SendResult send(const String& message) OVERRIDE; virtual WebSocketChannel::SendResult send(const String& message) OVERRIDE;
virtual WebSocketChannel::SendResult send(const ArrayBuffer&, unsigned byteOffset, unsigned byteLength) OVERRIDE; virtual WebSocketChannel::SendResult send(const ArrayBuffer&, unsigned byteOffset, unsigned byteLength) OVERRIDE;
virtual WebSocketChannel::SendResult send(PassRefPtr<BlobDataHandle>) OVERRIDE; virtual WebSocketChannel::SendResult send(PassRefPtr<BlobDataHandle>) OVERRIDE;
...@@ -117,7 +115,7 @@ public: ...@@ -117,7 +115,7 @@ public:
void resume(); void resume();
// WebSocketChannelClient functions. // WebSocketChannelClient functions.
virtual void didConnect() OVERRIDE; virtual void didConnect(const String& subprotocol, const String& extensions) OVERRIDE;
virtual void didReceiveMessage(const String& message) OVERRIDE; virtual void didReceiveMessage(const String& message) OVERRIDE;
virtual void didReceiveBinaryData(PassOwnPtr<Vector<char> >) OVERRIDE; virtual void didReceiveBinaryData(PassOwnPtr<Vector<char> >) OVERRIDE;
virtual void didUpdateBufferedAmount(unsigned long bufferedAmount) OVERRIDE; virtual void didUpdateBufferedAmount(unsigned long bufferedAmount) OVERRIDE;
......
...@@ -85,12 +85,12 @@ void WebSocketImpl::connect(const WebURL& url, const WebString& protocol) ...@@ -85,12 +85,12 @@ void WebSocketImpl::connect(const WebURL& url, const WebString& protocol)
WebString WebSocketImpl::subprotocol() WebString WebSocketImpl::subprotocol()
{ {
return m_private->subprotocol(); return m_subprotocol;
} }
WebString WebSocketImpl::extensions() WebString WebSocketImpl::extensions()
{ {
return m_private->extensions(); return m_extensions;
} }
bool WebSocketImpl::sendText(const WebString& message) bool WebSocketImpl::sendText(const WebString& message)
...@@ -124,8 +124,10 @@ void WebSocketImpl::disconnect() ...@@ -124,8 +124,10 @@ void WebSocketImpl::disconnect()
m_client = 0; m_client = 0;
} }
void WebSocketImpl::didConnect() void WebSocketImpl::didConnect(const String& subprotocol, const String& extensions)
{ {
m_subprotocol = subprotocol;
m_extensions = extensions;
m_client->didConnect(); m_client->didConnect();
} }
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "modules/websockets/WebSocketChannelClient.h" #include "modules/websockets/WebSocketChannelClient.h"
#include "platform/heap/Handle.h" #include "platform/heap/Handle.h"
#include "public/platform/WebCommon.h" #include "public/platform/WebCommon.h"
#include "public/platform/WebString.h"
#include "public/web/WebSocket.h" #include "public/web/WebSocket.h"
#include "public/web/WebSocketClient.h" #include "public/web/WebSocketClient.h"
#include "wtf/OwnPtr.h" #include "wtf/OwnPtr.h"
...@@ -44,7 +45,6 @@ namespace WebCore { class WebSocketChannel; } ...@@ -44,7 +45,6 @@ namespace WebCore { class WebSocketChannel; }
namespace blink { namespace blink {
class WebDocument; class WebDocument;
class WebString;
class WebURL; class WebURL;
class WebSocketImpl FINAL : public WebSocket, public WebCore::WebSocketChannelClient { class WebSocketImpl FINAL : public WebSocket, public WebCore::WebSocketChannelClient {
...@@ -67,7 +67,7 @@ public: ...@@ -67,7 +67,7 @@ public:
virtual void disconnect() OVERRIDE; virtual void disconnect() OVERRIDE;
// WebSocketChannelClient // WebSocketChannelClient
virtual void didConnect() OVERRIDE; virtual void didConnect(const String& subprotocol, const String& extensions) OVERRIDE;
virtual void didReceiveMessage(const String& message) OVERRIDE; virtual void didReceiveMessage(const String& message) OVERRIDE;
virtual void didReceiveBinaryData(PassOwnPtr<Vector<char> > binaryData) OVERRIDE; virtual void didReceiveBinaryData(PassOwnPtr<Vector<char> > binaryData) OVERRIDE;
virtual void didReceiveMessageError() OVERRIDE; virtual void didReceiveMessageError() OVERRIDE;
...@@ -79,6 +79,8 @@ private: ...@@ -79,6 +79,8 @@ private:
RefPtrWillBePersistent<WebCore::WebSocketChannel> m_private; RefPtrWillBePersistent<WebCore::WebSocketChannel> m_private;
WebSocketClient* m_client; WebSocketClient* m_client;
BinaryType m_binaryType; BinaryType m_binaryType;
WebString m_subprotocol;
WebString m_extensions;
}; };
} // namespace blink } // namespace blink
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment