mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 10:46:35 +01:00
Add UrlInterceptor interface
This commit is contained in:
parent
a6c9ca7b4c
commit
40eb1281f8
@ -131,6 +131,7 @@ SOURCES += \
|
||||
#network/cabundleupdater.cpp \
|
||||
network/networkmanager.cpp \
|
||||
network/networkproxyfactory.cpp \
|
||||
network/networkurlinterceptor.cpp \
|
||||
network/pac/pacmanager.cpp \
|
||||
network/pac/proxyautoconfig.cpp \
|
||||
network/schemehandlers/adblockschemehandler.cpp \
|
||||
@ -324,6 +325,7 @@ HEADERS += \
|
||||
#network/cabundleupdater.h \
|
||||
network/networkmanager.h \
|
||||
network/networkproxyfactory.h \
|
||||
network/networkurlinterceptor.h \
|
||||
network/pac/pacdatetime.h \
|
||||
network/pac/pacmanager.h \
|
||||
network/pac/proxyautoconfig.h \
|
||||
@ -331,6 +333,7 @@ HEADERS += \
|
||||
#network/schemehandlers/fileschemehandler.h \
|
||||
network/schemehandlers/qupzillaschemehandler.h \
|
||||
network/schemehandlers/schemehandler.h \
|
||||
network/urlinterceptor.h \
|
||||
network/sslerrordialog.h \
|
||||
notifications/desktopnotification.h \
|
||||
notifications/desktopnotificationsfactory.h \
|
||||
|
@ -21,8 +21,9 @@
|
||||
#include "mainapplication.h"
|
||||
#include "passwordmanager.h"
|
||||
#include "sslerrordialog.h"
|
||||
#include "network/schemehandlers/adblockschemehandler.h"
|
||||
#include "network/schemehandlers/qupzillaschemehandler.h"
|
||||
#include "networkurlinterceptor.h"
|
||||
#include "schemehandlers/adblockschemehandler.h"
|
||||
#include "schemehandlers/qupzillaschemehandler.h"
|
||||
|
||||
#include <QLabel>
|
||||
#include <QDialog>
|
||||
@ -43,6 +44,10 @@ NetworkManager::NetworkManager(QObject *parent)
|
||||
mApp->webProfile()->installUrlSchemeHandler(new AdBlockSchemeHandler(this));
|
||||
mApp->webProfile()->installUrlSchemeHandler(new QupZillaSchemeHandler(this));
|
||||
|
||||
// Create url interceptor
|
||||
m_urlInterceptor = new NetworkUrlInterceptor(this);
|
||||
mApp->webProfile()->setRequestInterceptor(m_urlInterceptor);
|
||||
|
||||
connect(this, &QNetworkAccessManager::authenticationRequired, this, [this](QNetworkReply *reply, QAuthenticator *auth) {
|
||||
authentication(reply->url(), auth);
|
||||
});
|
||||
@ -207,3 +212,13 @@ void NetworkManager::proxyAuthentication(const QString &proxyHost, QAuthenticato
|
||||
auth->setUser(user->text());
|
||||
auth->setPassword(pass->text());
|
||||
}
|
||||
|
||||
void NetworkManager::installUrlInterceptor(UrlInterceptor *interceptor)
|
||||
{
|
||||
m_urlInterceptor->installUrlInterceptor(interceptor);
|
||||
}
|
||||
|
||||
void NetworkManager::removeUrlInterceptor(UrlInterceptor *interceptor)
|
||||
{
|
||||
m_urlInterceptor->removeUrlInterceptor(interceptor);
|
||||
}
|
||||
|
@ -23,6 +23,9 @@
|
||||
|
||||
#include "qzcommon.h"
|
||||
|
||||
class UrlInterceptor;
|
||||
class NetworkUrlInterceptor;
|
||||
|
||||
class QUPZILLA_EXPORT NetworkManager : public QNetworkAccessManager
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -34,7 +37,11 @@ public:
|
||||
void authentication(const QUrl &url, QAuthenticator *auth, QWidget *parent = Q_NULLPTR);
|
||||
void proxyAuthentication(const QString &proxyHost, QAuthenticator *auth, QWidget *parent = Q_NULLPTR);
|
||||
|
||||
void installUrlInterceptor(UrlInterceptor *interceptor);
|
||||
void removeUrlInterceptor(UrlInterceptor *interceptor);
|
||||
|
||||
private:
|
||||
NetworkUrlInterceptor *m_urlInterceptor;
|
||||
QHash<QString, QWebEngineCertificateError::Error> m_ignoredSslErrors;
|
||||
};
|
||||
|
||||
|
46
src/lib/network/networkurlinterceptor.cpp
Normal file
46
src/lib/network/networkurlinterceptor.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
/* ============================================================
|
||||
* QupZilla - QtWebEngine based browser
|
||||
* Copyright (C) 2015 David Rosca <nowrep@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
|
||||
#include "networkurlinterceptor.h"
|
||||
#include "urlinterceptor.h"
|
||||
|
||||
NetworkUrlInterceptor::NetworkUrlInterceptor(QObject *parent)
|
||||
: QWebEngineUrlRequestInterceptor(parent)
|
||||
{
|
||||
}
|
||||
|
||||
bool NetworkUrlInterceptor::interceptRequest(QWebEngineUrlRequestInfo &info)
|
||||
{
|
||||
foreach (UrlInterceptor *interceptor, m_interceptors) {
|
||||
if (interceptor->interceptRequest(info))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void NetworkUrlInterceptor::installUrlInterceptor(UrlInterceptor *interceptor)
|
||||
{
|
||||
if (!m_interceptors.contains(interceptor))
|
||||
m_interceptors.append(interceptor);
|
||||
}
|
||||
|
||||
void NetworkUrlInterceptor::removeUrlInterceptor(UrlInterceptor *interceptor)
|
||||
{
|
||||
m_interceptors.removeOne(interceptor);
|
||||
}
|
42
src/lib/network/networkurlinterceptor.h
Normal file
42
src/lib/network/networkurlinterceptor.h
Normal file
@ -0,0 +1,42 @@
|
||||
/* ============================================================
|
||||
* QupZilla - QtWebEngine based browser
|
||||
* Copyright (C) 2015 David Rosca <nowrep@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
|
||||
#ifndef NETWORKURLINTERCEPTOR_H
|
||||
#define NETWORKURLINTERCEPTOR_H
|
||||
|
||||
#include <QWebEngineUrlRequestInterceptor>
|
||||
|
||||
#include "qzcommon.h"
|
||||
|
||||
class UrlInterceptor;
|
||||
|
||||
class QUPZILLA_EXPORT NetworkUrlInterceptor : public QWebEngineUrlRequestInterceptor
|
||||
{
|
||||
public:
|
||||
explicit NetworkUrlInterceptor(QObject* parent = Q_NULLPTR);
|
||||
|
||||
bool interceptRequest(QWebEngineUrlRequestInfo &info);
|
||||
|
||||
void installUrlInterceptor(UrlInterceptor *interceptor);
|
||||
void removeUrlInterceptor(UrlInterceptor *interceptor);
|
||||
|
||||
private:
|
||||
QList<UrlInterceptor*> m_interceptors;
|
||||
};
|
||||
|
||||
#endif // NETWORKURLINTERCEPTOR_H
|
32
src/lib/network/urlinterceptor.h
Normal file
32
src/lib/network/urlinterceptor.h
Normal file
@ -0,0 +1,32 @@
|
||||
/* ============================================================
|
||||
* QupZilla - QtWebEngine based browser
|
||||
* Copyright (C) 2015 David Rosca <nowrep@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
|
||||
#ifndef URLINTERCEPTOR_H
|
||||
#define URLINTERCEPTOR_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QWebEngineUrlRequestInfo>
|
||||
|
||||
class UrlInterceptor : public QObject
|
||||
{
|
||||
public:
|
||||
explicit UrlInterceptor(QObject *parent = Q_NULLPTR) : QObject(parent) { }
|
||||
virtual bool interceptRequest(QWebEngineUrlRequestInfo &info) = 0;
|
||||
};
|
||||
|
||||
#endif // URLINTERCEPTOR_H
|
Loading…
Reference in New Issue
Block a user