DebuggerNotificationObserver.h (2082B)
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/. */ 6 7 #ifndef mozilla_dom_DebuggerNotificationObserver_h 8 #define mozilla_dom_DebuggerNotificationObserver_h 9 10 #include "DebuggerNotificationManager.h" 11 #include "mozilla/RefPtr.h" 12 #include "mozilla/dom/DebuggerNotificationObserverBinding.h" 13 #include "nsTObserverArray.h" 14 #include "nsWrapperCache.h" 15 16 class nsIGlobalObject; 17 18 namespace mozilla::dom { 19 20 class DebuggerNotification; 21 22 class DebuggerNotificationObserver final : public nsISupports, 23 public nsWrapperCache { 24 public: 25 NS_DECL_CYCLE_COLLECTING_ISUPPORTS_FINAL 26 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(DebuggerNotificationObserver) 27 28 static already_AddRefed<DebuggerNotificationObserver> Constructor( 29 GlobalObject& aGlobal, ErrorResult& aRv); 30 31 nsIGlobalObject* GetParentObject() const { return mOwnerGlobal; } 32 33 // nsWrapperCache 34 virtual JSObject* WrapObject(JSContext* aCx, 35 JS::Handle<JSObject*> aGivenProto) override; 36 37 bool Connect(JSContext* aCx, JS::Handle<JSObject*> aDebuggeeGlobal, 38 ErrorResult& aRv); 39 bool Disconnect(JSContext* aCx, JS::Handle<JSObject*> aDebuggeeGlobal, 40 ErrorResult& aRv); 41 42 bool AddListener(DebuggerNotificationCallback& aHandlerFn); 43 bool RemoveListener(DebuggerNotificationCallback& aHandlerFn); 44 45 bool HasListeners(); 46 47 MOZ_CAN_RUN_SCRIPT void NotifyListeners(DebuggerNotification* aNotification); 48 49 private: 50 explicit DebuggerNotificationObserver(nsIGlobalObject* aOwnerGlobal); 51 ~DebuggerNotificationObserver() = default; 52 53 nsTObserverArray<RefPtr<DebuggerNotificationCallback>> 54 mEventListenerCallbacks; 55 nsCOMPtr<nsIGlobalObject> mOwnerGlobal; 56 }; 57 58 } // namespace mozilla::dom 59 60 #endif // mozilla_dom_DebuggerNotificationObserver_h