diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/Modules/websockets/WebSocket.h | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/WebCore/Modules/websockets/WebSocket.h')
-rw-r--r-- | Source/WebCore/Modules/websockets/WebSocket.h | 125 |
1 files changed, 61 insertions, 64 deletions
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 <wtf/Forward.h> -#include <wtf/OwnPtr.h> -#include <wtf/RefCounted.h> -#include <wtf/text/AtomicStringHash.h> +#include <wtf/Deque.h> + +namespace JSC { +class ArrayBuffer; +class ArrayBufferView; +} namespace WebCore { class Blob; class ThreadableWebSocketChannel; -class WebSocket final : public RefCounted<WebSocket>, public EventTargetWithInlineData, public ActiveDOMObject, public WebSocketChannelClient { +class WebSocket final : public RefCounted<WebSocket>, public EventTargetWithInlineData, public ActiveDOMObject, private WebSocketChannelClient { public: static void setIsAvailable(bool); static bool isAvailable(); - static const char* subProtocolSeperator(); - static PassRefPtr<WebSocket> create(ScriptExecutionContext&); - static PassRefPtr<WebSocket> create(ScriptExecutionContext&, const String& url, ExceptionCode&); - static PassRefPtr<WebSocket> create(ScriptExecutionContext&, const String& url, const String& protocol, ExceptionCode&); - static PassRefPtr<WebSocket> create(ScriptExecutionContext&, const String& url, const Vector<String>& protocols, ExceptionCode&); + + static const char* subprotocolSeparator(); + + static ExceptionOr<Ref<WebSocket>> create(ScriptExecutionContext&, const String& url); + static ExceptionOr<Ref<WebSocket>> create(ScriptExecutionContext&, const String& url, const String& protocol); + static ExceptionOr<Ref<WebSocket>> create(ScriptExecutionContext&, const String& url, const Vector<String>& 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<String>& protocols, ExceptionCode&); + ExceptionOr<void> connect(const String& url); + ExceptionOr<void> connect(const String& url, const String& protocol); + ExceptionOr<void> connect(const String& url, const Vector<String>& protocols); - void send(const String& message, ExceptionCode&); - void send(JSC::ArrayBuffer*, ExceptionCode&); - void send(JSC::ArrayBufferView*, ExceptionCode&); - void send(Blob*, ExceptionCode&); + ExceptionOr<void> send(const String& message); + ExceptionOr<void> send(JSC::ArrayBuffer&); + ExceptionOr<void> send(JSC::ArrayBufferView&); + ExceptionOr<void> 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<void> close(std::optional<unsigned short> 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<void> 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<WebSocket>::ref; - using RefCounted<WebSocket>::deref; + void resumeTimerFired(); + void dispatchOrQueueErrorEvent(); + void dispatchOrQueueEvent(Ref<Event>&&); - // WebSocketChannelClient functions. - virtual void didConnect() override; - virtual void didReceiveMessage(const String& message) override; - virtual void didReceiveBinaryData(PassOwnPtr<Vector<char>>) 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<uint8_t>&&) 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<ThreadableWebSocketChannel> 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<Ref<Event>> m_pendingEvents; + bool m_dispatchedErrorEvent { false }; }; } // namespace WebCore #endif // ENABLE(WEB_SOCKETS) - -#endif // WebSocket_h |