mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 09:32:12 +01:00
Initial work on support for 3rdparty AdBlock lists.
- also fixed one minor gcc warning
This commit is contained in:
parent
db1995d3ec
commit
0cba7628de
|
@ -67,7 +67,7 @@ AdBlockDialog::AdBlockDialog(QWidget* parent)
|
|||
connect(addButton, SIGNAL(clicked()), this, SLOT(addCustomRule()));
|
||||
connect(reloadButton, SIGNAL(clicked()), this, SLOT(updateSubscription()));
|
||||
connect(search, SIGNAL(textChanged(QString)), treeWidget, SLOT(filterString(QString)));
|
||||
connect(m_manager->subscription(), SIGNAL(rulesUpdated()), this, SLOT(refreshAfterUpdate()));
|
||||
connect(m_manager, SIGNAL(rulesChanged()), this, SLOT(refreshAfterUpdate()));
|
||||
connect(treeWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuRequested(QPoint)));
|
||||
|
||||
// QTimer::singleShot(0, this, SLOT(firstRefresh()));
|
||||
|
|
|
@ -44,10 +44,11 @@
|
|||
*/
|
||||
#include "adblockmanager.h"
|
||||
#include "adblockdialog.h"
|
||||
#include "adblocknetwork.h"
|
||||
#include "adblockpage.h"
|
||||
#include "adblocksubscription.h"
|
||||
#include "adblockblockednetworkreply.h"
|
||||
#include "mainapplication.h"
|
||||
#include "webpage.h"
|
||||
#include "networkmanager.h"
|
||||
#include "qupzilla.h"
|
||||
#include "settings.h"
|
||||
|
@ -62,7 +63,6 @@ AdBlockManager::AdBlockManager(QObject* parent)
|
|||
, m_enabled(true)
|
||||
, m_adBlockNetwork(0)
|
||||
, m_adBlockPage(0)
|
||||
, m_subscription(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -85,14 +85,6 @@ void AdBlockManager::setEnabled(bool enabled)
|
|||
mApp->sendMessages(Qz::AM_SetAdBlockIconEnabled, enabled);
|
||||
}
|
||||
|
||||
AdBlockNetwork* AdBlockManager::network()
|
||||
{
|
||||
if (!m_adBlockNetwork) {
|
||||
m_adBlockNetwork = new AdBlockNetwork(this);
|
||||
}
|
||||
return m_adBlockNetwork;
|
||||
}
|
||||
|
||||
AdBlockPage* AdBlockManager::page()
|
||||
{
|
||||
if (!m_adBlockPage) {
|
||||
|
@ -101,6 +93,46 @@ AdBlockPage* AdBlockManager::page()
|
|||
return m_adBlockPage;
|
||||
}
|
||||
|
||||
AdBlockSubscription *AdBlockManager::subscription()
|
||||
{
|
||||
return m_subscriptions.at(0);
|
||||
}
|
||||
|
||||
QNetworkReply* AdBlockManager::block(const QNetworkRequest &request)
|
||||
{
|
||||
const QString &urlString = request.url().toEncoded();
|
||||
const QString &urlScheme = request.url().scheme();
|
||||
|
||||
if (!isEnabled() || urlScheme == "data" || urlScheme == "qrc" || urlScheme == "file" || urlScheme == "qupzilla") {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const AdBlockRule* blockedRule = 0;
|
||||
|
||||
foreach (AdBlockSubscription* subscription, m_subscriptions) {
|
||||
if (subscription->allow(urlString)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (const AdBlockRule* rule = subscription->block(urlString)) {
|
||||
blockedRule = rule;
|
||||
}
|
||||
|
||||
if (blockedRule) {
|
||||
QVariant v = request.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 100));
|
||||
WebPage* webPage = static_cast<WebPage*>(v.value<void*>());
|
||||
if (WebPage::isPointerSafeToUse(webPage)) {
|
||||
webPage->addAdBlockRule(blockedRule->filter(), request.url());
|
||||
}
|
||||
|
||||
AdBlockBlockedNetworkReply* reply = new AdBlockBlockedNetworkReply(request, blockedRule, this);
|
||||
return reply;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void AdBlockManager::load()
|
||||
{
|
||||
if (m_loaded) {
|
||||
|
@ -114,12 +146,14 @@ void AdBlockManager::load()
|
|||
QDateTime lastUpdate = settings.value("lastUpdate", QDateTime()).toDateTime();
|
||||
settings.endGroup();
|
||||
|
||||
m_subscription = new AdBlockSubscription();
|
||||
connect(m_subscription, SIGNAL(rulesChanged()), this, SIGNAL(rulesChanged()));
|
||||
connect(m_subscription, SIGNAL(rulesUpdated()), this, SLOT(rulesUpdated()));
|
||||
AdBlockSubscription* easyList = new AdBlockSubscription();
|
||||
connect(easyList, SIGNAL(rulesChanged()), this, SIGNAL(rulesChanged()));
|
||||
connect(easyList, SIGNAL(rulesUpdated()), this, SLOT(rulesUpdated()));
|
||||
|
||||
m_subscriptions.append(easyList);
|
||||
|
||||
if (lastUpdate.addDays(3) < QDateTime::currentDateTime()) {
|
||||
m_subscription->scheduleUpdate();
|
||||
easyList->scheduleUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -137,7 +171,8 @@ void AdBlockManager::save()
|
|||
if (!m_loaded) {
|
||||
return;
|
||||
}
|
||||
m_subscription->saveRules();
|
||||
|
||||
subscription()->saveRules();
|
||||
|
||||
Settings settings;
|
||||
settings.beginGroup(QLatin1String("AdBlock"));
|
||||
|
|
|
@ -51,6 +51,8 @@
|
|||
#include "qz_namespace.h"
|
||||
|
||||
class QUrl;
|
||||
class QNetworkReply;
|
||||
class QNetworkRequest;
|
||||
|
||||
class AdBlockDialog;
|
||||
class AdBlockNetwork;
|
||||
|
@ -61,9 +63,6 @@ class QT_QUPZILLA_EXPORT AdBlockManager : public QObject
|
|||
{
|
||||
Q_OBJECT
|
||||
|
||||
signals:
|
||||
void rulesChanged();
|
||||
|
||||
public:
|
||||
AdBlockManager(QObject* parent = 0);
|
||||
~AdBlockManager();
|
||||
|
@ -73,18 +72,24 @@ public:
|
|||
static AdBlockManager* instance();
|
||||
bool isEnabled() { if (!m_loaded) load(); return m_enabled; }
|
||||
|
||||
AdBlockSubscription* subscription() { return m_subscription; }
|
||||
AdBlockNetwork* network();
|
||||
AdBlockPage* page();
|
||||
// FIXME: Remove when completely changed to multi-subscription model
|
||||
AdBlockSubscription* subscription();
|
||||
|
||||
QNetworkReply* block(const QNetworkRequest &request);
|
||||
|
||||
public slots:
|
||||
void setEnabled(bool enabled);
|
||||
AdBlockDialog* showDialog();
|
||||
void showRule();
|
||||
|
||||
AdBlockDialog* showDialog();
|
||||
|
||||
private slots:
|
||||
void rulesUpdated();
|
||||
|
||||
signals:
|
||||
void rulesChanged();
|
||||
|
||||
private:
|
||||
static AdBlockManager* s_adBlockManager;
|
||||
|
||||
|
@ -93,7 +98,7 @@ private:
|
|||
QWeakPointer<AdBlockDialog> m_adBlockDialog;
|
||||
AdBlockNetwork* m_adBlockNetwork;
|
||||
AdBlockPage* m_adBlockPage;
|
||||
AdBlockSubscription* m_subscription;
|
||||
QList<AdBlockSubscription*> m_subscriptions;
|
||||
};
|
||||
|
||||
#endif // ADBLOCKMANAGER_H
|
||||
|
|
|
@ -1,94 +0,0 @@
|
|||
/* ============================================================
|
||||
* QupZilla - WebKit based browser
|
||||
* Copyright (C) 2010-2012 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/>.
|
||||
* ============================================================ */
|
||||
/**
|
||||
* Copyright (c) 2009, Benjamin C. Meyer <ben@meyerhome.net>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Benjamin Meyer nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "adblocknetwork.h"
|
||||
#include "adblockblockednetworkreply.h"
|
||||
#include "adblockmanager.h"
|
||||
#include "adblocksubscription.h"
|
||||
#include "mainapplication.h"
|
||||
#include "webpage.h"
|
||||
|
||||
AdBlockNetwork::AdBlockNetwork(QObject* parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
QNetworkReply* AdBlockNetwork::block(const QNetworkRequest &request)
|
||||
{
|
||||
const QString &urlString = request.url().toEncoded();
|
||||
const QString &urlScheme = request.url().scheme();
|
||||
|
||||
if (urlScheme == "data" || urlScheme == "qrc" || urlScheme == "file" || urlScheme == "qupzilla") {
|
||||
return 0;
|
||||
}
|
||||
|
||||
AdBlockManager* manager = AdBlockManager::instance();
|
||||
if (!manager->isEnabled()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const AdBlockRule* blockedRule = 0;
|
||||
AdBlockSubscription* subscription = manager->subscription();
|
||||
|
||||
if (subscription->allow(urlString)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (const AdBlockRule* rule = subscription->block(urlString)) {
|
||||
blockedRule = rule;
|
||||
}
|
||||
|
||||
if (blockedRule) {
|
||||
QVariant v = request.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 100));
|
||||
WebPage* webPage = static_cast<WebPage*>(v.value<void*>());
|
||||
if (WebPage::isPointerSafeToUse(webPage)) {
|
||||
webPage->addAdBlockRule(blockedRule->filter(), request.url());
|
||||
}
|
||||
|
||||
AdBlockBlockedNetworkReply* reply = new AdBlockBlockedNetworkReply(request, blockedRule, this);
|
||||
return reply;
|
||||
}
|
||||
return 0;
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
/* ============================================================
|
||||
* QupZilla - WebKit based browser
|
||||
* Copyright (C) 2010-2012 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/>.
|
||||
* ============================================================ */
|
||||
/**
|
||||
* Copyright (c) 2009, Benjamin C. Meyer <ben@meyerhome.net>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Benjamin Meyer nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef ADBLOCKNETWORK_H
|
||||
#define ADBLOCKNETWORK_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include "qz_namespace.h"
|
||||
|
||||
class QNetworkRequest;
|
||||
class QNetworkReply;
|
||||
|
||||
class QT_QUPZILLA_EXPORT AdBlockNetwork : public QObject
|
||||
{
|
||||
public:
|
||||
AdBlockNetwork(QObject* parent = 0);
|
||||
QNetworkReply* block(const QNetworkRequest &request);
|
||||
};
|
||||
|
||||
#endif // ADBLOCKNETWORK_H
|
||||
|
|
@ -108,11 +108,11 @@ void AdBlockPage::applyRulesToPage(QWebPage* page)
|
|||
}
|
||||
|
||||
QString host = page->mainFrame()->url().host();
|
||||
AdBlockSubscription* subscription = manager->subscription();
|
||||
// AdBlockSubscription* subscription = manager->subscription();
|
||||
|
||||
QList<const AdBlockRule*> rules = subscription->pageRules();
|
||||
foreach(const AdBlockRule * rule, rules) {
|
||||
checkRule(rule, page, host);
|
||||
}
|
||||
// QList<const AdBlockRule*> rules = subscription->pageRules();
|
||||
// foreach(const AdBlockRule * rule, rules) {
|
||||
// checkRule(rule, page, host);
|
||||
// }
|
||||
}
|
||||
|
||||
|
|
|
@ -91,7 +91,6 @@ SOURCES += \
|
|||
adblock/adblocksubscription.cpp \
|
||||
adblock/adblockrule.cpp \
|
||||
adblock/adblockpage.cpp \
|
||||
adblock/adblocknetwork.cpp \
|
||||
adblock/adblockmanager.cpp \
|
||||
adblock/adblockdialog.cpp \
|
||||
adblock/adblockblockednetworkreply.cpp \
|
||||
|
@ -238,7 +237,6 @@ HEADERS += \
|
|||
adblock/adblocksubscription.h \
|
||||
adblock/adblockrule.h \
|
||||
adblock/adblockpage.h \
|
||||
adblock/adblocknetwork.h \
|
||||
adblock/adblockmanager.h \
|
||||
adblock/adblockdialog.h \
|
||||
adblock/adblockblockednetworkreply.h \
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
#include "webpage.h"
|
||||
#include "pluginproxy.h"
|
||||
#include "adblockmanager.h"
|
||||
#include "adblocknetwork.h"
|
||||
#include "networkproxyfactory.h"
|
||||
#include "qupzillaschemehandler.h"
|
||||
#include "certificateinfowidget.h"
|
||||
|
@ -59,7 +58,7 @@ QString fileNameForCert(const QSslCertificate &cert)
|
|||
|
||||
NetworkManager::NetworkManager(QupZilla* mainClass, QObject* parent)
|
||||
: NetworkManagerProxy(parent)
|
||||
, m_adblockNetwork(0)
|
||||
, m_adblockManager(0)
|
||||
, p_QupZilla(mainClass)
|
||||
, m_ignoreAllWarnings(false)
|
||||
{
|
||||
|
@ -348,10 +347,10 @@ QNetworkReply* NetworkManager::createRequest(QNetworkAccessManager::Operation op
|
|||
|
||||
// Adblock
|
||||
if (op == QNetworkAccessManager::GetOperation) {
|
||||
if (!m_adblockNetwork) {
|
||||
m_adblockNetwork = AdBlockManager::instance()->network();
|
||||
if (!m_adblockManager) {
|
||||
m_adblockManager = AdBlockManager::instance();
|
||||
}
|
||||
reply = m_adblockNetwork->block(req);
|
||||
reply = m_adblockManager->block(req);
|
||||
if (reply) {
|
||||
return reply;
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
class QNetworkDiskCache;
|
||||
|
||||
class QupZilla;
|
||||
class AdBlockNetwork;
|
||||
class AdBlockManager;
|
||||
class NetworkProxyFactory;
|
||||
class QupZillaSchemeHandler;
|
||||
class SchemeHandler;
|
||||
|
@ -70,7 +70,7 @@ private slots:
|
|||
void setSSLConfiguration(QNetworkReply* reply);
|
||||
|
||||
private:
|
||||
AdBlockNetwork* m_adblockNetwork;
|
||||
AdBlockManager* m_adblockManager;
|
||||
QupZilla* p_QupZilla;
|
||||
QNetworkDiskCache* m_diskCache;
|
||||
NetworkProxyFactory* m_proxyFactory;
|
||||
|
|
|
@ -51,6 +51,7 @@ class MouseGestureCallback
|
|||
{
|
||||
public:
|
||||
virtual void callback() = 0;
|
||||
virtual ~MouseGestureCallback() = 0;
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue
Block a user