| 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 26 matching lines...) Expand all Loading... |
| 37 // Returns a new v8::Object for an event with the given |event_name|. | 37 // Returns a new v8::Object for an event with the given |event_name|. |
| 38 v8::Local<v8::Object> CreateEventInstance(const std::string& event_name, | 38 v8::Local<v8::Object> CreateEventInstance(const std::string& event_name, |
| 39 v8::Local<v8::Context> context); | 39 v8::Local<v8::Context> context); |
| 40 | 40 |
| 41 // Notifies all listeners of the event with the given |event_name| in the | 41 // Notifies all listeners of the event with the given |event_name| in the |
| 42 // specified |context|, sending the included |arguments|. | 42 // specified |context|, sending the included |arguments|. |
| 43 void FireEventInContext(const std::string& event_name, | 43 void FireEventInContext(const std::string& event_name, |
| 44 v8::Local<v8::Context> context, | 44 v8::Local<v8::Context> context, |
| 45 const base::ListValue& arguments); | 45 const base::ListValue& arguments); |
| 46 | 46 |
| 47 // Registers a |function| to serve as an "argument massager" for the given |
| 48 // |event_name|, mutating the original arguments. |
| 49 // The function is called with two arguments: the array of original arguments |
| 50 // being dispatched to the event, and the function to dispatch the event to |
| 51 // listeners. |
| 52 void RegisterArgumentMassager(v8::Local<v8::Context> context, |
| 53 const std::string& event_name, |
| 54 v8::Local<v8::Function> function); |
| 55 |
| 47 // Returns the EventListeners for a given |event_name| and |context|. | 56 // Returns the EventListeners for a given |event_name| and |context|. |
| 48 size_t GetNumEventListenersForTesting(const std::string& event_name, | 57 size_t GetNumEventListenersForTesting(const std::string& event_name, |
| 49 v8::Local<v8::Context> context); | 58 v8::Local<v8::Context> context); |
| 50 | 59 |
| 51 private: | 60 private: |
| 52 // Method to run a given v8::Function. Curried in for testing. | 61 // Method to run a given v8::Function. Curried in for testing. |
| 53 binding::RunJSFunction call_js_; | 62 binding::RunJSFunction call_js_; |
| 54 | 63 |
| 55 EventListenersChangedMethod listeners_changed_; | 64 EventListenersChangedMethod listeners_changed_; |
| 56 | 65 |
| 57 DISALLOW_COPY_AND_ASSIGN(APIEventHandler); | 66 DISALLOW_COPY_AND_ASSIGN(APIEventHandler); |
| 58 }; | 67 }; |
| 59 | 68 |
| 60 } // namespace extensions | 69 } // namespace extensions |
| 61 | 70 |
| 62 #endif // EXTENSIONS_RENDERER_API_EVENT_HANDLER_H_ | 71 #endif // EXTENSIONS_RENDERER_API_EVENT_HANDLER_H_ |
| OLD | NEW |