| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef EXTENSIONS_RENDERER_NATIVE_EXTENSION_BINDINGS_SYSTEM_H_ | 5 #ifndef EXTENSIONS_RENDERER_NATIVE_EXTENSION_BINDINGS_SYSTEM_H_ |
| 6 #define EXTENSIONS_RENDERER_NATIVE_EXTENSION_BINDINGS_SYSTEM_H_ | 6 #define EXTENSIONS_RENDERER_NATIVE_EXTENSION_BINDINGS_SYSTEM_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "extensions/common/extension_messages.h" | 12 #include "extensions/common/extension_messages.h" |
| 13 #include "extensions/renderer/api_bindings_system.h" | 13 #include "extensions/renderer/api_bindings_system.h" |
| 14 #include "extensions/renderer/extension_bindings_system.h" |
| 14 #include "v8/include/v8.h" | 15 #include "v8/include/v8.h" |
| 15 | 16 |
| 16 namespace extensions { | 17 namespace extensions { |
| 17 class ScriptContext; | 18 class ScriptContext; |
| 18 | 19 |
| 19 // The implementation of the Bindings System for extensions code with native | 20 // The implementation of the Bindings System for extensions code with native |
| 20 // implementations (rather than JS hooks). Handles permission/availability | 21 // implementations (rather than JS hooks). Handles permission/availability |
| 21 // checking and creates all bindings available for a given context. Sending the | 22 // checking and creates all bindings available for a given context. Sending the |
| 22 // IPC is still abstracted out for testing purposes, but otherwise this should | 23 // IPC is still abstracted out for testing purposes, but otherwise this should |
| 23 // be a plug-and-play version for use in the Extensions system. | 24 // be a plug-and-play version for use in the Extensions system. |
| 24 // Designed to be used in a single thread, but for all contexts on that thread. | 25 // Designed to be used in a single thread, but for all contexts on that thread. |
| 25 class NativeExtensionBindingsSystem { | 26 class NativeExtensionBindingsSystem : public ExtensionBindingsSystem { |
| 26 public: | 27 public: |
| 27 using SendIPCMethod = | 28 using SendIPCMethod = |
| 28 base::Callback<void(const ExtensionHostMsg_Request_Params&)>; | 29 base::Callback<void(const ExtensionHostMsg_Request_Params&)>; |
| 29 | 30 |
| 30 explicit NativeExtensionBindingsSystem(const SendIPCMethod& send_ipc); | 31 explicit NativeExtensionBindingsSystem(const SendIPCMethod& send_ipc); |
| 31 ~NativeExtensionBindingsSystem(); | 32 ~NativeExtensionBindingsSystem() override; |
| 32 | 33 |
| 33 // Creates the "chrome" object (if it doesn't already exist) and instantiates | 34 // ExtensionBindingsSystem: |
| 34 // the individual APIs on top of it. Only exposes those APIs available to the | 35 void DidCreateScriptContext(ScriptContext* context) override; |
| 35 // given context. | 36 void WillReleaseScriptContext(ScriptContext* context) override; |
| 36 void CreateAPIsInContext(ScriptContext* context); | 37 void UpdateBindingsForContext(ScriptContext* context) override; |
| 37 | 38 void DispatchEventInContext(const std::string& event_name, |
| 38 // Handles responding to a given request. This signature matches the arguments | 39 const base::ListValue* event_args, |
| 39 // given to the response IPC. | 40 const base::DictionaryValue* filtering_info, |
| 40 void OnResponse(int request_id, | 41 ScriptContext* context) override; |
| 41 bool success, | 42 void HandleResponse(int request_id, |
| 42 const base::ListValue& response, | 43 bool success, |
| 43 const std::string& error); | 44 const base::ListValue& response, |
| 45 const std::string& error) override; |
| 46 RequestSender* GetRequestSender() override; |
| 44 | 47 |
| 45 private: | 48 private: |
| 46 // Handles sending a given |request|, forwarding it on to the send_ipc_ after | 49 // Handles sending a given |request|, forwarding it on to the send_ipc_ after |
| 47 // adding additional info. | 50 // adding additional info. |
| 48 void SendRequest(std::unique_ptr<APIBindingsSystem::Request> request, | 51 void SendRequest(std::unique_ptr<APIBindingsSystem::Request> request, |
| 49 v8::Local<v8::Context> context); | 52 v8::Local<v8::Context> context); |
| 50 | 53 |
| 51 // Handler to send IPCs. Abstracted out for testing purposes. | 54 // Handler to send IPCs. Abstracted out for testing purposes. |
| 52 SendIPCMethod send_ipc_; | 55 SendIPCMethod send_ipc_; |
| 53 | 56 |
| 54 // The APIBindingsSystem associated with this class. | 57 // The APIBindingsSystem associated with this class. |
| 55 APIBindingsSystem api_system_; | 58 APIBindingsSystem api_system_; |
| 56 | 59 |
| 57 DISALLOW_COPY_AND_ASSIGN(NativeExtensionBindingsSystem); | 60 DISALLOW_COPY_AND_ASSIGN(NativeExtensionBindingsSystem); |
| 58 }; | 61 }; |
| 59 | 62 |
| 60 } // namespace extensions | 63 } // namespace extensions |
| 61 | 64 |
| 62 #endif // EXTENSIONS_RENDERER_NATIVE_EXTENSION_BINDINGS_SYSTEM_H_ | 65 #endif // EXTENSIONS_RENDERER_NATIVE_EXTENSION_BINDINGS_SYSTEM_H_ |
| OLD | NEW |