Skip to content
Snippets Groups Projects
Commit e165855e authored by Ming Rui Zhang's avatar Ming Rui Zhang
Browse files

misc: use single process mode for qt webEngine

1. Add --single-process
2. Rename the httpUserAgent to jami-qt

Change-Id: I6de29ee89176b453f12ce225acf926dd1b819c18
parent 712f2c3b
No related branches found
No related tags found
No related merge requests found
...@@ -24,7 +24,9 @@ import QtQuick 2.14 ...@@ -24,7 +24,9 @@ import QtQuick 2.14
import net.jami.Helpers 1.0 import net.jami.Helpers 1.0
Item { Item {
readonly property string appTitle: "Jami" + (UpdateManager.isCurrentVersionBeta() ? " (BETA)" : "") readonly property string appTitle: "Jami" + (UpdateManager.isCurrentVersionBeta()
? " (BETA)" : "")
readonly property string httpUserAgentName: "jami-qt"
// Misc // Misc
property string accept: qsTr("Accept") property string accept: qsTr("Accept")
......
...@@ -31,26 +31,36 @@ ...@@ -31,26 +31,36 @@
#ifndef ENABLE_TESTS #ifndef ENABLE_TESTS
static char** static char**
parseInputArgument(int& argc, char* argv[], char* argToParse) parseInputArgument(int& argc, char* argv[], QList<char*> argsToParse)
{ {
/* /*
* Forcefully append argToParse. * Forcefully append argsToParse.
*/ */
int oldArgc = argc; int oldArgc = argc;
argc = argc + 1 + 1; argc += argsToParse.size();
char** newArgv = new char*[argc]; char** newArgv = new char*[argc];
for (int i = 0; i < oldArgc; i++) { for (int i = 0; i < oldArgc; i++) {
newArgv[i] = argv[i]; newArgv[i] = argv[i];
} }
newArgv[oldArgc] = argToParse;
newArgv[oldArgc + 1] = nullptr; for (int i = oldArgc; i < argc; i++) {
newArgv[i] = argsToParse.at(i - oldArgc);
}
return newArgv; return newArgv;
} }
// Qt WebEngine Chromium Flags
static char noSandbox[] {"--no-sandbox"};
static char disableWebSecurity[] {"--disable-web-security"};
static char singleProcess[] {"--single-process"};
int int
main(int argc, char* argv[]) main(int argc, char* argv[])
{ {
setlocale(LC_ALL, "en_US.utf8"); setlocale(LC_ALL, "en_US.utf8");
QList<char*> qtWebEngineChromiumFlags;
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX
setenv("QT_QPA_PLATFORMTHEME", "gtk3", true); setenv("QT_QPA_PLATFORMTHEME", "gtk3", true);
#ifdef __GLIBC__ #ifdef __GLIBC__
...@@ -59,9 +69,12 @@ main(int argc, char* argv[]) ...@@ -59,9 +69,12 @@ main(int argc, char* argv[])
// As I prefer to not use custom patched Qt, just wait for a // As I prefer to not use custom patched Qt, just wait for a
// new version with this bug fixed // new version with this bug fixed
if (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 33)) if (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 33))
setenv("QTWEBENGINE_CHROMIUM_FLAGS", "--no-sandbox", true); qtWebEngineChromiumFlags << noSandbox;
#endif #endif
#endif #endif
qtWebEngineChromiumFlags << disableWebSecurity;
qtWebEngineChromiumFlags << singleProcess;
QApplication::setApplicationName("Jami"); QApplication::setApplicationName("Jami");
QApplication::setOrganizationDomain("jami.net"); QApplication::setOrganizationDomain("jami.net");
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling, true); QApplication::setAttribute(Qt::AA_EnableHighDpiScaling, true);
...@@ -75,8 +88,8 @@ main(int argc, char* argv[]) ...@@ -75,8 +88,8 @@ main(int argc, char* argv[])
#endif #endif
QtWebEngine::initialize(); QtWebEngine::initialize();
char ARG_DISABLE_WEB_SECURITY[] = "--disable-web-security"; auto newArgv = parseInputArgument(argc, argv, qtWebEngineChromiumFlags);
auto newArgv = parseInputArgument(argc, argv, ARG_DISABLE_WEB_SECURITY);
MainApplication app(argc, newArgv); MainApplication app(argc, newArgv);
/* /*
......
...@@ -365,10 +365,16 @@ MainApplication::parseArguments() ...@@ -365,10 +365,16 @@ MainApplication::parseArguments()
parser.addHelpOption(); parser.addHelpOption();
parser.addVersionOption(); parser.addVersionOption();
// This option is forced into the arg list. // These options are potentially forced into the arg list.
QCommandLineOption webSecurityDisableOption(QStringList() << "disable-web-security"); QCommandLineOption webSecurityDisableOption(QStringList() << "disable-web-security");
parser.addOption(webSecurityDisableOption); parser.addOption(webSecurityDisableOption);
QCommandLineOption noSandboxOption(QStringList() << "no-sandbox");
parser.addOption(noSandboxOption);
QCommandLineOption singleProcessOption(QStringList() << "single-process");
parser.addOption(singleProcessOption);
QCommandLineOption webDebugOption(QStringList() << "remote-debugging-port", QCommandLineOption webDebugOption(QStringList() << "remote-debugging-port",
"Web debugging port.", "Web debugging port.",
"port"); "port");
......
...@@ -287,7 +287,6 @@ Rectangle { ...@@ -287,7 +287,6 @@ Rectangle {
settings.localStorageEnabled: true settings.localStorageEnabled: true
webChannel: messageWebViewChannel webChannel: messageWebViewChannel
profile: messageWebViewProfile
DropArea{ DropArea{
anchors.fill: parent anchors.fill: parent
...@@ -319,6 +318,8 @@ Rectangle { ...@@ -319,6 +318,8 @@ Rectangle {
":/linkify-string.js")) ":/linkify-string.js"))
messageWebView.runJavaScript(UtilsAdapter.qStringFromFile( messageWebView.runJavaScript(UtilsAdapter.qStringFromFile(
":/qwebchannel.js")) ":/qwebchannel.js"))
messageWebView.runJavaScript(UtilsAdapter.qStringFromFile(
":/jed.js"))
messageWebView.runJavaScript(UtilsAdapter.qStringFromFile( messageWebView.runJavaScript(UtilsAdapter.qStringFromFile(
":/emoji.js")) ":/emoji.js"))
messageWebView.runJavaScript(UtilsAdapter.qStringFromFile( messageWebView.runJavaScript(UtilsAdapter.qStringFromFile(
...@@ -342,24 +343,18 @@ Rectangle { ...@@ -342,24 +343,18 @@ Rectangle {
} }
Component.onCompleted: { Component.onCompleted: {
profile.cachePath = UtilsAdapter.getCachePath()
profile.persistentStoragePath = UtilsAdapter.getCachePath()
profile.persistentCookiesPolicy = WebEngineProfile.NoPersistentCookies
profile.httpCacheType = WebEngineProfile.NoCache
profile.httpUserAgent = JamiStrings.httpUserAgentName
messageWebView.loadHtml(UtilsAdapter.qStringFromFile( messageWebView.loadHtml(UtilsAdapter.qStringFromFile(
":/chatview.html"), ":/chatview.html") ":/chatview.html"), ":/chatview.html")
messageWebView.url = "qrc:/chatview.html" messageWebView.url = "qrc:/chatview.html"
} }
} }
// Provide WebEngineProfile.
WebEngineProfile {
id: messageWebViewProfile
cachePath: UtilsAdapter.getCachePath()
persistentStoragePath: UtilsAdapter.getCachePath()
persistentCookiesPolicy: WebEngineProfile.NoPersistentCookies
httpCacheType: WebEngineProfile.NoCache
httpUserAgent: "jami-windows"
}
// Provide WebChannel by registering jsBridgeObject. // Provide WebChannel by registering jsBridgeObject.
WebChannel { WebChannel {
id: messageWebViewChannel id: messageWebViewChannel
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment