| 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_API_BINDINGS_SYSTEM_H_ | 5 #ifndef EXTENSIONS_RENDERER_API_BINDINGS_SYSTEM_H_ |
| 6 #define EXTENSIONS_RENDERER_API_BINDINGS_SYSTEM_H_ | 6 #define EXTENSIONS_RENDERER_API_BINDINGS_SYSTEM_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "extensions/renderer/api_binding.h" | 14 #include "extensions/renderer/api_binding.h" |
| 15 #include "extensions/renderer/api_binding_types.h" | 15 #include "extensions/renderer/api_binding_types.h" |
| 16 #include "extensions/renderer/api_event_handler.h" | 16 #include "extensions/renderer/api_event_handler.h" |
| 17 #include "extensions/renderer/api_last_error.h" |
| 17 #include "extensions/renderer/api_request_handler.h" | 18 #include "extensions/renderer/api_request_handler.h" |
| 18 #include "extensions/renderer/api_type_reference_map.h" | 19 #include "extensions/renderer/api_type_reference_map.h" |
| 19 | 20 |
| 20 namespace base { | 21 namespace base { |
| 21 class DictionaryValue; | 22 class DictionaryValue; |
| 22 class ListValue; | 23 class ListValue; |
| 23 } | 24 } |
| 24 | 25 |
| 25 namespace extensions { | 26 namespace extensions { |
| 26 class APIRequestHandler; | 27 class APIRequestHandler; |
| 27 | 28 |
| 28 // A class encompassing the necessary pieces to construct the JS entry points | 29 // A class encompassing the necessary pieces to construct the JS entry points |
| 29 // for Extension APIs. Designed to be used on a single thread, but safe between | 30 // for Extension APIs. Designed to be used on a single thread, but safe between |
| 30 // multiple v8::Contexts. | 31 // multiple v8::Contexts. |
| 31 class APIBindingsSystem { | 32 class APIBindingsSystem { |
| 32 public: | 33 public: |
| 33 using GetAPISchemaMethod = | 34 using GetAPISchemaMethod = |
| 34 base::Callback<const base::DictionaryValue&(const std::string&)>; | 35 base::Callback<const base::DictionaryValue&(const std::string&)>; |
| 35 | 36 |
| 36 APIBindingsSystem(const binding::RunJSFunction& call_js, | 37 APIBindingsSystem(const binding::RunJSFunction& call_js, |
| 37 const binding::RunJSFunctionSync& call_js_sync, | 38 const binding::RunJSFunctionSync& call_js_sync, |
| 38 const GetAPISchemaMethod& get_api_schema, | 39 const GetAPISchemaMethod& get_api_schema, |
| 39 const APIBinding::SendRequestMethod& send_request, | 40 const APIBinding::SendRequestMethod& send_request, |
| 40 const APIEventHandler::EventListenersChangedMethod& | 41 const APIEventHandler::EventListenersChangedMethod& |
| 41 event_listeners_changed); | 42 event_listeners_changed, |
| 43 APILastError last_error); |
| 42 ~APIBindingsSystem(); | 44 ~APIBindingsSystem(); |
| 43 | 45 |
| 44 // Returns a new v8::Object representing the api specified by |api_name|. | 46 // Returns a new v8::Object representing the api specified by |api_name|. |
| 45 v8::Local<v8::Object> CreateAPIInstance( | 47 v8::Local<v8::Object> CreateAPIInstance( |
| 46 const std::string& api_name, | 48 const std::string& api_name, |
| 47 v8::Local<v8::Context> context, | 49 v8::Local<v8::Context> context, |
| 48 v8::Isolate* isolate, | 50 v8::Isolate* isolate, |
| 49 const APIBinding::AvailabilityCallback& is_available, | 51 const APIBinding::AvailabilityCallback& is_available, |
| 50 v8::Local<v8::Object>* hooks_interface_out); | 52 v8::Local<v8::Object>* hooks_interface_out); |
| 51 | 53 |
| 52 // Responds to the request with the given |request_id|, calling the callback | 54 // Responds to the request with the given |request_id|, calling the callback |
| 53 // with |response|. | 55 // with |response|. If |error| is non-empty, sets the last error. |
| 54 void CompleteRequest(int request_id, const base::ListValue& response); | 56 void CompleteRequest(int request_id, |
| 57 const base::ListValue& response, |
| 58 const std::string& error); |
| 55 | 59 |
| 56 // Notifies the APIEventHandler to fire the corresponding event, notifying | 60 // Notifies the APIEventHandler to fire the corresponding event, notifying |
| 57 // listeners. | 61 // listeners. |
| 58 void FireEventInContext(const std::string& event_name, | 62 void FireEventInContext(const std::string& event_name, |
| 59 v8::Local<v8::Context> context, | 63 v8::Local<v8::Context> context, |
| 60 const base::ListValue& response); | 64 const base::ListValue& response); |
| 61 | 65 |
| 62 // Returns the APIBindingHooks object for the given api to allow for | 66 // Returns the APIBindingHooks object for the given api to allow for |
| 63 // registering custom hooks. These must be registered *before* the | 67 // registering custom hooks. These must be registered *before* the |
| 64 // binding is instantiated. | 68 // binding is instantiated. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 // purposes. Typically, this would send an IPC to the browser to begin the | 110 // purposes. Typically, this would send an IPC to the browser to begin the |
| 107 // function work. | 111 // function work. |
| 108 APIBinding::SendRequestMethod send_request_; | 112 APIBinding::SendRequestMethod send_request_; |
| 109 | 113 |
| 110 DISALLOW_COPY_AND_ASSIGN(APIBindingsSystem); | 114 DISALLOW_COPY_AND_ASSIGN(APIBindingsSystem); |
| 111 }; | 115 }; |
| 112 | 116 |
| 113 } // namespace | 117 } // namespace |
| 114 | 118 |
| 115 #endif // EXTENSIONS_RENDERER_API_BINDINGS_SYSTEM_H_ | 119 #endif // EXTENSIONS_RENDERER_API_BINDINGS_SYSTEM_H_ |
| OLD | NEW |