diff options
author | Panagiotis Papadopoulos <pano_90@gmx.net> | 2009-12-09 17:23:35 +0100 |
---|---|---|
committer | Panagiotis Papadopoulos <pano_90@gmx.net> | 2009-12-09 17:23:35 +0100 |
commit | ba21553e2e6ce17fc4ad84b5ab587b4e7bc5345c (patch) | |
tree | 64f7b3a5cec066f06268e954899a78523dcaedf5 /src/adblock/adblockmanager.cpp | |
parent | Change a bit the WebKit settings UI (diff) | |
parent | xss attach prevention. (diff) | |
download | rekonq-ba21553e2e6ce17fc4ad84b5ab587b4e7bc5345c.tar.xz |
Merge branch 'master' of git://gitorious.org/rekonq/mainline into click-to-flash-ui
Diffstat (limited to 'src/adblock/adblockmanager.cpp')
-rw-r--r-- | src/adblock/adblockmanager.cpp | 53 |
1 files changed, 51 insertions, 2 deletions
diff --git a/src/adblock/adblockmanager.cpp b/src/adblock/adblockmanager.cpp index b25edcb1..209c2ab0 100644 --- a/src/adblock/adblockmanager.cpp +++ b/src/adblock/adblockmanager.cpp @@ -24,9 +24,12 @@ * ============================================================ */ +// Self Includes #include "adblockmanager.h" #include "adblockmanager.moc" +// Local Includes +#include "adblocknetworkreply.h" // KDE Includes #include <KSharedConfig> @@ -53,10 +56,56 @@ AdBlockManager::~AdBlockManager() void AdBlockManager::loadSettings() { + KSharedConfig::Ptr config = KSharedConfig::openConfig("khtmlrc", KConfig::NoGlobals); + KConfigGroup cg( config, "Filter Settings" ); + + if ( cg.exists() ) + { + _isAdblockEnabled = cg.readEntry("Enabled", false); + _isHideAdsEnabled = cg.readEntry("Shrink", false); + + 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 ) + { + QString name = it.key(); + QString url = it.value(); + + if (name.startsWith(QLatin1String("Filter"))) + { + AdBlockRule filter(url); + filterList << filter; + } + } + } } -bool AdBlockManager::isUrlAllowed(const QUrl &url) +QNetworkReply *AdBlockManager::block(const QNetworkRequest &request) { - return true; + if (!_isAdblockEnabled) + return 0; + + // 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; } |