Messagelib

interceptormanager.cpp
1 /*
2  SPDX-FileCopyrightText: 2016-2021 Laurent Montel <[email protected]>
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 
13 using namespace WebEngineViewer;
14 
15 class WebEngineViewer::NetworkAccessManagerWebEnginePrivate
16 {
17 public:
18  NetworkAccessManagerWebEnginePrivate() = default;
19 
21  WebEngineViewer::NetworkUrlInterceptor *mNetworkUrlInterceptor = nullptr;
22 };
23 
24 InterceptorManager::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 
39 InterceptorManager::~InterceptorManager() = default;
40 
41 void InterceptorManager::addInterceptor(WebEngineViewer::NetworkPluginUrlInterceptorInterface *interceptor)
42 {
43  d->mNetworkUrlInterceptor->addInterceptor(interceptor);
44 }
45 
46 void InterceptorManager::removeInterceptor(WebEngineViewer::NetworkPluginUrlInterceptorInterface *interceptor)
47 {
48  d->mNetworkUrlInterceptor->removeInterceptor(interceptor);
49 }
50 
51 QList<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 }
void reserve(int alloc)
The WebHitTestResult class.
void append(const T &value)
The NetworkUrlInterceptor class.
The NetworkUrlInterceptorManager class.
void result(KJob *job)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Nov 30 2021 23:05:46 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.