1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 02:36:34 +01:00

Parse but ignore unsupported adblock patterns

This commit is contained in:
Allan Sandfeld Jensen 2021-05-22 19:32:04 +02:00 committed by David Rosca
parent e6450ba8f9
commit 8080d3b70b
5 changed files with 52 additions and 13 deletions

View File

@ -132,6 +132,9 @@ void AdBlockMatcher::update()
// Don't add internally disabled rules to cache
if (rule->isInternalDisabled())
continue;
// Or unsupported ones
if (rule->isUnsupportedRule())
continue;
if (rule->isCssRule()) {
// We will add only enabled css rules to cache, because there is no enabled/disabled
@ -153,8 +156,7 @@ void AdBlockMatcher::update()
else if (rule->isException()) {
if (!m_networkExceptionTree.add(rule))
m_networkExceptionRules.append(rule);
}
else {
} else {
if (!m_networkBlockTree.add(rule))
m_networkBlockRules.append(rule);
}

View File

@ -149,6 +149,11 @@ QString AdBlockRule::cssSelector() const
return m_matchString;
}
bool AdBlockRule::isUnsupportedRule() const
{
return m_type == ExtendedCssRule || m_type == SnippetRule || m_isInternalDisabled;
}
bool AdBlockRule::isDocument() const
{
return hasOption(DocumentOption);
@ -356,13 +361,44 @@ void AdBlockRule::parseFilter()
return;
}
// Exception always starts with @@
if (parsedLine.startsWith(QL1S("@@"))) {
m_isException = true;
parsedLine.remove(0, 2);
}
// Extended CSS element hiding
if (parsedLine.contains(QL1S("#?#"))) {
m_type = ExtendedCssRule;
int pos = parsedLine.indexOf(QL1C('#'));
if (!parsedLine.startsWith(QL1S("#"))) {
QString domains = parsedLine.left(pos);
parseDomains(domains, QL1C(','));
}
m_matchString = parsedLine.mid(pos + 3);
// CSS rule cannot have more options -> stop parsing
return;
}
// Snippet rule
if (parsedLine.contains(QL1S("#$#"))) {
m_type = SnippetRule;
int pos = parsedLine.indexOf(QL1C('#'));
if (!parsedLine.startsWith(QL1S("#"))) {
QString domains = parsedLine.left(pos);
parseDomains(domains, QL1C(','));
}
m_matchString = parsedLine.mid(pos + 3);
return;
}
// CSS Element hiding rule
if (parsedLine.contains(QL1S("##")) || parsedLine.contains(QL1S("#@#"))) {
m_type = CssRule;
int pos = parsedLine.indexOf(QL1C('#'));
// Domain restricted rule
if (!parsedLine.startsWith(QL1S("##"))) {
if (!parsedLine.startsWith(QL1S("#"))) {
QString domains = parsedLine.left(pos);
parseDomains(domains, QL1C(','));
}
@ -374,12 +410,6 @@ void AdBlockRule::parseFilter()
return;
}
// Exception always starts with @@
if (parsedLine.startsWith(QL1S("@@"))) {
m_isException = true;
parsedLine.remove(0, 2);
}
// Parse all options following $ char
int optionsIndex = parsedLine.indexOf(QL1C('$'));
if (optionsIndex >= 0) {

View File

@ -77,6 +77,8 @@ public:
bool isCssRule() const;
QString cssSelector() const;
bool isUnsupportedRule() const;
bool isDocument() const;
bool isElemhide() const;
@ -112,7 +114,9 @@ private:
StringEndsMatchRule = 3,
StringContainsMatchRule = 4,
MatchAllUrlsRule = 5,
Invalid = 6
ExtendedCssRule = 6,
SnippetRule = 7,
Invalid = 8
};
enum RuleOption {

View File

@ -210,7 +210,10 @@ void AdBlockTreeWidget::adjustItemFeatures(QTreeWidgetItem* item, const AdBlockR
item->setForeground(0, palette().windowText());
item->setFont(0, font());
if (rule->isException()) {
if (rule->isUnsupportedRule()) {
item->setForeground(0, QColor(Qt::gray));
item->setFont(0, QFont());
} else if (rule->isException()) {
item->setForeground(0, QColor(Qt::darkGreen));
item->setFont(0, QFont());
}

View File

@ -29,7 +29,7 @@ SearchToolBar::SearchToolBar(WebView* view, QWidget* parent)
: QWidget(parent)
, ui(new Ui::SearchToolbar)
, m_view(view)
, m_findFlags(0)
, m_findFlags{}
{
setAttribute(Qt::WA_DeleteOnClose);
ui->setupUi(this);
@ -82,7 +82,7 @@ void SearchToolBar::close()
void SearchToolBar::findNext()
{
m_findFlags = 0;
m_findFlags = {};
updateFindFlags();
searchText(ui->lineEdit->text());