diff options
Diffstat (limited to 'src/adblock')
-rw-r--r-- | src/adblock/adblockhostmatcher.cpp | 8 | ||||
-rw-r--r-- | src/adblock/adblockmanager.cpp | 76 | ||||
-rw-r--r-- | src/adblock/adblocknetworkreply.cpp | 2 | ||||
-rw-r--r-- | src/adblock/adblockrule.cpp | 6 | ||||
-rw-r--r-- | src/adblock/adblockrule.h | 2 | ||||
-rw-r--r-- | src/adblock/adblockrulefallbackimpl.cpp | 28 | ||||
-rw-r--r-- | src/adblock/adblockrulenullimpl.cpp | 36 | ||||
-rw-r--r-- | src/adblock/adblockruletextmatchimpl.cpp | 16 |
8 files changed, 87 insertions, 87 deletions
diff --git a/src/adblock/adblockhostmatcher.cpp b/src/adblock/adblockhostmatcher.cpp index 021fe12d..4a29fb9e 100644 --- a/src/adblock/adblockhostmatcher.cpp +++ b/src/adblock/adblockhostmatcher.cpp @@ -31,20 +31,20 @@ bool AdBlockHostMatcher::tryAddFilter(const QString &filter) { - if (filter.startsWith(QL1S("||"))) + if(filter.startsWith(QL1S("||"))) { QString domain = filter.mid(2); - if (!domain.endsWith(QL1C('^'))) + if(!domain.endsWith(QL1C('^'))) return false; - if (domain.contains(QL1C('$'))) + if(domain.contains(QL1C('$'))) return false; domain = domain.left(domain.size() - 1); - if (domain.contains(QL1C('/')) || domain.contains(QL1C('*')) || domain.contains(QL1C('^'))) + if(domain.contains(QL1C('/')) || domain.contains(QL1C('*')) || domain.contains(QL1C('^'))) return false; domain = domain.toLower(); diff --git a/src/adblock/adblockmanager.cpp b/src/adblock/adblockmanager.cpp index 9b096bb9..d3af2722 100644 --- a/src/adblock/adblockmanager.cpp +++ b/src/adblock/adblockmanager.cpp @@ -46,10 +46,10 @@ AdBlockManager::AdBlockManager(QObject *parent) - : QObject(parent) - , _isAdblockEnabled(false) - , _isHideAdsEnabled(false) - , _index(0) + : QObject(parent) + , _isAdblockEnabled(false) + , _isHideAdsEnabled(false) + , _index(0) { } @@ -77,7 +77,7 @@ void AdBlockManager::loadSettings(bool checkUpdateDate) kDebug() << "ADBLOCK ENABLED = " << _isAdblockEnabled; // no need to load filters if adblock is not enabled :) - if (!_isAdblockEnabled) + if(!_isAdblockEnabled) return; // just to be sure.. @@ -96,7 +96,7 @@ void AdBlockManager::loadSettings(bool checkUpdateDate) QDateTime lastUpdate = ReKonfig::lastUpdate(); // the day of the implementation.. :) int days = ReKonfig::updateInterval(); - if (!checkUpdateDate || today > lastUpdate.addDays(days)) + if(!checkUpdateDate || today > lastUpdate.addDays(days)) { ReKonfig::setLastUpdate(today); @@ -106,7 +106,7 @@ void AdBlockManager::loadSettings(bool checkUpdateDate) // else QStringList titles = ReKonfig::subscriptionTitles(); - foreach(const QString &title, titles) + foreach(const QString & title, titles) { rules = rulesGroup.readEntry(title + "-rules" , QStringList()); loadRules(rules); @@ -116,26 +116,26 @@ void AdBlockManager::loadSettings(bool checkUpdateDate) void AdBlockManager::loadRules(const QStringList &rules) { - foreach(const QString &stringRule, rules) + foreach(const QString & stringRule, rules) { // ! rules are comments - if (stringRule.startsWith('!')) + if(stringRule.startsWith('!')) continue; // [ rules are ABP info - if (stringRule.startsWith('[')) + if(stringRule.startsWith('[')) continue; // empty rules are just dangerous.. // (an empty rule in whitelist allows all, in blacklist blocks all..) - if (stringRule.isEmpty()) + if(stringRule.isEmpty()) continue; // white rules - if (stringRule.startsWith(QL1S("@@"))) + if(stringRule.startsWith(QL1S("@@"))) { const QString filter = stringRule.mid(2); - if (_hostWhiteList.tryAddFilter(filter)) + if(_hostWhiteList.tryAddFilter(filter)) continue; AdBlockRule rule(filter); @@ -144,17 +144,17 @@ void AdBlockManager::loadRules(const QStringList &rules) } // hide (CSS) rules - if (stringRule.startsWith(QL1S("##"))) + if(stringRule.startsWith(QL1S("##"))) { _hideList << stringRule.mid(2); continue; } // TODO implement domain-specific hiding - if (stringRule.contains(QL1S("##"))) + if(stringRule.contains(QL1S("##"))) continue; - if (_hostBlackList.tryAddFilter(stringRule)) + if(_hostBlackList.tryAddFilter(stringRule)) continue; AdBlockRule rule(stringRule); @@ -165,11 +165,11 @@ void AdBlockManager::loadRules(const QStringList &rules) QNetworkReply *AdBlockManager::block(const QNetworkRequest &request, WebPage *page) { - if (!_isAdblockEnabled) + if(!_isAdblockEnabled) return 0; // we (ad)block just http traffic - if (request.url().scheme() != QL1S("http")) + if(request.url().scheme() != QL1S("http")) return 0; QString urlString = request.url().toString(); @@ -180,16 +180,16 @@ QNetworkReply *AdBlockManager::block(const QNetworkRequest &request, WebPage *pa // check white rules before :) - if (_hostWhiteList.match(host)) + if(_hostWhiteList.match(host)) { kDebug() << "****ADBLOCK: WHITE RULE (@@) Matched by host matcher: ***********"; kDebug() << "UrlString: " << urlString; return 0; } - foreach(const AdBlockRule &filter, _whiteList) + foreach(const AdBlockRule & filter, _whiteList) { - if (filter.match(request, urlString, urlStringLowerCase)) + if(filter.match(request, urlString, urlStringLowerCase)) { kDebug() << "****ADBLOCK: WHITE RULE (@@) Matched: ***********"; kDebug() << "UrlString: " << urlString; @@ -198,7 +198,7 @@ QNetworkReply *AdBlockManager::block(const QNetworkRequest &request, WebPage *pa } // then check the black ones :( - if (_hostBlackList.match(host)) + if(_hostBlackList.match(host)) { kDebug() << "****ADBLOCK: BLACK RULE Matched by host matcher: ***********"; kDebug() << "UrlString: " << urlString; @@ -206,9 +206,9 @@ QNetworkReply *AdBlockManager::block(const QNetworkRequest &request, WebPage *pa return reply; } - foreach(const AdBlockRule &filter, _blackList) + foreach(const AdBlockRule & filter, _blackList) { - if (filter.match(request, urlString, urlStringLowerCase)) + if(filter.match(request, urlString, urlStringLowerCase)) { kDebug() << "****ADBLOCK: BLACK RULE Matched: ***********"; kDebug() << "UrlString: " << urlString; @@ -218,7 +218,7 @@ QNetworkReply *AdBlockManager::block(const QNetworkRequest &request, WebPage *pa foreach(QWebElement el, elements) { const QString srcAttribute = el.attribute("src"); - if (filter.match(request, srcAttribute, srcAttribute.toLower())) + if(filter.match(request, srcAttribute, srcAttribute.toLower())) { kDebug() << "MATCHES ATTRIBUTE!!!!!"; el.setStyleProperty(QL1S("visibility"), QL1S("hidden")); @@ -239,25 +239,25 @@ QNetworkReply *AdBlockManager::block(const QNetworkRequest &request, WebPage *pa void AdBlockManager::applyHidingRules(WebPage *page) { - if (!page) + if(!page) return; - if (!_isAdblockEnabled) + if(!_isAdblockEnabled) return; - if (!_isHideAdsEnabled) + if(!_isHideAdsEnabled) return; QWebElement document = page->mainFrame()->documentElement(); // HIDE RULES - foreach(const QString &filter, _hideList) + foreach(const QString & filter, _hideList) { QWebElementCollection elements = document.findAll(filter); foreach(QWebElement el, elements) { - if (el.isNull()) + if(el.isNull()) continue; kDebug() << "Hide element: " << el.localName(); el.setStyleProperty(QL1S("visibility"), QL1S("hidden")); @@ -271,7 +271,7 @@ void AdBlockManager::updateNextSubscription() { QStringList locations = ReKonfig::subscriptionLocations(); - if (_index < locations.size()) + if(_index < locations.size()) { QString urlString = locations.at(_index); kDebug() << "DOWNLOADING FROM " << urlString; @@ -297,13 +297,13 @@ void AdBlockManager::updateNextSubscription() void AdBlockManager::slotResult(KJob *job) { - if (job->error()) + if(job->error()) return; kDebug() << "SAVING RULES.."; QList<QByteArray> list = _buffer.split('\n'); QStringList ruleList; - foreach(const QByteArray &ba, list) + foreach(const QByteArray & ba, list) { ruleList << QString(ba); } @@ -321,7 +321,7 @@ void AdBlockManager::subscriptionData(KIO::Job* job, const QByteArray& data) { Q_UNUSED(job) - if (data.isEmpty()) + if(data.isEmpty()) return; int oldSize = _buffer.size(); @@ -333,9 +333,9 @@ void AdBlockManager::subscriptionData(KIO::Job* job, const QByteArray& data) void AdBlockManager::saveRules(const QStringList &rules) { QStringList cleanedRules; - foreach(const QString &r, rules) + foreach(const QString & r, rules) { - if (!r.startsWith('!') && !r.startsWith('[') && !r.isEmpty()) + if(!r.startsWith('!') && !r.startsWith('[') && !r.isEmpty()) cleanedRules << r; } @@ -351,11 +351,11 @@ void AdBlockManager::saveRules(const QStringList &rules) void AdBlockManager::addSubscription(const QString &title, const QString &location) { QStringList titles = ReKonfig::subscriptionTitles(); - if (titles.contains(title)) + if(titles.contains(title)) return; QStringList locations = ReKonfig::subscriptionLocations(); - if (locations.contains(location)) + if(locations.contains(location)) return; titles << title; diff --git a/src/adblock/adblocknetworkreply.cpp b/src/adblock/adblocknetworkreply.cpp index 41eb04de..5a5e9d8b 100644 --- a/src/adblock/adblocknetworkreply.cpp +++ b/src/adblock/adblocknetworkreply.cpp @@ -40,7 +40,7 @@ AdBlockNetworkReply::AdBlockNetworkReply(const QNetworkRequest &request, const QString &urlString, QObject *parent) - : QNetworkReply(parent) + : QNetworkReply(parent) { setOperation(QNetworkAccessManager::GetOperation); setRequest(request); diff --git a/src/adblock/adblockrule.cpp b/src/adblock/adblockrule.cpp index 87fcb680..fcc5fd8c 100644 --- a/src/adblock/adblockrule.cpp +++ b/src/adblock/adblockrule.cpp @@ -37,7 +37,7 @@ AdBlockRule::AdBlockRule(const QString &filter) { - switch (AdBlockRule::ruleType(filter)) + switch(AdBlockRule::ruleType(filter)) { case TextRule: m_implementation = QSharedPointer<AdBlockRuleImpl>(new AdBlockRuleTextMatchImpl(filter)); @@ -57,10 +57,10 @@ AdBlockRule::AdBlockRule(const QString &filter) RuleTypes AdBlockRule::ruleType(const QString &filter) { - if (AdBlockRuleTextMatchImpl::isTextMatchFilter(filter)) + if(AdBlockRuleTextMatchImpl::isTextMatchFilter(filter)) return TextRule; - if (AdBlockRuleNullImpl::isNullFilter(filter)) + if(AdBlockRuleNullImpl::isNullFilter(filter)) return NullRule; return FallbackRule; diff --git a/src/adblock/adblockrule.h b/src/adblock/adblockrule.h index f5f913dc..336987b0 100644 --- a/src/adblock/adblockrule.h +++ b/src/adblock/adblockrule.h @@ -57,7 +57,7 @@ public: { Q_ASSERT(encodedUrl.toLower() == encodedUrlLowerCase); bool b = m_implementation->match(request, encodedUrl, encodedUrlLowerCase); - if (b) + if(b) { kDebug() << m_implementation->ruleType() << ": rule string = " << m_implementation->ruleString(); } diff --git a/src/adblock/adblockrulefallbackimpl.cpp b/src/adblock/adblockrulefallbackimpl.cpp index bb68b0c2..7977849b 100644 --- a/src/adblock/adblockrulefallbackimpl.cpp +++ b/src/adblock/adblockrulefallbackimpl.cpp @@ -52,27 +52,27 @@ AdBlockRuleFallbackImpl::AdBlockRuleFallbackImpl(const QString &filter) QString parsedLine = filter; const int optionsNumber = parsedLine.lastIndexOf(QL1C('$')); - if (optionsNumber >= 0 && !isRegExpFilter(parsedLine)) + if(optionsNumber >= 0 && !isRegExpFilter(parsedLine)) { const QStringList options(parsedLine.mid(optionsNumber + 1).split(QL1C(','))); parsedLine = parsedLine.left(optionsNumber); - if (options.contains(QL1S("match-case"))) + if(options.contains(QL1S("match-case"))) m_regExp.setCaseSensitivity(Qt::CaseSensitive); if(options.contains(QL1S("third-party"))) m_thirdPartyOption = true; - foreach(const QString &option, options) + foreach(const QString & option, options) { // Domain restricted filter const QString domainKeyword(QL1S("domain=")); - if (option.startsWith(domainKeyword)) + if(option.startsWith(domainKeyword)) { QStringList domainList = option.mid(domainKeyword.length()).split(QL1C('|')); - foreach(const QString &domain, domainList) + foreach(const QString & domain, domainList) { - if (domain.startsWith(QL1C('~'))) + if(domain.startsWith(QL1C('~'))) m_whiteDomains.insert(domain.toLower()); else m_blackDomains.insert(domain.toLower()); @@ -81,7 +81,7 @@ AdBlockRuleFallbackImpl::AdBlockRuleFallbackImpl(const QString &filter) } } - if (isRegExpFilter(parsedLine)) + if(isRegExpFilter(parsedLine)) parsedLine = parsedLine.mid(1, parsedLine.length() - 2); else parsedLine = convertPatternToRegExp(parsedLine); @@ -94,8 +94,8 @@ bool AdBlockRuleFallbackImpl::match(const QNetworkRequest &request, const QStrin { if(!request.hasRawHeader("referer")) return false; - - if (m_thirdPartyOption) + + if(m_thirdPartyOption) { const QString referer = request.rawHeader("referer"); const QString host = request.url().host(); @@ -106,22 +106,22 @@ bool AdBlockRuleFallbackImpl::match(const QNetworkRequest &request, const QStrin } const bool regexpMatch = m_regExp.indexIn(encodedUrl) != -1; - - if (regexpMatch && (!m_whiteDomains.isEmpty() || !m_blackDomains.isEmpty())) + + if(regexpMatch && (!m_whiteDomains.isEmpty() || !m_blackDomains.isEmpty())) { Q_ASSERT(qobject_cast<QWebFrame*>(request.originatingObject())); const QWebFrame *const origin = static_cast<QWebFrame * const>(request.originatingObject()); const QString originDomain = origin->url().host(); - if (!m_whiteDomains.isEmpty()) + if(!m_whiteDomains.isEmpty()) { // In this context, white domains means we block anything but what is in the list. - if (m_whiteDomains.contains(originDomain)) + if(m_whiteDomains.contains(originDomain)) return false; return true; } - else if (m_blackDomains.contains(originDomain)) + else if(m_blackDomains.contains(originDomain)) { return true; } diff --git a/src/adblock/adblockrulenullimpl.cpp b/src/adblock/adblockrulenullimpl.cpp index 7f4e40b3..ecd46b1b 100644 --- a/src/adblock/adblockrulenullimpl.cpp +++ b/src/adblock/adblockrulenullimpl.cpp @@ -35,7 +35,7 @@ AdBlockRuleNullImpl::AdBlockRuleNullImpl(const QString &filter) - : AdBlockRuleImpl(filter) + : AdBlockRuleImpl(filter) { } @@ -51,71 +51,71 @@ bool AdBlockRuleNullImpl::isNullFilter(const QString &filter) QString parsedLine = filter; const int optionsNumber = parsedLine.lastIndexOf(QL1C('$')); - if (optionsNumber == 0) + if(optionsNumber == 0) return false; const QStringList options(parsedLine.mid(optionsNumber + 1).split(QL1C(','))); - Q_FOREACH(const QString &option, options) + Q_FOREACH(const QString & option, options) { // script - if (option == QL1S("script")) + if(option == QL1S("script")) return true; // image - if (option == QL1S("image")) + if(option == QL1S("image")) return true; // background - if (option == QL1S("background")) + if(option == QL1S("background")) return true; // stylesheet - if (option == QL1S("stylesheet")) + if(option == QL1S("stylesheet")) return true; // object - if (option == QL1S("object")) + if(option == QL1S("object")) return true; // xbl - if (option == QL1S("xbl")) + if(option == QL1S("xbl")) return true; // ping - if (option == QL1S("ping")) + if(option == QL1S("ping")) return true; // xmlhttprequest - if (option == QL1S("xmlhttprequest")) + if(option == QL1S("xmlhttprequest")) return true; // object_subrequest - if (option == QL1S("object-subrequest")) + if(option == QL1S("object-subrequest")) return true; // dtd - if (option == QL1S("dtd")) + if(option == QL1S("dtd")) return true; // subdocument - if (option == QL1S("subdocument")) + if(option == QL1S("subdocument")) return true; // document - if (option == QL1S("document")) + if(option == QL1S("document")) return true; // other - if (option == QL1S("other")) + if(option == QL1S("other")) return true; // third_party: managed inside adblockrulefallbackimpl - if (option == QL1S("third-party")) + if(option == QL1S("third-party")) return false; // collapse - if (option == QL1S("collapse")) + if(option == QL1S("collapse")) return true; } diff --git a/src/adblock/adblockruletextmatchimpl.cpp b/src/adblock/adblockruletextmatchimpl.cpp index f3f93204..70b5d03d 100644 --- a/src/adblock/adblockruletextmatchimpl.cpp +++ b/src/adblock/adblockruletextmatchimpl.cpp @@ -35,7 +35,7 @@ AdBlockRuleTextMatchImpl::AdBlockRuleTextMatchImpl(const QString &filter) - : AdBlockRuleImpl(filter) + : AdBlockRuleImpl(filter) { Q_ASSERT(AdBlockRuleTextMatchImpl::isTextMatchFilter(filter)); @@ -46,10 +46,10 @@ AdBlockRuleTextMatchImpl::AdBlockRuleTextMatchImpl(const QString &filter) bool AdBlockRuleTextMatchImpl::match(const QNetworkRequest &request, const QString &encodedUrl, const QString &encodedUrlLowerCase) const { - // this basically lets the "first request" to pass... + // this basically lets the "first request" to pass... if(!request.hasRawHeader("referer")) return false; - + Q_UNUSED(encodedUrl); // Case sensitive compare is faster, but would be incorrect with encodedUrl since // we do want case insensitive. @@ -62,22 +62,22 @@ bool AdBlockRuleTextMatchImpl::match(const QNetworkRequest &request, const QStri bool AdBlockRuleTextMatchImpl::isTextMatchFilter(const QString &filter) { // We don't deal with options just yet - if (filter.contains(QL1C('$'))) + if(filter.contains(QL1C('$'))) return false; // We don't deal with element matching - if (filter.contains(QL1S("##"))) + if(filter.contains(QL1S("##"))) return false; // We don't deal with the begin-end matching - if (filter.startsWith(QL1C('|')) || filter.endsWith(QL1C('|'))) + if(filter.startsWith(QL1C('|')) || filter.endsWith(QL1C('|'))) return false; // We only handle * at the beginning or the end int starPosition = filter.indexOf(QL1C('*')); - while (starPosition >= 0) + while(starPosition >= 0) { - if (starPosition != 0 && starPosition != (filter.length() - 1)) + if(starPosition != 0 && starPosition != (filter.length() - 1)) return false; starPosition = filter.indexOf(QL1C('*'), starPosition + 1); } |