summaryrefslogtreecommitdiff
path: root/src/adblock
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2011-04-10 01:22:48 +0200
committerAndrea Diamantini <adjam7@gmail.com>2011-04-10 01:22:48 +0200
commit4b9753d82fceacfdd6db5d6e3f671aed7cc390ba (patch)
tree646138daa9014a074b032e64645384b4a77d7b06 /src/adblock
parentFix History ordering (check about:history page before and after this patch) (diff)
downloadrekonq-4b9753d82fceacfdd6db5d6e3f671aed7cc390ba.tar.xz
AdBlock Improvements:
- implemented "third party" support - do NOT block first requests (you cannot even see a blank page, sometimes...) BUG:270356 PS: Alberto, can you pls check this really works for you before backporting to 0.7 and let me know about? Many thanks for.
Diffstat (limited to 'src/adblock')
-rw-r--r--src/adblock/adblockrulefallbackimpl.cpp25
-rw-r--r--src/adblock/adblockrulefallbackimpl.h2
-rw-r--r--src/adblock/adblockrulenullimpl.cpp4
-rw-r--r--src/adblock/adblockruletextmatchimpl.cpp8
4 files changed, 34 insertions, 5 deletions
diff --git a/src/adblock/adblockrulefallbackimpl.cpp b/src/adblock/adblockrulefallbackimpl.cpp
index 915516c7..bb68b0c2 100644
--- a/src/adblock/adblockrulefallbackimpl.cpp
+++ b/src/adblock/adblockrulefallbackimpl.cpp
@@ -35,13 +35,16 @@
#include <QStringList>
+
static inline bool isRegExpFilter(const QString &filter)
{
return filter.startsWith(QL1C('/')) && filter.endsWith(QL1C('/'));
}
+
AdBlockRuleFallbackImpl::AdBlockRuleFallbackImpl(const QString &filter)
- : AdBlockRuleImpl(filter)
+ : AdBlockRuleImpl(filter)
+ , m_thirdPartyOption(false)
{
m_regExp.setCaseSensitivity(Qt::CaseInsensitive);
m_regExp.setPatternSyntax(QRegExp::RegExp2);
@@ -57,6 +60,9 @@ AdBlockRuleFallbackImpl::AdBlockRuleFallbackImpl(const QString &filter)
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)
{
// Domain restricted filter
@@ -83,10 +89,24 @@ AdBlockRuleFallbackImpl::AdBlockRuleFallbackImpl(const QString &filter)
m_regExp.setPattern(parsedLine);
}
+
bool AdBlockRuleFallbackImpl::match(const QNetworkRequest &request, const QString &encodedUrl, const QString &) const
{
- const bool regexpMatch = m_regExp.indexIn(encodedUrl) != -1;
+ if(!request.hasRawHeader("referer"))
+ return false;
+
+ if (m_thirdPartyOption)
+ {
+ const QString referer = request.rawHeader("referer");
+ const QString host = request.url().host();
+ bool isThirdParty = !referer.contains(host);
+
+ if(!isThirdParty)
+ return false;
+ }
+ const bool regexpMatch = m_regExp.indexIn(encodedUrl) != -1;
+
if (regexpMatch && (!m_whiteDomains.isEmpty() || !m_blackDomains.isEmpty()))
{
Q_ASSERT(qobject_cast<QWebFrame*>(request.originatingObject()));
@@ -110,6 +130,7 @@ bool AdBlockRuleFallbackImpl::match(const QNetworkRequest &request, const QStrin
return regexpMatch;
}
+
QString AdBlockRuleFallbackImpl::convertPatternToRegExp(const QString &wildcardPattern)
{
QString pattern = wildcardPattern;
diff --git a/src/adblock/adblockrulefallbackimpl.h b/src/adblock/adblockrulefallbackimpl.h
index bf842513..0003c037 100644
--- a/src/adblock/adblockrulefallbackimpl.h
+++ b/src/adblock/adblockrulefallbackimpl.h
@@ -48,6 +48,8 @@ private:
QRegExp m_regExp;
QSet<QString> m_whiteDomains;
QSet<QString> m_blackDomains;
+
+ bool m_thirdPartyOption;
};
#endif // ADBLOCKRULEFALLBACKIMPL_H
diff --git a/src/adblock/adblockrulenullimpl.cpp b/src/adblock/adblockrulenullimpl.cpp
index 7f6ab765..7f4e40b3 100644
--- a/src/adblock/adblockrulenullimpl.cpp
+++ b/src/adblock/adblockrulenullimpl.cpp
@@ -110,9 +110,9 @@ bool AdBlockRuleNullImpl::isNullFilter(const QString &filter)
if (option == QL1S("other"))
return true;
- // third_party
+ // third_party: managed inside adblockrulefallbackimpl
if (option == QL1S("third-party"))
- return true;
+ return false;
// collapse
if (option == QL1S("collapse"))
diff --git a/src/adblock/adblockruletextmatchimpl.cpp b/src/adblock/adblockruletextmatchimpl.cpp
index d8ec70b6..f3f93204 100644
--- a/src/adblock/adblockruletextmatchimpl.cpp
+++ b/src/adblock/adblockruletextmatchimpl.cpp
@@ -30,6 +30,9 @@
// Rekonq Includes
#include "rekonq_defines.h"
+// Qt Includes
+#include <QNetworkRequest>
+
AdBlockRuleTextMatchImpl::AdBlockRuleTextMatchImpl(const QString &filter)
: AdBlockRuleImpl(filter)
@@ -43,8 +46,11 @@ 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"))
+ return false;
+
Q_UNUSED(encodedUrl);
- Q_UNUSED(request);
// Case sensitive compare is faster, but would be incorrect with encodedUrl since
// we do want case insensitive.
// What we do is work on a lowercase version of m_textToMatch, and compare to the lowercase