aboutsummaryrefslogtreecommitdiff
path: root/lib/web/urlfilter/adblockrule.h
blob: 76484c3e2bdddd698dffb2d30692fcaeebc6853d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#ifndef ADBLOCKRULE_H
#define ADBLOCKRULE_H

#include <QObject>
#include <QString>
#include <QRegularExpression>
#include <QUrl>
#include <QWebEngineUrlRequestInfo>

class AdBlockRule
{
public:

    enum MatchType {
        InvalidMatch,
        RegularExpressionMatch,
        StringContains,
        StringStartsWith,
        StringEndsWith,
        StringEquals,
        DomainMatch
    };

    AdBlockRule(const QString &filter);

    bool isEnabled() const;
    bool matchesType(QWebEngineUrlRequestInfo::ResourceType type) const;
    bool matchesUrl(const QUrl &url) const;

private:
    bool m_isEnabled = false;
    bool m_isException = false;

    MatchType matchType = InvalidMatch;
    QHash<QWebEngineUrlRequestInfo::ResourceType, bool> m_resourceTypeOptions;
    QStringList allowedDomains, blockedDomains;

    QString match;
    QRegularExpression regexp;
    QStringMatcher matcher;
};

#endif // ADBLOCKRULE_H