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

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

Issue 2563093002: [Extension Bindings] Add JS custom hook support (Closed)
Patch Set: nits 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
« no previous file with comments | « extensions/renderer/api_bindings_system.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
11 11
12 namespace extensions { 12 namespace extensions {
13 13
14 APIBindingsSystem::Request::Request() {} 14 APIBindingsSystem::Request::Request() {}
15 APIBindingsSystem::Request::~Request() {} 15 APIBindingsSystem::Request::~Request() {}
16 16
17 APIBindingsSystem::APIBindingsSystem(const binding::RunJSFunction& call_js, 17 APIBindingsSystem::APIBindingsSystem(const binding::RunJSFunction& call_js,
18 const GetAPISchemaMethod& get_api_schema, 18 const GetAPISchemaMethod& get_api_schema,
19 const SendRequestMethod& send_request) 19 const SendRequestMethod& send_request)
20 : request_handler_(call_js), 20 : request_handler_(call_js),
21 event_handler_(call_js), 21 event_handler_(call_js),
22 call_js_(call_js),
22 get_api_schema_(get_api_schema), 23 get_api_schema_(get_api_schema),
23 send_request_(send_request) {} 24 send_request_(send_request) {}
24 25
25 APIBindingsSystem::~APIBindingsSystem() {} 26 APIBindingsSystem::~APIBindingsSystem() {}
26 27
27 v8::Local<v8::Object> APIBindingsSystem::CreateAPIInstance( 28 v8::Local<v8::Object> APIBindingsSystem::CreateAPIInstance(
28 const std::string& api_name, 29 const std::string& api_name,
29 v8::Local<v8::Context> context, 30 v8::Local<v8::Context> context,
30 v8::Isolate* isolate, 31 v8::Isolate* isolate,
31 const APIBinding::AvailabilityCallback& is_available) { 32 const APIBinding::AvailabilityCallback& is_available) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 const base::ListValue& response) { 73 const base::ListValue& response) {
73 event_handler_.FireEventInContext(event_name, context, response); 74 event_handler_.FireEventInContext(event_name, context, response);
74 } 75 }
75 76
76 APIBindingHooks* APIBindingsSystem::GetHooksForAPI( 77 APIBindingHooks* APIBindingsSystem::GetHooksForAPI(
77 const std::string& api_name) { 78 const std::string& api_name) {
78 DCHECK(api_bindings_.empty()) 79 DCHECK(api_bindings_.empty())
79 << "Hook registration must happen before creating any binding instances."; 80 << "Hook registration must happen before creating any binding instances.";
80 std::unique_ptr<APIBindingHooks>& hooks = binding_hooks_[api_name]; 81 std::unique_ptr<APIBindingHooks>& hooks = binding_hooks_[api_name];
81 if (!hooks) 82 if (!hooks)
82 hooks = base::MakeUnique<APIBindingHooks>(); 83 hooks = base::MakeUnique<APIBindingHooks>(call_js_);
83 return hooks.get(); 84 return hooks.get();
84 } 85 }
85 86
86 void APIBindingsSystem::OnAPICall(const std::string& name, 87 void APIBindingsSystem::OnAPICall(const std::string& name,
87 std::unique_ptr<base::ListValue> arguments, 88 std::unique_ptr<base::ListValue> arguments,
88 v8::Isolate* isolate, 89 v8::Isolate* isolate,
89 v8::Local<v8::Context> context, 90 v8::Local<v8::Context> context,
90 v8::Local<v8::Function> callback) { 91 v8::Local<v8::Function> callback) {
91 auto request = base::MakeUnique<Request>(); 92 auto request = base::MakeUnique<Request>();
92 if (!callback.IsEmpty()) { 93 if (!callback.IsEmpty()) {
93 request->request_id = 94 request->request_id =
94 request_handler_.AddPendingRequest(isolate, callback, context); 95 request_handler_.AddPendingRequest(isolate, callback, context);
95 request->has_callback = true; 96 request->has_callback = true;
96 } 97 }
97 // TODO(devlin): Query and curry user gestures around. 98 // TODO(devlin): Query and curry user gestures around.
98 request->has_user_gesture = false; 99 request->has_user_gesture = false;
99 request->arguments = std::move(arguments); 100 request->arguments = std::move(arguments);
100 request->method_name = name; 101 request->method_name = name;
101 102
102 send_request_.Run(std::move(request), context); 103 send_request_.Run(std::move(request), context);
103 } 104 }
104 105
105 } // namespace extensions 106 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/api_bindings_system.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698