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

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

Issue 2949143002: [Extensions Bindings] Support ArrayBufferView in idl files (Closed)
Patch Set: extend comment 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 #include "extensions/renderer/bindings/argument_spec.h" 5 #include "extensions/renderer/bindings/argument_spec.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/strings/string_piece.h" 8 #include "base/strings/string_piece.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 } 159 }
160 } 160 }
161 const base::DictionaryValue* additional_properties_value = nullptr; 161 const base::DictionaryValue* additional_properties_value = nullptr;
162 if (dict->GetDictionary("additionalProperties", 162 if (dict->GetDictionary("additionalProperties",
163 &additional_properties_value)) { 163 &additional_properties_value)) {
164 additional_properties_ = 164 additional_properties_ =
165 base::MakeUnique<ArgumentSpec>(*additional_properties_value); 165 base::MakeUnique<ArgumentSpec>(*additional_properties_value);
166 // Additional properties are always optional. 166 // Additional properties are always optional.
167 additional_properties_->optional_ = true; 167 additional_properties_->optional_ = true;
168 } 168 }
169 std::string instance_of;
170 if (dict->GetString("isInstanceOf", &instance_of)) {
171 instance_of_ = instance_of;
172 }
173 } else if (type_ == ArgumentType::LIST) { 169 } else if (type_ == ArgumentType::LIST) {
174 const base::DictionaryValue* item_value = nullptr; 170 const base::DictionaryValue* item_value = nullptr;
175 CHECK(dict->GetDictionary("items", &item_value)); 171 CHECK(dict->GetDictionary("items", &item_value));
176 list_element_type_ = base::MakeUnique<ArgumentSpec>(*item_value); 172 list_element_type_ = base::MakeUnique<ArgumentSpec>(*item_value);
177 } else if (type_ == ArgumentType::STRING) { 173 } else if (type_ == ArgumentType::STRING) {
178 // Technically, there's no reason enums couldn't be other objects (e.g. 174 // Technically, there's no reason enums couldn't be other objects (e.g.
179 // numbers), but right now they seem to be exclusively strings. We could 175 // numbers), but right now they seem to be exclusively strings. We could
180 // always update this if need be. 176 // always update this if need be.
181 const base::ListValue* enums = nullptr; 177 const base::ListValue* enums = nullptr;
182 if (dict->GetList("enum", &enums)) { 178 if (dict->GetList("enum", &enums)) {
(...skipping 11 matching lines...) Expand all
194 enum_values_.insert(std::move(enum_value)); 190 enum_values_.insert(std::move(enum_value));
195 } 191 }
196 } 192 }
197 } 193 }
198 194
199 // Check if we should preserve null in objects. Right now, this is only used 195 // Check if we should preserve null in objects. Right now, this is only used
200 // on arguments of type object and any (in fact, it's only used in the storage 196 // on arguments of type object and any (in fact, it's only used in the storage
201 // API), but it could potentially make sense for lists or functions as well. 197 // API), but it could potentially make sense for lists or functions as well.
202 if (type_ == ArgumentType::OBJECT || type_ == ArgumentType::ANY) 198 if (type_ == ArgumentType::OBJECT || type_ == ArgumentType::ANY)
203 dict->GetBoolean("preserveNull", &preserve_null_); 199 dict->GetBoolean("preserveNull", &preserve_null_);
200
201 if (type_ == ArgumentType::OBJECT || type_ == ArgumentType::BINARY) {
202 std::string instance_of;
203 if (dict->GetString("isInstanceOf", &instance_of))
204 instance_of_ = instance_of;
205 }
204 } 206 }
205 207
206 ArgumentSpec::~ArgumentSpec() {} 208 ArgumentSpec::~ArgumentSpec() {}
207 209
208 bool ArgumentSpec::ParseArgument(v8::Local<v8::Context> context, 210 bool ArgumentSpec::ParseArgument(v8::Local<v8::Context> context,
209 v8::Local<v8::Value> value, 211 v8::Local<v8::Value> value,
210 const APITypeReferenceMap& refs, 212 const APITypeReferenceMap& refs,
211 std::unique_ptr<base::Value>* out_value, 213 std::unique_ptr<base::Value>* out_value,
212 std::string* error) const { 214 std::string* error) const {
213 if (type_ == ArgumentType::FUNCTION) { 215 if (type_ == ArgumentType::FUNCTION) {
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 return true; 636 return true;
635 } 637 }
636 638
637 std::string ArgumentSpec::GetInvalidTypeError( 639 std::string ArgumentSpec::GetInvalidTypeError(
638 v8::Local<v8::Value> value) const { 640 v8::Local<v8::Value> value) const {
639 return api_errors::InvalidType(GetTypeName().c_str(), 641 return api_errors::InvalidType(GetTypeName().c_str(),
640 GetV8ValueTypeString(value)); 642 GetV8ValueTypeString(value));
641 } 643 }
642 644
643 } // namespace extensions 645 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/bindings/api_bindings_system.cc ('k') | extensions/renderer/v8_schema_registry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698