OLD | NEW |
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 14 matching lines...) Expand all Loading... |
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
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/ContextLifecycleObserver.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 "core/page/EventSourceParser.h" |
40 #include "platform/Timer.h" | 40 #include "platform/Timer.h" |
41 #include "platform/heap/Handle.h" | 41 #include "platform/heap/Handle.h" |
42 #include "platform/weborigin/KURL.h" | 42 #include "platform/weborigin/KURL.h" |
43 #include "wtf/Forward.h" | 43 #include "wtf/Forward.h" |
44 #include "wtf/RefPtr.h" | 44 #include "wtf/RefPtr.h" |
45 | 45 |
46 namespace blink { | 46 namespace blink { |
47 | 47 |
48 class EventSourceInit; | 48 class EventSourceInit; |
49 class ExceptionState; | 49 class ExceptionState; |
50 class ResourceResponse; | 50 class ResourceResponse; |
51 | 51 |
52 class CORE_EXPORT EventSource final : public RefCountedGarbageCollectedEventTarg
etWithInlineData<EventSource>, private ThreadableLoaderClient, public ActiveDOMO
bject, public EventSourceParser::Client { | 52 class CORE_EXPORT EventSource final : public RefCountedGarbageCollectedEventTarg
etWithInlineData<EventSource>, private ThreadableLoaderClient, public ContextLif
ecycleObserver, public EventSourceParser::Client { |
53 DEFINE_WRAPPERTYPEINFO(); | 53 DEFINE_WRAPPERTYPEINFO(); |
54 REFCOUNTED_GARBAGE_COLLECTED_EVENT_TARGET(EventSource); | 54 REFCOUNTED_GARBAGE_COLLECTED_EVENT_TARGET(EventSource); |
55 USING_GARBAGE_COLLECTED_MIXIN(EventSource); | 55 USING_GARBAGE_COLLECTED_MIXIN(EventSource); |
56 public: | 56 public: |
57 static EventSource* create(ExecutionContext*, const String& url, const Event
SourceInit&, ExceptionState&); | 57 static EventSource* create(ExecutionContext*, const String& url, const Event
SourceInit&, ExceptionState&); |
58 ~EventSource() override; | 58 ~EventSource() override; |
59 | 59 |
60 static const unsigned long long defaultReconnectDelay; | 60 static const unsigned long long defaultReconnectDelay; |
61 | 61 |
62 String url() const; | 62 String url() const; |
63 bool withCredentials() const; | 63 bool withCredentials() const; |
64 | 64 |
65 enum State : short { | 65 enum State : short { |
66 CONNECTING = 0, | 66 CONNECTING = 0, |
67 OPEN = 1, | 67 OPEN = 1, |
68 CLOSED = 2 | 68 CLOSED = 2 |
69 }; | 69 }; |
70 | 70 |
71 State readyState() const; | 71 State readyState() const; |
72 | 72 |
73 DEFINE_ATTRIBUTE_EVENT_LISTENER(open); | 73 DEFINE_ATTRIBUTE_EVENT_LISTENER(open); |
74 DEFINE_ATTRIBUTE_EVENT_LISTENER(message); | 74 DEFINE_ATTRIBUTE_EVENT_LISTENER(message); |
75 DEFINE_ATTRIBUTE_EVENT_LISTENER(error); | 75 DEFINE_ATTRIBUTE_EVENT_LISTENER(error); |
76 | 76 |
77 void close(); | 77 void close(); |
78 | 78 |
79 const AtomicString& interfaceName() const override; | 79 const AtomicString& interfaceName() const override; |
80 ExecutionContext* executionContext() const override; | 80 ExecutionContext* executionContext() const override; |
81 | 81 |
82 // ActiveDOMObject | 82 // Note: We don't need to override suspend() because it is noop since |
83 // | 83 // ScopedPageLoadDeferrer calls Page::setDefersLoading() and it defers |
84 // Note: suspend() is noop since ScopedPageLoadDeferrer calls | 84 // delivery of events from the loader, and therefore the methods of this |
85 // Page::setDefersLoading() and it defers delivery of events from the | 85 // class for receiving asynchronous events from the loader won't be invoked. |
86 // loader, and therefore the methods of this class for receiving | 86 void contextDestroyed() override; |
87 // asynchronous events from the loader won't be invoked. | |
88 void stop() override; | |
89 | 87 |
90 bool hasPendingActivity() const override; | 88 bool hasPendingActivity() const override; |
91 | 89 |
92 DECLARE_VIRTUAL_TRACE(); | 90 DECLARE_VIRTUAL_TRACE(); |
93 | 91 |
94 private: | 92 private: |
95 EventSource(ExecutionContext*, const KURL&, const EventSourceInit&); | 93 EventSource(ExecutionContext*, const KURL&, const EventSourceInit&); |
96 | 94 |
97 void didReceiveResponse(unsigned long, const ResourceResponse&, PassOwnPtr<W
ebDataConsumerHandle>) override; | 95 void didReceiveResponse(unsigned long, const ResourceResponse&, PassOwnPtr<W
ebDataConsumerHandle>) override; |
98 void didReceiveData(const char*, unsigned) override; | 96 void didReceiveData(const char*, unsigned) override; |
(...skipping 20 matching lines...) Expand all Loading... |
119 RefPtr<ThreadableLoader> m_loader; | 117 RefPtr<ThreadableLoader> m_loader; |
120 Timer<EventSource> m_connectTimer; | 118 Timer<EventSource> m_connectTimer; |
121 | 119 |
122 unsigned long long m_reconnectDelay; | 120 unsigned long long m_reconnectDelay; |
123 String m_eventStreamOrigin; | 121 String m_eventStreamOrigin; |
124 }; | 122 }; |
125 | 123 |
126 } // namespace blink | 124 } // namespace blink |
127 | 125 |
128 #endif // EventSource_h | 126 #endif // EventSource_h |
OLD | NEW |