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/page/EventSource.h | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/WebCore/page/EventSource.h')
-rw-r--r-- | Source/WebCore/page/EventSource.h | 95 |
1 files changed, 53 insertions, 42 deletions
diff --git a/Source/WebCore/page/EventSource.h b/Source/WebCore/page/EventSource.h index f2d1c1256..60501f3b2 100644 --- a/Source/WebCore/page/EventSource.h +++ b/Source/WebCore/page/EventSource.h @@ -29,99 +29,110 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef EventSource_h -#define EventSource_h +#pragma once #include "ActiveDOMObject.h" #include "EventTarget.h" +#include "ExceptionOr.h" #include "URL.h" #include "ThreadableLoaderClient.h" #include "Timer.h" -#include <wtf/RefPtr.h> #include <wtf/Vector.h> namespace WebCore { -class Dictionary; class MessageEvent; -class ResourceResponse; class TextResourceDecoder; class ThreadableLoader; class EventSource final : public RefCounted<EventSource>, public EventTargetWithInlineData, private ThreadableLoaderClient, public ActiveDOMObject { WTF_MAKE_FAST_ALLOCATED; public: - static PassRefPtr<EventSource> create(ScriptExecutionContext&, const String& url, const Dictionary&, ExceptionCode&); + struct Init { + bool withCredentials; + }; + static ExceptionOr<Ref<EventSource>> create(ScriptExecutionContext&, const String& url, const Init&); virtual ~EventSource(); - static const unsigned long long defaultReconnectDelay; - - String url() const; + const String& url() const; bool withCredentials() const; - typedef short State; + using State = short; static const State CONNECTING = 0; static const State OPEN = 1; static const State CLOSED = 2; State readyState() const; - DEFINE_ATTRIBUTE_EVENT_LISTENER(open); - DEFINE_ATTRIBUTE_EVENT_LISTENER(message); - DEFINE_ATTRIBUTE_EVENT_LISTENER(error); - void close(); - using RefCounted<EventSource>::ref; - using RefCounted<EventSource>::deref; - - virtual EventTargetInterface eventTargetInterface() const override { return EventSourceEventTargetInterfaceType; } - virtual ScriptExecutionContext* scriptExecutionContext() const override { return ActiveDOMObject::scriptExecutionContext(); } + using RefCounted::ref; + using RefCounted::deref; private: - EventSource(ScriptExecutionContext&, const URL&, const Dictionary&); + EventSource(ScriptExecutionContext&, const URL&, const Init&); - virtual void refEventTarget() override { ref(); } - virtual void derefEventTarget() override { deref(); } + EventTargetInterface eventTargetInterface() const final { return EventSourceEventTargetInterfaceType; } + ScriptExecutionContext* scriptExecutionContext() const final { return ActiveDOMObject::scriptExecutionContext(); } - virtual void didReceiveResponse(unsigned long, const ResourceResponse&) override; - virtual void didReceiveData(const char*, int) override; - virtual void didFinishLoading(unsigned long, double) override; - virtual void didFail(const ResourceError&) override; - virtual void didFailAccessControlCheck(const ResourceError&) override; - virtual void didFailRedirectCheck() override; + void refEventTarget() final { ref(); } + void derefEventTarget() final { deref(); } - virtual void stop() override; + // ThreadableLoaderClient + void didReceiveResponse(unsigned long, const ResourceResponse&) final; + void didReceiveData(const char*, int) final; + void didFinishLoading(unsigned long, double) final; + void didFail(const ResourceError&) final; + + void stop() final; + const char* activeDOMObjectName() const final; + bool canSuspendForDocumentSuspension() const final; void connect(); void networkRequestEnded(); void scheduleInitialConnect(); void scheduleReconnect(); - void connectTimerFired(Timer<EventSource>&); void abortConnectionAttempt(); void parseEventStream(); - void parseEventStreamLine(unsigned pos, int fieldLength, int lineLength); - PassRefPtr<MessageEvent> createMessageEvent(); + void parseEventStreamLine(unsigned position, std::optional<unsigned> fieldLength, unsigned lineLength); + void dispatchMessageEvent(); + + bool responseIsValid(const ResourceResponse&) const; + + static const uint64_t defaultReconnectDelay; URL m_url; bool m_withCredentials; - State m_state; + State m_state { CONNECTING }; - RefPtr<TextResourceDecoder> m_decoder; + Ref<TextResourceDecoder> m_decoder; RefPtr<ThreadableLoader> m_loader; - Timer<EventSource> m_connectTimer; - Vector<UChar> m_receiveBuf; - bool m_discardTrailingNewline; - bool m_requestInFlight; + Timer m_connectTimer; + Vector<UChar> m_receiveBuffer; + bool m_discardTrailingNewline { false }; + bool m_requestInFlight { false }; - String m_eventName; + AtomicString m_eventName; Vector<UChar> m_data; String m_currentlyParsedEventId; String m_lastEventId; - unsigned long long m_reconnectDelay; + uint64_t m_reconnectDelay { defaultReconnectDelay }; String m_eventStreamOrigin; }; -} // namespace WebCore +inline const String& EventSource::url() const +{ + return m_url.string(); +} + +inline bool EventSource::withCredentials() const +{ + return m_withCredentials; +} -#endif // EventSource_h +inline EventSource::State EventSource::readyState() const +{ + return m_state; +} + +} // namespace WebCore |