Bug 1550519 - Show a translucent parent highlight when a subgrid is highlighted....
[gecko.git] / dom / base / EventSource.h
bloba9f89cfe7adc2a0bf3e91fa84b9f78d672278d99
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /*
8 * This implementation has support only for http requests. It is because the
9 * spec has defined event streams only for http. HTTP is required because
10 * this implementation uses some http headers: "Last-Event-ID", "Cache-Control"
11 * and "Accept".
14 #ifndef mozilla_dom_EventSource_h
15 #define mozilla_dom_EventSource_h
17 #include "mozilla/Attributes.h"
18 #include "mozilla/DOMEventTargetHelper.h"
19 #include "nsIObserver.h"
20 #include "nsIStreamListener.h"
21 #include "nsIChannelEventSink.h"
22 #include "nsIInterfaceRequestor.h"
23 #include "nsITimer.h"
24 #include "nsIHttpChannel.h"
25 #include "nsDeque.h"
27 class nsIGlobalObject;
28 class nsICookieSettings;
30 namespace mozilla {
32 class ErrorResult;
34 namespace dom {
36 struct EventSourceInit;
38 class EventSourceImpl;
40 class EventSource final : public DOMEventTargetHelper {
41 friend class EventSourceImpl;
43 public:
44 NS_DECL_ISUPPORTS_INHERITED
45 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(EventSource, DOMEventTargetHelper)
46 virtual bool IsCertainlyAliveForCC() const override;
48 // EventTarget
49 void DisconnectFromOwner() override {
50 DOMEventTargetHelper::DisconnectFromOwner();
51 Close();
54 JSObject* WrapObject(JSContext* aCx,
55 JS::Handle<JSObject*> aGivenProto) override;
57 // WebIDL
58 static already_AddRefed<EventSource> Constructor(
59 const GlobalObject& aGlobal, const nsAString& aURL,
60 const EventSourceInit& aEventSourceInitDict, ErrorResult& aRv);
62 void GetUrl(nsAString& aURL) const {
63 AssertIsOnTargetThread();
64 aURL = mOriginalURL;
67 bool WithCredentials() const {
68 AssertIsOnTargetThread();
69 return mWithCredentials;
72 uint16_t ReadyState() const {
73 AssertIsOnTargetThread();
74 return mReadyState;
77 IMPL_EVENT_HANDLER(open)
78 IMPL_EVENT_HANDLER(message)
79 IMPL_EVENT_HANDLER(error)
81 void Close();
83 private:
84 EventSource(nsIGlobalObject* aGlobal, nsICookieSettings* aCookieSettings,
85 bool aWithCredentials);
86 virtual ~EventSource();
87 // prevent bad usage
88 EventSource(const EventSource& x) = delete;
89 EventSource& operator=(const EventSource& x) = delete;
91 void AssertIsOnTargetThread() const {
92 MOZ_ASSERT(NS_IsMainThread() == mIsMainThread);
95 nsresult CreateAndDispatchSimpleEvent(const nsAString& aName);
97 // Raw pointer because this EventSourceImpl is created, managed and destroyed
98 // by EventSource.
99 EventSourceImpl* mImpl;
100 nsString mOriginalURL;
101 uint16_t mReadyState;
102 bool mWithCredentials;
103 bool mIsMainThread;
104 // This is used to keep EventSourceImpl instance when there is a connection.
105 bool mKeepingAlive;
107 void UpdateMustKeepAlive();
108 void UpdateDontKeepAlive();
111 } // namespace dom
112 } // namespace mozilla
114 #endif // mozilla_dom_EventSource_h