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