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