1#include "DekkoWebContext.h"
2#include "DekkoWebEngineUrlSchemeHandler.h"
3#include "DekkoWebEngineUrlRequestInterceptor.h"
9#include <QCoreApplication>
10#include <QStandardPaths>
12DekkoWebContext::DekkoWebContext(QQuickWebEngineProfile *parent) : QQuickWebEngineProfile(parent)
14 this->setRequestInterceptor(&this->urlRequestInterceptor);
16 this->installUrlSchemeHandler(
"dekko-msg", &this->urlSchemeHandler);
17 this->installUrlSchemeHandler(
"dekko-part", &this->urlSchemeHandler);
18 this->installUrlSchemeHandler(
"cid", &this->urlSchemeHandler);
19 connect(&this->urlRequestInterceptor, SIGNAL(interceptedRemoteRequest(
bool)),
this, SLOT(onInterceptedRemoteRequest(
bool)));
22void DekkoWebContext::onInterceptedRemoteRequest(
bool wasBlocked)
26 emit remoteContentBlocked();
30void DekkoWebContext::setMessageUid(QString messageUid)
32 this->urlSchemeHandler.setMessageUid(messageUid);
35void DekkoWebContext::setRemoteContentAllowed(
bool allowed)
37 this->urlRequestInterceptor.setBlockRemoteResources(!allowed);
40QString DekkoWebContext::getMessageUid()
const
42 return this->urlSchemeHandler.getMessageUid();
45bool DekkoWebContext::isRemoteContentAllowed()
const
47 return !this->urlRequestInterceptor.areRemoteResourcesBlocked();
51QString DekkoWebContext::cacheLocation()
const
53 QDir location(QStandardPaths::writableLocation(QStandardPaths::CacheLocation));
54 if (!location.exists()) {
55 QDir::root().mkpath(location.absolutePath());
57 return location.absolutePath();
60QString DekkoWebContext::dataLocation()
const
62 QDir location(QStandardPaths::writableLocation(QStandardPaths::DataLocation));
63 if (!location.exists()) {
64 QDir::root().mkpath(location.absolutePath());
68 QDir(location.absoluteFilePath(
"Cache")).removeRecursively();
70 return location.absolutePath();
73int DekkoWebContext::cacheSizeHint()
const
75 if (QCoreApplication::applicationName() ==
"webbrowser-app") {
81 QStorageInfo storageInfo(QStandardPaths::writableLocation(QStandardPaths::CacheLocation));
82 const int MB = 1024 * 1024;
84 int maxSharedCache = storageInfo.bytesTotal() / MB * 0.1;
86 int maxAppCacheAllowance = maxSharedCache * 0.05;
88 int maxAppCacheAbsolute = qMin(maxAppCacheAllowance, 200);
90 int maxAppCacheRelative = storageInfo.bytesAvailable() / MB * 0.2;
92 return qMax(5, qMin(maxAppCacheAbsolute, maxAppCacheRelative));
96QObject * DekkoWebContext::qmlEngineInjector()
const
101void DekkoWebContext::setQmlEngineInjector(QObject * dummy)
103 QQmlEngine* engine = qmlEngine(dummy);
105 qDebug() <<
"Failed to get qml engine from injected qml object.";
109 this->urlSchemeHandler.setNetworkAccessManager(engine->networkAccessManager());