diff options
author | Andrea Diamantini <adjam7@gmail.com> | 2010-03-24 09:21:01 +0100 |
---|---|---|
committer | Andrea Diamantini <adjam7@gmail.com> | 2010-03-24 09:21:01 +0100 |
commit | 1b99d40d92a4c1e989a53724ea527b0e7d6388ff (patch) | |
tree | 9c4be829b25b79bb74786e8e3ef6d9281a033983 | |
parent | Doing "load finished" operations just on ok loading is really NOT (diff) | |
download | rekonq-1b99d40d92a4c1e989a53724ea527b0e7d6388ff.tar.xz |
Cleaning AdblockManager::loadRules slot
-rw-r--r-- | src/adblock/adblockmanager.cpp | 51 |
1 files changed, 30 insertions, 21 deletions
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) |