mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 18:56:34 +01:00
AdBlock: Bring back support for adding new subscription with abp: links
This commit is contained in:
parent
79dd0d5899
commit
5829318774
@ -21,6 +21,7 @@
|
|||||||
#include "mainapplication.h"
|
#include "mainapplication.h"
|
||||||
#include "passwordmanager.h"
|
#include "passwordmanager.h"
|
||||||
#include "sslerrordialog.h"
|
#include "sslerrordialog.h"
|
||||||
|
#include "network/schemehandlers/adblockschemehandler.h"
|
||||||
#include "network/schemehandlers/qupzillaschemehandler.h"
|
#include "network/schemehandlers/qupzillaschemehandler.h"
|
||||||
|
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
@ -39,6 +40,7 @@ NetworkManager::NetworkManager(QObject *parent)
|
|||||||
: QNetworkAccessManager(parent)
|
: QNetworkAccessManager(parent)
|
||||||
{
|
{
|
||||||
// Create scheme handlers
|
// Create scheme handlers
|
||||||
|
mApp->webProfile()->installUrlSchemeHandler(new AdBlockSchemeHandler(this));
|
||||||
mApp->webProfile()->installUrlSchemeHandler(new QupZillaSchemeHandler(this));
|
mApp->webProfile()->installUrlSchemeHandler(new QupZillaSchemeHandler(this));
|
||||||
|
|
||||||
connect(this, &QNetworkAccessManager::authenticationRequired, this, [this](QNetworkReply *reply, QAuthenticator *auth) {
|
connect(this, &QNetworkAccessManager::authenticationRequired, this, [this](QNetworkReply *reply, QAuthenticator *auth) {
|
||||||
|
@ -19,25 +19,18 @@
|
|||||||
#include "adblockmanager.h"
|
#include "adblockmanager.h"
|
||||||
#include "emptynetworkreply.h"
|
#include "emptynetworkreply.h"
|
||||||
|
|
||||||
#include <QNetworkRequest>
|
|
||||||
#include <QMessageBox>
|
|
||||||
|
|
||||||
#include <QUrlQuery>
|
#include <QUrlQuery>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QWebEngineUrlRequestJob>
|
||||||
|
|
||||||
AdBlockSchemeHandler::AdBlockSchemeHandler()
|
AdBlockSchemeHandler::AdBlockSchemeHandler(QObject *parent)
|
||||||
: SchemeHandler()
|
: QWebEngineUrlSchemeHandler(QByteArrayLiteral("abp"), parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QNetworkReply* AdBlockSchemeHandler::createRequest(QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice* outgoingData)
|
void AdBlockSchemeHandler::requestStarted(QWebEngineUrlRequestJob *job)
|
||||||
{
|
{
|
||||||
Q_UNUSED(outgoingData)
|
const QUrl url = job->requestUrl();
|
||||||
|
|
||||||
if (op != QNetworkAccessManager::GetOperation) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QUrl url = request.url();
|
|
||||||
const QList<QPair<QString, QString> > queryItems = QUrlQuery(url).queryItems();
|
const QList<QPair<QString, QString> > queryItems = QUrlQuery(url).queryItems();
|
||||||
|
|
||||||
QString subscriptionTitle;
|
QString subscriptionTitle;
|
||||||
@ -45,16 +38,17 @@ QNetworkReply* AdBlockSchemeHandler::createRequest(QNetworkAccessManager::Operat
|
|||||||
|
|
||||||
for (int i = 0; i < queryItems.count(); ++i) {
|
for (int i = 0; i < queryItems.count(); ++i) {
|
||||||
QPair<QString, QString> pair = queryItems.at(i);
|
QPair<QString, QString> pair = queryItems.at(i);
|
||||||
if (pair.first == QLatin1String("location")) {
|
if (pair.first == QL1S("location")) {
|
||||||
subscriptionUrl = pair.second;
|
subscriptionUrl = pair.second;
|
||||||
}
|
}
|
||||||
else if (pair.first == QLatin1String("title")) {
|
else if (pair.first == QL1S("title")) {
|
||||||
subscriptionTitle = pair.second;
|
subscriptionTitle = pair.second;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (subscriptionTitle.isEmpty() || subscriptionUrl.isEmpty()) {
|
if (subscriptionTitle.isEmpty() || subscriptionUrl.isEmpty()) {
|
||||||
return 0;
|
job->setError(QWebEngineUrlRequestJob::RequestAborted);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString message = AdBlockManager::tr("Do you want to add <b>%1</b> subscription?").arg(subscriptionTitle);
|
const QString message = AdBlockManager::tr("Do you want to add <b>%1</b> subscription?").arg(subscriptionTitle);
|
||||||
@ -65,5 +59,5 @@ QNetworkReply* AdBlockSchemeHandler::createRequest(QNetworkAccessManager::Operat
|
|||||||
AdBlockManager::instance()->showDialog();
|
AdBlockManager::instance()->showDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
return new EmptyNetworkReply;
|
job->setError(QWebEngineUrlRequestJob::RequestAborted);
|
||||||
}
|
}
|
||||||
|
@ -18,15 +18,16 @@
|
|||||||
#ifndef ADBLOCKSCHEMEHANDLER_H
|
#ifndef ADBLOCKSCHEMEHANDLER_H
|
||||||
#define ADBLOCKSCHEMEHANDLER_H
|
#define ADBLOCKSCHEMEHANDLER_H
|
||||||
|
|
||||||
#include "qzcommon.h"
|
#include <QWebEngineUrlSchemeHandler>
|
||||||
#include "schemehandler.h"
|
|
||||||
|
|
||||||
class QUPZILLA_EXPORT AdBlockSchemeHandler : public SchemeHandler
|
#include "qzcommon.h"
|
||||||
|
|
||||||
|
class QUPZILLA_EXPORT AdBlockSchemeHandler : public QWebEngineUrlSchemeHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AdBlockSchemeHandler();
|
explicit AdBlockSchemeHandler(QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
QNetworkReply* createRequest(QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice* outgoingData);
|
void requestStarted(QWebEngineUrlRequestJob *job) Q_DECL_OVERRIDE;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ADBLOCKSCHEMEHANDLER_H
|
#endif // ADBLOCKSCHEMEHANDLER_H
|
||||||
|
@ -18,9 +18,9 @@
|
|||||||
#ifndef QUPZILLASCHEMEHANDLER_H
|
#ifndef QUPZILLASCHEMEHANDLER_H
|
||||||
#define QUPZILLASCHEMEHANDLER_H
|
#define QUPZILLASCHEMEHANDLER_H
|
||||||
|
|
||||||
#include <QWebEngineUrlSchemeHandler>
|
|
||||||
#include <QBuffer>
|
#include <QBuffer>
|
||||||
#include <QIODevice>
|
#include <QIODevice>
|
||||||
|
#include <QWebEngineUrlSchemeHandler>
|
||||||
|
|
||||||
#include "qzcommon.h"
|
#include "qzcommon.h"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user