OLD | NEW |
(Empty) | |
| 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 |
| 5 #ifndef EXTENSIONS_RENDERER_API_BINDING_BRIDGE_H_ |
| 6 #define EXTENSIONS_RENDERER_API_BINDING_BRIDGE_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/macros.h" |
| 11 #include "extensions/renderer/api_binding_types.h" |
| 12 #include "gin/wrappable.h" |
| 13 #include "v8/include/v8.h" |
| 14 |
| 15 namespace extensions { |
| 16 |
| 17 // An object that serves as a bridge between the current JS-centric bindings and |
| 18 // the new native bindings system. This basically needs to conform to the public |
| 19 // methods of the Binding prototype in binding.js. |
| 20 class APIBindingBridge final : public gin::Wrappable<APIBindingBridge> { |
| 21 public: |
| 22 APIBindingBridge(v8::Local<v8::Context> context, |
| 23 v8::Local<v8::Value> api_object, |
| 24 v8::Local<v8::Value> js_hook_interface, |
| 25 const std::string& extension_id, |
| 26 const std::string& context_type, |
| 27 const binding::RunJSFunction& run_js); |
| 28 ~APIBindingBridge() override; |
| 29 |
| 30 static gin::WrapperInfo kWrapperInfo; |
| 31 |
| 32 // gin::Wrappable: |
| 33 gin::ObjectTemplateBuilder GetObjectTemplateBuilder( |
| 34 v8::Isolate* isolate) final; |
| 35 |
| 36 private: |
| 37 // Runs the given function and registers custom hooks. |
| 38 // The function takes three arguments: an object, |
| 39 // { |
| 40 // apiFunctions: <JSHookInterface> (see api_bindings_hooks.cc), |
| 41 // compiledApi: <the API object> |
| 42 // } |
| 43 // as well as a string for the extension ID and a string for the context type. |
| 44 // This should register any hooks that the JS needs for the given API. |
| 45 void RegisterCustomHook(v8::Isolate* isolate, |
| 46 v8::Local<v8::Function> function); |
| 47 |
| 48 // The id of the extension that owns the context this belongs to. |
| 49 std::string extension_id_; |
| 50 |
| 51 // The type of context this belongs to. |
| 52 std::string context_type_; |
| 53 |
| 54 // A function to run JS safely. |
| 55 binding::RunJSFunction run_js_; |
| 56 |
| 57 DISALLOW_COPY_AND_ASSIGN(APIBindingBridge); |
| 58 }; |
| 59 |
| 60 } // namespace extensions |
| 61 |
| 62 #endif // EXTENSIONS_RENDERER_API_BINDING_BRIDGE_H_ |
OLD | NEW |