OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef EXTENSIONS_RENDERER_EVENT_BINDINGS_H_ | 5 #ifndef EXTENSIONS_RENDERER_EVENT_BINDINGS_H_ |
6 #define EXTENSIONS_RENDERER_EVENT_BINDINGS_H_ | 6 #define EXTENSIONS_RENDERER_EVENT_BINDINGS_H_ |
7 | 7 |
8 #include <set> | |
9 #include <string> | |
10 | |
11 #include "base/macros.h" | |
12 #include "extensions/renderer/object_backed_native_handler.h" | 8 #include "extensions/renderer/object_backed_native_handler.h" |
13 #include "v8/include/v8.h" | 9 #include "v8/include/v8.h" |
14 | 10 |
15 namespace base { | 11 namespace base { |
16 class DictionaryValue; | 12 class DictionaryValue; |
17 } | 13 } |
18 | 14 |
19 namespace extensions { | 15 namespace extensions { |
20 class Dispatcher; | 16 class Dispatcher; |
| 17 class EventFilter; |
| 18 class EventFilteringInfo; |
21 class EventMatcher; | 19 class EventMatcher; |
22 | 20 |
23 // This class deals with the javascript bindings related to Event objects. | 21 // This class deals with the javascript bindings related to Event objects. |
24 class EventBindings : public ObjectBackedNativeHandler { | 22 class EventBindings : public ObjectBackedNativeHandler { |
25 public: | 23 public: |
26 EventBindings(Dispatcher* dispatcher, ScriptContext* context); | 24 EventBindings(Dispatcher* dispatcher, ScriptContext* context); |
27 ~EventBindings() override; | 25 ~EventBindings() override; |
28 | 26 |
29 private: | 27 private: |
30 // JavaScript handler which forwards to AttachEvent(). | |
31 // args[0] forwards to |event_name|. | |
32 void AttachEventHandler(const v8::FunctionCallbackInfo<v8::Value>& args); | |
33 | |
34 // Attach an event name to an object. | 28 // Attach an event name to an object. |
35 // |event_name| The name of the event to attach. | 29 // |event_name| The name of the event to attach. |
36 void AttachEvent(const std::string& event_name); | 30 void AttachEvent(const v8::FunctionCallbackInfo<v8::Value>& args); |
37 | 31 |
38 // JavaScript handler which forwards to DetachEvent(). | 32 // Detach an event name from an object. |
39 // args[0] forwards to |event_name|. | |
40 // args[1] forwards to |is_manual|. | |
41 void DetachEventHandler(const v8::FunctionCallbackInfo<v8::Value>& args); | |
42 | |
43 // Detaches an event name from an object. | |
44 // |event_name| The name of the event to stop listening to. | 33 // |event_name| The name of the event to stop listening to. |
45 // |is_manual| True if this detach was done by the user via removeListener() | 34 // |is_manual| True if this detach was done by the user via removeListener() |
46 // as opposed to automatically during shutdown, in which case we should inform | 35 // as opposed to automatically during shutdown, in which case we should inform |
47 // the browser we are no longer interested in that event. | 36 // the browser we are no longer interested in that event. |
48 void DetachEvent(const std::string& event_name, bool is_manual); | 37 void DetachEvent(const v8::FunctionCallbackInfo<v8::Value>& args); |
49 | 38 |
50 // MatcherID AttachFilteredEvent(string event_name, object filter) | 39 // MatcherID AttachFilteredEvent(string event_name, object filter) |
51 // |event_name| Name of the event to attach. | 40 // |event_name| Name of the event to attach. |
52 // |filter| Which instances of the named event are we interested in. | 41 // |filter| Which instances of the named event are we interested in. |
53 // returns the id assigned to the listener, which will be returned from calls | 42 // returns the id assigned to the listener, which will be returned from calls |
54 // to MatchAgainstEventFilter where this listener matches. | 43 // to MatchAgainstEventFilter where this listener matches. |
55 void AttachFilteredEvent(const v8::FunctionCallbackInfo<v8::Value>& args); | 44 void AttachFilteredEvent(const v8::FunctionCallbackInfo<v8::Value>& args); |
56 | 45 |
57 // void DetachFilteredEvent(int id, bool manual) | 46 // void DetachFilteredEvent(int id, bool manual) |
58 // id - Id of the event to detach. | 47 // id - Id of the event to detach. |
59 // manual - false if this is part of the extension unload process where all | 48 // manual - false if this is part of the extension unload process where all |
60 // listeners are automatically detached. | 49 // listeners are automatically detached. |
61 void DetachFilteredEvent(const v8::FunctionCallbackInfo<v8::Value>& args); | 50 void DetachFilteredEvent(const v8::FunctionCallbackInfo<v8::Value>& args); |
62 | 51 |
63 void MatchAgainstEventFilter(const v8::FunctionCallbackInfo<v8::Value>& args); | 52 void MatchAgainstEventFilter(const v8::FunctionCallbackInfo<v8::Value>& args); |
64 | 53 |
| 54 Dispatcher* dispatcher_; |
65 scoped_ptr<EventMatcher> ParseEventMatcher( | 55 scoped_ptr<EventMatcher> ParseEventMatcher( |
66 base::DictionaryValue* filter_dict); | 56 base::DictionaryValue* filter_dict); |
67 | |
68 // Called when our context, and therefore us, is invalidated. Run any cleanup. | |
69 void OnInvalidated(); | |
70 | |
71 // The set of attached events. Maintain this so that we can detch them on | |
72 // unload. | |
73 std::set<std::string> attached_event_names_; | |
74 | |
75 Dispatcher* dispatcher_; | |
76 | |
77 DISALLOW_COPY_AND_ASSIGN(EventBindings); | |
78 }; | 57 }; |
79 | 58 |
80 } // namespace extensions | 59 } // namespace extensions |
81 | 60 |
82 #endif // EXTENSIONS_RENDERER_EVENT_BINDINGS_H_ | 61 #endif // EXTENSIONS_RENDERER_EVENT_BINDINGS_H_ |
OLD | NEW |