From 11ecb9c8d08acb05be2becb073835a4e0e963639 Mon Sep 17 00:00:00 2001 From: Peter Varga Date: Mon, 15 Feb 2021 14:37:10 +0100 Subject: Make able to override disabled features from command line Change-Id: I438cbbfe52617ac0fff3a954ea35a9b48fd14625 Reviewed-by: Allan Sandfeld Jensen --- src/core/web_engine_context.cpp | 90 +++++++++++++++++++++++++---------------- 1 file changed, 55 insertions(+), 35 deletions(-) (limited to 'src/core/web_engine_context.cpp') diff --git a/src/core/web_engine_context.cpp b/src/core/web_engine_context.cpp index 41db33cd4..f342e788d 100644 --- a/src/core/web_engine_context.cpp +++ b/src/core/web_engine_context.cpp @@ -525,23 +525,47 @@ bool WebEngineContext::isGpuServiceOnUIThread() return !threadedGpu; } -static void appendToFeatureList(std::string &featureList, const char *feature) +static void initializeFeatureList(base::CommandLine *commandLine, std::vector enableFeatures, std::vector disableFeatures) { - if (featureList.empty()) - featureList = feature; - else - featureList = featureList + "," + feature; -} + std::string enableFeaturesString = base::JoinString(enableFeatures, ","); + if (commandLine->HasSwitch(switches::kEnableFeatures)) { + std::string commandLineEnableFeatures = commandLine->GetSwitchValueASCII(switches::kEnableFeatures); -static void appendToFeatureSwitch(base::CommandLine *commandLine, const char *featureSwitch, std::string feature) -{ - if (!commandLine->HasSwitch(featureSwitch)) { - commandLine->AppendSwitchASCII(featureSwitch, feature); - } else { - std::string featureList = commandLine->GetSwitchValueASCII(featureSwitch); - featureList = featureList + "," + feature; - commandLine->AppendSwitchASCII(featureSwitch, featureList); + for (const std::string &enableFeature : base::SplitString(commandLineEnableFeatures, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY)) { + auto it = std::find(disableFeatures.begin(), disableFeatures.end(), enableFeature); + if (it == disableFeatures.end()) + continue; + + qWarning("An unsupported feature has been enabled from command line: %s\n" + "The feature is enabled but there is no guarantee that it will work or not break QtWebEngine.", enableFeature.c_str()); + + // If a feature is disabled and enabled at the same time, then it will be disabled. + // Remove feature from the disable list to make it possible to override from command line. + disableFeatures.erase(it); + } + + enableFeaturesString = enableFeaturesString + "," + commandLineEnableFeatures; } + + std::string disableFeaturesString = base::JoinString(disableFeatures, ","); + if (commandLine->HasSwitch(switches::kDisableFeatures)) { + std::string commandLineDisableFeatures = commandLine->GetSwitchValueASCII(switches::kDisableFeatures); + + for (const std::string &disableFeature : base::SplitString(commandLineDisableFeatures, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY)) { + auto it = std::find(enableFeatures.begin(), enableFeatures.end(), disableFeature); + if (it == enableFeatures.end()) + continue; + + qWarning("An essential feature has been disabled from command line: %s\n" + "The feature is disabled but there is no guarantee that it will not break QtWebEngine.", disableFeature.c_str()); + } + + disableFeaturesString = disableFeaturesString + "," + commandLineDisableFeatures; + } + + commandLine->AppendSwitchASCII(switches::kEnableFeatures, enableFeaturesString); + commandLine->AppendSwitchASCII(switches::kDisableFeatures, disableFeaturesString); + base::FeatureList::InitializeInstance(enableFeaturesString, disableFeaturesString); } WebEngineContext::WebEngineContext() @@ -639,55 +663,51 @@ WebEngineContext::WebEngineContext() // Do not advertise a feature we have removed at compile time parsedCommandLine->AppendSwitch(switches::kDisableSpeechAPI); - std::string disableFeatures; - std::string enableFeatures; + std::vector disableFeatures; + std::vector enableFeatures; // Needed to allow navigations within pages that were set using setHtml(). One example is // tst_QWebEnginePage::acceptNavigationRequest. // This is deprecated behavior, and will be removed in a future Chromium version, as per // upstream Chromium commit ba52f56207a4b9d70b34880fbff2352e71a06422. - appendToFeatureList(enableFeatures, features::kAllowContentInitiatedDataUrlNavigations.name); + enableFeatures.push_back(features::kAllowContentInitiatedDataUrlNavigations.name); - appendToFeatureList(enableFeatures, features::kTracingServiceInProcess.name); + enableFeatures.push_back(features::kTracingServiceInProcess.name); // The video-capture service is not functioning at this moment (since 69) - appendToFeatureList(disableFeatures, features::kMojoVideoCapture.name); + disableFeatures.push_back(features::kMojoVideoCapture.name); #if defined(Q_OS_LINUX) // broken and crashy (even upstream): - appendToFeatureList(disableFeatures, features::kFontSrcLocalMatching.name); + disableFeatures.push_back(features::kFontSrcLocalMatching.name); #endif // We don't support the skia renderer (enabled by default on Linux since 80) - appendToFeatureList(disableFeatures, features::kUseSkiaRenderer.name); + disableFeatures.push_back(features::kUseSkiaRenderer.name); - appendToFeatureList(disableFeatures, network::features::kDnsOverHttpsUpgrade.name); + disableFeatures.push_back(network::features::kDnsOverHttpsUpgrade.name); // When enabled, event.movement is calculated in blink instead of in browser. - appendToFeatureList(disableFeatures, features::kConsolidatedMovementXY.name); + disableFeatures.push_back(features::kConsolidatedMovementXY.name); // Avoid crashing when websites tries using this feature (since 83) - appendToFeatureList(disableFeatures, features::kInstalledApp.name); + disableFeatures.push_back(features::kInstalledApp.name); // Explicitly tell Chromium about default-on features we do not support - appendToFeatureList(disableFeatures, features::kBackgroundFetch.name); - appendToFeatureList(disableFeatures, features::kSmsReceiver.name); - appendToFeatureList(disableFeatures, features::kWebPayments.name); - appendToFeatureList(disableFeatures, features::kWebUsb.name); - appendToFeatureList(disableFeatures, media::kPictureInPicture.name); + disableFeatures.push_back(features::kBackgroundFetch.name); + disableFeatures.push_back(features::kSmsReceiver.name); + disableFeatures.push_back(features::kWebPayments.name); + disableFeatures.push_back(features::kWebUsb.name); + disableFeatures.push_back(media::kPictureInPicture.name); if (useEmbeddedSwitches) { // embedded switches are based on the switches for Android, see content/browser/android/content_startup_flags.cc - appendToFeatureList(enableFeatures, features::kOverlayScrollbar.name); + enableFeatures.push_back(features::kOverlayScrollbar.name); parsedCommandLine->AppendSwitch(switches::kEnableViewport); parsedCommandLine->AppendSwitch(switches::kMainFrameResizesAreOrientationChanges); parsedCommandLine->AppendSwitch(cc::switches::kDisableCompositedAntialiasing); } - appendToFeatureSwitch(parsedCommandLine, switches::kDisableFeatures, disableFeatures); - appendToFeatureSwitch(parsedCommandLine, switches::kEnableFeatures, enableFeatures); - base::FeatureList::InitializeInstance( - parsedCommandLine->GetSwitchValueASCII(switches::kEnableFeatures), - parsedCommandLine->GetSwitchValueASCII(switches::kDisableFeatures)); + initializeFeatureList(parsedCommandLine, enableFeatures, disableFeatures); GLContextHelper::initialize(); -- cgit v1.2.3