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 604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
615 if (!IsFeatureAllowedForExtension(*i, extension)) { | 615 if (!IsFeatureAllowedForExtension(*i, extension)) { |
616 apis->erase(i++); | 616 apis->erase(i++); |
617 } else { | 617 } else { |
618 ++i; | 618 ++i; |
619 } | 619 } |
620 } | 620 } |
621 } | 621 } |
622 | 622 |
623 } // namespace | 623 } // namespace |
624 | 624 |
625 scoped_ptr<std::set<std::string> > ExtensionAPI::GetAPIsForContext( | 625 std::set<std::string> ExtensionAPI::GetAPIsForContext( |
626 Feature::Context context, const Extension* extension, const GURL& url) { | 626 Feature::Context context, const Extension* extension, const GURL& url) { |
627 // We're forced to load all schemas now because we need to know the metadata | 627 // We're forced to load all schemas now because we need to know the metadata |
628 // about every API -- and the metadata is stored in the schemas themselves. | 628 // about every API -- and the metadata is stored in the schemas themselves. |
629 // This is a shame. | 629 // This is a shame. |
630 // TODO(aa/kalman): store metadata in a separate file and don't load all | 630 // TODO(aa/kalman): store metadata in a separate file and don't load all |
631 // schemas. | 631 // schemas. |
632 LoadAllSchemas(); | 632 LoadAllSchemas(); |
633 | 633 |
634 std::set<std::string> temp_result; | 634 std::set<std::string> temp_result; |
635 | 635 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 case Feature::WEB_PAGE_CONTEXT: | 673 case Feature::WEB_PAGE_CONTEXT: |
674 if (url.is_valid()) { | 674 if (url.is_valid()) { |
675 // Availablility is determined by the url. | 675 // Availablility is determined by the url. |
676 GetAPIsMatchingURL(url, &temp_result); | 676 GetAPIsMatchingURL(url, &temp_result); |
677 } | 677 } |
678 break; | 678 break; |
679 } | 679 } |
680 | 680 |
681 // Filter out all non-API features and remove the feature type part of the | 681 // Filter out all non-API features and remove the feature type part of the |
682 // name. | 682 // name. |
683 scoped_ptr<std::set<std::string> > result(new std::set<std::string>()); | 683 std::set<std::string> result; |
684 for (std::set<std::string>::iterator iter = temp_result.begin(); | 684 for (std::set<std::string>::iterator iter = temp_result.begin(); |
685 iter != temp_result.end(); ++iter) { | 685 iter != temp_result.end(); ++iter) { |
686 std::string feature_type; | 686 std::string feature_type; |
687 std::string feature_name; | 687 std::string feature_name; |
688 SplitDependencyName(*iter, &feature_type, &feature_name); | 688 SplitDependencyName(*iter, &feature_type, &feature_name); |
689 if (feature_type == "api") | 689 if (feature_type == "api") |
690 result->insert(feature_name); | 690 result.insert(feature_name); |
691 } | 691 } |
692 | 692 |
693 return result.Pass(); | 693 return result; |
| 694 } |
| 695 |
| 696 std::set<std::string> ExtensionAPI::GetAllAPINames() { |
| 697 // Don't do this. Instead reference the unloaded schemas and load as needed. |
| 698 LoadAllSchemas(); |
| 699 std::set<std::string> result; |
| 700 for (SchemaMap::iterator i = schemas_.begin(); i != schemas_.end(); ++i) |
| 701 result.insert(i->first); |
| 702 return result; |
694 } | 703 } |
695 | 704 |
696 Feature* ExtensionAPI::GetFeature(const std::string& full_name) { | 705 Feature* ExtensionAPI::GetFeature(const std::string& full_name) { |
697 // Ensure it's loaded. | 706 // Ensure it's loaded. |
698 GetSchema(full_name); | 707 GetSchema(full_name); |
699 | 708 |
700 std::string child_name; | 709 std::string child_name; |
701 std::string api_namespace = GetAPINameFromFullName(full_name, &child_name); | 710 std::string api_namespace = GetAPINameFromFullName(full_name, &child_name); |
702 | 711 |
703 APIFeatureMap::iterator feature_map = features_.find(api_namespace); | 712 APIFeatureMap::iterator feature_map = features_.find(api_namespace); |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
856 | 865 |
857 void ExtensionAPI::LoadAllSchemas() { | 866 void ExtensionAPI::LoadAllSchemas() { |
858 while (unloaded_schemas_.size()) { | 867 while (unloaded_schemas_.size()) { |
859 std::map<std::string, base::StringPiece>::iterator it = | 868 std::map<std::string, base::StringPiece>::iterator it = |
860 unloaded_schemas_.begin(); | 869 unloaded_schemas_.begin(); |
861 LoadSchema(it->first, it->second); | 870 LoadSchema(it->first, it->second); |
862 } | 871 } |
863 } | 872 } |
864 | 873 |
865 } // namespace extensions | 874 } // namespace extensions |
OLD | NEW |