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

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

Issue 2947463002: [Extensions Bindings] Add a bindings/ subdirectory under renderer (Closed)
Patch Set: . Created 3 years, 5 months 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
« no previous file with comments | « extensions/renderer/declarative_event_unittest.cc ('k') | extensions/renderer/event_emitter.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "extensions/renderer/api_binding_types.h"
11 #include "gin/wrappable.h"
12 #include "v8/include/v8.h"
13
14 namespace gin {
15 class Arguments;
16 }
17
18 namespace extensions {
19 class APIEventListeners;
20 struct EventFilteringInfo;
21
22 // A gin::Wrappable Event object. One is expected to be created per event, per
23 // context. Note: this object *does not* clear any events, so it must be
24 // destroyed with the context to avoid leaking.
25 class EventEmitter final : public gin::Wrappable<EventEmitter> {
26 public:
27 EventEmitter(bool supports_filters,
28 std::unique_ptr<APIEventListeners> listeners,
29 const binding::RunJSFunction& run_js,
30 const binding::RunJSFunctionSync& run_js_sync);
31 ~EventEmitter() override;
32
33 static gin::WrapperInfo kWrapperInfo;
34
35 // gin::Wrappable:
36 gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
37 v8::Isolate* isolate) final;
38
39 void Fire(v8::Local<v8::Context> context,
40 std::vector<v8::Local<v8::Value>>* args,
41 const EventFilteringInfo* filter);
42
43 // Removes all listeners and marks this object as invalid so that no more
44 // are added.
45 void Invalidate(v8::Local<v8::Context> context);
46
47 // TODO(devlin): Consider making this a test-only method and exposing
48 // HasListeners() instead.
49 size_t GetNumListeners() const;
50
51 private:
52 // Bound methods for the Event JS object.
53 void AddListener(gin::Arguments* arguments);
54 void RemoveListener(gin::Arguments* arguments);
55 bool HasListener(v8::Local<v8::Function> function);
56 bool HasListeners();
57 void Dispatch(gin::Arguments* arguments);
58
59 // Notifies the listeners of an event with the given |args|. If |run_sync| is
60 // true, runs JS synchronously and populates |out_values| with the results of
61 // the listeners.
62 void DispatchImpl(v8::Local<v8::Context> context,
63 std::vector<v8::Local<v8::Value>>* args,
64 const EventFilteringInfo* filter,
65 bool run_sync,
66 std::vector<v8::Global<v8::Value>>* out_values);
67
68 // Whether or not this object is still valid; false upon context release.
69 // When invalid, no listeners can be added or removed.
70 bool valid_ = true;
71
72 // Whether the event supports filters.
73 bool supports_filters_ = false;
74
75 std::unique_ptr<APIEventListeners> listeners_;
76
77 binding::RunJSFunction run_js_;
78 binding::RunJSFunctionSync run_js_sync_;
79
80 DISALLOW_COPY_AND_ASSIGN(EventEmitter);
81 };
82
83 } // namespace extensions
84
85 #endif // EXTENSIONS_RENDERER_EVENT_EMITTER_H_
OLDNEW
« no previous file with comments | « extensions/renderer/declarative_event_unittest.cc ('k') | extensions/renderer/event_emitter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698