From b08df88b7c48c32131cbf198105266b7fd4d73d6 Mon Sep 17 00:00:00 2001 From: "trop[bot]" Date: Thu, 26 Jul 2018 08:29:08 -0700 Subject: [PATCH] fix: Use --enable-features and --disable-features (#13805) Unlike Chrome, we were not using the --enable-features and --disable-features command-line arguments to initialize `base::FeatureList`. --- brightray/brightray.gyp | 2 ++ brightray/browser/browser_main_parts.cc | 36 +++++++++++++++++++++---- brightray/browser/browser_main_parts.h | 3 +++ 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 312255cffc12..f233257e88ba 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -111,6 +111,7 @@ 'link_settings': { 'libraries': [ # Following libraries are always linked statically. + '<(libchromiumcontent_dir)/libbase_static.a', '<(libchromiumcontent_dir)/libgtkui.a', '<(libchromiumcontent_dir)/libhttp_server.a', '<(libchromiumcontent_dir)/libdevice_service.a', @@ -204,6 +205,7 @@ 'link_settings': { 'libraries': [ # Following libraries are always linked statically. + '<(libchromiumcontent_dir)/libbase_static.a', '<(libchromiumcontent_dir)/libhttp_server.a', '<(libchromiumcontent_dir)/libdevice_service.a', '<(libchromiumcontent_dir)/libdom_keycode_converter.a', diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index d44ace2dc330..9349a95ea222 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -15,6 +15,7 @@ #include // for g_setenv() #endif +#include "base/base_switches.h" #include "base/command_line.h" #include "base/feature_list.h" #include "base/message_loop/message_loop.h" @@ -178,14 +179,29 @@ void OverrideAppLogsPath() { } #endif -int BrowserMainParts::PreEarlyInitialization() { - std::unique_ptr feature_list(new base::FeatureList); +void BrowserMainParts::InitializeFeatureList() { + auto* cmd_line = base::CommandLine::ForCurrentProcess(); + const auto enable_features = + cmd_line->GetSwitchValueASCII(switches::kEnableFeatures); + auto disable_features = + cmd_line->GetSwitchValueASCII(switches::kDisableFeatures); + // TODO(deepak1556): Disable guest webcontents based on OOPIF feature. // Disable surface synchronization and async wheel events to make OSR work. - feature_list->InitializeFromCommandLine( - "", - "GuestViewCrossProcessFrames,SurfaceSynchronization,AsyncWheelEvents"); + disable_features += + ",GuestViewCrossProcessFrames,SurfaceSynchronization,AsyncWheelEvents"; + + auto feature_list = std::make_unique(); + feature_list->InitializeFromCommandLine(enable_features, disable_features); base::FeatureList::SetInstance(std::move(feature_list)); +} + +bool BrowserMainParts::ShouldContentCreateFeatureList() { + return false; +} + +int BrowserMainParts::PreEarlyInitialization() { + InitializeFeatureList(); OverrideAppLogsPath(); #if defined(USE_X11) views::LinuxUI::SetInstance(BuildGtkUi()); @@ -252,6 +268,16 @@ void BrowserMainParts::PreMainMessageLoopStart() { } void BrowserMainParts::PreMainMessageLoopRun() { + // We already initialized the feature list in PreEarlyInitialization(), but + // the user JS script would not have had a chance to alter the command-line + // switches at that point. Lets force re-initialization here to pick up the + // command-line changes. Note that some Chromium code (e.g. + // gpu_process_host.cc) queries the feature list between + // PreEarlyInitialization() and here so the user script may not have + // control over all features. Better than nothing though! + base::FeatureList::ClearInstanceForTesting(); + InitializeFeatureList(); + content::WebUIControllerFactory::RegisterFactory( WebUIControllerFactory::GetInstance()); diff --git a/brightray/browser/browser_main_parts.h b/brightray/browser/browser_main_parts.h index 0f82ce6daa9a..f8d758d0ab0c 100644 --- a/brightray/browser/browser_main_parts.h +++ b/brightray/browser/browser_main_parts.h @@ -33,6 +33,7 @@ class BrowserMainParts : public content::BrowserMainParts { protected: // content::BrowserMainParts: + bool ShouldContentCreateFeatureList() override; int PreEarlyInitialization() override; void ToolkitInitialized() override; void PreMainMessageLoopStart() override; @@ -48,6 +49,8 @@ class BrowserMainParts : public content::BrowserMainParts { void OverrideAppLogsPath(); #endif + void InitializeFeatureList(); + std::unique_ptr io_thread_; #if defined(USE_AURA)