Bug 1890277: part 2) Add `require-trusted-types-for` directive to CSP parser, guarded...
[gecko.git] / dom / base / EventSourceEventService.h
blobe4e0adec881b5c10403de9ee409f9867dffeae30
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 #ifndef mozilla_dom_EventSourceEventService_h
8 #define mozilla_dom_EventSourceEventService_h
10 #include "mozilla/AlreadyAddRefed.h"
11 #include "mozilla/Atomics.h"
12 #include "nsIEventSourceEventService.h"
13 #include "nsCOMPtr.h"
14 #include "nsClassHashtable.h"
15 #include "nsHashKeys.h"
16 #include "nsIObserver.h"
17 #include "nsISupportsImpl.h"
18 #include "nsTArray.h"
20 namespace mozilla::dom {
22 class EventSourceEventService final : public nsIEventSourceEventService,
23 public nsIObserver {
24 friend class EventSourceBaseRunnable;
26 public:
27 NS_DECL_THREADSAFE_ISUPPORTS
28 NS_DECL_NSIOBSERVER
29 NS_DECL_NSIEVENTSOURCEEVENTSERVICE
31 static already_AddRefed<EventSourceEventService> GetOrCreate();
33 void EventSourceConnectionOpened(uint64_t aHttpChannelId,
34 uint64_t aInnerWindowID);
36 void EventSourceConnectionClosed(uint64_t aHttpChannelId,
37 uint64_t aInnerWindowID);
39 void EventReceived(uint64_t aHttpChannelId, uint64_t aInnerWindowID,
40 const nsAString& aEventName, const nsAString& aLastEventID,
41 const nsAString& aData, uint32_t aRetry,
42 DOMHighResTimeStamp aTimeStamp);
44 private:
45 EventSourceEventService();
46 ~EventSourceEventService();
48 bool HasListeners() const;
49 void Shutdown();
51 using EventSourceListeners = nsTArray<nsCOMPtr<nsIEventSourceEventListener>>;
53 struct WindowListener {
54 EventSourceListeners mListeners;
57 void GetListeners(uint64_t aInnerWindowID,
58 EventSourceListeners& aListeners) const;
60 // Used only on the main-thread.
61 nsClassHashtable<nsUint64HashKey, WindowListener> mWindows;
63 Atomic<uint64_t> mCountListeners;
66 } // namespace mozilla::dom
68 /**
69 * Casting EventSourceEventService to nsISupports is ambiguous.
70 * This method handles that.
72 inline nsISupports* ToSupports(mozilla::dom::EventSourceEventService* p) {
73 return NS_ISUPPORTS_CAST(nsIEventSourceEventService*, p);
76 #endif // mozilla_dom_EventSourceEventService_h