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:
parent
e6450ba8f9
commit
8080d3b70b
@ -132,6 +132,9 @@ void AdBlockMatcher::update()
|
|||||||
// Don't add internally disabled rules to cache
|
// Don't add internally disabled rules to cache
|
||||||
if (rule->isInternalDisabled())
|
if (rule->isInternalDisabled())
|
||||||
continue;
|
continue;
|
||||||
|
// Or unsupported ones
|
||||||
|
if (rule->isUnsupportedRule())
|
||||||
|
continue;
|
||||||
|
|
||||||
if (rule->isCssRule()) {
|
if (rule->isCssRule()) {
|
||||||
// We will add only enabled css rules to cache, because there is no enabled/disabled
|
// 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()) {
|
else if (rule->isException()) {
|
||||||
if (!m_networkExceptionTree.add(rule))
|
if (!m_networkExceptionTree.add(rule))
|
||||||
m_networkExceptionRules.append(rule);
|
m_networkExceptionRules.append(rule);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (!m_networkBlockTree.add(rule))
|
if (!m_networkBlockTree.add(rule))
|
||||||
m_networkBlockRules.append(rule);
|
m_networkBlockRules.append(rule);
|
||||||
}
|
}
|
||||||
|
@ -149,6 +149,11 @@ QString AdBlockRule::cssSelector() const
|
|||||||
return m_matchString;
|
return m_matchString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AdBlockRule::isUnsupportedRule() const
|
||||||
|
{
|
||||||
|
return m_type == ExtendedCssRule || m_type == SnippetRule || m_isInternalDisabled;
|
||||||
|
}
|
||||||
|
|
||||||
bool AdBlockRule::isDocument() const
|
bool AdBlockRule::isDocument() const
|
||||||
{
|
{
|
||||||
return hasOption(DocumentOption);
|
return hasOption(DocumentOption);
|
||||||
@ -356,13 +361,44 @@ void AdBlockRule::parseFilter()
|
|||||||
return;
|
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
|
// CSS Element hiding rule
|
||||||
if (parsedLine.contains(QL1S("##")) || parsedLine.contains(QL1S("#@#"))) {
|
if (parsedLine.contains(QL1S("##")) || parsedLine.contains(QL1S("#@#"))) {
|
||||||
m_type = CssRule;
|
m_type = CssRule;
|
||||||
int pos = parsedLine.indexOf(QL1C('#'));
|
int pos = parsedLine.indexOf(QL1C('#'));
|
||||||
|
|
||||||
// Domain restricted rule
|
// Domain restricted rule
|
||||||
if (!parsedLine.startsWith(QL1S("##"))) {
|
if (!parsedLine.startsWith(QL1S("#"))) {
|
||||||
QString domains = parsedLine.left(pos);
|
QString domains = parsedLine.left(pos);
|
||||||
parseDomains(domains, QL1C(','));
|
parseDomains(domains, QL1C(','));
|
||||||
}
|
}
|
||||||
@ -374,12 +410,6 @@ void AdBlockRule::parseFilter()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exception always starts with @@
|
|
||||||
if (parsedLine.startsWith(QL1S("@@"))) {
|
|
||||||
m_isException = true;
|
|
||||||
parsedLine.remove(0, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse all options following $ char
|
// Parse all options following $ char
|
||||||
int optionsIndex = parsedLine.indexOf(QL1C('$'));
|
int optionsIndex = parsedLine.indexOf(QL1C('$'));
|
||||||
if (optionsIndex >= 0) {
|
if (optionsIndex >= 0) {
|
||||||
|
@ -77,6 +77,8 @@ public:
|
|||||||
bool isCssRule() const;
|
bool isCssRule() const;
|
||||||
QString cssSelector() const;
|
QString cssSelector() const;
|
||||||
|
|
||||||
|
bool isUnsupportedRule() const;
|
||||||
|
|
||||||
bool isDocument() const;
|
bool isDocument() const;
|
||||||
bool isElemhide() const;
|
bool isElemhide() const;
|
||||||
|
|
||||||
@ -112,7 +114,9 @@ private:
|
|||||||
StringEndsMatchRule = 3,
|
StringEndsMatchRule = 3,
|
||||||
StringContainsMatchRule = 4,
|
StringContainsMatchRule = 4,
|
||||||
MatchAllUrlsRule = 5,
|
MatchAllUrlsRule = 5,
|
||||||
Invalid = 6
|
ExtendedCssRule = 6,
|
||||||
|
SnippetRule = 7,
|
||||||
|
Invalid = 8
|
||||||
};
|
};
|
||||||
|
|
||||||
enum RuleOption {
|
enum RuleOption {
|
||||||
|
@ -210,7 +210,10 @@ void AdBlockTreeWidget::adjustItemFeatures(QTreeWidgetItem* item, const AdBlockR
|
|||||||
item->setForeground(0, palette().windowText());
|
item->setForeground(0, palette().windowText());
|
||||||
item->setFont(0, font());
|
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->setForeground(0, QColor(Qt::darkGreen));
|
||||||
item->setFont(0, QFont());
|
item->setFont(0, QFont());
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ SearchToolBar::SearchToolBar(WebView* view, QWidget* parent)
|
|||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
, ui(new Ui::SearchToolbar)
|
, ui(new Ui::SearchToolbar)
|
||||||
, m_view(view)
|
, m_view(view)
|
||||||
, m_findFlags(0)
|
, m_findFlags{}
|
||||||
{
|
{
|
||||||
setAttribute(Qt::WA_DeleteOnClose);
|
setAttribute(Qt::WA_DeleteOnClose);
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
@ -82,7 +82,7 @@ void SearchToolBar::close()
|
|||||||
|
|
||||||
void SearchToolBar::findNext()
|
void SearchToolBar::findNext()
|
||||||
{
|
{
|
||||||
m_findFlags = 0;
|
m_findFlags = {};
|
||||||
updateFindFlags();
|
updateFindFlags();
|
||||||
|
|
||||||
searchText(ui->lineEdit->text());
|
searchText(ui->lineEdit->text());
|
||||||
|
Loading…
Reference in New Issue
Block a user