Chromium Code Reviews| 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" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 86 } else if (type_ == ArgumentType::STRING) { | 86 } else if (type_ == ArgumentType::STRING) { |
| 87 // Technically, there's no reason enums couldn't be other objects (e.g. | 87 // Technically, there's no reason enums couldn't be other objects (e.g. |
| 88 // numbers), but right now they seem to be exclusively strings. We could | 88 // numbers), but right now they seem to be exclusively strings. We could |
| 89 // always update this if need be. | 89 // always update this if need be. |
| 90 const base::ListValue* enums = nullptr; | 90 const base::ListValue* enums = nullptr; |
| 91 if (dict->GetList("enum", &enums)) { | 91 if (dict->GetList("enum", &enums)) { |
| 92 size_t size = enums->GetSize(); | 92 size_t size = enums->GetSize(); |
| 93 CHECK_GT(size, 0u); | 93 CHECK_GT(size, 0u); |
| 94 for (size_t i = 0; i < size; ++i) { | 94 for (size_t i = 0; i < size; ++i) { |
| 95 std::string enum_value; | 95 std::string enum_value; |
| 96 CHECK(enums->GetString(i, &enum_value)); | 96 // Enum entries come in two versions: a list of possible strings, and |
|
jbroman
2016/10/21 22:53:59
Could this and its unit test be in another CL? It
Devlin
2016/10/22 00:49:15
Sure, I'll pull them out. They're still needed he
| |
| 97 // a dictionary with a field 'name'. | |
| 98 if (!enums->GetString(i, &enum_value)) { | |
| 99 const base::DictionaryValue* enum_value_dictionary = nullptr; | |
| 100 CHECK(enums->GetDictionary(i, &enum_value_dictionary)); | |
| 101 CHECK(enum_value_dictionary->GetString("name", &enum_value)); | |
| 102 } | |
| 97 enum_values_.insert(std::move(enum_value)); | 103 enum_values_.insert(std::move(enum_value)); |
| 98 } | 104 } |
| 99 } | 105 } |
| 100 } | 106 } |
| 101 } | 107 } |
| 102 | 108 |
| 103 ArgumentSpec::~ArgumentSpec() {} | 109 ArgumentSpec::~ArgumentSpec() {} |
| 104 | 110 |
| 105 std::unique_ptr<base::Value> ArgumentSpec::ConvertArgument( | 111 std::unique_ptr<base::Value> ArgumentSpec::ConvertArgument( |
| 106 v8::Local<v8::Context> context, | 112 v8::Local<v8::Context> context, |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 258 std::unique_ptr<content::V8ValueConverter> converter( | 264 std::unique_ptr<content::V8ValueConverter> converter( |
| 259 content::V8ValueConverter::create()); | 265 content::V8ValueConverter::create()); |
| 260 std::unique_ptr<base::Value> converted( | 266 std::unique_ptr<base::Value> converted( |
| 261 converter->FromV8Value(value, context)); | 267 converter->FromV8Value(value, context)); |
| 262 if (!converted) | 268 if (!converted) |
| 263 *error = "Could not convert to 'any'."; | 269 *error = "Could not convert to 'any'."; |
| 264 return converted; | 270 return converted; |
| 265 } | 271 } |
| 266 | 272 |
| 267 } // namespace extensions | 273 } // namespace extensions |
| OLD | NEW |