Bug 1806664 - Use python toolchain tasks to build firefox r=glandium,taskgraph-review...
[gecko.git] / dom / debugger / DebuggerNotification.h
bloba0d443c27c9ca4aa2599b9665179edf0a162c572
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 {
19 public:
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)
26 : mType(aType),
27 mDebuggeeGlobal(aDebuggeeGlobal),
28 mOwnerGlobal(aOwnerGlobal) {}
30 nsIGlobalObject* GetParentObject() const {
31 MOZ_ASSERT(mOwnerGlobal,
32 "Notification must be cloned into an observer global before "
33 "being wrapped");
34 return mOwnerGlobal;
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;
46 // nsWrapperCache
47 virtual JSObject* WrapObject(JSContext* aCx,
48 JS::Handle<JSObject*> aGivenProto) override;
50 protected:
51 virtual ~DebuggerNotification() = default;
53 DebuggerNotificationType mType;
54 nsCOMPtr<nsIGlobalObject> mDebuggeeGlobal;
56 private:
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