| 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 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 static gin::WrapperInfo kWrapperInfo; | 34 static gin::WrapperInfo kWrapperInfo; |
| 35 | 35 |
| 36 // gin::Wrappable: | 36 // gin::Wrappable: |
| 37 gin::ObjectTemplateBuilder GetObjectTemplateBuilder( | 37 gin::ObjectTemplateBuilder GetObjectTemplateBuilder( |
| 38 v8::Isolate* isolate) final; | 38 v8::Isolate* isolate) final; |
| 39 | 39 |
| 40 void Fire(v8::Local<v8::Context> context, | 40 void Fire(v8::Local<v8::Context> context, |
| 41 std::vector<v8::Local<v8::Value>>* args); | 41 std::vector<v8::Local<v8::Value>>* args); |
| 42 | 42 |
| 43 Listeners* listeners() { return &listeners_; } | 43 // Removes all listeners and marks this object as invalid so that no more |
| 44 // are added. |
| 45 void Invalidate(); |
| 46 |
| 47 const Listeners* listeners() const { return &listeners_; } |
| 44 | 48 |
| 45 private: | 49 private: |
| 46 // Bound methods for the Event JS object. | 50 // Bound methods for the Event JS object. |
| 47 void AddListener(gin::Arguments* arguments); | 51 void AddListener(gin::Arguments* arguments); |
| 48 void RemoveListener(gin::Arguments* arguments); | 52 void RemoveListener(gin::Arguments* arguments); |
| 49 bool HasListener(v8::Local<v8::Function> function); | 53 bool HasListener(v8::Local<v8::Function> function); |
| 50 bool HasListeners(); | 54 bool HasListeners(); |
| 51 void Dispatch(gin::Arguments* arguments); | 55 void Dispatch(gin::Arguments* arguments); |
| 52 | 56 |
| 57 // Whether or not this object is still valid; false upon context release. |
| 58 // When invalid, no listeners can be added or removed. |
| 59 bool valid_ = true; |
| 60 |
| 53 Listeners listeners_; | 61 Listeners listeners_; |
| 54 | 62 |
| 55 binding::RunJSFunction run_js_; | 63 binding::RunJSFunction run_js_; |
| 56 | 64 |
| 57 ListenersChangedMethod listeners_changed_; | 65 ListenersChangedMethod listeners_changed_; |
| 58 | 66 |
| 59 DISALLOW_COPY_AND_ASSIGN(EventEmitter); | 67 DISALLOW_COPY_AND_ASSIGN(EventEmitter); |
| 60 }; | 68 }; |
| 61 | 69 |
| 62 } // namespace extensions | 70 } // namespace extensions |
| 63 | 71 |
| 64 #endif // EXTENSIONS_RENDERER_EVENT_EMITTER_H_ | 72 #endif // EXTENSIONS_RENDERER_EVENT_EMITTER_H_ |
| OLD | NEW |