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/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 "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "content/public/common/console_message_level.h" | 9 #include "content/public/common/console_message_level.h" |
10 #include "content/public/common/content_switches.h" | 10 #include "content/public/common/content_switches.h" |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 } | 177 } |
178 | 178 |
179 // Returns the API schema indicated by |api_name|. | 179 // Returns the API schema indicated by |api_name|. |
180 const base::DictionaryValue& GetAPISchema(const std::string& api_name) { | 180 const base::DictionaryValue& GetAPISchema(const std::string& api_name) { |
181 const base::DictionaryValue* schema = | 181 const base::DictionaryValue* schema = |
182 ExtensionAPI::GetSharedInstance()->GetSchema(api_name); | 182 ExtensionAPI::GetSharedInstance()->GetSchema(api_name); |
183 CHECK(schema) << api_name; | 183 CHECK(schema) << api_name; |
184 return *schema; | 184 return *schema; |
185 } | 185 } |
186 | 186 |
187 // Returns true if the method specified by |method_name| is available to the | 187 // Returns true if the feature specified by |name| is available to the given |
188 // given |context|. | 188 // |context|. |
189 bool IsAPIMethodAvailable(ScriptContext* context, | 189 bool IsAPIFeatureAvailable(v8::Local<v8::Context> context, |
190 const std::string& method_name) { | 190 const std::string& name) { |
191 return context->GetAvailability(method_name).is_available(); | 191 ScriptContext* script_context = |
| 192 ScriptContextSet::GetContextByV8Context(context); |
| 193 DCHECK(script_context); |
| 194 return script_context->GetAvailability(name).is_available(); |
192 } | 195 } |
193 | 196 |
194 // Instantiates the binding object for the given |name|. |name| must specify a | 197 // Instantiates the binding object for the given |name|. |name| must specify a |
195 // specific feature. | 198 // specific feature. |
196 v8::Local<v8::Object> CreateRootBinding(v8::Local<v8::Context> context, | 199 v8::Local<v8::Object> CreateRootBinding(v8::Local<v8::Context> context, |
197 ScriptContext* script_context, | 200 ScriptContext* script_context, |
198 const std::string& name, | 201 const std::string& name, |
199 APIBindingsSystem* bindings_system) { | 202 APIBindingsSystem* bindings_system) { |
200 APIBindingHooks* hooks = nullptr; | 203 APIBindingHooks* hooks = nullptr; |
201 v8::Local<v8::Object> binding_object = bindings_system->CreateAPIInstance( | 204 v8::Local<v8::Object> binding_object = |
202 name, context, base::Bind(&IsAPIMethodAvailable, script_context), &hooks); | 205 bindings_system->CreateAPIInstance(name, context, &hooks); |
203 | 206 |
204 gin::Handle<APIBindingBridge> bridge_handle = gin::CreateHandle( | 207 gin::Handle<APIBindingBridge> bridge_handle = gin::CreateHandle( |
205 context->GetIsolate(), | 208 context->GetIsolate(), |
206 new APIBindingBridge(hooks, context, binding_object, | 209 new APIBindingBridge(hooks, context, binding_object, |
207 script_context->GetExtensionID(), | 210 script_context->GetExtensionID(), |
208 script_context->GetContextTypeDescription(), | 211 script_context->GetContextTypeDescription(), |
209 base::Bind(&CallJsFunction))); | 212 base::Bind(&CallJsFunction))); |
210 v8::Local<v8::Value> native_api_bridge = bridge_handle.ToV8(); | 213 v8::Local<v8::Value> native_api_bridge = bridge_handle.ToV8(); |
211 script_context->module_system()->OnNativeBindingCreated(name, | 214 script_context->module_system()->OnNativeBindingCreated(name, |
212 native_api_bridge); | 215 native_api_bridge); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 | 338 |
336 NativeExtensionBindingsSystem::NativeExtensionBindingsSystem( | 339 NativeExtensionBindingsSystem::NativeExtensionBindingsSystem( |
337 const SendRequestIPCMethod& send_request_ipc, | 340 const SendRequestIPCMethod& send_request_ipc, |
338 const SendEventListenerIPCMethod& send_event_listener_ipc) | 341 const SendEventListenerIPCMethod& send_event_listener_ipc) |
339 : send_request_ipc_(send_request_ipc), | 342 : send_request_ipc_(send_request_ipc), |
340 send_event_listener_ipc_(send_event_listener_ipc), | 343 send_event_listener_ipc_(send_event_listener_ipc), |
341 api_system_( | 344 api_system_( |
342 base::Bind(&CallJsFunction), | 345 base::Bind(&CallJsFunction), |
343 base::Bind(&CallJsFunctionSync), | 346 base::Bind(&CallJsFunctionSync), |
344 base::Bind(&GetAPISchema), | 347 base::Bind(&GetAPISchema), |
| 348 base::Bind(&IsAPIFeatureAvailable), |
345 base::Bind(&NativeExtensionBindingsSystem::SendRequest, | 349 base::Bind(&NativeExtensionBindingsSystem::SendRequest, |
346 base::Unretained(this)), | 350 base::Unretained(this)), |
347 base::Bind(&NativeExtensionBindingsSystem::OnEventListenerChanged, | 351 base::Bind(&NativeExtensionBindingsSystem::OnEventListenerChanged, |
348 base::Unretained(this)), | 352 base::Unretained(this)), |
349 APILastError(base::Bind(&GetRuntime), base::Bind(&AddConsoleError))), | 353 APILastError(base::Bind(&GetRuntime), base::Bind(&AddConsoleError))), |
350 weak_factory_(this) { | 354 weak_factory_(this) { |
351 api_system_.RegisterCustomType("storage.StorageArea", | 355 api_system_.RegisterCustomType("storage.StorageArea", |
352 base::Bind(&StorageArea::CreateStorageArea)); | 356 base::Bind(&StorageArea::CreateStorageArea)); |
353 api_system_.RegisterCustomType("types.ChromeSetting", | 357 api_system_.RegisterCustomType("types.ChromeSetting", |
354 base::Bind(&ChromeSetting::Create)); | 358 base::Bind(&ChromeSetting::Create)); |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
674 v8::Local<v8::Value>* binding_util_out) { | 678 v8::Local<v8::Value>* binding_util_out) { |
675 gin::Handle<APIBindingJSUtil> handle = gin::CreateHandle( | 679 gin::Handle<APIBindingJSUtil> handle = gin::CreateHandle( |
676 context->GetIsolate(), | 680 context->GetIsolate(), |
677 new APIBindingJSUtil( | 681 new APIBindingJSUtil( |
678 api_system_.type_reference_map(), api_system_.request_handler(), | 682 api_system_.type_reference_map(), api_system_.request_handler(), |
679 api_system_.event_handler(), base::Bind(&CallJsFunction))); | 683 api_system_.event_handler(), base::Bind(&CallJsFunction))); |
680 *binding_util_out = handle.ToV8(); | 684 *binding_util_out = handle.ToV8(); |
681 } | 685 } |
682 | 686 |
683 } // namespace extensions | 687 } // namespace extensions |
OLD | NEW |