| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/common/api/declarative/declarative_manifest_data.h" | 5 #include "extensions/common/api/declarative/declarative_manifest_data.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/strings/string_piece.h" | 10 #include "base/strings/string_piece.h" |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 new DeclarativeManifestData()); | 122 new DeclarativeManifestData()); |
| 123 const base::ListValue* list = nullptr; | 123 const base::ListValue* list = nullptr; |
| 124 if (!value.GetAsList(&list)) { | 124 if (!value.GetAsList(&list)) { |
| 125 error_builder.Append("'event_rules' expected list, got %s", | 125 error_builder.Append("'event_rules' expected list, got %s", |
| 126 base::Value::GetTypeName(value.GetType())); | 126 base::Value::GetTypeName(value.GetType())); |
| 127 return std::unique_ptr<DeclarativeManifestData>(); | 127 return std::unique_ptr<DeclarativeManifestData>(); |
| 128 } | 128 } |
| 129 | 129 |
| 130 for (const auto& element : *list) { | 130 for (const auto& element : *list) { |
| 131 const base::DictionaryValue* dict = nullptr; | 131 const base::DictionaryValue* dict = nullptr; |
| 132 if (!element.GetAsDictionary(&dict)) { | 132 if (!element->GetAsDictionary(&dict)) { |
| 133 error_builder.Append("expected dictionary, got %s", | 133 error_builder.Append("expected dictionary, got %s", |
| 134 base::Value::GetTypeName(element.GetType())); | 134 base::Value::GetTypeName(element->GetType())); |
| 135 return std::unique_ptr<DeclarativeManifestData>(); | 135 return std::unique_ptr<DeclarativeManifestData>(); |
| 136 } | 136 } |
| 137 std::string event; | 137 std::string event; |
| 138 if (!dict->GetString("event", &event)) { | 138 if (!dict->GetString("event", &event)) { |
| 139 error_builder.Append("'event' is required"); | 139 error_builder.Append("'event' is required"); |
| 140 return std::unique_ptr<DeclarativeManifestData>(); | 140 return std::unique_ptr<DeclarativeManifestData>(); |
| 141 } | 141 } |
| 142 | 142 |
| 143 linked_ptr<Rule> rule(new Rule()); | 143 linked_ptr<Rule> rule(new Rule()); |
| 144 if (!Rule::Populate(*dict, rule.get())) { | 144 if (!Rule::Populate(*dict, rule.get())) { |
| 145 error_builder.Append("rule failed to populate"); | 145 error_builder.Append("rule failed to populate"); |
| 146 return std::unique_ptr<DeclarativeManifestData>(); | 146 return std::unique_ptr<DeclarativeManifestData>(); |
| 147 } | 147 } |
| 148 | 148 |
| 149 if (!ConvertManifestRule(rule, &error_builder)) | 149 if (!ConvertManifestRule(rule, &error_builder)) |
| 150 return std::unique_ptr<DeclarativeManifestData>(); | 150 return std::unique_ptr<DeclarativeManifestData>(); |
| 151 | 151 |
| 152 result->event_rules_map_[event].push_back(rule); | 152 result->event_rules_map_[event].push_back(rule); |
| 153 } | 153 } |
| 154 return result; | 154 return result; |
| 155 } | 155 } |
| 156 | 156 |
| 157 std::vector<linked_ptr<DeclarativeManifestData::Rule>>& | 157 std::vector<linked_ptr<DeclarativeManifestData::Rule>>& |
| 158 DeclarativeManifestData::RulesForEvent(const std::string& event) { | 158 DeclarativeManifestData::RulesForEvent(const std::string& event) { |
| 159 return event_rules_map_[event]; | 159 return event_rules_map_[event]; |
| 160 } | 160 } |
| 161 | 161 |
| 162 } // namespace extensions | 162 } // namespace extensions |
| OLD | NEW |