Dekko
Loading...
Searching...
No Matches
DekkoWebEngineUrlRequestInterceptor.cpp
1#include "DekkoWebEngineUrlRequestInterceptor.h"
2#include <QWebEngineUrlRequestInfo>
3#include <QDebug>
4
5DekkoWebEngineUrlRequestInterceptor::DekkoWebEngineUrlRequestInterceptor(QWebEngineUrlRequestInterceptor *parent) : QWebEngineUrlRequestInterceptor(parent),
6 remoteResourcesAreBlocked(true)
7{
8}
9
10void DekkoWebEngineUrlRequestInterceptor::interceptRequest(QWebEngineUrlRequestInfo &info)
11{
12 auto requestUrl = info.requestUrl();
13
14 if (!this->hasAllowedScheme(requestUrl))
15 {
16 // check the resourceType() to not block links, not sure thats reliable, but it
17 // seems navigationType() == QWebEngineUrlRequestInfo::NavigationTypeLink always...
18 bool doBlock = this->remoteResourcesAreBlocked
19 && (info.resourceType() != QWebEngineUrlRequestInfo::ResourceTypeMainFrame);
20 info.block(doBlock);
21 emit interceptedRemoteRequest(doBlock);
22 }
23}
24
25bool DekkoWebEngineUrlRequestInterceptor::hasAllowedScheme(const QUrl &url)
26{
27 return this->testScheme("cid", url) || this->testScheme("dekko-part", url) || this->testScheme("dekko-msg", url) || this->testScheme("blob", url);
28}
29
30bool DekkoWebEngineUrlRequestInterceptor::testScheme(const QString &scheme, const QUrl &url)
31{
32 return url.scheme() == scheme;
33}
34
35void DekkoWebEngineUrlRequestInterceptor::setBlockRemoteResources(bool doBlock)
36{
37 this->remoteResourcesAreBlocked = doBlock;
38}
39
40bool DekkoWebEngineUrlRequestInterceptor::areRemoteResourcesBlocked() const
41{
42 return this->remoteResourcesAreBlocked;
43}
44