| 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_API_EVENT_HANDLER_H_ | 5 #ifndef EXTENSIONS_RENDERER_API_EVENT_HANDLER_H_ |
| 6 #define EXTENSIONS_RENDERER_API_EVENT_HANDLER_H_ | 6 #define EXTENSIONS_RENDERER_API_EVENT_HANDLER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 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 was_manual, |
| 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 EventListenersChangedMethod& listeners_changed); | 43 const EventListenersChangedMethod& listeners_changed); |
| 43 ~APIEventHandler(); | 44 ~APIEventHandler(); |
| 44 | 45 |
| 45 // 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 |
| 46 // |notify_on_change| is true, notifies whenever listeners state is changed. | 47 // |notify_on_change| is true, notifies whenever listeners state is changed. |
| 47 v8::Local<v8::Object> CreateEventInstance(const std::string& event_name, | 48 v8::Local<v8::Object> CreateEventInstance(const std::string& event_name, |
| 48 bool supports_filters, | 49 bool supports_filters, |
| 49 int max_listeners, | 50 int max_listeners, |
| 50 bool notify_on_change, | 51 bool notify_on_change, |
| 51 v8::Local<v8::Context> context); | 52 v8::Local<v8::Context> context); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 | 84 |
| 84 // Invalidates listeners for the given |context|. It's a shame we have to | 85 // Invalidates listeners for the given |context|. It's a shame we have to |
| 85 // have this separately (as opposed to hooking into e.g. a PerContextData | 86 // have this separately (as opposed to hooking into e.g. a PerContextData |
| 86 // destructor), but we need to do this before the context is fully removed | 87 // destructor), but we need to do this before the context is fully removed |
| 87 // (because the associated extension ScriptContext needs to be valid). | 88 // (because the associated extension ScriptContext needs to be valid). |
| 88 void InvalidateContext(v8::Local<v8::Context> context); | 89 void InvalidateContext(v8::Local<v8::Context> context); |
| 89 | 90 |
| 90 private: | 91 private: |
| 91 // Method to run a given v8::Function. Curried in for testing. | 92 // Method to run a given v8::Function. Curried in for testing. |
| 92 binding::RunJSFunction call_js_; | 93 binding::RunJSFunction call_js_; |
| 94 binding::RunJSFunctionSync call_js_sync_; |
| 93 | 95 |
| 94 EventListenersChangedMethod listeners_changed_; | 96 EventListenersChangedMethod listeners_changed_; |
| 95 | 97 |
| 96 // The associated EventFilter; shared across all contexts and events. | 98 // The associated EventFilter; shared across all contexts and events. |
| 97 EventFilter event_filter_; | 99 EventFilter event_filter_; |
| 98 | 100 |
| 99 DISALLOW_COPY_AND_ASSIGN(APIEventHandler); | 101 DISALLOW_COPY_AND_ASSIGN(APIEventHandler); |
| 100 }; | 102 }; |
| 101 | 103 |
| 102 } // namespace extensions | 104 } // namespace extensions |
| 103 | 105 |
| 104 #endif // EXTENSIONS_RENDERER_API_EVENT_HANDLER_H_ | 106 #endif // EXTENSIONS_RENDERER_API_EVENT_HANDLER_H_ |
| OLD | NEW |