| OLD | NEW |
| (Empty) | |
| 1 # Extension Features Files |
| 2 |
| 3 [TOC] |
| 4 |
| 5 ## Summary |
| 6 |
| 7 The Extension features files specify the different requirements for extension |
| 8 feature availability. |
| 9 |
| 10 An **extension feature** can be any component of extension capabilities. Most |
| 11 notably, this includes extension APIs, but there are also more structural or |
| 12 behavioral features, such as web accessible resources or event pages. |
| 13 |
| 14 ## Files |
| 15 |
| 16 There are four different feature files used: |
| 17 * [\_api\_features](https://chromium.googlesource.com/chromium/src/+/master/chro
me/common/extensions/api/_api_features.json): |
| 18 Specifies the requirements for API availability. If an extension doesn't satisfy |
| 19 the requirements, the API will not be accessible in the extension's code. |
| 20 * [\_permission\_features](https://chromium.googlesource.com/chromium/src/+/mast
er/chrome/common/extensions/api/_permission_features.json): |
| 21 Specifies the requirements for permission availability. If an extension doesn't |
| 22 satisfy the requirements, the permission will not be granted and the extension |
| 23 will have an install warning. |
| 24 * [\_manifest\_features](https://chromium.googlesource.com/chromium/src/+/master
/chrome/common/extensions/api/_manifest_features.json): |
| 25 Specifies the requirements for manifest entry availability. If an extension |
| 26 doesn'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): |
| 28 Specifies the requirements for miscellaneous extension behaviors. This should |
| 29 typically not be used. |
| 30 |
| 31 Note that these files may be present under chrome/common/extensions/api, as well |
| 32 as under extensions/common/api and extensions/shell/common/api. |
| 33 |
| 34 ## Grammar |
| 35 |
| 36 The feature files are written in JSON. Each file contains a single JSON object |
| 37 with properties for each feature. |
| 38 |
| 39 ``` |
| 40 { |
| 41 "feature1": <definition>, |
| 42 "feature2": <definition>, |
| 43 ... |
| 44 } |
| 45 ``` |
| 46 |
| 47 ### Simple and Complex Features |
| 48 |
| 49 Most features are known as "simple" features. These are features whose |
| 50 definition is a single object that contains the properties describing the |
| 51 criteria 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 |
| 59 permission must be present and it must be executed from a blessed context. |
| 60 (These concepts are covered more later in this document.) |
| 61 |
| 62 Features can also be "complex". A complex feature has a list of objects to |
| 63 specify multiple groups of possible properties. A complex feature could look |
| 64 like 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 |
| 75 With complex features, if either of the definitions are matched, the feature |
| 76 is available (in other words, the feature definitions are logically OR'd |
| 77 together). Complex features should frequently be avoided, as it makes the |
| 78 logic more involved and slower. |
| 79 |
| 80 ### Inheritance |
| 81 |
| 82 By default, features inherit from parents. A feature's ancestry is specified by |
| 83 its name, where a child feature is the parent's name followed by a '.' and the |
| 84 child's name. That is, `feature1.child` is the child of `feature1`. Inheritance |
| 85 can carry for multiple levels (e.g. `feature1.child.child`), but this is rarely |
| 86 (if ever) useful. |
| 87 |
| 88 A child feature inherits all the properties of its parent, but can choose to |
| 89 override 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 |
| 101 In 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 |
| 108 If you don't want a child to inherit any features from the parent, add the |
| 109 property `"noparent": true`. This is useful if, for instance, you have a |
| 110 prefixed API name that isn't dependent on the prefix, such as app.window |
| 111 (which is fully separate from the app API). |
| 112 |
| 113 If the parent of a feature is a complex feature, the feature system needs to |
| 114 know which parent to inherit from. To do this, add the property |
| 115 `"default_parent": true` to one of the feature definitions in the parent |
| 116 feature. |
| 117 |
| 118 ## Properties |
| 119 |
| 120 The following properties are supported in the feature system. |
| 121 |
| 122 ### blacklist |
| 123 |
| 124 The `blacklist` property specifies a list of ID hashes for extensions that |
| 125 cannot access a feature. See _api_features.json for how to generate these |
| 126 hashes. |
| 127 |
| 128 Accepted values are lists of id hashes. |
| 129 |
| 130 ### channel |
| 131 |
| 132 The `channel` property specifies a maximum channel for the feature availability. |
| 133 That is, specifying `dev` means that the feature is available on `dev`, |
| 134 `canary`, and `trunk`. |
| 135 |
| 136 Accepted values are a single string from `trunk`, `canary`, `dev`, `beta`, and |
| 137 `stable`. |
| 138 |
| 139 ### command\_line\_switch |
| 140 |
| 141 The `command_line_switch` property specifies a command line switch that must be |
| 142 present for the feature to be available. |
| 143 |
| 144 Accepted values are a single string for the command line switch (without the |
| 145 preceeding '--'). |
| 146 |
| 147 ### component\_extensions\_auto\_granted |
| 148 |
| 149 The `component_extensions_auto_granted` specifies whether or not component |
| 150 extensions should be automatically granted access to the feature. By default, |
| 151 this is `true`. |
| 152 |
| 153 The only accepted value is the bool `false` (since true is the default). |
| 154 |
| 155 ### contexts |
| 156 |
| 157 The `contexts` property specifies which JavaScript contexts can access the |
| 158 feature. All API features must specify at least one context, and only API |
| 159 features can specify contexts. |
| 160 |
| 161 Accepted values are a list of strings from `blessed_extension`, |
| 162 `blessed_web_page`, `content_script`, `extension_service_worker`, |
| 163 `web_page`, `webui`, and `unblessed_extension`. |
| 164 |
| 165 ### default\_parent |
| 166 |
| 167 The `default_parent` property specifies a feature definition from a complex |
| 168 feature to be used as the parent for any children. See also Inheritance. |
| 169 |
| 170 The only accepted value is the bool `true`. |
| 171 |
| 172 ### dependencies |
| 173 |
| 174 The `dependencies` property specifies which other features must be present in |
| 175 order to access this feature. This is useful so that you don't have to |
| 176 re-specify all the same properties on an API feature and a permission feature. |
| 177 |
| 178 A common practice is to put as many restrictions as possible in the |
| 179 permission or manifest feature so that we warn at extension load, and put |
| 180 relatively limited properties in an API feature with a dependency on the |
| 181 manifest or permission feature. |
| 182 |
| 183 To specify a dependent feature, use the prefix the feature name with the type |
| 184 of feature it is, followed by a colon. For example, in order to specify a |
| 185 dependency on a permission feature `foo`, we would add the dependency entry |
| 186 `permission:foo`. |
| 187 |
| 188 Accepted values are lists of strings specifying the dependent features. |
| 189 |
| 190 ### extension\_types |
| 191 |
| 192 The `extension_types` properties specifies the different classes of extensions |
| 193 that can use the feature. It is very common for certain features to only be |
| 194 allowed in certain extension classes, rather than available to all types. |
| 195 |
| 196 Accepted values are lists of strings from `extension`, `hosted_app`, |
| 197 `legacy_packaged_app`, `platform_app`, `shared_module`, and `theme`. |
| 198 |
| 199 ### location |
| 200 |
| 201 The `location` property specifies the required install location of the |
| 202 extension. |
| 203 |
| 204 Accepted values are a single string from `component`, `external_component`, and |
| 205 `policy`. |
| 206 |
| 207 ### internal |
| 208 |
| 209 The `internal` property specifies whether or not a feature is considered |
| 210 internal to Chromium. Internal features are not exposed to extensions, and can |
| 211 only be used from Chromium code. |
| 212 |
| 213 The only accepted value is the bool `true`. |
| 214 |
| 215 ### matches |
| 216 |
| 217 The `matches` property specifies url patterns which should be allowed to access |
| 218 the feature. Only API features may specify `matches`, and `matches` only make |
| 219 sense with a context of either `webui` or `web_page`. |
| 220 |
| 221 Accepted values are a list of strings specifying the match patterns. |
| 222 |
| 223 ### max\_manifest\_version |
| 224 |
| 225 The `max_manifest_version` property specifies the maximum manifest version to be |
| 226 allowed to access a feature. Extensions with a greater manifest version cannot |
| 227 access the feature. |
| 228 |
| 229 The only accepted value is `1`, as currently the highest possible manifest |
| 230 version is `2`. |
| 231 |
| 232 ### min\_manifest\_version |
| 233 |
| 234 The `min_manifest_version` property specifies the minimum manifest version to be |
| 235 allowed to access a feature. Extensions with a lesser manifest version cannot |
| 236 access the feature. |
| 237 |
| 238 The only accepted value is `2`, as this is currently the highest possible |
| 239 manifest version. |
| 240 |
| 241 ### noparent |
| 242 |
| 243 The `noparent` property specifies that a feature should not inherit any |
| 244 properties from a derived parent. See also Inheritance. |
| 245 |
| 246 The only accepted value is the bool `true`. |
| 247 |
| 248 ### platforms |
| 249 |
| 250 The `platforms` property specifies the properties the feature should be |
| 251 available on. |
| 252 |
| 253 The accepted values are lists of strings from `chromeos`, `mac`, `linux`, and |
| 254 `win`. |
| 255 |
| 256 ### whitelist |
| 257 |
| 258 The `whitelist` property specifies a list of ID hashes for extensions that |
| 259 are the only extensions allowed to access a feature. |
| 260 |
| 261 Accepted values are lists of id hashes. |
| 262 |
| 263 ## Still to come |
| 264 |
| 265 TODO(devlin): Move documentation for how to create ID hashes, possibly move |
| 266 documentation for feature contexts, add documentation for extension types, and |
| 267 add documentation for the compilation process. Probably also more on |
| 268 requirements for individual features. |
| OLD | NEW |