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/adblockhostmatcher.cpp | 7 ----- src/adblock/adblockhostmatcher.h | 2 -- src/adblock/adblockmanager.cpp | 53 ++++++-------------------------------- src/adblock/adblockmanager.h | 1 - 4 files changed, 8 insertions(+), 55 deletions(-) (limited to 'src/adblock') diff --git a/src/adblock/adblockhostmatcher.cpp b/src/adblock/adblockhostmatcher.cpp index 5033c6f7..60936ec0 100644 --- a/src/adblock/adblockhostmatcher.cpp +++ b/src/adblock/adblockhostmatcher.cpp @@ -80,10 +80,3 @@ bool AdBlockHostMatcher::tryAddFilter(const QString &filter) return false; } - - -void AdBlockHostMatcher::remove(const QString &hostRule) -{ - bool on = m_hostList.remove(hostRule); - kDebug() << "REMOVED? " << on; -} diff --git a/src/adblock/adblockhostmatcher.h b/src/adblock/adblockhostmatcher.h index 3ce6e284..79918239 100644 --- a/src/adblock/adblockhostmatcher.h +++ b/src/adblock/adblockhostmatcher.h @@ -48,8 +48,6 @@ public: { m_hostList.clear(); } - - void remove(const QString &hostRule); private: QSet m_hostList; 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); diff --git a/src/adblock/adblockmanager.h b/src/adblock/adblockmanager.h index 7e93a379..993fa9a7 100644 --- a/src/adblock/adblockmanager.h +++ b/src/adblock/adblockmanager.h @@ -165,7 +165,6 @@ public: bool blockRequest(const QNetworkRequest &request); void addCustomRule(const QString &, bool reloadPage = true); - void removeCustomHostRule(const QString &, bool reloadPage = true); bool isAdblockEnabledForHost(const QString &host); -- cgit v1.2.1