Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(393)

Side by Side Diff: extensions/renderer/api_bindings_system.cc

Issue 2575173002: [Extensions Bindings] Add a bridge to use current custom bindings (Closed)
Patch Set: . Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 11 matching lines...) Expand all
22 call_js_(call_js), 22 call_js_(call_js),
23 get_api_schema_(get_api_schema), 23 get_api_schema_(get_api_schema),
24 send_request_(send_request) {} 24 send_request_(send_request) {}
25 25
26 APIBindingsSystem::~APIBindingsSystem() {} 26 APIBindingsSystem::~APIBindingsSystem() {}
27 27
28 v8::Local<v8::Object> APIBindingsSystem::CreateAPIInstance( 28 v8::Local<v8::Object> APIBindingsSystem::CreateAPIInstance(
29 const std::string& api_name, 29 const std::string& api_name,
30 v8::Local<v8::Context> context, 30 v8::Local<v8::Context> context,
31 v8::Isolate* isolate, 31 v8::Isolate* isolate,
32 const APIBinding::AvailabilityCallback& is_available) { 32 const APIBinding::AvailabilityCallback& is_available,
33 v8::Local<v8::Object>* hooks_interface_out) {
33 std::unique_ptr<APIBinding>& binding = api_bindings_[api_name]; 34 std::unique_ptr<APIBinding>& binding = api_bindings_[api_name];
34 if (!binding) 35 if (!binding)
35 binding = CreateNewAPIBinding(api_name); 36 binding = CreateNewAPIBinding(api_name);
37 if (hooks_interface_out)
38 *hooks_interface_out = binding->GetJSHookInterface(context);
36 return binding->CreateInstance( 39 return binding->CreateInstance(
37 context, isolate, &event_handler_, is_available); 40 context, isolate, &event_handler_, is_available);
38 } 41 }
39 42
40 std::unique_ptr<APIBinding> APIBindingsSystem::CreateNewAPIBinding( 43 std::unique_ptr<APIBinding> APIBindingsSystem::CreateNewAPIBinding(
41 const std::string& api_name) { 44 const std::string& api_name) {
42 const base::DictionaryValue& api_schema = get_api_schema_.Run(api_name); 45 const base::DictionaryValue& api_schema = get_api_schema_.Run(api_name);
43 46
44 const base::ListValue* function_definitions = nullptr; 47 const base::ListValue* function_definitions = nullptr;
45 CHECK(api_schema.GetList("functions", &function_definitions)); 48 CHECK(api_schema.GetList("functions", &function_definitions));
46 const base::ListValue* type_definitions = nullptr; 49 const base::ListValue* type_definitions = nullptr;
47 // Type definitions might not exist for the given API. 50 // Type definitions might not exist for the given API.
48 api_schema.GetList("types", &type_definitions); 51 api_schema.GetList("types", &type_definitions);
49 const base::ListValue* event_definitions = nullptr; 52 const base::ListValue* event_definitions = nullptr;
50 api_schema.GetList("events", &event_definitions); 53 api_schema.GetList("events", &event_definitions);
51 54
52 // Find the hooks for the API, if any exist. 55 // Find the hooks for the API. If none exist, an empty set will be created so
56 // we can use JS custom bindings.
57 // TODO(devlin): Once all legacy custom bindings are converted, we don't have
58 // to unconditionally pass in binding hooks.
53 std::unique_ptr<APIBindingHooks> hooks; 59 std::unique_ptr<APIBindingHooks> hooks;
54 auto iter = binding_hooks_.find(api_name); 60 auto iter = binding_hooks_.find(api_name);
55 if (iter != binding_hooks_.end()) { 61 if (iter != binding_hooks_.end()) {
56 hooks = std::move(iter->second); 62 hooks = std::move(iter->second);
57 binding_hooks_.erase(iter); 63 binding_hooks_.erase(iter);
64 } else {
65 hooks = base::MakeUnique<APIBindingHooks>(call_js_);
58 } 66 }
59 67
60 return base::MakeUnique<APIBinding>( 68 return base::MakeUnique<APIBinding>(
61 api_name, *function_definitions, type_definitions, event_definitions, 69 api_name, *function_definitions, type_definitions, event_definitions,
62 base::Bind(&APIBindingsSystem::OnAPICall, base::Unretained(this)), 70 base::Bind(&APIBindingsSystem::OnAPICall, base::Unretained(this)),
63 std::move(hooks), &type_reference_map_); 71 std::move(hooks), &type_reference_map_);
64 } 72 }
65 73
66 void APIBindingsSystem::CompleteRequest(int request_id, 74 void APIBindingsSystem::CompleteRequest(int request_id,
67 const base::ListValue& response) { 75 const base::ListValue& response) {
(...skipping 29 matching lines...) Expand all
97 } 105 }
98 // TODO(devlin): Query and curry user gestures around. 106 // TODO(devlin): Query and curry user gestures around.
99 request->has_user_gesture = false; 107 request->has_user_gesture = false;
100 request->arguments = std::move(arguments); 108 request->arguments = std::move(arguments);
101 request->method_name = name; 109 request->method_name = name;
102 110
103 send_request_.Run(std::move(request), context); 111 send_request_.Run(std::move(request), context);
104 } 112 }
105 113
106 } // namespace extensions 114 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/api_bindings_system.h ('k') | extensions/renderer/api_bindings_system_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698