diff options
author | Michal Klocek <michal.klocek@qt.io> | 2018-10-23 19:11:39 +0200 |
---|---|---|
committer | Michal Klocek <michal.klocek@qt.io> | 2020-04-30 22:04:07 +0200 |
commit | af51e84171a922a67b59c1ad121b22a444f63bfb (patch) | |
tree | 351b98d5e5c8245cb5e077ea6bf4f5047fdd4373 /src/core | |
parent | 8d13facbd88d821cc89b21f43708cc1a81ac79f3 (diff) |
Add very basic chromium flags parser
Setting chromium flags QTWEBENGINE_CHROMIUM_FLAGS only worked
for simple flags, and we did only split(' '). This means setting
anything quoted is missing parser and misbehaves.
Add very very basic parser to support sth like:
QTWEBENGINE_CHROMIUM_FLAGS='foo="foo1 foo2 foor3" bar'
Fixes: QTBUG-78559
Fixes: QTBUG-83035
Change-Id: Ife62216ee013f4f888f2ec6f7cad59fcafb8a71e
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/web_engine_context.cpp | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/src/core/web_engine_context.cpp b/src/core/web_engine_context.cpp index 56ec4b90a..6a08b265e 100644 --- a/src/core/web_engine_context.cpp +++ b/src/core/web_engine_context.cpp @@ -261,6 +261,52 @@ static void cleanupVizProcess() vizCompositorThreadRunner->CleanupForShutdown(base::BindOnce(&completeVizCleanup)); } +static QStringList parseEnvCommandLine(const QString &cmdLine) +{ + QString arg; + QStringList arguments; + enum { Parse, Quoted, Unquoted } state = Parse; + for (const QChar c : cmdLine) { + switch (state) { + case Parse: + if (c == '"') { + state = Quoted; + } else if (c != ' ' ) { + arg += c; + state = Unquoted; + } + // skips spaces + break; + case Quoted: + if (c == '"') { + DCHECK(!arg.isEmpty()); + state = Unquoted; + } else { + // includes spaces + arg += c; + } + break; + case Unquoted: + if (c == '"') { + // skips quotes + state = Quoted; + } else if (c == ' ') { + arguments.append(arg); + arg.clear(); + state = Parse; + } else { + arg += c; + } + break; + } + } + // last arg + if (!arg.isEmpty()) { + arguments.append(arg); + } + return arguments; +} + scoped_refptr<QtWebEngineCore::WebEngineContext> WebEngineContext::m_handle; bool WebEngineContext::m_destroyed = false; @@ -829,7 +875,7 @@ base::CommandLine* WebEngineContext::commandLine() { QStringList appArgs = QCoreApplication::arguments(); if (qEnvironmentVariableIsSet(kChromiumFlagsEnv)) { appArgs = appArgs.mid(0, 1); // Take application name and drop the rest - appArgs.append(QString::fromLocal8Bit(qgetenv(kChromiumFlagsEnv)).split(' ')); + appArgs.append(parseEnvCommandLine(QString::fromLocal8Bit(qgetenv(kChromiumFlagsEnv)))); } #ifdef Q_OS_WIN appArgs.removeAll(QStringLiteral("--enable-webgl-software-rendering")); |