Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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_BINDINGS_API_EVENT_HANDLER_H_ | 5 #ifndef EXTENSIONS_RENDERER_BINDINGS_API_EVENT_HANDLER_H_ |
| 6 #define EXTENSIONS_RENDERER_BINDINGS_API_EVENT_HANDLER_H_ | 6 #define EXTENSIONS_RENDERER_BINDINGS_API_EVENT_HANDLER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "extensions/common/event_filter.h" | 12 #include "extensions/common/event_filter.h" |
| 13 #include "extensions/renderer/bindings/api_binding_types.h" | 13 #include "extensions/renderer/bindings/api_binding_types.h" |
| 14 #include "extensions/renderer/bindings/event_emitter.h" | 14 #include "extensions/renderer/bindings/event_emitter.h" |
| 15 #include "v8/include/v8.h" | 15 #include "v8/include/v8.h" |
| 16 | 16 |
| 17 namespace base { | 17 namespace base { |
| 18 class ListValue; | 18 class ListValue; |
| 19 } | 19 } |
| 20 | 20 |
| 21 namespace extensions { | 21 namespace extensions { |
| 22 struct EventFilteringInfo; | 22 struct EventFilteringInfo; |
| 23 | 23 |
| 24 // The object to handle API events. This includes vending v8::Objects for the | 24 // The object to handle API events. This includes vending v8::Objects for the |
| 25 // event; handling adding, removing, and querying listeners; and firing events | 25 // event; handling adding, removing, and querying listeners; and firing events |
| 26 // to subscribed listeners. Designed to be used across JS contexts, but on a | 26 // to subscribed listeners. Designed to be used across JS contexts, but on a |
| 27 // single thread. | 27 // single thread. |
| 28 class APIEventHandler { | 28 class APIEventHandler { |
| 29 public: | 29 public: |
| 30 // The callback to be called when event listeners change. |was_manual| | 30 // The callback to be called when event listeners change. |was_manual| |
|
lazyboy
2017/07/14 00:04:42
Update documentation
Devlin
2017/07/14 15:37:54
Done.
| |
| 31 // indicates that the change was due to an extension calling addListener or | 31 // indicates that the change was due to an extension calling addListener or |
| 32 // removeListener, rather than through something like context destruction. | 32 // removeListener, rather than through something like context destruction. |
| 33 // See also APIEventListeners. | 33 // See also APIEventListeners. |
| 34 using EventListenersChangedMethod = | 34 using EventListenersChangedMethod = |
| 35 base::Callback<void(const std::string& event_name, | 35 base::Callback<void(const std::string& event_name, |
| 36 binding::EventListenersChanged, | 36 binding::EventListenersChanged, |
| 37 const base::DictionaryValue* filter, | 37 const base::DictionaryValue* filter, |
| 38 bool was_manual, | 38 bool update_lazy_listeners, |
| 39 v8::Local<v8::Context>)>; | 39 v8::Local<v8::Context>)>; |
| 40 | 40 |
| 41 APIEventHandler(const binding::RunJSFunction& call_js, | 41 APIEventHandler(const binding::RunJSFunction& call_js, |
| 42 const binding::RunJSFunctionSync& call_js_sync, | 42 const binding::RunJSFunctionSync& call_js_sync, |
| 43 const EventListenersChangedMethod& listeners_changed); | 43 const EventListenersChangedMethod& listeners_changed); |
| 44 ~APIEventHandler(); | 44 ~APIEventHandler(); |
| 45 | 45 |
| 46 // Returns a new v8::Object for an event with the given |event_name|. If | 46 // Returns a new v8::Object for an event with the given |event_name|. If |
| 47 // |notify_on_change| is true, notifies whenever listeners state is changed. | 47 // |notify_on_change| is true, notifies whenever listeners state is changed. |
| 48 // TODO(devlin): Maybe worth creating a Params struct to hold the event | |
| 49 // information? | |
| 48 v8::Local<v8::Object> CreateEventInstance(const std::string& event_name, | 50 v8::Local<v8::Object> CreateEventInstance(const std::string& event_name, |
| 49 bool supports_filters, | 51 bool supports_filters, |
| 52 bool supports_lazy_listeners, | |
| 50 int max_listeners, | 53 int max_listeners, |
| 51 bool notify_on_change, | 54 bool notify_on_change, |
| 52 v8::Local<v8::Context> context); | 55 v8::Local<v8::Context> context); |
| 53 | 56 |
| 54 // Creates a new event without any name. This is used by custom bindings when | 57 // Creates a new event without any name. This is used by custom bindings when |
| 55 // the entirety of the logic for the event is contained in the renderer. These | 58 // the entirety of the logic for the event is contained in the renderer. These |
| 56 // events do not notify of new/removed listeners or allow for dispatching | 59 // events do not notify of new/removed listeners or allow for dispatching |
| 57 // through FireEventInContext(). | 60 // through FireEventInContext(). |
| 58 v8::Local<v8::Object> CreateAnonymousEventInstance( | 61 v8::Local<v8::Object> CreateAnonymousEventInstance( |
| 59 v8::Local<v8::Context> context); | 62 v8::Local<v8::Context> context); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 103 | 106 |
| 104 // The associated EventFilter; shared across all contexts and events. | 107 // The associated EventFilter; shared across all contexts and events. |
| 105 EventFilter event_filter_; | 108 EventFilter event_filter_; |
| 106 | 109 |
| 107 DISALLOW_COPY_AND_ASSIGN(APIEventHandler); | 110 DISALLOW_COPY_AND_ASSIGN(APIEventHandler); |
| 108 }; | 111 }; |
| 109 | 112 |
| 110 } // namespace extensions | 113 } // namespace extensions |
| 111 | 114 |
| 112 #endif // EXTENSIONS_RENDERER_BINDINGS_API_EVENT_HANDLER_H_ | 115 #endif // EXTENSIONS_RENDERER_BINDINGS_API_EVENT_HANDLER_H_ |
| OLD | NEW |