api_binding_bridge.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright 2016 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_BRIDGE_H_
  5. #define EXTENSIONS_RENDERER_BINDINGS_API_BINDING_BRIDGE_H_
  6. #include <string>
  7. #include "gin/wrappable.h"
  8. #include "v8/include/v8.h"
  9. namespace extensions {
  10. class APIBindingHooks;
  11. // An object that serves as a bridge between the current JS-centric bindings and
  12. // the new native bindings system. This basically needs to conform to the public
  13. // methods of the Binding prototype in binding.js.
  14. class APIBindingBridge final : public gin::Wrappable<APIBindingBridge> {
  15. public:
  16. APIBindingBridge(APIBindingHooks* hooks,
  17. v8::Local<v8::Context> context,
  18. v8::Local<v8::Value> api_object,
  19. const std::string& extension_id,
  20. const std::string& context_type);
  21. APIBindingBridge(const APIBindingBridge&) = delete;
  22. APIBindingBridge& operator=(const APIBindingBridge&) = delete;
  23. ~APIBindingBridge() override;
  24. static gin::WrapperInfo kWrapperInfo;
  25. // gin::Wrappable:
  26. gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
  27. v8::Isolate* isolate) final;
  28. private:
  29. // Runs the given function and registers custom hooks.
  30. // The function takes three arguments: an object,
  31. // {
  32. // apiFunctions: <JSHookInterface> (see api_bindings_hooks.cc),
  33. // compiledApi: <the API object>
  34. // }
  35. // as well as a string for the extension ID and a string for the context type.
  36. // This should register any hooks that the JS needs for the given API.
  37. void RegisterCustomHook(v8::Isolate* isolate,
  38. v8::Local<v8::Function> function);
  39. // The id of the extension that owns the context this belongs to.
  40. std::string extension_id_;
  41. // The type of context this belongs to.
  42. std::string context_type_;
  43. };
  44. } // namespace extensions
  45. #endif // EXTENSIONS_RENDERER_BINDINGS_API_BINDING_BRIDGE_H_