blob: 1890a613c92206b9ae30ca054f68c9324523d6d8 [file] [log] [blame] [view]
rdevlin.cronin8a23c0c2016-08-19 21:44:241# Extension Features Files
2
3[TOC]
4
5## Summary
6
7The Extension features files specify the different requirements for extension
8feature availability.
9
10An **extension feature** can be any component of extension capabilities. Most
11notably, this includes extension APIs, but there are also more structural or
12behavioral features, such as web accessible resources or event pages.
13
14## Files
15
16There are four different feature files used:
17* [\_api\_features](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/_api_features.json):
18Specifies the requirements for API availability. If an extension doesn't satisfy
19the requirements, the API will not be accessible in the extension's code.
20* [\_permission\_features](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/_permission_features.json):
21Specifies the requirements for permission availability. If an extension doesn't
22satisfy the requirements, the permission will not be granted and the extension
23will have an install warning.
24* [\_manifest\_features](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/_manifest_features.json):
25Specifies the requirements for manifest entry availability. If an extension
26doesn't satisfy the requirements, the extension will fail to load with an error.
emaxx08b41b02017-05-22 20:38:4527* [\_behavior\_features](https://chromium.googlesource.com/chromium/src/+/master/extensions/common/api/_behavior_features.json):
rdevlin.cronin8a23c0c2016-08-19 21:44:2428Specifies the requirements for miscellaneous extension behaviors. This should
29typically not be used.
30
31Note that these files may be present under chrome/common/extensions/api, as well
32as under extensions/common/api and extensions/shell/common/api.
33
34## Grammar
35
36The feature files are written in JSON. Each file contains a single JSON object
37with properties for each feature.
38
39```
40{
41 "feature1": <definition>,
42 "feature2": <definition>,
43 ...
44}
45```
46
47### Simple and Complex Features
48
49Most features are known as "simple" features. These are features whose
50definition is a single object that contains the properties describing the
51criteria for availability. A simple feature might look like this:
52```
53"feature1": {
54 "dependencies": ["permission:feature1"],
55 "contexts": ["blessed_extension"]
56}
57```
58`feature1` has a single definition, which says for it to be available, a
59permission must be present and it must be executed from a blessed context.
60(These concepts are covered more later in this document.)
61
62Features can also be "complex". A complex feature has a list of objects to
63specify multiple groups of possible properties. A complex feature could look
64like this:
65```
66"feature1": [{
67 "dependencies": ["permission:feature1"],
68 "contexts": ["blessed_extension"]
69}, {
70 "dependencies": ["permission:otherPermission"],
71 "contexts": ["blessed_extension", "unblessed_extension"]
72}]
73```
74
75With complex features, if either of the definitions are matched, the feature
76is available (in other words, the feature definitions are logically OR'd
77together). Complex features should frequently be avoided, as it makes the
78logic more involved and slower.
79
80### Inheritance
81
82By default, features inherit from parents. A feature's ancestry is specified by
83its name, where a child feature is the parent's name followed by a '.' and the
84child's name. That is, `feature1.child` is the child of `feature1`. Inheritance
85can carry for multiple levels (e.g. `feature1.child.child`), but this is rarely
86(if ever) useful.
87
88A child feature inherits all the properties of its parent, but can choose to
89override them or add additional properties. Take the example:
90```
91"feature1": {
92 "dependencies": ["permission:feature1"],
93 "contexts": ["blessed_extension"]
94},
95"feature1.child": {
96 "contexts": ["unblessed_extension"],
97 "extension_types": ["extension"]
98}
99```
100
101In this case, `feature1.child` will effectively have the properties
102```
103"dependencies": ["permission:feature1"], # inherited from feature1
104"contexts": ["unblessed_extension"], # inherited value overridden by child
105"extension_types": ["extension] # specified by child
106```
107
108If you don't want a child to inherit any features from the parent, add the
109property `"noparent": true`. This is useful if, for instance, you have a
110prefixed API name that isn't dependent on the prefix, such as app.window
111(which is fully separate from the app API).
112
113If the parent of a feature is a complex feature, the feature system needs to
114know which parent to inherit from. To do this, add the property
115`"default_parent": true` to one of the feature definitions in the parent
116feature.
117
118## Properties
119
120The following properties are supported in the feature system.
121
tbarzicfeb4b052016-11-29 18:23:09122### alias
123
124The `alias` property specifies that the feature has an associated alias feature.
125An alias feature is a feature that provides the same functionality as it's
126source feature (i.e. the feature referenced by the alias). For example, an API
127alias provides bindings for the source API under a different name. If one wanted
128to declare an API alias, they would have to introduce an API alias feature -
129defined as a feature that has `source` property, and set `alias` property on
130the original feature. For example, the following would introduce an API alias
131feature named `featureAlias` for API `feature`:
132```none
133{
134 "feature": {
135 "contexts": ["blessed_extension"],
136 "channel": "dev",
137 "alias": "featureAlias"
138 },
139 "featureAlias": {
140 "contexts": ["blessed_extension"],
141 "channel": "dev",
142 "source": "feature"
143 }
144}
145```
146`featureAlias[source]` value specifies that `featureAlias` is an alias for API
147feature `feature`
148
149`feature[alias]` value specifies that `feature` API has an API alias
150`featureAlias`
151
152When feature `featureAlias` is available, `feature` bindings would be accessible
153using `feauteAlias`. In other words `chrome.featureAlias` would point to an API
154with the bindings equivalent to the bindings of `feature` API.
155
156The alias API will inherit the schema from the source API, but it will not
157respect the source API child features. To accomplish parity with the source API
158feature children, identical child features should be added for the alias API.
159
160Note that to properly create an alias, both `source` property on the alias
161feature and `alias` property on the aliased feature have to be set.
162
163Alias features are only available for API features, and each API can have at
164most one alias.
165For complex features, `alias` property will be set to the `alias` value of the
166first component simple feature that has it set.
167
rdevlin.cronin8a23c0c2016-08-19 21:44:24168### blacklist
169
170The `blacklist` property specifies a list of ID hashes for extensions that
rdevlin.cronin1d4585192016-08-22 22:34:28171cannot access a feature. See ID Hashes in this document for how to generate
172these hashes.
rdevlin.cronin8a23c0c2016-08-19 21:44:24173
174Accepted values are lists of id hashes.
175
176### channel
177
178The `channel` property specifies a maximum channel for the feature availability.
179That is, specifying `dev` means that the feature is available on `dev`,
180`canary`, and `trunk`.
181
182Accepted values are a single string from `trunk`, `canary`, `dev`, `beta`, and
183`stable`.
184
185### command\_line\_switch
186
187The `command_line_switch` property specifies a command line switch that must be
188present for the feature to be available.
189
190Accepted values are a single string for the command line switch (without the
191preceeding '--').
192
193### component\_extensions\_auto\_granted
194
195The `component_extensions_auto_granted` specifies whether or not component
196extensions should be automatically granted access to the feature. By default,
197this is `true`.
198
199The only accepted value is the bool `false` (since true is the default).
200
201### contexts
202
203The `contexts` property specifies which JavaScript contexts can access the
204feature. All API features must specify at least one context, and only API
205features can specify contexts.
206
207Accepted values are a list of strings from `blessed_extension`,
208`blessed_web_page`, `content_script`, `extension_service_worker`,
tbarzic8e89b0b12017-06-10 03:25:51209`lock_screen_extension`, `web_page`, `webui`, and `unblessed_extension`.
210
211The `lock_screen_extension` context is used instead of `blessed_extension`
212context for extensions on the Chrome OS lock screen. Other extensions related
213contexts (`blessed_web_page`, `content_script`, `extension_service_worker`,
214`unblessed_extension`) are not expected to be present on the lock screen.
rdevlin.cronin8a23c0c2016-08-19 21:44:24215
216### default\_parent
217
218The `default_parent` property specifies a feature definition from a complex
219feature to be used as the parent for any children. See also Inheritance.
220
221The only accepted value is the bool `true`.
222
223### dependencies
224
225The `dependencies` property specifies which other features must be present in
226order to access this feature. This is useful so that you don't have to
227re-specify all the same properties on an API feature and a permission feature.
228
229A common practice is to put as many restrictions as possible in the
230permission or manifest feature so that we warn at extension load, and put
231relatively limited properties in an API feature with a dependency on the
232manifest or permission feature.
233
234To specify a dependent feature, use the prefix the feature name with the type
235of feature it is, followed by a colon. For example, in order to specify a
236dependency on a permission feature `foo`, we would add the dependency entry
237`permission:foo`.
238
239Accepted values are lists of strings specifying the dependent features.
240
241### extension\_types
242
243The `extension_types` properties specifies the different classes of extensions
244that can use the feature. It is very common for certain features to only be
245allowed in certain extension classes, rather than available to all types.
246
247Accepted values are lists of strings from `extension`, `hosted_app`,
Alexander Hendrich33ec65ee2019-05-21 09:29:13248`legacy_packaged_app`, `platform_app`, `shared_module`, `theme`, and
249`login_screen_extension`.
rdevlin.cronin8a23c0c2016-08-19 21:44:24250
251### location
252
253The `location` property specifies the required install location of the
254extension.
255
Kelvin Jiang38085102019-11-01 19:16:39256Accepted values are a single string from `component`, `external_component`,
257`policy`, and `unpacked`.
rdevlin.cronin8a23c0c2016-08-19 21:44:24258
259### internal
260
261The `internal` property specifies whether or not a feature is considered
262internal to Chromium. Internal features are not exposed to extensions, and can
263only be used from Chromium code.
264
265The only accepted value is the bool `true`.
266
267### matches
268
269The `matches` property specifies url patterns which should be allowed to access
270the feature. Only API features may specify `matches`, and `matches` only make
271sense with a context of either `webui` or `web_page`.
272
273Accepted values are a list of strings specifying the match patterns.
274
275### max\_manifest\_version
276
277The `max_manifest_version` property specifies the maximum manifest version to be
278allowed to access a feature. Extensions with a greater manifest version cannot
279access the feature.
280
281The only accepted value is `1`, as currently the highest possible manifest
282version is `2`.
283
284### min\_manifest\_version
285
286The `min_manifest_version` property specifies the minimum manifest version to be
287allowed to access a feature. Extensions with a lesser manifest version cannot
288access the feature.
289
Kelvin Jiang8cb81512019-04-17 19:02:57290Accepted values are `2` and `3`, as 3 is currently the highest possible manifest
291version.
rdevlin.cronin8a23c0c2016-08-19 21:44:24292
293### noparent
294
295The `noparent` property specifies that a feature should not inherit any
296properties from a derived parent. See also Inheritance.
297
298The only accepted value is the bool `true`.
299
300### platforms
301
302The `platforms` property specifies the properties the feature should be
303available on.
304
305The accepted values are lists of strings from `chromeos`, `mac`, `linux`, and
306`win`.
307
tbarzic64bf38de2016-09-15 19:58:14308### session\_types
309
310The `session_types` property specifies in which types of sessions a feature
311should be available. The session type describes the type of user that is
312logged in the current session. Session types to which feature can be restricted
313are only supported on Chrome OS - features restricted to set of session types
314will be disabled on other platforms. Also, note that all currently supported
315session types imply that a user is logged into the session (i.e. features that
tbarzicfeb4b052016-11-29 18:23:09316use `session_types` property will be disabled when a user is not logged in).
tbarzic64bf38de2016-09-15 19:58:14317
tbarzic5babfd312017-01-10 20:13:18318The accepted values are lists of strings from `regular`, `kiosk` and
319`kiosk.autolaunched`.
320
321`regular` session is a session launched for a regular, authenticated user.
322
323`kiosk` session is a session launched for a kiosk app - an app that runs on its
Alexander Hendrich33ec65ee2019-05-21 09:29:13324own, in full control of the current session.
tbarzic5babfd312017-01-10 20:13:18325
326`kiosk.autolaunched` represents auto-launched kiosk session - a kiosk session
327that is launched automatically from Chrome OS login screen, without any user
328interaction. Note that allowing `kiosk` session implies allowing
329`kiosk.autolaunched` session.
tbarzic64bf38de2016-09-15 19:58:14330
tbarzicfeb4b052016-11-29 18:23:09331### source
332
333The `source` property specifies that the feature is an alias for the feature
334specified by the property value, and is only allowed for API features.
tbarzic5babfd312017-01-10 20:13:18335For more information about alias features, see [alias](#alias) property
336documentation.
tbarzicfeb4b052016-11-29 18:23:09337
338For complex features, `source` property will be set to the `source` value of the
339first component simple feature that has it set.
340
rdevlin.cronin8a23c0c2016-08-19 21:44:24341### whitelist
342
343The `whitelist` property specifies a list of ID hashes for extensions that
344are the only extensions allowed to access a feature.
345
346Accepted values are lists of id hashes.
347
rdevlin.cronin1d4585192016-08-22 22:34:28348## ID Hashes
349
350Instead of listing the ID directly in the whitelist or blacklist section, we
351use an uppercased SHA1 hash of the id.
352
353To generate a new whitelisted ID for an extension ID, do the following in bash:
354```
355$ echo -n "aaaabbbbccccddddeeeeffffgggghhhh" | \
356 sha1sum | tr '[:lower:]' '[:upper:]'
357```
358(Replacing `aaaabbbbccccddddeeeeffffgggghhhh` with your extension ID.)
359
360The output should be something like:
361```
3629A0417016F345C934A1A88F55CA17C05014EEEBA -
363```
364
365Add the ID to the whitelist or blacklist for the desired feature. It is also
366often useful to link the crbug next to the id hash, e.g.:
367```
368"whitelist": [
369 "9A0417016F345C934A1A88F55CA17C05014EEEBA" // crbug.com/<num>
370]
371```
372
373Google employees: please update http://go/chrome-api-whitelist to map hashes
374back to ids.
375
rdevlin.cronin06d4e582016-08-25 20:13:11376## Feature Contexts
377
378A Feature Context is the type of JavaScript context that a feature can be made
379available in. This allows us to restrict certain features to only being
380accessible in more secure contexts, or to expose features to contexts outside
381of extensions.
382
383For each of these contexts, an "extension" context can refer to a context of
384either an app or an extension.
385
386### Blessed Extension Contexts
387
388The `blessed_extension` context refers to a JavaScript context running from an
389extension process. These are typically the most secure JavaScript contexts, as
390it reduces the likelihood that a compromised web page renderer will have access
391to secure APIs.
392
393Traditionally, only pages with a top-level extension frame (with a
394`chrome-extension://` scheme), extension popups, and app windows were blessed
395extension contexts. With [site isolation](https://www.chromium.org/developers/design-documents/site-isolation),
396extension frames running in web pages are also considered blessed extension
397contexts, since they are running in the extension process (rather than in the
398same process as the web page).
399
400### Blessed Web Page Contexts
401
402The `blessed_web_page` context refers to a JavaScript context running from a
403hosted app. These are similar to blessed extension contexts in that they are
404(partially) isolated from other processes, but are typically more restricted
405than blessed extension processes, since hosted apps generally have fewer
406permissions. Note that these contexts are unaffected by the `matches` property.
407
408### Content Script Contexts
409
410The `content_script` context refers to a JavaScript context for an extension
411content script. Since content scripts share a process with (and run on the same
412content as) web pages, these are considered very insecure contexts. Very few
413features should be exposed to these contexts.
414
415### Service Worker Contexts
416
417The `extension_service_worker` context refers to a JavaScript context for an
418extension's service worker. An extension can only register a service worker for
419it's own domain, and these should only be run within an extension process. Thus,
420these have similar privilege levels to blessed extension processes.
421
422### Web Page Contexts
423
424The `web_page` context refers to a JavaScript context for a simple web page,
425completely separate from extensions. This is the least secure of all contexts,
426and very few features should be exposed to these contexts. When specifying this
427context, an accompanying URL pattern should be provided with the `matches`
428property.
429
430### WebUI Contexts
431
432The `webui` context refers to a JavaScript context for a page with WebUI
433bindings, such as internal chrome pages like chrome://settings or
434chrome://extensions. These are considered secure contexts, since they are
435an internal part of chrome. When specifying this context, an accompanying URL
436pattern should be provided with the `matches` property.
437
438### Unblessed Extension Contexts
439
440The `unblessed_extension` context refers to a JavaScript context for an
441extension frame that is embedded in an external page, like a web page, and
442runs in the same process as the embedder. Given the limited separation between
443the (untrusted) embedder and the extension frame, relatively few features are
444exposed in these contexts. Note that with [site isolation](https://www.chromium.org/developers/design-documents/site-isolation),
445extension frames (even those embedded in web pages) run in the trusted
446extension process, and become blessed extension contexts.
447
rdevlin.cronin1d4585192016-08-22 22:34:28448## Compilation
449
450The feature files are compiled as part of the suite of tools in
451//tools/json\_schema\_compiler/. The output is a set of FeatureProviders that
452contain a mapping of all features.
453
454In addition to being significantly more performant than parsing the JSON files
455at runtime, this has the added benefit of allowing us to validate at compile
456time rather than needing a unittest (or allowing incorrect features).
457
458In theory, invalid features should result in a compilation failure; in practice,
459the compiler is probably missing some cases.
460
rdevlin.cronin8a23c0c2016-08-19 21:44:24461## Still to come
462
rdevlin.cronin06d4e582016-08-25 20:13:11463TODO(devlin): Add documentation for extension types. Probably also more on
464requirements for individual features.