summaryrefslogtreecommitdiff
path: root/src/adblock/adblockmanager.cpp
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2010-08-19 15:21:36 +0200
committerAndrea Diamantini <adjam7@gmail.com>2010-08-19 15:21:36 +0200
commita3f4b43ff806c3dab1f2410d6dc5017c6a05accb (patch)
tree7beab7f7433064692ace51fea3c81dd18e173478 /src/adblock/adblockmanager.cpp
parentBookmarkOwner class clean-up (diff)
parentSkip the hiding rules specific to domains (diff)
downloadrekonq-a3f4b43ff806c3dab1f2410d6dc5017c6a05accb.tar.xz
Merge commit 'refs/merge-requests/179' of git://gitorious.org/rekonq/mainline into m179
Diffstat (limited to 'src/adblock/adblockmanager.cpp')
-rw-r--r--src/adblock/adblockmanager.cpp38
1 files changed, 34 insertions, 4 deletions
diff --git a/src/adblock/adblockmanager.cpp b/src/adblock/adblockmanager.cpp
index 644ecff5..8deb0bcd 100644
--- a/src/adblock/adblockmanager.cpp
+++ b/src/adblock/adblockmanager.cpp
@@ -67,6 +67,8 @@ void AdBlockManager::loadSettings(bool checkUpdateDate)
_index = 0;
_buffer.clear();
+ _hostWhiteList.clear();
+ _hostBlackList.clear();
_whiteList.clear();
_blackList.clear();
_hideList.clear();
@@ -133,7 +135,10 @@ void AdBlockManager::loadRules(const QStringList &rules)
// white rules
if (stringRule.startsWith(QL1S("@@")))
{
- AdBlockRule rule(stringRule.mid(2));
+ const QString filter = stringRule.mid(2);
+ if (_hostWhiteList.tryAddFilter(filter))
+ continue;
+ AdBlockRule rule(filter);
_whiteList << rule;
continue;
}
@@ -145,6 +150,12 @@ void AdBlockManager::loadRules(const QStringList &rules)
continue;
}
+ // TODO implement domain-specific hiding
+ if (stringRule.contains(QL1S("##")))
+ continue;
+
+ if (_hostBlackList.tryAddFilter(stringRule))
+ continue;
AdBlockRule rule(stringRule);
_blackList << rule;
}
@@ -161,11 +172,22 @@ QNetworkReply *AdBlockManager::block(const QNetworkRequest &request, WebPage *pa
return 0;
QString urlString = request.url().toString();
+ // We compute a lowercase version of the URL so each rule does not
+ // have to do it.
+ const QString urlStringLowerCase = urlString.toLower();
+ const QString host = request.url().host();
// check white rules before :)
+
+ if (_hostWhiteList.match(host)) {
+ kDebug() << "****ADBLOCK: WHITE RULE (@@) Matched by host matcher: ***********";
+ kDebug() << "UrlString: " << urlString;
+ return 0;
+ }
+
foreach(const AdBlockRule &filter, _whiteList)
{
- if (filter.match(urlString))
+ if (filter.match(urlString, urlStringLowerCase))
{
kDebug() << "****ADBLOCK: WHITE RULE (@@) Matched: ***********";
kDebug() << "UrlString: " << urlString;
@@ -174,9 +196,16 @@ QNetworkReply *AdBlockManager::block(const QNetworkRequest &request, WebPage *pa
}
// then check the black ones :(
+ if (_hostBlackList.match(host)) {
+ kDebug() << "****ADBLOCK: BLACK RULE Matched by host matcher: ***********";
+ kDebug() << "UrlString: " << urlString;
+ AdBlockNetworkReply *reply = new AdBlockNetworkReply(request, urlString, this);
+ return reply;
+ }
+
foreach(const AdBlockRule &filter, _blackList)
{
- if (filter.match(urlString))
+ if (filter.match(urlString, urlStringLowerCase))
{
kDebug() << "****ADBLOCK: BLACK RULE Matched: ***********";
kDebug() << "UrlString: " << urlString;
@@ -185,7 +214,8 @@ QNetworkReply *AdBlockManager::block(const QNetworkRequest &request, WebPage *pa
QWebElementCollection elements = document.findAll("*");
foreach(QWebElement el, elements)
{
- if (filter.match(el.attribute("src")))
+ const QString srcAttribute = el.attribute("src");
+ if (filter.match(srcAttribute, srcAttribute.toLower()))
{
kDebug() << "MATCHES ATTRIBUTE!!!!!";
el.setStyleProperty(QL1S("visibility"), QL1S("hidden"));