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