Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(383)

Side by Side Diff: extensions/renderer/event_bindings.h

Issue 2924683002: [Extensions Bindings] Avoid passing the event filter to JS (Closed)
Patch Set: rebase Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 IPC { 16 namespace IPC {
17 class Sender; 17 class Sender;
18 } 18 }
19 19
20 namespace base { 20 namespace base {
21 class DictionaryValue; 21 class DictionaryValue;
22 class ListValue;
22 } 23 }
23 24
24 namespace extensions { 25 namespace extensions {
25 class EventMatcher; 26 class EventMatcher;
26 27
27 // This class deals with the javascript bindings related to Event objects. 28 // This class deals with the javascript bindings related to Event objects.
28 class EventBindings : public ObjectBackedNativeHandler { 29 class EventBindings : public ObjectBackedNativeHandler {
29 public: 30 public:
30 explicit EventBindings(ScriptContext* context); 31 explicit EventBindings(ScriptContext* context);
31 ~EventBindings() override; 32 ~EventBindings() override;
32 33
33 // Returns true if there is a listener for the given |event| in the given 34 // Returns true if there is a listener for the given |event| in the given
34 // |context|. 35 // |context|.
35 static bool HasListener(ScriptContext* context, 36 static bool HasListener(ScriptContext* context,
36 const std::string& event_name); 37 const std::string& event_name);
37 38
39 // Dispatches the event in the given |context| with the provided
40 // |event_args| and |filtering_info|.
41 static void DispatchEventInContext(
42 const std::string& event_name,
43 const base::ListValue* event_args,
44 const base::DictionaryValue* filtering_info,
45 ScriptContext* context);
46
38 private: 47 private:
39 // JavaScript handler which forwards to AttachEvent(). 48 // JavaScript handler which forwards to AttachEvent().
40 // args[0] forwards to |event_name|. 49 // args[0] forwards to |event_name|.
41 void AttachEventHandler(const v8::FunctionCallbackInfo<v8::Value>& args); 50 void AttachEventHandler(const v8::FunctionCallbackInfo<v8::Value>& args);
42 51
43 // Attach an event name to an object. 52 // Attach an event name to an object.
44 // |event_name| The name of the event to attach. 53 // |event_name| The name of the event to attach.
45 void AttachEvent(const std::string& event_name); 54 void AttachEvent(const std::string& event_name);
46 55
47 // JavaScript handler which forwards to DetachEvent(). 56 // JavaScript handler which forwards to DetachEvent().
(...skipping 22 matching lines...) Expand all
70 void DetachFilteredEventHandler( 79 void DetachFilteredEventHandler(
71 const v8::FunctionCallbackInfo<v8::Value>& args); 80 const v8::FunctionCallbackInfo<v8::Value>& args);
72 81
73 // Detaches a filtered event. Unlike a normal event, a filtered event is 82 // Detaches a filtered event. Unlike a normal event, a filtered event is
74 // identified by a unique ID per filter, not its name. 83 // identified by a unique ID per filter, not its name.
75 // |matcher_id| The ID of the filtered event. 84 // |matcher_id| The ID of the filtered event.
76 // |is_manual| false if this is part of the extension unload process where all 85 // |is_manual| false if this is part of the extension unload process where all
77 // listeners are automatically detached. 86 // listeners are automatically detached.
78 void DetachFilteredEvent(int matcher_id, bool is_manual); 87 void DetachFilteredEvent(int matcher_id, bool is_manual);
79 88
80 void MatchAgainstEventFilter(const v8::FunctionCallbackInfo<v8::Value>& args);
81
82 void AttachUnmanagedEvent(const v8::FunctionCallbackInfo<v8::Value>& args); 89 void AttachUnmanagedEvent(const v8::FunctionCallbackInfo<v8::Value>& args);
83 void DetachUnmanagedEvent(const v8::FunctionCallbackInfo<v8::Value>& args); 90 void DetachUnmanagedEvent(const v8::FunctionCallbackInfo<v8::Value>& args);
84 91
85 std::unique_ptr<EventMatcher> ParseEventMatcher( 92 std::unique_ptr<EventMatcher> ParseEventMatcher(
86 std::unique_ptr<base::DictionaryValue> filter); 93 std::unique_ptr<base::DictionaryValue> filter);
87 94
88 IPC::Sender* GetIPCSender(); 95 IPC::Sender* GetIPCSender();
89 96
90 // Called when our context, and therefore us, is invalidated. Run any cleanup. 97 // Called when our context, and therefore us, is invalidated. Run any cleanup.
91 void OnInvalidated(); 98 void OnInvalidated();
92 99
93 // The set of attached events and filtered events. Maintain these so that we 100 // The set of attached events and filtered events. Maintain these so that we
94 // can detch them on unload. 101 // can detch them on unload.
95 std::set<std::string> attached_event_names_; 102 std::set<std::string> attached_event_names_;
96 std::set<int> attached_matcher_ids_; 103 std::set<int> attached_matcher_ids_;
97 104
98 DISALLOW_COPY_AND_ASSIGN(EventBindings); 105 DISALLOW_COPY_AND_ASSIGN(EventBindings);
99 }; 106 };
100 107
101 } // namespace extensions 108 } // namespace extensions
102 109
103 #endif // EXTENSIONS_RENDERER_EVENT_BINDINGS_H_ 110 #endif // EXTENSIONS_RENDERER_EVENT_BINDINGS_H_
OLDNEW
« no previous file with comments | « chrome/test/data/extensions/api_test/bindings/event_filter/manifest.json ('k') | extensions/renderer/event_bindings.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698