mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 10:46:35 +01:00
Implement generichide and enable elemhide
This commit is contained in:
parent
8080d3b70b
commit
b0b89339f3
@ -412,7 +412,7 @@ bool AdBlockManager::canBeBlocked(const QUrl &url) const
|
|||||||
|
|
||||||
QString AdBlockManager::elementHidingRules(const QUrl &url) const
|
QString AdBlockManager::elementHidingRules(const QUrl &url) const
|
||||||
{
|
{
|
||||||
if (!isEnabled() || !canRunOnScheme(url.scheme()) || !canBeBlocked(url))
|
if (!isEnabled() || !canRunOnScheme(url.scheme()) || m_matcher->genericElemHideDisabledForUrl(url))
|
||||||
return QString();
|
return QString();
|
||||||
|
|
||||||
return m_matcher->elementHidingRules();
|
return m_matcher->elementHidingRules();
|
||||||
@ -420,7 +420,7 @@ QString AdBlockManager::elementHidingRules(const QUrl &url) const
|
|||||||
|
|
||||||
QString AdBlockManager::elementHidingRulesForDomain(const QUrl &url) const
|
QString AdBlockManager::elementHidingRulesForDomain(const QUrl &url) const
|
||||||
{
|
{
|
||||||
if (!isEnabled() || !canRunOnScheme(url.scheme()) || !canBeBlocked(url))
|
if (!isEnabled() || !canRunOnScheme(url.scheme()) || m_matcher->elemHideDisabledForUrl(url))
|
||||||
return QString();
|
return QString();
|
||||||
|
|
||||||
return m_matcher->elementHidingRulesForDomain(url.host());
|
return m_matcher->elementHidingRulesForDomain(url.host());
|
||||||
|
@ -83,6 +83,20 @@ bool AdBlockMatcher::elemHideDisabledForUrl(const QUrl &url) const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AdBlockMatcher::genericElemHideDisabledForUrl(const QUrl &url) const
|
||||||
|
{
|
||||||
|
if (elemHideDisabledForUrl(url))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
int count = m_generichideRules.count();
|
||||||
|
|
||||||
|
for (int i = 0; i < count; ++i)
|
||||||
|
if (m_generichideRules.at(i)->urlMatch(url))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
QString AdBlockMatcher::elementHidingRules() const
|
QString AdBlockMatcher::elementHidingRules() const
|
||||||
{
|
{
|
||||||
return m_elementHidingRules;
|
return m_elementHidingRules;
|
||||||
@ -153,6 +167,9 @@ void AdBlockMatcher::update()
|
|||||||
else if (rule->isElemhide()) {
|
else if (rule->isElemhide()) {
|
||||||
m_elemhideRules.append(rule);
|
m_elemhideRules.append(rule);
|
||||||
}
|
}
|
||||||
|
else if (rule->isGenerichide()) {
|
||||||
|
m_generichideRules.append(rule);
|
||||||
|
}
|
||||||
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);
|
||||||
|
@ -40,6 +40,7 @@ public:
|
|||||||
|
|
||||||
bool adBlockDisabledForUrl(const QUrl &url) const;
|
bool adBlockDisabledForUrl(const QUrl &url) const;
|
||||||
bool elemHideDisabledForUrl(const QUrl &url) const;
|
bool elemHideDisabledForUrl(const QUrl &url) const;
|
||||||
|
bool genericElemHideDisabledForUrl(const QUrl &url) const;
|
||||||
|
|
||||||
QString elementHidingRules() const;
|
QString elementHidingRules() const;
|
||||||
QString elementHidingRulesForDomain(const QString &domain) const;
|
QString elementHidingRulesForDomain(const QString &domain) const;
|
||||||
@ -57,6 +58,7 @@ private:
|
|||||||
QVector<const AdBlockRule*> m_domainRestrictedCssRules;
|
QVector<const AdBlockRule*> m_domainRestrictedCssRules;
|
||||||
QVector<const AdBlockRule*> m_documentRules;
|
QVector<const AdBlockRule*> m_documentRules;
|
||||||
QVector<const AdBlockRule*> m_elemhideRules;
|
QVector<const AdBlockRule*> m_elemhideRules;
|
||||||
|
QVector<const AdBlockRule*> m_generichideRules;
|
||||||
|
|
||||||
QString m_elementHidingRules;
|
QString m_elementHidingRules;
|
||||||
AdBlockSearchTree m_networkBlockTree;
|
AdBlockSearchTree m_networkBlockTree;
|
||||||
|
@ -164,6 +164,11 @@ bool AdBlockRule::isElemhide() const
|
|||||||
return hasOption(ElementHideOption);
|
return hasOption(ElementHideOption);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AdBlockRule::isGenerichide() const
|
||||||
|
{
|
||||||
|
return hasOption(GenericHideOption);
|
||||||
|
}
|
||||||
|
|
||||||
bool AdBlockRule::isDomainRestricted() const
|
bool AdBlockRule::isDomainRestricted() const
|
||||||
{
|
{
|
||||||
return hasOption(DomainRestrictedOption);
|
return hasOption(DomainRestrictedOption);
|
||||||
@ -201,7 +206,7 @@ bool AdBlockRule::isInternalDisabled() const
|
|||||||
|
|
||||||
bool AdBlockRule::urlMatch(const QUrl &url) const
|
bool AdBlockRule::urlMatch(const QUrl &url) const
|
||||||
{
|
{
|
||||||
if (!hasOption(DocumentOption) && !hasOption(ElementHideOption)) {
|
if (!hasOption(DocumentOption) && !hasOption(ElementHideOption) && !hasOption(GenericHideOption) && !hasOption(GenericBlockOption)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -485,6 +490,10 @@ void AdBlockRule::parseFilter()
|
|||||||
setException(OtherOption, option.startsWith(QL1C('~')));
|
setException(OtherOption, option.startsWith(QL1C('~')));
|
||||||
++handledOptions;
|
++handledOptions;
|
||||||
}
|
}
|
||||||
|
else if (option == QL1S("collapse")) {
|
||||||
|
// Hiding placeholders of blocked elements is enabled by default
|
||||||
|
++handledOptions;
|
||||||
|
}
|
||||||
else if (option == QL1S("popup")) {
|
else if (option == QL1S("popup")) {
|
||||||
// doesn't do anything yet
|
// doesn't do anything yet
|
||||||
setOption(PopupOption);
|
setOption(PopupOption);
|
||||||
@ -498,10 +507,15 @@ void AdBlockRule::parseFilter()
|
|||||||
setOption(ElementHideOption);
|
setOption(ElementHideOption);
|
||||||
++handledOptions;
|
++handledOptions;
|
||||||
}
|
}
|
||||||
else if (option == QL1S("collapse")) {
|
else if (option == QL1S("generichide") && m_isException) {
|
||||||
// Hiding placeholders of blocked elements is enabled by default
|
setOption(GenericHideOption);
|
||||||
++handledOptions;
|
++handledOptions;
|
||||||
}
|
}
|
||||||
|
else if (option == QL1S("genericblock") && m_isException) {
|
||||||
|
// doesn't do anything yet
|
||||||
|
setOption(GenericBlockOption);
|
||||||
|
// ++handledOptions;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we don't handle all options, it's safer to just disable this rule
|
// If we don't handle all options, it's safer to just disable this rule
|
||||||
|
@ -81,6 +81,7 @@ public:
|
|||||||
|
|
||||||
bool isDocument() const;
|
bool isDocument() const;
|
||||||
bool isElemhide() const;
|
bool isElemhide() const;
|
||||||
|
bool isGenerichide() const;
|
||||||
|
|
||||||
bool isDomainRestricted() const;
|
bool isDomainRestricted() const;
|
||||||
bool isException() const;
|
bool isException() const;
|
||||||
@ -152,6 +153,8 @@ private:
|
|||||||
// Exception only options
|
// Exception only options
|
||||||
DocumentOption = 1 << 20,
|
DocumentOption = 1 << 20,
|
||||||
ElementHideOption = 1 << 21,
|
ElementHideOption = 1 << 21,
|
||||||
|
GenericHideOption = 1 << 22,
|
||||||
|
GenericBlockOption = 1 << 23,
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_FLAGS(RuleOptions, RuleOption)
|
Q_DECLARE_FLAGS(RuleOptions, RuleOption)
|
||||||
|
Loading…
Reference in New Issue
Block a user