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 --- Source/WebCore/Modules/websockets/WebSocket.h | 125 +++++++++++++------------- 1 file changed, 61 insertions(+), 64 deletions(-) (limited to 'Source/WebCore/Modules/websockets/WebSocket.h') diff --git a/Source/WebCore/Modules/websockets/WebSocket.h b/Source/WebCore/Modules/websockets/WebSocket.h index 75482d811..7d43f0436 100644 --- a/Source/WebCore/Modules/websockets/WebSocket.h +++ b/Source/WebCore/Modules/websockets/WebSocket.h @@ -28,37 +28,38 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef WebSocket_h -#define WebSocket_h +#pragma once #if ENABLE(WEB_SOCKETS) #include "ActiveDOMObject.h" -#include "EventListener.h" -#include "EventNames.h" #include "EventTarget.h" +#include "ExceptionOr.h" +#include "Timer.h" #include "URL.h" -#include "WebSocketChannel.h" #include "WebSocketChannelClient.h" -#include -#include -#include -#include +#include + +namespace JSC { +class ArrayBuffer; +class ArrayBufferView; +} namespace WebCore { class Blob; class ThreadableWebSocketChannel; -class WebSocket final : public RefCounted, public EventTargetWithInlineData, public ActiveDOMObject, public WebSocketChannelClient { +class WebSocket final : public RefCounted, public EventTargetWithInlineData, public ActiveDOMObject, private WebSocketChannelClient { public: static void setIsAvailable(bool); static bool isAvailable(); - static const char* subProtocolSeperator(); - static PassRefPtr create(ScriptExecutionContext&); - static PassRefPtr create(ScriptExecutionContext&, const String& url, ExceptionCode&); - static PassRefPtr create(ScriptExecutionContext&, const String& url, const String& protocol, ExceptionCode&); - static PassRefPtr create(ScriptExecutionContext&, const String& url, const Vector& protocols, ExceptionCode&); + + static const char* subprotocolSeparator(); + + static ExceptionOr> create(ScriptExecutionContext&, const String& url); + static ExceptionOr> create(ScriptExecutionContext&, const String& url, const String& protocol); + static ExceptionOr> create(ScriptExecutionContext&, const String& url, const Vector& protocols); virtual ~WebSocket(); enum State { @@ -68,83 +69,79 @@ public: CLOSED = 3 }; - void connect(const String& url, ExceptionCode&); - void connect(const String& url, const String& protocol, ExceptionCode&); - void connect(const String& url, const Vector& protocols, ExceptionCode&); + ExceptionOr connect(const String& url); + ExceptionOr connect(const String& url, const String& protocol); + ExceptionOr connect(const String& url, const Vector& protocols); - void send(const String& message, ExceptionCode&); - void send(JSC::ArrayBuffer*, ExceptionCode&); - void send(JSC::ArrayBufferView*, ExceptionCode&); - void send(Blob*, ExceptionCode&); + ExceptionOr send(const String& message); + ExceptionOr send(JSC::ArrayBuffer&); + ExceptionOr send(JSC::ArrayBufferView&); + ExceptionOr send(Blob&); - void close(int code, const String& reason, ExceptionCode&); - void close(ExceptionCode& ec) { close(WebSocketChannel::CloseEventCodeNotSpecified, String(), ec); } - void close(int code, ExceptionCode& ec) { close(code, String(), ec); } + ExceptionOr close(std::optional code, const String& reason); const URL& url() const; State readyState() const; - unsigned long bufferedAmount() const; + unsigned bufferedAmount() const; String protocol() const; String extensions() const; String binaryType() const; - void setBinaryType(const String&); + ExceptionOr setBinaryType(const String&); - DEFINE_ATTRIBUTE_EVENT_LISTENER(open); - DEFINE_ATTRIBUTE_EVENT_LISTENER(message); - DEFINE_ATTRIBUTE_EVENT_LISTENER(error); - DEFINE_ATTRIBUTE_EVENT_LISTENER(close); + using RefCounted::ref; + using RefCounted::deref; - // EventTarget functions. - virtual EventTargetInterface eventTargetInterface() const override; - virtual ScriptExecutionContext* scriptExecutionContext() const override; +private: + explicit WebSocket(ScriptExecutionContext&); - using RefCounted::ref; - using RefCounted::deref; + void resumeTimerFired(); + void dispatchOrQueueErrorEvent(); + void dispatchOrQueueEvent(Ref&&); - // WebSocketChannelClient functions. - virtual void didConnect() override; - virtual void didReceiveMessage(const String& message) override; - virtual void didReceiveBinaryData(PassOwnPtr>) override; - virtual void didReceiveMessageError() override; - virtual void didUpdateBufferedAmount(unsigned long bufferedAmount) override; - virtual void didStartClosingHandshake() override; - virtual void didClose(unsigned long unhandledBufferedAmount, ClosingHandshakeCompletionStatus, unsigned short code, const String& reason) override; + void contextDestroyed() final; + bool canSuspendForDocumentSuspension() const final; + void suspend(ReasonForSuspension) final; + void resume() final; + void stop() final; + const char* activeDOMObjectName() const final; -private: - explicit WebSocket(ScriptExecutionContext&); + EventTargetInterface eventTargetInterface() const final; + ScriptExecutionContext* scriptExecutionContext() const final; - // ActiveDOMObject functions. - virtual void contextDestroyed() override; - virtual bool canSuspend() const override; - virtual void suspend(ReasonForSuspension) override; - virtual void resume() override; - virtual void stop() override; + void refEventTarget() final { ref(); } + void derefEventTarget() final { deref(); } - virtual void refEventTarget() override { ref(); } - virtual void derefEventTarget() override { deref(); } + void didConnect() final; + void didReceiveMessage(const String& message) final; + void didReceiveBinaryData(Vector&&) final; + void didReceiveMessageError() final; + void didUpdateBufferedAmount(unsigned bufferedAmount) final; + void didStartClosingHandshake() final; + void didClose(unsigned unhandledBufferedAmount, ClosingHandshakeCompletionStatus, unsigned short code, const String& reason) final; + void didUpgradeURL() final; size_t getFramingOverhead(size_t payloadSize); - enum BinaryType { - BinaryTypeBlob, - BinaryTypeArrayBuffer - }; + enum class BinaryType { Blob, ArrayBuffer }; RefPtr m_channel; - State m_state; + State m_state { CONNECTING }; URL m_url; - unsigned long m_bufferedAmount; - unsigned long m_bufferedAmountAfterClose; - BinaryType m_binaryType; + unsigned m_bufferedAmount { 0 }; + unsigned m_bufferedAmountAfterClose { 0 }; + BinaryType m_binaryType { BinaryType::Blob }; String m_subprotocol; String m_extensions; + + Timer m_resumeTimer; + bool m_shouldDelayEventFiring { false }; + Deque> m_pendingEvents; + bool m_dispatchedErrorEvent { false }; }; } // namespace WebCore #endif // ENABLE(WEB_SOCKETS) - -#endif // WebSocket_h -- cgit v1.2.1