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

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

Issue 2819683002: [Extenisons Bindings] Don't throw unchecked errors; add console errors (Closed)
Patch Set: . Created 3 years, 8 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 "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"
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 base::Unretained(&did_complete), base::Unretained(&result)); 158 base::Unretained(&did_complete), base::Unretained(&result));
158 159
159 ScriptContext* script_context = 160 ScriptContext* script_context =
160 ScriptContextSet::GetContextByV8Context(context); 161 ScriptContextSet::GetContextByV8Context(context);
161 CHECK(script_context); 162 CHECK(script_context);
162 script_context->SafeCallFunction(function, argc, argv, callback); 163 script_context->SafeCallFunction(function, argc, argv, callback);
163 CHECK(did_complete) << "expected script to execute synchronously"; 164 CHECK(did_complete) << "expected script to execute synchronously";
164 return result; 165 return result;
165 } 166 }
166 167
168 void AddConsoleError(v8::Local<v8::Context> context, const std::string& error) {
169 ScriptContext* script_context =
170 ScriptContextSet::GetContextByV8Context(context);
171 CHECK(script_context);
172 script_context->AddMessageToConsole(content::CONSOLE_MESSAGE_LEVEL_ERROR,
173 error);
174 }
175
167 // Returns the API schema indicated by |api_name|. 176 // Returns the API schema indicated by |api_name|.
168 const base::DictionaryValue& GetAPISchema(const std::string& api_name) { 177 const base::DictionaryValue& GetAPISchema(const std::string& api_name) {
169 const base::DictionaryValue* schema = 178 const base::DictionaryValue* schema =
170 ExtensionAPI::GetSharedInstance()->GetSchema(api_name); 179 ExtensionAPI::GetSharedInstance()->GetSchema(api_name);
171 CHECK(schema) << api_name; 180 CHECK(schema) << api_name;
172 return *schema; 181 return *schema;
173 } 182 }
174 183
175 // Returns true if the method specified by |method_name| is available to the 184 // Returns true if the method specified by |method_name| is available to the
176 // given |context|. 185 // given |context|.
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 : send_request_ipc_(send_request_ipc), 337 : send_request_ipc_(send_request_ipc),
329 send_event_listener_ipc_(send_event_listener_ipc), 338 send_event_listener_ipc_(send_event_listener_ipc),
330 api_system_( 339 api_system_(
331 base::Bind(&CallJsFunction), 340 base::Bind(&CallJsFunction),
332 base::Bind(&CallJsFunctionSync), 341 base::Bind(&CallJsFunctionSync),
333 base::Bind(&GetAPISchema), 342 base::Bind(&GetAPISchema),
334 base::Bind(&NativeExtensionBindingsSystem::SendRequest, 343 base::Bind(&NativeExtensionBindingsSystem::SendRequest,
335 base::Unretained(this)), 344 base::Unretained(this)),
336 base::Bind(&NativeExtensionBindingsSystem::OnEventListenerChanged, 345 base::Bind(&NativeExtensionBindingsSystem::OnEventListenerChanged,
337 base::Unretained(this)), 346 base::Unretained(this)),
338 APILastError(base::Bind(&GetRuntime))), 347 APILastError(base::Bind(&GetRuntime), base::Bind(&AddConsoleError))),
339 weak_factory_(this) { 348 weak_factory_(this) {
340 api_system_.RegisterCustomType("storage.StorageArea", 349 api_system_.RegisterCustomType("storage.StorageArea",
341 base::Bind(&StorageArea::CreateStorageArea)); 350 base::Bind(&StorageArea::CreateStorageArea));
342 api_system_.RegisterCustomType("types.ChromeSetting", 351 api_system_.RegisterCustomType("types.ChromeSetting",
343 base::Bind(&ChromeSetting::Create)); 352 base::Bind(&ChromeSetting::Create));
344 api_system_.GetHooksForAPI("webRequest") 353 api_system_.GetHooksForAPI("webRequest")
345 ->SetDelegate(base::MakeUnique<WebRequestHooks>()); 354 ->SetDelegate(base::MakeUnique<WebRequestHooks>());
346 } 355 }
347 356
348 NativeExtensionBindingsSystem::~NativeExtensionBindingsSystem() {} 357 NativeExtensionBindingsSystem::~NativeExtensionBindingsSystem() {}
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 v8::Local<v8::Value>* binding_util_out) { 662 v8::Local<v8::Value>* binding_util_out) {
654 gin::Handle<APIBindingJSUtil> handle = gin::CreateHandle( 663 gin::Handle<APIBindingJSUtil> handle = gin::CreateHandle(
655 context->GetIsolate(), 664 context->GetIsolate(),
656 new APIBindingJSUtil( 665 new APIBindingJSUtil(
657 api_system_.type_reference_map(), api_system_.request_handler(), 666 api_system_.type_reference_map(), api_system_.request_handler(),
658 api_system_.event_handler(), base::Bind(&CallJsFunction))); 667 api_system_.event_handler(), base::Bind(&CallJsFunction)));
659 *binding_util_out = handle.ToV8(); 668 *binding_util_out = handle.ToV8();
660 } 669 }
661 670
662 } // namespace extensions 671 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698