Commit ec77e5b2 authored by Rodney Ding's avatar Rodney Ding Committed by Commit Bot

Refactor setting of blink runtime flags from content: Part 2

- Use a mapping between runtime feature and command line switch
  to control the enable/disable logic for cleaner code

Design docs: https://docs.google.com/document/d/1d6_NBVPXh7B2XMk3H9b_qIxeuSXq6MblVSJldN7bTBY/edit?usp=sharing

Bug: 832393
Change-Id: I67c944e1d20d5c0d9ab871f87641cb6ea46fb8ff
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1822864
Commit-Queue: Rodney Ding <rodneyding@google.com>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarJason Chase <chasej@chromium.org>
Cr-Commit-Position: refs/heads/master@{#705952}
parent 97c70cb3
...@@ -48,6 +48,9 @@ void SetRuntimeFeatureDefaultsForPlatform( ...@@ -48,6 +48,9 @@ void SetRuntimeFeatureDefaultsForPlatform(
const base::CommandLine& command_line) { const base::CommandLine& command_line) {
// Please consider setting up feature defaults for different platforms // Please consider setting up feature defaults for different platforms
// in runtime_enabled_features.json5 instead of here // in runtime_enabled_features.json5 instead of here
// TODO(rodneyding): Move the more common cases here
// to baseFeature/switch functions below and move more complex
// ones to special case functions.
#if defined(USE_AURA) #if defined(USE_AURA)
WebRuntimeFeatures::EnableCompositedSelectionUpdate(true); WebRuntimeFeatures::EnableCompositedSelectionUpdate(true);
#endif #endif
...@@ -438,83 +441,75 @@ void SetRuntimeFeaturesFromChromiumFeatures() { ...@@ -438,83 +441,75 @@ void SetRuntimeFeaturesFromChromiumFeatures() {
base::FeatureList::IsEnabled(features::kDocumentPolicy)); base::FeatureList::IsEnabled(features::kDocumentPolicy));
} }
// Helper class that describes the desired enable/disable action
// for a runtime feature when a command line switch exists.
struct SwitchToFeatureMap {
// The enabler function defined in web_runtime_features.cc.
void (*feature_enabler)(bool);
// The switch to check for on command line.
const char* switch_name;
// This is the desired state for the runtime feature if the
// switch exists on command line.
bool target_enabled_state;
};
// Sets blink runtime features controlled by command line switches. // Sets blink runtime features controlled by command line switches.
void SetRuntimeFeaturesFromCommandLine(const base::CommandLine& command_line) { void SetRuntimeFeaturesFromCommandLine(const base::CommandLine& command_line) {
if (command_line.HasSwitch(switches::kDisableDatabases)) // To add a new switch-controlled runtime feature, add a new
WebRuntimeFeatures::EnableDatabase(false); // SwitchToFeatureMap entry to the initializer list below.
// Note: command line switches are now discouraged, please consider
if (command_line.HasSwitch(switches::kDisableNotifications)) { // using base::Feature instead.
WebRuntimeFeatures::EnableNotifications(false); // https://chromium.googlesource.com/chromium/src/+/refs/heads/master/docs/configuration.md#switches
using wrf = WebRuntimeFeatures;
// Chrome's Push Messaging implementation relies on Web Notifications. const SwitchToFeatureMap switchToFeatureMapping[] = {
WebRuntimeFeatures::EnablePushMessaging(false); // Stable Features
} {wrf::EnablePermissionsAPI, switches::kDisablePermissionsAPI, false},
{wrf::EnablePresentationAPI, switches::kDisablePresentationAPI, false},
if (command_line.HasSwitch(switches::kDisableSharedWorkers)) {wrf::EnableRemotePlaybackAPI, switches::kDisableRemotePlaybackAPI,
WebRuntimeFeatures::EnableSharedWorker(false); false},
{wrf::EnableTimerThrottlingForBackgroundTabs,
if (command_line.HasSwitch(switches::kDisableSpeechAPI)) { switches::kDisableBackgroundTimerThrottling, false},
WebRuntimeFeatures::EnableScriptedSpeechRecognition(false); // End of Stable Features
WebRuntimeFeatures::EnableScriptedSpeechSynthesis(false); {wrf::EnableDatabase, switches::kDisableDatabases, false},
} {wrf::EnableNotifications, switches::kDisableNotifications, false},
// Chrome's Push Messaging implementation relies on Web Notifications.
if (command_line.HasSwitch(switches::kDisableSpeechSynthesisAPI)) { {wrf::EnablePushMessaging, switches::kDisableNotifications, false},
WebRuntimeFeatures::EnableScriptedSpeechSynthesis(false); {wrf::EnableSharedWorker, switches::kDisableSharedWorkers, false},
{wrf::EnableScriptedSpeechRecognition, switches::kDisableSpeechAPI,
false},
{wrf::EnableScriptedSpeechSynthesis, switches::kDisableSpeechAPI, false},
{wrf::EnableScriptedSpeechSynthesis, switches::kDisableSpeechSynthesisAPI,
false},
{wrf::EnableFileSystem, switches::kDisableFileSystem, false},
{wrf::EnableWebGLDraftExtensions, switches::kEnableWebGLDraftExtensions,
true},
{wrf::EnableAutomationControlled, switches::kEnableAutomation, true},
{wrf::EnableAutomationControlled, switches::kHeadless, true},
{wrf::EnableAutomationControlled, switches::kRemoteDebuggingPipe, true},
{wrf::EnableAutomationControlled, switches::kRemoteDebuggingPort, true},
{wrf::ForceOverlayFullscreenVideo, switches::kForceOverlayFullscreenVideo,
true},
{wrf::EnablePreciseMemoryInfo, switches::kEnablePreciseMemoryInfo, true},
{wrf::EnablePrintBrowser, switches::kEnablePrintBrowser, true},
{wrf::EnableNetInfoDownlinkMax,
switches::kEnableNetworkInformationDownlinkMax, true},
{wrf::EnablePermissionsAPI, switches::kDisablePermissionsAPI, false},
{wrf::EnableWebGPU, switches::kEnableUnsafeWebGPU, true},
{wrf::EnableWebVR, switches::kEnableWebVR, true},
{wrf::EnablePresentationAPI, switches::kDisablePresentationAPI, false},
{wrf::EnableRemotePlaybackAPI, switches::kDisableRemotePlaybackAPI,
false},
{wrf::EnableTimerThrottlingForBackgroundTabs,
switches::kDisableBackgroundTimerThrottling, false},
{wrf::EnableAccessibilityObjectModel,
switches::kEnableAccessibilityObjectModel, true},
{wrf::EnableAllowSyncXHRInPageDismissal,
switches::kAllowSyncXHRInPageDismissal, true},
};
for (const auto& mapping : switchToFeatureMapping) {
if (command_line.HasSwitch(mapping.switch_name))
mapping.feature_enabler(mapping.target_enabled_state);
} }
if (command_line.HasSwitch(switches::kDisableFileSystem))
WebRuntimeFeatures::EnableFileSystem(false);
if (command_line.HasSwitch(switches::kEnableWebGLDraftExtensions))
WebRuntimeFeatures::EnableWebGLDraftExtensions(true);
if (command_line.HasSwitch(switches::kEnableAutomation) ||
command_line.HasSwitch(switches::kHeadless) ||
command_line.HasSwitch(switches::kRemoteDebuggingPipe) ||
command_line.HasSwitch(switches::kRemoteDebuggingPort)) {
WebRuntimeFeatures::EnableAutomationControlled(true);
}
if (command_line.HasSwitch(switches::kForceOverlayFullscreenVideo))
WebRuntimeFeatures::ForceOverlayFullscreenVideo(true);
if (command_line.HasSwitch(switches::kEnablePreciseMemoryInfo))
WebRuntimeFeatures::EnablePreciseMemoryInfo(true);
if (command_line.HasSwitch(switches::kEnablePrintBrowser))
WebRuntimeFeatures::EnablePrintBrowser(true);
if (command_line.HasSwitch(switches::kEnableNetworkInformationDownlinkMax))
WebRuntimeFeatures::EnableNetInfoDownlinkMax(true);
if (command_line.HasSwitch(switches::kDisablePermissionsAPI))
WebRuntimeFeatures::EnablePermissionsAPI(false);
if (command_line.HasSwitch(switches::kDisableV8IdleTasks))
WebRuntimeFeatures::EnableV8IdleTasks(false);
else
WebRuntimeFeatures::EnableV8IdleTasks(true);
if (command_line.HasSwitch(switches::kEnableUnsafeWebGPU))
WebRuntimeFeatures::EnableWebGPU(true);
if (command_line.HasSwitch(switches::kEnableWebVR))
WebRuntimeFeatures::EnableWebVR(true);
if (command_line.HasSwitch(switches::kDisablePresentationAPI))
WebRuntimeFeatures::EnablePresentationAPI(false);
if (command_line.HasSwitch(switches::kDisableRemotePlaybackAPI))
WebRuntimeFeatures::EnableRemotePlaybackAPI(false);
if (command_line.HasSwitch(switches::kDisableBackgroundTimerThrottling))
WebRuntimeFeatures::EnableTimerThrottlingForBackgroundTabs(false);
if (command_line.HasSwitch(switches::kEnableAccessibilityObjectModel))
WebRuntimeFeatures::EnableAccessibilityObjectModel(true);
if (command_line.HasSwitch(switches::kAllowSyncXHRInPageDismissal))
WebRuntimeFeatures::EnableAllowSyncXHRInPageDismissal(true);
} }
// Sets blink runtime features controlled by FieldTrial parameter values. // Sets blink runtime features controlled by FieldTrial parameter values.
...@@ -592,6 +587,11 @@ void SetCustomizedRuntimeFeaturesFromCombinedArgs( ...@@ -592,6 +587,11 @@ void SetCustomizedRuntimeFeaturesFromCombinedArgs(
WebRuntimeFeatures::EnableFeatureFromString("FileHandling", true); WebRuntimeFeatures::EnableFeatureFromString("FileHandling", true);
} }
if (command_line.HasSwitch(switches::kDisableV8IdleTasks))
WebRuntimeFeatures::EnableV8IdleTasks(false);
else
WebRuntimeFeatures::EnableV8IdleTasks(true);
// This is a hack to get the tests passing as they require // This is a hack to get the tests passing as they require
// these blink features to be enabled while they are disabled // these blink features to be enabled while they are disabled
// by base::Feature controls earlier in code. // by base::Feature controls earlier in code.
...@@ -627,6 +627,9 @@ void SetRuntimeFeaturesDefaultsAndUpdateFromArgs( ...@@ -627,6 +627,9 @@ void SetRuntimeFeaturesDefaultsAndUpdateFromArgs(
WebRuntimeFeatures::EnableOriginTrialControlledFeatures(false); WebRuntimeFeatures::EnableOriginTrialControlledFeatures(false);
} }
// TODO(rodneyding): add doc explaining ways to add new runtime features
// controls in the following functions.
SetRuntimeFeaturesFromChromiumFeatures(); SetRuntimeFeaturesFromChromiumFeatures();
SetRuntimeFeaturesFromCommandLine(command_line); SetRuntimeFeaturesFromCommandLine(command_line);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment