EventCallbackDebuggerNotification.h (3487B)
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_EventCallbackDebuggerNotification_h 8 #define mozilla_dom_EventCallbackDebuggerNotification_h 9 10 #include "CallbackDebuggerNotification.h" 11 #include "DebuggerNotificationManager.h" 12 #include "mozilla/RefPtr.h" 13 #include "mozilla/dom/Event.h" 14 15 namespace mozilla::dom { 16 17 class EventCallbackDebuggerNotification : public CallbackDebuggerNotification { 18 public: 19 NS_DECL_ISUPPORTS_INHERITED 20 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(EventCallbackDebuggerNotification, 21 CallbackDebuggerNotification) 22 23 EventCallbackDebuggerNotification( 24 nsIGlobalObject* aDebuggeeGlobal, DebuggerNotificationType aType, 25 Event* aEvent, EventCallbackDebuggerNotificationType aTargetType, 26 CallbackDebuggerNotificationPhase aPhase, 27 nsIGlobalObject* aOwnerGlobal = nullptr) 28 : CallbackDebuggerNotification(aDebuggeeGlobal, aType, aPhase, 29 aOwnerGlobal), 30 mEvent(aEvent), 31 mTargetType(aTargetType) {} 32 33 // nsWrapperCache 34 virtual JSObject* WrapObject(JSContext* aCx, 35 JS::Handle<JSObject*> aGivenProto) override; 36 37 already_AddRefed<DebuggerNotification> CloneInto( 38 nsIGlobalObject* aNewOwner) const override; 39 40 mozilla::dom::Event* Event() const { return mEvent; } 41 EventCallbackDebuggerNotificationType TargetType() const { 42 return mTargetType; 43 } 44 45 private: 46 ~EventCallbackDebuggerNotification() = default; 47 48 RefPtr<mozilla::dom::Event> mEvent; 49 EventCallbackDebuggerNotificationType mTargetType; 50 }; 51 52 class MOZ_RAII EventCallbackDebuggerNotificationGuard final { 53 public: 54 MOZ_CAN_RUN_SCRIPT_BOUNDARY explicit EventCallbackDebuggerNotificationGuard( 55 mozilla::dom::EventTarget* aEventTarget, mozilla::dom::Event* aEvent) 56 : mDebuggeeGlobal(aEventTarget ? aEventTarget->GetOwnerGlobal() 57 : nullptr), 58 mEventTarget(aEventTarget), 59 mEvent(aEvent) { 60 Dispatch(CallbackDebuggerNotificationPhase::Pre); 61 } 62 EventCallbackDebuggerNotificationGuard( 63 const EventCallbackDebuggerNotificationGuard&) = delete; 64 EventCallbackDebuggerNotificationGuard( 65 EventCallbackDebuggerNotificationGuard&&) = delete; 66 EventCallbackDebuggerNotificationGuard& operator=( 67 const EventCallbackDebuggerNotificationGuard&) = delete; 68 EventCallbackDebuggerNotificationGuard& operator=( 69 EventCallbackDebuggerNotificationGuard&&) = delete; 70 71 MOZ_CAN_RUN_SCRIPT_BOUNDARY ~EventCallbackDebuggerNotificationGuard() { 72 Dispatch(CallbackDebuggerNotificationPhase::Post); 73 } 74 75 private: 76 MOZ_CAN_RUN_SCRIPT void Dispatch(CallbackDebuggerNotificationPhase aPhase) { 77 auto manager = DebuggerNotificationManager::ForDispatch(mDebuggeeGlobal); 78 DispatchToManager(manager, aPhase); 79 } 80 81 MOZ_CAN_RUN_SCRIPT void DispatchToManager( 82 const RefPtr<DebuggerNotificationManager>& aManager, 83 CallbackDebuggerNotificationPhase aPhase); 84 85 nsIGlobalObject* mDebuggeeGlobal; 86 mozilla::dom::EventTarget* mEventTarget; 87 mozilla::dom::Event* mEvent; 88 }; 89 90 } // namespace mozilla::dom 91 92 #endif // mozilla_dom_EventCallbackDebuggerNotification_h