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 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
578 if (!IsFeatureAllowedForExtension(*i, extension)) { | 578 if (!IsFeatureAllowedForExtension(*i, extension)) { |
579 apis->erase(i++); | 579 apis->erase(i++); |
580 } else { | 580 } else { |
581 ++i; | 581 ++i; |
582 } | 582 } |
583 } | 583 } |
584 } | 584 } |
585 | 585 |
586 } // namespace | 586 } // namespace |
587 | 587 |
588 scoped_ptr<std::set<std::string> > ExtensionAPI::GetAPIsForContext( | 588 std::set<std::string> ExtensionAPI::GetAPIsForContext( |
589 Feature::Context context, const Extension* extension, const GURL& url) { | 589 Feature::Context context, const Extension* extension, const GURL& url) { |
590 // We're forced to load all schemas now because we need to know the metadata | 590 // We're forced to load all schemas now because we need to know the metadata |
591 // about every API -- and the metadata is stored in the schemas themselves. | 591 // about every API -- and the metadata is stored in the schemas themselves. |
592 // This is a shame. | 592 // This is a shame. |
593 // TODO(aa/kalman): store metadata in a separate file and don't load all | 593 // TODO(aa/kalman): store metadata in a separate file and don't load all |
594 // schemas. | 594 // schemas. |
595 LoadAllSchemas(); | 595 LoadAllSchemas(); |
596 | 596 |
597 std::set<std::string> temp_result; | 597 std::set<std::string> temp_result; |
598 | 598 |
(...skipping 24 matching lines...) Expand all Loading... | |
623 case Feature::UNBLESSED_EXTENSION_CONTEXT: | 623 case Feature::UNBLESSED_EXTENSION_CONTEXT: |
624 case Feature::CONTENT_SCRIPT_CONTEXT: | 624 case Feature::CONTENT_SCRIPT_CONTEXT: |
625 if (extension) { | 625 if (extension) { |
626 // Same as BLESSED_EXTENSION_CONTEXT, but only those APIs that are | 626 // Same as BLESSED_EXTENSION_CONTEXT, but only those APIs that are |
627 // unprivileged. | 627 // unprivileged. |
628 GetAllowedAPIs(extension, &temp_result); | 628 GetAllowedAPIs(extension, &temp_result); |
629 // Resolving dependencies before removing unprivileged APIs means that | 629 // Resolving dependencies before removing unprivileged APIs means that |
630 // some unprivileged APIs may have unrealised dependencies. Too bad! | 630 // some unprivileged APIs may have unrealised dependencies. Too bad! |
631 ResolveDependencies(&temp_result); | 631 ResolveDependencies(&temp_result); |
632 RemovePrivilegedAPIs(&temp_result); | 632 RemovePrivilegedAPIs(&temp_result); |
633 // TODO(cduvall): In DevTools.js:71777, there is a check if chrome has | |
634 // a getter for devtools. This is true, and then | |
635 // chrome.devtools.inspectedWindow is used. If devtools is not | |
636 // available, it is true that chrome has a getter for devtools, but the | |
637 // getter will return undefined in content scripts. This makes sure | |
638 // chrome.devtools is available everywhere. | |
not at google - send to devlin
2013/02/13 01:45:49
... but even for extensions that don't have the de
cduvall
2013/02/15 00:40:28
Took this out, because it works with a change in W
| |
639 temp_result.insert("devtools"); | |
633 } | 640 } |
634 break; | 641 break; |
635 | 642 |
636 case Feature::WEB_PAGE_CONTEXT: | 643 case Feature::WEB_PAGE_CONTEXT: |
637 if (url.is_valid()) { | 644 if (url.is_valid()) { |
638 // Availablility is determined by the url. | 645 // Availablility is determined by the url. |
639 GetAPIsMatchingURL(url, &temp_result); | 646 GetAPIsMatchingURL(url, &temp_result); |
640 } | 647 } |
641 break; | 648 break; |
642 } | 649 } |
643 | 650 |
644 // Filter out all non-API features and remove the feature type part of the | 651 // Filter out all non-API features and remove the feature type part of the |
645 // name. | 652 // name. |
646 scoped_ptr<std::set<std::string> > result(new std::set<std::string>()); | 653 std::set<std::string> result; |
647 for (std::set<std::string>::iterator iter = temp_result.begin(); | 654 for (std::set<std::string>::iterator iter = temp_result.begin(); |
648 iter != temp_result.end(); ++iter) { | 655 iter != temp_result.end(); ++iter) { |
649 std::string feature_type; | 656 std::string feature_type; |
650 std::string feature_name; | 657 std::string feature_name; |
651 SplitDependencyName(*iter, &feature_type, &feature_name); | 658 SplitDependencyName(*iter, &feature_type, &feature_name); |
652 if (feature_type == "api") | 659 if (feature_type == "api") |
653 result->insert(feature_name); | 660 result.insert(feature_name); |
654 } | 661 } |
655 | 662 |
656 return result.Pass(); | 663 return result; |
664 } | |
665 | |
666 std::set<std::string> ExtensionAPI::GetAllAPINames() { | |
667 std::set<std::string> result; | |
668 for (SchemaMap::iterator i = schemas_.begin(); i != schemas_.end(); ++i) | |
669 result.insert(i->first); | |
670 for (UnloadedSchemaMap::iterator i = unloaded_schemas_.begin(); | |
671 i != unloaded_schemas_.end(); ++i) { | |
672 result.insert(i->first); | |
673 } | |
674 return result; | |
657 } | 675 } |
658 | 676 |
659 Feature* ExtensionAPI::GetFeature(const std::string& full_name) { | 677 Feature* ExtensionAPI::GetFeature(const std::string& full_name) { |
660 // Ensure it's loaded. | 678 // Ensure it's loaded. |
661 GetSchema(full_name); | 679 GetSchema(full_name); |
662 | 680 |
663 std::string child_name; | 681 std::string child_name; |
664 std::string api_namespace = GetAPINameFromFullName(full_name, &child_name); | 682 std::string api_namespace = GetAPINameFromFullName(full_name, &child_name); |
665 | 683 |
666 APIFeatureMap::iterator feature_map = features_.find(api_namespace); | 684 APIFeatureMap::iterator feature_map = features_.find(api_namespace); |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
819 | 837 |
820 void ExtensionAPI::LoadAllSchemas() { | 838 void ExtensionAPI::LoadAllSchemas() { |
821 while (unloaded_schemas_.size()) { | 839 while (unloaded_schemas_.size()) { |
822 std::map<std::string, base::StringPiece>::iterator it = | 840 std::map<std::string, base::StringPiece>::iterator it = |
823 unloaded_schemas_.begin(); | 841 unloaded_schemas_.begin(); |
824 LoadSchema(it->first, it->second); | 842 LoadSchema(it->first, it->second); |
825 } | 843 } |
826 } | 844 } |
827 | 845 |
828 } // namespace extensions | 846 } // namespace extensions |
OLD | NEW |