summaryrefslogtreecommitdiff
path: root/Source/WebCore/Modules/websockets/WebSocketChannel.h
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/Modules/websockets/WebSocketChannel.h')
-rw-r--r--Source/WebCore/Modules/websockets/WebSocketChannel.h115
1 files changed, 51 insertions, 64 deletions
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 <wtf/Deque.h>
#include <wtf/Forward.h>
#include <wtf/RefCounted.h>
@@ -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<WebSocketChannel>, public SocketStreamHandleClient, public ThreadableWebSocketChannel
-#if ENABLE(BLOB)
- , public FileReaderLoaderClient
-#endif
+class WebSocketChannel : public RefCounted<WebSocketChannel>, public SocketStreamHandleClient, public ThreadableWebSocketChannel, public FileReaderLoaderClient
{
WTF_MAKE_FAST_ALLOCATED;
public:
- static PassRefPtr<WebSocketChannel> create(Document* document, WebSocketChannelClient* client) { return adoptRef(new WebSocketChannel(document, client)); }
+ static Ref<WebSocketChannel> 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<size_t>) 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<WebSocketChannel>::ref;
using RefCounted<WebSocketChannel>::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<WebSocketChannel>*);
+ void resumeTimerFired();
void startClosingHandshake(int code, const String& reason);
- void closingTimerFired(Timer<WebSocketChannel>*);
+ 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<WebSocketHandshake> m_handshake;
+ std::unique_ptr<WebSocketHandshake> m_handshake;
RefPtr<SocketStreamHandle> m_handle;
Vector<char> m_buffer;
- Timer<WebSocketChannel> m_resumeTimer;
- bool m_suspended;
- bool m_closing;
- bool m_receivedClosingHandshake;
- Timer<WebSocketChannel> 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<char> m_continuousFrameData;
- unsigned short m_closeEventCode;
+ Vector<uint8_t> m_continuousFrameData;
+ unsigned short m_closeEventCode { CloseEventCodeAbnormalClosure };
String m_closeEventReason;
- Deque<OwnPtr<QueuedFrame>> m_outgoingFrameQueue;
- OutgoingFrameQueueStatus m_outgoingFrameQueueStatus;
+ Deque<std::unique_ptr<QueuedFrame>> m_outgoingFrameQueue;
+ OutgoingFrameQueueStatus m_outgoingFrameQueueStatus { OutgoingFrameQueueOpen };
-#if ENABLE(BLOB)
// FIXME: Load two or more Blobs simultaneously for better performance.
- OwnPtr<FileReaderLoader> m_blobLoader;
- BlobLoaderStatus m_blobLoaderStatus;
-#endif
+ std::unique_ptr<FileReaderLoader> m_blobLoader;
+ BlobLoaderStatus m_blobLoaderStatus { BlobLoaderNotStarted };
WebSocketDeflateFramer m_deflateFramer;
+ Ref<SocketProvider> m_socketProvider;
};
} // namespace WebCore
#endif // ENABLE(WEB_SOCKETS)
-
-#endif // WebSocketChannel_h