summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/adblock/adblockmanager.cpp65
-rw-r--r--src/adblock/adblockmanager.h3
-rw-r--r--src/webpage.cpp4
4 files changed, 58 insertions, 15 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 4e12ccd7..1061f3e7 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -38,6 +38,7 @@ SET( rekonq_KDEINIT_SRCS
bookmarkspanel/bookmarksproxy.cpp
#----------------------------------------
adblock/adblockmanager.cpp
+ adblock/adblockrule.cpp
)
diff --git a/src/adblock/adblockmanager.cpp b/src/adblock/adblockmanager.cpp
index 6b2f9616..70960b44 100644
--- a/src/adblock/adblockmanager.cpp
+++ b/src/adblock/adblockmanager.cpp
@@ -27,6 +27,16 @@
#include "adblockmanager.h"
#include "adblockmanager.moc"
+
+// Local Includes
+#include "adblockrule.h"
+
+// KDE Includes
+#include <KSharedConfig>
+#include <KConfigGroup>
+#include <KDebug>
+
+// Qt Includes
#include <QUrl>
@@ -45,26 +55,53 @@ AdBlockManager::~AdBlockManager()
void AdBlockManager::loadSettings()
{
-// KConfigGroup cg(_config, _group);
-// groupBox->setChecked( cg.readEntry("Enabled", false) );
-//
-// int num = cg.readEntry("Count", 0);
-// for (int i = 0; i < num; ++i)
-// {
-// QString key = "Filter-" + QString::number(i);
-// QString filter = cg.readEntry( key, QString() );
-// listWidget->addItem(filter);
-// }
+ _blockList.clear();
+
+ KSharedConfig::Ptr config = KSharedConfig::openConfig("webkitrc", KConfig::NoGlobals);
+ KConfigGroup cg(config, "adblock");
+
+ _isAdblockEnabled = cg.readEntry("Enabled", false);
+
+ int num = cg.readEntry("Count", 0);
+ for (int i = 0; i < num; ++i)
+ {
+ QString key = "Filter-" + QString::number(i);
+ QString filter = cg.readEntry( key, QString() );
+ if(!filter.isEmpty())
+ {
+ if (filter.startsWith(QLatin1String("@@")))
+ _whiteList << filter;
+ else
+ _blockList << filter;
+ }
+ }
}
bool AdBlockManager::isUrlAllowed(const QUrl &url)
{
- if (url.scheme() == QLatin1String("data"))
- return false;
-
+ kDebug() << "matching rule...";
if (!_isAdblockEnabled)
- return false;
+ return true;
+ QString urlString = QString::fromUtf8(url.toEncoded());
+
+ foreach(const QString &str, _whiteList)
+ {
+ AdBlockRule rule(str);
+ kDebug() << "checking white list rule...";
+ if(rule.match(urlString))
+ return true;
+ }
+
+ foreach(const QString &str, _blockList)
+ {
+ AdBlockRule rule(str);
+ kDebug() << "checking block list rule...";
+ if(rule.match(urlString))
+ return false;
+ }
+
+ kDebug() << "done";
return true;
}
diff --git a/src/adblock/adblockmanager.h b/src/adblock/adblockmanager.h
index c782ee0d..a175fa2f 100644
--- a/src/adblock/adblockmanager.h
+++ b/src/adblock/adblockmanager.h
@@ -50,7 +50,8 @@ public:
private:
bool _isAdblockEnabled;
- QStringList _blocks;
+ QStringList _blockList;
+ QStringList _whiteList;
};
#endif
diff --git a/src/webpage.cpp b/src/webpage.cpp
index 9803d8a3..e8c204f8 100644
--- a/src/webpage.cpp
+++ b/src/webpage.cpp
@@ -253,5 +253,9 @@ QString WebPage::errorPage(QNetworkReply *reply)
bool WebPage::authorizedRequest(const QUrl &url) const
{
+ // we filter just http sites
+ if(url.scheme() != QLatin1String("http"))
+ return true;
+
return m_adBlockMan->isUrlAllowed(url);
}