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_API_EVENT_HANDLER_H_ | |
6 #define EXTENSIONS_RENDERER_API_EVENT_HANDLER_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/callback.h" | |
11 #include "base/macros.h" | |
12 #include "extensions/renderer/api_binding_types.h" | |
13 #include "extensions/renderer/event_emitter.h" | |
jbroman
2016/11/03 19:28:04
super-nit: unused include; move to .cc?
Devlin
2016/11/04 17:59:30
Done.
| |
14 #include "v8/include/v8.h" | |
15 | |
16 namespace base { | |
17 class ListValue; | |
18 } | |
19 | |
20 namespace gin { | |
21 class Arguments; | |
jbroman
2016/11/03 19:28:04
nit: unused forward declaration (apologies for mis
Devlin
2016/11/04 17:59:30
Done.
| |
22 } | |
23 | |
24 namespace extensions { | |
25 | |
26 // The object to handle API events. This includes vending v8::Objects for the | |
27 // event; handling adding, removing, and querying listeners; and firing events | |
28 // to subscribed listeners. Designed to be used across JS contexts, but on a | |
29 // single thread. | |
30 class APIEventHandler { | |
31 public: | |
32 APIEventHandler(const binding::RunJSFunction& call_js); | |
33 ~APIEventHandler(); | |
34 | |
35 // Returns a new v8::Object for an event with the given |event_name|. | |
36 v8::Local<v8::Object> CreateEventInstance(const std::string& event_name, | |
37 v8::Local<v8::Context> context); | |
38 | |
39 // Notifies all listeners of the event with the given |event_name| in the | |
40 // specified |context|, sending the included |arguments|. | |
41 void FireEventInContext(const std::string& event_name, | |
42 v8::Local<v8::Context> context, | |
43 const base::ListValue& arguments); | |
44 | |
45 // Returns the EventListeners for a given |event_name| and |context|. | |
46 size_t GetNumEventListenersForTesting(const std::string& event_name, | |
47 v8::Local<v8::Context> context); | |
48 | |
49 private: | |
50 // Method to run a given v8::Function. Curried in for testing. | |
51 binding::RunJSFunction call_js_; | |
52 | |
53 DISALLOW_COPY_AND_ASSIGN(APIEventHandler); | |
54 }; | |
55 | |
56 } // namespace extensions | |
57 | |
58 #endif // EXTENSIONS_RENDERER_API_EVENT_HANDLER_H_ | |
OLD | NEW |