Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(142)

Side by Side Diff: extensions/renderer/event_emitter.h

Issue 2469593002: [Extensions Bindings] Add Events support (Closed)
Patch Set: jbromans III Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698