blob: f6fe6b24168116761bc007513f39cd06c727eaa3 [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.
27* [\_behavior\_features](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/_behavior_features.json):
28Specifies 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`,
209`web_page`, `webui`, and `unblessed_extension`.
210
211### default\_parent
212
213The `default_parent` property specifies a feature definition from a complex
214feature to be used as the parent for any children. See also Inheritance.
215
216The only accepted value is the bool `true`.
217
218### dependencies
219
220The `dependencies` property specifies which other features must be present in
221order to access this feature. This is useful so that you don't have to
222re-specify all the same properties on an API feature and a permission feature.
223
224A common practice is to put as many restrictions as possible in the
225permission or manifest feature so that we warn at extension load, and put
226relatively limited properties in an API feature with a dependency on the
227manifest or permission feature.
228
229To specify a dependent feature, use the prefix the feature name with the type
230of feature it is, followed by a colon. For example, in order to specify a
231dependency on a permission feature `foo`, we would add the dependency entry
232`permission:foo`.
233
234Accepted values are lists of strings specifying the dependent features.
235
236### extension\_types
237
238The `extension_types` properties specifies the different classes of extensions
239that can use the feature. It is very common for certain features to only be
240allowed in certain extension classes, rather than available to all types.
241
242Accepted values are lists of strings from `extension`, `hosted_app`,
243`legacy_packaged_app`, `platform_app`, `shared_module`, and `theme`.
244
245### location
246
247The `location` property specifies the required install location of the
248extension.
249
250Accepted values are a single string from `component`, `external_component`, and
251`policy`.
252
253### internal
254
255The `internal` property specifies whether or not a feature is considered
256internal to Chromium. Internal features are not exposed to extensions, and can
257only be used from Chromium code.
258
259The only accepted value is the bool `true`.
260
261### matches
262
263The `matches` property specifies url patterns which should be allowed to access
264the feature. Only API features may specify `matches`, and `matches` only make
265sense with a context of either `webui` or `web_page`.
266
267Accepted values are a list of strings specifying the match patterns.
268
269### max\_manifest\_version
270
271The `max_manifest_version` property specifies the maximum manifest version to be
272allowed to access a feature. Extensions with a greater manifest version cannot
273access the feature.
274
275The only accepted value is `1`, as currently the highest possible manifest
276version is `2`.
277
278### min\_manifest\_version
279
280The `min_manifest_version` property specifies the minimum manifest version to be
281allowed to access a feature. Extensions with a lesser manifest version cannot
282access the feature.
283
284The only accepted value is `2`, as this is currently the highest possible
285manifest version.
286
287### noparent
288
289The `noparent` property specifies that a feature should not inherit any
290properties from a derived parent. See also Inheritance.
291
292The only accepted value is the bool `true`.
293
294### platforms
295
296The `platforms` property specifies the properties the feature should be
297available on.
298
299The accepted values are lists of strings from `chromeos`, `mac`, `linux`, and
300`win`.
301
tbarzic64bf38de2016-09-15 19:58:14302### session\_types
303
304The `session_types` property specifies in which types of sessions a feature
305should be available. The session type describes the type of user that is
306logged in the current session. Session types to which feature can be restricted
307are only supported on Chrome OS - features restricted to set of session types
308will be disabled on other platforms. Also, note that all currently supported
309session types imply that a user is logged into the session (i.e. features that
tbarzicfeb4b052016-11-29 18:23:09310use `session_types` property will be disabled when a user is not logged in).
tbarzic64bf38de2016-09-15 19:58:14311
tbarzic5babfd312017-01-10 20:13:18312The accepted values are lists of strings from `regular`, `kiosk` and
313`kiosk.autolaunched`.
314
315`regular` session is a session launched for a regular, authenticated user.
316
317`kiosk` session is a session launched for a kiosk app - an app that runs on its
318own, in full control of the current session.
319
320`kiosk.autolaunched` represents auto-launched kiosk session - a kiosk session
321that is launched automatically from Chrome OS login screen, without any user
322interaction. Note that allowing `kiosk` session implies allowing
323`kiosk.autolaunched` session.
tbarzic64bf38de2016-09-15 19:58:14324
tbarzicfeb4b052016-11-29 18:23:09325### source
326
327The `source` property specifies that the feature is an alias for the feature
328specified by the property value, and is only allowed for API features.
tbarzic5babfd312017-01-10 20:13:18329For more information about alias features, see [alias](#alias) property
330documentation.
tbarzicfeb4b052016-11-29 18:23:09331
332For complex features, `source` property will be set to the `source` value of the
333first component simple feature that has it set.
334
rdevlin.cronin8a23c0c2016-08-19 21:44:24335### whitelist
336
337The `whitelist` property specifies a list of ID hashes for extensions that
338are the only extensions allowed to access a feature.
339
340Accepted values are lists of id hashes.
341
rdevlin.cronin1d4585192016-08-22 22:34:28342## ID Hashes
343
344Instead of listing the ID directly in the whitelist or blacklist section, we
345use an uppercased SHA1 hash of the id.
346
347To generate a new whitelisted ID for an extension ID, do the following in bash:
348```
349$ echo -n "aaaabbbbccccddddeeeeffffgggghhhh" | \
350 sha1sum | tr '[:lower:]' '[:upper:]'
351```
352(Replacing `aaaabbbbccccddddeeeeffffgggghhhh` with your extension ID.)
353
354The output should be something like:
355```
3569A0417016F345C934A1A88F55CA17C05014EEEBA -
357```
358
359Add the ID to the whitelist or blacklist for the desired feature. It is also
360often useful to link the crbug next to the id hash, e.g.:
361```
362"whitelist": [
363 "9A0417016F345C934A1A88F55CA17C05014EEEBA" // crbug.com/<num>
364]
365```
366
367Google employees: please update http://go/chrome-api-whitelist to map hashes
368back to ids.
369
rdevlin.cronin06d4e582016-08-25 20:13:11370## Feature Contexts
371
372A Feature Context is the type of JavaScript context that a feature can be made
373available in. This allows us to restrict certain features to only being
374accessible in more secure contexts, or to expose features to contexts outside
375of extensions.
376
377For each of these contexts, an "extension" context can refer to a context of
378either an app or an extension.
379
380### Blessed Extension Contexts
381
382The `blessed_extension` context refers to a JavaScript context running from an
383extension process. These are typically the most secure JavaScript contexts, as
384it reduces the likelihood that a compromised web page renderer will have access
385to secure APIs.
386
387Traditionally, only pages with a top-level extension frame (with a
388`chrome-extension://` scheme), extension popups, and app windows were blessed
389extension contexts. With [site isolation](https://www.chromium.org/developers/design-documents/site-isolation),
390extension frames running in web pages are also considered blessed extension
391contexts, since they are running in the extension process (rather than in the
392same process as the web page).
393
394### Blessed Web Page Contexts
395
396The `blessed_web_page` context refers to a JavaScript context running from a
397hosted app. These are similar to blessed extension contexts in that they are
398(partially) isolated from other processes, but are typically more restricted
399than blessed extension processes, since hosted apps generally have fewer
400permissions. Note that these contexts are unaffected by the `matches` property.
401
402### Content Script Contexts
403
404The `content_script` context refers to a JavaScript context for an extension
405content script. Since content scripts share a process with (and run on the same
406content as) web pages, these are considered very insecure contexts. Very few
407features should be exposed to these contexts.
408
409### Service Worker Contexts
410
411The `extension_service_worker` context refers to a JavaScript context for an
412extension's service worker. An extension can only register a service worker for
413it's own domain, and these should only be run within an extension process. Thus,
414these have similar privilege levels to blessed extension processes.
415
416### Web Page Contexts
417
418The `web_page` context refers to a JavaScript context for a simple web page,
419completely separate from extensions. This is the least secure of all contexts,
420and very few features should be exposed to these contexts. When specifying this
421context, an accompanying URL pattern should be provided with the `matches`
422property.
423
424### WebUI Contexts
425
426The `webui` context refers to a JavaScript context for a page with WebUI
427bindings, such as internal chrome pages like chrome://settings or
428chrome://extensions. These are considered secure contexts, since they are
429an internal part of chrome. When specifying this context, an accompanying URL
430pattern should be provided with the `matches` property.
431
432### Unblessed Extension Contexts
433
434The `unblessed_extension` context refers to a JavaScript context for an
435extension frame that is embedded in an external page, like a web page, and
436runs in the same process as the embedder. Given the limited separation between
437the (untrusted) embedder and the extension frame, relatively few features are
438exposed in these contexts. Note that with [site isolation](https://www.chromium.org/developers/design-documents/site-isolation),
439extension frames (even those embedded in web pages) run in the trusted
440extension process, and become blessed extension contexts.
441
rdevlin.cronin1d4585192016-08-22 22:34:28442## Compilation
443
444The feature files are compiled as part of the suite of tools in
445//tools/json\_schema\_compiler/. The output is a set of FeatureProviders that
446contain a mapping of all features.
447
448In addition to being significantly more performant than parsing the JSON files
449at runtime, this has the added benefit of allowing us to validate at compile
450time rather than needing a unittest (or allowing incorrect features).
451
452In theory, invalid features should result in a compilation failure; in practice,
453the compiler is probably missing some cases.
454
rdevlin.cronin8a23c0c2016-08-19 21:44:24455## Still to come
456
rdevlin.cronin06d4e582016-08-25 20:13:11457TODO(devlin): Add documentation for extension types. Probably also more on
458requirements for individual features.