Chromium Code Reviews| 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/handle.h" | |
|
jbroman
2016/11/03 19:28:04
super-nit: since you ended up calling CreateHandle
Devlin
2016/11/04 17:59:30
Done.
| |
| 11 #include "gin/wrappable.h" | |
| 12 #include "v8/include/v8.h" | |
| 13 | |
| 14 namespace gin { | |
| 15 class Arguments; | |
| 16 } | |
| 17 | |
| 18 namespace extensions { | |
| 19 | |
| 20 // A gin::Wrappable Event object. One is expected to be created per event, per | |
| 21 // context. Note: this object *does not* clear any events, so it must be | |
| 22 // destroyed with the context to avoid leaking. | |
| 23 class EventEmitter final : public gin::Wrappable<EventEmitter> { | |
| 24 public: | |
| 25 using Listeners = std::vector<v8::Global<v8::Function>>; | |
| 26 | |
| 27 EventEmitter(); | |
| 28 ~EventEmitter() override; | |
| 29 | |
| 30 static gin::WrapperInfo kWrapperInfo; | |
| 31 | |
| 32 // gin::Wrappable: | |
| 33 gin::ObjectTemplateBuilder GetObjectTemplateBuilder( | |
| 34 v8::Isolate* isolate) final; | |
| 35 | |
| 36 Listeners* listeners() { return &listeners_; } | |
| 37 | |
| 38 private: | |
| 39 // Bound methods for the Event JS object. | |
| 40 void AddListener(gin::Arguments* arguments); | |
| 41 void RemoveListener(v8::Local<v8::Function> function); | |
| 42 bool HasListener(v8::Local<v8::Function> function); | |
| 43 bool HasListeners(); | |
| 44 | |
| 45 Listeners listeners_; | |
| 46 | |
| 47 DISALLOW_COPY_AND_ASSIGN(EventEmitter); | |
| 48 }; | |
| 49 | |
| 50 } // namespace extensions | |
| 51 | |
| 52 #endif // EXTENSIONS_RENDERER_EVENT_EMITTER_H_ | |
| OLD | NEW |