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

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

Issue 2936673004: Revert of [Extensions Bindings] Avoid passing the event filter to JS (Closed)
Patch Set: 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;
23 } 22 }
24 23
25 namespace extensions { 24 namespace extensions {
26 class EventMatcher; 25 class EventMatcher;
27 26
28 // This class deals with the javascript bindings related to Event objects. 27 // This class deals with the javascript bindings related to Event objects.
29 class EventBindings : public ObjectBackedNativeHandler { 28 class EventBindings : public ObjectBackedNativeHandler {
30 public: 29 public:
31 explicit EventBindings(ScriptContext* context); 30 explicit EventBindings(ScriptContext* context);
32 ~EventBindings() override; 31 ~EventBindings() override;
33 32
34 // Returns true if there is a listener for the given |event| in the given 33 // Returns true if there is a listener for the given |event| in the given
35 // |context|. 34 // |context|.
36 static bool HasListener(ScriptContext* context, 35 static bool HasListener(ScriptContext* context,
37 const std::string& event_name); 36 const std::string& event_name);
38 37
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
47 private: 38 private:
48 // JavaScript handler which forwards to AttachEvent(). 39 // JavaScript handler which forwards to AttachEvent().
49 // args[0] forwards to |event_name|. 40 // args[0] forwards to |event_name|.
50 void AttachEventHandler(const v8::FunctionCallbackInfo<v8::Value>& args); 41 void AttachEventHandler(const v8::FunctionCallbackInfo<v8::Value>& args);
51 42
52 // Attach an event name to an object. 43 // Attach an event name to an object.
53 // |event_name| The name of the event to attach. 44 // |event_name| The name of the event to attach.
54 void AttachEvent(const std::string& event_name); 45 void AttachEvent(const std::string& event_name);
55 46
56 // JavaScript handler which forwards to DetachEvent(). 47 // JavaScript handler which forwards to DetachEvent().
(...skipping 22 matching lines...) Expand all
79 void DetachFilteredEventHandler( 70 void DetachFilteredEventHandler(
80 const v8::FunctionCallbackInfo<v8::Value>& args); 71 const v8::FunctionCallbackInfo<v8::Value>& args);
81 72
82 // 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
83 // identified by a unique ID per filter, not its name. 74 // identified by a unique ID per filter, not its name.
84 // |matcher_id| The ID of the filtered event. 75 // |matcher_id| The ID of the filtered event.
85 // |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
86 // listeners are automatically detached. 77 // listeners are automatically detached.
87 void DetachFilteredEvent(int matcher_id, bool is_manual); 78 void DetachFilteredEvent(int matcher_id, bool is_manual);
88 79
80 void MatchAgainstEventFilter(const v8::FunctionCallbackInfo<v8::Value>& args);
81
89 void AttachUnmanagedEvent(const v8::FunctionCallbackInfo<v8::Value>& args); 82 void AttachUnmanagedEvent(const v8::FunctionCallbackInfo<v8::Value>& args);
90 void DetachUnmanagedEvent(const v8::FunctionCallbackInfo<v8::Value>& args); 83 void DetachUnmanagedEvent(const v8::FunctionCallbackInfo<v8::Value>& args);
91 84
92 std::unique_ptr<EventMatcher> ParseEventMatcher( 85 std::unique_ptr<EventMatcher> ParseEventMatcher(
93 std::unique_ptr<base::DictionaryValue> filter); 86 std::unique_ptr<base::DictionaryValue> filter);
94 87
95 IPC::Sender* GetIPCSender(); 88 IPC::Sender* GetIPCSender();
96 89
97 // 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.
98 void OnInvalidated(); 91 void OnInvalidated();
99 92
100 // 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
101 // can detch them on unload. 94 // can detch them on unload.
102 std::set<std::string> attached_event_names_; 95 std::set<std::string> attached_event_names_;
103 std::set<int> attached_matcher_ids_; 96 std::set<int> attached_matcher_ids_;
104 97
105 DISALLOW_COPY_AND_ASSIGN(EventBindings); 98 DISALLOW_COPY_AND_ASSIGN(EventBindings);
106 }; 99 };
107 100
108 } // namespace extensions 101 } // namespace extensions
109 102
110 #endif // EXTENSIONS_RENDERER_EVENT_BINDINGS_H_ 103 #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