File indexing completed on 2025-01-26 04:57:24
0001 /* 0002 SPDX-FileCopyrightText: 2016-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "loadexternalreferencesurlinterceptor.h" 0008 #include <QWebEngineUrlRequestInfo> 0009 0010 using namespace WebEngineViewer; 0011 0012 LoadExternalReferencesUrlInterceptor::LoadExternalReferencesUrlInterceptor(QObject *parent) 0013 : WebEngineViewer::NetworkPluginUrlInterceptorInterface(parent) 0014 { 0015 } 0016 0017 LoadExternalReferencesUrlInterceptor::~LoadExternalReferencesUrlInterceptor() = default; 0018 0019 bool LoadExternalReferencesUrlInterceptor::interceptRequest(QWebEngineUrlRequestInfo &info) 0020 { 0021 const QUrl requestUrl = info.requestUrl(); 0022 const QString scheme = requestUrl.scheme(); 0023 if (scheme == QLatin1StringView("data") || scheme == QLatin1StringView("file")) { 0024 return false; 0025 } 0026 const QWebEngineUrlRequestInfo::ResourceType resourceType{info.resourceType()}; 0027 if (mAllowLoadExternalReference) { 0028 if (resourceType == QWebEngineUrlRequestInfo::ResourceTypeImage && !requestUrl.isLocalFile() && (scheme != QLatin1StringView("cid"))) { 0029 return urlIsBlocked(requestUrl); 0030 } 0031 return false; 0032 } else { 0033 if (resourceType == QWebEngineUrlRequestInfo::ResourceTypeImage && !requestUrl.isLocalFile() && (scheme != QLatin1StringView("cid"))) { 0034 return urlIsAuthorized(requestUrl); 0035 } else if (resourceType == QWebEngineUrlRequestInfo::ResourceTypeFontResource) { 0036 return true; 0037 } else if (resourceType == QWebEngineUrlRequestInfo::ResourceTypeStylesheet) { 0038 return true; 0039 } 0040 } 0041 return false; 0042 } 0043 0044 bool LoadExternalReferencesUrlInterceptor::urlIsBlocked(const QUrl &requestedUrl) 0045 { 0046 Q_UNUSED(requestedUrl) 0047 return false; 0048 } 0049 0050 bool LoadExternalReferencesUrlInterceptor::urlIsAuthorized(const QUrl &requestedUrl) 0051 { 0052 Q_UNUSED(requestedUrl) 0053 return true; 0054 } 0055 0056 void LoadExternalReferencesUrlInterceptor::setAllowExternalContent(bool b) 0057 { 0058 mAllowLoadExternalReference = b; 0059 } 0060 0061 bool LoadExternalReferencesUrlInterceptor::allowExternalContent() const 0062 { 0063 return mAllowLoadExternalReference; 0064 } 0065 0066 #include "moc_loadexternalreferencesurlinterceptor.cpp"