diff options
author | Andrea Diamantini <adjam7@gmail.com> | 2009-11-30 14:57:09 +0100 |
---|---|---|
committer | Andrea Diamantini <adjam7@gmail.com> | 2009-11-30 14:57:09 +0100 |
commit | 78da6efbf8a6694cd1f1c11af404b21941099f95 (patch) | |
tree | 1a6fa792012fff7e9b6869e1581de822cf501c1c /src/adblock/adblockmanager.cpp | |
parent | Porting rekonq to last Qt/KDE API (diff) | |
download | rekonq-78da6efbf8a6694cd1f1c11af404b21941099f95.tar.xz |
We have adblock! (and it works)
I had a lot of problems implementing it because I started working on
assuming 2 things:
1) konqueror implementation works (it's not true, I found a bug! To guess what,
try loading current rekonq vs current konqueror against kde-apps.org)
2) Arora's implementation can be easily ported to kcm technology. Another wrong assumption,
based on MVP implementation.
Sorry for spamming master branch, guys.
Diffstat (limited to 'src/adblock/adblockmanager.cpp')
-rw-r--r-- | src/adblock/adblockmanager.cpp | 45 |
1 files changed, 33 insertions, 12 deletions
diff --git a/src/adblock/adblockmanager.cpp b/src/adblock/adblockmanager.cpp index 987c793f..4f4cff51 100644 --- a/src/adblock/adblockmanager.cpp +++ b/src/adblock/adblockmanager.cpp @@ -30,6 +30,7 @@ // Local Includes #include "adblocknetworkreply.h" +#include "adblockrule.h" // KDE Includes #include <KSharedConfig> @@ -64,9 +65,8 @@ void AdBlockManager::loadSettings() _isAdblockEnabled = cg.readEntry("Enabled", false); _isHideAdsEnabled = cg.readEntry("Shrink", false); - _adBlackList.clear(); - _adWhiteList.clear(); - + filterList.clear(); + QMap<QString,QString> entryMap = cg.entryMap(); QMap<QString,QString>::ConstIterator it; for( it = entryMap.constBegin(); it != entryMap.constEnd(); ++it ) @@ -76,10 +76,7 @@ void AdBlockManager::loadSettings() if (name.startsWith(QLatin1String("Filter"))) { - if (url.startsWith(QLatin1String("@@"))) - _adWhiteList.addFilter(url); - else - _adBlackList.addFilter(url); + filterList << url; } } } @@ -91,13 +88,37 @@ QNetworkReply *AdBlockManager::block(const QNetworkRequest &request) if (!_isAdblockEnabled) return 0; - QString urlString = request.url().toString(); + // we (ad)block just http traffic + if(request.url().scheme() != QLatin1String("http")) + return 0; - // Check the blacklist, and only if that matches, the whitelist - if(_adBlackList.isUrlMatched(urlString) && !_adWhiteList.isUrlMatched(urlString)) + QString urlString = request.url().toString(); + kDebug() << "****************************** ADBLOCK: Matching url: "<< urlString; + + foreach(const QString &filter, filterList) { - AdBlockNetworkReply *reply = new AdBlockNetworkReply(request, urlString, this); - return reply; + AdBlockRule rule(filter); + if(rule.match(urlString)) + { + kDebug() << "****ADBLOCK: Matched: **************************"; + AdBlockNetworkReply *reply = new AdBlockNetworkReply(request, urlString, this); + return reply; + } } + + + + // Check the blacklist, and only if that matches, the whitelist + + + + + +// if(_adBlackList.isUrlMatched(urlString) && !_adWhiteList.isUrlMatched(urlString)) +// { +// kDebug() << "****ADBLOCK: Matched: **************************"; +// AdBlockNetworkReply *reply = new AdBlockNetworkReply(request, urlString, this); +// return reply; +// } return 0; } |