Messagelib

webengineviewer/src/urlinterceptor/loadexternalreferencesurlinterceptor/loadexternalreferencesurlinterceptor.cpp
1/*
2 SPDX-FileCopyrightText: 2016-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "loadexternalreferencesurlinterceptor.h"
8#include <QWebEngineUrlRequestInfo>
9
10using namespace WebEngineViewer;
11
12LoadExternalReferencesUrlInterceptor::LoadExternalReferencesUrlInterceptor(QObject *parent)
13 : WebEngineViewer::NetworkPluginUrlInterceptorInterface(parent)
14{
15}
16
17LoadExternalReferencesUrlInterceptor::~LoadExternalReferencesUrlInterceptor() = default;
18
19bool LoadExternalReferencesUrlInterceptor::interceptRequest(QWebEngineUrlRequestInfo &info)
20{
21 const QUrl requestUrl = info.requestUrl();
22 const QString scheme = requestUrl.scheme();
23 if (scheme == QLatin1StringView("data") || scheme == QLatin1StringView("file") || scheme == QLatin1StringView("qrc")) {
24 return false;
25 }
26 const QWebEngineUrlRequestInfo::ResourceType resourceType{info.resourceType()};
27 if (mAllowLoadExternalReference) {
28 if (resourceType == QWebEngineUrlRequestInfo::ResourceTypeImage && !requestUrl.isLocalFile() && (scheme != QLatin1StringView("cid"))) {
29 return urlIsBlocked(requestUrl);
30 }
31 return false;
32 } else {
33 if (resourceType == QWebEngineUrlRequestInfo::ResourceTypeImage && !requestUrl.isLocalFile() && (scheme != QLatin1StringView("cid"))) {
34 return urlIsAuthorized(requestUrl);
35 } else if (resourceType == QWebEngineUrlRequestInfo::ResourceTypeFontResource) {
36 return true;
37 } else if (resourceType == QWebEngineUrlRequestInfo::ResourceTypeStylesheet) {
38 return true;
39 }
40 }
41 return false;
42}
43
44bool LoadExternalReferencesUrlInterceptor::urlIsBlocked(const QUrl &requestedUrl)
45{
46 Q_UNUSED(requestedUrl)
47 return false;
48}
49
50bool LoadExternalReferencesUrlInterceptor::urlIsAuthorized(const QUrl &requestedUrl)
51{
52 Q_UNUSED(requestedUrl)
53 return true;
54}
55
56void LoadExternalReferencesUrlInterceptor::setAllowExternalContent(bool b)
57{
58 mAllowLoadExternalReference = b;
59}
60
61bool LoadExternalReferencesUrlInterceptor::allowExternalContent() const
62{
63 return mAllowLoadExternalReference;
64}
65
66#include "moc_loadexternalreferencesurlinterceptor.cpp"
bool isLocalFile() const const
QString scheme() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 19 2024 11:56:57 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.