Commit 907fd3ab authored by Emircan Uysaler's avatar Emircan Uysaler Committed by Commit Bot

[Fuchsia] Allow adding features via config

This CL adds functionality to allow adding kEnableFeatures and
kDisableFeatures via config. Earlier there was a bug as adding
multiple feature sections to command line didn't work, so this CL
makes sure we serialize them in one switch.

Bug: 1026011
Change-Id: I6ba08023be8520119cc724300c306558e12e26e0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2006073
Commit-Queue: Emircan Uysaler <emircan@chromium.org>
Reviewed-by: default avatarWez <wez@chromium.org>
Reviewed-by: default avatarSergey Ulanov <sergeyu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#733798}
parent cf8adc47
......@@ -127,6 +127,23 @@ base::Value LoadConfig() {
return std::move(*config);
}
void AppendFeature(base::StringPiece features_flag,
base::StringPiece feature_string,
base::CommandLine* command_line) {
if (!command_line->HasSwitch(features_flag)) {
command_line->AppendSwitchNative(features_flag.as_string(),
feature_string.as_string());
return;
}
std::string new_feature_string =
command_line->GetSwitchValueASCII(features_flag);
new_feature_string.append(",").append(feature_string.as_string());
command_line->RemoveSwitch(features_flag);
command_line->AppendSwitchNative(features_flag.as_string(),
new_feature_string);
}
// Returns false if the config is present but has invalid contents.
bool MaybeAddCommandLineArgsFromConfig(const base::Value& config,
base::CommandLine* command_line) {
......@@ -135,6 +152,7 @@ bool MaybeAddCommandLineArgsFromConfig(const base::Value& config,
return true;
static const base::StringPiece kAllowedArgs[] = {
switches::kDisableFeatures,
switches::kDisableGpuWatchdog,
switches::kEnableFeatures,
switches::kEnableFuchsiaAudioConsumer,
......@@ -156,6 +174,8 @@ bool MaybeAddCommandLineArgsFromConfig(const base::Value& config,
LOG(ERROR) << "Config command-line arg must be a string: " << arg.first;
return false;
}
DCHECK(!command_line->HasSwitch(arg.first));
command_line->AppendSwitchNative(arg.first, arg.second.GetString());
// TODO(https://crbug.com/1023012): enable-low-end-device-mode currently
......@@ -260,6 +280,13 @@ void ContextProviderImpl::Create(
base::CommandLine launch_command = *base::CommandLine::ForCurrentProcess();
std::vector<zx::channel> devtools_listener_channels;
base::Value web_engine_config =
config_for_test_.is_none() ? LoadConfig() : std::move(config_for_test_);
if (!MaybeAddCommandLineArgsFromConfig(web_engine_config, &launch_command)) {
context_request.Close(ZX_ERR_INTERNAL);
return;
}
if (params.has_remote_debugging_port()) {
launch_command.AppendSwitchNative(
switches::kRemoteDebuggingPort,
......@@ -332,8 +359,8 @@ void ContextProviderImpl::Create(
launch_command.AppendSwitch(switches::kUseVulkan);
const std::vector<base::StringPiece> enabled_features = {
features::kUseSkiaRenderer.name, features::kVulkan.name};
launch_command.AppendSwitchASCII(switches::kEnableFeatures,
base::JoinString(enabled_features, ","));
AppendFeature(switches::kEnableFeatures,
base::JoinString(enabled_features, ","), &launch_command);
// SkiaRenderer requires out-of-process rasterization be enabled.
launch_command.AppendSwitch(switches::kEnableOopRasterization);
......@@ -350,9 +377,6 @@ void ContextProviderImpl::Create(
launch_command.AppendSwitch(switches::kDisableSoftwareRasterizer);
}
base::Value web_engine_config =
config_for_test_.is_none() ? LoadConfig() : std::move(config_for_test_);
bool allow_protected_graphics =
web_engine_config.FindBoolPath("allow-protected-graphics")
.value_or(false);
......@@ -411,11 +435,6 @@ void ContextProviderImpl::Create(
launch_command.AppendSwitch(switches::kDisableSoftwareVideoDecoders);
}
if (!MaybeAddCommandLineArgsFromConfig(web_engine_config, &launch_command)) {
context_request.Close(ZX_ERR_INTERNAL);
return;
}
// Validate embedder-supplied product, and optional version, and pass it to
// the Context to include in the UserAgent.
if (params.has_user_agent_product()) {
......@@ -463,8 +482,8 @@ void ContextProviderImpl::Create(
// TODO(crbug.com/1039788): Re-enable OutOfBlinkCors when custom HTTP header
// preflight validation errors are fixed.
launch_command.AppendSwitchASCII("disable-features",
network::features::kOutOfBlinkCors.name);
AppendFeature(switches::kDisableFeatures,
network::features::kOutOfBlinkCors.name, &launch_command);
if (launch_for_test_)
launch_for_test_.Run(launch_command, launch_options);
......
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