This source file includes following definitions.
- m_suspended
- create
- subprotocol
- setSubprotocol
- extensions
- setExtensions
- clearClient
- didConnect
- didReceiveMessage
- didReceiveBinaryData
- didUpdateBufferedAmount
- didStartClosingHandshake
- didClose
- didReceiveMessageError
- suspend
- resume
- processPendingTasks
- didConnectCallback
- didReceiveMessageCallback
- didReceiveBinaryDataCallback
- didUpdateBufferedAmountCallback
- didStartClosingHandshakeCallback
- didCloseCallback
- didReceiveMessageErrorCallback
#include "config.h"
#include "modules/websockets/ThreadableWebSocketChannelClientWrapper.h"
#include "core/dom/CrossThreadTask.h"
#include "core/dom/ExecutionContext.h"
#include "platform/CrossThreadCopier.h"
#include "wtf/PassRefPtr.h"
#include "wtf/RefPtr.h"
namespace WebCore {
ThreadableWebSocketChannelClientWrapper::ThreadableWebSocketChannelClientWrapper(WebSocketChannelClient* client)
: m_client(client)
, m_suspended(false)
{
}
PassRefPtr<ThreadableWebSocketChannelClientWrapper> ThreadableWebSocketChannelClientWrapper::create(WebSocketChannelClient* client)
{
return adoptRef(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()
{
m_client = 0;
}
void ThreadableWebSocketChannelClientWrapper::didConnect()
{
m_pendingTasks.append(createCallbackTask(&didConnectCallback, this));
if (!m_suspended)
processPendingTasks();
}
void ThreadableWebSocketChannelClientWrapper::didReceiveMessage(const String& message)
{
m_pendingTasks.append(createCallbackTask(&didReceiveMessageCallback, this, message));
if (!m_suspended)
processPendingTasks();
}
void ThreadableWebSocketChannelClientWrapper::didReceiveBinaryData(PassOwnPtr<Vector<char> > binaryData)
{
m_pendingTasks.append(createCallbackTask(&didReceiveBinaryDataCallback, this, binaryData));
if (!m_suspended)
processPendingTasks();
}
void ThreadableWebSocketChannelClientWrapper::didUpdateBufferedAmount(unsigned long bufferedAmount)
{
m_pendingTasks.append(createCallbackTask(&didUpdateBufferedAmountCallback, this, bufferedAmount));
if (!m_suspended)
processPendingTasks();
}
void ThreadableWebSocketChannelClientWrapper::didStartClosingHandshake()
{
m_pendingTasks.append(createCallbackTask(&didStartClosingHandshakeCallback, this));
if (!m_suspended)
processPendingTasks();
}
void ThreadableWebSocketChannelClientWrapper::didClose(unsigned long unhandledBufferedAmount, WebSocketChannelClient::ClosingHandshakeCompletionStatus closingHandshakeCompletion, unsigned short code, const String& reason)
{
m_pendingTasks.append(createCallbackTask(&didCloseCallback, this, unhandledBufferedAmount, closingHandshakeCompletion, code, reason));
if (!m_suspended)
processPendingTasks();
}
void ThreadableWebSocketChannelClientWrapper::didReceiveMessageError()
{
m_pendingTasks.append(createCallbackTask(&didReceiveMessageErrorCallback, this));
if (!m_suspended)
processPendingTasks();
}
void ThreadableWebSocketChannelClientWrapper::suspend()
{
m_suspended = true;
}
void ThreadableWebSocketChannelClientWrapper::resume()
{
m_suspended = false;
processPendingTasks();
}
void ThreadableWebSocketChannelClientWrapper::processPendingTasks()
{
if (m_suspended)
return;
Vector<OwnPtr<ExecutionContextTask> > tasks;
tasks.swap(m_pendingTasks);
for (Vector<OwnPtr<ExecutionContextTask> >::const_iterator iter = tasks.begin(); iter != tasks.end(); ++iter)
(*iter)->performTask(0);
}
void ThreadableWebSocketChannelClientWrapper::didConnectCallback(ExecutionContext* context, PassRefPtr<ThreadableWebSocketChannelClientWrapper> wrapper)
{
ASSERT_UNUSED(context, !context);
if (wrapper->m_client)
wrapper->m_client->didConnect();
}
void ThreadableWebSocketChannelClientWrapper::didReceiveMessageCallback(ExecutionContext* context, PassRefPtr<ThreadableWebSocketChannelClientWrapper> wrapper, const String& message)
{
ASSERT_UNUSED(context, !context);
if (wrapper->m_client)
wrapper->m_client->didReceiveMessage(message);
}
void ThreadableWebSocketChannelClientWrapper::didReceiveBinaryDataCallback(ExecutionContext* context, PassRefPtr<ThreadableWebSocketChannelClientWrapper> wrapper, PassOwnPtr<Vector<char> > binaryData)
{
ASSERT_UNUSED(context, !context);
if (wrapper->m_client)
wrapper->m_client->didReceiveBinaryData(binaryData);
}
void ThreadableWebSocketChannelClientWrapper::didUpdateBufferedAmountCallback(ExecutionContext* context, PassRefPtr<ThreadableWebSocketChannelClientWrapper> wrapper, unsigned long bufferedAmount)
{
ASSERT_UNUSED(context, !context);
if (wrapper->m_client)
wrapper->m_client->didUpdateBufferedAmount(bufferedAmount);
}
void ThreadableWebSocketChannelClientWrapper::didStartClosingHandshakeCallback(ExecutionContext* context, PassRefPtr<ThreadableWebSocketChannelClientWrapper> wrapper)
{
ASSERT_UNUSED(context, !context);
if (wrapper->m_client)
wrapper->m_client->didStartClosingHandshake();
}
void ThreadableWebSocketChannelClientWrapper::didCloseCallback(ExecutionContext* context, PassRefPtr<ThreadableWebSocketChannelClientWrapper> wrapper, unsigned long unhandledBufferedAmount, WebSocketChannelClient::ClosingHandshakeCompletionStatus closingHandshakeCompletion, unsigned short code, const String& reason)
{
ASSERT_UNUSED(context, !context);
if (wrapper->m_client)
wrapper->m_client->didClose(unhandledBufferedAmount, closingHandshakeCompletion, code, reason);
}
void ThreadableWebSocketChannelClientWrapper::didReceiveMessageErrorCallback(ExecutionContext* context, PassRefPtr<ThreadableWebSocketChannelClientWrapper> wrapper)
{
ASSERT_UNUSED(context, !context);
if (wrapper->m_client)
wrapper->m_client->didReceiveMessageError();
}
}