api_binding_hooks_delegate.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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_API_BINDING_HOOKS_DELEGATE_H_
  5. #define EXTENSIONS_RENDERER_BINDINGS_API_BINDING_HOOKS_DELEGATE_H_
  6. #include "extensions/renderer/bindings/api_binding_hooks.h"
  7. #include "v8/include/v8.h"
  8. namespace extensions {
  9. class APITypeReferenceMap;
  10. // A per-API set of custom hooks to override the default behavior.
  11. class APIBindingHooksDelegate {
  12. public:
  13. virtual ~APIBindingHooksDelegate();
  14. // Allows custom implementations to return a different event object.
  15. // Populates |event_out| and returns true if a custom implementation should
  16. // be used, otherwise returns false.
  17. virtual bool CreateCustomEvent(v8::Local<v8::Context> context,
  18. const std::string& event_name,
  19. v8::Local<v8::Value>* event_out);
  20. // Allows custom implementations to handle a given request.
  21. virtual APIBindingHooks::RequestResult HandleRequest(
  22. const std::string& method_name,
  23. const APISignature* signature,
  24. v8::Local<v8::Context> context,
  25. std::vector<v8::Local<v8::Value>>* arguments,
  26. const APITypeReferenceMap& refs);
  27. // Allows custom implementations to add additional properties or types to an
  28. // API object.
  29. virtual void InitializeTemplate(v8::Isolate* isolate,
  30. v8::Local<v8::ObjectTemplate> object_template,
  31. const APITypeReferenceMap& type_refs) {}
  32. // Allows custom implementations to mutate an instance of the API for a
  33. // specific context.
  34. virtual void InitializeInstance(v8::Local<v8::Context> context,
  35. v8::Local<v8::Object> instance) {}
  36. };
  37. } // namespace extensions
  38. #endif // EXTENSIONS_RENDERER_BINDINGS_API_BINDING_HOOKS_DELEGATE_H_