Messagelib

networkurlinterceptor.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 "networkurlinterceptor.h"
8#include "networkpluginurlinterceptorinterface.h"
9
10#include <QDebug>
11#include <QList>
12
13using namespace WebEngineViewer;
14
15class WebEngineViewer::NetworkUrlInterceptorPrivate
16{
17public:
18 NetworkUrlInterceptorPrivate() = default;
19
20 void addInterceptor(NetworkPluginUrlInterceptorInterface *interceptor);
21 void interceptRequest(QWebEngineUrlRequestInfo &info);
22 void removeInterceptor(NetworkPluginUrlInterceptorInterface *interceptor);
24};
25
26void NetworkUrlInterceptorPrivate::addInterceptor(NetworkPluginUrlInterceptorInterface *interceptor)
27{
28 if (!listInterceptor.contains(interceptor)) {
29 listInterceptor.append(interceptor);
30 }
31}
32
33void NetworkUrlInterceptorPrivate::removeInterceptor(NetworkPluginUrlInterceptorInterface *interceptor)
34{
35 if (listInterceptor.contains(interceptor)) {
36 listInterceptor.removeOne(interceptor);
37 }
38}
39
40void NetworkUrlInterceptorPrivate::interceptRequest(QWebEngineUrlRequestInfo &info)
41{
42 for (NetworkPluginUrlInterceptorInterface *inter : std::as_const(listInterceptor)) {
43 if (inter->interceptRequest(info)) {
44 // qDebug() << " intercep " << info.requestUrl() << " inter " << inter;
45 info.block(true);
46 break;
47 }
48 }
49}
50
51NetworkUrlInterceptor::NetworkUrlInterceptor(QObject *parent)
52 : QWebEngineUrlRequestInterceptor(parent)
53 , d(new NetworkUrlInterceptorPrivate)
54{
55}
56
57NetworkUrlInterceptor::~NetworkUrlInterceptor() = default;
58
59void NetworkUrlInterceptor::interceptRequest(QWebEngineUrlRequestInfo &info)
60{
61 d->interceptRequest(info);
62}
63
64void NetworkUrlInterceptor::addInterceptor(NetworkPluginUrlInterceptorInterface *interceptor)
65{
66 d->addInterceptor(interceptor);
67}
68
69void NetworkUrlInterceptor::removeInterceptor(NetworkPluginUrlInterceptorInterface *interceptor)
70{
71 d->removeInterceptor(interceptor);
72}
73
74#include "moc_networkurlinterceptor.cpp"
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:33:26 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.