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/strings/string_piece.h" | 8 #include "base/strings/string_piece.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "content/public/child/v8_value_converter.h" | 10 #include "content/public/child/v8_value_converter.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 } | 65 } |
66 if (maximum && value > *maximum) { | 66 if (maximum && value > *maximum) { |
67 *error = api_errors::NumberTooLarge(*maximum); | 67 *error = api_errors::NumberTooLarge(*maximum); |
68 return false; | 68 return false; |
69 } | 69 } |
70 return true; | 70 return true; |
71 } | 71 } |
72 | 72 |
73 } // namespace | 73 } // namespace |
74 | 74 |
75 ArgumentSpec::ArgumentSpec(const base::Value& value) | 75 ArgumentSpec::ArgumentSpec(const base::Value& value) { |
76 : type_(ArgumentType::INTEGER), optional_(false), preserve_null_(false) { | |
77 const base::DictionaryValue* dict = nullptr; | 76 const base::DictionaryValue* dict = nullptr; |
78 CHECK(value.GetAsDictionary(&dict)); | 77 CHECK(value.GetAsDictionary(&dict)); |
79 dict->GetBoolean("optional", &optional_); | 78 dict->GetBoolean("optional", &optional_); |
80 dict->GetString("name", &name_); | 79 dict->GetString("name", &name_); |
81 | 80 |
82 InitializeType(dict); | 81 InitializeType(dict); |
83 } | 82 } |
84 | 83 |
85 ArgumentSpec::ArgumentSpec(ArgumentType type) : type_(type), optional_(false) {} | 84 ArgumentSpec::ArgumentSpec(ArgumentType type) : type_(type) {} |
86 | 85 |
87 void ArgumentSpec::InitializeType(const base::DictionaryValue* dict) { | 86 void ArgumentSpec::InitializeType(const base::DictionaryValue* dict) { |
88 std::string ref_string; | 87 std::string ref_string; |
89 if (dict->GetString("$ref", &ref_string)) { | 88 if (dict->GetString("$ref", &ref_string)) { |
90 ref_ = std::move(ref_string); | 89 ref_ = std::move(ref_string); |
91 type_ = ArgumentType::REF; | 90 type_ = ArgumentType::REF; |
92 return; | 91 return; |
93 } | 92 } |
94 | 93 |
95 { | 94 { |
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 break; | 617 break; |
619 case ArgumentType::CHOICES: | 618 case ArgumentType::CHOICES: |
620 case ArgumentType::ANY: | 619 case ArgumentType::ANY: |
621 NOTREACHED(); | 620 NOTREACHED(); |
622 } | 621 } |
623 | 622 |
624 return api_errors::InvalidType(expected_type, GetV8ValueTypeString(value)); | 623 return api_errors::InvalidType(expected_type, GetV8ValueTypeString(value)); |
625 } | 624 } |
626 | 625 |
627 } // namespace extensions | 626 } // namespace extensions |
OLD | NEW |