DebuggerNotification.h (2305B)
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_DebuggerNotification_h 8 #define mozilla_dom_DebuggerNotification_h 9 10 #include "DebuggerNotificationManager.h" 11 #include "mozilla/dom/DebuggerNotificationBinding.h" 12 #include "nsIGlobalObject.h" 13 #include "nsISupports.h" 14 #include "nsWrapperCache.h" 15 16 namespace mozilla::dom { 17 18 class DebuggerNotification : public nsISupports, public nsWrapperCache { 19 public: 20 NS_DECL_CYCLE_COLLECTING_ISUPPORTS 21 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(DebuggerNotification) 22 23 DebuggerNotification(nsIGlobalObject* aDebuggeeGlobal, 24 DebuggerNotificationType aType, 25 nsIGlobalObject* aOwnerGlobal = nullptr) 26 : mType(aType), 27 mDebuggeeGlobal(aDebuggeeGlobal), 28 mOwnerGlobal(aOwnerGlobal) {} 29 30 nsIGlobalObject* GetParentObject() const { 31 MOZ_ASSERT(mOwnerGlobal, 32 "Notification must be cloned into an observer global before " 33 "being wrapped"); 34 return mOwnerGlobal; 35 } 36 37 DebuggerNotificationType Type() const { return mType; } 38 39 void GetGlobal(JSContext* aCx, JS::MutableHandle<JSObject*> aResult) { 40 aResult.set(mDebuggeeGlobal->GetGlobalJSObject()); 41 } 42 43 virtual already_AddRefed<DebuggerNotification> CloneInto( 44 nsIGlobalObject* aNewOwner) const; 45 46 // nsWrapperCache 47 virtual JSObject* WrapObject(JSContext* aCx, 48 JS::Handle<JSObject*> aGivenProto) override; 49 50 protected: 51 virtual ~DebuggerNotification() = default; 52 53 DebuggerNotificationType mType; 54 nsCOMPtr<nsIGlobalObject> mDebuggeeGlobal; 55 56 private: 57 nsCOMPtr<nsIGlobalObject> mOwnerGlobal; 58 }; 59 60 MOZ_CAN_RUN_SCRIPT inline void DebuggerNotificationDispatch( 61 nsIGlobalObject* aDebuggeeGlobal, DebuggerNotificationType aType) { 62 auto manager = DebuggerNotificationManager::ForDispatch(aDebuggeeGlobal); 63 if (MOZ_UNLIKELY(manager)) { 64 manager->Dispatch<DebuggerNotification>(aType); 65 } 66 } 67 68 } // namespace mozilla::dom 69 70 #endif // mozilla_dom_DebuggerNotification_h