aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/urlfilter/formats/adblockrule.cpp38
-rw-r--r--lib/urlfilter/formats/adblockrule.h7
2 files changed, 39 insertions, 6 deletions
diff --git a/lib/urlfilter/formats/adblockrule.cpp b/lib/urlfilter/formats/adblockrule.cpp
index 79a6dc8..6b97d5d 100644
--- a/lib/urlfilter/formats/adblockrule.cpp
+++ b/lib/urlfilter/formats/adblockrule.cpp
@@ -31,9 +31,11 @@ AdBlockRule *loadRule(const QString &filter)
}
// exception rules
- const bool isBlocking = parsedLine.startsWith(QLatin1Literal("@@"));
- if(isBlocking)
+ FilterLeaf::Action action = FilterLeaf::Block;
+ if(parsedLine.startsWith(QLatin1Literal("@@"))) {
+ action = FilterLeaf::Allow;
parsedLine.remove(0, 2);
+ }
// parse options
QStringList enabledOn, disabledOn;
@@ -105,7 +107,10 @@ AdBlockRule *loadRule(const QString &filter)
pattern = parsedLine;
}
}
- return nullptr;
+
+ auto *rule = new AdBlockRule(matchType, pattern, action);
+ rule->mergeOptions(optionsHash);
+ return rule;
}
std::optional<QPair<QWebEngineUrlRequestInfo::ResourceType, bool>> parseOption(const QString &option)
@@ -162,3 +167,30 @@ std::optional<QPair<QWebEngineUrlRequestInfo::ResourceType, bool>> parseOption(c
return std::nullopt;
}
+
+AdBlockRule::AdBlockRule(FilterLeaf::UrlMatchType matchType, const QString& filter, FilterLeaf::Action action)
+{
+ this->matchType = matchType;
+ this->m_request = filter;
+ this->m_isBlocking = (action == FilterLeaf::Block) ? true : false;
+}
+
+void AdBlockRule::mergeOptions(const QHash<QWebEngineUrlRequestInfo::ResourceType, bool> &options)
+{
+ this->resourceTypeOptions.unite(options);
+}
+
+bool AdBlockRule::match(const QUrl& requestUrl) const
+{
+ switch(matchType) {
+ case FilterLeaf::StringContains:
+ return requestUrl.toString().contains(m_request);
+ default:
+ return false;
+ }
+}
+
+FilterLeaf::Action AdBlockRule::action() const
+{
+ return m_isBlocking ? FilterLeaf::Block : FilterLeaf::Allow;
+}
diff --git a/lib/urlfilter/formats/adblockrule.h b/lib/urlfilter/formats/adblockrule.h
index 0f0873c..da7e4fc 100644
--- a/lib/urlfilter/formats/adblockrule.h
+++ b/lib/urlfilter/formats/adblockrule.h
@@ -15,10 +15,11 @@
class AdBlockRule : public FilterLeaf
{
public:
-// explicit AdBlockRule(const QString &filter);
+ explicit AdBlockRule(FilterLeaf::UrlMatchType matchType, const QString &filter, FilterLeaf::Action action);
+ void mergeOptions(const QHash<QWebEngineUrlRequestInfo::ResourceType, bool> &options);
-// bool match(const QUrl &requestUrl) const override;
-// FilterLeaf::Action action() const override;
+ bool match(const QUrl &requestUrl) const override;
+ FilterLeaf::Action action() const override;
};
std::optional<QPair<QWebEngineUrlRequestInfo::ResourceType, bool>> parseOption(const QString &option);