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_DebuggerNotification_h
8 #define mozilla_dom_DebuggerNotification_h
10 #include "DebuggerNotificationManager.h"
11 #include "mozilla/dom/DebuggerNotificationBinding.h"
12 #include "nsIGlobalObject.h"
13 #include "nsISupports.h"
14 #include "nsWrapperCache.h"
16 namespace mozilla::dom
{
18 class DebuggerNotification
: public nsISupports
, public nsWrapperCache
{
20 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
21 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(DebuggerNotification
)
23 DebuggerNotification(nsIGlobalObject
* aDebuggeeGlobal
,
24 DebuggerNotificationType aType
,
25 nsIGlobalObject
* aOwnerGlobal
= nullptr)
27 mDebuggeeGlobal(aDebuggeeGlobal
),
28 mOwnerGlobal(aOwnerGlobal
) {}
30 nsIGlobalObject
* GetParentObject() const {
31 MOZ_ASSERT(mOwnerGlobal
,
32 "Notification must be cloned into an observer global before "
37 DebuggerNotificationType
Type() const { return mType
; }
39 void GetGlobal(JSContext
* aCx
, JS::MutableHandle
<JSObject
*> aResult
) {
40 aResult
.set(mDebuggeeGlobal
->GetGlobalJSObject());
43 virtual already_AddRefed
<DebuggerNotification
> CloneInto(
44 nsIGlobalObject
* aNewOwner
) const;
47 virtual JSObject
* WrapObject(JSContext
* aCx
,
48 JS::Handle
<JSObject
*> aGivenProto
) override
;
51 virtual ~DebuggerNotification() = default;
53 DebuggerNotificationType mType
;
54 nsCOMPtr
<nsIGlobalObject
> mDebuggeeGlobal
;
57 nsCOMPtr
<nsIGlobalObject
> mOwnerGlobal
;
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
);
68 } // namespace mozilla::dom
70 #endif // mozilla_dom_DebuggerNotification_h