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