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

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

Issue 2575173002: [Extensions Bindings] Add a bridge to use current custom bindings (Closed)
Patch Set: . Created 3 years, 12 months 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/native_extension_bindings_system.h" 5 #include "extensions/renderer/native_extension_bindings_system.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "content/public/common/content_switches.h" 8 #include "content/public/common/content_switches.h"
9 #include "extensions/common/constants.h" 9 #include "extensions/common/constants.h"
10 #include "extensions/common/extension_api.h" 10 #include "extensions/common/extension_api.h"
11 #include "extensions/common/extension_messages.h" 11 #include "extensions/common/extension_messages.h"
12 #include "extensions/common/features/feature_provider.h" 12 #include "extensions/common/features/feature_provider.h"
13 #include "extensions/renderer/api_binding_bridge.h"
14 #include "extensions/renderer/api_binding_hooks.h"
15 #include "extensions/renderer/module_system.h"
13 #include "extensions/renderer/script_context.h" 16 #include "extensions/renderer/script_context.h"
14 #include "extensions/renderer/script_context_set.h" 17 #include "extensions/renderer/script_context_set.h"
15 #include "gin/converter.h" 18 #include "gin/converter.h"
19 #include "gin/handle.h"
16 #include "gin/per_context_data.h" 20 #include "gin/per_context_data.h"
17 #include "third_party/WebKit/public/web/WebDocument.h" 21 #include "third_party/WebKit/public/web/WebDocument.h"
18 #include "third_party/WebKit/public/web/WebLocalFrame.h" 22 #include "third_party/WebKit/public/web/WebLocalFrame.h"
19 23
20 namespace extensions { 24 namespace extensions {
21 25
22 namespace { 26 namespace {
23 27
24 const char kBindingsSystemPerContextKey[] = "extension_bindings_system"; 28 const char kBindingsSystemPerContextKey[] = "extension_bindings_system";
25 29
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 NativeExtensionBindingsSystem::~NativeExtensionBindingsSystem() {} 110 NativeExtensionBindingsSystem::~NativeExtensionBindingsSystem() {}
107 111
108 void NativeExtensionBindingsSystem::DidCreateScriptContext( 112 void NativeExtensionBindingsSystem::DidCreateScriptContext(
109 ScriptContext* context) {} 113 ScriptContext* context) {}
110 114
111 void NativeExtensionBindingsSystem::WillReleaseScriptContext( 115 void NativeExtensionBindingsSystem::WillReleaseScriptContext(
112 ScriptContext* context) {} 116 ScriptContext* context) {}
113 117
114 void NativeExtensionBindingsSystem::UpdateBindingsForContext( 118 void NativeExtensionBindingsSystem::UpdateBindingsForContext(
115 ScriptContext* context) { 119 ScriptContext* context) {
120 v8::HandleScope handle_scope(context->isolate());
116 v8::Local<v8::Context> v8_context = context->v8_context(); 121 v8::Local<v8::Context> v8_context = context->v8_context();
117 v8::Local<v8::Object> chrome = GetOrCreateChrome(v8_context); 122 v8::Local<v8::Object> chrome = GetOrCreateChrome(v8_context);
118 if (chrome.IsEmpty()) 123 if (chrome.IsEmpty())
119 return; 124 return;
120 125
121 gin::PerContextData* per_context_data = gin::PerContextData::From(v8_context); 126 gin::PerContextData* per_context_data = gin::PerContextData::From(v8_context);
122 DCHECK(per_context_data); 127 DCHECK(per_context_data);
123 BindingsSystemPerContextData* data = 128 BindingsSystemPerContextData* data =
124 static_cast<BindingsSystemPerContextData*>( 129 static_cast<BindingsSystemPerContextData*>(
125 per_context_data->GetUserData(kBindingsSystemPerContextKey)); 130 per_context_data->GetUserData(kBindingsSystemPerContextKey));
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 // one to handle any weirdness from the caller (non-existent strings, etc). 230 // one to handle any weirdness from the caller (non-existent strings, etc).
226 v8::Local<v8::String> api_name = info.Data().As<v8::String>(); 231 v8::Local<v8::String> api_name = info.Data().As<v8::String>();
227 v8::Local<v8::Value> result; 232 v8::Local<v8::Value> result;
228 v8::Maybe<bool> has_property = apis->HasRealNamedProperty(context, api_name); 233 v8::Maybe<bool> has_property = apis->HasRealNamedProperty(context, api_name);
229 if (!has_property.IsJust()) 234 if (!has_property.IsJust())
230 return; 235 return;
231 236
232 if (has_property.FromJust()) { 237 if (has_property.FromJust()) {
233 result = apis->GetRealNamedProperty(context, api_name).ToLocalChecked(); 238 result = apis->GetRealNamedProperty(context, api_name).ToLocalChecked();
234 } else { 239 } else {
240 ScriptContext* script_context =
241 ScriptContextSet::GetContextByV8Context(context);
235 std::string api_name_string; 242 std::string api_name_string;
236 CHECK(gin::Converter<std::string>::FromV8(isolate, api_name, 243 CHECK(gin::Converter<std::string>::FromV8(isolate, api_name,
237 &api_name_string)); 244 &api_name_string));
238 result = data->bindings_system->api_system_.CreateAPIInstance( 245 v8::Local<v8::Object> hooks_interface;
246 APIBindingsSystem& api_system = data->bindings_system->api_system_;
247 result = api_system.CreateAPIInstance(
239 api_name_string, context, isolate, 248 api_name_string, context, isolate,
240 base::Bind(&IsAPIMethodAvailable, 249 base::Bind(&IsAPIMethodAvailable, script_context), &hooks_interface);
241 ScriptContextSet::GetContextByV8Context(context))); 250
251 gin::Handle<APIBindingBridge> bridge_handle = gin::CreateHandle(
252 isolate,
253 new APIBindingBridge(context, result, hooks_interface,
254 script_context->GetExtensionID(),
255 script_context->GetContextTypeDescription(),
256 base::Bind(&CallJsFunction)));
257 v8::Local<v8::Value> native_api_bridge = bridge_handle.ToV8();
258
259 script_context->module_system()->OnNativeBindingCreated(api_name_string,
260 native_api_bridge);
261
242 v8::Maybe<bool> success = 262 v8::Maybe<bool> success =
243 apis->CreateDataProperty(context, api_name, result); 263 apis->CreateDataProperty(context, api_name, result);
244 if (!success.IsJust() || !success.FromJust()) 264 if (!success.IsJust() || !success.FromJust())
245 return; 265 return;
246 } 266 }
247 info.GetReturnValue().Set(result); 267 info.GetReturnValue().Set(result);
248 } 268 }
249 269
250 void NativeExtensionBindingsSystem::SendRequest( 270 void NativeExtensionBindingsSystem::SendRequest(
251 std::unique_ptr<APIBindingsSystem::Request> request, 271 std::unique_ptr<APIBindingsSystem::Request> request,
(...skipping 17 matching lines...) Expand all
269 params.has_callback = request->has_callback; 289 params.has_callback = request->has_callback;
270 params.user_gesture = request->has_user_gesture; 290 params.user_gesture = request->has_user_gesture;
271 // TODO(devlin): Make this work in ServiceWorkers. 291 // TODO(devlin): Make this work in ServiceWorkers.
272 params.worker_thread_id = -1; 292 params.worker_thread_id = -1;
273 params.service_worker_version_id = kInvalidServiceWorkerVersionId; 293 params.service_worker_version_id = kInvalidServiceWorkerVersionId;
274 294
275 send_ipc_.Run(script_context, params); 295 send_ipc_.Run(script_context, params);
276 } 296 }
277 297
278 } // namespace extensions 298 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/module_system.cc ('k') | extensions/renderer/native_extension_bindings_system_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698