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/content_switches.h" | 10 #include "content/public/common/content_switches.h" |
10 #include "extensions/common/constants.h" | 11 #include "extensions/common/constants.h" |
11 #include "extensions/common/event_filtering_info.h" | 12 #include "extensions/common/event_filtering_info.h" |
12 #include "extensions/common/extension_api.h" | 13 #include "extensions/common/extension_api.h" |
13 #include "extensions/common/extension_messages.h" | 14 #include "extensions/common/extension_messages.h" |
14 #include "extensions/common/features/feature_provider.h" | 15 #include "extensions/common/features/feature_provider.h" |
15 #include "extensions/renderer/api_binding_bridge.h" | 16 #include "extensions/renderer/api_binding_bridge.h" |
16 #include "extensions/renderer/api_binding_hooks.h" | 17 #include "extensions/renderer/api_binding_hooks.h" |
17 #include "extensions/renderer/api_binding_js_util.h" | 18 #include "extensions/renderer/api_binding_js_util.h" |
18 #include "extensions/renderer/chrome_setting.h" | 19 #include "extensions/renderer/chrome_setting.h" |
| 20 #include "extensions/renderer/console.h" |
19 #include "extensions/renderer/module_system.h" | 21 #include "extensions/renderer/module_system.h" |
20 #include "extensions/renderer/script_context.h" | 22 #include "extensions/renderer/script_context.h" |
21 #include "extensions/renderer/script_context_set.h" | 23 #include "extensions/renderer/script_context_set.h" |
22 #include "extensions/renderer/storage_area.h" | 24 #include "extensions/renderer/storage_area.h" |
23 #include "extensions/renderer/web_request_hooks.h" | 25 #include "extensions/renderer/web_request_hooks.h" |
24 #include "gin/converter.h" | 26 #include "gin/converter.h" |
25 #include "gin/handle.h" | 27 #include "gin/handle.h" |
26 #include "gin/per_context_data.h" | 28 #include "gin/per_context_data.h" |
27 #include "third_party/WebKit/public/web/WebDocument.h" | 29 #include "third_party/WebKit/public/web/WebDocument.h" |
28 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 30 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 base::Unretained(&did_complete), base::Unretained(&result)); | 159 base::Unretained(&did_complete), base::Unretained(&result)); |
158 | 160 |
159 ScriptContext* script_context = | 161 ScriptContext* script_context = |
160 ScriptContextSet::GetContextByV8Context(context); | 162 ScriptContextSet::GetContextByV8Context(context); |
161 CHECK(script_context); | 163 CHECK(script_context); |
162 script_context->SafeCallFunction(function, argc, argv, callback); | 164 script_context->SafeCallFunction(function, argc, argv, callback); |
163 CHECK(did_complete) << "expected script to execute synchronously"; | 165 CHECK(did_complete) << "expected script to execute synchronously"; |
164 return result; | 166 return result; |
165 } | 167 } |
166 | 168 |
| 169 void AddConsoleError(v8::Local<v8::Context> context, const std::string& error) { |
| 170 ScriptContext* script_context = |
| 171 ScriptContextSet::GetContextByV8Context(context); |
| 172 CHECK(script_context); |
| 173 console::AddMessage(script_context, content::CONSOLE_MESSAGE_LEVEL_ERROR, |
| 174 error); |
| 175 } |
| 176 |
167 // Returns the API schema indicated by |api_name|. | 177 // Returns the API schema indicated by |api_name|. |
168 const base::DictionaryValue& GetAPISchema(const std::string& api_name) { | 178 const base::DictionaryValue& GetAPISchema(const std::string& api_name) { |
169 const base::DictionaryValue* schema = | 179 const base::DictionaryValue* schema = |
170 ExtensionAPI::GetSharedInstance()->GetSchema(api_name); | 180 ExtensionAPI::GetSharedInstance()->GetSchema(api_name); |
171 CHECK(schema) << api_name; | 181 CHECK(schema) << api_name; |
172 return *schema; | 182 return *schema; |
173 } | 183 } |
174 | 184 |
175 // Returns true if the method specified by |method_name| is available to the | 185 // Returns true if the method specified by |method_name| is available to the |
176 // given |context|. | 186 // given |context|. |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 : send_request_ipc_(send_request_ipc), | 338 : send_request_ipc_(send_request_ipc), |
329 send_event_listener_ipc_(send_event_listener_ipc), | 339 send_event_listener_ipc_(send_event_listener_ipc), |
330 api_system_( | 340 api_system_( |
331 base::Bind(&CallJsFunction), | 341 base::Bind(&CallJsFunction), |
332 base::Bind(&CallJsFunctionSync), | 342 base::Bind(&CallJsFunctionSync), |
333 base::Bind(&GetAPISchema), | 343 base::Bind(&GetAPISchema), |
334 base::Bind(&NativeExtensionBindingsSystem::SendRequest, | 344 base::Bind(&NativeExtensionBindingsSystem::SendRequest, |
335 base::Unretained(this)), | 345 base::Unretained(this)), |
336 base::Bind(&NativeExtensionBindingsSystem::OnEventListenerChanged, | 346 base::Bind(&NativeExtensionBindingsSystem::OnEventListenerChanged, |
337 base::Unretained(this)), | 347 base::Unretained(this)), |
338 APILastError(base::Bind(&GetRuntime))), | 348 APILastError(base::Bind(&GetRuntime), base::Bind(&AddConsoleError))), |
339 weak_factory_(this) { | 349 weak_factory_(this) { |
340 api_system_.RegisterCustomType("storage.StorageArea", | 350 api_system_.RegisterCustomType("storage.StorageArea", |
341 base::Bind(&StorageArea::CreateStorageArea)); | 351 base::Bind(&StorageArea::CreateStorageArea)); |
342 api_system_.RegisterCustomType("types.ChromeSetting", | 352 api_system_.RegisterCustomType("types.ChromeSetting", |
343 base::Bind(&ChromeSetting::Create)); | 353 base::Bind(&ChromeSetting::Create)); |
344 api_system_.GetHooksForAPI("webRequest") | 354 api_system_.GetHooksForAPI("webRequest") |
345 ->SetDelegate(base::MakeUnique<WebRequestHooks>()); | 355 ->SetDelegate(base::MakeUnique<WebRequestHooks>()); |
346 } | 356 } |
347 | 357 |
348 NativeExtensionBindingsSystem::~NativeExtensionBindingsSystem() {} | 358 NativeExtensionBindingsSystem::~NativeExtensionBindingsSystem() {} |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 v8::Local<v8::Value>* binding_util_out) { | 663 v8::Local<v8::Value>* binding_util_out) { |
654 gin::Handle<APIBindingJSUtil> handle = gin::CreateHandle( | 664 gin::Handle<APIBindingJSUtil> handle = gin::CreateHandle( |
655 context->GetIsolate(), | 665 context->GetIsolate(), |
656 new APIBindingJSUtil( | 666 new APIBindingJSUtil( |
657 api_system_.type_reference_map(), api_system_.request_handler(), | 667 api_system_.type_reference_map(), api_system_.request_handler(), |
658 api_system_.event_handler(), base::Bind(&CallJsFunction))); | 668 api_system_.event_handler(), base::Bind(&CallJsFunction))); |
659 *binding_util_out = handle.ToV8(); | 669 *binding_util_out = handle.ToV8(); |
660 } | 670 } |
661 | 671 |
662 } // namespace extensions | 672 } // namespace extensions |
OLD | NEW |