Messagelib

networkurlinterceptor.cpp
1 /*
2  SPDX-FileCopyrightText: 2016-2021 Laurent Montel <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "networkurlinterceptor.h"
8 #include "networkpluginurlinterceptorinterface.h"
9 #include "webengineviewer_debug.h"
10 
11 #include <QVector>
12 
13 using namespace WebEngineViewer;
14 
15 class WebEngineViewer::NetworkUrlInterceptorPrivate
16 {
17 public:
18  NetworkUrlInterceptorPrivate() = default;
19 
20  void addInterceptor(NetworkPluginUrlInterceptorInterface *interceptor);
21  void interceptRequest(QWebEngineUrlRequestInfo &info);
22  void removeInterceptor(NetworkPluginUrlInterceptorInterface *interceptor);
24 };
25 
26 void NetworkUrlInterceptorPrivate::addInterceptor(NetworkPluginUrlInterceptorInterface *interceptor)
27 {
28  if (!listInterceptor.contains(interceptor)) {
29  listInterceptor.append(interceptor);
30  }
31 }
32 
33 void NetworkUrlInterceptorPrivate::removeInterceptor(NetworkPluginUrlInterceptorInterface *interceptor)
34 {
35  if (listInterceptor.contains(interceptor)) {
36  listInterceptor.removeOne(interceptor);
37  }
38 }
39 
40 void NetworkUrlInterceptorPrivate::interceptRequest(QWebEngineUrlRequestInfo &info)
41 {
42  for (NetworkPluginUrlInterceptorInterface *inter : std::as_const(listInterceptor)) {
43  if (inter->interceptRequest(info)) {
44  info.block(true);
45  break;
46  }
47  }
48 }
49 
50 NetworkUrlInterceptor::NetworkUrlInterceptor(QObject *parent)
51  : QWebEngineUrlRequestInterceptor(parent)
52  , d(new NetworkUrlInterceptorPrivate)
53 {
54 }
55 
56 NetworkUrlInterceptor::~NetworkUrlInterceptor() = default;
57 
58 void NetworkUrlInterceptor::interceptRequest(QWebEngineUrlRequestInfo &info)
59 {
60  d->interceptRequest(info);
61 }
62 
63 void NetworkUrlInterceptor::addInterceptor(NetworkPluginUrlInterceptorInterface *interceptor)
64 {
65  d->addInterceptor(interceptor);
66 }
67 
68 void NetworkUrlInterceptor::removeInterceptor(NetworkPluginUrlInterceptorInterface *interceptor)
69 {
70  d->removeInterceptor(interceptor);
71 }
void append(const T &value)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Dec 4 2021 23:12:54 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.