From 905d886a2626051a75180cf1818be35ba857bebc Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Fri, 5 Jul 2024 09:18:53 -0700 Subject: [PATCH] Flesh out request detail dialog. --- src/dialogs/FilterEntryDialog.cpp | 44 +- src/dialogs/RequestDetailDialog.cpp | 287 ++++++- src/dialogs/RequestDetailDialog.h | 45 +- src/dialogs/RequestsDialog.cpp | 39 +- src/enums/FilterOptionEnum.h | 32 - src/helpers/FilterListHelper.cpp | 539 ++++++------- src/helpers/FilterListHelper.h | 20 +- src/interceptors/UrlRequestInterceptor.cpp | 1 + src/structs/EntryStruct.h | 40 +- src/structs/RequestStruct.h | 19 +- src/structs/UrlStruct.h | 35 - src/uis/FilterEntryDialog.ui | 44 +- src/uis/RequestDetailDialog.ui | 863 ++++++++++++++++++--- 13 files changed, 1451 insertions(+), 557 deletions(-) delete mode 100644 src/enums/FilterOptionEnum.h delete mode 100644 src/structs/UrlStruct.h diff --git a/src/dialogs/FilterEntryDialog.cpp b/src/dialogs/FilterEntryDialog.cpp index 703ca04..d565d40 100644 --- a/src/dialogs/FilterEntryDialog.cpp +++ b/src/dialogs/FilterEntryDialog.cpp @@ -45,11 +45,11 @@ FilterEntryDialog::FilterEntryDialog(QWidget *parentWidgetPointer, QTableWidget QLineEdit *filterListLineEditPointer = filterEntryDialogUi.filterListLineEdit; QLineEdit *sublistLineEditPointer = filterEntryDialogUi.sublistListLineEdit; appliedEntryListLineEditPointer = filterEntryDialogUi.appliedEntryListLineEdit; + domainLineEditPointer = filterEntryDialogUi.domainLineEdit; + thirdPartyLineEditPointer = filterEntryDialogUi.thirdPartyLineEdit; initialMatchLineEditPointer = filterEntryDialogUi.initialMatchLineEdit; finalMatchLineEditPointer = filterEntryDialogUi.finalMatchLineEdit; - domainLineEditPointer = filterEntryDialogUi.domainLineEdit; domainListLineEditPointer = filterEntryDialogUi.domainListLineEdit; - thirdPartyLineEditPointer = filterEntryDialogUi.thirdPartyLineEdit; hasRequestOptionsCheckBoxPointer = filterEntryDialogUi.hasRequestOptionsCheckBox; fontLineEditPointer = filterEntryDialogUi.fontLineEdit; imageLineEditPointer = filterEntryDialogUi.imageLineEdit; @@ -89,8 +89,11 @@ FilterEntryDialog::FilterEntryDialog(QWidget *parentWidgetPointer, QTableWidget KColorScheme::adjustBackground(negativeBackgroundPalette, KColorScheme::NegativeBackground); KColorScheme::adjustBackground(positiveBackgroundPalette, KColorScheme::PositiveBackground); - // Set the sublist background palette. TODO Add logic for allow lists. - sublistLineEditPointer->setPalette(negativeBackgroundPalette); + // Set the sublist background palette. + if (sublistLineEditPointer->text().contains(QLatin1String("Allow"))) + sublistLineEditPointer->setPalette(positiveBackgroundPalette); + else + sublistLineEditPointer->setPalette(negativeBackgroundPalette); // Set the applied entry background palette to be the same as the sublist. appliedEntryListLineEditPointer->setPalette(sublistLineEditPointer->palette()); @@ -148,14 +151,17 @@ void FilterEntryDialog::populateDialog(const int row) originalFilterOptionsLineEditPointer->setText(tableWidgetPointer->item(row, 19)->text()); originalEntryLineEditPointer->setText(tableWidgetPointer->item(row, 20)->text()); + // Make a local copy of the has request options boolean. + bool hasRequestOptions = tableWidgetPointer->item(row, 6)->text() == i18n("Yes"); + // Populate the check boxes. - hasRequestOptionsCheckBoxPointer->setChecked(tableWidgetPointer->item(row, 6)->text() == i18n("Yes")); + hasRequestOptionsCheckBoxPointer->setChecked(hasRequestOptions); // Set the initial and final match background palettes. setInitialAndFinalMatchBackgroundPalette(initialMatchLineEditPointer); setInitialAndFinalMatchBackgroundPalette(finalMatchLineEditPointer); - // Set the request option background palettes and status. + // Set the request option background palettes. setFilterOptionBackgroundPalette(domainLineEditPointer); setFilterOptionBackgroundPalette(thirdPartyLineEditPointer); setFilterOptionBackgroundPalette(fontLineEditPointer); @@ -171,17 +177,17 @@ void FilterEntryDialog::populateDialog(const int row) setFilterOptionBackgroundPalette(xmlHttpRequestLineEditPointer); // Set the request option status. - fontLineEditPointer->setEnabled(hasRequestOptionsCheckBoxPointer->isChecked()); - imageLineEditPointer->setEnabled(hasRequestOptionsCheckBoxPointer->isChecked()); - mainFrameLineEditPointer->setEnabled(hasRequestOptionsCheckBoxPointer->isChecked()); - mediaLineEditPointer->setEnabled(hasRequestOptionsCheckBoxPointer->isChecked()); - objectLineEditPointer->setEnabled(hasRequestOptionsCheckBoxPointer->isChecked()); - otherLineEditPointer->setEnabled(hasRequestOptionsCheckBoxPointer->isChecked()); - pingLineEditPointer->setEnabled(hasRequestOptionsCheckBoxPointer->isChecked()); - scriptLineEditPointer->setEnabled(hasRequestOptionsCheckBoxPointer->isChecked()); - styleSheetLineEditPointer->setEnabled(hasRequestOptionsCheckBoxPointer->isChecked()); - subFrameLineEditPointer->setEnabled(hasRequestOptionsCheckBoxPointer->isChecked()); - xmlHttpRequestLineEditPointer->setEnabled(hasRequestOptionsCheckBoxPointer->isChecked()); + fontLineEditPointer->setEnabled(hasRequestOptions); + imageLineEditPointer->setEnabled(hasRequestOptions); + mainFrameLineEditPointer->setEnabled(hasRequestOptions); + mediaLineEditPointer->setEnabled(hasRequestOptions); + objectLineEditPointer->setEnabled(hasRequestOptions); + otherLineEditPointer->setEnabled(hasRequestOptions); + pingLineEditPointer->setEnabled(hasRequestOptions); + scriptLineEditPointer->setEnabled(hasRequestOptions); + styleSheetLineEditPointer->setEnabled(hasRequestOptions); + subFrameLineEditPointer->setEnabled(hasRequestOptions); + xmlHttpRequestLineEditPointer->setEnabled(hasRequestOptions); // Set the domain list line edit to have the same palette as the domain line edit. domainListLineEditPointer->setPalette(domainLineEditPointer->palette()); @@ -212,12 +218,12 @@ void FilterEntryDialog::next() void FilterEntryDialog::setFilterOptionBackgroundPalette(QLineEdit *lineEditPointer) { // Set the background palette according to the text. - if (lineEditPointer->text() == globalFilterListHelperPointer->getRequestOptionDispositionString(FilterOptionEnum::Disposition::Null)) // Not text is displayed. + if (lineEditPointer->text() == globalFilterListHelperPointer->getRequestOptionDispositionString(FilterOptionDisposition::Null)) // Not text is displayed. { // Set the normal background palette. lineEditPointer->setPalette(normalBackgroundPalette); } - else if (lineEditPointer->text() == globalFilterListHelperPointer->getRequestOptionDispositionString(FilterOptionEnum::Disposition::Apply)) // `Apply` is displayed. + else if (lineEditPointer->text() == globalFilterListHelperPointer->getRequestOptionDispositionString(FilterOptionDisposition::Apply)) // `Apply` is displayed. { // Set the negative (red) background palette. lineEditPointer->setPalette(negativeBackgroundPalette); diff --git a/src/dialogs/RequestDetailDialog.cpp b/src/dialogs/RequestDetailDialog.cpp index 78e2f00..28547e1 100644 --- a/src/dialogs/RequestDetailDialog.cpp +++ b/src/dialogs/RequestDetailDialog.cpp @@ -21,7 +21,6 @@ #include "RequestDetailDialog.h" #include "GlobalVariables.h" #include "ui_RequestDetailDialog.h" -#include "structs/RequestStruct.h" // KDE Frameworks headers. #include @@ -45,24 +44,47 @@ RequestDetailDialog::RequestDetailDialog(QWidget *parentWidgetPointer, QTableWid // Get handles for the views. dispositionLineEditPointer = requestDetailDialogUi.dispositionLineEdit; - urlLineEditPointer = requestDetailDialogUi.urlLineEdit; + webPageUrlLineEditPointer = requestDetailDialogUi.webPageUrlLineEdit; + requestUrlLineEditPointer = requestDetailDialogUi.requestUrlLineEdit; + requestUrlWithSeparatorsLineEditPointer = requestDetailDialogUi.requestUrlWithSeparatorsLineEdit; + truncatedRequestUrlLineEditPointer = requestDetailDialogUi.truncatedRequestUrlLineEdit; + truncatedRequestUrlWithSeparatorsLineEditPointer = requestDetailDialogUi.truncatedRequestUrlWithSeparatorsLineEdit; requestMethodLineEditPointer = requestDetailDialogUi.requestMethodLineEdit; navigationTypeLineEditPointer = requestDetailDialogUi.navigationTypeLineEdit; + thirdPartyRequestLineEditPointer = requestDetailDialogUi.thirdPartyRequestLineEdit; resourceTypeLineEditPointer = requestDetailDialogUi.resourceTypeLineEdit; - horizontalLinePointer = requestDetailDialogUi.horizontalLine; - filterListLabelPointer = requestDetailDialogUi.filterListLabel; + filterListEntryWidget = requestDetailDialogUi.filterListEntryWidget; filterListLineEditPointer = requestDetailDialogUi.filterListLineEdit; - sublistLabelPointer = requestDetailDialogUi.sublistLabel; sublistLineEditPointer = requestDetailDialogUi.sublistListLineEdit; - appliedEntryListLabelPointer = requestDetailDialogUi.appliedEntryListLabel; appliedEntryListLineEditPointer = requestDetailDialogUi.appliedEntryListLineEdit; - originalEntryLabelPointer = requestDetailDialogUi.originalEntryLabel; + domainLineEditPointer = requestDetailDialogUi.domainLineEdit; + thirdPartyFilterLineEditPointer = requestDetailDialogUi.thirdPartyFilterLineEdit; + initialMatchLineEditPointer = requestDetailDialogUi.initialMatchLineEdit; + finalMatchLineEditPointer = requestDetailDialogUi.finalMatchLineEdit; + domainListLineEditPointer = requestDetailDialogUi.domainListLineEdit; + hasRequestOptionsCheckBoxPointer = requestDetailDialogUi.hasRequestOptionsCheckBox; + fontLineEditPointer = requestDetailDialogUi.fontLineEdit; + imageLineEditPointer = requestDetailDialogUi.imageLineEdit; + mainFrameLineEditPointer = requestDetailDialogUi.mainFrameLineEdit; + mediaLineEditPointer = requestDetailDialogUi.mediaLineEdit; + objectLineEditPointer = requestDetailDialogUi.objectLineEdit; + otherLineEditPointer = requestDetailDialogUi.otherLineEdit; + pingLineEditPointer = requestDetailDialogUi.pingLineEdit; + scriptLineEditPointer = requestDetailDialogUi.scriptLineEdit; + styleSheetLineEditPointer = requestDetailDialogUi.styleSheetLineEdit; + subFrameLineEditPointer = requestDetailDialogUi.subFrameLineEdit; + xmlHttpRequestLineEditPointer = requestDetailDialogUi.xmlHttpRequestLineEdit; + appliedFilterOptionsLineEditPointer = requestDetailDialogUi.appliedFilterOptionsLineEdit; + originalFilterOptionsLineEditPointer = requestDetailDialogUi.originalFilterOptionsLineEdit; originalEntryLineEditPointer = requestDetailDialogUi.originalEntryLineEdit; previousButtonPointer = requestDetailDialogUi.previousButton; nextButtonPointer = requestDetailDialogUi.nextButton; QDialogButtonBox *dialogButtonBoxPointer = requestDetailDialogUi.dialogButtonBox; QPushButton *closeButtonPointer = dialogButtonBoxPointer->button(QDialogButtonBox::StandardButton::Close); + // Disable changing the checkbox checked status. + hasRequestOptionsCheckBoxPointer->setAttribute(Qt::WA_TransparentForMouseEvents); + // Make the close button the default. closeButtonPointer->setDefault(true); @@ -123,30 +145,135 @@ void RequestDetailDialog::populateDialog(const int row) // Populate the new request struct. requestStructDataStreamReader >> requestStructPointer->dispositionInt; - requestStructDataStreamReader >> requestStructPointer->entryStruct.appliedEntryList; requestStructDataStreamReader >> requestStructPointer->entryStruct.originalEntry; + requestStructDataStreamReader >> requestStructPointer->entryStruct.originalFilterOptions; + requestStructDataStreamReader >> requestStructPointer->entryStruct.appliedEntryList; + requestStructDataStreamReader >> requestStructPointer->entryStruct.appliedFilterOptionsList; + requestStructDataStreamReader >> requestStructPointer->entryStruct.domainList; + requestStructDataStreamReader >> requestStructPointer->entryStruct.finalMatch; + requestStructDataStreamReader >> requestStructPointer->entryStruct.hasRequestOptions; + requestStructDataStreamReader >> requestStructPointer->entryStruct.initialMatch; + requestStructDataStreamReader >> requestStructPointer->entryStruct.domain; + requestStructDataStreamReader >> requestStructPointer->entryStruct.font; + requestStructDataStreamReader >> requestStructPointer->entryStruct.image; + requestStructDataStreamReader >> requestStructPointer->entryStruct.mainFrame; + requestStructDataStreamReader >> requestStructPointer->entryStruct.media; + requestStructDataStreamReader >> requestStructPointer->entryStruct.object; + requestStructDataStreamReader >> requestStructPointer->entryStruct.other; + requestStructDataStreamReader >> requestStructPointer->entryStruct.ping; + requestStructDataStreamReader >> requestStructPointer->entryStruct.script; + requestStructDataStreamReader >> requestStructPointer->entryStruct.styleSheet; + requestStructDataStreamReader >> requestStructPointer->entryStruct.subFrame; + requestStructDataStreamReader >> requestStructPointer->entryStruct.thirdParty; + requestStructDataStreamReader >> requestStructPointer->entryStruct.xmlHttpRequest; requestStructDataStreamReader >> requestStructPointer->filterListTitle; + requestStructDataStreamReader >> requestStructPointer->isThirdPartyRequest; + requestStructDataStreamReader >> requestStructPointer->matchedUrlType; requestStructDataStreamReader >> requestStructPointer->navigationTypeInt; requestStructDataStreamReader >> requestStructPointer->requestMethodString; requestStructDataStreamReader >> requestStructPointer->resourceTypeInt; requestStructDataStreamReader >> requestStructPointer->sublistInt; + requestStructDataStreamReader >> requestStructPointer->truncatedUrlString; + requestStructDataStreamReader >> requestStructPointer->truncatedUrlStringWithSeparators; requestStructDataStreamReader >> requestStructPointer->urlString; + requestStructDataStreamReader >> requestStructPointer->urlStringWithSeparators; + requestStructDataStreamReader >> requestStructPointer->webPageUrlString; + + // Make a local copy of the has request options boolean. + bool hasRequestOptions = requestStructPointer->entryStruct.hasRequestOptions; // Populate the views. dispositionLineEditPointer->setText(globalFilterListHelperPointer->getDispositionString(requestStructPointer->dispositionInt)); - urlLineEditPointer->setText(requestStructPointer->urlString); + webPageUrlLineEditPointer->setText(requestStructPointer->webPageUrlString); + requestUrlLineEditPointer->setText(requestStructPointer->urlString); + requestUrlWithSeparatorsLineEditPointer->setText(requestStructPointer->urlStringWithSeparators); + truncatedRequestUrlLineEditPointer->setText(requestStructPointer->truncatedUrlString); + truncatedRequestUrlWithSeparatorsLineEditPointer->setText(requestStructPointer->truncatedUrlStringWithSeparators); requestMethodLineEditPointer->setText(requestStructPointer->requestMethodString); + thirdPartyRequestLineEditPointer->setText(requestStructPointer->isThirdPartyRequest ? i18n("Yes") : QLatin1String()); navigationTypeLineEditPointer->setText(globalFilterListHelperPointer->getNavigationTypeString(requestStructPointer->navigationTypeInt)); resourceTypeLineEditPointer->setText(globalFilterListHelperPointer->getResourceTypeString(requestStructPointer->resourceTypeInt)); filterListLineEditPointer->setText(requestStructPointer->filterListTitle); sublistLineEditPointer->setText(globalFilterListHelperPointer->getSublistName(requestStructPointer->sublistInt)); appliedEntryListLineEditPointer->setText(requestStructPointer->entryStruct.appliedEntryList.join(QLatin1String(" * "))); + domainLineEditPointer->setText(globalFilterListHelperPointer->getRequestOptionDispositionString(requestStructPointer->entryStruct.domain)); + thirdPartyFilterLineEditPointer->setText(globalFilterListHelperPointer->getRequestOptionDispositionString(requestStructPointer->entryStruct.thirdParty)); + initialMatchLineEditPointer->setText(requestStructPointer->entryStruct.initialMatch ? i18n("Yes") : QLatin1String()); + finalMatchLineEditPointer->setText(requestStructPointer->entryStruct.finalMatch ? i18n("Yes") : QLatin1String()); + domainListLineEditPointer->setText(requestStructPointer->entryStruct.domainList.join(QLatin1String(" | "))); + hasRequestOptionsCheckBoxPointer->setChecked(hasRequestOptions); + fontLineEditPointer->setText(globalFilterListHelperPointer->getRequestOptionDispositionString(requestStructPointer->entryStruct.font)); + imageLineEditPointer->setText(globalFilterListHelperPointer->getRequestOptionDispositionString(requestStructPointer->entryStruct.image)); + mainFrameLineEditPointer->setText(globalFilterListHelperPointer->getRequestOptionDispositionString(requestStructPointer->entryStruct.mainFrame)); + mediaLineEditPointer->setText(globalFilterListHelperPointer->getRequestOptionDispositionString(requestStructPointer->entryStruct.media)); + objectLineEditPointer->setText(globalFilterListHelperPointer->getRequestOptionDispositionString(requestStructPointer->entryStruct.object)); + otherLineEditPointer->setText(globalFilterListHelperPointer->getRequestOptionDispositionString(requestStructPointer->entryStruct.other)); + pingLineEditPointer->setText(globalFilterListHelperPointer->getRequestOptionDispositionString(requestStructPointer->entryStruct.ping)); + scriptLineEditPointer->setText(globalFilterListHelperPointer->getRequestOptionDispositionString(requestStructPointer->entryStruct.script)); + styleSheetLineEditPointer->setText(globalFilterListHelperPointer->getRequestOptionDispositionString(requestStructPointer->entryStruct.styleSheet)); + subFrameLineEditPointer->setText(globalFilterListHelperPointer->getRequestOptionDispositionString(requestStructPointer->entryStruct.subFrame)); + xmlHttpRequestLineEditPointer->setText(globalFilterListHelperPointer->getRequestOptionDispositionString(requestStructPointer->entryStruct.xmlHttpRequest)); + appliedFilterOptionsLineEditPointer->setText(requestStructPointer->entryStruct.appliedFilterOptionsList.join(QLatin1String(" , "))); + originalFilterOptionsLineEditPointer->setText(requestStructPointer->entryStruct.originalFilterOptions); originalEntryLineEditPointer->setText(requestStructPointer->entryStruct.originalEntry); + // Set the "Yes" background palettes. + setYesBackgroundPalette(thirdPartyRequestLineEditPointer); + setYesBackgroundPalette(initialMatchLineEditPointer); + setYesBackgroundPalette(finalMatchLineEditPointer); + + // Set the request option background palettes. + setFilterOptionBackgroundPalette(domainLineEditPointer); + setFilterOptionBackgroundPalette(thirdPartyFilterLineEditPointer); + setFilterOptionBackgroundPalette(fontLineEditPointer); + setFilterOptionBackgroundPalette(imageLineEditPointer); + setFilterOptionBackgroundPalette(mainFrameLineEditPointer); + setFilterOptionBackgroundPalette(mediaLineEditPointer); + setFilterOptionBackgroundPalette(objectLineEditPointer); + setFilterOptionBackgroundPalette(otherLineEditPointer); + setFilterOptionBackgroundPalette(pingLineEditPointer); + setFilterOptionBackgroundPalette(scriptLineEditPointer); + setFilterOptionBackgroundPalette(styleSheetLineEditPointer); + setFilterOptionBackgroundPalette(subFrameLineEditPointer); + setFilterOptionBackgroundPalette(xmlHttpRequestLineEditPointer); + + // Set the request option status. + fontLineEditPointer->setEnabled(hasRequestOptions); + imageLineEditPointer->setEnabled(hasRequestOptions); + mainFrameLineEditPointer->setEnabled(hasRequestOptions); + mediaLineEditPointer->setEnabled(hasRequestOptions); + objectLineEditPointer->setEnabled(hasRequestOptions); + otherLineEditPointer->setEnabled(hasRequestOptions); + pingLineEditPointer->setEnabled(hasRequestOptions); + scriptLineEditPointer->setEnabled(hasRequestOptions); + styleSheetLineEditPointer->setEnabled(hasRequestOptions); + subFrameLineEditPointer->setEnabled(hasRequestOptions); + xmlHttpRequestLineEditPointer->setEnabled(hasRequestOptions); + + // Set the domain list line edit to have the same palette as the domain line edit. + domainListLineEditPointer->setPalette(domainLineEditPointer->palette()); + // Set the button status. previousButtonPointer->setEnabled(previousEnabled); nextButtonPointer->setEnabled(nextEnabled); + // Set the sublist background palette. + switch (requestStructPointer->sublistInt) + { + case FilterListHelper::MAIN_ALLOWLIST: + sublistLineEditPointer->setPalette(positiveBackgroundPalette); + break; + + case FilterListHelper::MAIN_BLOCKLIST: + case FilterListHelper::INITIAL_DOMAIN_BLOCKLIST: + case FilterListHelper::REGULAR_EXPRESSION_BLOCKLIST: + sublistLineEditPointer->setPalette(negativeBackgroundPalette); + break; + } + + // Set the applied entry background palette to be the same as the sublist. + appliedEntryListLineEditPointer->setPalette(sublistLineEditPointer->palette()); + // Modify the interface based on the disposition. switch (requestStructPointer->dispositionInt) { @@ -155,16 +282,14 @@ void RequestDetailDialog::populateDialog(const int row) // Reset the disposition line edit background. dispositionLineEditPointer->setPalette(normalBackgroundPalette); - // Hide the views. - horizontalLinePointer->hide(); - filterListLabelPointer->hide(); - filterListLineEditPointer->hide(); - sublistLabelPointer->hide(); - sublistLineEditPointer->hide(); - appliedEntryListLabelPointer->hide(); - appliedEntryListLineEditPointer->hide(); - originalEntryLabelPointer->hide(); - originalEntryLineEditPointer->hide(); + // Reset the request URL palettes. + requestUrlLineEditPointer->setPalette(normalBackgroundPalette); + requestUrlWithSeparatorsLineEditPointer->setPalette(normalBackgroundPalette); + truncatedRequestUrlLineEditPointer->setPalette(normalBackgroundPalette); + truncatedRequestUrlWithSeparatorsLineEditPointer->setPalette(normalBackgroundPalette); + + // Hide the filter list entry views. + filterListEntryWidget->hide(); break; } @@ -174,16 +299,11 @@ void RequestDetailDialog::populateDialog(const int row) // Colorize the disposition line edit background. dispositionLineEditPointer->setPalette(positiveBackgroundPalette); - // Show the views. - horizontalLinePointer->show(); - filterListLabelPointer->show(); - filterListLineEditPointer->show(); - sublistLabelPointer->show(); - sublistLineEditPointer->show(); - appliedEntryListLabelPointer->show(); - appliedEntryListLineEditPointer->show(); - originalEntryLabelPointer->show(); - originalEntryLineEditPointer->show(); + // Colorize the request URLs. + setRequestUrlBackgroundPalettes(requestStructPointer->matchedUrlType); + + // Show the filter list entry views. + filterListEntryWidget->show(); break; } @@ -193,16 +313,11 @@ void RequestDetailDialog::populateDialog(const int row) // Colorize the disposition line edit background. dispositionLineEditPointer->setPalette(negativeBackgroundPalette); - // Show the views. - horizontalLinePointer->show(); - filterListLabelPointer->show(); - filterListLineEditPointer->show(); - sublistLabelPointer->show(); - sublistLineEditPointer->show(); - appliedEntryListLabelPointer->show(); - appliedEntryListLineEditPointer->show(); - originalEntryLabelPointer->show(); - originalEntryLineEditPointer->show(); + // Colorize the request URLs. + setRequestUrlBackgroundPalettes(requestStructPointer->matchedUrlType); + + // Show the filter list entry views. + filterListEntryWidget->show(); break; } @@ -226,3 +341,97 @@ void RequestDetailDialog::next() // Populate the dialog. populateDialog(currentRow); } + +void RequestDetailDialog::setFilterOptionBackgroundPalette(QLineEdit *lineEditPointer) +{ + // Set the background palette according to the text. + if (lineEditPointer->text() == globalFilterListHelperPointer->getRequestOptionDispositionString(FilterOptionDisposition::Null)) // Not text is displayed. + { + // Set the normal background palette. + lineEditPointer->setPalette(normalBackgroundPalette); + } + else if (lineEditPointer->text() == globalFilterListHelperPointer->getRequestOptionDispositionString(FilterOptionDisposition::Apply)) // `Apply` is displayed. + { + // Set the negative (red) background palette. + lineEditPointer->setPalette(negativeBackgroundPalette); + } + else // `Override` is displayed. + { + // Set the positive (green) background palette. + lineEditPointer->setPalette(positiveBackgroundPalette); + } +} + +void RequestDetailDialog::setRequestUrlBackgroundPalettes(RequestUrlType matchedUrlType) +{ + // Colorize the request URL strings according to the matched URL. + switch (matchedUrlType) + { + case RequestUrlType::Url: // URL. + { + // Set the request URL palette to match the disposition line edit. + requestUrlLineEditPointer->setPalette(dispositionLineEditPointer->palette()); + + // Reset the other palettes. + requestUrlWithSeparatorsLineEditPointer->setPalette(normalBackgroundPalette); + truncatedRequestUrlLineEditPointer->setPalette(normalBackgroundPalette); + truncatedRequestUrlWithSeparatorsLineEditPointer->setPalette(normalBackgroundPalette); + + break; + } + + case RequestUrlType::UrlWithSeparators: // URL with separators. + { + // Set the request URL with separators palette to match the disposition line edit. + requestUrlWithSeparatorsLineEditPointer->setPalette(dispositionLineEditPointer->palette()); + + // Reset the other palettes. + requestUrlLineEditPointer->setPalette(normalBackgroundPalette); + truncatedRequestUrlLineEditPointer->setPalette(normalBackgroundPalette); + truncatedRequestUrlWithSeparatorsLineEditPointer->setPalette(normalBackgroundPalette); + + break; + } + + case RequestUrlType::TruncatedUrl: // Truncated URL. + { + // Set the truncated request URL palette to match the disposition line edit. + truncatedRequestUrlLineEditPointer->setPalette(dispositionLineEditPointer->palette()); + + // Reset the other palettes. + requestUrlLineEditPointer->setPalette(normalBackgroundPalette); + requestUrlWithSeparatorsLineEditPointer->setPalette(normalBackgroundPalette); + truncatedRequestUrlWithSeparatorsLineEditPointer->setPalette(normalBackgroundPalette); + + break; + } + + case RequestUrlType::TruncatedUrlWithSeparators: // Truncated URL with separators. + { + // Set the truncated request URL with separators palette to match the disposition line edit. + truncatedRequestUrlWithSeparatorsLineEditPointer->setPalette(dispositionLineEditPointer->palette()); + + // Reset the other palettes. + requestUrlLineEditPointer->setPalette(normalBackgroundPalette); + requestUrlWithSeparatorsLineEditPointer->setPalette(normalBackgroundPalette); + truncatedRequestUrlLineEditPointer->setPalette(normalBackgroundPalette); + + break; + } + } +} + +void RequestDetailDialog::setYesBackgroundPalette(QLineEdit *lineEditPointer) +{ + // Set the background palette according to the text. + if (lineEditPointer->text() == i18n("Yes")) // `Yes` is displayed. + { + // Set the negative (red) background palette. + lineEditPointer->setPalette(negativeBackgroundPalette); + } + else // No text is displayed. + { + // Set the normal background palette. + lineEditPointer->setPalette(normalBackgroundPalette); + } +} diff --git a/src/dialogs/RequestDetailDialog.h b/src/dialogs/RequestDetailDialog.h index 8fb21c4..2d01aa6 100644 --- a/src/dialogs/RequestDetailDialog.h +++ b/src/dialogs/RequestDetailDialog.h @@ -17,10 +17,14 @@ * along with Privacy Browser PC. If not, see . */ -#ifndef REQUESTDETAILDIALOG_H -#define REQUESTDETAILDIALOG_H +#ifndef REQUEST_DETAIL_DIALOG_H +#define REQUEST_DETAIL_DIALOG_H + +// Application headers. +#include "structs/RequestStruct.h" // Qt toolkit headers. +#include #include #include #include @@ -41,29 +45,52 @@ private Q_SLOTS: private: // The private variables. - QLabel *appliedEntryListLabelPointer; QLineEdit *appliedEntryListLineEditPointer; + QLineEdit *appliedFilterOptionsLineEditPointer; int currentRow; QLineEdit *dispositionLineEditPointer; - QLabel *filterListLabelPointer; + QLineEdit *domainLineEditPointer; + QLineEdit *domainListLineEditPointer; + QWidget *filterListEntryWidget; QLineEdit *filterListLineEditPointer; - QFrame *horizontalLinePointer; + QLineEdit *finalMatchLineEditPointer; + QLineEdit *fontLineEditPointer; + QCheckBox *hasRequestOptionsCheckBoxPointer; + QLineEdit *imageLineEditPointer; + QLineEdit *initialMatchLineEditPointer; + QLineEdit *mainFrameLineEditPointer; + QLineEdit *mediaLineEditPointer; QLineEdit *navigationTypeLineEditPointer; QPalette negativeBackgroundPalette; QPushButton *nextButtonPointer; QPalette normalBackgroundPalette; - QLabel *originalEntryLabelPointer; + QLineEdit *objectLineEditPointer; QLineEdit *originalEntryLineEditPointer; - QPushButton *previousButtonPointer; + QLineEdit *originalFilterOptionsLineEditPointer; + QLineEdit *otherLineEditPointer; + QLineEdit *pingLineEditPointer; QPalette positiveBackgroundPalette; + QPushButton *previousButtonPointer; QLineEdit *requestMethodLineEditPointer; + QLineEdit *requestUrlLineEditPointer; + QLineEdit *requestUrlWithSeparatorsLineEditPointer; QLineEdit *resourceTypeLineEditPointer; - QLabel *sublistLabelPointer; + QLineEdit *scriptLineEditPointer; + QLineEdit *styleSheetLineEditPointer; + QLineEdit *subFrameLineEditPointer; QLineEdit *sublistLineEditPointer; QTableWidget *tableWidgetPointer; - QLineEdit *urlLineEditPointer; + QLineEdit *truncatedRequestUrlLineEditPointer; + QLineEdit *truncatedRequestUrlWithSeparatorsLineEditPointer; + QLineEdit *thirdPartyFilterLineEditPointer; + QLineEdit *thirdPartyRequestLineEditPointer; + QLineEdit *webPageUrlLineEditPointer; + QLineEdit *xmlHttpRequestLineEditPointer; // The private functions. void populateDialog(const int row); + void setFilterOptionBackgroundPalette(QLineEdit *lineEditPointer); + void setRequestUrlBackgroundPalettes(RequestUrlType matchedUrlType); + void setYesBackgroundPalette(QLineEdit *lineEditPointer); }; #endif diff --git a/src/dialogs/RequestsDialog.cpp b/src/dialogs/RequestsDialog.cpp index 43e1809..2ed1ba4 100644 --- a/src/dialogs/RequestsDialog.cpp +++ b/src/dialogs/RequestsDialog.cpp @@ -56,14 +56,14 @@ RequestsDialog::RequestsDialog(QWidget *parentWidgetPointer, QListsetHorizontalHeaderItem(0, dispositionHeaderItemPointer); tableWidgetPointer->setHorizontalHeaderItem(1, requestMethodHeaderItemPointer); tableWidgetPointer->setHorizontalHeaderItem(2, navigationTypeHeaderItemPointer); tableWidgetPointer->setHorizontalHeaderItem(3, resourceTypeHeaderItemPointer); - tableWidgetPointer->setHorizontalHeaderItem(4, urlHeaderItemPointer); + tableWidgetPointer->setHorizontalHeaderItem(4, requestUrlHeaderItemPointer); // Create the palette. QPalette negativePalette = QPalette(); @@ -90,7 +90,7 @@ RequestsDialog::RequestsDialog(QWidget *parentWidgetPointer, QListrequestMethodString); QTableWidgetItem *navigationTypeItemPointer = new QTableWidgetItem(globalFilterListHelperPointer->getNavigationTypeString(requestStructPointer->navigationTypeInt)); QTableWidgetItem *resourceTypeItemPointer = new QTableWidgetItem(globalFilterListHelperPointer->getResourceTypeString(requestStructPointer->resourceTypeInt)); - QTableWidgetItem *urlItemPointer = new QTableWidgetItem(requestStructPointer->urlString); + QTableWidgetItem *requestUrlItemPointer = new QTableWidgetItem(requestStructPointer->urlString); // Create a request struct byte array. QByteArray *requestStructByteArrayPointer = new QByteArray(); @@ -100,14 +100,39 @@ RequestsDialog::RequestsDialog(QWidget *parentWidgetPointer, QListdispositionInt; - requestStructDataStream << requestStructPointer->entryStruct.appliedEntryList; requestStructDataStream << requestStructPointer->entryStruct.originalEntry; + requestStructDataStream << requestStructPointer->entryStruct.originalFilterOptions; + requestStructDataStream << requestStructPointer->entryStruct.appliedEntryList; + requestStructDataStream << requestStructPointer->entryStruct.appliedFilterOptionsList; + requestStructDataStream << requestStructPointer->entryStruct.domainList; + requestStructDataStream << requestStructPointer->entryStruct.finalMatch; + requestStructDataStream << requestStructPointer->entryStruct.hasRequestOptions; + requestStructDataStream << requestStructPointer->entryStruct.initialMatch; + requestStructDataStream << requestStructPointer->entryStruct.domain; + requestStructDataStream << requestStructPointer->entryStruct.font; + requestStructDataStream << requestStructPointer->entryStruct.image; + requestStructDataStream << requestStructPointer->entryStruct.mainFrame; + requestStructDataStream << requestStructPointer->entryStruct.media; + requestStructDataStream << requestStructPointer->entryStruct.object; + requestStructDataStream << requestStructPointer->entryStruct.other; + requestStructDataStream << requestStructPointer->entryStruct.ping; + requestStructDataStream << requestStructPointer->entryStruct.script; + requestStructDataStream << requestStructPointer->entryStruct.styleSheet; + requestStructDataStream << requestStructPointer->entryStruct.subFrame; + requestStructDataStream << requestStructPointer->entryStruct.thirdParty; + requestStructDataStream << requestStructPointer->entryStruct.xmlHttpRequest; requestStructDataStream << requestStructPointer->filterListTitle; + requestStructDataStream << requestStructPointer->isThirdPartyRequest; + requestStructDataStream << requestStructPointer->matchedUrlType; requestStructDataStream << requestStructPointer->navigationTypeInt; requestStructDataStream << requestStructPointer->requestMethodString; requestStructDataStream << requestStructPointer->resourceTypeInt; requestStructDataStream << requestStructPointer->sublistInt; + requestStructDataStream << requestStructPointer->truncatedUrlString; + requestStructDataStream << requestStructPointer->truncatedUrlStringWithSeparators; requestStructDataStream << requestStructPointer->urlString; + requestStructDataStream << requestStructPointer->urlStringWithSeparators; + requestStructDataStream << requestStructPointer->webPageUrlString; // Add the request struct to the disposition item. dispositionItemPointer->setData(Qt::UserRole, *requestStructByteArrayPointer); @@ -120,7 +145,7 @@ RequestsDialog::RequestsDialog(QWidget *parentWidgetPointer, QListsetBackground(negativeBackgroundBrush); navigationTypeItemPointer->setBackground(negativeBackgroundBrush); resourceTypeItemPointer->setBackground(negativeBackgroundBrush); - urlItemPointer->setBackground(negativeBackgroundBrush); + requestUrlItemPointer->setBackground(negativeBackgroundBrush); } else if (requestStructPointer->dispositionInt == FilterListHelper::ALLOWED) // The request was allowed. { @@ -129,7 +154,7 @@ RequestsDialog::RequestsDialog(QWidget *parentWidgetPointer, QListsetBackground(positiveBackgroundBrush); navigationTypeItemPointer->setBackground(positiveBackgroundBrush); resourceTypeItemPointer->setBackground(positiveBackgroundBrush); - urlItemPointer->setBackground(positiveBackgroundBrush); + requestUrlItemPointer->setBackground(positiveBackgroundBrush); } // Add the entries to the table. @@ -137,7 +162,7 @@ RequestsDialog::RequestsDialog(QWidget *parentWidgetPointer, QListsetItem(rowCounter, 1, requestMethodItemPointer); tableWidgetPointer->setItem(rowCounter, 2, navigationTypeItemPointer); tableWidgetPointer->setItem(rowCounter, 3, resourceTypeItemPointer); - tableWidgetPointer->setItem(rowCounter, 4, urlItemPointer); + tableWidgetPointer->setItem(rowCounter, 4, requestUrlItemPointer); // Increment the row counter. ++rowCounter; diff --git a/src/enums/FilterOptionEnum.h b/src/enums/FilterOptionEnum.h deleted file mode 100644 index 8c01510..0000000 --- a/src/enums/FilterOptionEnum.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2024 Soren Stoutner . - * - * This file is part of 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. - * - * 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. - * - * You should have received a copy of the GNU General Public License - * along with Privacy Browser PC. If not, see . - */ - -#ifndef FILTEROPTIONENUM_H -#define FILTEROPTIONENUM_H - -struct FilterOptionEnum -{ - enum Disposition - { - Null = 0, - Apply = 1, - Override = 2, - }; -}; -#endif diff --git a/src/helpers/FilterListHelper.cpp b/src/helpers/FilterListHelper.cpp index e4ce25f..69bc80e 100644 --- a/src/helpers/FilterListHelper.cpp +++ b/src/helpers/FilterListHelper.cpp @@ -94,87 +94,85 @@ bool FilterListHelper::checkFilterLists(QWebEngineUrlRequestInfo &urlRequestInfo // Initiate a continue checking tracker. If the tracker changes to false, all processing of the request will be stopped. bool continueChecking = true; - // Create a URL struct. - UrlStruct urlStruct; - // Get the URLs. QUrl firstPartyUrl = urlRequestInfo.firstPartyUrl(); QUrl requestUrl = urlRequestInfo.requestUrl(); // Get the hosts. QString firstPartyHost = firstPartyUrl.host(); - urlStruct.fqdn = requestUrl.host(); + requestStructPointer->fqdn = requestUrl.host(); // Determine if this is a third-party request. - urlStruct.isThirdPartyRequest = (firstPartyHost != urlStruct.fqdn); + requestStructPointer->isThirdPartyRequest = (firstPartyHost != requestStructPointer->fqdn); // Get the request URL string. - urlStruct.urlString = requestUrl.toString(); + requestStructPointer->urlString = requestUrl.toString(); // Create a URL string with separators. - urlStruct.urlStringWithSeparators = urlStruct.urlString; + requestStructPointer->urlStringWithSeparators = requestStructPointer->urlString; // Replace the separators characters with `^`. - urlStruct.urlStringWithSeparators.replace(QLatin1Char(':'), QLatin1Char('^')); - urlStruct.urlStringWithSeparators.replace(QLatin1Char('/'), QLatin1Char('^')); - urlStruct.urlStringWithSeparators.replace(QLatin1Char('?'), QLatin1Char('^')); - urlStruct.urlStringWithSeparators.replace(QLatin1Char('='), QLatin1Char('^')); - urlStruct.urlStringWithSeparators.replace(QLatin1Char('&'), QLatin1Char('^')); + requestStructPointer->urlStringWithSeparators.replace(QLatin1Char(':'), QLatin1Char('^')); + requestStructPointer->urlStringWithSeparators.replace(QLatin1Char('/'), QLatin1Char('^')); + requestStructPointer->urlStringWithSeparators.replace(QLatin1Char('?'), QLatin1Char('^')); + requestStructPointer->urlStringWithSeparators.replace(QLatin1Char('='), QLatin1Char('^')); + requestStructPointer->urlStringWithSeparators.replace(QLatin1Char('&'), QLatin1Char('^')); // Add a `^` to the end of the string it it doesn't already contain one. - if (!urlStruct.urlStringWithSeparators.endsWith(QLatin1Char('^'))) - urlStruct.urlStringWithSeparators.append(QLatin1Char('^')); + if (!requestStructPointer->urlStringWithSeparators.endsWith(QLatin1Char('^'))) + requestStructPointer->urlStringWithSeparators.append(QLatin1Char('^')); // Create truncated URL strings and initially populate it with the original URL strings. - urlStruct.truncatedUrlString = urlStruct.urlString; - urlStruct.truncatedUrlStringWithSeparators = urlStruct.urlStringWithSeparators; + requestStructPointer->truncatedUrlString = requestStructPointer->urlString; + requestStructPointer->truncatedUrlStringWithSeparators = requestStructPointer->urlStringWithSeparators; // Get the index of the beginning of the fully qualified domain name. - int fqdnIndex = urlStruct.truncatedUrlString.indexOf(QLatin1String("://")) + 3; + int fqdnIndex = requestStructPointer->truncatedUrlString.indexOf(QLatin1String("://")) + 3; // Truncate the URL to the beginning of the fully qualified domain name. - urlStruct.truncatedUrlString.remove(0, fqdnIndex); - urlStruct.truncatedUrlStringWithSeparators.remove(0, fqdnIndex); - - // Check UltraList. - continueChecking = checkIndividualList(urlRequestInfo, urlStruct, requestStructPointer, ultraPrivacyStructPointer); - - // Check UltraPrivacy. - if (continueChecking) - continueChecking = checkIndividualList(urlRequestInfo, urlStruct, requestStructPointer, ultraListStructPointer); - - // Check EasyPrivacy. - if (continueChecking) - continueChecking = checkIndividualList(urlRequestInfo, urlStruct, requestStructPointer, easyPrivacyStructPointer); - - // Check EasyList. - if (continueChecking) - continueChecking = checkIndividualList(urlRequestInfo, urlStruct, requestStructPointer, easyListStructPointer); - - // Check Fanboy's Annoyance list. - if (continueChecking) - continueChecking = checkIndividualList(urlRequestInfo, urlStruct, requestStructPointer, fanboyAnnoyanceStructPointer); + requestStructPointer->truncatedUrlString.remove(0, fqdnIndex); + requestStructPointer->truncatedUrlStringWithSeparators.remove(0, fqdnIndex); + + // Create an array of filter list struct pointers. + FilterListStruct* filterListStructPointerArray[5] = {ultraPrivacyStructPointer, + ultraListStructPointer, + easyPrivacyStructPointer, + easyListStructPointer, + fanboyAnnoyanceStructPointer}; + + // Check each filter list. + for (FilterListStruct *filterListStructPointer : filterListStructPointerArray) + { + // Check the list unless a match has been found by a previous list. + if (continueChecking) + continueChecking = checkIndividualList(urlRequestInfo, requestStructPointer, filterListStructPointer); + } // Return the continue checking status. return continueChecking; } -bool FilterListHelper::checkIndividualList(QWebEngineUrlRequestInfo &urlRequestInfo, UrlStruct &urlStruct, RequestStruct *requestStructPointer, FilterListStruct *filterListStructPointer) const +bool FilterListHelper::checkIndividualList(QWebEngineUrlRequestInfo &urlRequestInfo, RequestStruct *requestStructPointer, FilterListStruct *filterListStructPointer) const { - // Initiate a continue checking tracker. If the tracker changes to false, all process of the request will be stopped. + // Initiate a continue checking tracker. If the tracker changes to false, all further checking of the request will be bypasses. bool continueChecking = true; + // Get the main allow list iterators. + auto mainAllowListEntry = filterListStructPointer->mainAllowListPointer->begin(); + auto mainAllowListEnd = filterListStructPointer->mainAllowListPointer->end(); + // Check the main allow list. - for (auto filterListEntry = filterListStructPointer->mainAllowListPointer->begin(); filterListEntry != filterListStructPointer->mainAllowListPointer->end(); ++filterListEntry) + while (continueChecking && (mainAllowListEntry != mainAllowListEnd)) { // Get the entry struct. - EntryStruct *entryStructPointer = *filterListEntry; + EntryStruct *entryStructPointer = *mainAllowListEntry; // TODO. Temporarily ignore empty applied entries. if (!entryStructPointer->appliedEntryList[0].isEmpty()) { // Check if the URL string contains the applied entry. TODO. - if (urlStruct.urlString.contains(entryStructPointer->appliedEntryList[0]) || urlStruct.urlStringWithSeparators.contains(entryStructPointer->appliedEntryList[0])) + if (requestStructPointer->urlString.contains(entryStructPointer->appliedEntryList[0]) || + requestStructPointer->urlStringWithSeparators.contains(entryStructPointer->appliedEntryList[0])) { // Allow the request. urlRequestInfo.block(false); @@ -189,162 +187,180 @@ bool FilterListHelper::checkIndividualList(QWebEngineUrlRequestInfo &urlRequestI return false; } } - } - // Get the main block list end. - auto mainBlockListEnd = filterListStructPointer->mainBlockListPointer->end(); + // Increment the main allow list entry. + ++mainAllowListEntry; + } - // Check the main block list. - for (auto mainBlockListEntry = filterListStructPointer->mainBlockListPointer->begin(); mainBlockListEntry != mainBlockListEnd; ++mainBlockListEntry) + // Check the main block list unless a match has already been found. + if (continueChecking) { - // Exit the loop if continue checking is false. - if (!continueChecking) - break; + // Get the main block list iterators. + auto mainBlockListEntry = filterListStructPointer->mainBlockListPointer->begin(); + auto mainBlockListEnd = filterListStructPointer->mainBlockListPointer->end(); - // Get the entry struct. - EntryStruct *entryStructPointer = *mainBlockListEntry; + // Check the main block list. + while (continueChecking && (mainBlockListEntry != mainBlockListEnd)) + { + // Get the entry struct. + EntryStruct *entryStructPointer = *mainBlockListEntry; - // Check the applied entries. - continueChecking = checkAppliedEntry(urlRequestInfo, urlStruct, requestStructPointer, filterListStructPointer->title, MAIN_BLOCKLIST, entryStructPointer, urlStruct.urlString, - urlStruct.urlStringWithSeparators); - } + // Check the applied entry against the request URL. + continueChecking = checkAppliedEntry(urlRequestInfo, requestStructPointer, filterListStructPointer->title, MAIN_BLOCKLIST, requestStructPointer->urlString, + RequestUrlType::Url, entryStructPointer); - // Get the initial domain block list end. - auto initialDomainBlockListEnd = filterListStructPointer->initialDomainBlockListPointer->end(); + // Check the applied entry against the request URL with separators. + if (continueChecking) + continueChecking = checkAppliedEntry(urlRequestInfo, requestStructPointer, filterListStructPointer->title, MAIN_BLOCKLIST, requestStructPointer->urlStringWithSeparators, + RequestUrlType::UrlWithSeparators, entryStructPointer); - // Check the initial domain block list. - for (auto initialDomainBlockListEntry = filterListStructPointer->initialDomainBlockListPointer->begin(); initialDomainBlockListEntry != initialDomainBlockListEnd; - ++initialDomainBlockListEntry) + // Increment the main block list entry. + ++mainBlockListEntry; + } + } + + // Check the initial domain block list unless a match has already been found. + if (continueChecking) { - // Exit the loop if continue checking is false. - if (!continueChecking) - break; + // Get the initial domain block list end. + auto initialDomainBlockListEntry = filterListStructPointer->initialDomainBlockListPointer->begin(); + auto initialDomainBlockListEnd = filterListStructPointer->initialDomainBlockListPointer->end(); - // Get the entry struct. - EntryStruct *entryStructPointer = *initialDomainBlockListEntry; + // Check the initial domain block list. + while (continueChecking && (initialDomainBlockListEntry != initialDomainBlockListEnd)) + { + // Get the entry struct. + EntryStruct *entryStructPointer = *initialDomainBlockListEntry; - // Check the applied entries. - continueChecking = checkAppliedEntry(urlRequestInfo, urlStruct, requestStructPointer, filterListStructPointer->title, INITIAL_DOMAIN_BLOCKLIST, entryStructPointer, - urlStruct.truncatedUrlString, urlStruct.truncatedUrlStringWithSeparators); - } + // Check the applied entry against the truncated URL. + continueChecking = checkAppliedEntry(urlRequestInfo, requestStructPointer, filterListStructPointer->title, INITIAL_DOMAIN_BLOCKLIST, requestStructPointer->truncatedUrlString, + RequestUrlType::TruncatedUrl, entryStructPointer); - // Get the regular expression block list end. - auto regularExpressionBlockListEnd = filterListStructPointer->regularExpressionBlockListPointer->end(); + // Check the applied entry against the truncated URL with separators. + if (continueChecking) + continueChecking = checkAppliedEntry(urlRequestInfo, requestStructPointer, filterListStructPointer->title, INITIAL_DOMAIN_BLOCKLIST, + requestStructPointer->truncatedUrlStringWithSeparators, RequestUrlType::TruncatedUrlWithSeparators, entryStructPointer); - // Check the regular expression block list. - for (auto regularExpressionBlockListEntry = filterListStructPointer->regularExpressionBlockListPointer->begin(); regularExpressionBlockListEntry != regularExpressionBlockListEnd; - ++regularExpressionBlockListEntry) + // Increment the initial domain block list entry. + ++initialDomainBlockListEntry; + } + } + + // Check the regular expression block list unless a match has already been found. + if (continueChecking) { - // Exit the loop if continue checking is false. - if (!continueChecking) - break; + // Get the regular expression block list end. + auto regularExpressionBlockListEntry = filterListStructPointer->regularExpressionBlockListPointer->begin(); + auto regularExpressionBlockListEnd = filterListStructPointer->regularExpressionBlockListPointer->end(); - // Get the entry struct. - EntryStruct *entryStructPointer = *regularExpressionBlockListEntry; + while (continueChecking && (regularExpressionBlockListEntry != regularExpressionBlockListEnd)) + { + // Get the entry struct. + EntryStruct *entryStructPointer = *regularExpressionBlockListEntry; + + // Check the applied entries. + continueChecking = checkRegularExpression(urlRequestInfo, requestStructPointer, filterListStructPointer->title, REGULAR_EXPRESSION_BLOCKLIST, entryStructPointer); - // Check the applied entries. - continueChecking = checkRegularExpression(urlRequestInfo, urlStruct, requestStructPointer, filterListStructPointer->title, REGULAR_EXPRESSION_BLOCKLIST, entryStructPointer); + // Increment the regular expression block list entry. + ++regularExpressionBlockListEntry; + } } // Return the continue checking status. return continueChecking; } -bool FilterListHelper::checkAppliedEntry(QWebEngineUrlRequestInfo &urlRequestInfo, UrlStruct &urlStruct, RequestStruct *requestStructPointer, const QString &filterListTitle, - const int sublistInt, EntryStruct *entryStructPointer, QString &urlString, QString &urlStringWithSeparators) const +bool FilterListHelper::checkAppliedEntry(QWebEngineUrlRequestInfo &urlRequestInfo, RequestStruct *requestStructPointer, const QString &filterListTitle, const int sublistInt, QString urlString, + const RequestUrlType requestUrlType, EntryStruct *entryStructPointer) const { // Check the entries according to the number. - if (entryStructPointer->singleAppliedEntry) + if (entryStructPointer->singleAppliedEntry) // There is a single entry. { // Process initial and final matches. if (entryStructPointer->initialMatch && entryStructPointer->finalMatch) // This is both an initial and final match. { // Check the URL against the applied entry. - if ((urlString == entryStructPointer->appliedEntryList[0]) || (urlStringWithSeparators == entryStructPointer->appliedEntryList[0])) + if (urlString == entryStructPointer->appliedEntryList[0]) { + // Set the matched URL type. + requestStructPointer->matchedUrlType = requestUrlType; + // Check the domain status. - return checkDomain(urlRequestInfo, urlStruct, requestStructPointer, filterListTitle, sublistInt, entryStructPointer); + return checkDomain(urlRequestInfo, requestStructPointer, filterListTitle, sublistInt, entryStructPointer); } } else if (entryStructPointer->initialMatch) // This is an initial match. { // Check the URL against the applied entry. - if (urlString.startsWith(entryStructPointer->appliedEntryList[0]) || urlStringWithSeparators.startsWith(entryStructPointer->appliedEntryList[0])) + if (urlString.startsWith(entryStructPointer->appliedEntryList[0])) { + // Set the matched URL type. + requestStructPointer->matchedUrlType = requestUrlType; + // Check the domain status. - return checkDomain(urlRequestInfo, urlStruct, requestStructPointer, filterListTitle, sublistInt, entryStructPointer); + return checkDomain(urlRequestInfo, requestStructPointer, filterListTitle, sublistInt, entryStructPointer); } } else if (entryStructPointer->finalMatch) // This is a final match. { // Check the URL against the applied entry. - if (urlString.endsWith(entryStructPointer->appliedEntryList[0]) || urlStringWithSeparators.endsWith(entryStructPointer->appliedEntryList[0])) + if (urlString.endsWith(entryStructPointer->appliedEntryList[0])) { + // Set the matched URL type. + requestStructPointer->matchedUrlType = requestUrlType; + // Check the domain status. - return checkDomain(urlRequestInfo, urlStruct, requestStructPointer, filterListTitle, sublistInt, entryStructPointer); + return checkDomain(urlRequestInfo, requestStructPointer, filterListTitle, sublistInt, entryStructPointer); } } else // There is no initial or final matching. { // Check if the URL string contains the applied entry. - if (urlString.contains(entryStructPointer->appliedEntryList[0]) || urlStringWithSeparators.contains(entryStructPointer->appliedEntryList[0])) + if (urlString.contains(entryStructPointer->appliedEntryList[0])) { + // Set the matched URL type. + requestStructPointer->matchedUrlType = requestUrlType; + // Check the domain status. - return checkDomain(urlRequestInfo, urlStruct, requestStructPointer, filterListTitle, sublistInt, entryStructPointer); + return checkDomain(urlRequestInfo, requestStructPointer, filterListTitle, sublistInt, entryStructPointer); } } } else // There are multiple entries. { - // Create a URL matches flag. - bool urlMatches = true; - // Process initial and final matches. if (entryStructPointer->initialMatch && entryStructPointer->finalMatch) // This is both an initial and final match. { - // Check the first entry. - if (urlString.startsWith(entryStructPointer->appliedEntryList[0]) || - urlStringWithSeparators.startsWith(entryStructPointer->appliedEntryList[0])) // The URL string starts with the first applied entry. + // Check the URL. + if (urlString.startsWith(entryStructPointer->appliedEntryList[0])) { - // Get the number of characters to remove from the front of the URL strings. + // Get the number of characters to remove from the front of the URL string. int charactersToRemove = entryStructPointer->appliedEntryList[0].size(); // Remove the entry from the front of the URL string copies. urlString.remove(0, charactersToRemove); - urlStringWithSeparators.remove(0, charactersToRemove); - } - else // The URL string does not end with the last applied entry. - { - // Mark the URL matches flag as false. - urlMatches = false; - } - // Check the other entries if the URL still matches. - if (urlMatches) - { - // Calculate the penultimate entry. + // Get the entry locations. int penultimateEntryNumber = (entryStructPointer->sizeOfAppliedEntryList - 1); int ultimateEntryIndex = penultimateEntryNumber; + // Create a URL matches flag. + bool urlMatches = true; + // Check all the middle entries. for (int i = 1; i < penultimateEntryNumber; ++i) { - // Get the index of the applied entry, which will be `-1` if it doesn't exist. - int stringIndex = urlString.indexOf(entryStructPointer->appliedEntryList[i]); - int stringWithSeparatorsIndex = urlStringWithSeparators.indexOf(entryStructPointer->appliedEntryList[i]); - - // Get the larger of the two indexes. - int index = std::max(stringIndex, stringWithSeparatorsIndex); + // Get the applied entry index, which will be `-1` if it doesn't exist. + int appliedEntryIndex = urlString.indexOf(entryStructPointer->appliedEntryList[i]); // Check if the entry was found. - if (index >= 0) // The entry is contained in the URL string. + if (appliedEntryIndex >= 0) // The entry is contained in the URL string. { // Get the number of characters to remove from the front of the URL strings. - int charactersToRemove = index + entryStructPointer->appliedEntryList[i].size(); + int charactersToRemove = appliedEntryIndex + entryStructPointer->appliedEntryList[i].size(); // Remove the entry from the front of the URL string copies. urlString.remove(0, charactersToRemove); - urlStringWithSeparators.remove(0, charactersToRemove); } else // The entry is not contained in the URL string. { @@ -356,59 +372,44 @@ bool FilterListHelper::checkAppliedEntry(QWebEngineUrlRequestInfo &urlRequestInf // Check the final entry if the URL still matches. if (urlMatches) { - if (urlString.endsWith(entryStructPointer->appliedEntryList[ultimateEntryIndex]) || - urlStringWithSeparators.endsWith(entryStructPointer->appliedEntryList[ultimateEntryIndex])) // The URL string ends with the last applied entry. - { - // There is no need to modify the URL string copies as no further checks will be performed. - } - else // The URL string does not end with the last applied entry. + if (urlString.endsWith(entryStructPointer->appliedEntryList[ultimateEntryIndex])) // The URL string ends with the last applied entry. { - // Mark the URL matches flag as false. - urlMatches = false; + // Set the matched URL type. + requestStructPointer->matchedUrlType = requestUrlType; + + // Check the domain status. + return checkDomain(urlRequestInfo, requestStructPointer, filterListTitle, sublistInt, entryStructPointer); } } } } else if (entryStructPointer->initialMatch) // This is an initial match. { - // Check the first entry. - if (urlString.startsWith(entryStructPointer->appliedEntryList[0]) || - urlStringWithSeparators.startsWith(entryStructPointer->appliedEntryList[0])) // The URL string starts with the first applied entry. + // Check the URL. + if (urlString.startsWith(entryStructPointer->appliedEntryList[0])) { // Get the number of characters to remove from the front of the URL strings. int charactersToRemove = entryStructPointer->appliedEntryList[0].size(); // Remove the entry from the front of the URL string copies. urlString.remove(0, charactersToRemove); - urlStringWithSeparators.remove(0, charactersToRemove); - } - else // The URL string does not end with the last applied entry. - { - // Mark the URL matches flag as false. - urlMatches = false; - } - // Check the other entries if the URL still matches. - if (urlMatches) - { + // Create a URL matches flag. + bool urlMatches = true; + for (int i = 1; i < entryStructPointer->sizeOfAppliedEntryList; ++i) { - // Get the index of the applied entry, which will be `-1` if it doesn't exist. - int stringIndex = urlString.indexOf(entryStructPointer->appliedEntryList[i]); - int stringWithSeparatorsIndex = urlStringWithSeparators.indexOf(entryStructPointer->appliedEntryList[i]); - - // Get the larger of the two indexes. - int index = std::max(stringIndex, stringWithSeparatorsIndex); + // Get the applied entry index, which will be `-1` if it doesn't exist. + int appliedEntryIndex = urlString.indexOf(entryStructPointer->appliedEntryList[i]); // Check if the entry was found. - if (index >= 0) // The entry is contained in the URL string. + if (appliedEntryIndex >= 0) // The entry is contained in the URL string. { // Get the number of characters to remove from the front of the URL strings. - int charactersToRemove = index + entryStructPointer->appliedEntryList[i].size(); + int charactersToRemove = appliedEntryIndex + entryStructPointer->appliedEntryList[i].size(); // Remove the entry from the front of the URL string copies. urlString.remove(0, charactersToRemove); - urlStringWithSeparators.remove(0, charactersToRemove); } else // The entry is not contained in the URL string. { @@ -416,33 +417,41 @@ bool FilterListHelper::checkAppliedEntry(QWebEngineUrlRequestInfo &urlRequestInf urlMatches = false; } } + + // Check the domain status if the URL still matches. + if (urlMatches) + { + // Set the matched URL type. + requestStructPointer->matchedUrlType = requestUrlType; + + // Check the domain status. + return checkDomain(urlRequestInfo, requestStructPointer, filterListTitle, sublistInt, entryStructPointer); + } } } else if (entryStructPointer->finalMatch) // This is a final match. { - // Calculate the penultimate entry. + // Get the entry locations. int penultimateEntryNumber = (entryStructPointer->sizeOfAppliedEntryList - 1); int ultimateEntryIndex = penultimateEntryNumber; + // Create a URL matches flag. + bool urlMatches = true; + // Check all the entries except the last one. for (int i = 0; i < penultimateEntryNumber; ++i) { - // Get the index of the applied entry, which will be `-1` if it doesn't exist. - int stringIndex = urlString.indexOf(entryStructPointer->appliedEntryList[i]); - int stringWithSeparatorsIndex = urlStringWithSeparators.indexOf(entryStructPointer->appliedEntryList[i]); - - // Get the larger of the two indexes. - int index = std::max(stringIndex, stringWithSeparatorsIndex); + // Get the applied entry index, which will be `-1` if it doesn't exist. + int appliedEntryIndex = urlString.indexOf(entryStructPointer->appliedEntryList[i]); // Check if the entry was found. - if (index >= 0) // The entry is contained in the URL string. + if (appliedEntryIndex >= 0) // The entry is contained in the URL string. { // Get the number of characters to remove from the front of the URL strings. - int charactersToRemove = index + entryStructPointer->appliedEntryList[i].size(); + int charactersToRemove = appliedEntryIndex + entryStructPointer->appliedEntryList[i].size(); // Remove the entry from the front of the URL string copies. urlString.remove(0, charactersToRemove); - urlStringWithSeparators.remove(0, charactersToRemove); } else // The entry is not contained in the URL string. { @@ -454,39 +463,34 @@ bool FilterListHelper::checkAppliedEntry(QWebEngineUrlRequestInfo &urlRequestInf // Check the final entry if the URL still matches. if (urlMatches) { - if (urlString.endsWith(entryStructPointer->appliedEntryList[ultimateEntryIndex]) || - urlStringWithSeparators.endsWith(entryStructPointer->appliedEntryList[ultimateEntryIndex])) // The URL string ends with the last applied entry. + if (urlString.endsWith(entryStructPointer->appliedEntryList[ultimateEntryIndex])) // The URL string ends with the last applied entry. { - // There is no need to modify the URL string copies as no further checks will be performed. - } - else // The URL string does not end with the last applied entry. - { - // Mark the URL matches flag as false. - urlMatches = false; + // Set the matched URL type. + requestStructPointer->matchedUrlType = requestUrlType; + + // Check the domain status. + return checkDomain(urlRequestInfo, requestStructPointer, filterListTitle, sublistInt, entryStructPointer); } } } else // There is no initial or final matching. { + // Create a URL matches flag. + bool urlMatches = true; + for (int i = 0; i < entryStructPointer->sizeOfAppliedEntryList; ++i) { - // Get the index of the applied entry, which will be `-1` if it doesn't exist. - int stringIndex = urlString.indexOf(entryStructPointer->appliedEntryList[i]); - int stringWithSeparatorsIndex = urlStringWithSeparators.indexOf(entryStructPointer->appliedEntryList[i]); - - // Get the larger of the two indexes. - int index = std::max(stringIndex, stringWithSeparatorsIndex); + // Get the applied entry index, which will be `-1` if it doesn't exist. + int appliedEntryIndex = urlString.indexOf(entryStructPointer->appliedEntryList[i]); // Check if the entry was found. - if (index >= 0) // The entry is contained in the URL string. + if (appliedEntryIndex >= 0) // The entry is contained in the URL string. { - // Get the number of characters to remove from the front of the URL strings. - int charactersToRemove = index + entryStructPointer->appliedEntryList[i].size(); + int charactersToRemove = appliedEntryIndex + entryStructPointer->appliedEntryList[i].size(); // Remove the entry from the front of the URL string copies. urlString.remove(0, charactersToRemove); - urlStringWithSeparators.remove(0, charactersToRemove); } else // The entry is not contained in the URL string. { @@ -494,57 +498,63 @@ bool FilterListHelper::checkAppliedEntry(QWebEngineUrlRequestInfo &urlRequestInf urlMatches = false; } } - } - // Check the domain status if the URL matches. - if (urlMatches) - return checkDomain(urlRequestInfo, urlStruct, requestStructPointer, filterListTitle, sublistInt, entryStructPointer); + // Check the domain status if the URL still matches. + if (urlMatches) + { + // Set the matched URL type. + requestStructPointer->matchedUrlType = requestUrlType; + + // Check the domain status. + return checkDomain(urlRequestInfo, requestStructPointer, filterListTitle, sublistInt, entryStructPointer); + } + } } - // If the applied entry doesn't match, return `true` to continue processing the URL request. + // The applied entry doesn't match. Return `true` to continue processing the URL request. return true; } -bool FilterListHelper::checkRegularExpression(QWebEngineUrlRequestInfo &urlRequestInfo, UrlStruct &urlStruct, RequestStruct *requestStructPointer, const QString &filterListTitle, - const int sublistInt, EntryStruct *entryStructPointer) const +bool FilterListHelper::checkRegularExpression(QWebEngineUrlRequestInfo &urlRequestInfo, RequestStruct *requestStructPointer, const QString &filterListTitle, const int sublistInt, + EntryStruct *entryStructPointer) const { // Create an applied entry regular expression. QRegularExpression appliedEntryRegularExpression(entryStructPointer->appliedEntryList[0]); // Check if the regular expression matches the applied entry. - if (urlStruct.urlString.contains(appliedEntryRegularExpression)) + if (requestStructPointer->urlString.contains(appliedEntryRegularExpression)) { // Check the domain status. - return checkDomain(urlRequestInfo, urlStruct, requestStructPointer, filterListTitle, sublistInt, entryStructPointer); + return checkDomain(urlRequestInfo, requestStructPointer, filterListTitle, sublistInt, entryStructPointer); } // If the regular expression doesn't match, return `true` to continue processing the URL request. return true; } -bool FilterListHelper::checkDomain(QWebEngineUrlRequestInfo &urlRequestInfo, UrlStruct &urlStruct, RequestStruct *requestStructPointer, const QString &filterListTitle, const int sublistInt, +bool FilterListHelper::checkDomain(QWebEngineUrlRequestInfo &urlRequestInfo, RequestStruct *requestStructPointer, const QString &filterListTitle, const int sublistInt, EntryStruct *entryStructPointer) const { // Check domain status. - if (entryStructPointer->domain == FilterOptionEnum::Disposition::Null) // Ignore domain status. + if (entryStructPointer->domain == FilterOptionDisposition::Null) // Ignore domain status. { // Check the third-party status. - return checkThirdParty(urlRequestInfo, requestStructPointer, urlStruct.isThirdPartyRequest, filterListTitle, sublistInt, entryStructPointer); + return checkThirdParty(urlRequestInfo, requestStructPointer, filterListTitle, sublistInt, entryStructPointer); } - else if (entryStructPointer->domain == FilterOptionEnum::Disposition::Apply) // Block requests from listed domains. + else if (entryStructPointer->domain == FilterOptionDisposition::Apply) // Block requests from listed domains. { // Check each domain. foreach (QString blockedDomain, entryStructPointer->domainList) { // Check if the request came from a blocked domain. - if (urlStruct.fqdn.endsWith(blockedDomain)) + if (requestStructPointer->fqdn.endsWith(blockedDomain)) { // Check the third-party status. - return checkThirdParty(urlRequestInfo, requestStructPointer, urlStruct.isThirdPartyRequest, filterListTitle, sublistInt, entryStructPointer); + return checkThirdParty(urlRequestInfo, requestStructPointer, filterListTitle, sublistInt, entryStructPointer); } } } - else if (entryStructPointer->domain == FilterOptionEnum::Disposition::Override) // Block domains that are not overridden. + else if (entryStructPointer->domain == FilterOptionDisposition::Override) // Block domains that are not overridden. { // Create a block domain flag. bool blockDomain = true; @@ -553,7 +563,7 @@ bool FilterListHelper::checkDomain(QWebEngineUrlRequestInfo &urlRequestInfo, Url foreach (QString overriddenDomain, entryStructPointer->domainList) { // Check if the request came from an overridden domain. - if (urlStruct.fqdn.endsWith(overriddenDomain)) + if (requestStructPointer->fqdn.endsWith(overriddenDomain)) { // Don't block the domain. blockDomain = false; @@ -564,7 +574,7 @@ bool FilterListHelper::checkDomain(QWebEngineUrlRequestInfo &urlRequestInfo, Url if (blockDomain) { // Check the third-party status. - return checkThirdParty(urlRequestInfo, requestStructPointer, urlStruct.isThirdPartyRequest, filterListTitle, sublistInt, entryStructPointer); + return checkThirdParty(urlRequestInfo, requestStructPointer, filterListTitle, sublistInt, entryStructPointer); } } @@ -572,11 +582,11 @@ bool FilterListHelper::checkDomain(QWebEngineUrlRequestInfo &urlRequestInfo, Url return true; } -bool FilterListHelper::checkThirdParty(QWebEngineUrlRequestInfo &urlRequestInfo, RequestStruct *requestStructPointer, const bool isThirdPartyRequest, const QString &filterListTitle, - const int sublistInt, EntryStruct *entryStructPointer) const +bool FilterListHelper::checkThirdParty(QWebEngineUrlRequestInfo &urlRequestInfo, RequestStruct *requestStructPointer, const QString &filterListTitle, const int sublistInt, + EntryStruct *entryStructPointer) const { // Check third-party status. - if (entryStructPointer->thirdParty == FilterOptionEnum::Disposition::Null) // Ignore third-party status. + if (entryStructPointer->thirdParty == FilterOptionDisposition::Null) // Ignore third-party status. { // Check if request options are applied. if (entryStructPointer->hasRequestOptions) // Request options are applied. @@ -590,7 +600,7 @@ bool FilterListHelper::checkThirdParty(QWebEngineUrlRequestInfo &urlRequestInfo, return blockRequest(urlRequestInfo, requestStructPointer, filterListTitle, sublistInt, entryStructPointer); } } - else if ((entryStructPointer->thirdParty == FilterOptionEnum::Disposition::Apply) && isThirdPartyRequest) // Block third-party request. + else if ((entryStructPointer->thirdParty == FilterOptionDisposition::Apply) && requestStructPointer->isThirdPartyRequest) // Block third-party request. { // Check if request options are applied. if (entryStructPointer->hasRequestOptions) // Request options are applied. @@ -604,7 +614,7 @@ bool FilterListHelper::checkThirdParty(QWebEngineUrlRequestInfo &urlRequestInfo, return blockRequest(urlRequestInfo, requestStructPointer, filterListTitle, sublistInt, entryStructPointer); } } - else if ((entryStructPointer->thirdParty == FilterOptionEnum::Disposition::Override) && !isThirdPartyRequest) // Block first-party requests. + else if ((entryStructPointer->thirdParty == FilterOptionDisposition::Override) && !requestStructPointer->isThirdPartyRequest) // Block first-party requests. { // Check if request options are applied. if (entryStructPointer->hasRequestOptions) // Request options are applied. @@ -627,87 +637,87 @@ bool FilterListHelper::checkRequestOptions(QWebEngineUrlRequestInfo &urlRequestI EntryStruct *entryStructPointer) const { // Block font requests. - if ((entryStructPointer->font == FilterOptionEnum::Disposition::Apply) && (requestStructPointer->resourceTypeInt == QWebEngineUrlRequestInfo::ResourceTypeFontResource)) + if ((entryStructPointer->font == FilterOptionDisposition::Apply) && (requestStructPointer->resourceTypeInt == QWebEngineUrlRequestInfo::ResourceTypeFontResource)) { // Block the request. return blockRequest(urlRequestInfo, requestStructPointer, filterListTitle, sublistInt, entryStructPointer); } // Block image requests. - if ((entryStructPointer->image == FilterOptionEnum::Disposition::Apply) && (requestStructPointer->resourceTypeInt == QWebEngineUrlRequestInfo::ResourceTypeImage)) + if ((entryStructPointer->image == FilterOptionDisposition::Apply) && (requestStructPointer->resourceTypeInt == QWebEngineUrlRequestInfo::ResourceTypeImage)) { // Block the request. return blockRequest(urlRequestInfo, requestStructPointer, filterListTitle, sublistInt, entryStructPointer); } // Block main frame requests. - if ((entryStructPointer->mainFrame == FilterOptionEnum::Disposition::Apply) && ((requestStructPointer->resourceTypeInt == QWebEngineUrlRequestInfo::ResourceTypeMainFrame) || - (requestStructPointer->resourceTypeInt == QWebEngineUrlRequestInfo::ResourceTypeNavigationPreloadMainFrame))) + if ((entryStructPointer->mainFrame == FilterOptionDisposition::Apply) && ((requestStructPointer->resourceTypeInt == QWebEngineUrlRequestInfo::ResourceTypeMainFrame) || + (requestStructPointer->resourceTypeInt == QWebEngineUrlRequestInfo::ResourceTypeNavigationPreloadMainFrame))) { // Block the request. return blockRequest(urlRequestInfo, requestStructPointer, filterListTitle, sublistInt, entryStructPointer); } // Block media requests. - if ((entryStructPointer->media == FilterOptionEnum::Disposition::Apply) && (requestStructPointer->resourceTypeInt == QWebEngineUrlRequestInfo::ResourceTypeMedia)) + if ((entryStructPointer->media == FilterOptionDisposition::Apply) && (requestStructPointer->resourceTypeInt == QWebEngineUrlRequestInfo::ResourceTypeMedia)) { // Block the request. return blockRequest(urlRequestInfo, requestStructPointer, filterListTitle, sublistInt, entryStructPointer); } // Block object requests. - if ((entryStructPointer->object == FilterOptionEnum::Disposition::Apply) && (requestStructPointer->resourceTypeInt == QWebEngineUrlRequestInfo::ResourceTypeObject)) + if ((entryStructPointer->object == FilterOptionDisposition::Apply) && (requestStructPointer->resourceTypeInt == QWebEngineUrlRequestInfo::ResourceTypeObject)) { // Block the request. return blockRequest(urlRequestInfo, requestStructPointer, filterListTitle, sublistInt, entryStructPointer); } // Block other requests. - if ((entryStructPointer->other == FilterOptionEnum::Disposition::Apply) && ((requestStructPointer->resourceTypeInt == QWebEngineUrlRequestInfo::ResourceTypeSubResource) || - (requestStructPointer->resourceTypeInt == QWebEngineUrlRequestInfo::ResourceTypeWorker) || - (requestStructPointer->resourceTypeInt == QWebEngineUrlRequestInfo::ResourceTypeSharedWorker) || - (requestStructPointer->resourceTypeInt == QWebEngineUrlRequestInfo::ResourceTypePrefetch) || - (requestStructPointer->resourceTypeInt == QWebEngineUrlRequestInfo::ResourceTypeFavicon) || - (requestStructPointer->resourceTypeInt == QWebEngineUrlRequestInfo::ResourceTypeServiceWorker) || - (requestStructPointer->resourceTypeInt == QWebEngineUrlRequestInfo::ResourceTypeCspReport) || - (requestStructPointer->resourceTypeInt == QWebEngineUrlRequestInfo::ResourceTypePluginResource) || - (requestStructPointer->resourceTypeInt == QWebEngineUrlRequestInfo::ResourceTypeUnknown))) + if ((entryStructPointer->other == FilterOptionDisposition::Apply) && ((requestStructPointer->resourceTypeInt == QWebEngineUrlRequestInfo::ResourceTypeSubResource) || + (requestStructPointer->resourceTypeInt == QWebEngineUrlRequestInfo::ResourceTypeWorker) || + (requestStructPointer->resourceTypeInt == QWebEngineUrlRequestInfo::ResourceTypeSharedWorker) || + (requestStructPointer->resourceTypeInt == QWebEngineUrlRequestInfo::ResourceTypePrefetch) || + (requestStructPointer->resourceTypeInt == QWebEngineUrlRequestInfo::ResourceTypeFavicon) || + (requestStructPointer->resourceTypeInt == QWebEngineUrlRequestInfo::ResourceTypeServiceWorker) || + (requestStructPointer->resourceTypeInt == QWebEngineUrlRequestInfo::ResourceTypeCspReport) || + (requestStructPointer->resourceTypeInt == QWebEngineUrlRequestInfo::ResourceTypePluginResource) || + (requestStructPointer->resourceTypeInt == QWebEngineUrlRequestInfo::ResourceTypeUnknown))) { // Block the request. return blockRequest(urlRequestInfo, requestStructPointer, filterListTitle, sublistInt, entryStructPointer); } // Block ping requests - if ((entryStructPointer->ping == FilterOptionEnum::Disposition::Apply) && (requestStructPointer->resourceTypeInt == QWebEngineUrlRequestInfo::ResourceTypePing)) + if ((entryStructPointer->ping == FilterOptionDisposition::Apply) && (requestStructPointer->resourceTypeInt == QWebEngineUrlRequestInfo::ResourceTypePing)) { // Block the request. return blockRequest(urlRequestInfo, requestStructPointer, filterListTitle, sublistInt, entryStructPointer); } // Block script requests. - if ((entryStructPointer->script == FilterOptionEnum::Disposition::Apply) && (requestStructPointer->resourceTypeInt == QWebEngineUrlRequestInfo::ResourceTypeScript)) + if ((entryStructPointer->script == FilterOptionDisposition::Apply) && (requestStructPointer->resourceTypeInt == QWebEngineUrlRequestInfo::ResourceTypeScript)) { // Block the request. return blockRequest(urlRequestInfo, requestStructPointer, filterListTitle, sublistInt, entryStructPointer); } // Block style sheet requests. - if ((entryStructPointer->styleSheet == FilterOptionEnum::Disposition::Apply) && (requestStructPointer->resourceTypeInt == QWebEngineUrlRequestInfo::ResourceTypeStylesheet)) + if ((entryStructPointer->styleSheet == FilterOptionDisposition::Apply) && (requestStructPointer->resourceTypeInt == QWebEngineUrlRequestInfo::ResourceTypeStylesheet)) { // Block the request. return blockRequest(urlRequestInfo, requestStructPointer, filterListTitle, sublistInt, entryStructPointer); } // Block sub resource requests. - if ((entryStructPointer->subFrame == FilterOptionEnum::Disposition::Apply) && ((requestStructPointer->resourceTypeInt == QWebEngineUrlRequestInfo::ResourceTypeSubFrame) || - (requestStructPointer->resourceTypeInt == QWebEngineUrlRequestInfo::ResourceTypeNavigationPreloadSubFrame))) + if ((entryStructPointer->subFrame == FilterOptionDisposition::Apply) && ((requestStructPointer->resourceTypeInt == QWebEngineUrlRequestInfo::ResourceTypeSubFrame) || + (requestStructPointer->resourceTypeInt == QWebEngineUrlRequestInfo::ResourceTypeNavigationPreloadSubFrame))) { // Block the request. return blockRequest(urlRequestInfo, requestStructPointer, filterListTitle, sublistInt, entryStructPointer); } // Block XML HTTP requests. - if ((entryStructPointer->xmlHttpRequest == FilterOptionEnum::Disposition::Apply) && (requestStructPointer->resourceTypeInt == QWebEngineUrlRequestInfo::ResourceTypeXhr)) + if ((entryStructPointer->xmlHttpRequest == FilterOptionDisposition::Apply) && (requestStructPointer->resourceTypeInt == QWebEngineUrlRequestInfo::ResourceTypeXhr)) { // Block the request. return blockRequest(urlRequestInfo, requestStructPointer, filterListTitle, sublistInt, entryStructPointer); @@ -759,13 +769,13 @@ QString FilterListHelper::getNavigationTypeString(int navigationTypeInt) const } } -QString FilterListHelper::getRequestOptionDispositionString(const FilterOptionEnum::Disposition filterOptionDisposition) const +QString FilterListHelper::getRequestOptionDispositionString(const FilterOptionDisposition filterOptionDisposition) const { // Return the translated filter option disposition string. switch (filterOptionDisposition) { - case FilterOptionEnum::Disposition::Apply: return FILTER_OPTION_APPLY; - case FilterOptionEnum::Disposition::Override: return FILTER_OPTION_OVERRIDE; + case FilterOptionDisposition::Apply: return FILTER_OPTION_APPLY; + case FilterOptionDisposition::Override: return FILTER_OPTION_OVERRIDE; default: return FILTER_OPTION_NULL; } } @@ -942,7 +952,7 @@ FilterListStruct* FilterListHelper::populateFilterList(const QString &filterList if (entryStructPointer->domainList[0].startsWith(QLatin1Char('~'))) // Override domains. { // Populate the domain filter disposition. - entryStructPointer->domain = FilterOptionEnum::Disposition::Override; + entryStructPointer->domain = FilterOptionDisposition::Override; // Remove the initial `~` from each domain. entryStructPointer->domainList.replaceInStrings(QLatin1String("~"), QLatin1String("")); @@ -950,23 +960,23 @@ FilterListStruct* FilterListHelper::populateFilterList(const QString &filterList else // Standard domains. { // Populate the domain filter disposition. - entryStructPointer->domain = FilterOptionEnum::Disposition::Apply; + entryStructPointer->domain = FilterOptionDisposition::Apply; } } else if (filterOption == QLatin1String("third-party")) // Third-party. { // Populate the third-party filter disposition. - entryStructPointer->thirdParty = FilterOptionEnum::Disposition::Apply; + entryStructPointer->thirdParty = FilterOptionDisposition::Apply; } else if (filterOption == QLatin1String("~third-party")) // Third-party override. { // Populate the third-party filter disposition. - entryStructPointer->thirdParty = FilterOptionEnum::Disposition::Override; + entryStructPointer->thirdParty = FilterOptionDisposition::Override; } else if ((filterOption == QLatin1String("document")) || (filterOption == QLatin1String("popup"))) // Document (and popup). { // Populate the main frame disposition. - entryStructPointer->mainFrame = FilterOptionEnum::Disposition::Apply; + entryStructPointer->mainFrame = FilterOptionDisposition::Apply; // Set the has request options flag. entryStructPointer->hasRequestOptions = true; @@ -974,7 +984,7 @@ FilterListStruct* FilterListHelper::populateFilterList(const QString &filterList else if (filterOption == QLatin1String("font")) // Font. { // Populate the font disposition. - entryStructPointer->font = FilterOptionEnum::Disposition::Apply; + entryStructPointer->font = FilterOptionDisposition::Apply; // Set the has request options flag. entryStructPointer->hasRequestOptions = true; @@ -982,7 +992,7 @@ FilterListStruct* FilterListHelper::populateFilterList(const QString &filterList else if (filterOption == QLatin1String("image")) // Image. { // Populate the image disposition. - entryStructPointer->image = FilterOptionEnum::Disposition::Apply; + entryStructPointer->image = FilterOptionDisposition::Apply; // Set the has request options flag. entryStructPointer->hasRequestOptions = true; @@ -990,7 +1000,7 @@ FilterListStruct* FilterListHelper::populateFilterList(const QString &filterList else if (filterOption == QLatin1String("media")) // Media. { // Populate the media disposition. - entryStructPointer->media = FilterOptionEnum::Disposition::Apply; + entryStructPointer->media = FilterOptionDisposition::Apply; // Set the has request options flag. entryStructPointer->hasRequestOptions = true; @@ -998,7 +1008,7 @@ FilterListStruct* FilterListHelper::populateFilterList(const QString &filterList else if (filterOption == QLatin1String("object")) // Object. { // Populate the object disposition. - entryStructPointer->object = FilterOptionEnum::Disposition::Apply; + entryStructPointer->object = FilterOptionDisposition::Apply; // Set the has request options flag. entryStructPointer->hasRequestOptions = true; @@ -1006,7 +1016,7 @@ FilterListStruct* FilterListHelper::populateFilterList(const QString &filterList else if ((filterOption == QLatin1String("other")) || (filterOption == QLatin1String("webrtc")) || (filterOption == QLatin1String("websocket"))) // Other. { // `websocket` will get its own section in Qt6. // Populate the other disposition. - entryStructPointer->other = FilterOptionEnum::Disposition::Apply; + entryStructPointer->other = FilterOptionDisposition::Apply; // Set the has request options flag. entryStructPointer->hasRequestOptions = true; @@ -1014,7 +1024,7 @@ FilterListStruct* FilterListHelper::populateFilterList(const QString &filterList else if (filterOption == QLatin1String("ping")) // Ping. { // Populate the ping disposition. - entryStructPointer->ping = FilterOptionEnum::Disposition::Apply; + entryStructPointer->ping = FilterOptionDisposition::Apply; // Set the has request options flag. entryStructPointer->hasRequestOptions = true; @@ -1022,7 +1032,7 @@ FilterListStruct* FilterListHelper::populateFilterList(const QString &filterList else if (filterOption == QLatin1String("script")) // Script. { // Populate the script disposition. - entryStructPointer->script = FilterOptionEnum::Disposition::Apply; + entryStructPointer->script = FilterOptionDisposition::Apply; // Set the has request options flag. entryStructPointer->hasRequestOptions = true; @@ -1030,7 +1040,7 @@ FilterListStruct* FilterListHelper::populateFilterList(const QString &filterList else if (filterOption == QLatin1String("stylesheet")) // Style sheet. { // Populate the script disposition. - entryStructPointer->styleSheet = FilterOptionEnum::Disposition::Apply; + entryStructPointer->styleSheet = FilterOptionDisposition::Apply; // Set the has request options flag. entryStructPointer->hasRequestOptions = true; @@ -1038,7 +1048,7 @@ FilterListStruct* FilterListHelper::populateFilterList(const QString &filterList else if (filterOption == QLatin1String("subdocument")) // Sub document. { // Populate the sub resource disposition. - entryStructPointer->subFrame = FilterOptionEnum::Disposition::Apply; + entryStructPointer->subFrame = FilterOptionDisposition::Apply; // Set the has request options flag. entryStructPointer->hasRequestOptions = true; @@ -1046,7 +1056,7 @@ FilterListStruct* FilterListHelper::populateFilterList(const QString &filterList else if (filterOption == QLatin1String("xmlhttprequest")) // XML HTTP request. { //Populate the XML HTTP request disposition. - entryStructPointer->xmlHttpRequest = FilterOptionEnum::Disposition::Apply; + entryStructPointer->xmlHttpRequest = FilterOptionDisposition::Apply; // Set the has request options flag. entryStructPointer->hasRequestOptions = true; @@ -1127,69 +1137,69 @@ FilterListStruct* FilterListHelper::populateFilterList(const QString &filterList // Font. if (overrideStruct.font) - entryStructPointer->font = FilterOptionEnum::Disposition::Override; + entryStructPointer->font = FilterOptionDisposition::Override; else - entryStructPointer->font = FilterOptionEnum::Disposition::Apply; + entryStructPointer->font = FilterOptionDisposition::Apply; // Image. if (overrideStruct.image) - entryStructPointer->image = FilterOptionEnum::Disposition::Override; + entryStructPointer->image = FilterOptionDisposition::Override; else - entryStructPointer->image = FilterOptionEnum::Disposition::Apply; + entryStructPointer->image = FilterOptionDisposition::Apply; // Main Frame (document). if (overrideStruct.mainFrame) - entryStructPointer->mainFrame = FilterOptionEnum::Disposition::Override; + entryStructPointer->mainFrame = FilterOptionDisposition::Override; else - entryStructPointer->mainFrame = FilterOptionEnum::Disposition::Apply; + entryStructPointer->mainFrame = FilterOptionDisposition::Apply; // Media. if (overrideStruct.media) - entryStructPointer->media = FilterOptionEnum::Disposition::Override; + entryStructPointer->media = FilterOptionDisposition::Override; else - entryStructPointer->media = FilterOptionEnum::Disposition::Apply; + entryStructPointer->media = FilterOptionDisposition::Apply; // Object. if (overrideStruct.object) - entryStructPointer->object = FilterOptionEnum::Disposition::Override; + entryStructPointer->object = FilterOptionDisposition::Override; else - entryStructPointer->object = FilterOptionEnum::Disposition::Apply; + entryStructPointer->object = FilterOptionDisposition::Apply; // Other. if (overrideStruct.other) - entryStructPointer->other = FilterOptionEnum::Disposition::Override; + entryStructPointer->other = FilterOptionDisposition::Override; else - entryStructPointer->other = FilterOptionEnum::Disposition::Apply; + entryStructPointer->other = FilterOptionDisposition::Apply; // Ping. if (overrideStruct.ping) - entryStructPointer->ping = FilterOptionEnum::Disposition::Override; + entryStructPointer->ping = FilterOptionDisposition::Override; else - entryStructPointer->ping = FilterOptionEnum::Disposition::Apply; + entryStructPointer->ping = FilterOptionDisposition::Apply; // Script. if (overrideStruct.script) - entryStructPointer->script = FilterOptionEnum::Disposition::Override; + entryStructPointer->script = FilterOptionDisposition::Override; else - entryStructPointer->script = FilterOptionEnum::Disposition::Apply; + entryStructPointer->script = FilterOptionDisposition::Apply; // Style Sheet. if (overrideStruct.styleSheet) - entryStructPointer->styleSheet = FilterOptionEnum::Disposition::Override; + entryStructPointer->styleSheet = FilterOptionDisposition::Override; else - entryStructPointer->styleSheet = FilterOptionEnum::Disposition::Apply; + entryStructPointer->styleSheet = FilterOptionDisposition::Apply; // Sub Resource. if (overrideStruct.subFrame) - entryStructPointer->subFrame = FilterOptionEnum::Disposition::Override; + entryStructPointer->subFrame = FilterOptionDisposition::Override; else - entryStructPointer->subFrame = FilterOptionEnum::Disposition::Apply; + entryStructPointer->subFrame = FilterOptionDisposition::Apply; // XML HTTP Request. if (overrideStruct.xmlHttpRequest) - entryStructPointer->xmlHttpRequest = FilterOptionEnum::Disposition::Override; + entryStructPointer->xmlHttpRequest = FilterOptionDisposition::Override; else - entryStructPointer->xmlHttpRequest = FilterOptionEnum::Disposition::Apply; + entryStructPointer->xmlHttpRequest = FilterOptionDisposition::Apply; } } // Finish processing filter options. @@ -1267,8 +1277,7 @@ void FilterListHelper::populateRequestStruct(RequestStruct *requestStructPointer requestStructPointer->dispositionInt = disposition; requestStructPointer->filterListTitle = filterListTitle; requestStructPointer->sublistInt = sublistInt; - requestStructPointer->entryStruct.appliedEntryList = entryStructPointer->appliedEntryList; - requestStructPointer->entryStruct.originalEntry = entryStructPointer->originalEntry; + requestStructPointer->entryStruct = *entryStructPointer; } void FilterListHelper::prepareFilterListString(QString &filterListString, EntryStruct *entryStructPointer) const diff --git a/src/helpers/FilterListHelper.h b/src/helpers/FilterListHelper.h index 772d86a..b1c93a0 100644 --- a/src/helpers/FilterListHelper.h +++ b/src/helpers/FilterListHelper.h @@ -17,13 +17,12 @@ * along with Privacy Browser PC. If not, see . */ -#ifndef FILTERLISTHELPER_H -#define FILTERLISTHELPER_H +#ifndef FILTER_LIST_HELPER_H +#define FILTER_LIST_HELPER_H // Application headers. #include "structs/FilterListStruct.h" #include "structs/RequestStruct.h" -#include "structs/UrlStruct.h" // Qt framework headers. #include @@ -57,7 +56,7 @@ public: bool checkFilterLists(QWebEngineUrlRequestInfo &urlRequestInfo, RequestStruct *requestStructPointer) const; QString getDispositionString(int dispositionInt) const; QString getNavigationTypeString(int navigationTypeInt) const; - QString getRequestOptionDispositionString(const FilterOptionEnum::Disposition filterOptionDisposition) const; + QString getRequestOptionDispositionString(const FilterOptionDisposition filterOptionDisposition) const; QString getResourceTypeString(int resourceTypeInt) const; QString getSublistName(int sublistInt) const; @@ -112,17 +111,16 @@ private: // The private functions. bool blockRequest(QWebEngineUrlRequestInfo &urlRequestInfo, RequestStruct *requestStructPointer, const QString &filterListTitle, const int sublistInt, EntryStruct *entryStructPointer) const; - bool checkAppliedEntry(QWebEngineUrlRequestInfo &urlRequestInfo, UrlStruct &urlStruct, RequestStruct *requestStructPointer, const QString &filterListTitle, const int sublistInt, - EntryStruct *entryStructPointer, QString &urlString, QString &urlStringWithSeparators) const; - bool checkDomain(QWebEngineUrlRequestInfo &urlRequestInfo, UrlStruct &urlStruct, RequestStruct *requestStructPointer, const QString &filterListTitle, const int sublistInt, + bool checkAppliedEntry(QWebEngineUrlRequestInfo &urlRequestInfo, RequestStruct *requestStructPointer, const QString &filterListTitle, const int sublistInt, QString urlString, + const RequestUrlType requestUrlType, EntryStruct *entryStructPointer) const; + bool checkDomain(QWebEngineUrlRequestInfo &urlRequestInfo, RequestStruct *requestStructPointer, const QString &filterListTitle, const int sublistInt, EntryStruct *entryStructPointer) const; - bool checkIndividualList(QWebEngineUrlRequestInfo &urlRequestInfo, UrlStruct &urlStruct, RequestStruct *requestStructPointer, FilterListStruct *filterListStructPointer) const; - bool checkRegularExpression(QWebEngineUrlRequestInfo &urlRequestInfo, UrlStruct &urlStruct, RequestStruct *requestStructPointer, const QString &filterListTitle, const int sublistInt, + bool checkIndividualList(QWebEngineUrlRequestInfo &urlRequestInfo, RequestStruct *requestStructPointer, FilterListStruct *filterListStructPointer) const; + bool checkRegularExpression(QWebEngineUrlRequestInfo &urlRequestInfo, RequestStruct *requestStructPointer, const QString &filterListTitle, const int sublistInt, EntryStruct *entryStructPointer) const; bool checkRequestOptions(QWebEngineUrlRequestInfo &urlRequestInfo, RequestStruct *requestStructPointer, const QString &filterListTitle, const int sublistInt, EntryStruct *entryStructPointer) const; - bool checkThirdParty(QWebEngineUrlRequestInfo &urlRequestInfo, RequestStruct *requestStructPointer, const bool isThirdPartyRequest, const QString &filterListTitle, const int sublistInt, - EntryStruct *entryStructPointer) const; + bool checkThirdParty(QWebEngineUrlRequestInfo &urlRequestInfo, RequestStruct *requestStructPointer, const QString &filterListTitle, const int sublistInt, EntryStruct *entryStructPointer) const; FilterListStruct* populateFilterList(const QString &filterListFileName) const; void populateRequestStruct(RequestStruct *requestStructPointer, const int disposition, const QString &filterListTitle, const int sublistInt, EntryStruct *entryStructPointer) const; void prepareFilterListString(QString &filterListString, EntryStruct *entryStructPointer) const; diff --git a/src/interceptors/UrlRequestInterceptor.cpp b/src/interceptors/UrlRequestInterceptor.cpp index 18944ea..199abcf 100644 --- a/src/interceptors/UrlRequestInterceptor.cpp +++ b/src/interceptors/UrlRequestInterceptor.cpp @@ -43,6 +43,7 @@ void UrlRequestInterceptor::interceptRequest(QWebEngineUrlRequestInfo &urlReques requestStructPointer->requestMethodString = urlRequestInfo.requestMethod(); requestStructPointer->resourceTypeInt = urlRequestInfo.resourceType(); requestStructPointer->urlString = urlRequestInfo.requestUrl().toString(); + requestStructPointer->webPageUrlString = urlRequestInfo.firstPartyUrl().toString(); // Check the filter lists. bool continueProcessing = globalFilterListHelperPointer->checkFilterLists(urlRequestInfo, requestStructPointer); diff --git a/src/structs/EntryStruct.h b/src/structs/EntryStruct.h index 3354a6a..6b0fed5 100644 --- a/src/structs/EntryStruct.h +++ b/src/structs/EntryStruct.h @@ -17,15 +17,19 @@ * along with Privacy Browser PC. If not, see . */ -#ifndef ENTRYSTRUCT_H -#define ENTRYSTRUCT_H - -// Application headers. -#include "enums/FilterOptionEnum.h" +#ifndef ENTRY_STRUCT_H +#define ENTRY_STRUCT_H // Qt toolkit headers. #include +enum FilterOptionDisposition +{ + Null = 0, + Apply = 1, + Override = 2, +}; + struct EntryStruct { // The strings. @@ -47,18 +51,18 @@ struct EntryStruct int sizeOfAppliedEntryList; // The filter options. - FilterOptionEnum::Disposition domain = FilterOptionEnum::Disposition::Null; - FilterOptionEnum::Disposition font = FilterOptionEnum::Disposition::Null; - FilterOptionEnum::Disposition image = FilterOptionEnum::Disposition::Null; - FilterOptionEnum::Disposition mainFrame = FilterOptionEnum::Disposition::Null; - FilterOptionEnum::Disposition media = FilterOptionEnum::Disposition::Null; - FilterOptionEnum::Disposition object = FilterOptionEnum::Disposition::Null; - FilterOptionEnum::Disposition other = FilterOptionEnum::Disposition::Null; - FilterOptionEnum::Disposition ping = FilterOptionEnum::Disposition::Null; - FilterOptionEnum::Disposition script = FilterOptionEnum::Disposition::Null; - FilterOptionEnum::Disposition styleSheet = FilterOptionEnum::Disposition::Null; - FilterOptionEnum::Disposition subFrame = FilterOptionEnum::Disposition::Null; - FilterOptionEnum::Disposition thirdParty = FilterOptionEnum::Disposition::Null; - FilterOptionEnum::Disposition xmlHttpRequest = FilterOptionEnum::Disposition::Null; + FilterOptionDisposition domain = FilterOptionDisposition::Null; + FilterOptionDisposition font = FilterOptionDisposition::Null; + FilterOptionDisposition image = FilterOptionDisposition::Null; + FilterOptionDisposition mainFrame = FilterOptionDisposition::Null; + FilterOptionDisposition media = FilterOptionDisposition::Null; + FilterOptionDisposition object = FilterOptionDisposition::Null; + FilterOptionDisposition other = FilterOptionDisposition::Null; + FilterOptionDisposition ping = FilterOptionDisposition::Null; + FilterOptionDisposition script = FilterOptionDisposition::Null; + FilterOptionDisposition styleSheet = FilterOptionDisposition::Null; + FilterOptionDisposition subFrame = FilterOptionDisposition::Null; + FilterOptionDisposition thirdParty = FilterOptionDisposition::Null; + FilterOptionDisposition xmlHttpRequest = FilterOptionDisposition::Null; }; #endif diff --git a/src/structs/RequestStruct.h b/src/structs/RequestStruct.h index 2866f9e..b6d7c3d 100644 --- a/src/structs/RequestStruct.h +++ b/src/structs/RequestStruct.h @@ -17,21 +17,36 @@ * along with Privacy Browser PC. If not, see . */ -#ifndef REQUESTSTRUCT_H -#define REQUESTSTRUCT_H +#ifndef REQUEST_STRUCT_H +#define REQUEST_STRUCT_H // Application headers. #include "EntryStruct.h" +enum RequestUrlType +{ + Url = 0, + TruncatedUrl = 1, + UrlWithSeparators = 2, + TruncatedUrlWithSeparators = 3 +}; + struct RequestStruct { int dispositionInt = 0; // `0` is the default disposition. EntryStruct entryStruct; QString filterListTitle; + QString fqdn; + bool isThirdPartyRequest; + RequestUrlType matchedUrlType; int navigationTypeInt; QString requestMethodString; int resourceTypeInt; int sublistInt = -1; // The sublist should be initialized because it is not always set later. + QString truncatedUrlString; + QString truncatedUrlStringWithSeparators; QString urlString; + QString urlStringWithSeparators; + QString webPageUrlString; }; #endif diff --git a/src/structs/UrlStruct.h b/src/structs/UrlStruct.h deleted file mode 100644 index 76a0371..0000000 --- a/src/structs/UrlStruct.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2024 Soren Stoutner . - * - * This file is part of 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. - * - * 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. - * - * You should have received a copy of the GNU General Public License - * along with Privacy Browser PC. If not, see . - */ - -#ifndef URLSTRUCT_H -#define URLSTRUCT_H - -// Qt toolkit headers. -#include - -struct UrlStruct -{ - QString urlString; - QString urlStringWithSeparators; - QString truncatedUrlString; - QString truncatedUrlStringWithSeparators; - QString fqdn; - bool isThirdPartyRequest; -}; -#endif diff --git a/src/uis/FilterEntryDialog.ui b/src/uis/FilterEntryDialog.ui index c465d16..4838cac 100644 --- a/src/uis/FilterEntryDialog.ui +++ b/src/uis/FilterEntryDialog.ui @@ -27,7 +27,7 @@ - + Filter List @@ -49,7 +49,7 @@ - + Sublist @@ -75,7 +75,7 @@ - + Applied Entry List @@ -101,7 +101,7 @@ - + Domain @@ -123,7 +123,7 @@ - + Third Party @@ -149,7 +149,7 @@ - + Initial Match @@ -171,7 +171,7 @@ - + Final Match @@ -197,7 +197,7 @@ - + Domain List @@ -261,7 +261,7 @@ - + Font @@ -287,7 +287,7 @@ - + Image @@ -313,7 +313,7 @@ - + Main Frame @@ -339,7 +339,7 @@ - + Media @@ -365,7 +365,7 @@ - + Object @@ -391,7 +391,7 @@ - + Other @@ -417,7 +417,7 @@ - + Ping @@ -443,7 +443,7 @@ - + Script @@ -469,7 +469,7 @@ - + Style Sheet @@ -495,7 +495,7 @@ - + Sub Frame @@ -521,7 +521,7 @@ - + XML HTTP Request @@ -554,7 +554,7 @@ - + Applied Filter Options @@ -580,7 +580,7 @@ - + Original Filter Options @@ -606,7 +606,7 @@ - + Original Entry diff --git a/src/uis/RequestDetailDialog.ui b/src/uis/RequestDetailDialog.ui index d0a471d..35a5f13 100644 --- a/src/uis/RequestDetailDialog.ui +++ b/src/uis/RequestDetailDialog.ui @@ -23,6 +23,25 @@ + + + + Request + + + + + 22 + true + + + + + Qt::AlignCenter + + + + @@ -49,19 +68,19 @@ - + - URL + Web Page URL - + true @@ -75,6 +94,102 @@ + + + + + + + + + + Request URL + + + + + + + + true + + + + + Qt::NoFocus + + + + + + + + + Request URL With Separators + + + + + + + + true + + + + + Qt::NoFocus + + + + + + + + + Truncated Request URL + + + + + + + + true + + + + + Qt::NoFocus + + + + + + + + + Truncated Request URL With Separators + + + + + + + + true + + + + + Qt::NoFocus + + + + + + + @@ -121,78 +236,17 @@ - + - Resource Type - - - - - - - - true - - - - - Qt::NoFocus - - - - - - - - - - - Qt::Horizontal - - - - - - - - - - - Filter List - - - - - - - - true - - - - - Qt::NoFocus - - - - - - - - - - - - - Sublist + Third Party - + true @@ -203,22 +257,18 @@ - - - - - + - + - Applied Entry List + Resource Type - + true @@ -232,30 +282,647 @@ - - - - - - Original Entry - - - - - - - - true - - - - - Qt::NoFocus - - - - + + + + + + + Qt::Horizontal + + + + + + + + Filter List Entry + + + + + 22 + true + + + + + Qt::AlignCenter + + + + + + + + + + + + + Filter List + + + + + + + + true + + + + + Qt::NoFocus + + + + + + + + + + + Sublist + + + + + + + + true + + + + + Qt::NoFocus + + + + + + + + + + + + + Applied Entry List + + + + + + + + true + + + + + Qt::NoFocus + + + + + + + + + + + + + Domain + + + + + + + + true + + + + + Qt::NoFocus + + + + + + + + + Third Party + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + true + + + + + Qt::NoFocus + + + + + + + + + Initial Match + + + + + + + + true + + + + + Qt::NoFocus + + + + + + + + + Final Match + + + + + + + + true + + + + + Qt::NoFocus + + + + + + + + + + + + + Domain List + + + + + + + + true + + + + + Qt::NoFocus + + + + + + + + + + + + + + + + + Qt::Horizontal + + + + + + + + Has Request Options + + + + + Qt::NoFocus + + + + + + + + Qt::Horizontal + + + + + + + + + + + + + Font + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + true + + + + + Qt::NoFocus + + + + + + + + + Image + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + true + + + + + Qt::NoFocus + + + + + + + + + Main Frame + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + true + + + + + Qt::NoFocus + + + + + + + + + Media + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + true + + + + + Qt::NoFocus + + + + + + + + + Object + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + true + + + + + Qt::NoFocus + + + + + + + + + Other + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + true + + + + + Qt::NoFocus + + + + + + + + + Ping + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + true + + + + + Qt::NoFocus + + + + + + + + + Script + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + true + + + + + Qt::NoFocus + + + + + + + + + Style Sheet + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + true + + + + + Qt::NoFocus + + + + + + + + + Sub Frame + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + true + + + + + Qt::NoFocus + + + + + + + + + XML HTTP Request + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + true + + + + + Qt::NoFocus + + + + + + + + + + + + + + + + Applied Filter Options + + + + + + + + true + + + + + Qt::NoFocus + + + + + + + + + + + + + Original Filter Options + + + + + + + + true + + + + + Qt::NoFocus + + + + + + + + + + + + + Original Entry + + + + + + + + true + + + + + Qt::NoFocus + + + + + + + -- 2.45.2