summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPeter Varga <pvarga@inf.u-szeged.hu>2023-01-18 13:38:00 +0100
committerPeter Varga <pvarga@inf.u-szeged.hu>2023-01-20 09:03:22 +0100
commit614d6639b875f53b21eaabd2d5928b84b59af707 (patch)
treec7d3d01260c74a33645010605abdd8317f139a15 /src
parent876f11854eddbe95132692b3b0853470563ff54a (diff)
downloadqtwebengine-614d6639b875f53b21eaabd2d5928b84b59af707.tar.gz
Improve error handling of argument parsing
As a corner case, QCoreApplication::arguments() might be empty. For example, the embedder sets argc=0. It is invalid but doesn't crash or warn. base::CommandLine expects program name to be set and Chromium code might use it. It is not possible to set program name if argv is not passed to QCoreApplication. This change does not handle this corner case but detects it, and warns the user to not expect proper behavior. Pick-to: 6.5 Task-number: QTBUG-110157 Change-Id: Ibf14b11bbf8b8c72d8a1d8419377a25b311b9ebe Reviewed-by: Michal Klocek <michal.klocek@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/core/web_engine_context.cpp62
1 files changed, 35 insertions, 27 deletions
diff --git a/src/core/web_engine_context.cpp b/src/core/web_engine_context.cpp
index ee90a5810..67d015e48 100644
--- a/src/core/web_engine_context.cpp
+++ b/src/core/web_engine_context.cpp
@@ -842,44 +842,52 @@ gpu::SyncPointManager *WebEngineContext::syncPointManager()
base::CommandLine *WebEngineContext::initCommandLine(bool &useEmbeddedSwitches,
bool &enableGLSoftwareRendering)
{
- if (base::CommandLine::CreateEmpty()) {
- base::CommandLine* parsedCommandLine = base::CommandLine::ForCurrentProcess();
- QStringList appArgs = QCoreApplication::arguments();
- if (qEnvironmentVariableIsSet(kChromiumFlagsEnv)) {
- appArgs = appArgs.mid(0, 1); // Take application name and drop the rest
- appArgs.append(parseEnvCommandLine(qEnvironmentVariable(kChromiumFlagsEnv)));
+ if (!base::CommandLine::CreateEmpty())
+ qFatal("base::CommandLine has been initialized unexpectedly.");
+
+ base::CommandLine *parsedCommandLine = base::CommandLine::ForCurrentProcess();
+ QStringList appArgs = QCoreApplication::arguments();
+ if (qEnvironmentVariableIsSet(kChromiumFlagsEnv)) {
+ appArgs = appArgs.mid(0, 1); // Take application name and drop the rest
+ appArgs.append(parseEnvCommandLine(qEnvironmentVariable(kChromiumFlagsEnv)));
+ } else {
+ int index = appArgs.indexOf(QLatin1String("--webEngineArgs"));
+ if (index > -1) {
+ appArgs.erase(appArgs.begin() + 1, appArgs.begin() + index + 1);
} else {
- int index = appArgs.indexOf(QLatin1String("--webEngineArgs"));
- if (index > -1) {
- appArgs.erase(appArgs.begin() + 1, appArgs.begin() + index + 1);
- } else {
- appArgs = appArgs.mid(0, 1);
- }
+ appArgs = appArgs.mid(0, 1);
}
+ }
#if defined(QTWEBENGINE_EMBEDDED_SWITCHES)
- useEmbeddedSwitches = !appArgs.contains(QStringLiteral("--disable-embedded-switches"));
+ useEmbeddedSwitches = !appArgs.contains(QStringLiteral("--disable-embedded-switches"));
#else
- useEmbeddedSwitches = appArgs.contains(QStringLiteral("--enable-embedded-switches"));
+ useEmbeddedSwitches = appArgs.contains(QStringLiteral("--enable-embedded-switches"));
#endif
- enableGLSoftwareRendering =
+ enableGLSoftwareRendering =
appArgs.removeAll(QStringLiteral("--enable-webgl-software-rendering"));
- appArgs.removeAll(QStringLiteral("--disable-embedded-switches"));
- appArgs.removeAll(QStringLiteral("--enable-embedded-switches"));
+ appArgs.removeAll(QStringLiteral("--disable-embedded-switches"));
+ appArgs.removeAll(QStringLiteral("--enable-embedded-switches"));
- base::CommandLine::StringVector argv;
- argv.resize(appArgs.size());
+ base::CommandLine::StringVector argv;
+ argv.resize(appArgs.size());
#if defined(Q_OS_WIN)
- for (int i = 0; i < appArgs.size(); ++i)
- argv[i] = appArgs[i].toStdWString();
+ for (int i = 0; i < appArgs.size(); ++i)
+ argv[i] = appArgs[i].toStdWString();
#else
- for (int i = 0; i < appArgs.size(); ++i)
- argv[i] = appArgs[i].toStdString();
+ for (int i = 0; i < appArgs.size(); ++i)
+ argv[i] = appArgs[i].toStdString();
#endif
- parsedCommandLine->InitFromArgv(argv);
- return parsedCommandLine;
- } else {
- return base::CommandLine::ForCurrentProcess();
+ parsedCommandLine->InitFromArgv(argv);
+
+ if (QCoreApplication::arguments().empty()) {
+ // TODO: Replace this qWarning with a qFatal at the beginning of the function
+ // when the corresponding Active Qt issue gets fixed: QTBUG-110158.
+ qWarning("Argument list is empty, the program name is not passed to QCoreApplication. "
+ "Command line arguments might be ignored. Unexpected behavior may occur.");
+ Q_ASSERT(false);
}
+
+ return parsedCommandLine;
}
bool WebEngineContext::closingDown()