Chromium Code Reviews| Index: extensions/renderer/native_extension_bindings_system.cc |
| diff --git a/extensions/renderer/native_extension_bindings_system.cc b/extensions/renderer/native_extension_bindings_system.cc |
| index 1ff3cd5f28b68cf63e47806e2656bb0d17d1d357..a107e17976e35fc0566aad5bd59ef04e6c235200 100644 |
| --- a/extensions/renderer/native_extension_bindings_system.cc |
| +++ b/extensions/renderer/native_extension_bindings_system.cc |
| @@ -326,7 +326,8 @@ NativeExtensionBindingsSystem::NativeExtensionBindingsSystem( |
| base::Bind(&NativeExtensionBindingsSystem::SendRequest, |
| base::Unretained(this)), |
| base::Bind(&NativeExtensionBindingsSystem::OnEventListenerChanged, |
| - base::Unretained(this))), |
| + base::Unretained(this)), |
| + APILastError(base::Bind(&GetRuntime))), |
| weak_factory_(this) {} |
| NativeExtensionBindingsSystem::~NativeExtensionBindingsSystem() {} |
| @@ -403,7 +404,7 @@ void NativeExtensionBindingsSystem::UpdateBindingsForContext( |
| v8::Local<v8::String> api_name = |
| gin::StringToSymbol(v8_context->GetIsolate(), accessor_name); |
| v8::Maybe<bool> success = chrome->SetAccessor( |
| - v8_context, api_name, &GetAPIHelper, nullptr, api_name); |
| + v8_context, api_name, &BindingAccessor, nullptr, api_name); |
| if (!success.IsJust() || !success.FromJust()) { |
| LOG(ERROR) << "Failed to create API on Chrome object."; |
| return; |
| @@ -428,24 +429,37 @@ void NativeExtensionBindingsSystem::HandleResponse( |
| bool success, |
| const base::ListValue& response, |
| const std::string& error) { |
| - api_system_.CompleteRequest(request_id, response); |
| + api_system_.CompleteRequest(request_id, response, error); |
| } |
| RequestSender* NativeExtensionBindingsSystem::GetRequestSender() { |
| return nullptr; |
| } |
| -// static |
| -void NativeExtensionBindingsSystem::GetAPIHelper( |
| +void NativeExtensionBindingsSystem::BindingAccessor( |
| v8::Local<v8::Name> name, |
| const v8::PropertyCallbackInfo<v8::Value>& info) { |
| v8::Isolate* isolate = info.GetIsolate(); |
| v8::HandleScope handle_scope(isolate); |
| v8::Local<v8::Context> context = info.Holder()->CreationContext(); |
| + |
| + // We use info.Data() to store a real name here instead of using the provided |
| + // one to handle any weirdness from the caller (non-existent strings, etc). |
| + v8::Local<v8::String> api_name = info.Data().As<v8::String>(); |
| + v8::Local<v8::Object> binding = GetAPIHelper(context, api_name); |
| + if (!binding.IsEmpty()) |
| + info.GetReturnValue().Set(binding); |
| +} |
| + |
| +// static |
| +v8::Local<v8::Object> NativeExtensionBindingsSystem::GetAPIHelper( |
| + v8::Local<v8::Context> context, |
| + v8::Local<v8::String> api_name) { |
| BindingsSystemPerContextData* data = GetBindingsDataFromContext(context); |
| if (!data) |
| - return; |
| + return v8::Local<v8::Object>(); |
| + v8::Isolate* isolate = context->GetIsolate(); |
| v8::Local<v8::Object> apis; |
| if (data->api_object.IsEmpty()) { |
| apis = v8::Object::New(isolate); |
| @@ -465,16 +479,16 @@ void NativeExtensionBindingsSystem::GetAPIHelper( |
| ->GetFunction(context) |
| .ToLocalChecked(); |
| - // We use info.Data() to store a real name here instead of using the provided |
| - // one to handle any weirdness from the caller (non-existent strings, etc). |
| - v8::Local<v8::String> api_name = info.Data().As<v8::String>(); |
| - v8::Local<v8::Value> result; |
| + v8::Local<v8::Object> result; |
|
jbroman
2017/02/13 19:41:27
nit: Does this variable still need to exist? Looks
Devlin
2017/02/14 04:57:08
Done.
|
| v8::Maybe<bool> has_property = apis->HasRealNamedProperty(context, api_name); |
| if (!has_property.IsJust()) |
| - return; |
| + return v8::Local<v8::Object>(); |
| if (has_property.FromJust()) { |
| - result = apis->GetRealNamedProperty(context, api_name).ToLocalChecked(); |
| + v8::Local<v8::Value> value = |
| + apis->GetRealNamedProperty(context, api_name).ToLocalChecked(); |
| + DCHECK(value->IsObject()); |
| + result = value.As<v8::Object>(); |
| } else { |
| ScriptContext* script_context = |
| ScriptContextSet::GetContextByV8Context(context); |
| @@ -486,17 +500,23 @@ void NativeExtensionBindingsSystem::GetAPIHelper( |
| context, script_context, &data->bindings_system->api_system_, |
| FeatureProvider::GetAPIFeatures(), api_name_string, get_internal_api); |
| if (root_binding.IsEmpty()) |
| - return; |
| + return v8::Local<v8::Object>(); |
| v8::Maybe<bool> success = |
| apis->CreateDataProperty(context, api_name, root_binding); |
| if (!success.IsJust() || !success.FromJust()) |
| - return; |
| + return v8::Local<v8::Object>(); |
| result = root_binding; |
| } |
| - info.GetReturnValue().Set(result); |
| + return result; |
| +} |
| + |
| +v8::Local<v8::Object> NativeExtensionBindingsSystem::GetRuntime( |
| + v8::Local<v8::Context> context) { |
| + return GetAPIHelper(context, |
| + gin::StringToSymbol(context->GetIsolate(), "runtime")); |
| } |
| // static |