From 067b99a053b6f8b1ccab507be8e828b2f72a1e43 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Wed, 10 Feb 2010 10:57:57 +0100 Subject: Fix copyright for 0.4 beta release --- src/adblock/adblockmanager.cpp | 2 +- src/adblock/adblockmanager.h | 2 +- src/adblock/adblocknetworkreply.cpp | 2 +- src/adblock/adblocknetworkreply.h | 2 +- src/adblock/adblockrule.cpp | 2 +- src/adblock/adblockrule.h | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src/adblock') diff --git a/src/adblock/adblockmanager.cpp b/src/adblock/adblockmanager.cpp index c2a42f0b..bcb5b556 100644 --- a/src/adblock/adblockmanager.cpp +++ b/src/adblock/adblockmanager.cpp @@ -2,7 +2,7 @@ * * This file is a part of the rekonq project * -* Copyright (C) 2009 by Andrea Diamantini +* Copyright (C) 2010 by Andrea Diamantini * * * This program is free software; you can redistribute it and/or diff --git a/src/adblock/adblockmanager.h b/src/adblock/adblockmanager.h index f01aaca0..754c81c2 100644 --- a/src/adblock/adblockmanager.h +++ b/src/adblock/adblockmanager.h @@ -2,7 +2,7 @@ * * This file is a part of the rekonq project * -* Copyright (C) 2009 by Andrea Diamantini +* Copyright (C) 2010 by Andrea Diamantini * * * This program is free software; you can redistribute it and/or diff --git a/src/adblock/adblocknetworkreply.cpp b/src/adblock/adblocknetworkreply.cpp index 1ccca96d..804524b3 100644 --- a/src/adblock/adblocknetworkreply.cpp +++ b/src/adblock/adblocknetworkreply.cpp @@ -28,7 +28,7 @@ * * This file is a part of the rekonq project * - * Copyright (C) 2009 by Andrea Diamantini + * Copyright (C) 2010 by Andrea Diamantini * * * This program is free software; you can redistribute it and/or diff --git a/src/adblock/adblocknetworkreply.h b/src/adblock/adblocknetworkreply.h index b5bb8300..36dd7fdb 100644 --- a/src/adblock/adblocknetworkreply.h +++ b/src/adblock/adblocknetworkreply.h @@ -28,7 +28,7 @@ * * This file is a part of the rekonq project * - * Copyright (C) 2009 by Andrea Diamantini + * Copyright (C) 2010 by Andrea Diamantini * * * This program is free software; you can redistribute it and/or diff --git a/src/adblock/adblockrule.cpp b/src/adblock/adblockrule.cpp index 9f86ffee..25ca3678 100644 --- a/src/adblock/adblockrule.cpp +++ b/src/adblock/adblockrule.cpp @@ -30,7 +30,7 @@ * * This file is a part of the rekonq project * - * Copyright (C) 2009 by Andrea Diamantini + * Copyright (C) 2010 by Andrea Diamantini * * * This program is free software; you can redistribute it and/or diff --git a/src/adblock/adblockrule.h b/src/adblock/adblockrule.h index 35715051..1cb97dc4 100644 --- a/src/adblock/adblockrule.h +++ b/src/adblock/adblockrule.h @@ -29,7 +29,7 @@ * * This file is a part of the rekonq project * - * Copyright (C) 2009 by Andrea Diamantini + * Copyright (C) 2010 by Andrea Diamantini * * * This program is free software; you can redistribute it and/or -- cgit v1.2.1 From 3e1ac6fb3f9865bf5bb0c156e985c1a4577b20e0 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Sun, 14 Feb 2010 11:23:37 +0100 Subject: Krazy issues (1st branch) --- src/adblock/adblockmanager.cpp | 6 +++--- src/adblock/adblocknetworkreply.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/adblock') diff --git a/src/adblock/adblockmanager.cpp b/src/adblock/adblockmanager.cpp index bcb5b556..06f0d164 100644 --- a/src/adblock/adblockmanager.cpp +++ b/src/adblock/adblockmanager.cpp @@ -83,10 +83,10 @@ void AdBlockManager::loadSettings() if (name.startsWith(QLatin1String("Filter"))) { - if(!url.startsWith("!")) + if(!url.startsWith('!')) { // white rules - if(url.startsWith("@@")) + if( url.startsWith( QLatin1String("@@") ) ) { AdBlockRule rule( url.mid(2) ); _whiteList << rule; @@ -94,7 +94,7 @@ void AdBlockManager::loadSettings() } // hide (CSS) rules - if(url.startsWith("##")) + if( url.startsWith( QLatin1String("##") ) ) { _hideList << url.mid(2); continue; diff --git a/src/adblock/adblocknetworkreply.cpp b/src/adblock/adblocknetworkreply.cpp index 804524b3..3b73b8a0 100644 --- a/src/adblock/adblocknetworkreply.cpp +++ b/src/adblock/adblocknetworkreply.cpp @@ -68,7 +68,7 @@ AdBlockNetworkReply::AdBlockNetworkReply(const QNetworkRequest &request, const Q setOperation(QNetworkAccessManager::GetOperation); setRequest(request); setUrl(request.url()); - setError(QNetworkReply::ContentAccessDenied, i18n("Blocked by AdBlockRule: %1").arg(urlString)); + setError(QNetworkReply::ContentAccessDenied, i18n("Blocked by AdBlockRule: %1", urlString) ); QTimer::singleShot(0, this, SLOT(delayedFinished())); } -- cgit v1.2.1 From 8dda858403d283f1850c0298aac0fb5212a27952 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Fri, 26 Feb 2010 11:37:11 +0100 Subject: tests support for every Qt derived rekonq class --- src/adblock/adblockmanager.h | 3 ++- src/adblock/adblocknetworkreply.h | 5 ++++- src/adblock/adblockrule.h | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) (limited to 'src/adblock') diff --git a/src/adblock/adblockmanager.h b/src/adblock/adblockmanager.h index 754c81c2..d1bbe7ba 100644 --- a/src/adblock/adblockmanager.h +++ b/src/adblock/adblockmanager.h @@ -105,6 +105,7 @@ // Local Includes +#include "rekonqprivate_export.h" #include "adblockrule.h" // Qt Includes @@ -120,7 +121,7 @@ class WebPage; typedef QList AdBlockRuleList; -class AdBlockManager : public QObject +class REKONQ_TESTS_EXPORT AdBlockManager : public QObject { Q_OBJECT diff --git a/src/adblock/adblocknetworkreply.h b/src/adblock/adblocknetworkreply.h index 36dd7fdb..bbc3471e 100644 --- a/src/adblock/adblocknetworkreply.h +++ b/src/adblock/adblocknetworkreply.h @@ -54,6 +54,9 @@ #define ADBLOCK_NETWORK_REPLY_H +// Local Includes +#include "rekonqprivate_export.h" + // Qt Includes #include #include @@ -62,7 +65,7 @@ class AdBlockRule; -class AdBlockNetworkReply : public QNetworkReply +class REKONQ_TESTS_EXPORT AdBlockNetworkReply : public QNetworkReply { Q_OBJECT diff --git a/src/adblock/adblockrule.h b/src/adblock/adblockrule.h index 1cb97dc4..8f79d16e 100644 --- a/src/adblock/adblockrule.h +++ b/src/adblock/adblockrule.h @@ -54,6 +54,7 @@ #ifndef ADBLOCKRULE_H #define ADBLOCKRULE_H + // Qt Includes #include #include -- cgit v1.2.1 From 6faa12680a0d7d2f13c2862628325ab65521004b Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Sat, 13 Mar 2010 23:24:45 +0100 Subject: Implemented automatic adblock update. This (squashed) commit adds this new feature in rekonq, letting people to simply "forgot" adblock and let rekonq do everything for it I added: - a new (rekonq) adblock widget - an asyncronous method to update rules from the net every TOT days - a better AdBlockManager management. What it is actually missing is the adp protocol support to add new subscriptions to adblock. This will come the next week. For now this part seems stable and needs just testing :) --- src/adblock/adblockmanager.cpp | 198 ++++++++++++++++++++++++++++++++--------- src/adblock/adblockmanager.h | 18 +++- src/adblock/adblockrule.cpp | 6 ++ src/adblock/adblockrule.h | 4 +- 4 files changed, 182 insertions(+), 44 deletions(-) (limited to 'src/adblock') diff --git a/src/adblock/adblockmanager.cpp b/src/adblock/adblockmanager.cpp index 06f0d164..d2c2b013 100644 --- a/src/adblock/adblockmanager.cpp +++ b/src/adblock/adblockmanager.cpp @@ -28,6 +28,9 @@ #include "adblockmanager.h" #include "adblockmanager.moc" +// Auto Includes +#include "rekonq.h" + // Local Includes #include "adblocknetworkreply.h" #include "webpage.h" @@ -36,6 +39,7 @@ #include #include #include +#include // Qt Includes #include @@ -46,8 +50,8 @@ AdBlockManager::AdBlockManager(QObject *parent) : QObject(parent) , _isAdblockEnabled(false) , _isHideAdsEnabled(false) + , _index(0) { - loadSettings(); } @@ -58,52 +62,78 @@ AdBlockManager::~AdBlockManager() void AdBlockManager::loadSettings() { - KSharedConfig::Ptr config = KSharedConfig::openConfig("khtmlrc", KConfig::NoGlobals); - KConfigGroup cg( config, "Filter Settings" ); + _index = 0; + _buffer.clear(); + + _whiteList.clear(); + _blackList.clear(); + _hideList.clear(); + + _isAdblockEnabled = ReKonfig::adBlockEnabled(); + kDebug() << "ADBLOCK ENABLED = " << _isAdblockEnabled; + + // no need to load filters if adblock is not enabled :) + if(!_isAdblockEnabled) + return; + + // just to be sure.. + _isHideAdsEnabled = ReKonfig::hideAdsEnabled(); + + // local settings + KSharedConfig::Ptr config = KGlobal::config(); + KConfigGroup rulesGroup( config, "rules" ); + QStringList rules; + rules = rulesGroup.readEntry( "local-rules" , QStringList() ); + loadRules( rules ); - if ( cg.exists() ) + // ---------------------------------------------------------- + + QDateTime today = QDateTime::currentDateTime(); + QDateTime lastUpdate = ReKonfig::lastUpdate(); // the day of the implementation.. :) + int days = ReKonfig::updateInterval(); + + if( today > lastUpdate.addDays( days ) ) { - _isAdblockEnabled = cg.readEntry("Enabled", false); - _isHideAdsEnabled = cg.readEntry("Shrink", false); + ReKonfig::setLastUpdate( today ); + + updateNextSubscription(); + return; + } - // no need to load filters if adblock is not enabled :) - if(!_isAdblockEnabled) - return; + // else + QStringList names = ReKonfig::subscriptionNames(); + foreach(const QString &name, names) + { + rules = rulesGroup.readEntry( name + "-rules" , QStringList() ); + loadRules(rules); + } +} - _whiteList.clear(); - _blackList.clear(); - _hideList.clear(); - - QMap entryMap = cg.entryMap(); - QMap::ConstIterator it; - for( it = entryMap.constBegin(); it != entryMap.constEnd(); ++it ) - { - QString name = it.key(); - QString url = it.value(); - if (name.startsWith(QLatin1String("Filter"))) +void AdBlockManager::loadRules(const QStringList &rules) +{ + foreach(const QString &stringRule, rules) + { + // ! rules are comments + if( !stringRule.startsWith('!') && !stringRule.startsWith('[') && !stringRule.isEmpty() ) + { + // white rules + if( stringRule.startsWith( QLatin1String("@@") ) ) { - if(!url.startsWith('!')) - { - // white rules - if( url.startsWith( QLatin1String("@@") ) ) - { - AdBlockRule rule( url.mid(2) ); - _whiteList << rule; - continue; - } - - // hide (CSS) rules - if( url.startsWith( QLatin1String("##") ) ) - { - _hideList << url.mid(2); - continue; - } - - AdBlockRule rule( url ); - _blackList << rule; - } + AdBlockRule rule( stringRule.mid(2) ); + _whiteList << rule; + continue; } + + // hide (CSS) rules + if( stringRule.startsWith( QLatin1String("##") ) ) + { + _hideList << stringRule.mid(2); + continue; + } + + AdBlockRule rule( stringRule ); + _blackList << rule; } } } @@ -125,7 +155,9 @@ QNetworkReply *AdBlockManager::block(const QNetworkRequest &request) { if(filter.match(urlString)) { - kDebug() << "****ADBLOCK: WHITE RULE (@@) Matched: ***********" << urlString; + kDebug() << "****ADBLOCK: WHITE RULE (@@) Matched: ***********"; + kDebug() << "Filter exp: " << filter.pattern(); + kDebug() << "UrlString: " << urlString; return 0; } } @@ -135,7 +167,9 @@ QNetworkReply *AdBlockManager::block(const QNetworkRequest &request) { if(filter.match(urlString)) { - kDebug() << "****ADBLOCK: BLACK RULE Matched: ***********" << urlString; + kDebug() << "****ADBLOCK: BLACK RULE Matched: ***********"; + kDebug() << "Filter exp: " << filter.pattern(); + kDebug() << "UrlString: " << urlString; AdBlockNetworkReply *reply = new AdBlockNetworkReply(request, urlString, this); return reply; } @@ -164,8 +198,88 @@ void AdBlockManager::applyHidingRules(WebPage *page) foreach (QWebElement element, elements) { + kDebug() << "Hide element: " << element.localName(); element.setStyleProperty(QLatin1String("visibility"), QLatin1String("hidden")); element.removeFromDocument(); } } } + + +void AdBlockManager::updateNextSubscription() +{ + kDebug() << "OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO"; + + QStringList subUrlStrings = ReKonfig::subscriptionUrls(); + + if( _index < subUrlStrings.size() ) + { + QString urlString = subUrlStrings.at(_index); + kDebug() << "DOWNLOADING FROM " << urlString; + KUrl subUrl = KUrl( urlString ); + + KIO::TransferJob* job = KIO::get( subUrl , KIO::Reload , KIO::HideProgressInfo ); + connect(job, SIGNAL(data(KIO::Job*, const QByteArray&)), this, SLOT(subscriptionData(KIO::Job*, const QByteArray&))); + connect(job, SIGNAL(result(KJob*)), this, SLOT(slotResult(KJob*))); + + return; + } + + _index = 0; + _buffer.clear(); +} + + +void AdBlockManager::slotResult(KJob *job) +{ + kDebug() << "SLOTRESULT"; + if(job->error()) + return; + + QList list = _buffer.split('\n'); + QStringList ruleList; + foreach(const QByteArray &ba, list) + { + kDebug() << ba; + ruleList << QString(ba); + } + loadRules(ruleList); + saveRules(ruleList); + + _index++; + + // last.. + updateNextSubscription(); +} + + +void AdBlockManager::subscriptionData(KIO::Job* job, const QByteArray& data) +{ + kDebug() << "subscriptionData"; + Q_UNUSED(job) + + if (data.isEmpty()) + return; + + int oldSize = _buffer.size(); + _buffer.resize( _buffer.size() + data.size() ); + memcpy( _buffer.data() + oldSize, data.data(), data.size() ); +} + + +void AdBlockManager::saveRules(const QStringList &rules) +{ + QStringList cleanedRules; + foreach(const QString &r, rules) + { + if( !r.startsWith('!') && !r.startsWith('[') && !r.isEmpty() ) + cleanedRules << r; + } + + QStringList names = ReKonfig::subscriptionNames(); + QString name = names.at(_index) + "-rules"; + + KSharedConfig::Ptr config = KGlobal::config(); + KConfigGroup cg( config , "rules" ); + cg.writeEntry( name, cleanedRules ); +} diff --git a/src/adblock/adblockmanager.h b/src/adblock/adblockmanager.h index d1bbe7ba..aac78e3b 100644 --- a/src/adblock/adblockmanager.h +++ b/src/adblock/adblockmanager.h @@ -112,6 +112,8 @@ #include #include #include +#include +#include // Forward Includes class QNetworkRequest; @@ -129,9 +131,20 @@ public: AdBlockManager(QObject *parent = 0); ~AdBlockManager(); - void loadSettings(); QNetworkReply *block(const QNetworkRequest &request); void applyHidingRules(WebPage *page); + +public slots: + void loadSettings(); + +private: + void updateNextSubscription(); + void saveRules(const QStringList &); + void loadRules(const QStringList &); + +private slots: + void slotResult(KJob *); + void subscriptionData(KIO::Job*, const QByteArray&); private: bool _isAdblockEnabled; @@ -140,6 +153,9 @@ private: AdBlockRuleList _blackList; AdBlockRuleList _whiteList; QStringList _hideList; + + int _index; + QByteArray _buffer; }; #endif diff --git a/src/adblock/adblockrule.cpp b/src/adblock/adblockrule.cpp index 25ca3678..c0c3fd5b 100644 --- a/src/adblock/adblockrule.cpp +++ b/src/adblock/adblockrule.cpp @@ -181,3 +181,9 @@ QString AdBlockRule::convertPatternToRegExp(const QString &wildcardPattern) // Finally, return... return pattern; } + + +QString AdBlockRule::pattern() const +{ + return m_regExp.pattern(); +} diff --git a/src/adblock/adblockrule.h b/src/adblock/adblockrule.h index 8f79d16e..ee4825d1 100644 --- a/src/adblock/adblockrule.h +++ b/src/adblock/adblockrule.h @@ -69,7 +69,9 @@ public: AdBlockRule(const QString &filter); bool match(const QString &encodedUrl) const; - + + QString pattern() const; + private: QString convertPatternToRegExp(const QString &wildcardPattern); -- cgit v1.2.1 From f51c660a207364b9b5ff400a29e8ff1dba721e61 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Fri, 19 Mar 2010 11:00:18 +0100 Subject: abp (Ad Block Plus) fake protocol support This will let rekonq to automatically add abp subscriptions from the adblockplus.org site (or wherever someone provides abp urls) Anyway, consider that the raccomended way to manage adblock (by me and by abp developers) is just adding the EasyList subscription. rekonq just does it by default!! --- src/adblock/adblockmanager.cpp | 42 +++++++++++++++++++++++++++++------------- src/adblock/adblockmanager.h | 5 +++-- 2 files changed, 32 insertions(+), 15 deletions(-) (limited to 'src/adblock') diff --git a/src/adblock/adblockmanager.cpp b/src/adblock/adblockmanager.cpp index d2c2b013..66e11277 100644 --- a/src/adblock/adblockmanager.cpp +++ b/src/adblock/adblockmanager.cpp @@ -60,7 +60,7 @@ AdBlockManager::~AdBlockManager() } -void AdBlockManager::loadSettings() +void AdBlockManager::loadSettings(bool checkUpdateDate) { _index = 0; _buffer.clear(); @@ -92,7 +92,7 @@ void AdBlockManager::loadSettings() QDateTime lastUpdate = ReKonfig::lastUpdate(); // the day of the implementation.. :) int days = ReKonfig::updateInterval(); - if( today > lastUpdate.addDays( days ) ) + if( !checkUpdateDate || today > lastUpdate.addDays( days ) ) { ReKonfig::setLastUpdate( today ); @@ -101,10 +101,10 @@ void AdBlockManager::loadSettings() } // else - QStringList names = ReKonfig::subscriptionNames(); - foreach(const QString &name, names) + QStringList titles = ReKonfig::subscriptionTitles(); + foreach(const QString &title, titles) { - rules = rulesGroup.readEntry( name + "-rules" , QStringList() ); + rules = rulesGroup.readEntry( title + "-rules" , QStringList() ); loadRules(rules); } } @@ -208,13 +208,11 @@ void AdBlockManager::applyHidingRules(WebPage *page) void AdBlockManager::updateNextSubscription() { - kDebug() << "OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO"; - - QStringList subUrlStrings = ReKonfig::subscriptionUrls(); + QStringList locations = ReKonfig::subscriptionLocations(); - if( _index < subUrlStrings.size() ) + if( _index < locations.size() ) { - QString urlString = subUrlStrings.at(_index); + QString urlString = locations.at(_index); kDebug() << "DOWNLOADING FROM " << urlString; KUrl subUrl = KUrl( urlString ); @@ -276,10 +274,28 @@ void AdBlockManager::saveRules(const QStringList &rules) cleanedRules << r; } - QStringList names = ReKonfig::subscriptionNames(); - QString name = names.at(_index) + "-rules"; + QStringList titles = ReKonfig::subscriptionTitles(); + QString title = titles.at(_index) + "-rules"; KSharedConfig::Ptr config = KGlobal::config(); KConfigGroup cg( config , "rules" ); - cg.writeEntry( name, cleanedRules ); + cg.writeEntry( title, cleanedRules ); +} + + +void AdBlockManager::addSubscription(const QString &title, const QString &location) +{ + QStringList titles = ReKonfig::subscriptionTitles(); + if( titles.contains(title) ) + return; + + QStringList locations = ReKonfig::subscriptionLocations(); + if( locations.contains(location) ) + return; + + titles << title; + locations << location; + + ReKonfig::setSubscriptionTitles(titles); + ReKonfig::setSubscriptionLocations(locations); } diff --git a/src/adblock/adblockmanager.h b/src/adblock/adblockmanager.h index aac78e3b..c0bd2b70 100644 --- a/src/adblock/adblockmanager.h +++ b/src/adblock/adblockmanager.h @@ -133,9 +133,10 @@ public: QNetworkReply *block(const QNetworkRequest &request); void applyHidingRules(WebPage *page); - + void addSubscription(const QString &title, const QString &location); + public slots: - void loadSettings(); + void loadSettings(bool checkUpdateDate = true); private: void updateNextSubscription(); -- cgit v1.2.1 From 1b99d40d92a4c1e989a53724ea527b0e7d6388ff Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Wed, 24 Mar 2010 09:21:01 +0100 Subject: Cleaning AdblockManager::loadRules slot --- src/adblock/adblockmanager.cpp | 51 +++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 21 deletions(-) (limited to 'src/adblock') diff --git a/src/adblock/adblockmanager.cpp b/src/adblock/adblockmanager.cpp index 66e11277..71412d5d 100644 --- a/src/adblock/adblockmanager.cpp +++ b/src/adblock/adblockmanager.cpp @@ -84,7 +84,7 @@ void AdBlockManager::loadSettings(bool checkUpdateDate) KConfigGroup rulesGroup( config, "rules" ); QStringList rules; rules = rulesGroup.readEntry( "local-rules" , QStringList() ); - loadRules( rules ); + loadRules(rules); // ---------------------------------------------------------- @@ -115,26 +115,35 @@ void AdBlockManager::loadRules(const QStringList &rules) foreach(const QString &stringRule, rules) { // ! rules are comments - if( !stringRule.startsWith('!') && !stringRule.startsWith('[') && !stringRule.isEmpty() ) - { - // white rules - if( stringRule.startsWith( QLatin1String("@@") ) ) - { - AdBlockRule rule( stringRule.mid(2) ); - _whiteList << rule; - continue; - } - - // hide (CSS) rules - if( stringRule.startsWith( QLatin1String("##") ) ) - { - _hideList << stringRule.mid(2); - continue; - } - - AdBlockRule rule( stringRule ); - _blackList << rule; + if( stringRule.startsWith('!') ) + continue; + + // [ rules are ABP infos + if( stringRule.startsWith('[') ) + continue; + + // empty rules are just dangerous.. + // (an empty rule in whitelist allows all, in blacklist blocks all..) + if( stringRule.isEmpty() ) + continue; + + // white rules + if( stringRule.startsWith( QLatin1String("@@") ) ) + { + AdBlockRule rule( stringRule.mid(2) ); + _whiteList << rule; + continue; } + + // hide (CSS) rules + if( stringRule.startsWith( QLatin1String("##") ) ) + { + _hideList << stringRule.mid(2); + continue; + } + + AdBlockRule rule( stringRule ); + _blackList << rule; } } @@ -182,7 +191,7 @@ QNetworkReply *AdBlockManager::block(const QNetworkRequest &request) void AdBlockManager::applyHidingRules(WebPage *page) { - if(!page || !page->mainFrame()) + if(!page) return; if (!_isAdblockEnabled) -- cgit v1.2.1 From c5e684b649d5aac0424abcd573c1cb1a3e7dbb9d Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Tue, 30 Mar 2010 17:14:54 +0200 Subject: Not so stupid, after all.. --- src/adblock/adblockmanager.cpp | 44 ++++++++++++++++++++++++++++++++++++------ src/adblock/adblockmanager.h | 2 +- 2 files changed, 39 insertions(+), 7 deletions(-) (limited to 'src/adblock') diff --git a/src/adblock/adblockmanager.cpp b/src/adblock/adblockmanager.cpp index 71412d5d..e4986264 100644 --- a/src/adblock/adblockmanager.cpp +++ b/src/adblock/adblockmanager.cpp @@ -148,7 +148,7 @@ void AdBlockManager::loadRules(const QStringList &rules) } -QNetworkReply *AdBlockManager::block(const QNetworkRequest &request) +QNetworkReply *AdBlockManager::block(const QNetworkRequest &request, WebPage *page) { if (!_isAdblockEnabled) return 0; @@ -179,6 +179,19 @@ QNetworkReply *AdBlockManager::block(const QNetworkRequest &request) kDebug() << "****ADBLOCK: BLACK RULE Matched: ***********"; kDebug() << "Filter exp: " << filter.pattern(); kDebug() << "UrlString: " << urlString; + + QWebElement document = page->mainFrame()->documentElement(); + QWebElementCollection elements = document.findAll("*"); + foreach (QWebElement el, elements) + { + if(filter.match( el.attribute("src") ) ) + { + kDebug() << "MATCHES ATTRIBUTE!!!!!"; + el.setStyleProperty(QLatin1String("visibility"), QLatin1String("hidden")); + el.removeFromDocument(); + } + } + AdBlockNetworkReply *reply = new AdBlockNetworkReply(request, urlString, this); return reply; } @@ -197,19 +210,38 @@ void AdBlockManager::applyHidingRules(WebPage *page) if (!_isAdblockEnabled) return; +// // BLACK RULES +// foreach(const AdBlockRule &filter, _blackList) +// { +// QWebElementCollection elements = document.findAll("*"); +// foreach (QWebElement el, elements) +// { +// if(filter.match( el.attribute("src") ) ) +// { +// kDebug() << "MATCHES!!!!!"; +// el.setStyleProperty(QLatin1String("visibility"), QLatin1String("hidden")); +// el.removeFromDocument(); +// } +// } +// } + if (!_isHideAdsEnabled) return; + + QWebElement document = page->mainFrame()->documentElement(); + // HIDE RULES foreach(const QString &filter, _hideList) { - QWebElement document = page->mainFrame()->documentElement(); QWebElementCollection elements = document.findAll(filter); - foreach (QWebElement element, elements) + foreach (QWebElement el, elements) { - kDebug() << "Hide element: " << element.localName(); - element.setStyleProperty(QLatin1String("visibility"), QLatin1String("hidden")); - element.removeFromDocument(); + if(el.isNull()) + continue; + kDebug() << "Hide element: " << el.localName(); + el.setStyleProperty(QLatin1String("visibility"), QLatin1String("hidden")); + el.removeFromDocument(); } } } diff --git a/src/adblock/adblockmanager.h b/src/adblock/adblockmanager.h index c0bd2b70..9b1cc915 100644 --- a/src/adblock/adblockmanager.h +++ b/src/adblock/adblockmanager.h @@ -131,7 +131,7 @@ public: AdBlockManager(QObject *parent = 0); ~AdBlockManager(); - QNetworkReply *block(const QNetworkRequest &request); + QNetworkReply *block(const QNetworkRequest &request, WebPage *page); void applyHidingRules(WebPage *page); void addSubscription(const QString &title, const QString &location); -- cgit v1.2.1 From 66e7ed81f0612a11bcc424658ceec733447975a5 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Wed, 31 Mar 2010 01:33:48 +0200 Subject: This is just a stupid idea, but it seems working well.. :) The idea basically is: hide and set dimensione to ZERO to adblocked elements. This seems cleaning page WARNING: NEED TESTS!!! --- src/adblock/adblockmanager.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/adblock') diff --git a/src/adblock/adblockmanager.cpp b/src/adblock/adblockmanager.cpp index e4986264..feb92864 100644 --- a/src/adblock/adblockmanager.cpp +++ b/src/adblock/adblockmanager.cpp @@ -188,7 +188,8 @@ QNetworkReply *AdBlockManager::block(const QNetworkRequest &request, WebPage *pa { kDebug() << "MATCHES ATTRIBUTE!!!!!"; el.setStyleProperty(QLatin1String("visibility"), QLatin1String("hidden")); - el.removeFromDocument(); + el.setStyleProperty(QLatin1String("width"), QLatin1String("0")); + el.setStyleProperty(QLatin1String("height"), QLatin1String("0")); } } -- cgit v1.2.1 From a6da0df7e0f72f1d7185e39815c17b7fab07d790 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Wed, 31 Mar 2010 10:54:02 +0200 Subject: Auto Scrolling, first bunch. key combinations just work :) --- src/adblock/adblockmanager.cpp | 15 --------------- 1 file changed, 15 deletions(-) (limited to 'src/adblock') diff --git a/src/adblock/adblockmanager.cpp b/src/adblock/adblockmanager.cpp index feb92864..0a139bdc 100644 --- a/src/adblock/adblockmanager.cpp +++ b/src/adblock/adblockmanager.cpp @@ -211,21 +211,6 @@ void AdBlockManager::applyHidingRules(WebPage *page) if (!_isAdblockEnabled) return; -// // BLACK RULES -// foreach(const AdBlockRule &filter, _blackList) -// { -// QWebElementCollection elements = document.findAll("*"); -// foreach (QWebElement el, elements) -// { -// if(filter.match( el.attribute("src") ) ) -// { -// kDebug() << "MATCHES!!!!!"; -// el.setStyleProperty(QLatin1String("visibility"), QLatin1String("hidden")); -// el.removeFromDocument(); -// } -// } -// } - if (!_isHideAdsEnabled) return; -- cgit v1.2.1