Index: chrome/common/extensions/api/extension_api.cc |
diff --git a/chrome/common/extensions/api/extension_api.cc b/chrome/common/extensions/api/extension_api.cc |
index 829ec472a7661490b33fdae0d71d1fb6b2e27281..ec098d23cdb0d455f687c1322fc54d16ec11c7c6 100644 |
--- a/chrome/common/extensions/api/extension_api.cc |
+++ b/chrome/common/extensions/api/extension_api.cc |
@@ -252,7 +252,9 @@ void ExtensionAPI::LoadSchema(const std::string& name, |
CHECK(schema->GetString("namespace", &schema_namespace)); |
PrefixWithNamespace(schema_namespace, schema); |
schemas_[schema_namespace] = make_linked_ptr(schema); |
- CHECK_EQ(1u, unloaded_schemas_.erase(schema_namespace)); |
+ if (!GeneratedSchemas::IsGenerated(schema_namespace)) { |
+ CHECK_EQ(1u, unloaded_schemas_.erase(schema_namespace)); |
+ } |
// Populate |{completely,partially}_unprivileged_apis_|. |
@@ -286,66 +288,48 @@ void ExtensionAPI::InitDefaultConfiguration() { |
// Schemas to be loaded from resources. |
CHECK(unloaded_schemas_.empty()); |
- RegisterSchema("app", ReadFromResource( |
- IDR_EXTENSION_API_JSON_APP)); |
- RegisterSchema("browserAction", ReadFromResource( |
- IDR_EXTENSION_API_JSON_BROWSERACTION)); |
- RegisterSchema("browsingData", ReadFromResource( |
- IDR_EXTENSION_API_JSON_BROWSINGDATA)); |
- RegisterSchema("commands", ReadFromResource( |
- IDR_EXTENSION_API_JSON_COMMANDS)); |
- RegisterSchema("declarativeContent", ReadFromResource( |
- IDR_EXTENSION_API_JSON_DECLARATIVE_CONTENT)); |
- RegisterSchema("declarativeWebRequest", ReadFromResource( |
- IDR_EXTENSION_API_JSON_DECLARATIVE_WEBREQUEST)); |
- RegisterSchema("experimental.input.virtualKeyboard", ReadFromResource( |
- IDR_EXTENSION_API_JSON_EXPERIMENTAL_INPUT_VIRTUALKEYBOARD)); |
- RegisterSchema("experimental.processes", ReadFromResource( |
- IDR_EXTENSION_API_JSON_EXPERIMENTAL_PROCESSES)); |
- RegisterSchema("experimental.rlz", ReadFromResource( |
- IDR_EXTENSION_API_JSON_EXPERIMENTAL_RLZ)); |
- RegisterSchema("runtime", ReadFromResource( |
- IDR_EXTENSION_API_JSON_RUNTIME)); |
- RegisterSchema("fileBrowserHandler", ReadFromResource( |
- IDR_EXTENSION_API_JSON_FILEBROWSERHANDLER)); |
- RegisterSchema("fileBrowserPrivate", ReadFromResource( |
- IDR_EXTENSION_API_JSON_FILEBROWSERPRIVATE)); |
- RegisterSchema("input.ime", ReadFromResource( |
- IDR_EXTENSION_API_JSON_INPUT_IME)); |
- RegisterSchema("inputMethodPrivate", ReadFromResource( |
- IDR_EXTENSION_API_JSON_INPUTMETHODPRIVATE)); |
- RegisterSchema("pageAction", ReadFromResource( |
- IDR_EXTENSION_API_JSON_PAGEACTION)); |
- RegisterSchema("pageActions", ReadFromResource( |
- IDR_EXTENSION_API_JSON_PAGEACTIONS)); |
- RegisterSchema("privacy", ReadFromResource( |
- IDR_EXTENSION_API_JSON_PRIVACY)); |
- RegisterSchema("proxy", ReadFromResource( |
- IDR_EXTENSION_API_JSON_PROXY)); |
- RegisterSchema("scriptBadge", ReadFromResource( |
- IDR_EXTENSION_API_JSON_SCRIPTBADGE)); |
- RegisterSchema("streamsPrivate", ReadFromResource( |
- IDR_EXTENSION_API_JSON_STREAMSPRIVATE)); |
- RegisterSchema("ttsEngine", ReadFromResource( |
- IDR_EXTENSION_API_JSON_TTSENGINE)); |
- RegisterSchema("tts", ReadFromResource( |
- IDR_EXTENSION_API_JSON_TTS)); |
- RegisterSchema("types", ReadFromResource( |
- IDR_EXTENSION_API_JSON_TYPES)); |
- RegisterSchema("webRequestInternal", ReadFromResource( |
- IDR_EXTENSION_API_JSON_WEBREQUESTINTERNAL)); |
- RegisterSchema("webstore", ReadFromResource( |
- IDR_EXTENSION_API_JSON_WEBSTORE)); |
- RegisterSchema("webstorePrivate", ReadFromResource( |
- IDR_EXTENSION_API_JSON_WEBSTOREPRIVATE)); |
- |
- // Schemas to be loaded via JSON generated from IDL files. |
- GeneratedSchemas::Get(&unloaded_schemas_); |
+ RegisterSchemaResource("app", IDR_EXTENSION_API_JSON_APP); |
+ RegisterSchemaResource("browserAction", IDR_EXTENSION_API_JSON_BROWSERACTION); |
+ RegisterSchemaResource("browsingData", IDR_EXTENSION_API_JSON_BROWSINGDATA); |
+ RegisterSchemaResource("commands", IDR_EXTENSION_API_JSON_COMMANDS); |
+ RegisterSchemaResource("declarativeContent", |
+ IDR_EXTENSION_API_JSON_DECLARATIVE_CONTENT); |
+ RegisterSchemaResource("declarativeWebRequest", |
+ IDR_EXTENSION_API_JSON_DECLARATIVE_WEBREQUEST); |
+ RegisterSchemaResource("experimental.input.virtualKeyboard", |
+ IDR_EXTENSION_API_JSON_EXPERIMENTAL_INPUT_VIRTUALKEYBOARD); |
+ RegisterSchemaResource("experimental.processes", |
+ IDR_EXTENSION_API_JSON_EXPERIMENTAL_PROCESSES); |
+ RegisterSchemaResource("experimental.rlz", |
+ IDR_EXTENSION_API_JSON_EXPERIMENTAL_RLZ); |
+ RegisterSchemaResource("runtime", IDR_EXTENSION_API_JSON_RUNTIME); |
+ RegisterSchemaResource("fileBrowserHandler", |
+ IDR_EXTENSION_API_JSON_FILEBROWSERHANDLER); |
+ RegisterSchemaResource("fileBrowserPrivate", |
+ IDR_EXTENSION_API_JSON_FILEBROWSERPRIVATE); |
+ RegisterSchemaResource("input.ime", IDR_EXTENSION_API_JSON_INPUT_IME); |
+ RegisterSchemaResource("inputMethodPrivate", |
+ IDR_EXTENSION_API_JSON_INPUTMETHODPRIVATE); |
+ RegisterSchemaResource("pageAction", IDR_EXTENSION_API_JSON_PAGEACTION); |
+ RegisterSchemaResource("pageActions", IDR_EXTENSION_API_JSON_PAGEACTIONS); |
+ RegisterSchemaResource("privacy", IDR_EXTENSION_API_JSON_PRIVACY); |
+ RegisterSchemaResource("proxy", IDR_EXTENSION_API_JSON_PROXY); |
+ RegisterSchemaResource("scriptBadge", IDR_EXTENSION_API_JSON_SCRIPTBADGE); |
+ RegisterSchemaResource("streamsPrivate", |
+ IDR_EXTENSION_API_JSON_STREAMSPRIVATE); |
+ RegisterSchemaResource("ttsEngine", IDR_EXTENSION_API_JSON_TTSENGINE); |
+ RegisterSchemaResource("tts", IDR_EXTENSION_API_JSON_TTS); |
+ RegisterSchemaResource("types", IDR_EXTENSION_API_JSON_TYPES); |
+ RegisterSchemaResource("webRequestInternal", |
+ IDR_EXTENSION_API_JSON_WEBREQUESTINTERNAL); |
+ RegisterSchemaResource("webstore", IDR_EXTENSION_API_JSON_WEBSTORE); |
+ RegisterSchemaResource("webstorePrivate", |
+ IDR_EXTENSION_API_JSON_WEBSTOREPRIVATE); |
} |
-void ExtensionAPI::RegisterSchema(const std::string& name, |
- const base::StringPiece& source) { |
- unloaded_schemas_[name] = source; |
+void ExtensionAPI::RegisterSchemaResource(const std::string& name, |
+ int resource_id) { |
+ unloaded_schemas_[name] = resource_id; |
} |
void ExtensionAPI::RegisterDependencyProvider(const std::string& name, |
@@ -385,15 +369,7 @@ Feature::Availability ExtensionAPI::IsAvailable(const std::string& full_name, |
std::string api_name = GetAPINameFromFullName(feature_name, &child_name); |
Feature* feature = GetFeatureDependency(full_name); |
- |
- // Check APIs not using the feature system first. |
- if (!feature) { |
- return IsNonFeatureAPIAvailable(api_name, context, extension, url) |
- ? Feature::CreateAvailability(Feature::IS_AVAILABLE, |
- std::string()) |
- : Feature::CreateAvailability(Feature::INVALID_CONTEXT, |
- kUnavailableMessage); |
- } |
+ CHECK(feature); |
Feature::Availability availability = |
feature->IsAvailableToContext(extension, context, url); |
@@ -455,12 +431,17 @@ const DictionaryValue* ExtensionAPI::GetSchema(const std::string& full_name) { |
result = maybe_schema->second.get(); |
} else { |
// Might not have loaded yet; or might just not exist. |
- std::map<std::string, base::StringPiece>::iterator maybe_schema_resource = |
+ UnloadedSchemaMap::iterator maybe_schema_resource = |
unloaded_schemas_.find(api_name); |
- if (maybe_schema_resource == unloaded_schemas_.end()) |
+ if (maybe_schema_resource != unloaded_schemas_.end()) { |
+ LoadSchema(maybe_schema_resource->first, |
+ ReadFromResource(maybe_schema_resource->second)); |
+ } else if (GeneratedSchemas::IsGenerated(api_name)) { |
+ LoadSchema(api_name, GeneratedSchemas::Get(api_name)); |
+ } else { |
return NULL; |
+ } |
- LoadSchema(maybe_schema_resource->first, maybe_schema_resource->second); |
maybe_schema = schemas_.find(api_name); |
CHECK(schemas_.end() != maybe_schema); |
result = maybe_schema->second.get(); |
@@ -472,69 +453,6 @@ const DictionaryValue* ExtensionAPI::GetSchema(const std::string& full_name) { |
return result; |
} |
-namespace { |
- |
-const char* kDisallowedPlatformAppFeatures[] = { |
- // "app" refers to the the legacy app namespace for hosted apps. |
- "app", |
- "extension", |
- "tabs", |
- "windows" |
-}; |
- |
-bool IsFeatureAllowedForExtension(const std::string& feature, |
- const extensions::Extension& extension) { |
- if (extension.is_platform_app()) { |
- for (size_t i = 0; i < arraysize(kDisallowedPlatformAppFeatures); ++i) { |
- if (feature == kDisallowedPlatformAppFeatures[i]) |
- return false; |
- } |
- } |
- |
- return true; |
-} |
- |
-} // namespace |
- |
-bool ExtensionAPI::IsNonFeatureAPIAvailable(const std::string& name, |
- Feature::Context context, |
- const Extension* extension, |
- const GURL& url) { |
- // Make sure schema is loaded. |
- GetSchema(name); |
- switch (context) { |
- case Feature::UNSPECIFIED_CONTEXT: |
- break; |
- |
- case Feature::BLESSED_EXTENSION_CONTEXT: |
- if (extension) { |
- // Availability is determined by the permissions of the extension. |
- if (!IsAPIAllowed(name, extension)) |
- return false; |
- if (!IsFeatureAllowedForExtension(name, *extension)) |
- return false; |
- } |
- break; |
- |
- case Feature::UNBLESSED_EXTENSION_CONTEXT: |
- case Feature::CONTENT_SCRIPT_CONTEXT: |
- if (extension) { |
- // Same as BLESSED_EXTENSION_CONTEXT, but only those APIs that are |
- // unprivileged. |
- if (!IsAPIAllowed(name, extension)) |
- return false; |
- if (!IsPrivilegedAPI(name)) |
- return false; |
- } |
- break; |
- |
- case Feature::WEB_PAGE_CONTEXT: |
- return false; |
- } |
- |
- return true; |
-} |
- |
std::set<std::string> ExtensionAPI::GetAllAPINames() { |
not at google - send to devlin
2013/05/20 17:19:04
If all APIs are in the feature files, this can jus
cduvall
2013/05/22 03:19:56
I ended up removing this and just using the BaseFe
not at google - send to devlin
2013/05/23 00:09:40
good call.
|
std::set<std::string> result; |
for (SchemaMap::iterator i = schemas_.begin(); i != schemas_.end(); ++i) |
@@ -543,6 +461,9 @@ std::set<std::string> ExtensionAPI::GetAllAPINames() { |
i != unloaded_schemas_.end(); ++i) { |
result.insert(i->first); |
} |
+ std::set<std::string> generated_names; |
+ GeneratedSchemas::GetNames(&generated_names); |
+ result.insert(generated_names.begin(), generated_names.end()); |
return result; |
} |
@@ -571,6 +492,7 @@ std::string ExtensionAPI::GetAPINameFromFullName(const std::string& full_name, |
std::string api_name_candidate = full_name; |
while (true) { |
if (schemas_.find(api_name_candidate) != schemas_.end() || |
+ GeneratedSchemas::IsGenerated(api_name_candidate) || |
unloaded_schemas_.find(api_name_candidate) != unloaded_schemas_.end()) { |
std::string result = api_name_candidate; |
@@ -595,17 +517,4 @@ std::string ExtensionAPI::GetAPINameFromFullName(const std::string& full_name, |
return std::string(); |
} |
-bool ExtensionAPI::IsAPIAllowed(const std::string& name, |
- const Extension* extension) { |
- return PermissionsData::GetRequiredPermissions(extension)-> |
- HasAnyAccessToAPI(name) || |
- PermissionsData::GetOptionalPermissions(extension)-> |
- HasAnyAccessToAPI(name); |
-} |
- |
-bool ExtensionAPI::IsPrivilegedAPI(const std::string& name) { |
- return completely_unprivileged_apis_.count(name) || |
- partially_unprivileged_apis_.count(name); |
-} |
- |
} // namespace extensions |