OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // GENERATED FROM THE API DEFINITION IN |
| 6 // chrome/common/extensions/api/experimental.declarative.json |
| 7 // DO NOT EDIT. |
| 8 |
| 9 #include "tools/json_schema_compiler/util.h" |
| 10 #include "chrome/common/extensions/api/experimental.declarative.h" |
| 11 |
| 12 using base::Value; |
| 13 using base::DictionaryValue; |
| 14 using base::ListValue; |
| 15 |
| 16 namespace extensions { |
| 17 namespace api { |
| 18 namespace experimental { |
| 19 |
| 20 // |
| 21 // Types |
| 22 // |
| 23 |
| 24 Rule::Rule() {} |
| 25 Rule::~Rule() {} |
| 26 |
| 27 // static |
| 28 bool Rule::Populate(const Value& value, Rule* out) { |
| 29 if (!value.IsType(Value::TYPE_DICTIONARY)) |
| 30 return false; |
| 31 const DictionaryValue* dict = static_cast<const DictionaryValue*>(&value); |
| 32 |
| 33 Value* priority_value = NULL; |
| 34 if (dict->GetWithoutPathExpansion("priority", &priority_value)) { |
| 35 { |
| 36 if (!priority_value->IsType(Value::TYPE_INTEGER)) |
| 37 return false; |
| 38 int temp; |
| 39 if (priority_value->GetAsInteger(&temp)) |
| 40 out->priority.reset(new int(temp)); |
| 41 } |
| 42 } |
| 43 |
| 44 Value* conditions_value = NULL; |
| 45 if (!dict->GetWithoutPathExpansion("conditions", &conditions_value)) |
| 46 return false; |
| 47 { |
| 48 if (!conditions_value->IsType(Value::TYPE_LIST)) |
| 49 return false; |
| 50 ListValue* list = NULL; |
| 51 if (!conditions_value->GetAsList(&list)) |
| 52 return false; |
| 53 if (!json_schema_compiler::util::PopulateArrayFromList(*list, &out->conditio
ns)) |
| 54 return false; |
| 55 } |
| 56 |
| 57 Value* id_value = NULL; |
| 58 if (dict->GetWithoutPathExpansion("id", &id_value)) { |
| 59 { |
| 60 if (!id_value->IsType(Value::TYPE_STRING)) |
| 61 return false; |
| 62 std::string temp; |
| 63 if (id_value->GetAsString(&temp)) |
| 64 out->id.reset(new std::string(temp)); |
| 65 } |
| 66 } |
| 67 |
| 68 Value* actions_value = NULL; |
| 69 if (!dict->GetWithoutPathExpansion("actions", &actions_value)) |
| 70 return false; |
| 71 { |
| 72 if (!actions_value->IsType(Value::TYPE_LIST)) |
| 73 return false; |
| 74 ListValue* list = NULL; |
| 75 if (!actions_value->GetAsList(&list)) |
| 76 return false; |
| 77 if (!json_schema_compiler::util::PopulateArrayFromList(*list, &out->actions)
) |
| 78 return false; |
| 79 } |
| 80 |
| 81 return true; |
| 82 } |
| 83 |
| 84 scoped_ptr<DictionaryValue> Rule::ToValue() const { |
| 85 scoped_ptr<DictionaryValue> value(new DictionaryValue()); |
| 86 |
| 87 if (priority.get()) |
| 88 value->SetWithoutPathExpansion("priority", Value::CreateIntegerValue(*priori
ty)); |
| 89 json_schema_compiler::util::PopulateDictionaryFromArray(conditions, "condition
s", value.get()); |
| 90 if (id.get()) |
| 91 value->SetWithoutPathExpansion("id", Value::CreateStringValue(*id)); |
| 92 json_schema_compiler::util::PopulateDictionaryFromArray(actions, "actions", va
lue.get()); |
| 93 |
| 94 return value.Pass(); |
| 95 } |
| 96 |
| 97 |
| 98 // |
| 99 // Functions |
| 100 // |
| 101 |
| 102 GetRules::Params::Params() {} |
| 103 GetRules::Params::~Params() {} |
| 104 |
| 105 // static |
| 106 scoped_ptr<GetRules::Params> GetRules::Params::Create(const ListValue& args) { |
| 107 if (args.GetSize() < 1 || args.GetSize() > 2) |
| 108 return scoped_ptr<Params>(); |
| 109 scoped_ptr<Params> params(new Params()); |
| 110 |
| 111 Value* event_value = NULL; |
| 112 if (!args.Get(0, &event_value) || event_value->IsType(Value::TYPE_NULL)) |
| 113 return scoped_ptr<Params>(); |
| 114 { |
| 115 if (!event_value->IsType(Value::TYPE_STRING)) |
| 116 return scoped_ptr<Params>(); |
| 117 if (!event_value->GetAsString(¶ms->event)) |
| 118 return scoped_ptr<Params>(); |
| 119 } |
| 120 |
| 121 Value* rule_identifiers_value = NULL; |
| 122 if (!args.Get(1, &rule_identifiers_value) || rule_identifiers_value->IsType(Va
lue::TYPE_NULL)) |
| 123 return params.Pass(); |
| 124 { |
| 125 if (!rule_identifiers_value->IsType(Value::TYPE_LIST)) |
| 126 return scoped_ptr<Params>(); |
| 127 ListValue* list = NULL; |
| 128 if (!rule_identifiers_value->GetAsList(&list)) |
| 129 return scoped_ptr<Params>(); |
| 130 if (!json_schema_compiler::util::PopulateOptionalArrayFromList(*list, ¶m
s->rule_identifiers)) |
| 131 return scoped_ptr<Params>(); |
| 132 } |
| 133 |
| 134 return params.Pass(); |
| 135 } |
| 136 |
| 137 |
| 138 Value* GetRules::Result::Create(const std::vector<linked_ptr<Rule> >& rules) { |
| 139 ListValue* value = new ListValue(); |
| 140 json_schema_compiler::util::PopulateListFromArray(rules, value); |
| 141 return value; |
| 142 } |
| 143 |
| 144 RemoveRules::Params::Params() {} |
| 145 RemoveRules::Params::~Params() {} |
| 146 |
| 147 // static |
| 148 scoped_ptr<RemoveRules::Params> RemoveRules::Params::Create(const ListValue& arg
s) { |
| 149 if (args.GetSize() < 1 || args.GetSize() > 2) |
| 150 return scoped_ptr<Params>(); |
| 151 scoped_ptr<Params> params(new Params()); |
| 152 |
| 153 Value* event_value = NULL; |
| 154 if (!args.Get(0, &event_value) || event_value->IsType(Value::TYPE_NULL)) |
| 155 return scoped_ptr<Params>(); |
| 156 { |
| 157 if (!event_value->IsType(Value::TYPE_STRING)) |
| 158 return scoped_ptr<Params>(); |
| 159 if (!event_value->GetAsString(¶ms->event)) |
| 160 return scoped_ptr<Params>(); |
| 161 } |
| 162 |
| 163 Value* rule_identifiers_value = NULL; |
| 164 if (!args.Get(1, &rule_identifiers_value) || rule_identifiers_value->IsType(Va
lue::TYPE_NULL)) |
| 165 return params.Pass(); |
| 166 { |
| 167 if (!rule_identifiers_value->IsType(Value::TYPE_LIST)) |
| 168 return scoped_ptr<Params>(); |
| 169 ListValue* list = NULL; |
| 170 if (!rule_identifiers_value->GetAsList(&list)) |
| 171 return scoped_ptr<Params>(); |
| 172 if (!json_schema_compiler::util::PopulateOptionalArrayFromList(*list, ¶m
s->rule_identifiers)) |
| 173 return scoped_ptr<Params>(); |
| 174 } |
| 175 |
| 176 return params.Pass(); |
| 177 } |
| 178 |
| 179 |
| 180 Value* RemoveRules::Result::Create() { |
| 181 return Value::CreateNullValue(); |
| 182 } |
| 183 |
| 184 AddRules::Params::Params() {} |
| 185 AddRules::Params::~Params() {} |
| 186 |
| 187 // static |
| 188 scoped_ptr<AddRules::Params> AddRules::Params::Create(const ListValue& args) { |
| 189 if (args.GetSize() != 2) |
| 190 return scoped_ptr<Params>(); |
| 191 scoped_ptr<Params> params(new Params()); |
| 192 |
| 193 Value* event_value = NULL; |
| 194 if (!args.Get(0, &event_value) || event_value->IsType(Value::TYPE_NULL)) |
| 195 return scoped_ptr<Params>(); |
| 196 { |
| 197 if (!event_value->IsType(Value::TYPE_STRING)) |
| 198 return scoped_ptr<Params>(); |
| 199 if (!event_value->GetAsString(¶ms->event)) |
| 200 return scoped_ptr<Params>(); |
| 201 } |
| 202 |
| 203 Value* rules_value = NULL; |
| 204 if (!args.Get(1, &rules_value) || rules_value->IsType(Value::TYPE_NULL)) |
| 205 return scoped_ptr<Params>(); |
| 206 { |
| 207 if (!rules_value->IsType(Value::TYPE_LIST)) |
| 208 return scoped_ptr<Params>(); |
| 209 ListValue* list = NULL; |
| 210 if (!rules_value->GetAsList(&list)) |
| 211 return scoped_ptr<Params>(); |
| 212 if (!json_schema_compiler::util::PopulateArrayFromList(*list, ¶ms->rules
)) |
| 213 return scoped_ptr<Params>(); |
| 214 } |
| 215 |
| 216 return params.Pass(); |
| 217 } |
| 218 |
| 219 |
| 220 Value* AddRules::Result::Create(const std::vector<linked_ptr<Rule> >& rules) { |
| 221 ListValue* value = new ListValue(); |
| 222 json_schema_compiler::util::PopulateListFromArray(rules, value); |
| 223 return value; |
| 224 } |
| 225 |
| 226 } // experimental |
| 227 } // api |
| 228 } // extensions |
OLD | NEW |