Chromium Code Reviews| 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 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 348 IDR_EXTENSION_API_JSON_BROWSERACTION)); | 348 IDR_EXTENSION_API_JSON_BROWSERACTION)); |
| 349 RegisterSchema("browsingData", ReadFromResource( | 349 RegisterSchema("browsingData", ReadFromResource( |
| 350 IDR_EXTENSION_API_JSON_BROWSINGDATA)); | 350 IDR_EXTENSION_API_JSON_BROWSINGDATA)); |
| 351 RegisterSchema("commands", ReadFromResource( | 351 RegisterSchema("commands", ReadFromResource( |
| 352 IDR_EXTENSION_API_JSON_COMMANDS)); | 352 IDR_EXTENSION_API_JSON_COMMANDS)); |
| 353 RegisterSchema("declarativeContent", ReadFromResource( | 353 RegisterSchema("declarativeContent", ReadFromResource( |
| 354 IDR_EXTENSION_API_JSON_DECLARATIVE_CONTENT)); | 354 IDR_EXTENSION_API_JSON_DECLARATIVE_CONTENT)); |
| 355 RegisterSchema("declarativeWebRequest", ReadFromResource( | 355 RegisterSchema("declarativeWebRequest", ReadFromResource( |
| 356 IDR_EXTENSION_API_JSON_DECLARATIVE_WEBREQUEST)); | 356 IDR_EXTENSION_API_JSON_DECLARATIVE_WEBREQUEST)); |
| 357 RegisterSchema("devtools", ReadFromResource( | 357 RegisterSchema("devtools", ReadFromResource( |
| 358 IDR_EXTENSION_API_JSON_DEVTOOLS)); | 358 IDR_EXTENSION_API_JSON_DEVTOOLS)); |
|
not at google - send to devlin
2013/02/15 22:26:17
Good news! https://codereview.chromium.org/1228100
cduvall
2013/02/19 23:58:49
Yay!
| |
| 359 RegisterSchema("experimental.input.virtualKeyboard", ReadFromResource( | 359 RegisterSchema("experimental.input.virtualKeyboard", ReadFromResource( |
| 360 IDR_EXTENSION_API_JSON_EXPERIMENTAL_INPUT_VIRTUALKEYBOARD)); | 360 IDR_EXTENSION_API_JSON_EXPERIMENTAL_INPUT_VIRTUALKEYBOARD)); |
| 361 RegisterSchema("experimental.processes", ReadFromResource( | 361 RegisterSchema("experimental.processes", ReadFromResource( |
| 362 IDR_EXTENSION_API_JSON_EXPERIMENTAL_PROCESSES)); | 362 IDR_EXTENSION_API_JSON_EXPERIMENTAL_PROCESSES)); |
| 363 RegisterSchema("experimental.rlz", ReadFromResource( | 363 RegisterSchema("experimental.rlz", ReadFromResource( |
| 364 IDR_EXTENSION_API_JSON_EXPERIMENTAL_RLZ)); | 364 IDR_EXTENSION_API_JSON_EXPERIMENTAL_RLZ)); |
| 365 RegisterSchema("runtime", ReadFromResource( | 365 RegisterSchema("runtime", ReadFromResource( |
| 366 IDR_EXTENSION_API_JSON_RUNTIME)); | 366 IDR_EXTENSION_API_JSON_RUNTIME)); |
| 367 RegisterSchema("experimental.speechInput", ReadFromResource( | 367 RegisterSchema("experimental.speechInput", ReadFromResource( |
| 368 IDR_EXTENSION_API_JSON_EXPERIMENTAL_SPEECHINPUT)); | 368 IDR_EXTENSION_API_JSON_EXPERIMENTAL_SPEECHINPUT)); |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 538 if (!IsFeatureAllowedForExtension(*i, extension)) { | 538 if (!IsFeatureAllowedForExtension(*i, extension)) { |
| 539 apis->erase(i++); | 539 apis->erase(i++); |
| 540 } else { | 540 } else { |
| 541 ++i; | 541 ++i; |
| 542 } | 542 } |
| 543 } | 543 } |
| 544 } | 544 } |
| 545 | 545 |
| 546 } // namespace | 546 } // namespace |
| 547 | 547 |
| 548 scoped_ptr<std::set<std::string> > ExtensionAPI::GetAPIsForContext( | 548 std::set<std::string> ExtensionAPI::GetAPIsForContext( |
| 549 Feature::Context context, const Extension* extension, const GURL& url) { | 549 Feature::Context context, const Extension* extension, const GURL& url) { |
| 550 // We're forced to load all schemas now because we need to know the metadata | 550 // We're forced to load all schemas now because we need to know the metadata |
| 551 // about every API -- and the metadata is stored in the schemas themselves. | 551 // about every API -- and the metadata is stored in the schemas themselves. |
| 552 // This is a shame. | 552 // This is a shame. |
| 553 // TODO(aa/kalman): store metadata in a separate file and don't load all | 553 // TODO(aa/kalman): store metadata in a separate file and don't load all |
| 554 // schemas. | 554 // schemas. |
| 555 LoadAllSchemas(); | 555 LoadAllSchemas(); |
| 556 | 556 |
| 557 std::set<std::string> temp_result; | 557 std::set<std::string> temp_result; |
| 558 | 558 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 596 case Feature::WEB_PAGE_CONTEXT: | 596 case Feature::WEB_PAGE_CONTEXT: |
| 597 if (url.is_valid()) { | 597 if (url.is_valid()) { |
| 598 // Availablility is determined by the url. | 598 // Availablility is determined by the url. |
| 599 GetAPIsMatchingURL(url, &temp_result); | 599 GetAPIsMatchingURL(url, &temp_result); |
| 600 } | 600 } |
| 601 break; | 601 break; |
| 602 } | 602 } |
| 603 | 603 |
| 604 // Filter out all non-API features and remove the feature type part of the | 604 // Filter out all non-API features and remove the feature type part of the |
| 605 // name. | 605 // name. |
| 606 scoped_ptr<std::set<std::string> > result(new std::set<std::string>()); | 606 std::set<std::string> result; |
| 607 for (std::set<std::string>::iterator iter = temp_result.begin(); | 607 for (std::set<std::string>::iterator iter = temp_result.begin(); |
| 608 iter != temp_result.end(); ++iter) { | 608 iter != temp_result.end(); ++iter) { |
| 609 std::string feature_type; | 609 std::string feature_type; |
| 610 std::string feature_name; | 610 std::string feature_name; |
| 611 SplitDependencyName(*iter, &feature_type, &feature_name); | 611 SplitDependencyName(*iter, &feature_type, &feature_name); |
| 612 if (feature_type == "api") | 612 if (feature_type == "api") |
| 613 result->insert(feature_name); | 613 result.insert(feature_name); |
| 614 } | 614 } |
| 615 | 615 |
| 616 return result.Pass(); | 616 return result; |
| 617 } | |
| 618 | |
| 619 std::set<std::string> ExtensionAPI::GetAllAPINames() { | |
| 620 std::set<std::string> result; | |
| 621 for (SchemaMap::iterator i = schemas_.begin(); i != schemas_.end(); ++i) | |
| 622 result.insert(i->first); | |
| 623 for (UnloadedSchemaMap::iterator i = unloaded_schemas_.begin(); | |
| 624 i != unloaded_schemas_.end(); ++i) { | |
| 625 result.insert(i->first); | |
| 626 } | |
| 627 return result; | |
| 617 } | 628 } |
| 618 | 629 |
| 619 Feature* ExtensionAPI::GetFeature(const std::string& full_name) { | 630 Feature* ExtensionAPI::GetFeature(const std::string& full_name) { |
| 620 // Ensure it's loaded. | 631 // Ensure it's loaded. |
| 621 GetSchema(full_name); | 632 GetSchema(full_name); |
| 622 | 633 |
| 623 std::string child_name; | 634 std::string child_name; |
| 624 std::string api_namespace = GetAPINameFromFullName(full_name, &child_name); | 635 std::string api_namespace = GetAPINameFromFullName(full_name, &child_name); |
| 625 | 636 |
| 626 APIFeatureMap::iterator feature_map = features_.find(api_namespace); | 637 APIFeatureMap::iterator feature_map = features_.find(api_namespace); |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 779 | 790 |
| 780 void ExtensionAPI::LoadAllSchemas() { | 791 void ExtensionAPI::LoadAllSchemas() { |
| 781 while (unloaded_schemas_.size()) { | 792 while (unloaded_schemas_.size()) { |
| 782 std::map<std::string, base::StringPiece>::iterator it = | 793 std::map<std::string, base::StringPiece>::iterator it = |
| 783 unloaded_schemas_.begin(); | 794 unloaded_schemas_.begin(); |
| 784 LoadSchema(it->first, it->second); | 795 LoadSchema(it->first, it->second); |
| 785 } | 796 } |
| 786 } | 797 } |
| 787 | 798 |
| 788 } // namespace extensions | 799 } // namespace extensions |
| OLD | NEW |