From 582931877471487aad2c4b38ff785ad60344896a Mon Sep 17 00:00:00 2001 From: David Rosca Date: Mon, 5 Oct 2015 18:54:58 +0200 Subject: [PATCH] AdBlock: Bring back support for adding new subscription with abp: links --- src/lib/network/networkmanager.cpp | 2 ++ .../schemehandlers/adblockschemehandler.cpp | 28 ++++++++----------- .../schemehandlers/adblockschemehandler.h | 11 ++++---- .../schemehandlers/qupzillaschemehandler.h | 2 +- 4 files changed, 20 insertions(+), 23 deletions(-) diff --git a/src/lib/network/networkmanager.cpp b/src/lib/network/networkmanager.cpp index aae82e077..35a28ecbe 100644 --- a/src/lib/network/networkmanager.cpp +++ b/src/lib/network/networkmanager.cpp @@ -21,6 +21,7 @@ #include "mainapplication.h" #include "passwordmanager.h" #include "sslerrordialog.h" +#include "network/schemehandlers/adblockschemehandler.h" #include "network/schemehandlers/qupzillaschemehandler.h" #include @@ -39,6 +40,7 @@ NetworkManager::NetworkManager(QObject *parent) : QNetworkAccessManager(parent) { // Create scheme handlers + mApp->webProfile()->installUrlSchemeHandler(new AdBlockSchemeHandler(this)); mApp->webProfile()->installUrlSchemeHandler(new QupZillaSchemeHandler(this)); connect(this, &QNetworkAccessManager::authenticationRequired, this, [this](QNetworkReply *reply, QAuthenticator *auth) { diff --git a/src/lib/network/schemehandlers/adblockschemehandler.cpp b/src/lib/network/schemehandlers/adblockschemehandler.cpp index 5a45db66b..529c4495b 100644 --- a/src/lib/network/schemehandlers/adblockschemehandler.cpp +++ b/src/lib/network/schemehandlers/adblockschemehandler.cpp @@ -19,25 +19,18 @@ #include "adblockmanager.h" #include "emptynetworkreply.h" -#include -#include - #include +#include +#include -AdBlockSchemeHandler::AdBlockSchemeHandler() - : SchemeHandler() +AdBlockSchemeHandler::AdBlockSchemeHandler(QObject *parent) + : QWebEngineUrlSchemeHandler(QByteArrayLiteral("abp"), parent) { } -QNetworkReply* AdBlockSchemeHandler::createRequest(QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice* outgoingData) +void AdBlockSchemeHandler::requestStarted(QWebEngineUrlRequestJob *job) { - Q_UNUSED(outgoingData) - - if (op != QNetworkAccessManager::GetOperation) { - return 0; - } - - const QUrl url = request.url(); + const QUrl url = job->requestUrl(); const QList > queryItems = QUrlQuery(url).queryItems(); QString subscriptionTitle; @@ -45,16 +38,17 @@ QNetworkReply* AdBlockSchemeHandler::createRequest(QNetworkAccessManager::Operat for (int i = 0; i < queryItems.count(); ++i) { QPair pair = queryItems.at(i); - if (pair.first == QLatin1String("location")) { + if (pair.first == QL1S("location")) { subscriptionUrl = pair.second; } - else if (pair.first == QLatin1String("title")) { + else if (pair.first == QL1S("title")) { subscriptionTitle = pair.second; } } if (subscriptionTitle.isEmpty() || subscriptionUrl.isEmpty()) { - return 0; + job->setError(QWebEngineUrlRequestJob::RequestAborted); + return; } const QString message = AdBlockManager::tr("Do you want to add %1 subscription?").arg(subscriptionTitle); @@ -65,5 +59,5 @@ QNetworkReply* AdBlockSchemeHandler::createRequest(QNetworkAccessManager::Operat AdBlockManager::instance()->showDialog(); } - return new EmptyNetworkReply; + job->setError(QWebEngineUrlRequestJob::RequestAborted); } diff --git a/src/lib/network/schemehandlers/adblockschemehandler.h b/src/lib/network/schemehandlers/adblockschemehandler.h index 1343c8631..35e80dc75 100644 --- a/src/lib/network/schemehandlers/adblockschemehandler.h +++ b/src/lib/network/schemehandlers/adblockschemehandler.h @@ -18,15 +18,16 @@ #ifndef ADBLOCKSCHEMEHANDLER_H #define ADBLOCKSCHEMEHANDLER_H -#include "qzcommon.h" -#include "schemehandler.h" +#include -class QUPZILLA_EXPORT AdBlockSchemeHandler : public SchemeHandler +#include "qzcommon.h" + +class QUPZILLA_EXPORT AdBlockSchemeHandler : public QWebEngineUrlSchemeHandler { 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 diff --git a/src/lib/network/schemehandlers/qupzillaschemehandler.h b/src/lib/network/schemehandlers/qupzillaschemehandler.h index 2592d42d2..dcb5935d5 100644 --- a/src/lib/network/schemehandlers/qupzillaschemehandler.h +++ b/src/lib/network/schemehandlers/qupzillaschemehandler.h @@ -18,9 +18,9 @@ #ifndef QUPZILLASCHEMEHANDLER_H #define QUPZILLASCHEMEHANDLER_H -#include #include #include +#include #include "qzcommon.h"