summaryrefslogtreecommitdiff
path: root/chromium/extensions/renderer/bindings/declarative_event.h
blob: 5566fa889cbaf9b20cb09ec1031e966f6b940a8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef EXTENSIONS_RENDERER_BINDINGS_DECLARATIVE_EVENT_H_
#define EXTENSIONS_RENDERER_BINDINGS_DECLARATIVE_EVENT_H_

#include <vector>

#include "gin/wrappable.h"
#include "v8/include/v8.h"

namespace gin {
class Arguments;
}

namespace extensions {
class APIRequestHandler;
class APITypeReferenceMap;

// A gin::Wrappable object for declarative events (i.e., events that support
// "rules"). Unlike regular events, these do not have associated listeners, and
// extensions register an action to perform when the event happens.
class DeclarativeEvent final : public gin::Wrappable<DeclarativeEvent> {
 public:
  DeclarativeEvent(const std::string& name,
                   APITypeReferenceMap* type_refs,
                   APIRequestHandler* request_handler,
                   const std::vector<std::string>& actions_list,
                   const std::vector<std::string>& conditions_list,
                   int webview_instance_id);
  ~DeclarativeEvent() override;

  static gin::WrapperInfo kWrapperInfo;

  // gin::Wrappable:
  gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
      v8::Isolate* isolate) final;

 private:
  // Bound methods for the JS object.
  void AddRules(gin::Arguments* arguments);
  void RemoveRules(gin::Arguments* arguments);
  void GetRules(gin::Arguments* arguments);

  void HandleFunction(const std::string& signature_name,
                      const std::string& request_name,
                      gin::Arguments* arguments);

  std::string event_name_;

  APITypeReferenceMap* type_refs_;

  APIRequestHandler* request_handler_;

  const int webview_instance_id_;

  DISALLOW_COPY_AND_ASSIGN(DeclarativeEvent);
};

}  // namespace extensions

#endif  // EXTENSIONS_RENDERER_BINDINGS_DECLARATIVE_EVENT_H_