Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(511)

Side by Side Diff: third_party/WebKit/Source/core/page/EventSource.h

Issue 1642563002: Introduce EventSourceParser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@event-source-retry-fix
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009, 2012 Ericsson AB. All rights reserved. 2 * Copyright (C) 2009, 2012 Ericsson AB. All rights reserved.
3 * Copyright (C) 2010 Apple Inc. All rights reserved. 3 * Copyright (C) 2010 Apple Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 18 matching lines...) Expand all
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32 #ifndef EventSource_h 32 #ifndef EventSource_h
33 #define EventSource_h 33 #define EventSource_h
34 34
35 #include "core/dom/ActiveDOMObject.h" 35 #include "core/dom/ActiveDOMObject.h"
36 #include "core/events/EventTarget.h" 36 #include "core/events/EventTarget.h"
37 #include "core/loader/ThreadableLoader.h" 37 #include "core/loader/ThreadableLoader.h"
38 #include "core/loader/ThreadableLoaderClient.h" 38 #include "core/loader/ThreadableLoaderClient.h"
39 #include "core/page/EventSourceParser.h"
39 #include "platform/Timer.h" 40 #include "platform/Timer.h"
40 #include "platform/heap/Handle.h" 41 #include "platform/heap/Handle.h"
41 #include "platform/weborigin/KURL.h" 42 #include "platform/weborigin/KURL.h"
43 #include "wtf/Forward.h"
42 #include "wtf/RefPtr.h" 44 #include "wtf/RefPtr.h"
43 #include "wtf/Vector.h"
44 45
45 namespace blink { 46 namespace blink {
46 47
47 class EventSourceInit; 48 class EventSourceInit;
48 class ExceptionState; 49 class ExceptionState;
49 class MessageEvent;
50 class ResourceResponse; 50 class ResourceResponse;
51 class TextResourceDecoder;
52 51
53 class CORE_EXPORT EventSource final : public RefCountedGarbageCollectedEventTarg etWithInlineData<EventSource>, private ThreadableLoaderClient, public ActiveDOMO bject { 52 class CORE_EXPORT EventSource final : public RefCountedGarbageCollectedEventTarg etWithInlineData<EventSource>, private ThreadableLoaderClient, public ActiveDOMO bject, public EventSourceParser::Client {
54 DEFINE_WRAPPERTYPEINFO(); 53 DEFINE_WRAPPERTYPEINFO();
55 REFCOUNTED_GARBAGE_COLLECTED_EVENT_TARGET(EventSource); 54 REFCOUNTED_GARBAGE_COLLECTED_EVENT_TARGET(EventSource);
56 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(EventSource); 55 USING_GARBAGE_COLLECTED_MIXIN(EventSource);
57 public: 56 public:
58 static EventSource* create(ExecutionContext*, const String& url, const Event SourceInit&, ExceptionState&); 57 static EventSource* create(ExecutionContext*, const String& url, const Event SourceInit&, ExceptionState&);
59 ~EventSource() override; 58 ~EventSource() override;
60 59
61 static const unsigned long long defaultReconnectDelay; 60 static const unsigned long long defaultReconnectDelay;
62 61
63 String url() const; 62 String url() const;
64 bool withCredentials() const; 63 bool withCredentials() const;
65 64
66 enum State : unsigned short { 65 enum State : unsigned short {
(...skipping 18 matching lines...) Expand all
85 // Note: suspend() is noop since ScopedPageLoadDeferrer calls 84 // Note: suspend() is noop since ScopedPageLoadDeferrer calls
86 // Page::setDefersLoading() and it defers delivery of events from the 85 // Page::setDefersLoading() and it defers delivery of events from the
87 // loader, and therefore the methods of this class for receiving 86 // loader, and therefore the methods of this class for receiving
88 // asynchronous events from the loader won't be invoked. 87 // asynchronous events from the loader won't be invoked.
89 void stop() override; 88 void stop() override;
90 89
91 bool hasPendingActivity() const override; 90 bool hasPendingActivity() const override;
92 91
93 DECLARE_VIRTUAL_TRACE(); 92 DECLARE_VIRTUAL_TRACE();
94 93
95 void setStateForTest(State state) { m_state = state; }
96 void setThreadableLoaderForTest(PassRefPtr<ThreadableLoader> loader) { m_loa der = loader; }
97 ThreadableLoaderClient* asThreadableLoaderClientForTest() { return this; }
98 unsigned long long reconnectDelayForTest() const { return m_reconnectDelay; }
99
100 private: 94 private:
101 EventSource(ExecutionContext*, const KURL&, const EventSourceInit&); 95 EventSource(ExecutionContext*, const KURL&, const EventSourceInit&);
102 96
103 void didReceiveResponse(unsigned long, const ResourceResponse&, PassOwnPtr<W ebDataConsumerHandle>) override; 97 void didReceiveResponse(unsigned long, const ResourceResponse&, PassOwnPtr<W ebDataConsumerHandle>) override;
104 void didReceiveData(const char*, unsigned) override; 98 void didReceiveData(const char*, unsigned) override;
105 void didFinishLoading(unsigned long, double) override; 99 void didFinishLoading(unsigned long, double) override;
106 void didFail(const ResourceError&) override; 100 void didFail(const ResourceError&) override;
107 void didFailAccessControlCheck(const ResourceError&) override; 101 void didFailAccessControlCheck(const ResourceError&) override;
108 void didFailRedirectCheck() override; 102 void didFailRedirectCheck() override;
109 103
104 void onMessageEvent(const AtomicString& event, const String& data, const Ato micString& id) override;
105 void onReconnectionTimeSet(unsigned long long reconnectionTime) override;
106
110 void scheduleInitialConnect(); 107 void scheduleInitialConnect();
111 void connect(); 108 void connect();
112 void networkRequestEnded(); 109 void networkRequestEnded();
113 void scheduleReconnect(); 110 void scheduleReconnect();
114 void connectTimerFired(Timer<EventSource>*); 111 void connectTimerFired(Timer<EventSource>*);
115 void abortConnectionAttempt(); 112 void abortConnectionAttempt();
116 void parseEventStream();
117 void parseEventStreamLine(unsigned pos, int fieldLength, int lineLength);
118 PassRefPtrWillBeRawPtr<MessageEvent> createMessageEvent();
119 113
120 KURL m_url; 114 KURL m_url;
121 bool m_withCredentials; 115 bool m_withCredentials;
122 State m_state; 116 State m_state;
123 117
124 OwnPtr<TextResourceDecoder> m_decoder; 118 Member<EventSourceParser> m_parser;
125 RefPtr<ThreadableLoader> m_loader; 119 RefPtr<ThreadableLoader> m_loader;
126 Timer<EventSource> m_connectTimer; 120 Timer<EventSource> m_connectTimer;
127 Vector<UChar> m_receiveBuf;
128 bool m_discardTrailingNewline;
129 121
130 AtomicString m_eventName;
131 Vector<UChar> m_data;
132 AtomicString m_currentlyParsedEventId;
133 AtomicString m_lastEventId;
134 unsigned long long m_reconnectDelay; 122 unsigned long long m_reconnectDelay;
135 String m_eventStreamOrigin; 123 String m_eventStreamOrigin;
136 }; 124 };
137 125
138 } // namespace blink 126 } // namespace blink
139 127
140 #endif // EventSource_h 128 #endif // EventSource_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698