1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 09:32:12 +01:00

[AdBlock] Download also whitelist rules from EasyList.

This commit is contained in:
nowrep 2013-02-27 19:51:34 +01:00
parent 7e6d619516
commit 4d82e307ad
2 changed files with 14 additions and 11 deletions

View File

@ -172,7 +172,7 @@ void AdBlockSubscription::subscriptionDownloaded()
m_reply = 0;
}
void AdBlockSubscription::saveDownloadedData(QByteArray &data)
void AdBlockSubscription::saveDownloadedData(const QByteArray &data)
{
QFile file(m_filePath);
@ -374,6 +374,11 @@ void AdBlockSubscription::populateCache()
}
}
AdBlockSubscription::~AdBlockSubscription()
{
qDeleteAll(m_rules);
}
// AdBlockEasyList
AdBlockEasyList::AdBlockEasyList(QObject* parent)
@ -388,7 +393,7 @@ bool AdBlockEasyList::canBeRemoved() const
return false;
}
void AdBlockEasyList::saveDownloadedData(QByteArray &data)
void AdBlockEasyList::saveDownloadedData(const QByteArray &data)
{
QFile file(filePath());
@ -399,9 +404,12 @@ void AdBlockEasyList::saveDownloadedData(QByteArray &data)
// Third-party advertisers rules are with start domain (||) placeholder which needs regexps
// So we are ignoring it for keeping good performance
data = data.left(data.indexOf(QLatin1String("!-----------------------------Third-party adverts-----------------------------!")));
// But we will use whitelist rules at the end of list
file.write(data);
QByteArray part1 = data.left(data.indexOf(QLatin1String("!-----------------------------Third-party adverts-----------------------------!")));
QByteArray part2 = data.mid(data.indexOf(QLatin1String("!---------------------------------Whitelists----------------------------------!")));
file.write(part1 + part2);
file.close();
}
@ -514,8 +522,3 @@ const AdBlockRule* AdBlockCustomList::replaceRule(AdBlockRule* rule, int offset)
return m_rules[offset];
}
AdBlockSubscription::~AdBlockSubscription()
{
qDeleteAll(m_rules);
}

View File

@ -107,7 +107,7 @@ protected slots:
void subscriptionDownloaded();
protected:
virtual void saveDownloadedData(QByteArray &data);
virtual void saveDownloadedData(const QByteArray &data);
void populateCache();
@ -140,7 +140,7 @@ public:
bool canBeRemoved() const;
protected:
void saveDownloadedData(QByteArray &data);
void saveDownloadedData(const QByteArray &data);
};
class AdBlockCustomList : public AdBlockSubscription