| Index: extensions/renderer/event_emitter.h
|
| diff --git a/extensions/renderer/event_emitter.h b/extensions/renderer/event_emitter.h
|
| index 3f5b95b7488f213b834efe32e1ae5adf1072c965..e843323bbfa63bb7a796298eee86c5bd66383d53 100644
|
| --- a/extensions/renderer/event_emitter.h
|
| +++ b/extensions/renderer/event_emitter.h
|
| @@ -16,19 +16,17 @@ class Arguments;
|
| }
|
|
|
| namespace extensions {
|
| +class APIEventListeners;
|
| +class EventFilteringInfo;
|
|
|
| // A gin::Wrappable Event object. One is expected to be created per event, per
|
| // context. Note: this object *does not* clear any events, so it must be
|
| // destroyed with the context to avoid leaking.
|
| class EventEmitter final : public gin::Wrappable<EventEmitter> {
|
| public:
|
| - using Listeners = std::vector<v8::Global<v8::Function>>;
|
| - using ListenersChangedMethod =
|
| - base::Callback<void(binding::EventListenersChanged,
|
| - v8::Local<v8::Context>)>;
|
| -
|
| - EventEmitter(const binding::RunJSFunction& run_js,
|
| - const ListenersChangedMethod& listeners_changed);
|
| + EventEmitter(bool supports_filters,
|
| + std::unique_ptr<APIEventListeners> listeners,
|
| + const binding::RunJSFunction& run_js);
|
| ~EventEmitter() override;
|
|
|
| static gin::WrapperInfo kWrapperInfo;
|
| @@ -38,13 +36,14 @@ class EventEmitter final : public gin::Wrappable<EventEmitter> {
|
| v8::Isolate* isolate) final;
|
|
|
| void Fire(v8::Local<v8::Context> context,
|
| - std::vector<v8::Local<v8::Value>>* args);
|
| + std::vector<v8::Local<v8::Value>>* args,
|
| + const EventFilteringInfo* filter);
|
|
|
| // Removes all listeners and marks this object as invalid so that no more
|
| // are added.
|
| - void Invalidate();
|
| + void Invalidate(v8::Local<v8::Context> context);
|
|
|
| - const Listeners* listeners() const { return &listeners_; }
|
| + size_t GetNumListeners() const;
|
|
|
| private:
|
| // Bound methods for the Event JS object.
|
| @@ -58,19 +57,12 @@ class EventEmitter final : public gin::Wrappable<EventEmitter> {
|
| // When invalid, no listeners can be added or removed.
|
| bool valid_ = true;
|
|
|
| - // The event listeners associated with this event.
|
| - // TODO(devlin): Having these listeners held as v8::Globals means that we
|
| - // need to worry about cycles when a listener holds a reference to the event,
|
| - // e.g. EventEmitter -> Listener -> EventEmitter. Right now, we handle that by
|
| - // requiring Invalidate() to be called, but that means that events that aren't
|
| - // Invalidate()'d earlier can leak until context destruction. We could
|
| - // circumvent this by storing the listeners strongly in a private propery
|
| - // (thus traceable by v8), and optionally keep a weak cache on this object.
|
| - Listeners listeners_;
|
| + // Whether the event supports filters.
|
| + bool supports_filters_ = false;
|
|
|
| - binding::RunJSFunction run_js_;
|
| + std::unique_ptr<APIEventListeners> listeners_;
|
|
|
| - ListenersChangedMethod listeners_changed_;
|
| + binding::RunJSFunction run_js_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(EventEmitter);
|
| };
|
|
|