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 "apps/shell/common/shell_extensions_client.h" |
6 | 6 |
7 #include "apps/shell/common/shell_app_runtime.h" | 7 #include "apps/shell/common/shell_app_runtime.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "chrome/common/extensions/api/generated_schemas.h" | 9 #include "chrome/common/extensions/api/generated_schemas.h" |
10 #include "chrome/common/extensions/permissions/chrome_api_permissions.h" | 10 #include "chrome/common/extensions/permissions/chrome_api_permissions.h" |
11 #include "extensions/common/api/generated_schemas.h" | 11 #include "extensions/common/api/generated_schemas.h" |
12 #include "extensions/common/api/sockets/sockets_manifest_handler.h" | 12 #include "extensions/common/api/sockets/sockets_manifest_handler.h" |
13 #include "extensions/common/common_manifest_handlers.h" | 13 #include "extensions/common/common_manifest_handlers.h" |
| 14 #include "extensions/common/features/api_feature.h" |
14 #include "extensions/common/features/base_feature_provider.h" | 15 #include "extensions/common/features/base_feature_provider.h" |
| 16 #include "extensions/common/features/json_feature_provider_source.h" |
| 17 #include "extensions/common/features/manifest_feature.h" |
| 18 #include "extensions/common/features/permission_feature.h" |
| 19 #include "extensions/common/features/simple_feature.h" |
15 #include "extensions/common/manifest_handler.h" | 20 #include "extensions/common/manifest_handler.h" |
16 #include "extensions/common/permissions/permission_message_provider.h" | 21 #include "extensions/common/permissions/permission_message_provider.h" |
17 #include "extensions/common/permissions/permissions_provider.h" | 22 #include "extensions/common/permissions/permissions_provider.h" |
18 #include "extensions/common/url_pattern_set.h" | 23 #include "extensions/common/url_pattern_set.h" |
| 24 #include "grit/common_resources.h" |
| 25 #include "grit/extensions_resources.h" |
19 | 26 |
20 using extensions::APIPermissionInfo; | 27 using extensions::APIPermissionInfo; |
21 using extensions::APIPermissionSet; | 28 using extensions::APIPermissionSet; |
| 29 using extensions::BaseFeatureProvider; |
22 using extensions::Extension; | 30 using extensions::Extension; |
| 31 using extensions::FeatureProvider; |
23 using extensions::Manifest; | 32 using extensions::Manifest; |
24 using extensions::PermissionMessage; | 33 using extensions::PermissionMessage; |
25 using extensions::PermissionMessages; | 34 using extensions::PermissionMessages; |
26 using extensions::PermissionSet; | 35 using extensions::PermissionSet; |
27 using extensions::URLPatternSet; | 36 using extensions::URLPatternSet; |
28 | 37 |
29 namespace apps { | 38 namespace apps { |
30 | 39 |
31 namespace { | 40 namespace { |
32 | 41 |
| 42 template <class FeatureClass> |
| 43 extensions::SimpleFeature* CreateFeature() { |
| 44 return new FeatureClass; |
| 45 } |
| 46 |
33 // TODO(jamescook): Refactor ChromePermissionsMessageProvider so we can share | 47 // TODO(jamescook): Refactor ChromePermissionsMessageProvider so we can share |
34 // code. | 48 // code. |
35 class ShellPermissionMessageProvider | 49 class ShellPermissionMessageProvider |
36 : public extensions::PermissionMessageProvider { | 50 : public extensions::PermissionMessageProvider { |
37 public: | 51 public: |
38 ShellPermissionMessageProvider() {} | 52 ShellPermissionMessageProvider() {} |
39 virtual ~ShellPermissionMessageProvider() {} | 53 virtual ~ShellPermissionMessageProvider() {} |
40 | 54 |
41 // PermissionMessageProvider implementation. | 55 // PermissionMessageProvider implementation. |
42 virtual PermissionMessages GetPermissionMessages( | 56 virtual PermissionMessages GetPermissionMessages( |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 return provider; | 121 return provider; |
108 } | 122 } |
109 | 123 |
110 const extensions::PermissionMessageProvider& | 124 const extensions::PermissionMessageProvider& |
111 ShellExtensionsClient::GetPermissionMessageProvider() const { | 125 ShellExtensionsClient::GetPermissionMessageProvider() const { |
112 NOTIMPLEMENTED(); | 126 NOTIMPLEMENTED(); |
113 static ShellPermissionMessageProvider provider; | 127 static ShellPermissionMessageProvider provider; |
114 return provider; | 128 return provider; |
115 } | 129 } |
116 | 130 |
117 extensions::FeatureProvider* ShellExtensionsClient::GetFeatureProviderByName( | 131 scoped_ptr<FeatureProvider> ShellExtensionsClient::CreateFeatureProvider( |
118 const std::string& name) const { | 132 const std::string& name) const { |
119 // TODO(jamescook): Factor out an extensions module feature provider. | 133 extensions::JSONFeatureProviderSource source(name); |
120 return extensions::BaseFeatureProvider::GetByName(name); | 134 if (name == "api") { |
| 135 // TODO(yoz): Only include src/extensions resources. |
| 136 source.LoadJSON(IDR_EXTENSION_API_FEATURES); |
| 137 source.LoadJSON(IDR_CHROME_EXTENSION_API_FEATURES); |
| 138 return scoped_ptr<FeatureProvider>(new BaseFeatureProvider( |
| 139 source.dictionary(), CreateFeature<extensions::APIFeature>)); |
| 140 } else if (name == "manifest") { |
| 141 source.LoadJSON(IDR_EXTENSION_MANIFEST_FEATURES); |
| 142 source.LoadJSON(IDR_CHROME_EXTENSION_MANIFEST_FEATURES); |
| 143 return scoped_ptr<FeatureProvider>(new BaseFeatureProvider( |
| 144 source.dictionary(), CreateFeature<extensions::ManifestFeature>)); |
| 145 } else if (name == "permission") { |
| 146 source.LoadJSON(IDR_EXTENSION_PERMISSION_FEATURES); |
| 147 source.LoadJSON(IDR_CHROME_EXTENSION_PERMISSION_FEATURES); |
| 148 return scoped_ptr<FeatureProvider>(new BaseFeatureProvider( |
| 149 source.dictionary(), CreateFeature<extensions::PermissionFeature>)); |
| 150 } else { |
| 151 NOTREACHED(); |
| 152 } |
| 153 return scoped_ptr<FeatureProvider>(); |
121 } | 154 } |
122 | 155 |
123 void ShellExtensionsClient::FilterHostPermissions( | 156 void ShellExtensionsClient::FilterHostPermissions( |
124 const URLPatternSet& hosts, | 157 const URLPatternSet& hosts, |
125 URLPatternSet* new_hosts, | 158 URLPatternSet* new_hosts, |
126 std::set<PermissionMessage>* messages) const { | 159 std::set<PermissionMessage>* messages) const { |
127 NOTIMPLEMENTED(); | 160 NOTIMPLEMENTED(); |
128 } | 161 } |
129 | 162 |
130 void ShellExtensionsClient::SetScriptingWhitelist( | 163 void ShellExtensionsClient::SetScriptingWhitelist( |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 if (extensions::api::GeneratedSchemas::IsGenerated(name)) | 202 if (extensions::api::GeneratedSchemas::IsGenerated(name)) |
170 return extensions::api::GeneratedSchemas::Get(name); | 203 return extensions::api::GeneratedSchemas::Get(name); |
171 | 204 |
172 // Special-case our simplified app.runtime implementation. | 205 // Special-case our simplified app.runtime implementation. |
173 if (name == extensions::ShellAppRuntime::GetName()) | 206 if (name == extensions::ShellAppRuntime::GetName()) |
174 return extensions::ShellAppRuntime::GetSchema(); | 207 return extensions::ShellAppRuntime::GetSchema(); |
175 | 208 |
176 return extensions::core_api::GeneratedSchemas::Get(name); | 209 return extensions::core_api::GeneratedSchemas::Get(name); |
177 } | 210 } |
178 | 211 |
179 void ShellExtensionsClient::AddExtraFeatureFilters( | |
180 extensions::SimpleFeature* feature) const {} | |
181 | |
182 bool ShellExtensionsClient::ShouldSuppressFatalErrors() const { return true; } | 212 bool ShellExtensionsClient::ShouldSuppressFatalErrors() const { return true; } |
183 | 213 |
184 } // namespace apps | 214 } // namespace apps |
OLD | NEW |