no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / dom / debugger / DebuggerNotificationManager.h
blob6f46f777ae59034352c05a0fe583a2ce75b45356
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_DebuggerNotificationManager_h
8 #define mozilla_dom_DebuggerNotificationManager_h
10 #include "DebuggerNotificationObserver.h"
11 #include "nsCycleCollectionParticipant.h"
12 #include "nsIGlobalObject.h"
13 #include "nsISupports.h"
14 #include "nsTObserverArray.h"
16 namespace mozilla::dom {
18 class DebuggerNotification;
19 class DebuggerNotificationObserver;
21 class DebuggerNotificationManager final : public nsISupports {
22 public:
23 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
24 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DebuggerNotificationManager)
26 static RefPtr<DebuggerNotificationManager> ForDispatch(
27 nsIGlobalObject* aDebuggeeGlobal) {
28 if (MOZ_UNLIKELY(!aDebuggeeGlobal)) {
29 return nullptr;
31 auto managerPtr = aDebuggeeGlobal->GetExistingDebuggerNotificationManager();
32 if (MOZ_LIKELY(!managerPtr) || !managerPtr->HasListeners()) {
33 return nullptr;
36 return managerPtr;
39 explicit DebuggerNotificationManager(nsIGlobalObject* aDebuggeeGlobal)
40 : mDebuggeeGlobal(aDebuggeeGlobal) {}
42 bool Attach(DebuggerNotificationObserver* aObserver);
43 bool Detach(DebuggerNotificationObserver* aObserver);
45 bool HasListeners();
47 template <typename T, typename... Args>
48 MOZ_CAN_RUN_SCRIPT void Dispatch(Args... aArgs) {
49 RefPtr<DebuggerNotification> notification(new T(mDebuggeeGlobal, aArgs...));
50 NotifyListeners(notification);
53 private:
54 ~DebuggerNotificationManager() = default;
56 MOZ_CAN_RUN_SCRIPT void NotifyListeners(DebuggerNotification* aNotification);
58 nsCOMPtr<nsIGlobalObject> mDebuggeeGlobal;
59 nsTObserverArray<RefPtr<DebuggerNotificationObserver>> mNotificationObservers;
62 } // namespace mozilla::dom
64 #endif // mozilla_dom_DebuggerNotificationManager_h