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

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

Issue 2947223003: [Extensions Bindings] Consider argument type more in signature parsing (Closed)
Patch Set: rebase Created 3 years, 6 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 #ifndef EXTENSIONS_RENDERER_BINDINGS_ARGUMENT_SPEC_H_ 5 #ifndef EXTENSIONS_RENDERER_BINDINGS_ARGUMENT_SPEC_H_
6 #define EXTENSIONS_RENDERER_BINDINGS_ARGUMENT_SPEC_H_ 6 #define EXTENSIONS_RENDERER_BINDINGS_ARGUMENT_SPEC_H_
7 7
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <set> 10 #include <set>
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 public: 43 public:
44 using PropertiesMap = std::map<std::string, std::unique_ptr<ArgumentSpec>>; 44 using PropertiesMap = std::map<std::string, std::unique_ptr<ArgumentSpec>>;
45 45
46 // Reads the description from |value| and sets associated fields. 46 // Reads the description from |value| and sets associated fields.
47 // TODO(devlin): We should strongly think about generating these instead of 47 // TODO(devlin): We should strongly think about generating these instead of
48 // populating them at runtime. 48 // populating them at runtime.
49 explicit ArgumentSpec(const base::Value& value); 49 explicit ArgumentSpec(const base::Value& value);
50 explicit ArgumentSpec(ArgumentType type); 50 explicit ArgumentSpec(ArgumentType type);
51 ~ArgumentSpec(); 51 ~ArgumentSpec();
52 52
53 // Returns true if the given |value| is of the correct type to match this
54 // spec. If it is not, populates |error|.
55 bool IsCorrectType(v8::Local<v8::Value> value,
56 const APITypeReferenceMap& refs,
57 std::string* error) const;
58
53 // Returns true if the passed |value| matches this specification. If 59 // Returns true if the passed |value| matches this specification. If
54 // |out_value| is non-null, converts the value to a base::Value and populates 60 // |out_value| is non-null, converts the value to a base::Value and populates
55 // |out_value|. Otherwise, no conversion is performed. 61 // |out_value|. Otherwise, no conversion is performed.
56 bool ParseArgument(v8::Local<v8::Context> context, 62 bool ParseArgument(v8::Local<v8::Context> context,
57 v8::Local<v8::Value> value, 63 v8::Local<v8::Value> value,
58 const APITypeReferenceMap& refs, 64 const APITypeReferenceMap& refs,
59 std::unique_ptr<base::Value>* out_value, 65 std::unique_ptr<base::Value>* out_value,
60 std::string* error) const; 66 std::string* error) const;
61 67
62 // Returns a type name for this argument. Note: This should only be used to 68 // Returns a type name for this argument. Note: This should only be used to
(...skipping 23 matching lines...) Expand all
86 } 92 }
87 void set_additional_properties( 93 void set_additional_properties(
88 std::unique_ptr<ArgumentSpec> additional_properties) { 94 std::unique_ptr<ArgumentSpec> additional_properties) {
89 additional_properties_ = std::move(additional_properties); 95 additional_properties_ = std::move(additional_properties);
90 } 96 }
91 97
92 private: 98 private:
93 // Initializes this object according to |type_string| and |dict|. 99 // Initializes this object according to |type_string| and |dict|.
94 void InitializeType(const base::DictionaryValue* dict); 100 void InitializeType(const base::DictionaryValue* dict);
95 101
96 // Returns true if this argument refers to a fundamental type.
97 bool IsFundamentalType() const;
98
99 // Conversion functions. These should only be used if the spec is of the given 102 // Conversion functions. These should only be used if the spec is of the given
100 // type (otherwise, they will DCHECK). 103 // type (otherwise, they will DCHECK).
101 bool ParseArgumentToFundamental(v8::Local<v8::Context> context, 104 bool ParseArgumentToFundamental(v8::Local<v8::Context> context,
102 v8::Local<v8::Value> value, 105 v8::Local<v8::Value> value,
103 std::unique_ptr<base::Value>* out_value, 106 std::unique_ptr<base::Value>* out_value,
104 std::string* error) const; 107 std::string* error) const;
105 bool ParseArgumentToObject(v8::Local<v8::Context> context, 108 bool ParseArgumentToObject(v8::Local<v8::Context> context,
106 v8::Local<v8::Object> object, 109 v8::Local<v8::Object> object,
107 const APITypeReferenceMap& refs, 110 const APITypeReferenceMap& refs,
108 std::unique_ptr<base::Value>* out_value, 111 std::unique_ptr<base::Value>* out_value,
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 // to allow the API to pass an object with arbitrary properties. Only 176 // to allow the API to pass an object with arbitrary properties. Only
174 // applicable for ArgumentType::OBJECT. 177 // applicable for ArgumentType::OBJECT.
175 std::unique_ptr<ArgumentSpec> additional_properties_; 178 std::unique_ptr<ArgumentSpec> additional_properties_;
176 179
177 DISALLOW_COPY_AND_ASSIGN(ArgumentSpec); 180 DISALLOW_COPY_AND_ASSIGN(ArgumentSpec);
178 }; 181 };
179 182
180 } // namespace extensions 183 } // namespace extensions
181 184
182 #endif // EXTENSIONS_RENDERER_BINDINGS_ARGUMENT_SPEC_H_ 185 #endif // EXTENSIONS_RENDERER_BINDINGS_ARGUMENT_SPEC_H_
OLDNEW
« no previous file with comments | « extensions/renderer/bindings/api_signature_unittest.cc ('k') | extensions/renderer/bindings/argument_spec.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698