| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_BINDINGS_H_ | 5 #ifndef EXTENSIONS_RENDERER_EVENT_BINDINGS_H_ |
| 6 #define EXTENSIONS_RENDERER_EVENT_BINDINGS_H_ | 6 #define EXTENSIONS_RENDERER_EVENT_BINDINGS_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "extensions/renderer/object_backed_native_handler.h" | 13 #include "extensions/renderer/object_backed_native_handler.h" |
| 14 #include "v8/include/v8.h" | 14 #include "v8/include/v8.h" |
| 15 | 15 |
| 16 namespace base { | 16 namespace base { |
| 17 class DictionaryValue; | 17 class DictionaryValue; |
| 18 } | 18 } |
| 19 | 19 |
| 20 namespace extensions { | 20 namespace extensions { |
| 21 class EventMatcher; | 21 class EventMatcher; |
| 22 | 22 |
| 23 // This class deals with the javascript bindings related to Event objects. | 23 // This class deals with the javascript bindings related to Event objects. |
| 24 class EventBindings : public ObjectBackedNativeHandler { | 24 class EventBindings : public ObjectBackedNativeHandler { |
| 25 public: | 25 public: |
| 26 explicit EventBindings(ScriptContext* context); | 26 explicit EventBindings(ScriptContext* context); |
| 27 ~EventBindings() override; | 27 ~EventBindings() override; |
| 28 | 28 |
| 29 // Returns true if there is a listener for the given |event| in the given |
| 30 // |context|. |
| 31 static bool HasListener(ScriptContext* context, |
| 32 const std::string& event_name); |
| 33 |
| 29 private: | 34 private: |
| 30 // JavaScript handler which forwards to AttachEvent(). | 35 // JavaScript handler which forwards to AttachEvent(). |
| 31 // args[0] forwards to |event_name|. | 36 // args[0] forwards to |event_name|. |
| 32 void AttachEventHandler(const v8::FunctionCallbackInfo<v8::Value>& args); | 37 void AttachEventHandler(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 33 | 38 |
| 34 // Attach an event name to an object. | 39 // Attach an event name to an object. |
| 35 // |event_name| The name of the event to attach. | 40 // |event_name| The name of the event to attach. |
| 36 void AttachEvent(const std::string& event_name); | 41 void AttachEvent(const std::string& event_name); |
| 37 | 42 |
| 38 // JavaScript handler which forwards to DetachEvent(). | 43 // JavaScript handler which forwards to DetachEvent(). |
| (...skipping 24 matching lines...) Expand all Loading... |
| 63 | 68 |
| 64 // Detaches a filtered event. Unlike a normal event, a filtered event is | 69 // Detaches a filtered event. Unlike a normal event, a filtered event is |
| 65 // identified by a unique ID per filter, not its name. | 70 // identified by a unique ID per filter, not its name. |
| 66 // |matcher_id| The ID of the filtered event. | 71 // |matcher_id| The ID of the filtered event. |
| 67 // |is_manual| false if this is part of the extension unload process where all | 72 // |is_manual| false if this is part of the extension unload process where all |
| 68 // listeners are automatically detached. | 73 // listeners are automatically detached. |
| 69 void DetachFilteredEvent(int matcher_id, bool is_manual); | 74 void DetachFilteredEvent(int matcher_id, bool is_manual); |
| 70 | 75 |
| 71 void MatchAgainstEventFilter(const v8::FunctionCallbackInfo<v8::Value>& args); | 76 void MatchAgainstEventFilter(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 72 | 77 |
| 78 void AttachUnmanagedEvent(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 79 void DetachUnmanagedEvent(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 80 |
| 73 std::unique_ptr<EventMatcher> ParseEventMatcher( | 81 std::unique_ptr<EventMatcher> ParseEventMatcher( |
| 74 std::unique_ptr<base::DictionaryValue> filter); | 82 std::unique_ptr<base::DictionaryValue> filter); |
| 75 | 83 |
| 76 // Called when our context, and therefore us, is invalidated. Run any cleanup. | 84 // Called when our context, and therefore us, is invalidated. Run any cleanup. |
| 77 void OnInvalidated(); | 85 void OnInvalidated(); |
| 78 | 86 |
| 79 // The set of attached events and filtered events. Maintain these so that we | 87 // The set of attached events and filtered events. Maintain these so that we |
| 80 // can detch them on unload. | 88 // can detch them on unload. |
| 81 std::set<std::string> attached_event_names_; | 89 std::set<std::string> attached_event_names_; |
| 82 std::set<int> attached_matcher_ids_; | 90 std::set<int> attached_matcher_ids_; |
| 83 | 91 |
| 84 DISALLOW_COPY_AND_ASSIGN(EventBindings); | 92 DISALLOW_COPY_AND_ASSIGN(EventBindings); |
| 85 }; | 93 }; |
| 86 | 94 |
| 87 } // namespace extensions | 95 } // namespace extensions |
| 88 | 96 |
| 89 #endif // EXTENSIONS_RENDERER_EVENT_BINDINGS_H_ | 97 #endif // EXTENSIONS_RENDERER_EVENT_BINDINGS_H_ |
| OLD | NEW |