blob: 257b3b2e5487822a36227fc9bcf1e25728274912 [file] [log] [blame] [view]
Rodney Dingafca3362019-11-01 20:07:341# Initialization of Blink runtime features in content layer
2This document outlines how to initialize your Blink runtime features in the
3Chromium content layer, more specifically in
4[content/child/runtime_features.cc][runtime_features]. To learn more on how to
5set up features in blink, see
6[Runtime Enabled Features][RuntimeEnabledFeatures].
7
8## Step 1: Do you need a custom Blink feature enabler function?
9If you simply need to enable/disable the Blink feature you can simply use
10[WebRuntimeFeatures::EnableFeatureFromString()][EnableFeatureFromString].
11
12However, if there are side effects (e.g. you need to disable other features if
13this feature is also disabled), you should declare a custom enabler function in
Kevin McNee92b18f732020-11-10 00:48:2814- [third_party/blink/public/platform/web_runtime_features.h][web_runtime_features.h]
15- [third_party/blink/renderer/platform/exported/web_runtime_features.cc][web_runtime_features.cc]
Rodney Dingafca3362019-11-01 20:07:3416
17## Step 2: Determine how your feature is initialized.
18### 1) Depends on OS-specific Macros:
19Add your code for controlling the Blink feature in
20[SetRuntimeFeatureDefaultsForPlatform()][SetRuntimeFeatureDefaultsForPlatform]
21using the appropriate OS macros.
22### 2) Depends on the status of a base::Feature:
23Add your code to the function
24[SetRuntimeFeaturesFromChromiumFeatures()][SetRuntimeFeaturesFromChromiumFeatures].
25
26If your Blink feature has a custom enabler function, add a new entry to
27`blinkFeatureToBaseFeatureMapping`. For example, a new entry like this:
28```
Xianzhu Wang05355f4a2020-09-02 01:22:1629{wf::EnableNewFeatureX, features::kNewFeatureX, kDefault},
Rodney Dingafca3362019-11-01 20:07:3430```
31will call `wf::EnableNewFeatureX` to enable it only if `features::kNewFeatureX`
Xianzhu Wang05355f4a2020-09-02 01:22:1632is enabled, or to set it to the same status as `features::kNewFeatureX` if its
33default status is overridden by any field trial or command line switch.
Rodney Dingafca3362019-11-01 20:07:3434
35If your Blink feature does not have a custom enabler function, you need to add
36the entry to `runtimeFeatureNameToChromiumFeatureMapping`. For example, a new
37entry like this:
38```
Xianzhu Wang05355f4a2020-09-02 01:22:1639{"NewFeatureY", features::kNewFeatureY, kDefault},
Rodney Dingafca3362019-11-01 20:07:3440```
Xianzhu Wang05355f4a2020-09-02 01:22:1641will call `wf::EnableFeatureFromString` with your feature name instead of
42`wf::EnableNewFeatureX` in the same cases as above.
43
44The following table summarizes the relationship between the default status of
45the Chromium feature and the status of the blink feature, when `kDefault` is
46specified, if **not overridden** by field trial or command line switches
47(horizontal headers: blink feature status; vertical headers: chromium feature
48default status):
49
50| |No status|`status:"test"`|`status:"experimental"`|`status:"stable"`|
Charlie Harrison1daccc92021-11-05 15:21:1751|---|---------|-----------------|--------------------------|-------------------|
Xianzhu Wang05355f4a2020-09-02 01:22:1652|`FEATURE_DISABLED_BY_DEFAULT`|Disabled everywhere|Blink feature is enabled for tests, or everywhere with `--enable-blink-test-features` [1]|Blink feature is enabled for tests, or everywhere with `--enable-experimental-web-platform-features` [1]|Blink feature is enabled everywhere [2]|
53|`FEATURE_ENABLED_BY_DEFAULT`|Enabled everywhere|Enabled everywhere|Enabled everywhere|Enabled everywhere|
54
55\[1]: `base::FeatureList::IsEnabled(features::kNewFeatureX)` is still
56false. These combinations are suitable for features there are fully implemented
57at blink side. Otherwise normally the blink feature should not have a status so
Quinten Yearsley317532d2021-10-20 17:10:3158that the Chromium feature can fully control the feature.
Xianzhu Wang05355f4a2020-09-02 01:22:1659
60\[2]: This combination is counter-intuitive and should be avoided.
61
62Field trial and command line switches can always override the Chromium feature
63status and the blink feature status.
64
65Besides `kDefault`, there are also other options for the relationship
66between the Chromium feature and the blink feature. These other options should
67only be used in rare cases when the default relationship doesn't work.
Rodney Dingafca3362019-11-01 20:07:3468
69For more detailed explanation on the options you have, read the comment in enum
70[RuntimeFeatureEnableOptions][EnableOptions].
71### 3) Set by a command line switch to enable or disable:
72Add your code to the function
73[SetRuntimeFeaturesFromCommandLine()][SetRuntimeFeaturesFromCommandLine].
74
75If your Blink feature has a custom enabler function, add a new entry to
76`switchToFeatureMapping`. For example, a new entry like this:
77```
78{wrf::EnableNewFeatureX, switches::kNewFeatureX, false},
79```
80will call `wf::EnableNewFeatureX` to disable it only if that
81`switches::kNewFeatureX` exists on the command line.
82
Ming-Ying Chungc23505d62022-09-22 10:07:3383### 4) Combination of the previous options or not covered:
Rodney Dingafca3362019-11-01 20:07:3484For example, you Blink feature could be controlled by both a base::Feature and a
85command line switch. In this case, your custom logic should live here in
86[`SetCustomizedRuntimeFeaturesFromCombinedArgs()`][SetCustomizedRuntimeFeaturesFromCombinedArgs].
87
88
89[EnableOptions]:<https://chromium.googlesource.com/chromium/src/+/HEAD/content/child/runtime_features.cc#135>
90[runtime_features]:<https://chromium.googlesource.com/chromium/src/+/HEAD/content/child/runtime_features.cc>
91[RuntimeEnabledFeatures]:
92<https://chromium.googlesource.com/chromium/src/+/HEAD/third_party/blink/renderer/platform/RuntimeEnabledFeatures.md>
Kevin McNee92b18f732020-11-10 00:48:2893[web_runtime_features.h]:
94<https://chromium.googlesource.com/chromium/src/+/HEAD/third_party/blink/public/platform/web_runtime_features.h>
95[web_runtime_features.cc]:
Rodney Dingafca3362019-11-01 20:07:3496<https://chromium.googlesource.com/chromium/src/+/HEAD/third_party/blink/renderer/platform/exported/web_runtime_features.cc>
97[EnableFeatureFromString]:<https://chromium.googlesource.com/chromium/src/+/HEAD/third_party/blink/public/platform/web_runtime_features.h#56>
98[SetRuntimeFeatureDefaultsForPlatform]:<https://chromium.googlesource.com/chromium/src/+/HEAD/content/child/runtime_features.cc#46>
99[SetCustomizedRuntimeFeaturesFromCombinedArgs]:<https://chromium.googlesource.com/chromium/src/+/HEAD/content/child/runtime_features.cc#487>
100[SetRuntimeFeaturesFromChromiumFeatures]:<https://chromium.googlesource.com/chromium/src/+/HEAD/content/child/runtime_features.cc#160>
101[SetRuntimeFeaturesFromCommandLine]:<https://chromium.googlesource.com/chromium/src/+/HEAD/content/child/runtime_features.cc#390>
Ming-Ying Chungc23505d62022-09-22 10:07:33102[SetRuntimeFeaturesFromFieldTrialParams]:<https://chromium.googlesource.com/chromium/src/+/HEAD/content/child/runtime_features.cc#448>