| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 | 49 |
| 50 // Returns whether the list at |name_space_node|.|child_kind| contains any | 50 // Returns whether the list at |name_space_node|.|child_kind| contains any |
| 51 // children with an { "unprivileged": true } property. | 51 // children with an { "unprivileged": true } property. |
| 52 bool HasUnprivilegedChild(const DictionaryValue* name_space_node, | 52 bool HasUnprivilegedChild(const DictionaryValue* name_space_node, |
| 53 const std::string& child_kind) { | 53 const std::string& child_kind) { |
| 54 const ListValue* child_list = NULL; | 54 const ListValue* child_list = NULL; |
| 55 const DictionaryValue* child_dict = NULL; | 55 const DictionaryValue* child_dict = NULL; |
| 56 | 56 |
| 57 if (name_space_node->GetList(child_kind, &child_list)) { | 57 if (name_space_node->GetList(child_kind, &child_list)) { |
| 58 for (size_t i = 0; i < child_list->GetSize(); ++i) { | 58 for (size_t i = 0; i < child_list->GetSize(); ++i) { |
| 59 DictionaryValue* item = NULL; | 59 const DictionaryValue* item = NULL; |
| 60 CHECK(child_list->GetDictionary(i, &item)); | 60 CHECK(child_list->GetDictionary(i, &item)); |
| 61 if (IsUnprivileged(item)) | 61 if (IsUnprivileged(item)) |
| 62 return true; | 62 return true; |
| 63 } | 63 } |
| 64 } else if (name_space_node->GetDictionary(child_kind, &child_dict)) { | 64 } else if (name_space_node->GetDictionary(child_kind, &child_dict)) { |
| 65 for (DictionaryValue::Iterator it(*child_dict); it.HasNext(); | 65 for (DictionaryValue::Iterator it(*child_dict); it.HasNext(); |
| 66 it.Advance()) { | 66 it.Advance()) { |
| 67 const DictionaryValue* item = NULL; | 67 const DictionaryValue* item = NULL; |
| 68 CHECK(it.value().GetAsDictionary(&item)); | 68 CHECK(it.value().GetAsDictionary(&item)); |
| 69 if (IsUnprivileged(item)) | 69 if (IsUnprivileged(item)) |
| (...skipping 24 matching lines...) Expand all Loading... |
| 94 base::snprintf(buf, arraysize(buf), "%s: (%d) '%s'", | 94 base::snprintf(buf, arraysize(buf), "%s: (%d) '%s'", |
| 95 name.c_str(), | 95 name.c_str(), |
| 96 result.get() ? result->GetType() : -1, | 96 result.get() ? result->GetType() : -1, |
| 97 error_message.c_str()); | 97 error_message.c_str()); |
| 98 | 98 |
| 99 CHECK(result.get()) << error_message << " for schema " << schema; | 99 CHECK(result.get()) << error_message << " for schema " << schema; |
| 100 CHECK(result->IsType(Value::TYPE_LIST)) << " for schema " << schema; | 100 CHECK(result->IsType(Value::TYPE_LIST)) << " for schema " << schema; |
| 101 return scoped_ptr<ListValue>(static_cast<ListValue*>(result.release())); | 101 return scoped_ptr<ListValue>(static_cast<ListValue*>(result.release())); |
| 102 } | 102 } |
| 103 | 103 |
| 104 DictionaryValue* FindListItem(const ListValue* list, | 104 const DictionaryValue* FindListItem(const ListValue* list, |
| 105 const std::string& property_name, | 105 const std::string& property_name, |
| 106 const std::string& property_value) { | 106 const std::string& property_value) { |
| 107 for (size_t i = 0; i < list->GetSize(); ++i) { | 107 for (size_t i = 0; i < list->GetSize(); ++i) { |
| 108 DictionaryValue* item = NULL; | 108 const DictionaryValue* item = NULL; |
| 109 CHECK(list->GetDictionary(i, &item)) | 109 CHECK(list->GetDictionary(i, &item)) |
| 110 << property_value << "/" << property_name; | 110 << property_value << "/" << property_name; |
| 111 std::string value; | 111 std::string value; |
| 112 if (item->GetString(property_name, &value) && value == property_value) | 112 if (item->GetString(property_name, &value) && value == property_value) |
| 113 return item; | 113 return item; |
| 114 } | 114 } |
| 115 | 115 |
| 116 return NULL; | 116 return NULL; |
| 117 } | 117 } |
| 118 | 118 |
| 119 const DictionaryValue* GetSchemaChild(const DictionaryValue* schema_node, | 119 const DictionaryValue* GetSchemaChild(const DictionaryValue* schema_node, |
| 120 const std::string& child_name) { | 120 const std::string& child_name) { |
| 121 DictionaryValue* child_node = NULL; | 121 const DictionaryValue* child_node = NULL; |
| 122 for (size_t i = 0; i < arraysize(kChildKinds); ++i) { | 122 for (size_t i = 0; i < arraysize(kChildKinds); ++i) { |
| 123 const ListValue* list_node = NULL; | 123 const ListValue* list_node = NULL; |
| 124 if (!schema_node->GetList(kChildKinds[i], &list_node)) | 124 if (!schema_node->GetList(kChildKinds[i], &list_node)) |
| 125 continue; | 125 continue; |
| 126 child_node = FindListItem(list_node, "name", child_name); | 126 child_node = FindListItem(list_node, "name", child_name); |
| 127 if (child_node) | 127 if (child_node) |
| 128 return child_node; | 128 return child_node; |
| 129 } | 129 } |
| 130 | 130 |
| 131 return NULL; | 131 return NULL; |
| (...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 843 | 843 |
| 844 void ExtensionAPI::LoadAllSchemas() { | 844 void ExtensionAPI::LoadAllSchemas() { |
| 845 while (unloaded_schemas_.size()) { | 845 while (unloaded_schemas_.size()) { |
| 846 std::map<std::string, base::StringPiece>::iterator it = | 846 std::map<std::string, base::StringPiece>::iterator it = |
| 847 unloaded_schemas_.begin(); | 847 unloaded_schemas_.begin(); |
| 848 LoadSchema(it->first, it->second); | 848 LoadSchema(it->first, it->second); |
| 849 } | 849 } |
| 850 } | 850 } |
| 851 | 851 |
| 852 } // namespace extensions | 852 } // namespace extensions |
| OLD | NEW |