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

Unified Diff: extensions/renderer/api_signature.h

Issue 2583273002: [Extensions Bindings] Allow for argument validation without conversion (Closed)
Patch Set: format Created 4 years 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
Index: extensions/renderer/api_signature.h
diff --git a/extensions/renderer/api_signature.h b/extensions/renderer/api_signature.h
index c2f3ab888749c7824f9c4c5e511a43621d2fb0d7..c9b120183cb5975256134be88cea7c581cf22fe7 100644
--- a/extensions/renderer/api_signature.h
+++ b/extensions/renderer/api_signature.h
@@ -30,32 +30,52 @@ class APISignature {
APISignature(const base::ListValue& specification);
~APISignature();
+ // Parses |arguments| against this signature, and populates |args_out| with
+ // the v8 values (performing no conversion). The resulting vector may differ
+ // from the list of arguments passed in because it will include null-filled
+ // optional arguments.
+ // Returns true if the arguments were successfully parsed and converted.
+ bool ParseArgumentsToV8(gin::Arguments* arguments,
+ const ArgumentSpec::RefMap& type_refs,
+ std::vector<v8::Local<v8::Value>>* args_out,
+ std::string* error) const;
+
// Parses |arguments| against this signature, converting to a base::ListValue.
- // If the arguments don't match, null is returned and |error| is populated.
- std::unique_ptr<base::ListValue> ParseArguments(
- gin::Arguments* arguments,
- const ArgumentSpec::RefMap& type_refs,
- v8::Local<v8::Function>* callback_out,
- std::string* error) const;
+ // Returns true if the arguments were successfully parsed and converted, and
+ // populates |args_out| and |callback_out| with the JSON arguments and
+ // callback values, respectively. On failure, returns false populates |error|.
+ bool ParseArgumentsToJSON(gin::Arguments* arguments,
+ const ArgumentSpec::RefMap& type_refs,
+ std::unique_ptr<base::ListValue>* args_out,
+ v8::Local<v8::Function>* callback_out,
+ std::string* error) const;
private:
+ // Common implementation for ParseArgumentsToJSON and ParseArgumentsToV8.
+ bool ParseArgumentsImpl(gin::Arguments* arguments,
+ const ArgumentSpec::RefMap& type_refs,
+ std::vector<v8::Local<v8::Value>>* v8_out,
+ std::unique_ptr<base::ListValue>* json_out,
+ v8::Local<v8::Function>* callback_out,
+ std::string* error) const;
+
// Attempts to match an argument from |arguments| to the given |spec|.
- // If the next argmument does not match and |spec| is optional, a null
- // base::Value is returned.
- // If the argument matches, |arguments| is advanced and the converted value is
- // returned.
- // If the argument does not match and it is not optional, returns null and
- // populates error.
- std::unique_ptr<base::Value> ParseArgument(
- const ArgumentSpec& spec,
- v8::Local<v8::Context> context,
- gin::Arguments* arguments,
- const ArgumentSpec::RefMap& type_refs,
- std::string* error) const;
+ // If the next argmument does not match and |spec| is optional, uses a null
+ // value.
+ // If the argument matches, |arguments| is advanced, and the matched value is
+ // added to either |v8_out| or |json_out|.
+ // Returns true on success.
+ bool ParseArgument(const ArgumentSpec& spec,
+ v8::Local<v8::Context> context,
+ gin::Arguments* arguments,
+ const ArgumentSpec::RefMap& type_refs,
+ std::vector<v8::Local<v8::Value>>* v8_out,
+ base::ListValue* json_out,
+ std::string* error) const;
// Parses the callback from |arguments| according to |callback_spec|. Since
- // the callback isn't converted into a base::Value, this is different from
- // ParseArgument() above.
+ // the callback can be treated differently than the rest of the arguments,
+ // this differs from ParseArgument() above.
bool ParseCallback(gin::Arguments* arguments,
const ArgumentSpec& callback_spec,
std::string* error,

Powered by Google App Engine
This is Rietveld 408576698