OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef EXTENSIONS_RENDERER_EVENT_EMITTER_H_ |
| 6 #define EXTENSIONS_RENDERER_EVENT_EMITTER_H_ |
| 7 |
| 8 #include <vector> |
| 9 |
| 10 #include "gin/wrappable.h" |
| 11 #include "v8/include/v8.h" |
| 12 |
| 13 namespace gin { |
| 14 class Arguments; |
| 15 } |
| 16 |
| 17 namespace extensions { |
| 18 |
| 19 // A gin::Wrappable Event object. One is expected to be created per event, per |
| 20 // context. Note: this object *does not* clear any events, so it must be |
| 21 // destroyed with the context to avoid leaking. |
| 22 class EventEmitter final : public gin::Wrappable<EventEmitter> { |
| 23 public: |
| 24 using Listeners = std::vector<v8::Global<v8::Function>>; |
| 25 |
| 26 EventEmitter(); |
| 27 ~EventEmitter() override; |
| 28 |
| 29 static gin::WrapperInfo kWrapperInfo; |
| 30 |
| 31 // gin::Wrappable: |
| 32 gin::ObjectTemplateBuilder GetObjectTemplateBuilder( |
| 33 v8::Isolate* isolate) final; |
| 34 |
| 35 Listeners* listeners() { return &listeners_; } |
| 36 |
| 37 private: |
| 38 // Bound methods for the Event JS object. |
| 39 void AddListener(gin::Arguments* arguments); |
| 40 void RemoveListener(v8::Local<v8::Function> function); |
| 41 bool HasListener(v8::Local<v8::Function> function); |
| 42 bool HasListeners(); |
| 43 |
| 44 Listeners listeners_; |
| 45 |
| 46 DISALLOW_COPY_AND_ASSIGN(EventEmitter); |
| 47 }; |
| 48 |
| 49 } // namespace extensions |
| 50 |
| 51 #endif // EXTENSIONS_RENDERER_EVENT_EMITTER_H_ |
OLD | NEW |