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