diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2016-11-28 16:18:08 +0100 |
---|---|---|
committer | Jani Heikkinen <jani.heikkinen@qt.io> | 2016-12-01 11:14:56 +0000 |
commit | 04bf324fe80a81359c3e8aa6d25d56374c3d19ff (patch) | |
tree | 86ee336b5e728436af259f52d2ea36488f913ed1 /src/core/web_engine_context.cpp | |
parent | 79649acb80e4bc1bc343dfeb70545400915eaa8e (diff) |
Add environment variable to set chromium flags
It is not always possible to pass random flags to any QtWebEngine
application, so we should allow another way of setting Chromium flags.
Among other things this makes it easy to set flags when running auto
tests.
Change-Id: I7ffb3bf8c9ceafc7d6b1bd2ba135643a687e480f
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'src/core/web_engine_context.cpp')
-rw-r--r-- | src/core/web_engine_context.cpp | 43 |
1 files changed, 22 insertions, 21 deletions
diff --git a/src/core/web_engine_context.cpp b/src/core/web_engine_context.cpp index 227918d51..152859bee 100644 --- a/src/core/web_engine_context.cpp +++ b/src/core/web_engine_context.cpp @@ -240,17 +240,15 @@ QObject *WebEngineContext::globalQObject() #define CHROMIUM_VERSION // This is solely to keep Qt Creator happy. #endif +const static char kChromiumFlagsEnv[] = "QTWEBENGINE_CHROMIUM_FLAGS"; +const static char kDisableSandboxEnv[] = "QTWEBENGINE_DISABLE_SANDBOX"; + WebEngineContext::WebEngineContext() : m_mainDelegate(new ContentMainDelegateQt) , m_contentRunner(content::ContentMainRunner::Create()) , m_browserRunner(content::BrowserMainRunner::Create()) , m_globalQObject(new QObject()) { - QStringList appArgs = QCoreApplication::arguments(); - bool useEmbeddedSwitches = appArgs.removeAll(QStringLiteral("--enable-embedded-switches")); -#if defined(QTWEBENGINE_EMBEDDED_SWITCHES) - useEmbeddedSwitches = !appArgs.removeAll(QStringLiteral("--disable-embedded-switches")); -#endif #ifdef Q_OS_LINUX // Call qputenv before BrowserMainRunnerImpl::Initialize is called. @@ -261,32 +259,35 @@ WebEngineContext::WebEngineContext() // Allow us to inject javascript like any webview toolkit. content::RenderFrameHost::AllowInjectingJavaScriptForAndroidWebView(); -#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(); + 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(' ')); + } + + bool useEmbeddedSwitches = false; +#if defined(QTWEBENGINE_EMBEDDED_SWITCHES) + useEmbeddedSwitches = !appArgs.removeAll(QStringLiteral("--disable-embedded-switches")); +#else + useEmbeddedSwitches = appArgs.removeAll(QStringLiteral("--enable-embedded-switches")); +#endif base::CommandLine::StringVector argv; argv.resize(appArgs.size()); - std::transform(appArgs.constBegin(), appArgs.constEnd(), argv.begin(), &toString16); - parsedCommandLine->InitFromArgv(argv); +#if defined(Q_OS_WIN) + for (int i = 0; i < appArgs.size(); ++i) + argv[i] = toString16(appArgs[i]); #else - QVector<QByteArray> args; - Q_FOREACH (const QString& arg, appArgs) - args << arg.toUtf8(); - - QVector<const char*> 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(); + for (int i = 0; i < appArgs.size(); ++i) + argv[i] = appArgs[i].toStdString(); #endif + parsedCommandLine->InitFromArgv(argv); parsedCommandLine->AppendSwitchPath(switches::kBrowserSubprocessPath, WebEngineLibraryInfo::getPath(content::CHILD_PROCESS_EXE)); // Enable sandboxing on OS X and Linux (Desktop / Embedded) by default. - bool disable_sandbox = qEnvironmentVariableIsSet("QTWEBENGINE_DISABLE_SANDBOX"); + bool disable_sandbox = qEnvironmentVariableIsSet(kDisableSandboxEnv); if (!disable_sandbox) { #if defined(Q_OS_WIN) parsedCommandLine->AppendSwitch(switches::kNoSandbox); |