| 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 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 if (!IsFeatureAllowedForExtension(*i, extension)) { | 536 if (!IsFeatureAllowedForExtension(*i, extension)) { |
| 537 apis->erase(i++); | 537 apis->erase(i++); |
| 538 } else { | 538 } else { |
| 539 ++i; | 539 ++i; |
| 540 } | 540 } |
| 541 } | 541 } |
| 542 } | 542 } |
| 543 | 543 |
| 544 } // namespace | 544 } // namespace |
| 545 | 545 |
| 546 std::set<std::string> ExtensionAPI::GetAPIsForContext( | 546 scoped_ptr<std::set<std::string> > ExtensionAPI::GetAPIsForContext( |
| 547 Feature::Context context, const Extension* extension, const GURL& url) { | 547 Feature::Context context, const Extension* extension, const GURL& url) { |
| 548 // We're forced to load all schemas now because we need to know the metadata | 548 // We're forced to load all schemas now because we need to know the metadata |
| 549 // about every API -- and the metadata is stored in the schemas themselves. | 549 // about every API -- and the metadata is stored in the schemas themselves. |
| 550 // This is a shame. | 550 // This is a shame. |
| 551 // TODO(aa/kalman): store metadata in a separate file and don't load all | 551 // TODO(aa/kalman): store metadata in a separate file and don't load all |
| 552 // schemas. | 552 // schemas. |
| 553 LoadAllSchemas(); | 553 LoadAllSchemas(); |
| 554 | 554 |
| 555 std::set<std::string> temp_result; | 555 std::set<std::string> temp_result; |
| 556 | 556 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 case Feature::WEB_PAGE_CONTEXT: | 594 case Feature::WEB_PAGE_CONTEXT: |
| 595 if (url.is_valid()) { | 595 if (url.is_valid()) { |
| 596 // Availablility is determined by the url. | 596 // Availablility is determined by the url. |
| 597 GetAPIsMatchingURL(url, &temp_result); | 597 GetAPIsMatchingURL(url, &temp_result); |
| 598 } | 598 } |
| 599 break; | 599 break; |
| 600 } | 600 } |
| 601 | 601 |
| 602 // Filter out all non-API features and remove the feature type part of the | 602 // Filter out all non-API features and remove the feature type part of the |
| 603 // name. | 603 // name. |
| 604 std::set<std::string> result; | 604 scoped_ptr<std::set<std::string> > result(new std::set<std::string>()); |
| 605 for (std::set<std::string>::iterator iter = temp_result.begin(); | 605 for (std::set<std::string>::iterator iter = temp_result.begin(); |
| 606 iter != temp_result.end(); ++iter) { | 606 iter != temp_result.end(); ++iter) { |
| 607 std::string feature_type; | 607 std::string feature_type; |
| 608 std::string feature_name; | 608 std::string feature_name; |
| 609 SplitDependencyName(*iter, &feature_type, &feature_name); | 609 SplitDependencyName(*iter, &feature_type, &feature_name); |
| 610 if (feature_type == "api") | 610 if (feature_type == "api") |
| 611 result.insert(feature_name); | 611 result->insert(feature_name); |
| 612 } | 612 } |
| 613 | 613 |
| 614 return result; | 614 return result.Pass(); |
| 615 } | |
| 616 | |
| 617 std::set<std::string> ExtensionAPI::GetAllAPINames() { | |
| 618 std::set<std::string> result; | |
| 619 for (SchemaMap::iterator i = schemas_.begin(); i != schemas_.end(); ++i) | |
| 620 result.insert(i->first); | |
| 621 for (UnloadedSchemaMap::iterator i = unloaded_schemas_.begin(); | |
| 622 i != unloaded_schemas_.end(); ++i) { | |
| 623 result.insert(i->first); | |
| 624 } | |
| 625 return result; | |
| 626 } | 615 } |
| 627 | 616 |
| 628 Feature* ExtensionAPI::GetFeature(const std::string& full_name) { | 617 Feature* ExtensionAPI::GetFeature(const std::string& full_name) { |
| 629 // Ensure it's loaded. | 618 // Ensure it's loaded. |
| 630 GetSchema(full_name); | 619 GetSchema(full_name); |
| 631 | 620 |
| 632 std::string child_name; | 621 std::string child_name; |
| 633 std::string api_namespace = GetAPINameFromFullName(full_name, &child_name); | 622 std::string api_namespace = GetAPINameFromFullName(full_name, &child_name); |
| 634 | 623 |
| 635 APIFeatureMap::iterator feature_map = features_.find(api_namespace); | 624 APIFeatureMap::iterator feature_map = features_.find(api_namespace); |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 788 | 777 |
| 789 void ExtensionAPI::LoadAllSchemas() { | 778 void ExtensionAPI::LoadAllSchemas() { |
| 790 while (unloaded_schemas_.size()) { | 779 while (unloaded_schemas_.size()) { |
| 791 std::map<std::string, base::StringPiece>::iterator it = | 780 std::map<std::string, base::StringPiece>::iterator it = |
| 792 unloaded_schemas_.begin(); | 781 unloaded_schemas_.begin(); |
| 793 LoadSchema(it->first, it->second); | 782 LoadSchema(it->first, it->second); |
| 794 } | 783 } |
| 795 } | 784 } |
| 796 | 785 |
| 797 } // namespace extensions | 786 } // namespace extensions |
| OLD | NEW |