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

Side by Side Diff: extensions/renderer/argument_spec.h

Issue 2583273002: [Extensions Bindings] Allow for argument validation without conversion (Closed)
Patch Set: lazyboy's Created 3 years, 12 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
« no previous file with comments | « extensions/renderer/api_signature.cc ('k') | extensions/renderer/argument_spec.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifndef EXTENSIONS_RENDERER_ARGUMENT_SPEC_H_ 5 #ifndef EXTENSIONS_RENDERER_ARGUMENT_SPEC_H_
6 #define EXTENSIONS_RENDERER_ARGUMENT_SPEC_H_ 6 #define EXTENSIONS_RENDERER_ARGUMENT_SPEC_H_
7 7
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <set> 10 #include <set>
(...skipping 30 matching lines...) Expand all
41 // A map from name -> definition for type definitions. This is used when an 41 // A map from name -> definition for type definitions. This is used when an
42 // argument is declared to be a reference to a type defined elsewhere. 42 // argument is declared to be a reference to a type defined elsewhere.
43 using RefMap = std::map<std::string, std::unique_ptr<ArgumentSpec>>; 43 using RefMap = std::map<std::string, std::unique_ptr<ArgumentSpec>>;
44 44
45 // Reads the description from |value| and sets associated fields. 45 // Reads the description from |value| and sets associated fields.
46 // TODO(devlin): We should strongly think about generating these instead of 46 // TODO(devlin): We should strongly think about generating these instead of
47 // populating them at runtime. 47 // populating them at runtime.
48 explicit ArgumentSpec(const base::Value& value); 48 explicit ArgumentSpec(const base::Value& value);
49 ~ArgumentSpec(); 49 ~ArgumentSpec();
50 50
51 // Returns the converted base::Value or null if the |value| didn't match. 51 // Returns true if the passed |value| matches this specification. If
52 std::unique_ptr<base::Value> ConvertArgument( 52 // |out_value| is non-null, converts the value to a base::Value and populates
53 v8::Local<v8::Context> context, 53 // |out_value|. Otherwise, no conversion is performed.
54 v8::Local<v8::Value> value, 54 bool ParseArgument(v8::Local<v8::Context> context,
55 const RefMap& refs, 55 v8::Local<v8::Value> value,
56 std::string* error) const; 56 const RefMap& refs,
57 std::unique_ptr<base::Value>* out_value,
58 std::string* error) const;
57 59
58 const std::string& name() const { return name_; } 60 const std::string& name() const { return name_; }
59 bool optional() const { return optional_; } 61 bool optional() const { return optional_; }
60 ArgumentType type() const { return type_; } 62 ArgumentType type() const { return type_; }
61 63
62 private: 64 private:
63 // Initializes this object according to |type_string| and |dict|. 65 // Initializes this object according to |type_string| and |dict|.
64 void InitializeType(const base::DictionaryValue* dict); 66 void InitializeType(const base::DictionaryValue* dict);
65 67
66 // Returns true if this argument refers to a fundamental type. 68 // Returns true if this argument refers to a fundamental type.
67 bool IsFundamentalType() const; 69 bool IsFundamentalType() const;
68 70
69 // Conversion functions. These should only be used if the spec is of the given 71 // Conversion functions. These should only be used if the spec is of the given
70 // type (otherwise, they will DCHECK). 72 // type (otherwise, they will DCHECK).
71 std::unique_ptr<base::Value> ConvertArgumentToFundamental( 73 bool ParseArgumentToFundamental(v8::Local<v8::Context> context,
72 v8::Local<v8::Context> context, 74 v8::Local<v8::Value> value,
73 v8::Local<v8::Value> value, 75 std::unique_ptr<base::Value>* out_value,
74 std::string* error) const; 76 std::string* error) const;
75 std::unique_ptr<base::Value> ConvertArgumentToObject( 77 bool ParseArgumentToObject(v8::Local<v8::Context> context,
76 v8::Local<v8::Context> context, 78 v8::Local<v8::Object> object,
77 v8::Local<v8::Object> object, 79 const RefMap& refs,
78 const RefMap& refs, 80 std::unique_ptr<base::Value>* out_value,
79 std::string* error) const; 81 std::string* error) const;
80 std::unique_ptr<base::Value> ConvertArgumentToArray( 82 bool ParseArgumentToArray(v8::Local<v8::Context> context,
81 v8::Local<v8::Context> context, 83 v8::Local<v8::Array> value,
82 v8::Local<v8::Array> value, 84 const RefMap& refs,
83 const RefMap& refs, 85 std::unique_ptr<base::Value>* out_value,
84 std::string* error) const; 86 std::string* error) const;
85 std::unique_ptr<base::Value> ConvertArgumentToAny( 87 bool ParseArgumentToAny(v8::Local<v8::Context> context,
86 v8::Local<v8::Context> context, 88 v8::Local<v8::Value> value,
87 v8::Local<v8::Value> value, 89 std::unique_ptr<base::Value>* out_value,
88 std::string* error) const; 90 std::string* error) const;
89 91
90 // The name of the argument. 92 // The name of the argument.
91 std::string name_; 93 std::string name_;
92 94
93 // The type of the argument. 95 // The type of the argument.
94 ArgumentType type_; 96 ArgumentType type_;
95 97
96 // Whether or not the argument is required. 98 // Whether or not the argument is required.
97 bool optional_; 99 bool optional_;
98 100
(...skipping 17 matching lines...) Expand all
116 118
117 // The possible enum values, if defined for this argument. 119 // The possible enum values, if defined for this argument.
118 std::set<std::string> enum_values_; 120 std::set<std::string> enum_values_;
119 121
120 DISALLOW_COPY_AND_ASSIGN(ArgumentSpec); 122 DISALLOW_COPY_AND_ASSIGN(ArgumentSpec);
121 }; 123 };
122 124
123 } // namespace extensions 125 } // namespace extensions
124 126
125 #endif // EXTENSIONS_RENDERER_ARGUMENT_SPEC_H_ 127 #endif // EXTENSIONS_RENDERER_ARGUMENT_SPEC_H_
OLDNEW
« no previous file with comments | « extensions/renderer/api_signature.cc ('k') | extensions/renderer/argument_spec.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698