From e25c011d5db32104ccdb3e8949082345efdba805 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Mon, 11 Dec 2017 18:16:50 +0100 Subject: Simple filterlist --- src/filter/filter.h | 91 +++++++++++------------------------------------------ 1 file changed, 19 insertions(+), 72 deletions(-) (limited to 'src/filter/filter.h') diff --git a/src/filter/filter.h b/src/filter/filter.h index aeababd..bd3e2ca 100644 --- a/src/filter/filter.h +++ b/src/filter/filter.h @@ -18,90 +18,37 @@ ** ******************************************************************************/ -#ifndef FILTERNODE_H -#define FILTERNODE_H +#ifndef FILTERRULE_H +#define FILTERRULE_H -#include -#include -#include -#include "regexp.h" -#include +#include -class Filter +class QUrl; +class FilterRule { public: - enum ResourceType { - NoType = 0, - MainFrame = 1, - SubFrame = 2, - Stylesheet = 4, - Script = 8, - Image = 16, - Font = 32, - SubResource = 64, - Object = 128, - Media = 256, - Worker = 512, - SharedWorker = 1024, - Prefetch = 2048, - Favicon = 4096, - Xhr = 8192, - Ping = 16384, - ServiceWorker = 32768, - CspReport = 65536, - PluginResource = 131072, - Unknown = 262144 - }; - Q_DECLARE_FLAGS(Resources, ResourceType) + FilterRule(const QString &line); - struct ResourceRules { - Resources allowed; - Resources blocked; - }; + // delete the copy constructor and assignment operator + FilterRule(const FilterRule&) = delete; + FilterRule& operator=(const FilterRule&) = delete; - explicit Filter(const QString &domain, const QString &request, ResourceRules rules, bool shouldBlock, Filter *parentItem = 0); - ~Filter(); + // move constructor + FilterRule(FilterRule&& other) { + matcher = other.matcher; + } - void enable(); + ~FilterRule(); - Filter *parentItem(); - - // children - void appendChild(Filter *child); - Filter *child(int row); - int childCount() const; - - // data - QString domain() const; - QString request() const; - bool isBlocking(); - QString allowedTypes() const; - QString blockedTypes() const; - - int row() const; - - // filtering - bool hasDomainMatch(const QString &string); - bool hasRuleMatch(const QString &string); - bool shouldBlock(const QWebEngineUrlRequestInfo &info); - - bool isValid(); + bool shouldBlock(const QUrl &requestUrl) const; private: - bool testFlag(ResourceType flag); - QString flags(Resources f) const; - - Filter *m_parentItem; - QList m_children; - - RegExp m_domainUrl; - RegExp m_requestUrl; + void parse(const QString &line); - ResourceRules m_rules; + // QStringMatcher: holds a pattern you want to repeatedly match against some strings + QStringMatcher matcher; - bool m_valid = false; - bool m_shouldBlock; }; -#endif // FILTERNODE_H +#endif // FILTERRULE_H -- cgit v1.2.1