summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2009-11-25 02:14:36 +0100
committerAndrea Diamantini <adjam7@gmail.com>2009-11-25 02:14:36 +0100
commit85a0f0d8f7cf37ba74182e0f9f94e69fe8c9bf61 (patch)
tree20a4546e0fd5e98612d7f1ac6ce3c34a4e7d2f13
parentLast history fixes (diff)
downloadrekonq-85a0f0d8f7cf37ba74182e0f9f94e69fe8c9bf61.tar.xz
Moving (back?) to konqueror adblock support.
This will be useful (if someone is interested) in pushing our patches directly on khtml filter engine.
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/adblock/CMakeLists.txt21
-rw-r--r--src/adblock/adblockmanager.cpp59
-rw-r--r--src/adblock/adblockmanager.h9
-rw-r--r--src/adblock/kcmwebkitadblock.cpp187
-rw-r--r--src/adblock/kcmwebkitadblock.h63
-rw-r--r--src/adblock/khtml_filter.cpp266
-rw-r--r--src/adblock/khtml_filter_p.h79
-rw-r--r--src/adblock/webkitAdblock.desktop14
-rw-r--r--src/adblock/webkitadblock.ui113
-rw-r--r--src/settings/settingsdialog.cpp2
11 files changed, 379 insertions, 436 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 96fddbff..7f7c85dd 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -38,7 +38,7 @@ SET( rekonq_KDEINIT_SRCS
bookmarkspanel/bookmarksproxy.cpp
#----------------------------------------
adblock/adblockmanager.cpp
- adblock/adblockrule.cpp
+ adblock/khtml_filter.cpp
)
diff --git a/src/adblock/CMakeLists.txt b/src/adblock/CMakeLists.txt
deleted file mode 100644
index f2785811..00000000
--- a/src/adblock/CMakeLists.txt
+++ /dev/null
@@ -1,21 +0,0 @@
-
-ADD_DEFINITIONS ( ${KDE4_DEFINITIONS} )
-
-SET(kcm_webkitadblock_SRCS
- kcmwebkitadblock.cpp
-)
-
-kde4_add_ui_files(kcm_webkitadblock_SRCS
- webkitadblock.ui
-)
-
-kde4_add_plugin(kcm_webkitadblock ${kcm_webkitadblock_SRCS})
-
-target_link_libraries(kcm_webkitadblock
- ${KDE4_KDEUI_LIBS}
- ${KDE4_KIO_LIBS}
-)
-
-install(TARGETS kcm_webkitadblock DESTINATION ${PLUGIN_INSTALL_DIR} )
-
-install( FILES webkitAdblock.desktop DESTINATION ${SERVICES_INSTALL_DIR} )
diff --git a/src/adblock/adblockmanager.cpp b/src/adblock/adblockmanager.cpp
index 70960b44..a0bc4e00 100644
--- a/src/adblock/adblockmanager.cpp
+++ b/src/adblock/adblockmanager.cpp
@@ -43,6 +43,7 @@
AdBlockManager::AdBlockManager(QObject *parent)
: QObject(parent)
, _isAdblockEnabled(false)
+ , _isHideAdsEnabled(false)
{
loadSettings();
}
@@ -55,24 +56,31 @@ AdBlockManager::~AdBlockManager()
void AdBlockManager::loadSettings()
{
- _blockList.clear();
-
- KSharedConfig::Ptr config = KSharedConfig::openConfig("webkitrc", KConfig::NoGlobals);
- KConfigGroup cg(config, "adblock");
-
- _isAdblockEnabled = cg.readEntry("Enabled", false);
+ KSharedConfig::Ptr config = KSharedConfig::openConfig("khtmlrc", KConfig::NoGlobals);
+ KConfigGroup cg( config, "Filter Settings" );
- int num = cg.readEntry("Count", 0);
- for (int i = 0; i < num; ++i)
+ if ( cg.exists() )
{
- QString key = "Filter-" + QString::number(i);
- QString filter = cg.readEntry( key, QString() );
- if(!filter.isEmpty())
+ _isAdblockEnabled = cg.readEntry("Enabled", false);
+ _isHideAdsEnabled = cg.readEntry("Shrink", false);
+
+ _adBlackList.clear();
+ _adWhiteList.clear();
+
+ QMap<QString,QString> entryMap = cg.entryMap();
+ QMap<QString,QString>::ConstIterator it;
+ for( it = entryMap.constBegin(); it != entryMap.constEnd(); ++it )
{
- if (filter.startsWith(QLatin1String("@@")))
- _whiteList << filter;
- else
- _blockList << filter;
+ QString name = it.key();
+ QString url = it.value();
+
+ if (name.startsWith(QLatin1String("Filter")))
+ {
+ if (url.startsWith(QLatin1String("@@")))
+ _adWhiteList.addFilter(url);
+ else
+ _adBlackList.addFilter(url);
+ }
}
}
}
@@ -80,28 +88,11 @@ void AdBlockManager::loadSettings()
bool AdBlockManager::isUrlAllowed(const QUrl &url)
{
- kDebug() << "matching rule...";
if (!_isAdblockEnabled)
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;
+ // Check the blacklist, and only if that matches, the whitelist
+ return _adBlackList.isUrlMatched(urlString) && !_adWhiteList.isUrlMatched(urlString);
}
diff --git a/src/adblock/adblockmanager.h b/src/adblock/adblockmanager.h
index a175fa2f..a57e3020 100644
--- a/src/adblock/adblockmanager.h
+++ b/src/adblock/adblockmanager.h
@@ -29,6 +29,9 @@
#define ADBLOCK_MANAGER_H
+// Local Includes
+#include "khtml_filter_p.h"
+
// Qt Includes
#include <QObject>
#include <QStringList>
@@ -50,8 +53,10 @@ public:
private:
bool _isAdblockEnabled;
- QStringList _blockList;
- QStringList _whiteList;
+ bool _isHideAdsEnabled;
+
+ khtml::FilterSet _adBlackList;
+ khtml::FilterSet _adWhiteList;
};
#endif
diff --git a/src/adblock/kcmwebkitadblock.cpp b/src/adblock/kcmwebkitadblock.cpp
deleted file mode 100644
index bbe44c0e..00000000
--- a/src/adblock/kcmwebkitadblock.cpp
+++ /dev/null
@@ -1,187 +0,0 @@
-/* ============================================================
-*
-* This file is a part of the rekonq project
-*
-* Copyright (C) 2009 by Andrea Diamantini <adjam7 at gmail dot com>
-*
-*
-* This program is free software; you can redistribute it and/or
-* modify it under the terms of the GNU General Public License as
-* published by the Free Software Foundation; either version 2 of
-* the License or (at your option) version 3 or any later version
-* accepted by the membership of KDE e.V. (or its successor approved
-* by the membership of KDE e.V.), which shall act as a proxy
-* defined in Section 14 of version 3 of the license.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program. If not, see <http://www.gnu.org/licenses/>.
-*
-* ============================================================ */
-
-
-// Self Includes
-#include "kcmwebkitadblock.h"
-#include "kcmwebkitadblock.moc"
-
-// KDE Includes
-#include <KDE/KPluginFactory>
-#include <KDE/KPluginLoader>
-#include <KDE/KAboutData>
-#include <KDE/KTemporaryFile>
-#include <KDE/KIO/NetAccess>
-#include <KDE/KDebug>
-
-// Qt Includes
-#include <QtCore/QTextStream>
-#include <QtGui/QWhatsThis>
-#include <QtGui/QListWidgetItem>
-
-
-K_PLUGIN_FACTORY(RekonqPluginFactory,
- registerPlugin<KCMWebkitAdblock>("webkitAdblock");
- )
-
-K_EXPORT_PLUGIN(RekonqPluginFactory("kcmrekonqfactory"))
-
-
-KCMWebkitAdblock::KCMWebkitAdblock(QWidget *parent, const QVariantList &args)
- : KCModule(KGlobal::mainComponent(), parent, args)
- , _group("adblock")
-{
- KAboutData *about = new KAboutData( I18N_NOOP("kcmrekonqfactory"), 0,
- ki18n( "rekonq Browsing Control Module" ), 0,
- KLocalizedString(), KAboutData::License_GPL,
- ki18n( "(c) 2009 Andrea Diamantini" ) );
-
- about->addAuthor( ki18n("Andrea Diamantini"), KLocalizedString(), "adjam7@gmail.com" );
- setAboutData( about );
-
- setupUi(this);
- connect(label, SIGNAL(linkActivated(const QString &)), SLOT(infoLinkActivated(const QString &)) );
- searchLine->setListWidget(listWidget);
-
- connect(addButton,SIGNAL(clicked()),this,SLOT(addExpr()));
- connect(removeButton, SIGNAL(clicked()), this, SLOT(removeSelected()));
- connect(importButton, SIGNAL(clicked()), this, SLOT(importExpr()));
-
- _config = KSharedConfig::openConfig("webkitrc", KConfig::NoGlobals);
-}
-
-
-KCMWebkitAdblock::~KCMWebkitAdblock()
-{
-}
-
-
-void KCMWebkitAdblock::defaults()
-{
- searchLine->clear();
- lineEdit->clear();
- listWidget->clear();
- groupBox->setChecked(false);
-}
-
-
-void KCMWebkitAdblock::load()
-{
- 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);
- }
-}
-
-
-void KCMWebkitAdblock::save()
-{
- KConfigGroup cg(_config, _group);
- cg.deleteGroup();
- cg = KConfigGroup(_config, _group);
-
- cg.writeEntry("Enabled", groupBox->isChecked());
-
- for(int i = 0; i < listWidget->count(); ++i )
- {
- QString key = "Filter-" + QString::number(i);
- cg.writeEntry(key, listWidget->item(i)->text());
- }
- cg.writeEntry("Count", listWidget->count());
- cg.sync();
-}
-
-
-void KCMWebkitAdblock::infoLinkActivated(const QString &url)
-{
- QString helpString = i18n("<qt><p>Enter an expression to filter. Filters can be defined as either:"
- "<ul><li>a shell-style wildcard, e.g. <tt>http://www.example.com/ads*</tt>, the wildcards <tt>*?[]</tt> may be used</li>"
- "<li>a full regular expression by surrounding the string with '<tt>/</tt>', e.g. <tt>/\\/(ad|banner)\\./</tt></li></ul>"
- "<p>Any filter string can be preceded by '<tt>@@</tt>' to whitelist (allow) any matching URL, "
- "which takes priority over any blacklist (blocking) filter.");
-
-
- if ( url == "filterhelp" )
- QWhatsThis::showText( QCursor::pos(), helpString );
-}
-
-
-void KCMWebkitAdblock::addExpr()
-{
- listWidget->addItem( lineEdit->text() );
- lineEdit->clear();
- emit changed(true);
-}
-
-
-void KCMWebkitAdblock::removeSelected()
-{
- listWidget->takeItem(listWidget->currentRow());
- searchLine->clear();
- emit changed(true);
-}
-
-
-void KCMWebkitAdblock::importExpr()
-{
-
- QString target;
- KUrl url("http://adblockplus.mozdev.org/easylist/easylist.txt");
-
- kDebug() << "downloading list..";
-
- bool success = KIO::NetAccess::download(url, target, 0);
- if(!success)
- {
- kDebug() << "not success";
- return;
- }
-
- QFile temp(target);
- if (!temp.open(QIODevice::ReadOnly | QIODevice::Text))
- {
- kDebug() << "File not open";
- return;
- }
-
- QTextStream stream(&temp);
- QString line;
- do
- {
- line = stream.readLine();
- if(!line.startsWith('!') && !line.startsWith('['))
- listWidget->addItem(line);
- }
- while (!line.isNull());
-
- KIO::NetAccess::removeTempFile(target);
- emit changed(true);
-}
diff --git a/src/adblock/kcmwebkitadblock.h b/src/adblock/kcmwebkitadblock.h
deleted file mode 100644
index 37130613..00000000
--- a/src/adblock/kcmwebkitadblock.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/* ============================================================
-*
-* This file is a part of the rekonq project
-*
-* Copyright (C) 2009 by Andrea Diamantini <adjam7 at gmail dot com>
-*
-*
-* This program is free software; you can redistribute it and/or
-* modify it under the terms of the GNU General Public License as
-* published by the Free Software Foundation; either version 2 of
-* the License or (at your option) version 3 or any later version
-* accepted by the membership of KDE e.V. (or its successor approved
-* by the membership of KDE e.V.), which shall act as a proxy
-* defined in Section 14 of version 3 of the license.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program. If not, see <http://www.gnu.org/licenses/>.
-*
-* ============================================================ */
-
-
-#ifndef KCM_WEBKIT_ADBLOCK_H
-#define KCM_WEBKIT_ADBLOCK_H
-
-
-// UI Includes
-#include "ui_webkitadblock.h"
-
-// KDE Includes
-#include <kcmodule.h>
-#include <ksharedconfig.h>
-
-
-class KCMWebkitAdblock : public KCModule, private Ui::WebkitAdblock
-{
-Q_OBJECT
-
-public:
- KCMWebkitAdblock(QWidget *parent, const QVariantList &args);
- ~KCMWebkitAdblock();
-
- void defaults();
- void load();
- void save();
-
-private slots:
- void infoLinkActivated(const QString &url);
-
- void addExpr();
- void removeSelected();
- void importExpr();
-
-private:
- KSharedConfig::Ptr _config;
- QString _group;
-};
-
-#endif
diff --git a/src/adblock/khtml_filter.cpp b/src/adblock/khtml_filter.cpp
new file mode 100644
index 00000000..f258d1e7
--- /dev/null
+++ b/src/adblock/khtml_filter.cpp
@@ -0,0 +1,266 @@
+/* This file is part of the KDE project
+
+ Copyright (C) 2005 Ivor Hewitt <ivor@kde.org>
+ Copyright (C) 2008 Maksim Orlovich <maksim@kde.org>
+ Copyright (C) 2008 Vyacheslav Tokarev <tsjoker@gmail.com>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "khtml_filter_p.h"
+#include <QDebug>
+
+// rolling hash parameters
+#define HASH_P (1997)
+#define HASH_Q (17509)
+// HASH_MOD = (HASH_P^7) % HASH_Q
+#define HASH_MOD (523)
+
+namespace khtml {
+
+void FilterSet::addFilter(const QString& filterStr)
+{
+ QString filter = filterStr;
+
+ if (filter.startsWith(QLatin1Char('!')))
+ return;
+
+ // Strip leading @@
+ int first = 0;
+ int last = filter.length() - 1;
+ if (filter.startsWith(QLatin1String("@@")))
+ first = 2;
+
+ // Strip options, we ignore them for now.
+ int dollar = filter.lastIndexOf(QLatin1Char('$'));
+ if (dollar != -1)
+ last = dollar - 1;
+
+ // Perhaps nothing left?
+ if (first > last)
+ return;
+
+ filter = filter.mid(first, last - first + 1);
+
+ // Is it a regexp filter?
+ if (filter.length()>2 && filter.startsWith(QLatin1Char('/')) && filter.endsWith(QLatin1Char('/')))
+ {
+ QString inside = filter.mid(1, filter.length()-2);
+ QRegExp rx(inside);
+ reFilters.append(rx);
+// qDebug() << "R:" << inside;
+ }
+ else
+ {
+ // Nope, a wildcard one.
+ // Note: For these, we also need to handle |.
+
+ // Strip wildcards at the ends
+ first = 0;
+ last = filter.length() - 1;
+
+ while (first < filter.length() && filter[first] == QLatin1Char('*'))
+ ++first;
+
+ while (last >= 0 && filter[last] == QLatin1Char('*'))
+ --last;
+
+ if (first > last)
+ filter = QLatin1String("*"); // erm... Well, they asked for it.
+ else
+ filter = filter.mid(first, last - first + 1);
+
+ // Now, do we still have any wildcard stuff left?
+ if (filter.contains("*") || filter.contains("?"))
+ {
+// qDebug() << "W:" << filter;
+ // check if we can use RK first (and then check full RE for the rest) for better performance
+ int aPos = filter.indexOf('*');
+ if (aPos < 0)
+ aPos = filter.length();
+ int qPos = filter.indexOf('?');
+ if (qPos < 0)
+ qPos = filter.length();
+ int pos = qMin(aPos, qPos);
+ if (pos > 7) {
+ QRegExp rx;
+
+ rx.setPatternSyntax(QRegExp::Wildcard);
+ rx.setPattern(filter.mid(pos));
+
+ stringFiltersMatcher.addWildedString(filter.mid(0, pos), rx);
+
+ } else {
+ QRegExp rx;
+
+ rx.setPatternSyntax(QRegExp::Wildcard);
+ rx.setPattern(filter);
+ reFilters.append(rx);
+ }
+ }
+ else
+ {
+ // Fast path
+ stringFiltersMatcher.addString(filter);
+ }
+ }
+}
+
+bool FilterSet::isUrlMatched(const QString& url)
+{
+ if (stringFiltersMatcher.isMatched(url))
+ return true;
+
+ for (int c = 0; c < reFilters.size(); ++c)
+ {
+ if (url.contains(reFilters[c]))
+ return true;
+ }
+
+ return false;
+}
+
+void FilterSet::clear()
+{
+ reFilters.clear();
+ stringFiltersMatcher.clear();
+}
+
+
+void StringsMatcher::addString(const QString& pattern)
+{
+ if (pattern.length() < 8) {
+ // handle short string differently
+ shortStringFilters.append(pattern);
+ } else {
+ // use modified Rabin-Karp's algorithm with 8-length string hash
+ // i.e. store hash of first 8 chars in the HashMap for fast look-up
+ stringFilters.append(pattern);
+ int ind = stringFilters.size() - 1;
+ int current = 0;
+
+ // compute hash using rolling hash
+ // hash for string: x0,x1,x2...xn-1 will be:
+ // (p^(n-1)*x0 + p^(n-2)*x1 + ... + p * xn-2 + xn-1) % q
+ // where p and q some wisely-chosen integers
+ /*for (int k = 0; k < 8; ++k)*/
+ int len = pattern.length();
+ for (int k = len - 8; k < len; ++k)
+ current = (current * HASH_P + pattern[k].unicode()) % HASH_Q;
+
+ // insert computed hash value into HashMap
+ QHash<int, QVector<int> >::iterator it = stringFiltersHash.find(current + 1);
+ if (it == stringFiltersHash.end()) {
+ QVector<int> list;
+ list.append(ind);
+ stringFiltersHash.insert(current + 1, list);
+ fastLookUp.setBit(current);
+ } else {
+ it.value().append(ind);
+ }
+ }
+}
+
+void StringsMatcher::addWildedString(const QString& prefix, const QRegExp& rx)
+{
+ rePrefixes.append(prefix);
+ reFilters.append(rx);
+ int index = -rePrefixes.size();
+
+ int current = 0;
+ for (int k = 0; k < 8; ++k)
+ current = (current * HASH_P + prefix[k].unicode()) % HASH_Q;
+
+ // insert computed hash value into HashMap
+ QHash<int, QVector<int> >::iterator it = stringFiltersHash.find(current + 1);
+ if (it == stringFiltersHash.end()) {
+ QVector<int> list;
+ list.append(index);
+ stringFiltersHash.insert(current + 1, list);
+ fastLookUp.setBit(current);
+ } else {
+ it.value().append(index);
+ }
+}
+
+bool StringsMatcher::isMatched(const QString& str) const
+{
+ // check short strings first
+ for (int i = 0; i < shortStringFilters.size(); ++i) {
+ if (str.contains(shortStringFilters[i]))
+ return true;
+ }
+
+ int len = str.length();
+ int k;
+
+ int current = 0;
+ int next = 0;
+ // compute hash for first 8 characters
+ for (k = 0; k < 8 && k < len; ++k)
+ current = (current * HASH_P + str[k].unicode()) % HASH_Q;
+
+ QHash<int, QVector<int> >::const_iterator hashEnd = stringFiltersHash.end();
+ // main Rabin-Karp's algorithm loop
+ for (k = 7; k < len; ++k, current = next) {
+ // roll the hash if not at the end
+ // (calculate hash for the next iteration)
+ if (k + 1 < len)
+ next = (HASH_P * ((current + HASH_Q - ((HASH_MOD * str[k - 7].unicode()) % HASH_Q)) % HASH_Q) + str[k + 1].unicode()) % HASH_Q;
+
+ if (!fastLookUp.testBit(current))
+ continue;
+
+ // look-up the hash in the HashMap and check all strings
+ QHash<int, QVector<int> >::const_iterator it = stringFiltersHash.find(current + 1);
+
+ // check possible strings
+ if (it != hashEnd) {
+ for (int j = 0; j < it.value().size(); ++j) {
+ int index = it.value()[j];
+ // check if we got simple string or REs prefix
+ if (index >= 0) {
+ int flen = stringFilters[index].length();
+ if (k - flen + 1 >= 0 && stringFilters[index] == str.midRef(k - flen + 1 , flen))
+ return true;
+ } else {
+ index = -index - 1;
+ int flen = rePrefixes[index].length();
+ if (k - 8 + flen < len && rePrefixes[index] == str.midRef(k - 7, flen) &&
+ str.indexOf(reFilters[index], k - 7 + flen) == k - 7 + flen)
+ return true;
+ }
+ }
+ }
+ }
+
+ return false;
+}
+
+void StringsMatcher::clear()
+{
+ stringFilters.clear();
+ shortStringFilters.clear();
+ reFilters.clear();
+ rePrefixes.clear();
+ stringFiltersHash.clear();
+ fastLookUp.resize(HASH_Q);
+ fastLookUp.fill(0, 0, HASH_Q);
+}
+
+}
+
+// kate: indent-width 4; replace-tabs on; tab-width 4; space-indent on;
diff --git a/src/adblock/khtml_filter_p.h b/src/adblock/khtml_filter_p.h
new file mode 100644
index 00000000..4490bbd8
--- /dev/null
+++ b/src/adblock/khtml_filter_p.h
@@ -0,0 +1,79 @@
+/* This file is part of the KDE project
+
+ Copyright (C) 2005 Ivor Hewitt <ivor@kde.org>
+ Copyright (C) 2008 Maksim Orlovich <maksim@kde.org>
+ Copyright (C) 2008 Vyacheslav Tokarev <tsjoker@gmail.com>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef KHTML_FILTER_P_H
+#define KHTML_FILTER_P_H
+
+#include <QString>
+#include <QRegExp>
+#include <QVector>
+#include <QHash>
+#include <QBitArray>
+
+namespace khtml {
+
+// Updateable Multi-String Matcher based on Rabin-Karp's algorithm
+class StringsMatcher {
+public:
+ // add filter to matching set
+ void addString(const QString& pattern);
+
+ // check if string match at least one string from matching set
+ bool isMatched(const QString& str) const;
+
+ // add filter to matching set with wildcards (*,?) in it
+ void addWildedString(const QString& prefix, const QRegExp& rx);
+
+ void clear();
+
+private:
+ QVector<QString> stringFilters;
+ QVector<QString> shortStringFilters;
+ QVector<QRegExp> reFilters;
+ QVector<QString> rePrefixes;
+ QBitArray fastLookUp;
+
+ QHash<int, QVector<int> > stringFiltersHash;
+};
+
+// This represents a set of filters that may match URLs.
+// Currently it supports a subset of AddBlock Plus functionality.
+class FilterSet {
+public:
+ // Parses and registers a filter. This will also strip @@ for exclusion rules, skip comments, etc.
+ // The user does have to split black and white lists into separate sets, however
+ void addFilter(const QString& filter);
+
+ bool isUrlMatched(const QString& url);
+
+ void clear();
+
+private:
+ QVector<QRegExp> reFilters;
+ StringsMatcher stringFiltersMatcher;
+};
+
+}
+
+#endif // KHTML_FILTER_P_H
+
+// kate: indent-width 4; replace-tabs on; tab-width 4; space-indent on;
diff --git a/src/adblock/webkitAdblock.desktop b/src/adblock/webkitAdblock.desktop
deleted file mode 100644
index 61fa99c0..00000000
--- a/src/adblock/webkitAdblock.desktop
+++ /dev/null
@@ -1,14 +0,0 @@
-[Desktop Entry]
-Type=Service
-X-KDE-ServiceTypes=KCModule
-
-Icon=preferences-web-browser-adblock
-Exec=kcmshell4 webkitAdblock
-
-X-KDE-Library=kcm_webkitadblock
-X-KDE-PluginKeyword=webkitAdblock
-X-KDE-ParentApp=kcontrol
-
-Name=Webkit AdBlock
-
-Categories=Qt;KDE;X-KDE-settings-webbrowsing;
diff --git a/src/adblock/webkitadblock.ui b/src/adblock/webkitadblock.ui
deleted file mode 100644
index c75c0f0f..00000000
--- a/src/adblock/webkitadblock.ui
+++ /dev/null
@@ -1,113 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>WebkitAdblock</class>
- <widget class="QWidget" name="WebkitAdblock">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>543</width>
- <height>491</height>
- </rect>
- </property>
- <property name="windowTitle">
- <string>Form</string>
- </property>
- <layout class="QVBoxLayout" name="verticalLayout_2">
- <item>
- <widget class="QGroupBox" name="groupBox">
- <property name="title">
- <string>enable adblock</string>
- </property>
- <property name="checkable">
- <bool>true</bool>
- </property>
- <property name="checked">
- <bool>true</bool>
- </property>
- <layout class="QVBoxLayout" name="verticalLayout">
- <item>
- <layout class="QHBoxLayout" name="horizontalLayout_3">
- <item>
- <widget class="QLabel" name="label_2">
- <property name="text">
- <string>Search:</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="KListWidgetSearchLine" name="searchLine">
- <property name="text">
- <string/>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- <item>
- <widget class="KListWidget" name="listWidget"/>
- </item>
- <item>
- <widget class="QLabel" name="label">
- <property name="text">
- <string>&lt;qt&gt;Filter expression (e.g. &lt;tt&gt;http://www.example.com/*&lt;/tt&gt;, &lt;a href=&quot;filterhelp&quot;&gt;more info&lt;/a&gt;):</string>
- </property>
- </widget>
- </item>
- <item>
- <layout class="QHBoxLayout" name="horizontalLayout_2">
- <item>
- <widget class="KLineEdit" name="lineEdit"/>
- </item>
- <item>
- <widget class="QPushButton" name="addButton">
- <property name="text">
- <string>Add</string>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- <item>
- <layout class="QHBoxLayout" name="horizontalLayout">
- <item>
- <widget class="QPushButton" name="removeButton">
- <property name="text">
- <string>Remove Expr</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="importButton">
- <property name="text">
- <string>Import from...</string>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- </layout>
- </widget>
- </item>
- </layout>
- </widget>
- <customwidgets>
- <customwidget>
- <class>KListWidget</class>
- <extends>QListWidget</extends>
- <header>klistwidget.h</header>
- </customwidget>
- <customwidget>
- <class>KLineEdit</class>
- <extends>QLineEdit</extends>
- <header>klineedit.h</header>
- </customwidget>
- <customwidget>
- <class>KListWidgetSearchLine</class>
- <extends>KLineEdit</extends>
- <header>klistwidgetsearchline.h</header>
- </customwidget>
- </customwidgets>
- <resources/>
- <connections/>
-</ui>
diff --git a/src/settings/settingsdialog.cpp b/src/settings/settingsdialog.cpp
index 1dde1196..ee0c1794 100644
--- a/src/settings/settingsdialog.cpp
+++ b/src/settings/settingsdialog.cpp
@@ -125,7 +125,7 @@ Private::Private(SettingsDialog *parent)
KIcon webkitIcon = KIcon(QIcon(webkitIconPath));
pageItem->setIcon(webkitIcon);
- KCModuleInfo adblockInfo("webkitAdblock.desktop");
+ KCModuleInfo adblockInfo("khtml_filter.desktop");
adblockModule = new KCModuleProxy(adblockInfo,parent);
pageItem = parent->addPage(adblockModule, i18n(adblockInfo.moduleName().toLocal8Bit()));
pageItem->setIcon(KIcon(adblockInfo.icon()));