File indexing completed on 2025-03-09 04:54:39

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 "remote-content/remotecontentmanager.h"
0009 
0010 using namespace MessageViewer;
0011 
0012 LoadExternalReferencesUrlInterceptor::LoadExternalReferencesUrlInterceptor(QObject *parent)
0013     : WebEngineViewer::LoadExternalReferencesUrlInterceptor(parent)
0014 {
0015 }
0016 
0017 LoadExternalReferencesUrlInterceptor::~LoadExternalReferencesUrlInterceptor() = default;
0018 bool LoadExternalReferencesUrlInterceptor::urlIsBlocked(const QUrl &requestedUrl)
0019 {
0020     const QUrl url = requestedUrl.adjusted(QUrl::RemovePath | QUrl::RemovePort | QUrl::RemoveQuery);
0021     bool contains = false;
0022     if (MessageViewer::RemoteContentManager::self()->isBlocked(url, contains)) {
0023         return true;
0024     }
0025     return false;
0026 }
0027 
0028 bool LoadExternalReferencesUrlInterceptor::urlIsAuthorized(const QUrl &requestedUrl)
0029 {
0030     const QUrl url = requestedUrl.adjusted(QUrl::RemovePath | QUrl::RemovePort | QUrl::RemoveQuery);
0031     bool contains = false;
0032     if (MessageViewer::RemoteContentManager::self()->isAutorized(url, contains)) {
0033         return false;
0034     }
0035     if (!contains) {
0036         Q_EMIT urlBlocked(requestedUrl);
0037     }
0038     return true;
0039 }
0040 
0041 #include "moc_loadexternalreferencesurlinterceptor.cpp"