2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2014-03-17 10:56:50 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_EventListenerService_h_
|
|
|
|
#define mozilla_EventListenerService_h_
|
|
|
|
|
|
|
|
#include "jsapi.h"
|
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsIDOMEventListener.h"
|
|
|
|
#include "nsIEventListenerService.h"
|
|
|
|
#include "nsString.h"
|
2015-04-28 23:10:05 +03:00
|
|
|
#include "nsTObserverArray.h"
|
|
|
|
#include "nsDataHashtable.h"
|
2015-07-17 18:07:37 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2015-04-28 23:10:05 +03:00
|
|
|
|
|
|
|
class nsIMutableArray;
|
2014-03-17 10:56:50 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
2015-04-28 23:10:05 +03:00
|
|
|
namespace dom {
|
|
|
|
class EventTarget;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
2014-03-17 10:56:50 +04:00
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
class Maybe;
|
|
|
|
|
2015-07-17 18:07:37 +03:00
|
|
|
class EventListenerChange final : public nsIEventListenerChange
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit EventListenerChange(dom::EventTarget* aTarget);
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
void AddChangedListenerName(nsAtom* aEventName);
|
2015-07-17 18:07:37 +03:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIEVENTLISTENERCHANGE
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~EventListenerChange();
|
|
|
|
nsCOMPtr<dom::EventTarget> mTarget;
|
2017-10-03 01:05:19 +03:00
|
|
|
nsTArray<RefPtr<nsAtom>> mChangedListenerNames;
|
2015-07-17 18:07:37 +03:00
|
|
|
};
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class EventListenerInfo final : public nsIEventListenerInfo
|
2014-03-17 10:56:50 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
EventListenerInfo(const nsAString& aType,
|
2018-04-12 07:03:44 +03:00
|
|
|
JS::Handle<JSObject*> aScriptedListener,
|
2018-08-07 15:06:44 +03:00
|
|
|
JS::Handle<JSObject*> aScriptedListenerGlobal,
|
2014-03-17 10:56:50 +04:00
|
|
|
bool aCapturing,
|
|
|
|
bool aAllowsUntrusted,
|
2018-04-12 07:03:44 +03:00
|
|
|
bool aInSystemEventGroup);
|
2014-03-17 10:56:50 +04:00
|
|
|
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2018-04-12 07:03:44 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(EventListenerInfo)
|
2014-03-17 10:56:50 +04:00
|
|
|
NS_DECL_NSIEVENTLISTENERINFO
|
|
|
|
|
|
|
|
protected:
|
2018-04-12 07:03:44 +03:00
|
|
|
virtual ~EventListenerInfo();
|
2014-06-23 23:56:07 +04:00
|
|
|
|
2014-03-17 10:56:50 +04:00
|
|
|
bool GetJSVal(JSContext* aCx,
|
2018-08-07 15:06:44 +03:00
|
|
|
Maybe<JSAutoRealm>& aAr,
|
2014-03-17 10:56:50 +04:00
|
|
|
JS::MutableHandle<JS::Value> aJSVal);
|
|
|
|
|
|
|
|
nsString mType;
|
2018-04-12 07:03:44 +03:00
|
|
|
JS::Heap<JSObject*> mScriptedListener; // May be null.
|
2018-08-07 15:06:44 +03:00
|
|
|
// mScriptedListener may be a cross-compartment wrapper so we cannot use it
|
|
|
|
// with JSAutoRealm because CCWs are not associated with a single realm. We
|
|
|
|
// use this global instead (must be same-compartment with mScriptedListener
|
|
|
|
// and must be non-null if mScriptedListener is non-null).
|
|
|
|
JS::Heap<JSObject*> mScriptedListenerGlobal;
|
2014-03-17 10:56:50 +04:00
|
|
|
bool mCapturing;
|
|
|
|
bool mAllowsUntrusted;
|
|
|
|
bool mInSystemEventGroup;
|
|
|
|
};
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class EventListenerService final : public nsIEventListenerService
|
2014-03-17 10:56:50 +04:00
|
|
|
{
|
2015-04-28 23:10:05 +03:00
|
|
|
~EventListenerService();
|
2014-03-17 10:56:50 +04:00
|
|
|
public:
|
2015-04-28 23:10:05 +03:00
|
|
|
EventListenerService();
|
2014-03-17 10:56:50 +04:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIEVENTLISTENERSERVICE
|
2015-04-28 23:10:05 +03:00
|
|
|
|
2015-07-17 18:07:37 +03:00
|
|
|
static void NotifyAboutMainThreadListenerChange(dom::EventTarget* aTarget,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aName)
|
2015-04-28 23:10:05 +03:00
|
|
|
{
|
|
|
|
if (sInstance) {
|
2015-07-17 18:07:37 +03:00
|
|
|
sInstance->NotifyAboutMainThreadListenerChangeInternal(aTarget, aName);
|
2015-04-28 23:10:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void NotifyPendingChanges();
|
|
|
|
private:
|
2015-07-17 18:07:37 +03:00
|
|
|
void NotifyAboutMainThreadListenerChangeInternal(dom::EventTarget* aTarget,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aName);
|
2015-04-28 23:10:05 +03:00
|
|
|
nsTObserverArray<nsCOMPtr<nsIListenerChangeListener>> mChangeListeners;
|
|
|
|
nsCOMPtr<nsIMutableArray> mPendingListenerChanges;
|
2015-10-18 08:24:48 +03:00
|
|
|
nsDataHashtable<nsISupportsHashKey, RefPtr<EventListenerChange>> mPendingListenerChangesSet;
|
2015-04-28 23:10:05 +03:00
|
|
|
|
|
|
|
static EventListenerService* sInstance;
|
2014-03-17 10:56:50 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_EventListenerService_h_
|