Roll WebRTC 9745:9761, Libjingle 9742:9761
[chromium-blink-merge.git] / extensions / renderer / event_bindings.h
blobad979fce22b39d4ea9f2dd410063859b88908ea5
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
3 // found in the LICENSE file.
5 #ifndef EXTENSIONS_RENDERER_EVENT_BINDINGS_H_
6 #define EXTENSIONS_RENDERER_EVENT_BINDINGS_H_
8 #include <set>
9 #include <string>
11 #include "base/macros.h"
12 #include "extensions/renderer/object_backed_native_handler.h"
13 #include "v8/include/v8.h"
15 namespace base {
16 class DictionaryValue;
19 namespace extensions {
20 class EventMatcher;
22 // This class deals with the javascript bindings related to Event objects.
23 class EventBindings : public ObjectBackedNativeHandler {
24 public:
25 explicit EventBindings(ScriptContext* context);
26 ~EventBindings() override;
28 private:
29 // JavaScript handler which forwards to AttachEvent().
30 // args[0] forwards to |event_name|.
31 void AttachEventHandler(const v8::FunctionCallbackInfo<v8::Value>& args);
33 // Attach an event name to an object.
34 // |event_name| The name of the event to attach.
35 void AttachEvent(const std::string& event_name);
37 // JavaScript handler which forwards to DetachEvent().
38 // args[0] forwards to |event_name|.
39 // args[1] forwards to |is_manual|.
40 void DetachEventHandler(const v8::FunctionCallbackInfo<v8::Value>& args);
42 // Detaches an event name from an object.
43 // |event_name| The name of the event to stop listening to.
44 // |is_manual| True if this detach was done by the user via removeListener()
45 // as opposed to automatically during shutdown, in which case we should inform
46 // the browser we are no longer interested in that event.
47 void DetachEvent(const std::string& event_name, bool is_manual);
49 // MatcherID AttachFilteredEvent(string event_name, object filter)
50 // |event_name| Name of the event to attach.
51 // |filter| Which instances of the named event are we interested in.
52 // returns the id assigned to the listener, which will be returned from calls
53 // to MatchAgainstEventFilter where this listener matches.
54 void AttachFilteredEvent(const v8::FunctionCallbackInfo<v8::Value>& args);
56 // JavaScript handler which forwards to DetachFilteredEvent.
57 // void DetachFilteredEvent(int id, bool manual)
58 // args[0] forwards to |matcher_id|
59 // args[1] forwards to |is_manual|
60 void DetachFilteredEventHandler(
61 const v8::FunctionCallbackInfo<v8::Value>& args);
63 // Detaches a filtered event. Unlike a normal event, a filtered event is
64 // identified by a unique ID per filter, not its name.
65 // |matcher_id| The ID of the filtered event.
66 // |is_manual| false if this is part of the extension unload process where all
67 // listeners are automatically detached.
68 void DetachFilteredEvent(int matcher_id, bool is_manual);
70 void MatchAgainstEventFilter(const v8::FunctionCallbackInfo<v8::Value>& args);
72 scoped_ptr<EventMatcher> ParseEventMatcher(
73 scoped_ptr<base::DictionaryValue> filter);
75 // Called when our context, and therefore us, is invalidated. Run any cleanup.
76 void OnInvalidated();
78 // The set of attached events and filtered events. Maintain these so that we
79 // can detch them on unload.
80 std::set<std::string> attached_event_names_;
81 std::set<int> attached_matcher_ids_;
83 DISALLOW_COPY_AND_ASSIGN(EventBindings);
86 } // namespace extensions
88 #endif // EXTENSIONS_RENDERER_EVENT_BINDINGS_H_