blob: 16140d2eb6700f1b2228dd24b92388045aa6d93d [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
14- [third_party/blink/public/platform/web_runtime_features.h][WebRuntimeFeatures.h]
15- [third_party/blink/public/platform/web_runtime_features.cc][WebRuntimeFeatures.cc]
16
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```
29{wf::EnableNewFeatureX, features::kNewFeatureX, kEnableOnly},
30```
31will call `wf::EnableNewFeatureX` to enable it only if `features::kNewFeatureX`
32is enabled.
33
34If your Blink feature does not have a custom enabler function, you need to add
35the entry to `runtimeFeatureNameToChromiumFeatureMapping`. For example, a new
36entry like this:
37```
38{"NewFeatureY", features::kNewFeatureY, kUseFeatureState},
39```
40will call `wf::EnableFeatureFromString` with your feature name to set it to
41whichever state your `features::kNewFeatureY` is in.
42
43For more detailed explanation on the options you have, read the comment in enum
44[RuntimeFeatureEnableOptions][EnableOptions].
45### 3) Set by a command line switch to enable or disable:
46Add your code to the function
47[SetRuntimeFeaturesFromCommandLine()][SetRuntimeFeaturesFromCommandLine].
48
49If your Blink feature has a custom enabler function, add a new entry to
50`switchToFeatureMapping`. For example, a new entry like this:
51```
52{wrf::EnableNewFeatureX, switches::kNewFeatureX, false},
53```
54will call `wf::EnableNewFeatureX` to disable it only if that
55`switches::kNewFeatureX` exists on the command line.
56
57### 4) Controlled by parameters from a field trial:
58Add your code to the function
59[SetRuntimeFeaturesFromFieldTrialParams()][SetRuntimeFeaturesFromFieldTrialParams].
60
61### 5) Combination of the previous options or not covered:
62For example, you Blink feature could be controlled by both a base::Feature and a
63command line switch. In this case, your custom logic should live here in
64[`SetCustomizedRuntimeFeaturesFromCombinedArgs()`][SetCustomizedRuntimeFeaturesFromCombinedArgs].
65
66
67[EnableOptions]:<https://chromium.googlesource.com/chromium/src/+/HEAD/content/child/runtime_features.cc#135>
68[runtime_features]:<https://chromium.googlesource.com/chromium/src/+/HEAD/content/child/runtime_features.cc>
69[RuntimeEnabledFeatures]:
70<https://chromium.googlesource.com/chromium/src/+/HEAD/third_party/blink/renderer/platform/RuntimeEnabledFeatures.md>
71[WebRuntimeFeatures.h]:
72<https://chromium.googlesource.com/chromium/src/+/HEAD/third_party/blink/renderer/platform/exported/web_runtime_features.h>
73[WebRuntimeFeatures.cc]:
74<https://chromium.googlesource.com/chromium/src/+/HEAD/third_party/blink/renderer/platform/exported/web_runtime_features.cc>
75[EnableFeatureFromString]:<https://chromium.googlesource.com/chromium/src/+/HEAD/third_party/blink/public/platform/web_runtime_features.h#56>
76[SetRuntimeFeatureDefaultsForPlatform]:<https://chromium.googlesource.com/chromium/src/+/HEAD/content/child/runtime_features.cc#46>
77[SetCustomizedRuntimeFeaturesFromCombinedArgs]:<https://chromium.googlesource.com/chromium/src/+/HEAD/content/child/runtime_features.cc#487>
78[SetRuntimeFeaturesFromChromiumFeatures]:<https://chromium.googlesource.com/chromium/src/+/HEAD/content/child/runtime_features.cc#160>
79[SetRuntimeFeaturesFromCommandLine]:<https://chromium.googlesource.com/chromium/src/+/HEAD/content/child/runtime_features.cc#390>
80[SetRuntimeFeaturesFromFieldTrialParams]:<https://chromium.googlesource.com/chromium/src/+/HEAD/content/child/runtime_features.cc#448>