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

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

Issue 2469593002: [Extensions Bindings] Add Events support (Closed)
Patch Set: jbromans II 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_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_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698