]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/blob - src/helpers/FilterListHelper.h
Partial filter list 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
27 // Qt framework headers.
28 #include <QString>
29 #include <QWebEngineUrlRequestInfo>
30
31 class FilterListHelper
32 {
33 public:
34     // The default constructor.
35     FilterListHelper();
36
37     // The public static disposition constant integers.
38     static const int DEFAULT = 0;
39     static const int ALLOWED = 1;
40     static const int BLOCKED = 2;
41
42     // The public static sublist constant integers.
43     static const int MAIN_BLOCKLIST = 0;
44
45     // The public variables.
46     FilterListStruct *easyListStructPointer;
47     FilterListStruct *easyPrivacyStructPointer;
48     FilterListStruct *fanboyAnnoyanceStructPointer;
49     FilterListStruct *ultraListStructPointer;
50     FilterListStruct *ultraPrivacyStructPointer;
51
52     // The public functions.
53     bool checkFilterLists(QWebEngineUrlRequestInfo &urlRequestInfo, RequestStruct *requestStructPointer) const;
54     QString getDispositionString(int dispositionInt) const;
55     QString getNavigationTypeString(int navigationTypeInt) const;
56     QString getResourceTypeString(int resourceTypeInt) const;
57     QString getSublistName(int sublistInt) const;
58
59 private:
60     // The private translated disposition strings.
61     QString DEFAULT_STRING;
62     QString ALLOWED_STRING;
63     QString BLOCKED_STRING;
64
65     // The private translated navigation type strings.
66     QString NAVIGATION_TYPE_LINK;
67     QString NAVIGATION_TYPE_TYPED;
68     QString NAVIGATION_TYPE_FORM_SUBMITTED;
69     QString NAVIGATION_TYPE_BACK_FORWARD;
70     QString NAVIGATION_TYPE_RELOAD;
71     QString NAVIGATION_TYPE_REDIRECT;
72     QString NAVIGATION_TYPE_OTHER;
73
74     // The private translated resource type strings.
75     QString RESOURCE_TYPE_MAIN_FRAME;
76     QString RESOURCE_TYPE_SUB_FRAME;
77     QString RESOURCE_TYPE_STYLESHEET;
78     QString RESOURCE_TYPE_SCRIPT;
79     QString RESOURCE_TYPE_IMAGE;
80     QString RESOURCE_TYPE_FONT_RESOURCE;
81     QString RESOURCE_TYPE_SUB_RESOURCE;
82     QString RESOURCE_TYPE_OBJECT;
83     QString RESOURCE_TYPE_MEDIA;
84     QString RESOURCE_TYPE_WORKER;
85     QString RESOURCE_TYPE_SHARED_WORKER;
86     QString RESOURCE_TYPE_PREFETCH;
87     QString RESOURCE_TYPE_FAVICON;
88     QString RESOURCE_TYPE_XHR;
89     QString RESOURCE_TYPE_PING;
90     QString RESOURCE_TYPE_SERVICE_WORKER;
91     QString RESOURCE_TYPE_CSP_REPORT;
92     QString RESOURCE_TYPE_PLUGIN_RESOURCE;
93     QString RESOURCE_TYPE_NAVIGATION_PRELOAD_MAIN_FRAME;
94     QString RESOURCE_TYPE_NAVIGATION_PRELOAD_SUB_FRAME;
95     QString RESOURCE_TYPE_UNKNOWN;
96
97     // The private translated sublist strings.
98     QString MAIN_BLOCKLIST_STRING;
99
100     // The private functions.
101     bool checkIndividualList(QWebEngineUrlRequestInfo &urlRequestInfo, RequestStruct *requestStructPointer, FilterListStruct *filterListStruct) const;
102     FilterListStruct* populateFilterList(const QString &filterListFileName) const;
103     void populateRequestStruct(RequestStruct *requestStructPointer, const int disposition, const QString &filterListTitle, const int sublistInt, const QString &appliedEntry,
104                                const QString &originalEntry) const;
105 };
106 #endif