1
0
Fork 0
mirror of https://git.jami.net/savoirfairelinux/jami-client-qt.git synced 2025-09-10 03:53:23 +02:00
jami-client-qt/src/previewengine.cpp
Andreas Traczyk 9aad97763c chatview: base previewengine on QWebEnginePage not QWebEngineView
Qt6 allows us to set the RHI backend, however QQuickWidget is only
supported when using OpenGL. QWebEngineView instantiation uses
QQuickWidget and isn't required as we wish to use the previewengine
in a headless mode. So it can just be based on QWebEnginePage.

Change-Id: If05ca5c89272704b54c29318803c8773984b087c
2022-01-25 13:13:45 -05:00

87 lines
3.6 KiB
C++

/*
* Copyright (C) 2021-2022 Savoir-faire Linux Inc.
* Author: Trevor Tabah <trevor.tabah@savoirfairelinux.com>
* Author: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "previewengine.h"
#include <QWebEngineScript>
#include <QWebEngineProfile>
#include <QWebEngineSettings>
PreviewEngine::PreviewEngine(QObject* parent)
: QWebEnginePage(parent)
, pimpl_(new PreviewEnginePrivate(this))
{
QWebEngineProfile* profile = QWebEngineProfile::defaultProfile();
QDir dataDir(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation));
dataDir.cdUp();
auto cachePath = dataDir.absolutePath() + "/jami";
profile->setCachePath(cachePath);
profile->setPersistentStoragePath(cachePath);
profile->setPersistentCookiesPolicy(QWebEngineProfile::NoPersistentCookies);
profile->setHttpCacheType(QWebEngineProfile::NoCache);
settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, true);
settings()->setAttribute(QWebEngineSettings::ScrollAnimatorEnabled, false);
settings()->setAttribute(QWebEngineSettings::ErrorPageEnabled, false);
settings()->setAttribute(QWebEngineSettings::PluginsEnabled, false);
settings()->setAttribute(QWebEngineSettings::ScreenCaptureEnabled, false);
settings()->setAttribute(QWebEngineSettings::LinksIncludedInFocusChain, false);
settings()->setAttribute(QWebEngineSettings::LocalStorageEnabled, false);
settings()->setAttribute(QWebEngineSettings::AllowRunningInsecureContent, true);
settings()->setAttribute(QWebEngineSettings::LocalContentCanAccessRemoteUrls, true);
settings()->setAttribute(QWebEngineSettings::XSSAuditingEnabled, false);
settings()->setAttribute(QWebEngineSettings::LocalContentCanAccessFileUrls, true);
channel_ = new QWebChannel(this);
channel_->registerObject(QStringLiteral("jsbridge"), pimpl_);
setWebChannel(channel_);
runJavaScript(Utils::QByteArrayFromFile(":/linkify.js"), QWebEngineScript::MainWorld);
runJavaScript(Utils::QByteArrayFromFile(":/linkify-string.js"), QWebEngineScript::MainWorld);
runJavaScript(Utils::QByteArrayFromFile(":/qwebchannel.js"), QWebEngineScript::MainWorld);
runJavaScript(Utils::QByteArrayFromFile(":/previewInfo.js"), QWebEngineScript::MainWorld);
runJavaScript(Utils::QByteArrayFromFile(":/misc/previewInterop.js"),
QWebEngineScript::MainWorld);
}
void
PreviewEngine::parseMessage(const QString& messageId, const QString& msg, bool showPreview)
{
runJavaScript(
QString("parseMessage(`%1`, `%2`, %3)").arg(messageId, msg, showPreview ? "true" : "false"));
}
void
PreviewEnginePrivate::log(const QString& str)
{
qDebug() << str;
}
void
PreviewEnginePrivate::infoReady(const QString& messageId, const QVariantMap& info)
{
Q_EMIT parent_->infoReady(messageId, info);
}
void
PreviewEnginePrivate::linkifyReady(const QString& messageId, const QString& linkified)
{
Q_EMIT parent_->linkifyReady(messageId, linkified);
}