diff options
Diffstat (limited to 'src/adblock/adblockmanager.cpp')
-rw-r--r-- | src/adblock/adblockmanager.cpp | 43 |
1 files changed, 28 insertions, 15 deletions
diff --git a/src/adblock/adblockmanager.cpp b/src/adblock/adblockmanager.cpp index a0bc4e00..209c2ab0 100644 --- a/src/adblock/adblockmanager.cpp +++ b/src/adblock/adblockmanager.cpp @@ -24,12 +24,12 @@ * ============================================================ */ +// Self Includes #include "adblockmanager.h" #include "adblockmanager.moc" - // Local Includes -#include "adblockrule.h" +#include "adblocknetworkreply.h" // KDE Includes #include <KSharedConfig> @@ -64,9 +64,12 @@ void AdBlockManager::loadSettings() _isAdblockEnabled = cg.readEntry("Enabled", false); _isHideAdsEnabled = cg.readEntry("Shrink", false); - _adBlackList.clear(); - _adWhiteList.clear(); - + filterList.clear(); + + // no need to load filters if adblock is not enabled :) + if(!_isAdblockEnabled) + return; + QMap<QString,QString> entryMap = cg.entryMap(); QMap<QString,QString>::ConstIterator it; for( it = entryMap.constBegin(); it != entryMap.constEnd(); ++it ) @@ -76,23 +79,33 @@ void AdBlockManager::loadSettings() if (name.startsWith(QLatin1String("Filter"))) { - if (url.startsWith(QLatin1String("@@"))) - _adWhiteList.addFilter(url); - else - _adBlackList.addFilter(url); + AdBlockRule filter(url); + filterList << filter; } } } } -bool AdBlockManager::isUrlAllowed(const QUrl &url) +QNetworkReply *AdBlockManager::block(const QNetworkRequest &request) { if (!_isAdblockEnabled) - return true; - - QString urlString = QString::fromUtf8(url.toEncoded()); + return 0; - // Check the blacklist, and only if that matches, the whitelist - return _adBlackList.isUrlMatched(urlString) && !_adWhiteList.isUrlMatched(urlString); + // we (ad)block just http traffic + if(request.url().scheme() != QLatin1String("http")) + return 0; + + QString urlString = request.url().toString(); + + foreach(const AdBlockRule &filter, filterList) + { + if(filter.match(urlString)) + { + kDebug() << "****ADBLOCK: Matched: ***********" << urlString; + AdBlockNetworkReply *reply = new AdBlockNetworkReply(request, urlString, this); + return reply; + } + } + return 0; } |