From af51e84171a922a67b59c1ad121b22a444f63bfb Mon Sep 17 00:00:00 2001 From: Michal Klocek Date: Tue, 23 Oct 2018 19:11:39 +0200 Subject: 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 --- src/core/web_engine_context.cpp | 48 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) (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 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 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")); -- cgit v1.2.3