diff --git a/src/lib/adblock/adblockmanager.cpp b/src/lib/adblock/adblockmanager.cpp index 3310b8a0e..9cf50ba91 100644 --- a/src/lib/adblock/adblockmanager.cpp +++ b/src/lib/adblock/adblockmanager.cpp @@ -32,6 +32,8 @@ #include #include #include +#include +#include //#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 > queryItems = QUrlQuery(url).queryItems(); + + QString subscriptionTitle; + QString subscriptionUrl; + + for (int i = 0; i < queryItems.count(); ++i) { + QPair 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 %1 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()) { diff --git a/src/lib/adblock/adblockmanager.h b/src/lib/adblock/adblockmanager.h index 40b2361a6..2722295d0 100644 --- a/src/lib/adblock/adblockmanager.h +++ b/src/lib/adblock/adblockmanager.h @@ -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); diff --git a/src/lib/lib.pro b/src/lib/lib.pro index f4221b258..6e6e9a088 100644 --- a/src/lib/lib.pro +++ b/src/lib/lib.pro @@ -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 \ diff --git a/src/lib/network/networkmanager.cpp b/src/lib/network/networkmanager.cpp index 4ffb3d55e..a8985c13b 100644 --- a/src/lib/network/networkmanager.cpp +++ b/src/lib/network/networkmanager.cpp @@ -25,7 +25,6 @@ #include "passwordmanager.h" #include "sslerrordialog.h" #include "networkurlinterceptor.h" -#include "schemehandlers/adblockschemehandler.h" #include "schemehandlers/qupzillaschemehandler.h" #include @@ -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 diff --git a/src/lib/network/schemehandlers/adblockschemehandler.cpp b/src/lib/network/schemehandlers/adblockschemehandler.cpp deleted file mode 100644 index 0825f50ba..000000000 --- a/src/lib/network/schemehandlers/adblockschemehandler.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/* ============================================================ -* QupZilla - WebKit based browser -* Copyright (C) 2010-2014 David Rosca -* -* 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 . -* ============================================================ */ -#include "adblockschemehandler.h" -#include "adblockmanager.h" -#include "emptynetworkreply.h" - -#include -#include -#include -#include - -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 > queryItems = QUrlQuery(url).queryItems(); - - QString subscriptionTitle; - QString subscriptionUrl; - - for (int i = 0; i < queryItems.count(); ++i) { - QPair 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 %1 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(); - } -} diff --git a/src/lib/network/schemehandlers/adblockschemehandler.h b/src/lib/network/schemehandlers/adblockschemehandler.h deleted file mode 100644 index 35e80dc75..000000000 --- a/src/lib/network/schemehandlers/adblockschemehandler.h +++ /dev/null @@ -1,33 +0,0 @@ -/* ============================================================ -* QupZilla - WebKit based browser -* Copyright (C) 2010-2014 David Rosca -* -* 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 . -* ============================================================ */ -#ifndef ADBLOCKSCHEMEHANDLER_H -#define ADBLOCKSCHEMEHANDLER_H - -#include - -#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 diff --git a/src/lib/webengine/webpage.cpp b/src/lib/webengine/webpage.cpp index ab8666f3c..7d0b7b0af 100644 --- a/src/lib/webengine/webpage.cpp +++ b/src/lib/webengine/webpage.cpp @@ -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); } diff --git a/src/lib/webengine/webpage.h b/src/lib/webengine/webpage.h index 3a0cde300..a19ee0bfa 100644 --- a/src/lib/webengine/webpage.h +++ b/src/lib/webengine/webpage.h @@ -96,8 +96,6 @@ private: QVector m_passwordEntries; - QUrl m_lastRequestUrl; - int m_loadProgress; bool m_blockAlerts; bool m_secureStatus;