]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/blobdiff - src/dialogs/FilterListsDialog.cpp
Block all CSP requests. https://redmine.stoutner.com/issues/1193
[PrivacyBrowserPC.git] / src / dialogs / FilterListsDialog.cpp
index 2d019d87e22b6814c5077723a3963545cebbfda9..faf3b49d88265c007bc2bb18124f08e5378bfb90 100644 (file)
@@ -1,20 +1,20 @@
-/*
- * Copyright 2024 Soren Stoutner <soren@stoutner.com>.
+/* SPDX-License-Identifier: GPL-3.0-or-later
+ * SPDX-FileCopyrightText: 2024-2025 Soren Stoutner <soren@stoutner.com>
  *
  * This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc/>.
  *
- * Privacy Browser PC is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later
+ * version.
  *
- * Privacy Browser PC is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
  *
- * You should have received a copy of the GNU General Public License
- * along with Privacy Browser PC.  If not, see <http://www.gnu.org/licenses/>.
+ * You should have received a copy of the GNU General Public License along with
+ * this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
 // Application headers.
@@ -77,6 +77,8 @@ std::forward_list<EntryStruct *>* FilterListsDialog::getFilterListForwardList(Fi
     switch (sublistComboBoxPointer->currentIndex())
     {
         case FilterListHelper::MAIN_ALLOWLIST: return filterListStructPointer->mainAllowListPointer;  // The main allow list.
+        case FilterListHelper::INITIAL_DOMAIN_ALLOWLIST: return filterListStructPointer->initialDomainAllowListPointer;  // The initial domain allow list.
+        case FilterListHelper::REGULAR_EXPRESSION_ALLOWLIST: return filterListStructPointer->regularExpressionAllowListPointer;  // The regular expression allow list.
         case FilterListHelper::MAIN_BLOCKLIST: return filterListStructPointer->mainBlockListPointer;  // The main block list.
         case FilterListHelper::INITIAL_DOMAIN_BLOCKLIST: return filterListStructPointer->initialDomainBlockListPointer;  // The initial domain block list.
         case FilterListHelper::REGULAR_EXPRESSION_BLOCKLIST: return filterListStructPointer->regularExpressionBlockListPointer;  // The regular expression block list.
@@ -130,18 +132,24 @@ void FilterListsDialog::populateFilterListTextEdit(int filterListComboBoxIndex)
 
     // Calculate the size of the filter lists.
     int mainAllowListSize = distance(filterListStructPointer->mainAllowListPointer->begin(), filterListStructPointer->mainAllowListPointer->end());
+    int initialDomainAllowListSize = distance(filterListStructPointer->initialDomainAllowListPointer->begin(), filterListStructPointer->initialDomainAllowListPointer->end());
+    int regularExpressionAllowListSize = distance(filterListStructPointer->regularExpressionAllowListPointer->begin(), filterListStructPointer->regularExpressionAllowListPointer->end());
     int mainBlockListSize = distance(filterListStructPointer->mainBlockListPointer->begin(), filterListStructPointer->mainBlockListPointer->end());
     int initialDomainBlockListSize = distance(filterListStructPointer->initialDomainBlockListPointer->begin(), filterListStructPointer->initialDomainBlockListPointer->end());
     int regularExpressionBlockListSize = distance(filterListStructPointer->regularExpressionBlockListPointer->begin(), filterListStructPointer->regularExpressionBlockListPointer->end());
 
     // Get the translated filter list names.
     QString mainAllowListName = globalFilterListHelperPointer->getSublistName(FilterListHelper::MAIN_ALLOWLIST);
+    QString initialDomainAllowListName = globalFilterListHelperPointer->getSublistName(FilterListHelper::INITIAL_DOMAIN_ALLOWLIST);
+    QString regularExpressionAllowListName = globalFilterListHelperPointer->getSublistName(FilterListHelper::REGULAR_EXPRESSION_ALLOWLIST);
     QString mainBlockListName = globalFilterListHelperPointer->getSublistName(FilterListHelper::MAIN_BLOCKLIST);
     QString initialDomainBlockListName = globalFilterListHelperPointer->getSublistName(FilterListHelper::INITIAL_DOMAIN_BLOCKLIST);
     QString regularExpressionBlockListName = globalFilterListHelperPointer->getSublistName(FilterListHelper::REGULAR_EXPRESSION_BLOCKLIST);
 
     // Populate the sublist combo box.
     sublistComboBoxPointer->addItem(i18nc("The main allow list", "%1 - %2", mainAllowListName, mainAllowListSize));
+    sublistComboBoxPointer->addItem(i18nc("The initial domain allow list", "%1 - %2", initialDomainAllowListName, initialDomainAllowListSize));
+    sublistComboBoxPointer->addItem(i18nc("The regular expression allow list", "%1 - %2", regularExpressionAllowListName, regularExpressionAllowListSize));
     sublistComboBoxPointer->addItem(i18nc("The main block list", "%1 - %2", mainBlockListName, mainBlockListSize));
     sublistComboBoxPointer->addItem(i18nc("The initial domain block list", "%1 - %2", initialDomainBlockListName, initialDomainBlockListSize));
     sublistComboBoxPointer->addItem(i18nc("the regular expression block list", "%1 - %2", regularExpressionBlockListName, regularExpressionBlockListSize));
@@ -170,6 +178,14 @@ void FilterListsDialog::populateTableWidget(int sublistComboBoxIndex) const
                 filterListForwardListPointer = filterListStructPointer->mainAllowListPointer;
                 break;
 
+            case FilterListHelper::INITIAL_DOMAIN_ALLOWLIST:  // The initial domain allow list.
+                filterListForwardListPointer = filterListStructPointer->initialDomainAllowListPointer;
+                break;
+
+            case FilterListHelper::REGULAR_EXPRESSION_ALLOWLIST:  // The regular expression allow list.
+                filterListForwardListPointer = filterListStructPointer->regularExpressionAllowListPointer;
+                break;
+
             case FilterListHelper::MAIN_BLOCKLIST:  // The main block list.
                 filterListForwardListPointer = filterListStructPointer->mainBlockListPointer;
                 break;
@@ -184,7 +200,7 @@ void FilterListsDialog::populateTableWidget(int sublistComboBoxIndex) const
         }
 
         // Create the columns.
-        sublistTableWidgetPointer->setColumnCount(21);
+        sublistTableWidgetPointer->setColumnCount(22);
 
         // Create the table headers.
         QTableWidgetItem *appliedEntryListHeaderItemPointer = new QTableWidgetItem(i18nc("Sublist applied entry list header", "Applied Entry List"));
@@ -204,6 +220,7 @@ void FilterListsDialog::populateTableWidget(int sublistComboBoxIndex) const
         QTableWidgetItem *scriptHeaderItemPointer = new QTableWidgetItem(i18nc("Sublist script header", "Script"));
         QTableWidgetItem *styleSheetHeaderItemPointer = new QTableWidgetItem(i18nc("Sublist style sheet header", "Style Sheet"));
         QTableWidgetItem *subFrameHeaderItemPointer = new QTableWidgetItem(i18nc("Sublist sub frame header", "Sub Frame"));
+        QTableWidgetItem *webSocketHeaderItemPointer = new QTableWidgetItem(i18nc("Sublist web socket header", "Web Socket"));
         QTableWidgetItem *xmlHttpRequestHeaderItemPointer = new QTableWidgetItem(i18nc("Sublist XML HTTP request header", "XML HTTP Request"));
         QTableWidgetItem *appliedFilterOptionsHeaderItemPointer = new QTableWidgetItem(i18nc("Sublist applied filter options header", "Applied Filter Options"));
         QTableWidgetItem *originalFilterOptionsHeaderItemPointer = new QTableWidgetItem(i18nc("Sublist original filter options header", "Original Filter Options"));
@@ -227,10 +244,11 @@ void FilterListsDialog::populateTableWidget(int sublistComboBoxIndex) const
         sublistTableWidgetPointer->setHorizontalHeaderItem(14, scriptHeaderItemPointer);
         sublistTableWidgetPointer->setHorizontalHeaderItem(15, styleSheetHeaderItemPointer);
         sublistTableWidgetPointer->setHorizontalHeaderItem(16, subFrameHeaderItemPointer);
-        sublistTableWidgetPointer->setHorizontalHeaderItem(17, xmlHttpRequestHeaderItemPointer);
-        sublistTableWidgetPointer->setHorizontalHeaderItem(18, appliedFilterOptionsHeaderItemPointer);
-        sublistTableWidgetPointer->setHorizontalHeaderItem(19, originalFilterOptionsHeaderItemPointer);
-        sublistTableWidgetPointer->setHorizontalHeaderItem(20, originalEntryHeaderItemPointer);
+        sublistTableWidgetPointer->setHorizontalHeaderItem(17, webSocketHeaderItemPointer);
+        sublistTableWidgetPointer->setHorizontalHeaderItem(18, xmlHttpRequestHeaderItemPointer);
+        sublistTableWidgetPointer->setHorizontalHeaderItem(19, appliedFilterOptionsHeaderItemPointer);
+        sublistTableWidgetPointer->setHorizontalHeaderItem(20, originalFilterOptionsHeaderItemPointer);
+        sublistTableWidgetPointer->setHorizontalHeaderItem(21, originalEntryHeaderItemPointer);
 
         // Initialize the row counter.
         int rowCounter = 0;
@@ -261,6 +279,7 @@ void FilterListsDialog::populateTableWidget(int sublistComboBoxIndex) const
             QTableWidgetItem *scriptItemPointer = new QTableWidgetItem(globalFilterListHelperPointer->getRequestOptionDispositionString(entryStructPointer->script));
             QTableWidgetItem *styleSheetItemPointer = new QTableWidgetItem(globalFilterListHelperPointer->getRequestOptionDispositionString(entryStructPointer->styleSheet));
             QTableWidgetItem *subFrameItemPointer = new QTableWidgetItem(globalFilterListHelperPointer->getRequestOptionDispositionString(entryStructPointer->subFrame));
+            QTableWidgetItem *webSocketItemPointer = new QTableWidgetItem(globalFilterListHelperPointer->getRequestOptionDispositionString(entryStructPointer->webSocket));
             QTableWidgetItem *xmlHttpRequestItemPointer = new QTableWidgetItem(globalFilterListHelperPointer->getRequestOptionDispositionString(entryStructPointer->xmlHttpRequest));
             QTableWidgetItem *appliedFilterOptionsItemPointer = new QTableWidgetItem(entryStructPointer->appliedFilterOptionsList.join(QLatin1String(" , ")));
             QTableWidgetItem *originalFilterOptionsItemPointer = new QTableWidgetItem(entryStructPointer->originalFilterOptions);
@@ -284,10 +303,11 @@ void FilterListsDialog::populateTableWidget(int sublistComboBoxIndex) const
             sublistTableWidgetPointer->setItem(rowCounter, 14, scriptItemPointer);
             sublistTableWidgetPointer->setItem(rowCounter, 15, styleSheetItemPointer);
             sublistTableWidgetPointer->setItem(rowCounter, 16, subFrameItemPointer);
-            sublistTableWidgetPointer->setItem(rowCounter, 17, xmlHttpRequestItemPointer);
-            sublistTableWidgetPointer->setItem(rowCounter, 18, appliedFilterOptionsItemPointer);
-            sublistTableWidgetPointer->setItem(rowCounter, 19, originalFilterOptionsItemPointer);
-            sublistTableWidgetPointer->setItem(rowCounter, 20, originalEntryItemPointer);
+            sublistTableWidgetPointer->setItem(rowCounter, 17, webSocketItemPointer);
+            sublistTableWidgetPointer->setItem(rowCounter, 18, xmlHttpRequestItemPointer);
+            sublistTableWidgetPointer->setItem(rowCounter, 19, appliedFilterOptionsItemPointer);
+            sublistTableWidgetPointer->setItem(rowCounter, 20, originalFilterOptionsItemPointer);
+            sublistTableWidgetPointer->setItem(rowCounter, 21, originalEntryItemPointer);
 
             // Increment the row counter.
             ++rowCounter;
@@ -309,11 +329,17 @@ void FilterListsDialog::showFilterEntryDialog(int row)
     // Get the filter list struct.
     FilterListStruct *filterListStructPointer = getFilterListStruct(filterListComboBoxPointer->currentIndex());
 
+    // Get the sublist combo box index.
+    int sublistComboBoxIndex = sublistComboBoxPointer->currentIndex();
+
     // Create a sublist title.
-    QString sublistTitle = globalFilterListHelperPointer->getSublistName(sublistComboBoxPointer->currentIndex());
+    QString sublistTitle = globalFilterListHelperPointer->getSublistName(sublistComboBoxIndex);
+
+    // Determine if this is an allow list (which have indexes of 0-2).
+    bool isAllowList = (sublistComboBoxIndex <= 2);
 
     // Instantiate the filter entry dialog.
-    FilterEntryDialog *filterEntryDialogPointer = new FilterEntryDialog(this, sublistTableWidgetPointer, row, filterListStructPointer->title, sublistTitle);
+    FilterEntryDialog *filterEntryDialogPointer = new FilterEntryDialog(this, sublistTableWidgetPointer, row, filterListStructPointer->title, sublistTitle, isAllowList);
 
     // Show the dialog.
     filterEntryDialogPointer->show();