EventCallbackDebuggerNotification.cpp (2955B)
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 #include "EventCallbackDebuggerNotification.h" 8 9 #include "DebuggerNotificationManager.h" 10 #include "mozilla/CycleCollectedJSContext.h" 11 #include "mozilla/dom/EventTarget.h" 12 #include "mozilla/dom/Worker.h" 13 #include "mozilla/dom/XMLHttpRequestEventTarget.h" 14 #include "nsIGlobalObject.h" 15 #include "nsINode.h" 16 #include "nsQueryObject.h" 17 18 namespace mozilla::dom { 19 20 NS_IMPL_CYCLE_COLLECTION_INHERITED(EventCallbackDebuggerNotification, 21 CallbackDebuggerNotification, mEvent) 22 23 NS_IMPL_ADDREF_INHERITED(EventCallbackDebuggerNotification, 24 CallbackDebuggerNotification) 25 NS_IMPL_RELEASE_INHERITED(EventCallbackDebuggerNotification, 26 CallbackDebuggerNotification) 27 28 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(EventCallbackDebuggerNotification) 29 NS_INTERFACE_MAP_END_INHERITING(CallbackDebuggerNotification) 30 31 JSObject* EventCallbackDebuggerNotification::WrapObject( 32 JSContext* aCx, JS::Handle<JSObject*> aGivenProto) { 33 return EventCallbackDebuggerNotification_Binding::Wrap(aCx, this, 34 aGivenProto); 35 } 36 37 already_AddRefed<DebuggerNotification> 38 EventCallbackDebuggerNotification::CloneInto(nsIGlobalObject* aNewOwner) const { 39 RefPtr<EventCallbackDebuggerNotification> notification( 40 new EventCallbackDebuggerNotification(mDebuggeeGlobal, mType, mEvent, 41 mTargetType, mPhase, aNewOwner)); 42 return notification.forget(); 43 } 44 45 void EventCallbackDebuggerNotificationGuard::DispatchToManager( 46 const RefPtr<DebuggerNotificationManager>& aManager, 47 CallbackDebuggerNotificationPhase aPhase) { 48 if (!mEventTarget) { 49 MOZ_ASSERT(false, "target should exist"); 50 return; 51 } 52 53 Maybe<EventCallbackDebuggerNotificationType> notificationType( 54 mEventTarget->GetDebuggerNotificationType()); 55 56 if (notificationType) { 57 #ifdef MOZ_EXECUTION_TRACING 58 CycleCollectedJSContext* ccjcx = CycleCollectedJSContext::Get(); 59 if (ccjcx) { 60 nsAutoString eventType; 61 mEvent->GetType(eventType); 62 if (aPhase == CallbackDebuggerNotificationPhase::Pre) { 63 JS_TracerEnterLabelTwoByte(ccjcx->Context(), eventType.get()); 64 } else { 65 JS_TracerLeaveLabelTwoByte(ccjcx->Context(), eventType.get()); 66 } 67 } 68 #endif 69 if (MOZ_UNLIKELY(aManager)) { 70 aManager->Dispatch<EventCallbackDebuggerNotification>( 71 DebuggerNotificationType::DomEvent, 72 // The DOM event will always be live during event dispatch. 73 MOZ_KnownLive(mEvent), *notificationType, aPhase); 74 } 75 } 76 } 77 78 } // namespace mozilla::dom