declarative_event.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright 2017 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.
  4. #ifndef EXTENSIONS_RENDERER_BINDINGS_DECLARATIVE_EVENT_H_
  5. #define EXTENSIONS_RENDERER_BINDINGS_DECLARATIVE_EVENT_H_
  6. #include <vector>
  7. #include "gin/wrappable.h"
  8. #include "v8/include/v8.h"
  9. namespace gin {
  10. class Arguments;
  11. }
  12. namespace extensions {
  13. class APIRequestHandler;
  14. class APITypeReferenceMap;
  15. // A gin::Wrappable object for declarative events (i.e., events that support
  16. // "rules"). Unlike regular events, these do not have associated listeners, and
  17. // extensions register an action to perform when the event happens.
  18. class DeclarativeEvent final : public gin::Wrappable<DeclarativeEvent> {
  19. public:
  20. DeclarativeEvent(const std::string& name,
  21. APITypeReferenceMap* type_refs,
  22. APIRequestHandler* request_handler,
  23. const std::vector<std::string>& actions_list,
  24. const std::vector<std::string>& conditions_list,
  25. int webview_instance_id);
  26. DeclarativeEvent(const DeclarativeEvent&) = delete;
  27. DeclarativeEvent& operator=(const DeclarativeEvent&) = delete;
  28. ~DeclarativeEvent() override;
  29. static gin::WrapperInfo kWrapperInfo;
  30. // gin::Wrappable:
  31. gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
  32. v8::Isolate* isolate) final;
  33. const char* GetTypeName() override;
  34. private:
  35. // Bound methods for the JS object.
  36. void AddRules(gin::Arguments* arguments);
  37. void RemoveRules(gin::Arguments* arguments);
  38. void GetRules(gin::Arguments* arguments);
  39. void HandleFunction(const std::string& signature_name,
  40. const std::string& request_name,
  41. gin::Arguments* arguments);
  42. std::string event_name_;
  43. APITypeReferenceMap* type_refs_;
  44. APIRequestHandler* request_handler_;
  45. const int webview_instance_id_;
  46. };
  47. } // namespace extensions
  48. #endif // EXTENSIONS_RENDERER_BINDINGS_DECLARATIVE_EVENT_H_