| 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 #include "extensions/renderer/api_bindings_system.h" | 5 #include "extensions/renderer/api_bindings_system.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "extensions/renderer/api_binding_hooks.h" | 10 #include "extensions/renderer/api_binding_hooks.h" |
| 11 | 11 |
| 12 namespace extensions { | 12 namespace extensions { |
| 13 | 13 |
| 14 APIBindingsSystem::APIBindingsSystem( | 14 APIBindingsSystem::APIBindingsSystem( |
| 15 const binding::RunJSFunction& call_js, | 15 const binding::RunJSFunction& call_js, |
| 16 const binding::RunJSFunctionSync& call_js_sync, | 16 const binding::RunJSFunctionSync& call_js_sync, |
| 17 const GetAPISchemaMethod& get_api_schema, | 17 const GetAPISchemaMethod& get_api_schema, |
| 18 const APIBinding::SendRequestMethod& send_request, | 18 const APIBinding::SendRequestMethod& send_request, |
| 19 const APIEventHandler::EventListenersChangedMethod& event_listeners_changed) | 19 const APIEventHandler::EventListenersChangedMethod& event_listeners_changed, |
| 20 : request_handler_(call_js), | 20 APILastError last_error) |
| 21 : request_handler_(call_js, std::move(last_error)), |
| 21 event_handler_(call_js, event_listeners_changed), | 22 event_handler_(call_js, event_listeners_changed), |
| 22 call_js_(call_js), | 23 call_js_(call_js), |
| 23 call_js_sync_(call_js_sync), | 24 call_js_sync_(call_js_sync), |
| 24 get_api_schema_(get_api_schema), | 25 get_api_schema_(get_api_schema), |
| 25 send_request_(send_request) {} | 26 send_request_(send_request) {} |
| 26 | 27 |
| 27 APIBindingsSystem::~APIBindingsSystem() {} | 28 APIBindingsSystem::~APIBindingsSystem() {} |
| 28 | 29 |
| 29 v8::Local<v8::Object> APIBindingsSystem::CreateAPIInstance( | 30 v8::Local<v8::Object> APIBindingsSystem::CreateAPIInstance( |
| 30 const std::string& api_name, | 31 const std::string& api_name, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 } else { | 65 } else { |
| 65 hooks = base::MakeUnique<APIBindingHooks>(call_js_sync_); | 66 hooks = base::MakeUnique<APIBindingHooks>(call_js_sync_); |
| 66 } | 67 } |
| 67 | 68 |
| 68 return base::MakeUnique<APIBinding>( | 69 return base::MakeUnique<APIBinding>( |
| 69 api_name, function_definitions, type_definitions, event_definitions, | 70 api_name, function_definitions, type_definitions, event_definitions, |
| 70 send_request_, std::move(hooks), &type_reference_map_, &request_handler_); | 71 send_request_, std::move(hooks), &type_reference_map_, &request_handler_); |
| 71 } | 72 } |
| 72 | 73 |
| 73 void APIBindingsSystem::CompleteRequest(int request_id, | 74 void APIBindingsSystem::CompleteRequest(int request_id, |
| 74 const base::ListValue& response) { | 75 const base::ListValue& response, |
| 75 request_handler_.CompleteRequest(request_id, response); | 76 const std::string& error) { |
| 77 request_handler_.CompleteRequest(request_id, response, error); |
| 76 } | 78 } |
| 77 | 79 |
| 78 void APIBindingsSystem::FireEventInContext(const std::string& event_name, | 80 void APIBindingsSystem::FireEventInContext(const std::string& event_name, |
| 79 v8::Local<v8::Context> context, | 81 v8::Local<v8::Context> context, |
| 80 const base::ListValue& response) { | 82 const base::ListValue& response) { |
| 81 event_handler_.FireEventInContext(event_name, context, response); | 83 event_handler_.FireEventInContext(event_name, context, response); |
| 82 } | 84 } |
| 83 | 85 |
| 84 APIBindingHooks* APIBindingsSystem::GetHooksForAPI( | 86 APIBindingHooks* APIBindingsSystem::GetHooksForAPI( |
| 85 const std::string& api_name) { | 87 const std::string& api_name) { |
| 86 DCHECK(api_bindings_.empty()) | 88 DCHECK(api_bindings_.empty()) |
| 87 << "Hook registration must happen before creating any binding instances."; | 89 << "Hook registration must happen before creating any binding instances."; |
| 88 std::unique_ptr<APIBindingHooks>& hooks = binding_hooks_[api_name]; | 90 std::unique_ptr<APIBindingHooks>& hooks = binding_hooks_[api_name]; |
| 89 if (!hooks) | 91 if (!hooks) |
| 90 hooks = base::MakeUnique<APIBindingHooks>(call_js_sync_); | 92 hooks = base::MakeUnique<APIBindingHooks>(call_js_sync_); |
| 91 return hooks.get(); | 93 return hooks.get(); |
| 92 } | 94 } |
| 93 | 95 |
| 94 } // namespace extensions | 96 } // namespace extensions |
| OLD | NEW |