Messagelib

interceptormanager.cpp
1/*
2 SPDX-FileCopyrightText: 2016-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6#include "interceptormanager.h"
7#include "urlinterceptor/networkurlinterceptor.h"
8#include "urlinterceptor/networkurlinterceptormanager.h"
9#include <QWebEngineProfile>
10#include <QWebEngineView>
11#include <WebEngineViewer/NetworkPluginUrlInterceptorInterface>
12
13using namespace WebEngineViewer;
14
15class WebEngineViewer::NetworkAccessManagerWebEnginePrivate
16{
17public:
18 NetworkAccessManagerWebEnginePrivate() = default;
19
21 WebEngineViewer::NetworkUrlInterceptor *mNetworkUrlInterceptor = nullptr;
22};
23
24InterceptorManager::InterceptorManager(QWebEngineView *webEngine, KActionCollection *ac, QObject *parent)
25 : QObject(parent)
26 , d(new NetworkAccessManagerWebEnginePrivate)
27{
28 d->mManager = new WebEngineViewer::NetworkUrlInterceptorManager(webEngine, ac, this);
29
30 // Add interceptor.
31 d->mNetworkUrlInterceptor = new WebEngineViewer::NetworkUrlInterceptor(this);
32 const auto interfaceList = d->mManager->interfaceList();
33 for (WebEngineViewer::NetworkPluginUrlInterceptorInterface *interface : interfaceList) {
34 d->mNetworkUrlInterceptor->addInterceptor(interface);
35 }
36 webEngine->page()->profile()->setUrlRequestInterceptor(d->mNetworkUrlInterceptor);
37}
38
39InterceptorManager::~InterceptorManager() = default;
40
41void InterceptorManager::addInterceptor(WebEngineViewer::NetworkPluginUrlInterceptorInterface *interceptor)
42{
43 d->mNetworkUrlInterceptor->addInterceptor(interceptor);
44}
45
46void InterceptorManager::removeInterceptor(WebEngineViewer::NetworkPluginUrlInterceptorInterface *interceptor)
47{
48 d->mNetworkUrlInterceptor->removeInterceptor(interceptor);
49}
50
51QList<QAction *> InterceptorManager::interceptorUrlActions(const WebEngineViewer::WebHitTestResult &result) const
52{
53 QList<QAction *> actions;
54 const auto interfaceList = d->mManager->interfaceList();
55 actions.reserve(interfaceList.count());
56 for (WebEngineViewer::NetworkPluginUrlInterceptorInterface *interface : interfaceList) {
57 actions.append(interface->interceptorUrlActions(result));
58 }
59 return actions;
60}
61
62#include "moc_interceptormanager.cpp"
The NetworkUrlInterceptor class.
The WebHitTestResult class.
void append(QList< T > &&value)
void reserve(qsizetype size)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:07:25 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.