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

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

Issue 2469593002: [Extensions Bindings] Add Events support (Closed)
Patch Set: asantest 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 "v8/include/v8.h"
14
15 namespace base {
16 class ListValue;
17 }
18
19 namespace extensions {
20
21 // The object to handle API events. This includes vending v8::Objects for the
22 // event; handling adding, removing, and querying listeners; and firing events
23 // to subscribed listeners. Designed to be used across JS contexts, but on a
24 // single thread.
25 class APIEventHandler {
26 public:
27 APIEventHandler(const binding::RunJSFunction& call_js);
28 ~APIEventHandler();
29
30 // Returns a new v8::Object for an event with the given |event_name|.
31 v8::Local<v8::Object> CreateEventInstance(const std::string& event_name,
32 v8::Local<v8::Context> context);
33
34 // Notifies all listeners of the event with the given |event_name| in the
35 // specified |context|, sending the included |arguments|.
36 void FireEventInContext(const std::string& event_name,
37 v8::Local<v8::Context> context,
38 const base::ListValue& arguments);
39
40 // Returns the EventListeners for a given |event_name| and |context|.
41 size_t GetNumEventListenersForTesting(const std::string& event_name,
42 v8::Local<v8::Context> context);
43
44 private:
45 // Method to run a given v8::Function. Curried in for testing.
46 binding::RunJSFunction call_js_;
47
48 DISALLOW_COPY_AND_ASSIGN(APIEventHandler);
49 };
50
51 } // namespace extensions
52
53 #endif // EXTENSIONS_RENDERER_API_EVENT_HANDLER_H_
OLDNEW
« no previous file with comments | « extensions/renderer/api_bindings_system_unittest.cc ('k') | extensions/renderer/api_event_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698