| 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_EVENT_EMITTER_H_ | 5 #ifndef EXTENSIONS_RENDERER_EVENT_EMITTER_H_ |
| 6 #define EXTENSIONS_RENDERER_EVENT_EMITTER_H_ | 6 #define EXTENSIONS_RENDERER_EVENT_EMITTER_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "extensions/renderer/api_binding_types.h" | 10 #include "extensions/renderer/api_binding_types.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 v8::Isolate* isolate) final; | 36 v8::Isolate* isolate) final; |
| 37 | 37 |
| 38 void Fire(v8::Local<v8::Context> context, | 38 void Fire(v8::Local<v8::Context> context, |
| 39 std::vector<v8::Local<v8::Value>>* args, | 39 std::vector<v8::Local<v8::Value>>* args, |
| 40 const EventFilteringInfo* filter); | 40 const EventFilteringInfo* filter); |
| 41 | 41 |
| 42 // Removes all listeners and marks this object as invalid so that no more | 42 // Removes all listeners and marks this object as invalid so that no more |
| 43 // are added. | 43 // are added. |
| 44 void Invalidate(v8::Local<v8::Context> context); | 44 void Invalidate(v8::Local<v8::Context> context); |
| 45 | 45 |
| 46 // TODO(devlin): Consider making this a test-only method and exposing |
| 47 // HasListeners() instead. |
| 46 size_t GetNumListeners() const; | 48 size_t GetNumListeners() const; |
| 47 | 49 |
| 48 private: | 50 private: |
| 49 // Bound methods for the Event JS object. | 51 // Bound methods for the Event JS object. |
| 50 void AddListener(gin::Arguments* arguments); | 52 void AddListener(gin::Arguments* arguments); |
| 51 void RemoveListener(gin::Arguments* arguments); | 53 void RemoveListener(gin::Arguments* arguments); |
| 52 bool HasListener(v8::Local<v8::Function> function); | 54 bool HasListener(v8::Local<v8::Function> function); |
| 53 bool HasListeners(); | 55 bool HasListeners(); |
| 54 void Dispatch(gin::Arguments* arguments); | 56 void Dispatch(gin::Arguments* arguments); |
| 55 | 57 |
| 56 // Whether or not this object is still valid; false upon context release. | 58 // Whether or not this object is still valid; false upon context release. |
| 57 // When invalid, no listeners can be added or removed. | 59 // When invalid, no listeners can be added or removed. |
| 58 bool valid_ = true; | 60 bool valid_ = true; |
| 59 | 61 |
| 60 // Whether the event supports filters. | 62 // Whether the event supports filters. |
| 61 bool supports_filters_ = false; | 63 bool supports_filters_ = false; |
| 62 | 64 |
| 63 std::unique_ptr<APIEventListeners> listeners_; | 65 std::unique_ptr<APIEventListeners> listeners_; |
| 64 | 66 |
| 65 binding::RunJSFunction run_js_; | 67 binding::RunJSFunction run_js_; |
| 66 | 68 |
| 67 DISALLOW_COPY_AND_ASSIGN(EventEmitter); | 69 DISALLOW_COPY_AND_ASSIGN(EventEmitter); |
| 68 }; | 70 }; |
| 69 | 71 |
| 70 } // namespace extensions | 72 } // namespace extensions |
| 71 | 73 |
| 72 #endif // EXTENSIONS_RENDERER_EVENT_EMITTER_H_ | 74 #endif // EXTENSIONS_RENDERER_EVENT_EMITTER_H_ |
| OLD | NEW |