| 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_BINDINGS_API_BINDINGS_SYSTEM_H_ | 5 #ifndef EXTENSIONS_RENDERER_BINDINGS_API_BINDINGS_SYSTEM_H_ |
| 6 #define EXTENSIONS_RENDERER_BINDINGS_API_BINDINGS_SYSTEM_H_ | 6 #define EXTENSIONS_RENDERER_BINDINGS_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/bindings/api_binding.h" | 14 #include "extensions/renderer/bindings/api_binding.h" |
| 15 #include "extensions/renderer/bindings/api_binding_types.h" | 15 #include "extensions/renderer/bindings/api_binding_types.h" |
| 16 #include "extensions/renderer/bindings/api_event_handler.h" | 16 #include "extensions/renderer/bindings/api_event_handler.h" |
| 17 #include "extensions/renderer/bindings/api_last_error.h" | 17 #include "extensions/renderer/bindings/api_last_error.h" |
| 18 #include "extensions/renderer/bindings/api_request_handler.h" | 18 #include "extensions/renderer/bindings/api_request_handler.h" |
| 19 #include "extensions/renderer/bindings/api_type_reference_map.h" | 19 #include "extensions/renderer/bindings/api_type_reference_map.h" |
| 20 #include "extensions/renderer/bindings/binding_access_checker.h" | 20 #include "extensions/renderer/bindings/binding_access_checker.h" |
| 21 #include "extensions/renderer/bindings/exception_handler.h" |
| 21 | 22 |
| 22 namespace base { | 23 namespace base { |
| 23 class DictionaryValue; | 24 class DictionaryValue; |
| 24 class ListValue; | 25 class ListValue; |
| 25 } | 26 } |
| 26 | 27 |
| 27 namespace extensions { | 28 namespace extensions { |
| 28 class APIBindingHooks; | 29 class APIBindingHooks; |
| 29 | 30 |
| 30 // A class encompassing the necessary pieces to construct the JS entry points | 31 // A class encompassing the necessary pieces to construct the JS entry points |
| (...skipping 14 matching lines...) Expand all Loading... |
| 45 | 46 |
| 46 APIBindingsSystem( | 47 APIBindingsSystem( |
| 47 const binding::RunJSFunction& call_js, | 48 const binding::RunJSFunction& call_js, |
| 48 const binding::RunJSFunctionSync& call_js_sync, | 49 const binding::RunJSFunctionSync& call_js_sync, |
| 49 const GetAPISchemaMethod& get_api_schema, | 50 const GetAPISchemaMethod& get_api_schema, |
| 50 const BindingAccessChecker::AvailabilityCallback& is_available, | 51 const BindingAccessChecker::AvailabilityCallback& is_available, |
| 51 const APIRequestHandler::SendRequestMethod& send_request, | 52 const APIRequestHandler::SendRequestMethod& send_request, |
| 52 const APIEventHandler::EventListenersChangedMethod& | 53 const APIEventHandler::EventListenersChangedMethod& |
| 53 event_listeners_changed, | 54 event_listeners_changed, |
| 54 const APIBinding::OnSilentRequest& on_silent_request, | 55 const APIBinding::OnSilentRequest& on_silent_request, |
| 56 const binding::AddConsoleError& add_console_error, |
| 55 APILastError last_error); | 57 APILastError last_error); |
| 56 ~APIBindingsSystem(); | 58 ~APIBindingsSystem(); |
| 57 | 59 |
| 58 // Returns a new v8::Object representing the api specified by |api_name|. | 60 // Returns a new v8::Object representing the api specified by |api_name|. |
| 59 v8::Local<v8::Object> CreateAPIInstance( | 61 v8::Local<v8::Object> CreateAPIInstance( |
| 60 const std::string& api_name, | 62 const std::string& api_name, |
| 61 v8::Local<v8::Context> context, | 63 v8::Local<v8::Context> context, |
| 62 APIBindingHooks** hooks_out); | 64 APIBindingHooks** hooks_out); |
| 63 | 65 |
| 64 // Responds to the request with the given |request_id|, calling the callback | 66 // Responds to the request with the given |request_id|, calling the callback |
| (...skipping 23 matching lines...) Expand all Loading... |
| 88 // storage.StorageArea). | 90 // storage.StorageArea). |
| 89 void RegisterCustomType(const std::string& type_name, | 91 void RegisterCustomType(const std::string& type_name, |
| 90 const CustomTypeHandler& function); | 92 const CustomTypeHandler& function); |
| 91 | 93 |
| 92 // Handles any cleanup necessary before releasing the given |context|. | 94 // Handles any cleanup necessary before releasing the given |context|. |
| 93 void WillReleaseContext(v8::Local<v8::Context> context); | 95 void WillReleaseContext(v8::Local<v8::Context> context); |
| 94 | 96 |
| 95 APIRequestHandler* request_handler() { return &request_handler_; } | 97 APIRequestHandler* request_handler() { return &request_handler_; } |
| 96 APIEventHandler* event_handler() { return &event_handler_; } | 98 APIEventHandler* event_handler() { return &event_handler_; } |
| 97 APITypeReferenceMap* type_reference_map() { return &type_reference_map_; } | 99 APITypeReferenceMap* type_reference_map() { return &type_reference_map_; } |
| 100 ExceptionHandler* exception_handler() { return &exception_handler_; } |
| 98 | 101 |
| 99 private: | 102 private: |
| 100 // Creates a new APIBinding for the given |api_name|. | 103 // Creates a new APIBinding for the given |api_name|. |
| 101 std::unique_ptr<APIBinding> CreateNewAPIBinding(const std::string& api_name); | 104 std::unique_ptr<APIBinding> CreateNewAPIBinding(const std::string& api_name); |
| 102 | 105 |
| 103 // Callback for the APITypeReferenceMap in order to initialize an unknown | 106 // Callback for the APITypeReferenceMap in order to initialize an unknown |
| 104 // type. | 107 // type. |
| 105 void InitializeType(const std::string& name); | 108 void InitializeType(const std::string& name); |
| 106 | 109 |
| 107 // Handles creating the type for the specified property. | 110 // Handles creating the type for the specified property. |
| 108 v8::Local<v8::Object> CreateCustomType( | 111 v8::Local<v8::Object> CreateCustomType( |
| 109 v8::Isolate* isolate, | 112 v8::Isolate* isolate, |
| 110 const std::string& type_name, | 113 const std::string& type_name, |
| 111 const std::string& property_name, | 114 const std::string& property_name, |
| 112 const base::ListValue* property_values); | 115 const base::ListValue* property_values); |
| 113 | 116 |
| 114 // The map of cached API reference types. | 117 // The map of cached API reference types. |
| 115 APITypeReferenceMap type_reference_map_; | 118 APITypeReferenceMap type_reference_map_; |
| 116 | 119 |
| 120 // The exception handler for the system. |
| 121 ExceptionHandler exception_handler_; |
| 122 |
| 117 // The request handler associated with the system. | 123 // The request handler associated with the system. |
| 118 APIRequestHandler request_handler_; | 124 APIRequestHandler request_handler_; |
| 119 | 125 |
| 120 // The event handler associated with the system. | 126 // The event handler associated with the system. |
| 121 APIEventHandler event_handler_; | 127 APIEventHandler event_handler_; |
| 122 | 128 |
| 123 // The access checker associated with the system. | 129 // The access checker associated with the system. |
| 124 BindingAccessChecker access_checker_; | 130 BindingAccessChecker access_checker_; |
| 125 | 131 |
| 126 // A map from api_name -> APIBinding for constructed APIs. APIBindings are | 132 // A map from api_name -> APIBinding for constructed APIs. APIBindings are |
| (...skipping 18 matching lines...) Expand all Loading... |
| 145 // The method to call when the system silently handles an API request without | 151 // The method to call when the system silently handles an API request without |
| 146 // notifying the browser. | 152 // notifying the browser. |
| 147 APIBinding::OnSilentRequest on_silent_request_; | 153 APIBinding::OnSilentRequest on_silent_request_; |
| 148 | 154 |
| 149 DISALLOW_COPY_AND_ASSIGN(APIBindingsSystem); | 155 DISALLOW_COPY_AND_ASSIGN(APIBindingsSystem); |
| 150 }; | 156 }; |
| 151 | 157 |
| 152 } // namespace | 158 } // namespace |
| 153 | 159 |
| 154 #endif // EXTENSIONS_RENDERER_BINDINGS_API_BINDINGS_SYSTEM_H_ | 160 #endif // EXTENSIONS_RENDERER_BINDINGS_API_BINDINGS_SYSTEM_H_ |
| OLD | NEW |