This document outlines how to initialize your Blink runtime features in the Chromium content layer, more specifically in content/child/runtime_features.cc. To learn more on how to set up features in blink, see Runtime Enabled Features.
If you simply need to enable/disable the Blink feature you can simply use WebRuntimeFeatures::EnableFeatureFromString().
However, if there are side effects (e.g. you need to disable other features if this feature is also disabled), you should declare a custom enabler function in
- third_party/blink/public/platform/web_runtime_features.h
- third_party/blink/public/platform/web_runtime_features.cc
Add your code for controlling the Blink feature in SetRuntimeFeatureDefaultsForPlatform() using the appropriate OS macros.
Add your code to the function SetRuntimeFeaturesFromChromiumFeatures().
If your Blink feature has a custom enabler function, add a new entry to
blinkFeatureToBaseFeatureMapping
. For example, a new entry like this:
{wf::EnableNewFeatureX, features::kNewFeatureX, kEnableOnly},
will call wf::EnableNewFeatureX
to enable it only if features::kNewFeatureX
is enabled.
If your Blink feature does not have a custom enabler function, you need to add
the entry to runtimeFeatureNameToChromiumFeatureMapping
. For example, a new
entry like this:
{"NewFeatureY", features::kNewFeatureY, kUseFeatureState},
will call wf::EnableFeatureFromString
with your feature name to set it to
whichever state your features::kNewFeatureY
is in.
For more detailed explanation on the options you have, read the comment in enum RuntimeFeatureEnableOptions.
Add your code to the function SetRuntimeFeaturesFromCommandLine().
If your Blink feature has a custom enabler function, add a new entry to
switchToFeatureMapping
. For example, a new entry like this:
{wrf::EnableNewFeatureX, switches::kNewFeatureX, false},
will call wf::EnableNewFeatureX
to disable it only if that
switches::kNewFeatureX
exists on the command line.
Add your code to the function SetRuntimeFeaturesFromFieldTrialParams().
For example, you Blink feature could be controlled by both a base::Feature and a
command line switch. In this case, your custom logic should live here in
SetCustomizedRuntimeFeaturesFromCombinedArgs()
.