From 5d2d1c86ae51a7d17fb3e9906dbc6d5f563f19a9 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Thu, 8 Nov 2012 17:19:52 +0100 Subject: Clean up previous commit about adblock and fix enable/disable feature --- src/adblock/adblockmanager.cpp | 53 +++++++----------------------------------- 1 file changed, 8 insertions(+), 45 deletions(-) (limited to 'src/adblock/adblockmanager.cpp') diff --git a/src/adblock/adblockmanager.cpp b/src/adblock/adblockmanager.cpp index 49dfa4f4..d5a3e27c 100644 --- a/src/adblock/adblockmanager.cpp +++ b/src/adblock/adblockmanager.cpp @@ -241,6 +241,14 @@ bool AdBlockManager::blockRequest(const QNetworkRequest &request) if (request.url().scheme() != QL1S("http")) return false; + QStringList whiteRefererList = ReKonfig::whiteReferer(); + const QString referer = request.rawHeader("referer"); + Q_FOREACH(const QString &host, whiteRefererList) + { + if (referer.contains(host)) + return false; + } + QString urlString = request.url().toString(); // We compute a lowercase version of the URL so each rule does not // have to do it. @@ -368,51 +376,6 @@ void AdBlockManager::addCustomRule(const QString &stringRule, bool reloadPage) } -void AdBlockManager::removeCustomHostRule(const QString &stringRule, bool reloadPage) -{ - // save rule in local filters - QString localRulesFilePath = KStandardDirs::locateLocal("appdata" , QL1S("adblockrules_local")); - - QFile ruleFile(localRulesFilePath); - if (!ruleFile.open(QFile::ReadOnly)) - { - kDebug() << "Unable to open rule file" << localRulesFilePath; - return; - } - - QTextStream in(&ruleFile); - QStringList localRules; - QString r; - do - { - r = in.readLine(); - if (r != stringRule) - localRules << r; - } - while (!r.isNull()); - ruleFile.close(); - - if (!ruleFile.open(QFile::WriteOnly)) - { - kDebug() << "Unable to open rule file" << localRulesFilePath; - return; - } - - QTextStream out(&ruleFile); - Q_FOREACH(const QString &r, localRules) - { - out << r << '\n'; - } - - // (un)load it - _hostWhiteList.remove(stringRule); - - // eventually reload page - if (reloadPage) - emit reloadCurrentPage(); -} - - bool AdBlockManager::isAdblockEnabledForHost(const QString &host) { return ! _hostWhiteList.match(host); -- cgit v1.2.1