aboutsummaryrefslogtreecommitdiff
path: root/lib/web/urlfilter/adblockrule.h
blob: a08fbb75448c2183a85bcf62c8f144864fffc90a (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
44
45
#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 matches(QWebEngineUrlRequestInfo::ResourceType type) const;
    bool shouldBlock(const QUrl &url) const;

private:
    Q_DISABLE_COPY(AdBlockRule)

    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