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_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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 68 | 68 |
| 69 // Registers a |function| to serve as an "argument massager" for the given | 69 // Registers a |function| to serve as an "argument massager" for the given |
| 70 // |event_name|, mutating the original arguments. | 70 // |event_name|, mutating the original arguments. |
| 71 // The function is called with two arguments: the array of original arguments | 71 // The function is called with two arguments: the array of original arguments |
| 72 // being dispatched to the event, and the function to dispatch the event to | 72 // being dispatched to the event, and the function to dispatch the event to |
| 73 // listeners. | 73 // listeners. |
| 74 void RegisterArgumentMassager(v8::Local<v8::Context> context, | 74 void RegisterArgumentMassager(v8::Local<v8::Context> context, |
| 75 const std::string& event_name, | 75 const std::string& event_name, |
| 76 v8::Local<v8::Function> function); | 76 v8::Local<v8::Function> function); |
| 77 | 77 |
| 78 // Returns the EventListeners for a given |event_name| and |context|. | 78 // Returns true if there is a listener for the given |event_name| in the |
| 79 size_t GetNumEventListenersForTesting(const std::string& event_name, | 79 // given |context|. |
| 80 v8::Local<v8::Context> context); | 80 bool HasListenerForEvent(const std::string& event_name, |
| 81 v8::Local<v8::Context> context); | |
| 81 | 82 |
| 82 // Invalidates listeners for the given |context|. It's a shame we have to | 83 // Invalidates listeners for the given |context|. It's a shame we have to |
| 83 // have this separately (as opposed to hooking into e.g. a PerContextData | 84 // have this separately (as opposed to hooking into e.g. a PerContextData |
| 84 // destructor), but we need to do this before the context is fully removed | 85 // destructor), but we need to do this before the context is fully removed |
| 85 // (because the associated extension ScriptContext needs to be valid). | 86 // (because the associated extension ScriptContext needs to be valid). |
| 86 void InvalidateContext(v8::Local<v8::Context> context); | 87 void InvalidateContext(v8::Local<v8::Context> context); |
| 87 | 88 |
| 89 // Returns the EventListeners for a given |event_name| and |context|. | |
|
lazyboy
2017/06/05 18:18:32
the number of EventListeners
Devlin
2017/06/09 20:18:02
Done.
| |
| 90 size_t GetNumEventListenersForTesting(const std::string& event_name, | |
| 91 v8::Local<v8::Context> context); | |
| 92 | |
| 88 private: | 93 private: |
| 89 // Method to run a given v8::Function. Curried in for testing. | 94 // Method to run a given v8::Function. Curried in for testing. |
| 90 binding::RunJSFunction call_js_; | 95 binding::RunJSFunction call_js_; |
| 91 | 96 |
| 92 EventListenersChangedMethod listeners_changed_; | 97 EventListenersChangedMethod listeners_changed_; |
| 93 | 98 |
| 94 // The associated EventFilter; shared across all contexts and events. | 99 // The associated EventFilter; shared across all contexts and events. |
| 95 EventFilter event_filter_; | 100 EventFilter event_filter_; |
| 96 | 101 |
| 97 DISALLOW_COPY_AND_ASSIGN(APIEventHandler); | 102 DISALLOW_COPY_AND_ASSIGN(APIEventHandler); |
| 98 }; | 103 }; |
| 99 | 104 |
| 100 } // namespace extensions | 105 } // namespace extensions |
| 101 | 106 |
| 102 #endif // EXTENSIONS_RENDERER_API_EVENT_HANDLER_H_ | 107 #endif // EXTENSIONS_RENDERER_API_EVENT_HANDLER_H_ |
| OLD | NEW |