OLD | NEW |
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/argument_spec.h" | 5 #include "extensions/renderer/argument_spec.h" |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "content/public/child/v8_value_converter.h" | 9 #include "content/public/child/v8_value_converter.h" |
10 #include "extensions/renderer/api_type_reference_map.h" | 10 #include "extensions/renderer/api_type_reference_map.h" |
11 #include "gin/converter.h" | 11 #include "gin/converter.h" |
12 #include "gin/dictionary.h" | 12 #include "gin/dictionary.h" |
13 | 13 |
14 namespace extensions { | 14 namespace extensions { |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 template <class T> | 18 template <class T> |
19 bool ParseFundamentalValueHelper(v8::Local<v8::Value> arg, | 19 bool ParseFundamentalValueHelper(v8::Local<v8::Value> arg, |
20 v8::Local<v8::Context> context, | 20 v8::Local<v8::Context> context, |
21 const base::Optional<int>& minimum, | 21 const base::Optional<int>& minimum, |
22 std::unique_ptr<base::Value>* out_value) { | 22 std::unique_ptr<base::Value>* out_value) { |
23 T val; | 23 T val; |
24 if (!gin::Converter<T>::FromV8(context->GetIsolate(), arg, &val)) | 24 if (!gin::Converter<T>::FromV8(context->GetIsolate(), arg, &val)) |
25 return false; | 25 return false; |
26 if (minimum && val < minimum.value()) | 26 if (minimum && val < minimum.value()) |
27 return false; | 27 return false; |
28 if (out_value) | 28 if (out_value) |
29 *out_value = base::MakeUnique<base::FundamentalValue>(val); | 29 *out_value = base::MakeUnique<base::Value>(val); |
30 return true; | 30 return true; |
31 } | 31 } |
32 | 32 |
33 } // namespace | 33 } // namespace |
34 | 34 |
35 ArgumentSpec::ArgumentSpec(const base::Value& value) | 35 ArgumentSpec::ArgumentSpec(const base::Value& value) |
36 : type_(ArgumentType::INTEGER), optional_(false) { | 36 : type_(ArgumentType::INTEGER), optional_(false) { |
37 const base::DictionaryValue* dict = nullptr; | 37 const base::DictionaryValue* dict = nullptr; |
38 CHECK(value.GetAsDictionary(&dict)); | 38 CHECK(value.GetAsDictionary(&dict)); |
39 dict->GetBoolean("optional", &optional_); | 39 dict->GetBoolean("optional", &optional_); |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 // TODO(devlin): If base::StringValue ever takes a std::string&&, we | 231 // TODO(devlin): If base::StringValue ever takes a std::string&&, we |
232 // could use std::move to construct. | 232 // could use std::move to construct. |
233 *out_value = base::MakeUnique<base::StringValue>(s); | 233 *out_value = base::MakeUnique<base::StringValue>(s); |
234 } | 234 } |
235 return true; | 235 return true; |
236 } | 236 } |
237 case ArgumentType::BOOLEAN: { | 237 case ArgumentType::BOOLEAN: { |
238 if (!value->IsBoolean()) | 238 if (!value->IsBoolean()) |
239 return false; | 239 return false; |
240 if (out_value) { | 240 if (out_value) { |
241 *out_value = base::MakeUnique<base::FundamentalValue>( | 241 *out_value = |
242 value.As<v8::Boolean>()->Value()); | 242 base::MakeUnique<base::Value>(value.As<v8::Boolean>()->Value()); |
243 } | 243 } |
244 return true; | 244 return true; |
245 } | 245 } |
246 default: | 246 default: |
247 NOTREACHED(); | 247 NOTREACHED(); |
248 } | 248 } |
249 return false; | 249 return false; |
250 } | 250 } |
251 | 251 |
252 bool ArgumentSpec::ParseArgumentToObject( | 252 bool ArgumentSpec::ParseArgumentToObject( |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 return false; | 391 return false; |
392 } | 392 } |
393 if (type_ == ArgumentType::BINARY) | 393 if (type_ == ArgumentType::BINARY) |
394 DCHECK_EQ(base::Value::Type::BINARY, converted->GetType()); | 394 DCHECK_EQ(base::Value::Type::BINARY, converted->GetType()); |
395 *out_value = std::move(converted); | 395 *out_value = std::move(converted); |
396 } | 396 } |
397 return true; | 397 return true; |
398 } | 398 } |
399 | 399 |
400 } // namespace extensions | 400 } // namespace extensions |
OLD | NEW |