Commit 4b34f0b7 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Create own loadexternalreferencesurlinterceptor

parent 4e7e93ad
Pipeline #55589 passed with stage
in 42 minutes and 41 seconds
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
set(PIM_VERSION "5.17.41")
set(PIM_VERSION "5.17.42")
if (POLICY CMP0053)
cmake_policy(SET CMP0053 NEW)
......
......@@ -12,38 +12,13 @@
using namespace MessageViewer;
LoadExternalReferencesUrlInterceptor::LoadExternalReferencesUrlInterceptor(QObject *parent)
: WebEngineViewer::NetworkPluginUrlInterceptorInterface(parent)
: WebEngineViewer::LoadExternalReferencesUrlInterceptor(parent)
{
}
LoadExternalReferencesUrlInterceptor::~LoadExternalReferencesUrlInterceptor()
{
}
bool LoadExternalReferencesUrlInterceptor::interceptRequest(QWebEngineUrlRequestInfo &info)
{
const QUrl requestUrl = info.requestUrl();
const QString scheme = requestUrl.scheme();
if (scheme == QLatin1String("data") || scheme == QLatin1String("file")) {
return false;
}
if (mAllowLoadExternalReference) {
if (info.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeImage && !requestUrl.isLocalFile() && (scheme != QLatin1String("cid"))) {
return urlIsBlocked(requestUrl);
}
return false;
} else {
if (info.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeImage && !requestUrl.isLocalFile() && (scheme != QLatin1String("cid"))) {
return urlIsAuthorized(requestUrl);
} else if (info.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeFontResource) {
return true;
} else if (info.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeStylesheet) {
return true;
}
}
return false;
}
bool LoadExternalReferencesUrlInterceptor::urlIsBlocked(const QUrl &requestedUrl)
{
const QUrl url = requestedUrl.adjusted(QUrl::RemovePath | QUrl::RemovePort | QUrl::RemoveQuery);
......@@ -66,13 +41,3 @@ bool LoadExternalReferencesUrlInterceptor::urlIsAuthorized(const QUrl &requested
}
return true;
}
void LoadExternalReferencesUrlInterceptor::setAllowExternalContent(bool b)
{
mAllowLoadExternalReference = b;
}
bool LoadExternalReferencesUrlInterceptor::allowExternalContent() const
{
return mAllowLoadExternalReference;
}
......@@ -5,29 +5,19 @@
*/
#pragma once
#include <WebEngineViewer/LoadExternalReferencesUrlInterceptor>
#include <WebEngineViewer/NetworkPluginUrlInterceptorInterface>
namespace MessageViewer
{
class LoadExternalReferencesUrlInterceptor : public WebEngineViewer::NetworkPluginUrlInterceptorInterface
class LoadExternalReferencesUrlInterceptor : public WebEngineViewer::LoadExternalReferencesUrlInterceptor
{
Q_OBJECT
public:
explicit LoadExternalReferencesUrlInterceptor(QObject *parent = nullptr);
~LoadExternalReferencesUrlInterceptor() override;
Q_REQUIRED_RESULT bool interceptRequest(QWebEngineUrlRequestInfo &info) override;
void setAllowExternalContent(bool b);
Q_REQUIRED_RESULT bool allowExternalContent() const;
Q_SIGNALS:
void urlBlocked(const QUrl &url);
protected:
Q_REQUIRED_RESULT bool urlIsAuthorized(const QUrl &requestedUrl);
Q_REQUIRED_RESULT bool urlIsBlocked(const QUrl &requestedUrl);
private:
bool mAllowLoadExternalReference = false;
Q_REQUIRED_RESULT bool urlIsAuthorized(const QUrl &requestedUrl) override;
Q_REQUIRED_RESULT bool urlIsBlocked(const QUrl &requestedUrl) override;
};
}
......@@ -51,6 +51,7 @@ set(libwebengineviewer_interceptor_SRCS
urlinterceptor/networkurlinterceptormanager.cpp
urlinterceptor/networkpluginurlinterceptorconfigurewidget.cpp
urlinterceptor/blockmailtrackingurlinterceptor/blockmailtrackingurlinterceptor.cpp
urlinterceptor/loadexternalreferencesurlinterceptor/loadexternalreferencesurlinterceptor.cpp
)
set(libwebengineviewer_accesskey_SRCS
......@@ -204,6 +205,14 @@ ecm_generate_headers(WebEngineViewer_Camelblockmailtrackingurlinterceptor_HEADER
RELATIVE urlinterceptor/blockmailtrackingurlinterceptor/
)
ecm_generate_headers(WebEngineViewer_Camelloadexternalreferencesurlinterceptor_HEADERS
HEADER_NAMES
LoadExternalReferencesUrlInterceptor
REQUIRED_HEADERS WebEngineViewer_loadexternalreferencesurlinterceptor_HEADERS
PREFIX WebEngineViewer
RELATIVE urlinterceptor/loadexternalreferencesurlinterceptor/
)
ecm_generate_pri_file(BASE_NAME WebEngineViewer
LIB_NAME KF5WebEngineViewer
......@@ -212,6 +221,7 @@ ecm_generate_pri_file(BASE_NAME WebEngineViewer
install(FILES
${WebEngineViewer_Camelloadexternalreferencesurlinterceptor_HEADERS}
${WebEngineViewer_Camelblockmailtrackingurlinterceptor_HEADERS}
${WebEngineViewer_Camelcasewebengine_checkurl_HEADERS}
${WebEngineViewer_Camelcasewebengine_accesskey_HEADERS}
......@@ -226,6 +236,7 @@ install(FILES
)
install(FILES
${WebEngineViewer_loadexternalreferencesurlinterceptor_HEADERS}
${WebEngineViewer_blockmailtrackingurlinterceptor_HEADERS}
${WebEngineViewer_webengine_checkurl_HEADERS}
${WebEngineViewer_webengine_accesskey_HEADERS}
......
/*
SPDX-FileCopyrightText: 2016-2021 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "loadexternalreferencesurlinterceptor.h"
#include <QDebug>
#include <QWebEngineUrlRequestInfo>
using namespace WebEngineViewer;
LoadExternalReferencesUrlInterceptor::LoadExternalReferencesUrlInterceptor(QObject *parent)
: WebEngineViewer::NetworkPluginUrlInterceptorInterface(parent)
{
}
LoadExternalReferencesUrlInterceptor::~LoadExternalReferencesUrlInterceptor()
{
}
bool LoadExternalReferencesUrlInterceptor::interceptRequest(QWebEngineUrlRequestInfo &info)
{
const QUrl requestUrl = info.requestUrl();
const QString scheme = requestUrl.scheme();
if (scheme == QLatin1String("data") || scheme == QLatin1String("file")) {
return false;
}
const QWebEngineUrlRequestInfo::ResourceType resourceType{info.resourceType()};
if (mAllowLoadExternalReference) {
if (resourceType == QWebEngineUrlRequestInfo::ResourceTypeImage && !requestUrl.isLocalFile() && (scheme != QLatin1String("cid"))) {
return urlIsBlocked(requestUrl);
}
return false;
} else {
if (resourceType == QWebEngineUrlRequestInfo::ResourceTypeImage && !requestUrl.isLocalFile() && (scheme != QLatin1String("cid"))) {
return urlIsAuthorized(requestUrl);
} else if (resourceType == QWebEngineUrlRequestInfo::ResourceTypeFontResource) {
return true;
} else if (resourceType == QWebEngineUrlRequestInfo::ResourceTypeStylesheet) {
return true;
}
}
return false;
}
bool LoadExternalReferencesUrlInterceptor::urlIsBlocked(const QUrl &requestedUrl)
{
Q_UNUSED(requestedUrl)
return false;
}
bool LoadExternalReferencesUrlInterceptor::urlIsAuthorized(const QUrl &requestedUrl)
{
Q_UNUSED(requestedUrl)
return true;
}
void LoadExternalReferencesUrlInterceptor::setAllowExternalContent(bool b)
{
mAllowLoadExternalReference = b;
}
bool LoadExternalReferencesUrlInterceptor::allowExternalContent() const
{
return mAllowLoadExternalReference;
}
/*
SPDX-FileCopyrightText: 2016-2021 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#pragma once
#include "webengineviewer_export.h"
#include <WebEngineViewer/NetworkPluginUrlInterceptorInterface>
namespace WebEngineViewer
{
class WEBENGINEVIEWER_EXPORT LoadExternalReferencesUrlInterceptor : public WebEngineViewer::NetworkPluginUrlInterceptorInterface
{
Q_OBJECT
public:
explicit LoadExternalReferencesUrlInterceptor(QObject *parent = nullptr);
~LoadExternalReferencesUrlInterceptor() override;
Q_REQUIRED_RESULT bool interceptRequest(QWebEngineUrlRequestInfo &info) override;
void setAllowExternalContent(bool b);
Q_REQUIRED_RESULT bool allowExternalContent() const;
Q_SIGNALS:
void urlBlocked(const QUrl &url);
protected:
virtual Q_REQUIRED_RESULT bool urlIsAuthorized(const QUrl &requestedUrl);
virtual Q_REQUIRED_RESULT bool urlIsBlocked(const QUrl &requestedUrl);
private:
bool mAllowLoadExternalReference = false;
};
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment