diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2021-03-12 12:41:40 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2021-03-16 12:03:57 +0100 |
commit | 3c544a5d0d59b0533f507a6131fbbc093ed223ea (patch) | |
tree | c64d3ae8e17280350037ff1d6687ec797ca4715c /src/core/web_engine_context.cpp | |
parent | e7c869c225075d898cb5d20b194af4b939d2dbc1 (diff) | |
parent | fdec85eba16d6321597e93b447bc13a611cfdd23 (diff) |
Merge remote-tracking branch 'origin/5.15' into dev
Change-Id: I0dd7c64669f4b130047a4a3836f62f7ee5b5f8d9
Diffstat (limited to 'src/core/web_engine_context.cpp')
-rw-r--r-- | src/core/web_engine_context.cpp | 108 |
1 files changed, 67 insertions, 41 deletions
diff --git a/src/core/web_engine_context.cpp b/src/core/web_engine_context.cpp index 7f338efe8..94f214a07 100644 --- a/src/core/web_engine_context.cpp +++ b/src/core/web_engine_context.cpp @@ -431,6 +431,15 @@ void WebEngineContext::removeProfileAdapter(ProfileAdapter *profileAdapter) m_profileAdapters.removeAll(profileAdapter); } +void WebEngineContext::flushMessages() +{ + if (!m_destroyed) { + base::MessagePump::Delegate *delegate = static_cast< + base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl *>( + WebEngineContext::current()->m_runLoop->delegate_); + while (delegate->DoWork().is_immediate()) { } + } +} void WebEngineContext::destroy() { if (m_devtoolsServer) @@ -441,20 +450,17 @@ void WebEngineContext::destroy() m_webrtcLogUploader->Shutdown(); #endif - base::MessagePump::Delegate *delegate = - static_cast<base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl *>( - m_runLoop->delegate_); // Normally the GPU thread is shut down when the GpuProcessHost is destroyed // on IO thread (triggered by ~BrowserMainRunner). But by that time the UI // task runner is not working anymore so we need to do this earlier. cleanupVizProcess(); while (waitForViz) { - while (delegate->DoWork().is_immediate()) { } + flushMessages(); QThread::msleep(50); } destroyGpuProcess(); // Flush the UI message loop before quitting. - while (delegate->DoWork().is_immediate()) { } + flushMessages(); #if QT_CONFIG(webengine_printing_and_pdf) // Kill print job manager early as it has a content::NotificationRegistrar @@ -476,7 +482,7 @@ void WebEngineContext::destroy() // Handle any events posted by browser-context shutdown. // This should deliver all nessesery calls of DeleteSoon from PostTask - while (delegate->DoWork().is_immediate()) { } + flushMessages(); m_devtoolsServer.reset(); m_runLoop->AfterRun(); @@ -596,23 +602,47 @@ bool WebEngineContext::isGpuServiceOnUIThread() return !threadedGpu; } -static void appendToFeatureList(std::string &featureList, const char *feature) +static void initializeFeatureList(base::CommandLine *commandLine, std::vector<std::string> enableFeatures, std::vector<std::string> 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() @@ -683,55 +713,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<std::string> disableFeatures; + std::vector<std::string> 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(); |