diff options
author | Benjamin Poulain <benjamin.poulain@nokia.com> | 2010-08-19 02:26:40 +0200 |
---|---|---|
committer | Benjamin Poulain <benjamin.poulain@nokia.com> | 2010-08-19 03:18:29 +0200 |
commit | a4631fb9ec2541f99e1aba05cf1e7d2b5ebecb98 (patch) | |
tree | 2db557fe27ed8589eb0937755cf9bbe69dc1b1e5 /src/adblock/adblockmanager.cpp | |
parent | Improve the performance of AdBlockRuleTextMatchImpl (diff) | |
download | rekonq-a4631fb9ec2541f99e1aba05cf1e7d2b5ebecb98.tar.xz |
Add a special matcher for ad block filters for host name
Quite a few rules of ad block are just matching domains. Those
are of the form:
||trolltech.com^$options
This patch add a new class to deal with this kind of filter,
AdBlockHostMatcher. Matching a host address is much faster (O(1))
than going through the entire list of rules.
Diffstat (limited to 'src/adblock/adblockmanager.cpp')
-rw-r--r-- | src/adblock/adblockmanager.cpp | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/adblock/adblockmanager.cpp b/src/adblock/adblockmanager.cpp index e0a109f0..600dc5ce 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,8 @@ void AdBlockManager::loadRules(const QStringList &rules) continue; } + if (_hostBlackList.tryAddFilter(stringRule)) + continue; AdBlockRule rule(stringRule); _blackList << rule; } @@ -164,8 +171,16 @@ QNetworkReply *AdBlockManager::block(const QNetworkRequest &request, WebPage *pa // 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, urlStringLowerCase)) @@ -177,6 +192,13 @@ 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, urlStringLowerCase)) |