| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "apps/shell/common/shell_extensions_client.h" | 5 #include "extensions/shell/common/shell_extensions_client.h" |
| 6 | 6 |
| 7 #include "apps/shell/common/api/generated_schemas.h" | |
| 8 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 9 #include "base/logging.h" | 8 #include "base/logging.h" |
| 10 #include "extensions/common/api/generated_schemas.h" | 9 #include "extensions/common/api/generated_schemas.h" |
| 11 #include "extensions/common/api/sockets/sockets_manifest_handler.h" | 10 #include "extensions/common/api/sockets/sockets_manifest_handler.h" |
| 12 #include "extensions/common/common_manifest_handlers.h" | 11 #include "extensions/common/common_manifest_handlers.h" |
| 13 #include "extensions/common/features/api_feature.h" | 12 #include "extensions/common/features/api_feature.h" |
| 14 #include "extensions/common/features/base_feature_provider.h" | 13 #include "extensions/common/features/base_feature_provider.h" |
| 15 #include "extensions/common/features/json_feature_provider_source.h" | 14 #include "extensions/common/features/json_feature_provider_source.h" |
| 16 #include "extensions/common/features/manifest_feature.h" | 15 #include "extensions/common/features/manifest_feature.h" |
| 17 #include "extensions/common/features/permission_feature.h" | 16 #include "extensions/common/features/permission_feature.h" |
| 18 #include "extensions/common/features/simple_feature.h" | 17 #include "extensions/common/features/simple_feature.h" |
| 19 #include "extensions/common/manifest_handler.h" | 18 #include "extensions/common/manifest_handler.h" |
| 20 #include "extensions/common/permissions/permission_message_provider.h" | 19 #include "extensions/common/permissions/permission_message_provider.h" |
| 21 #include "extensions/common/permissions/permissions_info.h" | 20 #include "extensions/common/permissions/permissions_info.h" |
| 22 #include "extensions/common/permissions/permissions_provider.h" | 21 #include "extensions/common/permissions/permissions_provider.h" |
| 23 #include "extensions/common/url_pattern_set.h" | 22 #include "extensions/common/url_pattern_set.h" |
| 23 #include "extensions/shell/common/api/generated_schemas.h" |
| 24 #include "grit/app_shell_resources.h" | 24 #include "grit/app_shell_resources.h" |
| 25 #include "grit/extensions_resources.h" | 25 #include "grit/extensions_resources.h" |
| 26 | 26 |
| 27 using extensions::APIPermissionInfo; | 27 namespace extensions { |
| 28 using extensions::APIPermissionSet; | |
| 29 using extensions::BaseFeatureProvider; | |
| 30 using extensions::Extension; | |
| 31 using extensions::FeatureProvider; | |
| 32 using extensions::JSONFeatureProviderSource; | |
| 33 using extensions::Manifest; | |
| 34 using extensions::PermissionMessage; | |
| 35 using extensions::PermissionMessages; | |
| 36 using extensions::PermissionSet; | |
| 37 using extensions::URLPatternSet; | |
| 38 | |
| 39 namespace apps { | |
| 40 | 28 |
| 41 namespace { | 29 namespace { |
| 42 | 30 |
| 43 template <class FeatureClass> | 31 template <class FeatureClass> |
| 44 extensions::SimpleFeature* CreateFeature() { | 32 SimpleFeature* CreateFeature() { |
| 45 return new FeatureClass; | 33 return new FeatureClass; |
| 46 } | 34 } |
| 47 | 35 |
| 48 // TODO(jamescook): Refactor ChromePermissionsMessageProvider so we can share | 36 // TODO(jamescook): Refactor ChromePermissionsMessageProvider so we can share |
| 49 // code. For now, this implementation does nothing. | 37 // code. For now, this implementation does nothing. |
| 50 class ShellPermissionMessageProvider | 38 class ShellPermissionMessageProvider : public PermissionMessageProvider { |
| 51 : public extensions::PermissionMessageProvider { | |
| 52 public: | 39 public: |
| 53 ShellPermissionMessageProvider() {} | 40 ShellPermissionMessageProvider() {} |
| 54 virtual ~ShellPermissionMessageProvider() {} | 41 virtual ~ShellPermissionMessageProvider() {} |
| 55 | 42 |
| 56 // PermissionMessageProvider implementation. | 43 // PermissionMessageProvider implementation. |
| 57 virtual PermissionMessages GetPermissionMessages( | 44 virtual PermissionMessages GetPermissionMessages( |
| 58 const PermissionSet* permissions, | 45 const PermissionSet* permissions, |
| 59 Manifest::Type extension_type) const OVERRIDE { | 46 Manifest::Type extension_type) const OVERRIDE { |
| 60 return PermissionMessages(); | 47 return PermissionMessages(); |
| 61 } | 48 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 84 private: | 71 private: |
| 85 DISALLOW_COPY_AND_ASSIGN(ShellPermissionMessageProvider); | 72 DISALLOW_COPY_AND_ASSIGN(ShellPermissionMessageProvider); |
| 86 }; | 73 }; |
| 87 | 74 |
| 88 base::LazyInstance<ShellPermissionMessageProvider> | 75 base::LazyInstance<ShellPermissionMessageProvider> |
| 89 g_permission_message_provider = LAZY_INSTANCE_INITIALIZER; | 76 g_permission_message_provider = LAZY_INSTANCE_INITIALIZER; |
| 90 | 77 |
| 91 } // namespace | 78 } // namespace |
| 92 | 79 |
| 93 ShellExtensionsClient::ShellExtensionsClient() | 80 ShellExtensionsClient::ShellExtensionsClient() |
| 94 : extensions_api_permissions_(extensions::ExtensionsAPIPermissions()) { | 81 : extensions_api_permissions_(ExtensionsAPIPermissions()) { |
| 95 } | 82 } |
| 96 | 83 |
| 97 ShellExtensionsClient::~ShellExtensionsClient() { | 84 ShellExtensionsClient::~ShellExtensionsClient() { |
| 98 } | 85 } |
| 99 | 86 |
| 100 void ShellExtensionsClient::Initialize() { | 87 void ShellExtensionsClient::Initialize() { |
| 101 extensions::RegisterCommonManifestHandlers(); | 88 RegisterCommonManifestHandlers(); |
| 102 | 89 |
| 103 // TODO(rockot): API manifest handlers which move out to src/extensions | 90 // TODO(rockot): API manifest handlers which move out to src/extensions |
| 104 // should either end up in RegisterCommonManifestHandlers or some new | 91 // should either end up in RegisterCommonManifestHandlers or some new |
| 105 // initialization step specifically for API manifest handlers. | 92 // initialization step specifically for API manifest handlers. |
| 106 (new extensions::SocketsManifestHandler)->Register(); | 93 (new SocketsManifestHandler)->Register(); |
| 107 | 94 |
| 108 extensions::ManifestHandler::FinalizeRegistration(); | 95 ManifestHandler::FinalizeRegistration(); |
| 109 // TODO(jamescook): Do we need to whitelist any extensions? | 96 // TODO(jamescook): Do we need to whitelist any extensions? |
| 110 | 97 |
| 111 extensions::PermissionsInfo::GetInstance()->AddProvider( | 98 PermissionsInfo::GetInstance()->AddProvider(extensions_api_permissions_); |
| 112 extensions_api_permissions_); | |
| 113 } | 99 } |
| 114 | 100 |
| 115 const extensions::PermissionMessageProvider& | 101 const PermissionMessageProvider& |
| 116 ShellExtensionsClient::GetPermissionMessageProvider() const { | 102 ShellExtensionsClient::GetPermissionMessageProvider() const { |
| 117 NOTIMPLEMENTED(); | 103 NOTIMPLEMENTED(); |
| 118 return g_permission_message_provider.Get(); | 104 return g_permission_message_provider.Get(); |
| 119 } | 105 } |
| 120 | 106 |
| 121 scoped_ptr<FeatureProvider> ShellExtensionsClient::CreateFeatureProvider( | 107 scoped_ptr<FeatureProvider> ShellExtensionsClient::CreateFeatureProvider( |
| 122 const std::string& name) const { | 108 const std::string& name) const { |
| 123 scoped_ptr<FeatureProvider> provider; | 109 scoped_ptr<FeatureProvider> provider; |
| 124 scoped_ptr<JSONFeatureProviderSource> source( | 110 scoped_ptr<JSONFeatureProviderSource> source( |
| 125 CreateFeatureProviderSource(name)); | 111 CreateFeatureProviderSource(name)); |
| 126 if (name == "api") { | 112 if (name == "api") { |
| 127 provider.reset(new BaseFeatureProvider( | 113 provider.reset(new BaseFeatureProvider(source->dictionary(), |
| 128 source->dictionary(), CreateFeature<extensions::APIFeature>)); | 114 CreateFeature<APIFeature>)); |
| 129 } else if (name == "manifest") { | 115 } else if (name == "manifest") { |
| 130 provider.reset(new BaseFeatureProvider( | 116 provider.reset(new BaseFeatureProvider(source->dictionary(), |
| 131 source->dictionary(), CreateFeature<extensions::ManifestFeature>)); | 117 CreateFeature<ManifestFeature>)); |
| 132 } else if (name == "permission") { | 118 } else if (name == "permission") { |
| 133 provider.reset(new BaseFeatureProvider( | 119 provider.reset(new BaseFeatureProvider(source->dictionary(), |
| 134 source->dictionary(), CreateFeature<extensions::PermissionFeature>)); | 120 CreateFeature<PermissionFeature>)); |
| 135 } else { | 121 } else { |
| 136 NOTREACHED(); | 122 NOTREACHED(); |
| 137 } | 123 } |
| 138 return provider.Pass(); | 124 return provider.Pass(); |
| 139 } | 125 } |
| 140 | 126 |
| 141 scoped_ptr<JSONFeatureProviderSource> | 127 scoped_ptr<JSONFeatureProviderSource> |
| 142 ShellExtensionsClient::CreateFeatureProviderSource( | 128 ShellExtensionsClient::CreateFeatureProviderSource( |
| 143 const std::string& name) const { | 129 const std::string& name) const { |
| 144 scoped_ptr<JSONFeatureProviderSource> source( | 130 scoped_ptr<JSONFeatureProviderSource> source( |
| (...skipping 17 matching lines...) Expand all Loading... |
| 162 URLPatternSet* new_hosts, | 148 URLPatternSet* new_hosts, |
| 163 std::set<PermissionMessage>* messages) const { | 149 std::set<PermissionMessage>* messages) const { |
| 164 NOTIMPLEMENTED(); | 150 NOTIMPLEMENTED(); |
| 165 } | 151 } |
| 166 | 152 |
| 167 void ShellExtensionsClient::SetScriptingWhitelist( | 153 void ShellExtensionsClient::SetScriptingWhitelist( |
| 168 const ScriptingWhitelist& whitelist) { | 154 const ScriptingWhitelist& whitelist) { |
| 169 scripting_whitelist_ = whitelist; | 155 scripting_whitelist_ = whitelist; |
| 170 } | 156 } |
| 171 | 157 |
| 172 const extensions::ExtensionsClient::ScriptingWhitelist& | 158 const ExtensionsClient::ScriptingWhitelist& |
| 173 ShellExtensionsClient::GetScriptingWhitelist() const { | 159 ShellExtensionsClient::GetScriptingWhitelist() const { |
| 174 // TODO(jamescook): Real whitelist. | 160 // TODO(jamescook): Real whitelist. |
| 175 return scripting_whitelist_; | 161 return scripting_whitelist_; |
| 176 } | 162 } |
| 177 | 163 |
| 178 URLPatternSet ShellExtensionsClient::GetPermittedChromeSchemeHosts( | 164 URLPatternSet ShellExtensionsClient::GetPermittedChromeSchemeHosts( |
| 179 const Extension* extension, | 165 const Extension* extension, |
| 180 const APIPermissionSet& api_permissions) const { | 166 const APIPermissionSet& api_permissions) const { |
| 181 NOTIMPLEMENTED(); | 167 NOTIMPLEMENTED(); |
| 182 return URLPatternSet(); | 168 return URLPatternSet(); |
| 183 } | 169 } |
| 184 | 170 |
| 185 bool ShellExtensionsClient::IsScriptableURL(const GURL& url, | 171 bool ShellExtensionsClient::IsScriptableURL(const GURL& url, |
| 186 std::string* error) const { | 172 std::string* error) const { |
| 187 NOTIMPLEMENTED(); | 173 NOTIMPLEMENTED(); |
| 188 return true; | 174 return true; |
| 189 } | 175 } |
| 190 | 176 |
| 191 bool ShellExtensionsClient::IsAPISchemaGenerated( | 177 bool ShellExtensionsClient::IsAPISchemaGenerated( |
| 192 const std::string& name) const { | 178 const std::string& name) const { |
| 193 // TODO(rockot): Remove dependency on src/chrome once we have some core APIs | 179 // TODO(rockot): Remove dependency on src/chrome once we have some core APIs |
| 194 // moved out. See http://crbug.com/349042. | 180 // moved out. See http://crbug.com/349042. |
| 195 // Special-case our simplified app.runtime implementation because we don't | 181 // Special-case our simplified app.runtime implementation because we don't |
| 196 // have the Chrome app APIs available. | 182 // have the Chrome app APIs available. |
| 197 return extensions::core_api::GeneratedSchemas::IsGenerated(name) || | 183 return core_api::GeneratedSchemas::IsGenerated(name) || |
| 198 apps::shell_api::GeneratedSchemas::IsGenerated(name); | 184 shell_api::GeneratedSchemas::IsGenerated(name); |
| 199 } | 185 } |
| 200 | 186 |
| 201 base::StringPiece ShellExtensionsClient::GetAPISchema( | 187 base::StringPiece ShellExtensionsClient::GetAPISchema( |
| 202 const std::string& name) const { | 188 const std::string& name) const { |
| 203 // Schema for chrome.shell APIs. | 189 // Schema for chrome.shell APIs. |
| 204 if (apps::shell_api::GeneratedSchemas::IsGenerated(name)) | 190 if (shell_api::GeneratedSchemas::IsGenerated(name)) |
| 205 return apps::shell_api::GeneratedSchemas::Get(name); | 191 return shell_api::GeneratedSchemas::Get(name); |
| 206 | 192 |
| 207 return extensions::core_api::GeneratedSchemas::Get(name); | 193 return core_api::GeneratedSchemas::Get(name); |
| 208 } | 194 } |
| 209 | 195 |
| 210 void ShellExtensionsClient::RegisterAPISchemaResources( | 196 void ShellExtensionsClient::RegisterAPISchemaResources( |
| 211 extensions::ExtensionAPI* api) const { | 197 ExtensionAPI* api) const { |
| 212 } | 198 } |
| 213 | 199 |
| 214 bool ShellExtensionsClient::ShouldSuppressFatalErrors() const { return true; } | 200 bool ShellExtensionsClient::ShouldSuppressFatalErrors() const { |
| 201 return true; |
| 202 } |
| 215 | 203 |
| 216 } // namespace apps | 204 } // namespace extensions |
| OLD | NEW |