Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: chrome/common/extensions/api/extension_api.cc

Issue 11316164: Implement ComplexFeature to support permission features with multiple rules. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: new Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 } 279 }
280 280
281 // Populate feature maps. 281 // Populate feature maps.
282 // TODO(aa): Consider not storing features that can never run on the current 282 // TODO(aa): Consider not storing features that can never run on the current
283 // machine (e.g., because of platform restrictions). 283 // machine (e.g., because of platform restrictions).
284 bool uses_feature_system = false; 284 bool uses_feature_system = false;
285 schema->GetBoolean("uses_feature_system", &uses_feature_system); 285 schema->GetBoolean("uses_feature_system", &uses_feature_system);
286 if (!uses_feature_system) 286 if (!uses_feature_system)
287 continue; 287 continue;
288 288
289 Feature* feature = new Feature(); 289 SimpleFeature* feature = new SimpleFeature();
not at google - send to devlin 2012/12/12 17:42:41 s/SimpleFeature/Feature/ in the LHS of expressions
justinlin 2012/12/14 12:26:26 Done, except for this instance in the file. In thi
290 feature->set_name(schema_namespace); 290 feature->set_name(schema_namespace);
291 feature->Parse(schema); 291 feature->Parse(schema);
292 292
293 FeatureMap* schema_features = new FeatureMap(); 293 FeatureMap* schema_features = new FeatureMap();
294 CHECK(features_.insert( 294 CHECK(features_.insert(
295 std::make_pair(schema_namespace, 295 std::make_pair(schema_namespace,
296 make_linked_ptr(schema_features))).second); 296 make_linked_ptr(schema_features))).second);
297 CHECK(schema_features->insert( 297 CHECK(schema_features->insert(
298 std::make_pair("", make_linked_ptr(feature))).second); 298 std::make_pair("", make_linked_ptr(feature))).second);
299 299
300 for (size_t i = 0; i < arraysize(kChildKinds); ++i) { 300 for (size_t i = 0; i < arraysize(kChildKinds); ++i) {
301 ListValue* child_list = NULL; 301 ListValue* child_list = NULL;
302 schema->GetList(kChildKinds[i], &child_list); 302 schema->GetList(kChildKinds[i], &child_list);
303 if (!child_list) 303 if (!child_list)
304 continue; 304 continue;
305 305
306 for (size_t j = 0; j < child_list->GetSize(); ++j) { 306 for (size_t j = 0; j < child_list->GetSize(); ++j) {
307 DictionaryValue* child = NULL; 307 DictionaryValue* child = NULL;
308 CHECK(child_list->GetDictionary(j, &child)); 308 CHECK(child_list->GetDictionary(j, &child));
309 309
310 scoped_ptr<Feature> child_feature(new Feature(*feature)); 310 scoped_ptr<SimpleFeature> child_feature(new SimpleFeature(*feature));
311 child_feature->Parse(child); 311 child_feature->Parse(child);
312 if (child_feature->Equals(*feature)) 312 if (child_feature->Equals(*feature))
313 continue; // no need to store no-op features 313 continue; // no need to store no-op features
314 314
315 std::string child_name; 315 std::string child_name;
316 CHECK(child->GetString("name", &child_name)); 316 CHECK(child->GetString("name", &child_name));
317 child_feature->set_name(schema_namespace + "." + child_name); 317 child_feature->set_name(schema_namespace + "." + child_name);
318 CHECK(schema_features->insert( 318 CHECK(schema_features->insert(
319 std::make_pair(child_name, 319 std::make_pair(child_name,
320 make_linked_ptr(child_feature.release()))).second); 320 make_linked_ptr(child_feature.release()))).second);
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 // First try to use the feature system. 518 // First try to use the feature system.
519 Feature* feature(GetFeature(full_name)); 519 Feature* feature(GetFeature(full_name));
520 if (feature) { 520 if (feature) {
521 // An API is 'privileged' if it or any of its dependencies can only be run 521 // An API is 'privileged' if it or any of its dependencies can only be run
522 // in a blessed context. 522 // in a blessed context.
523 std::set<std::string> resolved_dependencies; 523 std::set<std::string> resolved_dependencies;
524 resolved_dependencies.insert(full_name); 524 resolved_dependencies.insert(full_name);
525 ResolveDependencies(&resolved_dependencies); 525 ResolveDependencies(&resolved_dependencies);
526 for (std::set<std::string>::iterator iter = resolved_dependencies.begin(); 526 for (std::set<std::string>::iterator iter = resolved_dependencies.begin();
527 iter != resolved_dependencies.end(); ++iter) { 527 iter != resolved_dependencies.end(); ++iter) {
528 Feature* dependency = GetFeatureDependency(*iter); 528 SimpleFeature* dependency =
529 static_cast<SimpleFeature*>(GetFeatureDependency(*iter));
529 for (std::set<Feature::Context>::iterator context = 530 for (std::set<Feature::Context>::iterator context =
530 dependency->contexts()->begin(); 531 dependency->contexts()->begin();
531 context != dependency->contexts()->end(); ++context) { 532 context != dependency->contexts()->end(); ++context) {
532 if (*context != Feature::BLESSED_EXTENSION_CONTEXT) 533 if (*context != Feature::BLESSED_EXTENSION_CONTEXT)
533 return false; 534 return false;
534 } 535 }
535 } 536 }
536 return true; 537 return true;
537 } 538 }
538 539
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 std::string feature_type; 689 std::string feature_type;
689 std::string feature_name; 690 std::string feature_name;
690 SplitDependencyName(*iter, &feature_type, &feature_name); 691 SplitDependencyName(*iter, &feature_type, &feature_name);
691 if (feature_type == "api") 692 if (feature_type == "api")
692 result->insert(feature_name); 693 result->insert(feature_name);
693 } 694 }
694 695
695 return result.Pass(); 696 return result.Pass();
696 } 697 }
697 698
698 Feature* ExtensionAPI::GetFeature(const std::string& full_name) { 699 SimpleFeature* ExtensionAPI::GetFeature(const std::string& full_name) {
699 // Ensure it's loaded. 700 // Ensure it's loaded.
700 GetSchema(full_name); 701 GetSchema(full_name);
701 702
702 std::string child_name; 703 std::string child_name;
703 std::string api_namespace = GetAPINameFromFullName(full_name, &child_name); 704 std::string api_namespace = GetAPINameFromFullName(full_name, &child_name);
704 705
705 APIFeatureMap::iterator feature_map = features_.find(api_namespace); 706 APIFeatureMap::iterator feature_map = features_.find(api_namespace);
706 if (feature_map == features_.end()) 707 if (feature_map == features_.end())
707 return NULL; 708 return NULL;
708 709
709 Feature* result = NULL; 710 SimpleFeature* result = NULL;
710 FeatureMap::iterator child_feature = feature_map->second->find(child_name); 711 FeatureMap::iterator child_feature = feature_map->second->find(child_name);
711 if (child_feature != feature_map->second->end()) { 712 if (child_feature != feature_map->second->end()) {
712 result = child_feature->second.get(); 713 result = child_feature->second.get();
713 } else { 714 } else {
714 FeatureMap::iterator parent_feature = feature_map->second->find(""); 715 FeatureMap::iterator parent_feature = feature_map->second->find("");
715 CHECK(parent_feature != feature_map->second->end()); 716 CHECK(parent_feature != feature_map->second->end());
716 result = parent_feature->second.get(); 717 result = parent_feature->second.get();
717 } 718 }
718 719
719 if (result->contexts()->empty()) { 720 if (result->contexts()->empty()) {
720 LOG(ERROR) << "API feature '" << full_name 721 LOG(ERROR) << "API feature '" << full_name
721 << "' must specify at least one context."; 722 << "' must specify at least one context.";
722 return NULL; 723 return NULL;
723 } 724 }
724 725
725 return result; 726 return result;
726 } 727 }
727 728
728 Feature* ExtensionAPI::GetFeatureDependency(const std::string& full_name) { 729 Feature* ExtensionAPI::GetFeatureDependency(
730 const std::string& full_name) {
729 std::string feature_type; 731 std::string feature_type;
730 std::string feature_name; 732 std::string feature_name;
731 SplitDependencyName(full_name, &feature_type, &feature_name); 733 SplitDependencyName(full_name, &feature_type, &feature_name);
732 734
733 FeatureProviderMap::iterator provider = 735 FeatureProviderMap::iterator provider =
734 dependency_providers_.find(feature_type); 736 dependency_providers_.find(feature_type);
735 CHECK(provider != dependency_providers_.end()) << full_name; 737 CHECK(provider != dependency_providers_.end()) << full_name;
736 738
737 Feature* feature = provider->second->GetFeature(feature_name); 739 Feature* feature = provider->second->GetFeature(feature_name);
738 CHECK(feature) << full_name; 740 CHECK(feature) << full_name;
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
858 860
859 void ExtensionAPI::LoadAllSchemas() { 861 void ExtensionAPI::LoadAllSchemas() {
860 while (unloaded_schemas_.size()) { 862 while (unloaded_schemas_.size()) {
861 std::map<std::string, base::StringPiece>::iterator it = 863 std::map<std::string, base::StringPiece>::iterator it =
862 unloaded_schemas_.begin(); 864 unloaded_schemas_.begin();
863 LoadSchema(it->first, it->second); 865 LoadSchema(it->first, it->second);
864 } 866 }
865 } 867 }
866 868
867 } // namespace extensions 869 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698