summaryrefslogtreecommitdiffstats
path: root/chromium/third_party/WebKit/Source/modules/websockets/MainThreadWebSocketChannel.h
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/WebKit/Source/modules/websockets/MainThreadWebSocketChannel.h')
-rw-r--r--chromium/third_party/WebKit/Source/modules/websockets/MainThreadWebSocketChannel.h68
1 files changed, 42 insertions, 26 deletions
diff --git a/chromium/third_party/WebKit/Source/modules/websockets/MainThreadWebSocketChannel.h b/chromium/third_party/WebKit/Source/modules/websockets/MainThreadWebSocketChannel.h
index 5a4532c7e1c..729792e3f46 100644
--- a/chromium/third_party/WebKit/Source/modules/websockets/MainThreadWebSocketChannel.h
+++ b/chromium/third_party/WebKit/Source/modules/websockets/MainThreadWebSocketChannel.h
@@ -44,7 +44,6 @@
#include "wtf/Deque.h"
#include "wtf/Forward.h"
#include "wtf/PassOwnPtr.h"
-#include "wtf/RefCounted.h"
#include "wtf/Vector.h"
#include "wtf/text/CString.h"
@@ -57,63 +56,76 @@ class SocketStreamHandle;
class SocketStreamError;
class WebSocketChannelClient;
-class MainThreadWebSocketChannel : public RefCounted<MainThreadWebSocketChannel>, public SocketStreamHandleClient, public WebSocketChannel, public FileReaderLoaderClient {
- WTF_MAKE_FAST_ALLOCATED;
+class MainThreadWebSocketChannel FINAL : public WebSocketChannel, public SocketStreamHandleClient, public FileReaderLoaderClient {
+ WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED;
public:
// You can specify the source file and the line number information
// explicitly by passing the last parameter.
// In the usual case, they are set automatically and you don't have to
// pass it.
- static PassRefPtr<MainThreadWebSocketChannel> create(Document* document, WebSocketChannelClient* client, const String& sourceURL = String(), unsigned lineNumber = 0) { return adoptRef(new MainThreadWebSocketChannel(document, client, sourceURL, lineNumber)); }
+ static PassRefPtrWillBeRawPtr<MainThreadWebSocketChannel> create(Document* document, WebSocketChannelClient* client, const String& sourceURL = String(), unsigned lineNumber = 0)
+ {
+ return adoptRefWillBeRefCountedGarbageCollected(new MainThreadWebSocketChannel(document, client, sourceURL, lineNumber));
+ }
virtual ~MainThreadWebSocketChannel();
- bool send(const char* data, int length);
-
// WebSocketChannel functions.
- virtual void connect(const KURL&, const String& protocol) OVERRIDE;
- virtual String subprotocol() OVERRIDE;
- virtual String extensions() OVERRIDE;
+ virtual bool connect(const KURL&, const String& protocol) OVERRIDE;
virtual WebSocketChannel::SendResult send(const String& message) OVERRIDE;
virtual WebSocketChannel::SendResult send(const ArrayBuffer&, unsigned byteOffset, unsigned byteLength) OVERRIDE;
virtual WebSocketChannel::SendResult send(PassRefPtr<BlobDataHandle>) OVERRIDE;
- virtual unsigned long bufferedAmount() const OVERRIDE;
+ virtual WebSocketChannel::SendResult send(PassOwnPtr<Vector<char> > data) OVERRIDE;
// Start closing handshake. Use the CloseEventCodeNotSpecified for the code
// argument to omit payload.
virtual void close(int code, const String& reason) OVERRIDE;
virtual void fail(const String& reason, MessageLevel, const String&, unsigned lineNumber) OVERRIDE;
- using WebSocketChannel::fail;
virtual void disconnect() OVERRIDE;
virtual void suspend() OVERRIDE;
virtual void resume() OVERRIDE;
// SocketStreamHandleClient functions.
- virtual void willOpenSocketStream(SocketStreamHandle*) OVERRIDE;
virtual void didOpenSocketStream(SocketStreamHandle*) OVERRIDE;
virtual void didCloseSocketStream(SocketStreamHandle*) OVERRIDE;
virtual void didReceiveSocketStreamData(SocketStreamHandle*, const char*, int) OVERRIDE;
- virtual void didUpdateBufferedAmount(SocketStreamHandle*, size_t bufferedAmount) OVERRIDE;
+ virtual void didConsumeBufferedAmount(SocketStreamHandle*, size_t consumed) OVERRIDE;
virtual void didFailSocketStream(SocketStreamHandle*, const SocketStreamError&) OVERRIDE;
// FileReaderLoaderClient functions.
- virtual void didStartLoading();
- virtual void didReceiveData();
- virtual void didFinishLoading();
- virtual void didFail(FileError::ErrorCode);
-
- using RefCounted<MainThreadWebSocketChannel>::ref;
- using RefCounted<MainThreadWebSocketChannel>::deref;
-
-protected:
- // WebSocketChannel functions.
- virtual void refWebSocketChannel() OVERRIDE { ref(); }
- virtual void derefWebSocketChannel() OVERRIDE { deref(); }
+ virtual void didStartLoading() OVERRIDE;
+ virtual void didReceiveData() OVERRIDE;
+ virtual void didFinishLoading() OVERRIDE;
+ virtual void didFail(FileError::ErrorCode) OVERRIDE;
private:
MainThreadWebSocketChannel(Document*, WebSocketChannelClient*, const String&, unsigned);
+ class FramingOverhead {
+ public:
+ FramingOverhead(WebSocketFrame::OpCode opcode, size_t frameDataSize, size_t originalPayloadLength)
+ : m_opcode(opcode)
+ , m_frameDataSize(frameDataSize)
+ , m_originalPayloadLength(originalPayloadLength)
+ {
+ }
+
+ WebSocketFrame::OpCode opcode() const { return m_opcode; }
+ size_t frameDataSize() const { return m_frameDataSize; }
+ size_t originalPayloadLength() const { return m_originalPayloadLength; }
+
+ private:
+ WebSocketFrame::OpCode m_opcode;
+ size_t m_frameDataSize;
+ size_t m_originalPayloadLength;
+ };
+
+ void clearDocument();
+
void disconnectHandle();
+ // Calls didReceiveMessageError() on m_client if we haven't yet.
+ void callDidReceiveMessageError();
+
bool appendToBuffer(const char* data, size_t len);
void skipBuffer(size_t len);
// Repeats parsing data from m_buffer until instructed to stop.
@@ -150,6 +162,7 @@ private:
};
void enqueueTextFrame(const CString&);
void enqueueRawFrame(WebSocketFrame::OpCode, const char* data, size_t dataLength);
+ void enqueueVector(WebSocketFrame::OpCode, PassOwnPtr<Vector<char> >);
void enqueueBlobFrame(WebSocketFrame::OpCode, PassRefPtr<BlobDataHandle>);
void failAsError(const String& reason) { fail(reason, ErrorMessageLevel, m_sourceURLAtConstruction, m_lineNumberAtConstruction); }
@@ -201,7 +214,6 @@ private:
Timer<MainThreadWebSocketChannel> m_closingTimer;
ChannelState m_state;
bool m_shouldDiscardReceivedData;
- unsigned long m_unhandledBufferedAmount;
unsigned long m_identifier; // m_identifier == 0 means that we could not obtain a valid identifier.
@@ -214,6 +226,10 @@ private:
Deque<OwnPtr<QueuedFrame> > m_outgoingFrameQueue;
OutgoingFrameQueueStatus m_outgoingFrameQueueStatus;
+ Deque<FramingOverhead> m_framingOverheadQueue;
+ // The number of bytes that are already consumed (i.e. sent) in the
+ // current frame.
+ size_t m_numConsumedBytesInCurrentFrame;
// FIXME: Load two or more Blobs simultaneously for better performance.
OwnPtr<FileReaderLoader> m_blobLoader;