| 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 "gin/converter.h" | 10 #include "gin/converter.h" |
| 11 #include "gin/dictionary.h" | 11 #include "gin/dictionary.h" |
| 12 | 12 |
| 13 namespace extensions { | 13 namespace extensions { |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 template <class T> | 17 template <class T> |
| 18 std::unique_ptr<base::Value> GetFundamentalConvertedValueHelper( | 18 std::unique_ptr<base::Value> GetFundamentalConvertedValueHelper( |
| 19 v8::Local<v8::Value> arg, | 19 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 T val; | 22 T val; |
| 23 if (!gin::Converter<T>::FromV8(context->GetIsolate(), arg, &val)) | 23 if (!gin::Converter<T>::FromV8(context->GetIsolate(), arg, &val)) |
| 24 return nullptr; | 24 return nullptr; |
| 25 if (minimum && val < minimum.value()) | 25 if (minimum && val < minimum.value()) |
| 26 return nullptr; | 26 return nullptr; |
| 27 return base::MakeUnique<base::FundamentalValue>(val); | 27 return base::MakeUnique<base::Value>(val); |
| 28 } | 28 } |
| 29 | 29 |
| 30 } // namespace | 30 } // namespace |
| 31 | 31 |
| 32 ArgumentSpec::ArgumentSpec(const base::Value& value) | 32 ArgumentSpec::ArgumentSpec(const base::Value& value) |
| 33 : type_(ArgumentType::INTEGER), optional_(false) { | 33 : type_(ArgumentType::INTEGER), optional_(false) { |
| 34 const base::DictionaryValue* dict = nullptr; | 34 const base::DictionaryValue* dict = nullptr; |
| 35 CHECK(value.GetAsDictionary(&dict)); | 35 CHECK(value.GetAsDictionary(&dict)); |
| 36 dict->GetBoolean("optional", &optional_); | 36 dict->GetBoolean("optional", &optional_); |
| 37 dict->GetString("name", &name_); | 37 dict->GetString("name", &name_); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 value, &s) || | 173 value, &s) || |
| 174 (!enum_values_.empty() && enum_values_.count(s) == 0)) { | 174 (!enum_values_.empty() && enum_values_.count(s) == 0)) { |
| 175 return nullptr; | 175 return nullptr; |
| 176 } | 176 } |
| 177 return base::MakeUnique<base::StringValue>(s); | 177 return base::MakeUnique<base::StringValue>(s); |
| 178 } | 178 } |
| 179 case ArgumentType::BOOLEAN: { | 179 case ArgumentType::BOOLEAN: { |
| 180 bool b = false; | 180 bool b = false; |
| 181 if (value->IsBoolean() && | 181 if (value->IsBoolean() && |
| 182 gin::Converter<bool>::FromV8(context->GetIsolate(), value, &b)) { | 182 gin::Converter<bool>::FromV8(context->GetIsolate(), value, &b)) { |
| 183 return base::MakeUnique<base::FundamentalValue>(b); | 183 return base::MakeUnique<base::Value>(b); |
| 184 } | 184 } |
| 185 return nullptr; | 185 return nullptr; |
| 186 } | 186 } |
| 187 default: | 187 default: |
| 188 NOTREACHED(); | 188 NOTREACHED(); |
| 189 } | 189 } |
| 190 return nullptr; | 190 return nullptr; |
| 191 } | 191 } |
| 192 | 192 |
| 193 std::unique_ptr<base::Value> ArgumentSpec::ConvertArgumentToObject( | 193 std::unique_ptr<base::Value> ArgumentSpec::ConvertArgumentToObject( |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 std::unique_ptr<content::V8ValueConverter> converter( | 264 std::unique_ptr<content::V8ValueConverter> converter( |
| 265 content::V8ValueConverter::create()); | 265 content::V8ValueConverter::create()); |
| 266 std::unique_ptr<base::Value> converted( | 266 std::unique_ptr<base::Value> converted( |
| 267 converter->FromV8Value(value, context)); | 267 converter->FromV8Value(value, context)); |
| 268 if (!converted) | 268 if (!converted) |
| 269 *error = "Could not convert to 'any'."; | 269 *error = "Could not convert to 'any'."; |
| 270 return converted; | 270 return converted; |
| 271 } | 271 } |
| 272 | 272 |
| 273 } // namespace extensions | 273 } // namespace extensions |
| OLD | NEW |