| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 const ListValue* child_list = NULL; | 53 const ListValue* child_list = NULL; |
| 54 const 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 const 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(); |
| 65 it.Advance()) { | 65 it.Advance()) { |
| 66 const DictionaryValue* item = NULL; | 66 const DictionaryValue* item = NULL; |
| 67 CHECK(it.value().GetAsDictionary(&item)); | 67 CHECK(it.value().GetAsDictionary(&item)); |
| 68 if (IsUnprivileged(item)) | 68 if (IsUnprivileged(item)) |
| (...skipping 24 matching lines...) Expand all Loading... |
| 93 base::snprintf(buf, arraysize(buf), "%s: (%d) '%s'", | 93 base::snprintf(buf, arraysize(buf), "%s: (%d) '%s'", |
| 94 name.c_str(), | 94 name.c_str(), |
| 95 result.get() ? result->GetType() : -1, | 95 result.get() ? result->GetType() : -1, |
| 96 error_message.c_str()); | 96 error_message.c_str()); |
| 97 | 97 |
| 98 CHECK(result.get()) << error_message << " for schema " << schema; | 98 CHECK(result.get()) << error_message << " for schema " << schema; |
| 99 CHECK(result->IsType(Value::TYPE_LIST)) << " for schema " << schema; | 99 CHECK(result->IsType(Value::TYPE_LIST)) << " for schema " << schema; |
| 100 return scoped_ptr<ListValue>(static_cast<ListValue*>(result.release())); | 100 return scoped_ptr<ListValue>(static_cast<ListValue*>(result.release())); |
| 101 } | 101 } |
| 102 | 102 |
| 103 DictionaryValue* FindListItem(const ListValue* list, | 103 const DictionaryValue* FindListItem(const ListValue* list, |
| 104 const std::string& property_name, | 104 const std::string& property_name, |
| 105 const std::string& property_value) { | 105 const std::string& property_value) { |
| 106 for (size_t i = 0; i < list->GetSize(); ++i) { | 106 for (size_t i = 0; i < list->GetSize(); ++i) { |
| 107 DictionaryValue* item = NULL; | 107 const DictionaryValue* item = NULL; |
| 108 CHECK(list->GetDictionary(i, &item)) | 108 CHECK(list->GetDictionary(i, &item)) |
| 109 << property_value << "/" << property_name; | 109 << property_value << "/" << property_name; |
| 110 std::string value; | 110 std::string value; |
| 111 if (item->GetString(property_name, &value) && value == property_value) | 111 if (item->GetString(property_name, &value) && value == property_value) |
| 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 const 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 const 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; |
| (...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 842 | 842 |
| 843 void ExtensionAPI::LoadAllSchemas() { | 843 void ExtensionAPI::LoadAllSchemas() { |
| 844 while (unloaded_schemas_.size()) { | 844 while (unloaded_schemas_.size()) { |
| 845 std::map<std::string, base::StringPiece>::iterator it = | 845 std::map<std::string, base::StringPiece>::iterator it = |
| 846 unloaded_schemas_.begin(); | 846 unloaded_schemas_.begin(); |
| 847 LoadSchema(it->first, it->second); | 847 LoadSchema(it->first, it->second); |
| 848 } | 848 } |
| 849 } | 849 } |
| 850 | 850 |
| 851 } // namespace extensions | 851 } // namespace extensions |
| OLD | NEW |