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_
11 #include "base/macros.h"
12 #include "extensions/renderer/object_backed_native_handler.h"
13 #include "v8/include/v8.h"
16 class DictionaryValue
;
19 namespace extensions
{
22 // This class deals with the javascript bindings related to Event objects.
23 class EventBindings
: public ObjectBackedNativeHandler
{
25 explicit EventBindings(ScriptContext
* context
);
26 ~EventBindings() override
;
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 // void DetachFilteredEvent(int id, bool manual)
57 // id - Id of the event to detach.
58 // manual - false if this is part of the extension unload process where all
59 // listeners are automatically detached.
60 void DetachFilteredEvent(const v8::FunctionCallbackInfo
<v8::Value
>& args
);
62 void MatchAgainstEventFilter(const v8::FunctionCallbackInfo
<v8::Value
>& args
);
64 scoped_ptr
<EventMatcher
> ParseEventMatcher(
65 base::DictionaryValue
* filter_dict
);
67 // Called when our context, and therefore us, is invalidated. Run any cleanup.
70 // The set of attached events. Maintain this so that we can detch them on
72 std::set
<std::string
> attached_event_names_
;
74 DISALLOW_COPY_AND_ASSIGN(EventBindings
);
77 } // namespace extensions
79 #endif // EXTENSIONS_RENDERER_EVENT_BINDINGS_H_