summaryrefslogtreecommitdiff
path: root/src/adblock/adblockrulefallbackimpl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/adblock/adblockrulefallbackimpl.cpp')
-rw-r--r--src/adblock/adblockrulefallbackimpl.cpp25
1 files changed, 23 insertions, 2 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;