2021-07-06 10:20:46 -04:00
|
|
|
/*
|
2022-01-06 11:24:13 -05:00
|
|
|
* Copyright (C) 2021-2022 Savoir-faire Linux Inc.
|
2021-07-06 10:20:46 -04:00
|
|
|
* 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)
|
2022-01-24 13:17:45 -05:00
|
|
|
: QWebEnginePage(parent)
|
2021-07-06 10:20:46 -04:00
|
|
|
, 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_);
|
|
|
|
|
2022-01-24 13:17:45 -05:00
|
|
|
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);
|
2021-07-06 10:20:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-10-25 14:57:36 -04:00
|
|
|
PreviewEngine::parseMessage(const QString& messageId, const QString& msg, bool showPreview)
|
2021-07-06 10:20:46 -04:00
|
|
|
{
|
2022-01-24 13:17:45 -05:00
|
|
|
runJavaScript(
|
|
|
|
QString("parseMessage(`%1`, `%2`, %3)").arg(messageId, msg, showPreview ? "true" : "false"));
|
2021-07-06 10:20:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|