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_EventListenerService_h_
8 #define mozilla_EventListenerService_h_
11 #include "mozilla/Attributes.h"
12 #include "nsCycleCollectionParticipant.h"
13 #include "EventListenerManager.h"
14 #include "nsIEventListenerService.h"
16 #include "nsTObserverArray.h"
17 #include "nsTHashMap.h"
18 #include "nsGkAtoms.h"
20 class nsIMutableArray
;
30 class EventListenerChange final
: public nsIEventListenerChange
{
32 explicit EventListenerChange(dom::EventTarget
* aTarget
);
34 void AddChangedListenerName(nsAtom
* aEventName
);
37 NS_DECL_NSIEVENTLISTENERCHANGE
40 virtual ~EventListenerChange();
41 nsCOMPtr
<dom::EventTarget
> mTarget
;
42 nsTArray
<RefPtr
<nsAtom
>> mChangedListenerNames
;
45 class EventListenerInfo final
: public nsIEventListenerInfo
{
47 EventListenerInfo(EventListenerManager
* aListenerManager
,
48 const nsAString
& aType
,
49 JS::Handle
<JSObject
*> aScriptedListener
,
50 JS::Handle
<JSObject
*> aScriptedListenerGlobal
,
51 bool aCapturing
, bool aAllowsUntrusted
,
52 bool aInSystemEventGroup
, bool aIsHandler
);
54 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
55 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(EventListenerInfo
)
56 NS_DECL_NSIEVENTLISTENERINFO
59 virtual ~EventListenerInfo();
61 bool GetJSVal(JSContext
* aCx
, Maybe
<JSAutoRealm
>& aAr
,
62 JS::MutableHandle
<JS::Value
> aJSVal
);
64 RefPtr
<EventListenerManager
> mListenerManager
;
66 JS::Heap
<JSObject
*> mScriptedListener
; // May be null.
67 // mScriptedListener may be a cross-compartment wrapper so we cannot use it
68 // with JSAutoRealm because CCWs are not associated with a single realm. We
69 // use this global instead (must be same-compartment with mScriptedListener
70 // and must be non-null if mScriptedListener is non-null).
71 JS::Heap
<JSObject
*> mScriptedListenerGlobal
;
73 bool mAllowsUntrusted
;
74 bool mInSystemEventGroup
;
78 class EventListenerService final
: public nsIEventListenerService
{
79 ~EventListenerService();
82 EventListenerService();
84 NS_DECL_NSIEVENTLISTENERSERVICE
86 static void NotifyAboutMainThreadListenerChange(dom::EventTarget
* aTarget
,
89 sInstance
->NotifyAboutMainThreadListenerChangeInternal(aTarget
, aName
);
93 void NotifyPendingChanges();
96 void NotifyAboutMainThreadListenerChangeInternal(dom::EventTarget
* aTarget
,
98 nsTObserverArray
<nsCOMPtr
<nsIListenerChangeListener
>> mChangeListeners
;
99 nsCOMPtr
<nsIMutableArray
> mPendingListenerChanges
;
100 nsTHashMap
<nsISupportsHashKey
, RefPtr
<EventListenerChange
>>
101 mPendingListenerChangesSet
;
103 static EventListenerService
* sInstance
;
106 } // namespace mozilla
108 #endif // mozilla_EventListenerService_h_