This source file includes following definitions.
- m_binaryType
- binaryType
- setBinaryType
- connect
- subprotocol
- extensions
- sendText
- sendArrayBuffer
- bufferedAmount
- close
- fail
- disconnect
- didConnect
- didReceiveMessage
- didReceiveBinaryData
- didReceiveMessageError
- didUpdateBufferedAmount
- didStartClosingHandshake
- didClose
#include "config.h"
#include "WebSocketImpl.h"
#include "RuntimeEnabledFeatures.h"
#include "WebDocument.h"
#include "core/dom/Document.h"
#include "core/frame/ConsoleTypes.h"
#include "modules/websockets/MainThreadWebSocketChannel.h"
#include "modules/websockets/NewWebSocketChannelImpl.h"
#include "modules/websockets/WebSocketChannel.h"
#include "public/platform/WebArrayBuffer.h"
#include "public/platform/WebString.h"
#include "public/platform/WebURL.h"
#include "wtf/ArrayBuffer.h"
using namespace WebCore;
namespace blink {
WebSocketImpl::WebSocketImpl(const WebDocument& document, WebSocketClient* client)
: m_client(client)
, m_binaryType(BinaryTypeBlob)
{
RefPtr<Document> coreDocument = PassRefPtr<Document>(document);
if (RuntimeEnabledFeatures::experimentalWebSocketEnabled()) {
m_private = NewWebSocketChannelImpl::create(coreDocument.get(), this);
} else {
m_private = MainThreadWebSocketChannel::create(coreDocument.get(), this);
}
}
WebSocketImpl::~WebSocketImpl()
{
m_private->disconnect();
}
WebSocket::BinaryType WebSocketImpl::binaryType() const
{
return m_binaryType;
}
bool WebSocketImpl::setBinaryType(BinaryType binaryType)
{
if (binaryType > BinaryTypeArrayBuffer)
return false;
m_binaryType = binaryType;
return true;
}
void WebSocketImpl::connect(const WebURL& url, const WebString& protocol)
{
m_private->connect(url, protocol);
}
WebString WebSocketImpl::subprotocol()
{
return m_private->subprotocol();
}
WebString WebSocketImpl::extensions()
{
return m_private->extensions();
}
bool WebSocketImpl::sendText(const WebString& message)
{
return m_private->send(message) == WebSocketChannel::SendSuccess;
}
bool WebSocketImpl::sendArrayBuffer(const WebArrayBuffer& webArrayBuffer)
{
return m_private->send(*PassRefPtr<ArrayBuffer>(webArrayBuffer), 0, webArrayBuffer.byteLength()) == WebSocketChannel::SendSuccess;
}
unsigned long WebSocketImpl::bufferedAmount() const
{
return m_private->bufferedAmount();
}
void WebSocketImpl::close(int code, const WebString& reason)
{
m_private->close(code, reason);
}
void WebSocketImpl::fail(const WebString& reason)
{
m_private->fail(reason, ErrorMessageLevel);
}
void WebSocketImpl::disconnect()
{
m_private->disconnect();
m_client = 0;
}
void WebSocketImpl::didConnect()
{
m_client->didConnect();
}
void WebSocketImpl::didReceiveMessage(const String& message)
{
m_client->didReceiveMessage(WebString(message));
}
void WebSocketImpl::didReceiveBinaryData(PassOwnPtr<Vector<char> > binaryData)
{
switch (m_binaryType) {
case BinaryTypeBlob:
break;
case BinaryTypeArrayBuffer:
m_client->didReceiveArrayBuffer(WebArrayBuffer(ArrayBuffer::create(binaryData->data(), binaryData->size())));
break;
}
}
void WebSocketImpl::didReceiveMessageError()
{
m_client->didReceiveMessageError();
}
void WebSocketImpl::didUpdateBufferedAmount(unsigned long bufferedAmount)
{
m_client->didUpdateBufferedAmount(bufferedAmount);
}
void WebSocketImpl::didStartClosingHandshake()
{
m_client->didStartClosingHandshake();
}
void WebSocketImpl::didClose(unsigned long bufferedAmount, ClosingHandshakeCompletionStatus status, unsigned short code, const String& reason)
{
m_client->didClose(bufferedAmount, static_cast<WebSocketClient::ClosingHandshakeCompletionStatus>(status), code, WebString(reason));
}
}