summaryrefslogtreecommitdiff
path: root/src/adblock
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2011-07-25 19:48:41 +0200
committerAndrea Diamantini <adjam7@gmail.com>2011-07-25 19:48:41 +0200
commit14664e54b1a2dbe9c06f474a0918a262dba04e20 (patch)
tree2f48b455d90b5a966045f8ba6388ac8c0620259f /src/adblock
parentLast SSL fixes (diff)
downloadrekonq-14664e54b1a2dbe9c06f474a0918a262dba04e20.tar.xz
clean up
- QL1S - one stupid kDebug less - codingstyle
Diffstat (limited to 'src/adblock')
-rw-r--r--src/adblock/adblockhostmatcher.cpp8
-rw-r--r--src/adblock/adblockmanager.cpp54
-rw-r--r--src/adblock/adblockrule.cpp6
-rw-r--r--src/adblock/adblockrule.h2
-rw-r--r--src/adblock/adblockrulefallbackimpl.cpp26
-rw-r--r--src/adblock/adblockrulenullimpl.cpp32
-rw-r--r--src/adblock/adblockruletextmatchimpl.cpp12
7 files changed, 70 insertions, 70 deletions
diff --git a/src/adblock/adblockhostmatcher.cpp b/src/adblock/adblockhostmatcher.cpp
index 4a29fb9e..021fe12d 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 c41ff2eb..6a4a3827 100644
--- a/src/adblock/adblockmanager.cpp
+++ b/src/adblock/adblockmanager.cpp
@@ -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);
@@ -119,23 +119,23 @@ void AdBlockManager::loadRules(const QStringList &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,7 +180,7 @@ 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;
@@ -189,7 +189,7 @@ QNetworkReply *AdBlockManager::block(const QNetworkRequest &request, WebPage *pa
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;
@@ -208,7 +208,7 @@ QNetworkReply *AdBlockManager::block(const QNetworkRequest &request, WebPage *pa
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,13 +239,13 @@ 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();
@@ -257,7 +257,7 @@ void AdBlockManager::applyHidingRules(WebPage *page)
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);
KUrl subUrl = KUrl(urlString);
@@ -296,7 +296,7 @@ void AdBlockManager::updateNextSubscription()
void AdBlockManager::slotResult(KJob *job)
{
- if(job->error())
+ if (job->error())
return;
QList<QByteArray> list = _buffer.split('\n');
@@ -319,7 +319,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,7 +333,7 @@ void AdBlockManager::saveRules(const QStringList &rules)
QStringList cleanedRules;
foreach(const QString & r, rules)
{
- if(!r.startsWith('!') && !r.startsWith('[') && !r.isEmpty())
+ if (!r.startsWith('!') && !r.startsWith('[') && !r.isEmpty())
cleanedRules << r;
}
@@ -349,11 +349,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/adblockrule.cpp b/src/adblock/adblockrule.cpp
index fcc5fd8c..87fcb680 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 336987b0..f5f913dc 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 7977849b..7b18feec 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")))
+ if (options.contains(QL1S("third-party")))
m_thirdPartyOption = true;
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)
{
- 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);
@@ -92,36 +92,36 @@ AdBlockRuleFallbackImpl::AdBlockRuleFallbackImpl(const QString &filter)
bool AdBlockRuleFallbackImpl::match(const QNetworkRequest &request, const QString &encodedUrl, const QString &) const
{
- if(!request.hasRawHeader("referer"))
+ if (!request.hasRawHeader("referer"))
return false;
- if(m_thirdPartyOption)
+ if (m_thirdPartyOption)
{
const QString referer = request.rawHeader("referer");
const QString host = request.url().host();
bool isThirdParty = !referer.contains(host);
- if(!isThirdParty)
+ if (!isThirdParty)
return false;
}
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 ecd46b1b..807efc64 100644
--- a/src/adblock/adblockrulenullimpl.cpp
+++ b/src/adblock/adblockrulenullimpl.cpp
@@ -51,7 +51,7 @@ 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(',')));
@@ -59,63 +59,63 @@ bool AdBlockRuleNullImpl::isNullFilter(const QString &filter)
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 70b5d03d..7b55bf27 100644
--- a/src/adblock/adblockruletextmatchimpl.cpp
+++ b/src/adblock/adblockruletextmatchimpl.cpp
@@ -47,7 +47,7 @@ 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...
- if(!request.hasRawHeader("referer"))
+ if (!request.hasRawHeader("referer"))
return false;
Q_UNUSED(encodedUrl);
@@ -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);
}