]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/blob - src/helpers/FilterListHelper.h
Filter options implementation.
[PrivacyBrowserPC.git] / src / helpers / FilterListHelper.h
1 /*
2  * Copyright 2024 Soren Stoutner <soren@stoutner.com>.
3  *
4  * This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc/>.
5  *
6  * Privacy Browser PC is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Privacy Browser PC is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Privacy Browser PC.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 #ifndef FILTERLISTHELPER_H
21 #define FILTERLISTHELPER_H
22
23 // Application headers.
24 #include "structs/FilterListStruct.h"
25 #include "structs/RequestStruct.h"
26 #include "structs/UrlStruct.h"
27
28 // Qt framework headers.
29 #include <QString>
30 #include <QWebEngineUrlRequestInfo>
31
32 class FilterListHelper
33 {
34 public:
35     // The default constructor.
36     FilterListHelper();
37
38     // The public static disposition constant integers.
39     static const int DEFAULT = 0;
40     static const int ALLOWED = 1;
41     static const int BLOCKED = 2;
42
43     // The public static sublist constant integers.
44     static const int MAIN_ALLOWLIST = 0;
45     static const int MAIN_BLOCKLIST = 1;
46     static const int INITIAL_DOMAIN_BLOCKLIST = 2;
47
48     // The public variables.
49     FilterListStruct *easyListStructPointer;
50     FilterListStruct *easyPrivacyStructPointer;
51     FilterListStruct *fanboyAnnoyanceStructPointer;
52     FilterListStruct *ultraListStructPointer;
53     FilterListStruct *ultraPrivacyStructPointer;
54
55     // The public functions.
56     bool checkFilterLists(QWebEngineUrlRequestInfo &urlRequestInfo, RequestStruct *requestStructPointer) const;
57     QString getDispositionString(int dispositionInt) const;
58     QString getFilterOptionDispositionString(const FilterOptionEnum::Disposition filterOptionDisposition) const;
59     QString getNavigationTypeString(int navigationTypeInt) const;
60     QString getResourceTypeString(int resourceTypeInt) const;
61     QString getSublistName(int sublistInt) const;
62
63 private:
64     // The private translated disposition strings.
65     QString DEFAULT_STRING;
66     QString ALLOWED_STRING;
67     QString BLOCKED_STRING;
68
69     // The private translated filter option dispositions.
70     QString FILTER_OPTION_NULL;
71     QString FILTER_OPTION_APPLY;
72     QString FILTER_OPTION_OVERRIDE;
73
74     // The private translated navigation type strings.
75     QString NAVIGATION_TYPE_LINK;
76     QString NAVIGATION_TYPE_TYPED;
77     QString NAVIGATION_TYPE_FORM_SUBMITTED;
78     QString NAVIGATION_TYPE_BACK_FORWARD;
79     QString NAVIGATION_TYPE_RELOAD;
80     QString NAVIGATION_TYPE_REDIRECT;
81     QString NAVIGATION_TYPE_OTHER;
82
83     // The private translated resource type strings.
84     QString RESOURCE_TYPE_MAIN_FRAME;
85     QString RESOURCE_TYPE_SUB_FRAME;
86     QString RESOURCE_TYPE_STYLESHEET;
87     QString RESOURCE_TYPE_SCRIPT;
88     QString RESOURCE_TYPE_IMAGE;
89     QString RESOURCE_TYPE_FONT_RESOURCE;
90     QString RESOURCE_TYPE_SUB_RESOURCE;
91     QString RESOURCE_TYPE_OBJECT;
92     QString RESOURCE_TYPE_MEDIA;
93     QString RESOURCE_TYPE_WORKER;
94     QString RESOURCE_TYPE_SHARED_WORKER;
95     QString RESOURCE_TYPE_PREFETCH;
96     QString RESOURCE_TYPE_FAVICON;
97     QString RESOURCE_TYPE_XHR;
98     QString RESOURCE_TYPE_PING;
99     QString RESOURCE_TYPE_SERVICE_WORKER;
100     QString RESOURCE_TYPE_CSP_REPORT;
101     QString RESOURCE_TYPE_PLUGIN_RESOURCE;
102     QString RESOURCE_TYPE_NAVIGATION_PRELOAD_MAIN_FRAME;
103     QString RESOURCE_TYPE_NAVIGATION_PRELOAD_SUB_FRAME;
104     QString RESOURCE_TYPE_UNKNOWN;
105
106     // The private translated sublist strings.
107     QString MAIN_ALLOWLIST_STRING;
108     QString MAIN_BLOCKLIST_STRING;
109     QString INITIAL_DOMAIN_BLOCKLIST_STRING;
110
111     // The private functions.
112     bool blockRequest(QWebEngineUrlRequestInfo &urlRequestInfo, RequestStruct *requestStructPointer, const QString &filterListTitle, const int sublistInt, EntryStruct *entryStructPointer) const;
113     bool checkIndividualList(QWebEngineUrlRequestInfo &urlRequestInfo, UrlStruct &urlStruct, RequestStruct *requestStructPointer, FilterListStruct *filterListStructPointer) const;
114     bool checkThirdParty(QWebEngineUrlRequestInfo &urlRequestInfo, RequestStruct *requestStructPointer, const bool isThirdPartyRequest, const QString &filterListTitle, const int sublistInt,
115                          EntryStruct *entryStructPointer) const;
116     FilterListStruct* populateFilterList(const QString &filterListFileName) const;
117     void populateRequestStruct(RequestStruct *requestStructPointer, const int disposition, const QString &filterListTitle, const int sublistInt, EntryStruct *entryStructPointer) const;
118     bool processFilterOptions(QWebEngineUrlRequestInfo &urlRequestInfo, RequestStruct *requestStructPointer, const QString &filterListTitle, const int sublistInt,
119                               EntryStruct *entryStructPointer) const;
120     void removeInitialAndTrailingAsterisks(QString &filterListEntry) const;
121 };
122 #endif