+2012-02-14 Takashi Toyoshima <toyoshim@chromium.org>
+
+ WebSocketChannel minor refactoring for code manageability
+ https://bugs.webkit.org/show_bug.cgi?id=78576
+
+ Reviewed by Kent Tamura.
+
+ Change the first argument type of WebSocketChannel
+ from ScriptExecutionContext to Document.
+ WebSocketChannel always assume this ScriptExecutionContext must
+ inherit Document. Then, it results in many static cast.
+ It isn't readable and dangerous against future code changes.
+
+ * websockets/ThreadableWebSocketChannel.cpp: Pass the first argument for WebSocketChannel as Document.
+ (WebCore::ThreadableWebSocketChannel::create):
+ * websockets/WebSocketChannel.cpp: Replace all ScriptExecutionContext* m_context descriptions to Document* m_document.
+ (WebCore::WebSocketChannel::WebSocketChannel):
+ (WebCore::WebSocketChannel::connect):
+ (WebCore::WebSocketChannel::fail):
+ (WebCore::WebSocketChannel::disconnect):
+ (WebCore::WebSocketChannel::didOpenSocketStream):
+ (WebCore::WebSocketChannel::didCloseSocketStream):
+ (WebCore::WebSocketChannel::didReceiveSocketStreamData):
+ (WebCore::WebSocketChannel::didFailSocketStream):
+ (WebCore::WebSocketChannel::processBuffer):
+ (WebCore::WebSocketChannel::processOutgoingFrameQueue):
+ * websockets/WebSocketChannel.h: Change the first argument for construction to Document and hold it as Document m_document.
+ (WebCore):
+ (WebCore::WebSocketChannel::create):
+ (WebSocketChannel):
+ * websockets/WorkerThreadableWebSocketChannel.cpp: Pass the first argument for WebSocketChannel as Document.
+ (WebCore::WorkerThreadableWebSocketChannel::Peer::Peer):
+
2012-02-14 Noel Gordon <noel.gordon@gmail.com>
Unreviewed, rolling out r107774.
/*
- * Copyright (C) 2011 Google Inc. All rights reserved.
+ * Copyright (C) 2011, 2012 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
const WebSocketChannel::OpCode WebSocketChannel::OpCodePing = 0x9;
const WebSocketChannel::OpCode WebSocketChannel::OpCodePong = 0xA;
-WebSocketChannel::WebSocketChannel(ScriptExecutionContext* context, WebSocketChannelClient* client)
- : m_context(context)
+WebSocketChannel::WebSocketChannel(Document* document, WebSocketChannelClient* client)
+ : m_document(document)
, m_client(client)
, m_buffer(0)
, m_bufferSize(0)
, m_blobLoaderStatus(BlobLoaderNotStarted)
#endif
{
- ASSERT(m_context->isDocument());
- Document* document = static_cast<Document*>(m_context);
- if (Settings* settings = document->settings())
+ if (Settings* settings = m_document->settings())
m_useHixie76Protocol = settings->useHixie76WebSocketProtocol();
- if (Page* page = document->page())
+ if (Page* page = m_document->page())
m_identifier = page->progress()->createUniqueIdentifier();
}
LOG(Network, "WebSocketChannel %p connect", this);
ASSERT(!m_handle);
ASSERT(!m_suspended);
- m_handshake = adoptPtr(new WebSocketHandshake(url, protocol, m_context, m_useHixie76Protocol));
+ m_handshake = adoptPtr(new WebSocketHandshake(url, protocol, m_document, m_useHixie76Protocol));
m_handshake->reset();
if (m_identifier)
- InspectorInstrumentation::didCreateWebSocket(m_context, m_identifier, url, m_context->url());
+ InspectorInstrumentation::didCreateWebSocket(m_document, m_identifier, url, m_document->url());
ref();
m_handle = SocketStreamHandle::create(m_handshake->url(), this);
}
{
LOG(Network, "WebSocketChannel %p fail: %s", this, reason.utf8().data());
ASSERT(!m_suspended);
- if (m_context)
- m_context->addConsoleMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, reason, m_handshake->clientOrigin());
+ if (m_document)
+ m_document->addConsoleMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, reason, m_handshake->clientOrigin());
if (!m_useHixie76Protocol) {
// Hybi-10 specification explicitly states we must not continue to handle incoming data
// once the WebSocket connection is failed (section 7.1.7).
void WebSocketChannel::disconnect()
{
LOG(Network, "WebSocketChannel %p disconnect", this);
- if (m_identifier && m_context)
- InspectorInstrumentation::didCloseWebSocket(m_context, m_identifier);
+ if (m_identifier && m_document)
+ InspectorInstrumentation::didCloseWebSocket(m_document, m_identifier);
if (m_handshake)
m_handshake->clearScriptExecutionContext();
m_client = 0;
- m_context = 0;
+ m_document = 0;
if (m_handle)
m_handle->disconnect();
}
{
LOG(Network, "WebSocketChannel %p didOpenSocketStream", this);
ASSERT(handle == m_handle);
- if (!m_context)
+ if (!m_document)
return;
if (m_identifier)
- InspectorInstrumentation::willSendWebSocketHandshakeRequest(m_context, m_identifier, m_handshake->clientHandshakeRequest());
+ InspectorInstrumentation::willSendWebSocketHandshakeRequest(m_document, m_identifier, m_handshake->clientHandshakeRequest());
CString handshakeMessage = m_handshake->clientHandshakeMessage();
if (!handle->send(handshakeMessage.data(), handshakeMessage.length()))
fail("Failed to send WebSocket handshake.");
void WebSocketChannel::didCloseSocketStream(SocketStreamHandle* handle)
{
LOG(Network, "WebSocketChannel %p didCloseSocketStream", this);
- if (m_identifier && m_context)
- InspectorInstrumentation::didCloseWebSocket(m_context, m_identifier);
+ if (m_identifier && m_document)
+ InspectorInstrumentation::didCloseWebSocket(m_document, m_identifier);
ASSERT_UNUSED(handle, handle == m_handle || !m_handle);
m_closed = true;
if (m_closingTimer.isActive())
return;
WebSocketChannelClient* client = m_client;
m_client = 0;
- m_context = 0;
+ m_document = 0;
m_handle = 0;
if (client)
client->didClose(m_unhandledBufferedAmount, m_receivedClosingHandshake ? WebSocketChannelClient::ClosingHandshakeComplete : WebSocketChannelClient::ClosingHandshakeIncomplete, m_closeEventCode, m_closeEventReason);
LOG(Network, "WebSocketChannel %p didReceiveSocketStreamData %d", this, len);
RefPtr<WebSocketChannel> protect(this); // The client can close the channel, potentially removing the last reference.
ASSERT(handle == m_handle);
- if (!m_context) {
+ if (!m_document) {
return;
}
if (len <= 0) {
{
LOG(Network, "WebSocketChannel %p didFailSocketStream", this);
ASSERT(handle == m_handle || !m_handle);
- if (m_context) {
+ if (m_document) {
String message;
if (error.isNull())
message = "WebSocket network error";
ASSERT(failingURL.isNull() || m_handshake->url().string() == failingURL);
if (failingURL.isNull())
failingURL = m_handshake->url().string();
- m_context->addConsoleMessage(NetworkMessageSource, LogMessageType, ErrorMessageLevel, message, failingURL);
+ m_document->addConsoleMessage(NetworkMessageSource, LogMessageType, ErrorMessageLevel, message, failingURL);
}
m_shouldDiscardReceivedData = true;
handle->disconnect();
return false;
if (m_handshake->mode() == WebSocketHandshake::Connected) {
if (m_identifier)
- InspectorInstrumentation::didReceiveWebSocketHandshakeResponse(m_context, m_identifier, m_handshake->serverHandshakeResponse());
+ InspectorInstrumentation::didReceiveWebSocketHandshakeResponse(m_document, m_identifier, m_handshake->serverHandshakeResponse());
if (!m_handshake->serverSetCookie().isEmpty()) {
- if (m_context->isDocument()) {
- Document* document = static_cast<Document*>(m_context);
- if (cookiesEnabled(document)) {
- ExceptionCode ec; // Exception (for sandboxed documents) ignored.
- document->setCookie(m_handshake->serverSetCookie(), ec);
- }
+ if (cookiesEnabled(m_document)) {
+ ExceptionCode ec; // Exception (for sandboxed documents) ignored.
+ m_document->setCookie(m_handshake->serverSetCookie(), ec);
}
}
// FIXME: handle set-cookie2.
ASSERT(!m_blobLoader);
m_blobLoader = adoptPtr(new FileReaderLoader(FileReaderLoader::ReadAsArrayBuffer, this));
m_blobLoaderStatus = BlobLoaderStarted;
- m_blobLoader->start(m_context, frame->blobData.get());
+ m_blobLoader->start(m_document, frame->blobData.get());
m_outgoingFrameQueue.prepend(frame.release());
return;
/*
- * Copyright (C) 2011 Google Inc. All rights reserved.
+ * Copyright (C) 2011, 2012 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
namespace WebCore {
class Blob;
+class Document;
class FileReaderLoader;
-class ScriptExecutionContext;
class SocketStreamHandle;
class SocketStreamError;
class WebSocketChannelClient;
{
WTF_MAKE_FAST_ALLOCATED;
public:
- static PassRefPtr<WebSocketChannel> create(ScriptExecutionContext* context, WebSocketChannelClient* client) { return adoptRef(new WebSocketChannel(context, client)); }
+ static PassRefPtr<WebSocketChannel> create(Document* document, WebSocketChannelClient* client) { return adoptRef(new WebSocketChannel(document, client)); }
virtual ~WebSocketChannel();
bool send(const char* data, int length);
virtual void derefThreadableWebSocketChannel() { deref(); }
private:
- WebSocketChannel(ScriptExecutionContext*, WebSocketChannelClient*);
+ WebSocketChannel(Document*, WebSocketChannelClient*);
bool appendToBuffer(const char* data, size_t len);
void skipBuffer(size_t len);
};
#endif
- ScriptExecutionContext* m_context;
+ Document* m_document;
WebSocketChannelClient* m_client;
OwnPtr<WebSocketHandshake> m_handshake;
RefPtr<SocketStreamHandle> m_handle;