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"