| 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 |
| 11 #include "base/json/json_reader.h" | 11 #include "base/json/json_reader.h" |
| 12 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
| 13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/string_number_conversions.h" | 15 #include "base/string_number_conversions.h" |
| 16 #include "base/string_split.h" | 16 #include "base/string_split.h" |
| 17 #include "base/string_util.h" | 17 #include "base/string_util.h" |
| 18 #include "base/values.h" | 18 #include "base/values.h" |
| 19 #include "chrome/common/extensions/api/generated_schemas.h" | 19 #include "chrome/common/extensions/api/generated_schemas.h" |
| 20 #include "chrome/common/extensions/extension.h" | 20 #include "chrome/common/extensions/extension.h" |
| 21 #include "chrome/common/extensions/features/simple_feature.h" |
| 21 #include "chrome/common/extensions/features/simple_feature_provider.h" | 22 #include "chrome/common/extensions/features/simple_feature_provider.h" |
| 22 #include "chrome/common/extensions/permissions/permission_set.h" | 23 #include "chrome/common/extensions/permissions/permission_set.h" |
| 23 #include "googleurl/src/gurl.h" | 24 #include "googleurl/src/gurl.h" |
| 24 #include "grit/common_resources.h" | 25 #include "grit/common_resources.h" |
| 25 #include "grit/extensions_api_resources.h" | 26 #include "grit/extensions_api_resources.h" |
| 26 #include "ui/base/resource/resource_bundle.h" | 27 #include "ui/base/resource/resource_bundle.h" |
| 27 | 28 |
| 28 using base::DictionaryValue; | 29 using base::DictionaryValue; |
| 29 using base::ListValue; | 30 using base::ListValue; |
| 30 using base::Value; | 31 using base::Value; |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 } | 280 } |
| 280 | 281 |
| 281 // Populate feature maps. | 282 // Populate feature maps. |
| 282 // TODO(aa): Consider not storing features that can never run on the current | 283 // TODO(aa): Consider not storing features that can never run on the current |
| 283 // machine (e.g., because of platform restrictions). | 284 // machine (e.g., because of platform restrictions). |
| 284 bool uses_feature_system = false; | 285 bool uses_feature_system = false; |
| 285 schema->GetBoolean("uses_feature_system", &uses_feature_system); | 286 schema->GetBoolean("uses_feature_system", &uses_feature_system); |
| 286 if (!uses_feature_system) | 287 if (!uses_feature_system) |
| 287 continue; | 288 continue; |
| 288 | 289 |
| 289 Feature* feature = new Feature(); | 290 SimpleFeature* feature = new SimpleFeature(); |
| 290 feature->set_name(schema_namespace); | 291 feature->set_name(schema_namespace); |
| 291 feature->Parse(schema); | 292 feature->Parse(schema); |
| 292 | 293 |
| 293 FeatureMap* schema_features = new FeatureMap(); | 294 FeatureMap* schema_features = new FeatureMap(); |
| 294 CHECK(features_.insert( | 295 CHECK(features_.insert( |
| 295 std::make_pair(schema_namespace, | 296 std::make_pair(schema_namespace, |
| 296 make_linked_ptr(schema_features))).second); | 297 make_linked_ptr(schema_features))).second); |
| 297 CHECK(schema_features->insert( | 298 CHECK(schema_features->insert( |
| 298 std::make_pair("", make_linked_ptr(feature))).second); | 299 std::make_pair("", make_linked_ptr(feature))).second); |
| 299 | 300 |
| 300 for (size_t i = 0; i < arraysize(kChildKinds); ++i) { | 301 for (size_t i = 0; i < arraysize(kChildKinds); ++i) { |
| 301 ListValue* child_list = NULL; | 302 ListValue* child_list = NULL; |
| 302 schema->GetList(kChildKinds[i], &child_list); | 303 schema->GetList(kChildKinds[i], &child_list); |
| 303 if (!child_list) | 304 if (!child_list) |
| 304 continue; | 305 continue; |
| 305 | 306 |
| 306 for (size_t j = 0; j < child_list->GetSize(); ++j) { | 307 for (size_t j = 0; j < child_list->GetSize(); ++j) { |
| 307 DictionaryValue* child = NULL; | 308 DictionaryValue* child = NULL; |
| 308 CHECK(child_list->GetDictionary(j, &child)); | 309 CHECK(child_list->GetDictionary(j, &child)); |
| 309 | 310 |
| 310 scoped_ptr<Feature> child_feature(new Feature(*feature)); | 311 scoped_ptr<SimpleFeature> child_feature(new SimpleFeature(*feature)); |
| 311 child_feature->Parse(child); | 312 child_feature->Parse(child); |
| 312 if (child_feature->Equals(*feature)) | 313 if (child_feature->Equals(*feature)) |
| 313 continue; // no need to store no-op features | 314 continue; // no need to store no-op features |
| 314 | 315 |
| 315 std::string child_name; | 316 std::string child_name; |
| 316 CHECK(child->GetString("name", &child_name)); | 317 CHECK(child->GetString("name", &child_name)); |
| 317 child_feature->set_name(schema_namespace + "." + child_name); | 318 child_feature->set_name(schema_namespace + "." + child_name); |
| 318 CHECK(schema_features->insert( | 319 CHECK(schema_features->insert( |
| 319 std::make_pair(child_name, | 320 std::make_pair(child_name, |
| 320 make_linked_ptr(child_feature.release()))).second); | 321 make_linked_ptr(child_feature.release()))).second); |
| (...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 856 | 857 |
| 857 void ExtensionAPI::LoadAllSchemas() { | 858 void ExtensionAPI::LoadAllSchemas() { |
| 858 while (unloaded_schemas_.size()) { | 859 while (unloaded_schemas_.size()) { |
| 859 std::map<std::string, base::StringPiece>::iterator it = | 860 std::map<std::string, base::StringPiece>::iterator it = |
| 860 unloaded_schemas_.begin(); | 861 unloaded_schemas_.begin(); |
| 861 LoadSchema(it->first, it->second); | 862 LoadSchema(it->first, it->second); |
| 862 } | 863 } |
| 863 } | 864 } |
| 864 | 865 |
| 865 } // namespace extensions | 866 } // namespace extensions |
| OLD | NEW |