diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2017-12-11 18:16:50 +0100 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2017-12-11 18:16:50 +0100 |
commit | e25c011d5db32104ccdb3e8949082345efdba805 (patch) | |
tree | fb1892f8ae292a088638abaf158d086216106ad2 /src/filter/filter.h | |
parent | Fixed new window action (diff) | |
download | smolbote-e25c011d5db32104ccdb3e8949082345efdba805.tar.xz |
Simple filterlist
Diffstat (limited to 'src/filter/filter.h')
-rw-r--r-- | src/filter/filter.h | 91 |
1 files changed, 19 insertions, 72 deletions
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 <QList> -#include <QVariant> -#include <QUrl> -#include "regexp.h" -#include <QWebEngineUrlRequestInfo> +#include <QStringMatcher> -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<Filter*> 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 |