mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 09:32:12 +01:00
Use acceptNavigationRequest to handle abp: urls
QtWebEngine now sends external urls through acceptNavigationRequest so it is no longer needed to install scheme handler.
This commit is contained in:
parent
afa59f1a45
commit
03399c7b2c
|
@ -32,6 +32,8 @@
|
|||
#include <QTextStream>
|
||||
#include <QDir>
|
||||
#include <QTimer>
|
||||
#include <QMessageBox>
|
||||
#include <QUrlQuery>
|
||||
|
||||
//#define ADBLOCK_DEBUG
|
||||
|
||||
|
@ -131,6 +133,35 @@ void AdBlockManager::removeDisabledRule(const QString &filter)
|
|||
m_disabledRules.removeOne(filter);
|
||||
}
|
||||
|
||||
bool AdBlockManager::addSubscriptionFromUrl(const QUrl &url)
|
||||
{
|
||||
const QList<QPair<QString, QString> > queryItems = QUrlQuery(url).queryItems();
|
||||
|
||||
QString subscriptionTitle;
|
||||
QString subscriptionUrl;
|
||||
|
||||
for (int i = 0; i < queryItems.count(); ++i) {
|
||||
QPair<QString, QString> pair = queryItems.at(i);
|
||||
if (pair.first == QL1S("location"))
|
||||
subscriptionUrl = pair.second;
|
||||
else if (pair.first == QL1S("title"))
|
||||
subscriptionTitle = pair.second;
|
||||
}
|
||||
|
||||
if (subscriptionTitle.isEmpty() || subscriptionUrl.isEmpty())
|
||||
return false;
|
||||
|
||||
const QString message = AdBlockManager::tr("Do you want to add <b>%1</b> subscription?").arg(subscriptionTitle);
|
||||
|
||||
QMessageBox::StandardButton result = QMessageBox::question(0, AdBlockManager::tr("AdBlock Subscription"), message, QMessageBox::Yes | QMessageBox::No);
|
||||
if (result == QMessageBox::Yes) {
|
||||
AdBlockManager::instance()->addSubscription(subscriptionTitle, subscriptionUrl);
|
||||
AdBlockManager::instance()->showDialog();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
AdBlockSubscription* AdBlockManager::addSubscription(const QString &title, const QString &url)
|
||||
{
|
||||
if (title.isEmpty() || url.isEmpty()) {
|
||||
|
|
|
@ -63,6 +63,8 @@ public:
|
|||
void addDisabledRule(const QString &filter);
|
||||
void removeDisabledRule(const QString &filter);
|
||||
|
||||
bool addSubscriptionFromUrl(const QUrl &url);
|
||||
|
||||
AdBlockSubscription* addSubscription(const QString &title, const QString &url);
|
||||
bool removeSubscription(AdBlockSubscription* subscription);
|
||||
|
||||
|
|
|
@ -133,7 +133,6 @@ SOURCES += \
|
|||
network/networkurlinterceptor.cpp \
|
||||
network/pac/pacmanager.cpp \
|
||||
network/pac/proxyautoconfig.cpp \
|
||||
network/schemehandlers/adblockschemehandler.cpp \
|
||||
#network/schemehandlers/fileschemehandler.cpp \
|
||||
network/schemehandlers/qupzillaschemehandler.cpp \
|
||||
network/sslerrordialog.cpp \
|
||||
|
@ -323,7 +322,6 @@ HEADERS += \
|
|||
network/pac/pacdatetime.h \
|
||||
network/pac/pacmanager.h \
|
||||
network/pac/proxyautoconfig.h \
|
||||
network/schemehandlers/adblockschemehandler.h \
|
||||
#network/schemehandlers/fileschemehandler.h \
|
||||
network/schemehandlers/qupzillaschemehandler.h \
|
||||
network/schemehandlers/schemehandler.h \
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
#include "passwordmanager.h"
|
||||
#include "sslerrordialog.h"
|
||||
#include "networkurlinterceptor.h"
|
||||
#include "schemehandlers/adblockschemehandler.h"
|
||||
#include "schemehandlers/qupzillaschemehandler.h"
|
||||
|
||||
#include <QLabel>
|
||||
|
@ -44,7 +43,6 @@ NetworkManager::NetworkManager(QObject *parent)
|
|||
: QNetworkAccessManager(parent)
|
||||
{
|
||||
// Create scheme handlers
|
||||
mApp->webProfile()->installUrlSchemeHandler(new AdBlockSchemeHandler(this));
|
||||
mApp->webProfile()->installUrlSchemeHandler(new QupZillaSchemeHandler(this));
|
||||
|
||||
// Create url interceptor
|
||||
|
|
|
@ -1,65 +0,0 @@
|
|||
/* ============================================================
|
||||
* QupZilla - WebKit based browser
|
||||
* Copyright (C) 2010-2014 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 "adblockschemehandler.h"
|
||||
#include "adblockmanager.h"
|
||||
#include "emptynetworkreply.h"
|
||||
|
||||
#include <QBuffer>
|
||||
#include <QUrlQuery>
|
||||
#include <QMessageBox>
|
||||
#include <QWebEngineUrlRequestJob>
|
||||
|
||||
AdBlockSchemeHandler::AdBlockSchemeHandler(QObject *parent)
|
||||
: QWebEngineUrlSchemeHandler(QByteArrayLiteral("abp"), parent)
|
||||
{
|
||||
}
|
||||
|
||||
void AdBlockSchemeHandler::requestStarted(QWebEngineUrlRequestJob *job)
|
||||
{
|
||||
// Ignore the request
|
||||
job->reply(QByteArray(), new QBuffer());
|
||||
//job->fail(QWebEngineUrlRequestJob::RequestAborted);
|
||||
|
||||
const QUrl url = job->requestUrl();
|
||||
const QList<QPair<QString, QString> > queryItems = QUrlQuery(url).queryItems();
|
||||
|
||||
QString subscriptionTitle;
|
||||
QString subscriptionUrl;
|
||||
|
||||
for (int i = 0; i < queryItems.count(); ++i) {
|
||||
QPair<QString, QString> pair = queryItems.at(i);
|
||||
if (pair.first == QL1S("location")) {
|
||||
subscriptionUrl = pair.second;
|
||||
}
|
||||
else if (pair.first == QL1S("title")) {
|
||||
subscriptionTitle = pair.second;
|
||||
}
|
||||
}
|
||||
|
||||
if (subscriptionTitle.isEmpty() || subscriptionUrl.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const QString message = AdBlockManager::tr("Do you want to add <b>%1</b> subscription?").arg(subscriptionTitle);
|
||||
|
||||
QMessageBox::StandardButton result = QMessageBox::question(0, AdBlockManager::tr("AdBlock Subscription"), message, QMessageBox::Yes | QMessageBox::No);
|
||||
if (result == QMessageBox::Yes) {
|
||||
AdBlockManager::instance()->addSubscription(subscriptionTitle, subscriptionUrl);
|
||||
AdBlockManager::instance()->showDialog();
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
/* ============================================================
|
||||
* QupZilla - WebKit based browser
|
||||
* Copyright (C) 2010-2014 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 ADBLOCKSCHEMEHANDLER_H
|
||||
#define ADBLOCKSCHEMEHANDLER_H
|
||||
|
||||
#include <QWebEngineUrlSchemeHandler>
|
||||
|
||||
#include "qzcommon.h"
|
||||
|
||||
class QUPZILLA_EXPORT AdBlockSchemeHandler : public QWebEngineUrlSchemeHandler
|
||||
{
|
||||
public:
|
||||
explicit AdBlockSchemeHandler(QObject *parent = Q_NULLPTR);
|
||||
|
||||
void requestStarted(QWebEngineUrlRequestJob *job) Q_DECL_OVERRIDE;
|
||||
};
|
||||
|
||||
#endif // ADBLOCKSCHEMEHANDLER_H
|
|
@ -28,7 +28,6 @@
|
|||
#include "autofill.h"
|
||||
#include "popupwebview.h"
|
||||
#include "popupwindow.h"
|
||||
#include "adblockicon.h"
|
||||
#include "adblockmanager.h"
|
||||
#include "iconprovider.h"
|
||||
#include "qzsettings.h"
|
||||
|
@ -336,11 +335,13 @@ bool WebPage::isFullScreen()
|
|||
|
||||
bool WebPage::acceptNavigationRequest(const QUrl &url, QWebEnginePage::NavigationType type, bool isMainFrame)
|
||||
{
|
||||
m_lastRequestUrl = url;
|
||||
|
||||
if (!mApp->plugins()->acceptNavigationRequest(this, url, type, isMainFrame))
|
||||
return false;
|
||||
|
||||
// AdBlock
|
||||
if (url.scheme() == QL1S("abp") && AdBlockManager::instance()->addSubscriptionFromUrl(url))
|
||||
return false;
|
||||
|
||||
return QWebEnginePage::acceptNavigationRequest(url, type, isMainFrame);
|
||||
}
|
||||
|
||||
|
|
|
@ -96,8 +96,6 @@ private:
|
|||
|
||||
QVector<PasswordEntry> m_passwordEntries;
|
||||
|
||||
QUrl m_lastRequestUrl;
|
||||
|
||||
int m_loadProgress;
|
||||
bool m_blockAlerts;
|
||||
bool m_secureStatus;
|
||||
|
|
Loading…
Reference in New Issue
Block a user