diff options
author | yoz@chromium.org <yoz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-24 03:14:39 +0000 |
---|---|---|
committer | yoz@chromium.org <yoz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-24 03:14:39 +0000 |
commit | cce6098f7f1bf24fecf648e3cdb6c1f23db42ef8 (patch) | |
tree | f414f043dee276f6a4e153251ccff4369a2d4ccb | |
parent | 8204ede6262a8d7aa0c76f399c6c435babd0855b (diff) | |
download | chromium_src-cce6098f7f1bf24fecf648e3cdb6c1f23db42ef8.zip chromium_src-cce6098f7f1bf24fecf648e3cdb6c1f23db42ef8.tar.gz chromium_src-cce6098f7f1bf24fecf648e3cdb6c1f23db42ef8.tar.bz2 |
Move extension API schema registration to ExtensionsClient.
BUG=368334
Review URL: https://codereview.chromium.org/296133011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@272696 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | apps/shell/common/shell_extensions_client.cc | 4 | ||||
-rw-r--r-- | apps/shell/common/shell_extensions_client.h | 2 | ||||
-rw-r--r-- | chrome/common/extensions/chrome_extensions_client.cc | 40 | ||||
-rw-r--r-- | chrome/common/extensions/chrome_extensions_client.h | 1 | ||||
-rw-r--r-- | extensions/DEPS | 1 | ||||
-rw-r--r-- | extensions/common/extension_api.cc | 30 | ||||
-rw-r--r-- | extensions/common/extension_api.h | 3 | ||||
-rw-r--r-- | extensions/common/extensions_client.h | 7 | ||||
-rw-r--r-- | extensions/test/test_extensions_client.cc | 3 | ||||
-rw-r--r-- | extensions/test/test_extensions_client.h | 1 |
10 files changed, 61 insertions, 31 deletions
diff --git a/apps/shell/common/shell_extensions_client.cc b/apps/shell/common/shell_extensions_client.cc index 2dac9e1..cc2f055 100644 --- a/apps/shell/common/shell_extensions_client.cc +++ b/apps/shell/common/shell_extensions_client.cc @@ -207,6 +207,10 @@ base::StringPiece ShellExtensionsClient::GetAPISchema( return extensions::core_api::GeneratedSchemas::Get(name); } +void ShellExtensionsClient::RegisterAPISchemaResources( + extensions::ExtensionAPI* api) const { +} + bool ShellExtensionsClient::ShouldSuppressFatalErrors() const { return true; } } // namespace apps diff --git a/apps/shell/common/shell_extensions_client.h b/apps/shell/common/shell_extensions_client.h index 4ccd1a5..0ebb3ad 100644 --- a/apps/shell/common/shell_extensions_client.h +++ b/apps/shell/common/shell_extensions_client.h @@ -41,6 +41,8 @@ class ShellExtensionsClient : public extensions::ExtensionsClient { virtual bool IsAPISchemaGenerated(const std::string& name) const OVERRIDE; virtual base::StringPiece GetAPISchema(const std::string& name) const OVERRIDE; + virtual void RegisterAPISchemaResources( + extensions::ExtensionAPI* api) const OVERRIDE; virtual bool ShouldSuppressFatalErrors() const OVERRIDE; private: diff --git a/chrome/common/extensions/chrome_extensions_client.cc b/chrome/common/extensions/chrome_extensions_client.cc index 7e0f0eb..cd58fb8 100644 --- a/chrome/common/extensions/chrome_extensions_client.cc +++ b/chrome/common/extensions/chrome_extensions_client.cc @@ -17,6 +17,7 @@ #include "extensions/common/api/generated_schemas.h" #include "extensions/common/common_manifest_handlers.h" #include "extensions/common/extension.h" +#include "extensions/common/extension_api.h" #include "extensions/common/features/api_feature.h" #include "extensions/common/features/base_feature_provider.h" #include "extensions/common/features/feature_provider.h" @@ -33,6 +34,9 @@ #include "extensions/common/url_pattern.h" #include "extensions/common/url_pattern_set.h" #include "grit/common_resources.h" +#if defined(ENABLE_EXTENSIONS) +#include "grit/extensions_api_resources.h" +#endif #include "grit/extensions_resources.h" #include "grit/generated_resources.h" #include "ui/base/l10n/l10n_util.h" @@ -231,6 +235,42 @@ base::StringPiece ChromeExtensionsClient::GetAPISchema( return apps::api::GeneratedSchemas::Get(name); } +void ChromeExtensionsClient::RegisterAPISchemaResources( + ExtensionAPI* api) const { +#if defined(ENABLE_EXTENSIONS) + api->RegisterSchemaResource("accessibilityPrivate", + IDR_EXTENSION_API_JSON_ACCESSIBILITYPRIVATE); + api->RegisterSchemaResource("app", IDR_EXTENSION_API_JSON_APP); + api->RegisterSchemaResource("browserAction", + IDR_EXTENSION_API_JSON_BROWSERACTION); + api->RegisterSchemaResource("commands", IDR_EXTENSION_API_JSON_COMMANDS); + api->RegisterSchemaResource("declarativeContent", + IDR_EXTENSION_API_JSON_DECLARATIVE_CONTENT); + api->RegisterSchemaResource("declarativeWebRequest", + IDR_EXTENSION_API_JSON_DECLARATIVE_WEBREQUEST); + api->RegisterSchemaResource("fileBrowserHandler", + IDR_EXTENSION_API_JSON_FILEBROWSERHANDLER); + api->RegisterSchemaResource("inputMethodPrivate", + IDR_EXTENSION_API_JSON_INPUTMETHODPRIVATE); + api->RegisterSchemaResource("pageAction", IDR_EXTENSION_API_JSON_PAGEACTION); + api->RegisterSchemaResource("pageActions", + IDR_EXTENSION_API_JSON_PAGEACTIONS); + api->RegisterSchemaResource("privacy", IDR_EXTENSION_API_JSON_PRIVACY); + api->RegisterSchemaResource("processes", IDR_EXTENSION_API_JSON_PROCESSES); + api->RegisterSchemaResource("proxy", IDR_EXTENSION_API_JSON_PROXY); + api->RegisterSchemaResource("scriptBadge", + IDR_EXTENSION_API_JSON_SCRIPTBADGE); + api->RegisterSchemaResource("ttsEngine", IDR_EXTENSION_API_JSON_TTSENGINE); + api->RegisterSchemaResource("tts", IDR_EXTENSION_API_JSON_TTS); + api->RegisterSchemaResource("types", IDR_EXTENSION_API_JSON_TYPES); + api->RegisterSchemaResource("types.private", + IDR_EXTENSION_API_JSON_TYPES_PRIVATE); + api->RegisterSchemaResource("webstore", IDR_EXTENSION_API_JSON_WEBSTORE); + api->RegisterSchemaResource("webViewRequest", + IDR_EXTENSION_API_JSON_WEBVIEW_REQUEST); +#endif // defined(ENABLE_EXTENSIONS) +} + bool ChromeExtensionsClient::ShouldSuppressFatalErrors() const { // <= dev means dev, canary, and trunk. return GetCurrentChannel() <= chrome::VersionInfo::CHANNEL_DEV; diff --git a/chrome/common/extensions/chrome_extensions_client.h b/chrome/common/extensions/chrome_extensions_client.h index ce88bba..03474f5 100644 --- a/chrome/common/extensions/chrome_extensions_client.h +++ b/chrome/common/extensions/chrome_extensions_client.h @@ -45,6 +45,7 @@ class ChromeExtensionsClient : public ExtensionsClient { virtual bool IsAPISchemaGenerated(const std::string& name) const OVERRIDE; virtual base::StringPiece GetAPISchema(const std::string& name) const OVERRIDE; + virtual void RegisterAPISchemaResources(ExtensionAPI* api) const OVERRIDE; virtual bool ShouldSuppressFatalErrors() const OVERRIDE; // Get the LazyInstance for ChromeExtensionsClient. diff --git a/extensions/DEPS b/extensions/DEPS index 0fc52ca..f919975 100644 --- a/extensions/DEPS +++ b/extensions/DEPS @@ -13,7 +13,6 @@ include_rules = [ # # TODO(jamescook): Remove these. http://crbug.com/162530 "!chrome/browser/chrome_notification_types.h", - '!grit/extensions_api_resources.h', # This is needed for renderer JS sources which should eventually move to # the extensions_resources target. "!grit/renderer_resources.h", diff --git a/extensions/common/extension_api.cc b/extensions/common/extension_api.cc index 4d6b6ec..9e284f2 100644 --- a/extensions/common/extension_api.cc +++ b/extensions/common/extension_api.cc @@ -22,7 +22,6 @@ #include "extensions/common/features/feature_provider.h" #include "extensions/common/permissions/permission_set.h" #include "extensions/common/permissions/permissions_data.h" -#include "grit/extensions_api_resources.h" #include "ui/base/resource/resource_bundle.h" #include "url/gurl.h" @@ -227,34 +226,7 @@ void ExtensionAPI::InitDefaultConfiguration() { for (size_t i = 0; i < arraysize(names); ++i) RegisterDependencyProvider(names[i], FeatureProvider::GetByName(names[i])); - // Schemas to be loaded from resources. - CHECK(unloaded_schemas_.empty()); - RegisterSchemaResource("accessibilityPrivate", - IDR_EXTENSION_API_JSON_ACCESSIBILITYPRIVATE); - RegisterSchemaResource("app", IDR_EXTENSION_API_JSON_APP); - RegisterSchemaResource("browserAction", IDR_EXTENSION_API_JSON_BROWSERACTION); - RegisterSchemaResource("commands", IDR_EXTENSION_API_JSON_COMMANDS); - RegisterSchemaResource("declarativeContent", - IDR_EXTENSION_API_JSON_DECLARATIVE_CONTENT); - RegisterSchemaResource("declarativeWebRequest", - IDR_EXTENSION_API_JSON_DECLARATIVE_WEBREQUEST); - RegisterSchemaResource("fileBrowserHandler", - IDR_EXTENSION_API_JSON_FILEBROWSERHANDLER); - 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("processes", IDR_EXTENSION_API_JSON_PROCESSES); - RegisterSchemaResource("proxy", IDR_EXTENSION_API_JSON_PROXY); - RegisterSchemaResource("scriptBadge", IDR_EXTENSION_API_JSON_SCRIPTBADGE); - RegisterSchemaResource("ttsEngine", IDR_EXTENSION_API_JSON_TTSENGINE); - RegisterSchemaResource("tts", IDR_EXTENSION_API_JSON_TTS); - RegisterSchemaResource("types", IDR_EXTENSION_API_JSON_TYPES); - RegisterSchemaResource("types.private", IDR_EXTENSION_API_JSON_TYPES_PRIVATE); - RegisterSchemaResource("webstore", IDR_EXTENSION_API_JSON_WEBSTORE); - RegisterSchemaResource("webViewRequest", - IDR_EXTENSION_API_JSON_WEBVIEW_REQUEST); + ExtensionsClient::Get()->RegisterAPISchemaResources(this); default_configuration_initialized_ = true; } diff --git a/extensions/common/extension_api.h b/extensions/common/extension_api.h index bd2e315..e16d401 100644 --- a/extensions/common/extension_api.h +++ b/extensions/common/extension_api.h @@ -60,8 +60,11 @@ class ExtensionAPI { ExtensionAPI(); virtual ~ExtensionAPI(); + // Add a (non-generated) API schema resource. void RegisterSchemaResource(const std::string& api_name, int resource_id); + // Add a FeatureProvider for APIs. The features are used to specify + // dependencies and constraints on the availability of APIs. void RegisterDependencyProvider(const std::string& name, const FeatureProvider* provider); diff --git a/extensions/common/extensions_client.h b/extensions/common/extensions_client.h index f0bdc8c..9f4ebf9 100644 --- a/extensions/common/extensions_client.h +++ b/extensions/common/extensions_client.h @@ -18,6 +18,7 @@ namespace extensions { class APIPermissionSet; class Extension; +class ExtensionAPI; class FeatureProvider; class JSONFeatureProviderSource; class ManifestPermissionSet; @@ -82,9 +83,13 @@ class ExtensionsClient { // Returns true iff a schema named |name| is generated. virtual bool IsAPISchemaGenerated(const std::string& name) const = 0; - // Gets the API schema named |name|. + // Gets the generated API schema named |name|. virtual base::StringPiece GetAPISchema(const std::string& name) const = 0; + // Register non-generated API schema resources with the global ExtensionAPI. + // Called when the ExtensionAPI is lazily initialized. + virtual void RegisterAPISchemaResources(ExtensionAPI* api) const = 0; + // Determines if certain fatal extensions errors should be surpressed // (i.e., only logged) or allowed (i.e., logged before crashing). virtual bool ShouldSuppressFatalErrors() const = 0; diff --git a/extensions/test/test_extensions_client.cc b/extensions/test/test_extensions_client.cc index 7ef0277..8cee49a 100644 --- a/extensions/test/test_extensions_client.cc +++ b/extensions/test/test_extensions_client.cc @@ -85,6 +85,9 @@ base::StringPiece TestExtensionsClient::GetAPISchema( return base::StringPiece(); } +void TestExtensionsClient::RegisterAPISchemaResources(ExtensionAPI* api) const { +} + bool TestExtensionsClient::ShouldSuppressFatalErrors() const { return true; } diff --git a/extensions/test/test_extensions_client.h b/extensions/test/test_extensions_client.h index 399f43f..be2acd7 100644 --- a/extensions/test/test_extensions_client.h +++ b/extensions/test/test_extensions_client.h @@ -38,6 +38,7 @@ class TestExtensionsClient : public ExtensionsClient { virtual bool IsAPISchemaGenerated(const std::string& name) const OVERRIDE; virtual base::StringPiece GetAPISchema( const std::string& name) const OVERRIDE; + virtual void RegisterAPISchemaResources(ExtensionAPI* api) const OVERRIDE; virtual bool ShouldSuppressFatalErrors() const OVERRIDE; // A whitelist of extensions that can script anywhere. Do not add to this |