From 665c422803e9d6767f9fa2fd69964c03a254167b Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Mon, 21 Mar 2016 13:56:20 +0100 Subject: Fix CommandLine initialization on Windows Chromium insists on getting the command line via the system call GetCommandLineW. QCoreApplication already did that, and we want to pass the already split argument vector to init CommandLine. This way, the user can pass custom arguments to QGuiApplication, and Chromium will pick those up correctly. Task-number: QTBUG-51971 Change-Id: I85b2071fcd8e5781b13ec8d22dc00b1a0c71601b Reviewed-by: Kai Koehne --- src/core/web_engine_context.cpp | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 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 a8cab45c5..8845cedbe 100644 --- a/src/core/web_engine_context.cpp +++ b/src/core/web_engine_context.cpp @@ -203,21 +203,34 @@ WebEngineContext::WebEngineContext() , m_browserRunner(content::BrowserMainRunner::Create()) , m_globalQObject(new QObject()) { - QVector args; - Q_FOREACH (const QString& arg, QCoreApplication::arguments()) - args << arg.toUtf8(); - - bool useEmbeddedSwitches = args.removeAll("--enable-embedded-switches"); + QStringList appArgs = QCoreApplication::arguments(); + bool useEmbeddedSwitches = appArgs.removeAll(QStringLiteral("--enable-embedded-switches")); #if defined(QTWEBENGINE_EMBEDDED_SWITCHES) - useEmbeddedSwitches = !args.removeAll("--disable-embedded-switches"); + useEmbeddedSwitches = !appArgs.removeAll(QStringLiteral("--disable-embedded-switches")); #endif +#if defined(Q_OS_WIN) + // We must initialize the command line with the UTF-16 arguments vector we got from + // QCoreApplication. CommandLine::Init ignores its arguments on Windows and calls + // GetCommandLineW() instead. + base::CommandLine::CreateEmpty(); + base::CommandLine* parsedCommandLine = base::CommandLine::ForCurrentProcess(); + base::CommandLine::StringVector argv; + argv.resize(appArgs.size()); + std::transform(appArgs.constBegin(), appArgs.constEnd(), argv.begin(), &toString16); + parsedCommandLine->InitFromArgv(argv); +#else + QVector args; + Q_FOREACH (const QString& arg, appArgs) + args << arg.toUtf8(); + QVector argv(args.size()); for (int i = 0; i < args.size(); ++i) argv[i] = args[i].constData(); base::CommandLine::Init(argv.size(), argv.constData()); - base::CommandLine* parsedCommandLine = base::CommandLine::ForCurrentProcess(); +#endif + parsedCommandLine->AppendSwitchPath(switches::kBrowserSubprocessPath, WebEngineLibraryInfo::getPath(content::CHILD_PROCESS_EXE)); parsedCommandLine->AppendSwitch(switches::kNoSandbox); parsedCommandLine->AppendSwitch(switches::kEnableDelegatedRenderer); -- cgit v1.2.3 From b98d79b561791459dd6bfb0fed5dc7462a1a09a7 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Wed, 30 Mar 2016 18:22:21 +0200 Subject: Fix crashes due to qputenv being called after Chromium initialization. The qputenv() call inside gl_surface_qt.cpp, which is executed on a GpuChildThread, can reallocate the process environment structure, and it is possible that at the same time the main thread calls getenv, which will dereference a pointer to the freed environment structure, essentially causing a use-after-free crash. Make sure the qputenv() call happens before Chromium initialization starts, so no thread-race can occur. Change-Id: I4ecbdc8bf2abbe45f7d6c5d2633dc9fe27f51e66 Task-number: QTBUG-52124 Reviewed-by: Allan Sandfeld Jensen Reviewed-by: Kai Koehne (cherry picked from commit 76c61aa1400ef2def204c3732e30e08e40631e8d) --- src/core/web_engine_context.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (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 8845cedbe..9a96f695e 100644 --- a/src/core/web_engine_context.cpp +++ b/src/core/web_engine_context.cpp @@ -209,6 +209,12 @@ WebEngineContext::WebEngineContext() useEmbeddedSwitches = !appArgs.removeAll(QStringLiteral("--disable-embedded-switches")); #endif +#ifdef Q_OS_LINUX + // Call qputenv before BrowserMainRunnerImpl::Initialize is called. + // http://crbug.com/245466 + qputenv("force_s3tc_enable", "true"); +#endif + #if defined(Q_OS_WIN) // We must initialize the command line with the UTF-16 arguments vector we got from // QCoreApplication. CommandLine::Init ignores its arguments on Windows and calls -- cgit v1.2.3