aboutsummaryrefslogtreecommitdiff
path: root/src/filter/filter.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/filter/filter.h')
-rw-r--r--src/filter/filter.h91
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