From 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c Mon Sep 17 00:00:00 2001 From: Lorry Tar Creator Date: Tue, 27 Jun 2017 06:07:23 +0000 Subject: webkitgtk-2.16.5 --- .../WebCore/Modules/websockets/WebSocketChannel.h | 115 +++++++++------------ 1 file changed, 51 insertions(+), 64 deletions(-) (limited to 'Source/WebCore/Modules/websockets/WebSocketChannel.h') diff --git a/Source/WebCore/Modules/websockets/WebSocketChannel.h b/Source/WebCore/Modules/websockets/WebSocketChannel.h index 1102f6aaf..b3a52ccc7 100644 --- a/Source/WebCore/Modules/websockets/WebSocketChannel.h +++ b/Source/WebCore/Modules/websockets/WebSocketChannel.h @@ -28,8 +28,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef WebSocketChannel_h -#define WebSocketChannel_h +#pragma once #if ENABLE(WEB_SOCKETS) @@ -39,7 +38,6 @@ #include "Timer.h" #include "WebSocketDeflateFramer.h" #include "WebSocketFrame.h" -#include "WebSocketHandshake.h" #include #include #include @@ -51,46 +49,42 @@ namespace WebCore { class Blob; class Document; class FileReaderLoader; +class SocketProvider; class SocketStreamHandle; class SocketStreamError; class WebSocketChannelClient; +class WebSocketHandshake; -class WebSocketChannel : public RefCounted, public SocketStreamHandleClient, public ThreadableWebSocketChannel -#if ENABLE(BLOB) - , public FileReaderLoaderClient -#endif +class WebSocketChannel : public RefCounted, public SocketStreamHandleClient, public ThreadableWebSocketChannel, public FileReaderLoaderClient { WTF_MAKE_FAST_ALLOCATED; public: - static PassRefPtr create(Document* document, WebSocketChannelClient* client) { return adoptRef(new WebSocketChannel(document, client)); } + static Ref create(Document& document, WebSocketChannelClient& client, SocketProvider& provider) { return adoptRef(*new WebSocketChannel(document, client, provider)); } virtual ~WebSocketChannel(); bool send(const char* data, int length); // ThreadableWebSocketChannel functions. - virtual void connect(const URL&, const String& protocol) override; - virtual String subprotocol() override; - virtual String extensions() override; - virtual ThreadableWebSocketChannel::SendResult send(const String& message) override; - virtual ThreadableWebSocketChannel::SendResult send(const JSC::ArrayBuffer&, unsigned byteOffset, unsigned byteLength) override; - virtual ThreadableWebSocketChannel::SendResult send(const Blob&) override; - virtual unsigned long bufferedAmount() const override; - virtual void close(int code, const String& reason) override; // Start closing handshake. - virtual void fail(const String& reason) override; - virtual void disconnect() override; - - virtual void suspend() override; - virtual void resume() override; + void connect(const URL&, const String& protocol) override; + String subprotocol() override; + String extensions() override; + ThreadableWebSocketChannel::SendResult send(const String& message) override; + ThreadableWebSocketChannel::SendResult send(const JSC::ArrayBuffer&, unsigned byteOffset, unsigned byteLength) override; + ThreadableWebSocketChannel::SendResult send(Blob&) override; + unsigned bufferedAmount() const override; + void close(int code, const String& reason) override; // Start closing handshake. + void fail(const String& reason) override; + void disconnect() override; + + void suspend() override; + 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 didFailSocketStream(SocketStreamHandle*, const SocketStreamError&) override; - virtual void didReceiveAuthenticationChallenge(SocketStreamHandle*, const AuthenticationChallenge&) override; - virtual void didCancelAuthenticationChallenge(SocketStreamHandle*, const AuthenticationChallenge&) override; + void didOpenSocketStream(SocketStreamHandle&) final; + void didCloseSocketStream(SocketStreamHandle&) final; + void didReceiveSocketStreamData(SocketStreamHandle&, const char*, std::optional) final; + void didUpdateBufferedAmount(SocketStreamHandle&, size_t bufferedAmount) final; + void didFailSocketStream(SocketStreamHandle&, const SocketStreamError&) final; enum CloseEventCode { CloseEventCodeNotSpecified = -1, @@ -111,30 +105,28 @@ public: CloseEventCodeMaximumUserDefined = 4999 }; -#if ENABLE(BLOB) // FileReaderLoaderClient functions. - virtual void didStartLoading(); - virtual void didReceiveData(); - virtual void didFinishLoading(); - virtual void didFail(int errorCode); -#endif + void didStartLoading() override; + void didReceiveData() override; + void didFinishLoading() override; + void didFail(int errorCode) override; using RefCounted::ref; using RefCounted::deref; protected: - virtual void refThreadableWebSocketChannel() { ref(); } - virtual void derefThreadableWebSocketChannel() { deref(); } + void refThreadableWebSocketChannel() override { ref(); } + void derefThreadableWebSocketChannel() override { deref(); } private: - WebSocketChannel(Document*, WebSocketChannelClient*); + WEBCORE_EXPORT WebSocketChannel(Document&, WebSocketChannelClient&, SocketProvider&); bool appendToBuffer(const char* data, size_t len); void skipBuffer(size_t len); bool processBuffer(); - void resumeTimerFired(Timer*); + void resumeTimerFired(); void startClosingHandshake(int code, const String& reason); - void closingTimerFired(Timer*); + void closingTimerFired(); bool processFrame(); @@ -161,7 +153,7 @@ private: }; void enqueueTextFrame(const CString&); void enqueueRawFrame(WebSocketFrame::OpCode, const char* data, size_t dataLength); - void enqueueBlobFrame(WebSocketFrame::OpCode, const Blob&); + void enqueueBlobFrame(WebSocketFrame::OpCode, Blob&); void processOutgoingFrameQueue(); void abortOutgoingFrameQueue(); @@ -182,53 +174,48 @@ private: // instead of call sendFrame() directly. bool sendFrame(WebSocketFrame::OpCode, const char* data, size_t dataLength); -#if ENABLE(BLOB) enum BlobLoaderStatus { BlobLoaderNotStarted, BlobLoaderStarted, BlobLoaderFinished, BlobLoaderFailed }; -#endif Document* m_document; WebSocketChannelClient* m_client; - OwnPtr m_handshake; + std::unique_ptr m_handshake; RefPtr m_handle; Vector m_buffer; - Timer m_resumeTimer; - bool m_suspended; - bool m_closing; - bool m_receivedClosingHandshake; - Timer m_closingTimer; - bool m_closed; - bool m_shouldDiscardReceivedData; - unsigned long m_unhandledBufferedAmount; + Timer m_resumeTimer; + bool m_suspended { false }; + bool m_closing { false }; + bool m_receivedClosingHandshake { false }; + Timer m_closingTimer; + bool m_closed { false }; + bool m_shouldDiscardReceivedData { false }; + unsigned m_unhandledBufferedAmount { 0 }; - unsigned long m_identifier; // m_identifier == 0 means that we could not obtain a valid identifier. + unsigned m_identifier { 0 }; // m_identifier == 0 means that we could not obtain a valid identifier. // Private members only for hybi-10 protocol. - bool m_hasContinuousFrame; + bool m_hasContinuousFrame { false }; WebSocketFrame::OpCode m_continuousFrameOpCode; - Vector m_continuousFrameData; - unsigned short m_closeEventCode; + Vector m_continuousFrameData; + unsigned short m_closeEventCode { CloseEventCodeAbnormalClosure }; String m_closeEventReason; - Deque> m_outgoingFrameQueue; - OutgoingFrameQueueStatus m_outgoingFrameQueueStatus; + Deque> m_outgoingFrameQueue; + OutgoingFrameQueueStatus m_outgoingFrameQueueStatus { OutgoingFrameQueueOpen }; -#if ENABLE(BLOB) // FIXME: Load two or more Blobs simultaneously for better performance. - OwnPtr m_blobLoader; - BlobLoaderStatus m_blobLoaderStatus; -#endif + std::unique_ptr m_blobLoader; + BlobLoaderStatus m_blobLoaderStatus { BlobLoaderNotStarted }; WebSocketDeflateFramer m_deflateFramer; + Ref m_socketProvider; }; } // namespace WebCore #endif // ENABLE(WEB_SOCKETS) - -#endif // WebSocketChannel_h -- cgit v1.2.1