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 "networkurlinterceptormanager.h"
0008 #include "networkurlinterceptorpluginmanager.h"
0009 
0010 using namespace WebEngineViewer;
0011 
0012 class WebEngineViewer::NetworkUrlInterceptorManagerPrivate
0013 {
0014 public:
0015     NetworkUrlInterceptorManagerPrivate(QWebEngineView *webEngine, KActionCollection *ac, NetworkUrlInterceptorManager *qq)
0016         : q(qq)
0017     {
0018         createInterfaces(webEngine, ac);
0019     }
0020 
0021     [[nodiscard]] QList<QAction *> interceptorUrlActions(const WebEngineViewer::WebHitTestResult &result) const;
0022     void createInterfaces(QWebEngineView *webEngine, KActionCollection *ac);
0023     QList<WebEngineViewer::NetworkPluginUrlInterceptorInterface *> mListInterface;
0024 
0025 private:
0026     NetworkUrlInterceptorManager *const q;
0027 };
0028 
0029 QList<QAction *> NetworkUrlInterceptorManagerPrivate::interceptorUrlActions(const WebEngineViewer::WebHitTestResult &result) const
0030 {
0031     QList<QAction *> lstActions;
0032     for (WebEngineViewer::NetworkPluginUrlInterceptorInterface *interface : std::as_const(mListInterface)) {
0033         lstActions.append(interface->interceptorUrlActions(result));
0034     }
0035     return lstActions;
0036 }
0037 
0038 void NetworkUrlInterceptorManagerPrivate::createInterfaces(QWebEngineView *webEngine, KActionCollection *ac)
0039 {
0040     const auto pluginsList = NetworkUrlInterceptorPluginManager::self()->pluginsList();
0041     for (NetworkPluginUrlInterceptor *plugin : pluginsList) {
0042         if (plugin->isEnabled()) {
0043             WebEngineViewer::NetworkPluginUrlInterceptorInterface *interface = plugin->createInterface(webEngine, q);
0044             interface->createActions(ac);
0045             mListInterface.append(interface);
0046         }
0047     }
0048 }
0049 
0050 NetworkUrlInterceptorManager::NetworkUrlInterceptorManager(QWebEngineView *webEngine, KActionCollection *ac, QObject *parent)
0051     : QObject(parent)
0052     , d(new NetworkUrlInterceptorManagerPrivate(webEngine, ac, this))
0053 {
0054 }
0055 
0056 NetworkUrlInterceptorManager::~NetworkUrlInterceptorManager() = default;
0057 
0058 QList<WebEngineViewer::NetworkPluginUrlInterceptorInterface *> NetworkUrlInterceptorManager::interfaceList() const
0059 {
0060     return d->mListInterface;
0061 }
0062 
0063 QList<QAction *> NetworkUrlInterceptorManager::interceptorUrlActions(const WebEngineViewer::WebHitTestResult &result) const
0064 {
0065     return d->interceptorUrlActions(result);
0066 }
0067 
0068 #include "moc_networkurlinterceptormanager.cpp"