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

Unified Diff: extensions/renderer/api_binding.cc

Issue 2598123002: [Extensions Bindings] Add support for updateArgumentsPreValidate (Closed)
Patch Set: rebase Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | extensions/renderer/api_binding_hooks.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/renderer/api_binding.cc
diff --git a/extensions/renderer/api_binding.cc b/extensions/renderer/api_binding.cc
index bf559f995355231fd20557ecbba4e48a311eae88..7e59671985123ce69ff3e84358bf8b98e6ffc269 100644
--- a/extensions/renderer/api_binding.cc
+++ b/extensions/renderer/api_binding.cc
@@ -190,36 +190,56 @@ void APIBinding::HandleCall(const std::string& name,
// GetCurrentContext() should always be correct.
v8::Local<v8::Context> context = isolate->GetCurrentContext();
- APIBindingHooks::RequestResult hooks_result =
- APIBindingHooks::RequestResult::NOT_HANDLED;
- hooks_result = binding_hooks_->HandleRequest(api_name_, name, context,
- signature, arguments,
- *type_refs_);
-
- switch (hooks_result) {
- case APIBindingHooks::RequestResult::INVALID_INVOCATION:
- arguments->ThrowTypeError("Invalid invocation");
- return;
- case APIBindingHooks::RequestResult::HANDLED:
- return; // Our work here is done.
- case APIBindingHooks::RequestResult::NOT_HANDLED:
- break; // Handle in the default manner.
+ std::vector<v8::Local<v8::Value>> argument_list;
+ if (arguments->Length() > 0) {
+ // Just copying handles should never fail.
+ CHECK(arguments->GetRemaining(&argument_list));
+ }
+
+ bool invalid_invocation = false;
+ {
+ v8::TryCatch try_catch(isolate);
+ APIBindingHooks::RequestResult hooks_result =
+ APIBindingHooks::RequestResult::NOT_HANDLED;
+ hooks_result = binding_hooks_->HandleRequest(api_name_, name, context,
+ signature, &argument_list,
+ *type_refs_);
+
+ switch (hooks_result) {
+ case APIBindingHooks::RequestResult::INVALID_INVOCATION:
+ invalid_invocation = true;
+ // Throw a type error below so that it's not caught by our try-catch.
+ break;
+ case APIBindingHooks::RequestResult::THROWN:
+ DCHECK(try_catch.HasCaught());
+ try_catch.ReThrow();
+ return;
+ case APIBindingHooks::RequestResult::HANDLED:
+ return; // Our work here is done.
+ case APIBindingHooks::RequestResult::NOT_HANDLED:
+ break; // Handle in the default manner.
+ }
+ }
+
+ if (invalid_invocation) {
+ arguments->ThrowTypeError("Invalid invocation");
+ return;
}
std::unique_ptr<base::ListValue> converted_arguments;
v8::Local<v8::Function> callback;
- bool conversion_success = false;
{
v8::TryCatch try_catch(isolate);
- conversion_success = signature->ParseArgumentsToJSON(
- arguments, *type_refs_, &converted_arguments, &callback, &error);
+ invalid_invocation = !signature->ParseArgumentsToJSON(
+ context, argument_list, *type_refs_,
+ &converted_arguments, &callback, &error);
if (try_catch.HasCaught()) {
DCHECK(!converted_arguments);
try_catch.ReThrow();
return;
}
}
- if (!conversion_success) {
+ if (invalid_invocation) {
arguments->ThrowTypeError("Invalid invocation");
return;
}
« no previous file with comments | « no previous file | extensions/renderer/api_binding_hooks.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698