1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 02:36:34 +01:00

AdBlock: Bring back support for adding new subscription with abp: links

This commit is contained in:
David Rosca 2015-10-05 18:54:58 +02:00
parent 79dd0d5899
commit 5829318774
4 changed files with 20 additions and 23 deletions

View File

@ -21,6 +21,7 @@
#include "mainapplication.h"
#include "passwordmanager.h"
#include "sslerrordialog.h"
#include "network/schemehandlers/adblockschemehandler.h"
#include "network/schemehandlers/qupzillaschemehandler.h"
#include <QLabel>
@ -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) {

View File

@ -19,25 +19,18 @@
#include "adblockmanager.h"
#include "emptynetworkreply.h"
#include <QNetworkRequest>
#include <QMessageBox>
#include <QUrlQuery>
#include <QMessageBox>
#include <QWebEngineUrlRequestJob>
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<QPair<QString, QString> > queryItems = QUrlQuery(url).queryItems();
QString subscriptionTitle;
@ -45,16 +38,17 @@ QNetworkReply* AdBlockSchemeHandler::createRequest(QNetworkAccessManager::Operat
for (int i = 0; i < queryItems.count(); ++i) {
QPair<QString, QString> 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 <b>%1</b> subscription?").arg(subscriptionTitle);
@ -65,5 +59,5 @@ QNetworkReply* AdBlockSchemeHandler::createRequest(QNetworkAccessManager::Operat
AdBlockManager::instance()->showDialog();
}
return new EmptyNetworkReply;
job->setError(QWebEngineUrlRequestJob::RequestAborted);
}

View File

@ -18,15 +18,16 @@
#ifndef ADBLOCKSCHEMEHANDLER_H
#define ADBLOCKSCHEMEHANDLER_H
#include "qzcommon.h"
#include "schemehandler.h"
#include <QWebEngineUrlSchemeHandler>
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

View File

@ -18,9 +18,9 @@
#ifndef QUPZILLASCHEMEHANDLER_H
#define QUPZILLASCHEMEHANDLER_H
#include <QWebEngineUrlSchemeHandler>
#include <QBuffer>
#include <QIODevice>
#include <QWebEngineUrlSchemeHandler>
#include "qzcommon.h"