OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/common/extensions/api/extension_api.h" | 5 #include "chrome/common/extensions/api/extension_api.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 // Returns true if |dict| has an unprivileged "true" property. | 43 // Returns true if |dict| has an unprivileged "true" property. |
44 bool IsUnprivileged(const DictionaryValue* dict) { | 44 bool IsUnprivileged(const DictionaryValue* dict) { |
45 bool unprivileged = false; | 45 bool unprivileged = false; |
46 return dict->GetBoolean("unprivileged", &unprivileged) && unprivileged; | 46 return dict->GetBoolean("unprivileged", &unprivileged) && unprivileged; |
47 } | 47 } |
48 | 48 |
49 // Returns whether the list at |name_space_node|.|child_kind| contains any | 49 // Returns whether the list at |name_space_node|.|child_kind| contains any |
50 // children with an { "unprivileged": true } property. | 50 // children with an { "unprivileged": true } property. |
51 bool HasUnprivilegedChild(const DictionaryValue* name_space_node, | 51 bool HasUnprivilegedChild(const DictionaryValue* name_space_node, |
52 const std::string& child_kind) { | 52 const std::string& child_kind) { |
53 ListValue* child_list = NULL; | 53 const ListValue* child_list = NULL; |
54 DictionaryValue* child_dict = NULL; | 54 const DictionaryValue* child_dict = NULL; |
55 | 55 |
56 if (name_space_node->GetList(child_kind, &child_list)) { | 56 if (name_space_node->GetList(child_kind, &child_list)) { |
57 for (size_t i = 0; i < child_list->GetSize(); ++i) { | 57 for (size_t i = 0; i < child_list->GetSize(); ++i) { |
58 DictionaryValue* item = NULL; | 58 DictionaryValue* item = NULL; |
59 CHECK(child_list->GetDictionary(i, &item)); | 59 CHECK(child_list->GetDictionary(i, &item)); |
60 if (IsUnprivileged(item)) | 60 if (IsUnprivileged(item)) |
61 return true; | 61 return true; |
62 } | 62 } |
63 } else if (name_space_node->GetDictionary(child_kind, &child_dict)) { | 63 } else if (name_space_node->GetDictionary(child_kind, &child_dict)) { |
64 for (DictionaryValue::Iterator it(*child_dict); it.HasNext(); | 64 for (DictionaryValue::Iterator it(*child_dict); it.HasNext(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 return item; | 112 return item; |
113 } | 113 } |
114 | 114 |
115 return NULL; | 115 return NULL; |
116 } | 116 } |
117 | 117 |
118 const DictionaryValue* GetSchemaChild(const DictionaryValue* schema_node, | 118 const DictionaryValue* GetSchemaChild(const DictionaryValue* schema_node, |
119 const std::string& child_name) { | 119 const std::string& child_name) { |
120 DictionaryValue* child_node = NULL; | 120 DictionaryValue* child_node = NULL; |
121 for (size_t i = 0; i < arraysize(kChildKinds); ++i) { | 121 for (size_t i = 0; i < arraysize(kChildKinds); ++i) { |
122 ListValue* list_node = NULL; | 122 const ListValue* list_node = NULL; |
123 if (!schema_node->GetList(kChildKinds[i], &list_node)) | 123 if (!schema_node->GetList(kChildKinds[i], &list_node)) |
124 continue; | 124 continue; |
125 child_node = FindListItem(list_node, "name", child_name); | 125 child_node = FindListItem(list_node, "name", child_name); |
126 if (child_node) | 126 if (child_node) |
127 return child_node; | 127 return child_node; |
128 } | 128 } |
129 | 129 |
130 return NULL; | 130 return NULL; |
131 } | 131 } |
132 | 132 |
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
789 std::string feature_name; | 789 std::string feature_name; |
790 SplitDependencyName(api_name, &feature_type, &feature_name); | 790 SplitDependencyName(api_name, &feature_type, &feature_name); |
791 | 791 |
792 // Only API features can have dependencies for now. | 792 // Only API features can have dependencies for now. |
793 if (feature_type != "api") | 793 if (feature_type != "api") |
794 return; | 794 return; |
795 | 795 |
796 const DictionaryValue* schema = GetSchema(feature_name); | 796 const DictionaryValue* schema = GetSchema(feature_name); |
797 CHECK(schema) << "Schema for " << feature_name << " not found"; | 797 CHECK(schema) << "Schema for " << feature_name << " not found"; |
798 | 798 |
799 ListValue* dependencies = NULL; | 799 const ListValue* dependencies = NULL; |
800 if (!schema->GetList("dependencies", &dependencies)) | 800 if (!schema->GetList("dependencies", &dependencies)) |
801 return; | 801 return; |
802 | 802 |
803 for (size_t i = 0; i < dependencies->GetSize(); ++i) { | 803 for (size_t i = 0; i < dependencies->GetSize(); ++i) { |
804 std::string dependency_name; | 804 std::string dependency_name; |
805 if (dependencies->GetString(i, &dependency_name) && | 805 if (dependencies->GetString(i, &dependency_name) && |
806 !excluding.count(dependency_name)) { | 806 !excluding.count(dependency_name)) { |
807 out->insert(dependency_name); | 807 out->insert(dependency_name); |
808 } | 808 } |
809 } | 809 } |
(...skipping 30 matching lines...) Expand all Loading... |
840 | 840 |
841 void ExtensionAPI::LoadAllSchemas() { | 841 void ExtensionAPI::LoadAllSchemas() { |
842 while (unloaded_schemas_.size()) { | 842 while (unloaded_schemas_.size()) { |
843 std::map<std::string, base::StringPiece>::iterator it = | 843 std::map<std::string, base::StringPiece>::iterator it = |
844 unloaded_schemas_.begin(); | 844 unloaded_schemas_.begin(); |
845 LoadSchema(it->first, it->second); | 845 LoadSchema(it->first, it->second); |
846 } | 846 } |
847 } | 847 } |
848 | 848 |
849 } // namespace extensions | 849 } // namespace extensions |
OLD | NEW |