summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/adblock/adblockrule.cpp6
-rw-r--r--src/adblock/adblockruletextmatchimpl.cpp68
-rw-r--r--src/adblock/adblockruletextmatchimpl.h47
4 files changed, 121 insertions, 1 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 8f4ac651..127c1c4f 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -54,6 +54,7 @@ SET( rekonq_KDEINIT_SRCS
adblock/adblocknetworkreply.cpp
adblock/adblockrule.cpp
adblock/adblockrulefallbackimpl.cpp
+ adblock/adblockruletextmatchimpl.cpp
#----------------------------------------
urlbar/stackedurlbar.cpp
urlbar/urlbar.cpp
diff --git a/src/adblock/adblockrule.cpp b/src/adblock/adblockrule.cpp
index 8236f920..1cb6773a 100644
--- a/src/adblock/adblockrule.cpp
+++ b/src/adblock/adblockrule.cpp
@@ -56,8 +56,12 @@
#include "adblockrule.h"
#include "adblockrulefallbackimpl.h"
+#include "adblockruletextmatchimpl.h"
AdBlockRule::AdBlockRule(const QString &filter)
{
- m_implementation = QSharedPointer<AdBlockRuleImpl>(new AdBlockRuleFallbackImpl(filter));
+ if (AdBlockRuleTextMatchImpl::isTextMatchFilter(filter))
+ m_implementation = QSharedPointer<AdBlockRuleImpl>(new AdBlockRuleTextMatchImpl(filter));
+ else
+ m_implementation = QSharedPointer<AdBlockRuleImpl>(new AdBlockRuleFallbackImpl(filter));
}
diff --git a/src/adblock/adblockruletextmatchimpl.cpp b/src/adblock/adblockruletextmatchimpl.cpp
new file mode 100644
index 00000000..7c02ea37
--- /dev/null
+++ b/src/adblock/adblockruletextmatchimpl.cpp
@@ -0,0 +1,68 @@
+/* ============================================================
+*
+* This file is a part of the rekonq project
+*
+* Copyright (C) 2010 by Benjamin Poulain <ikipou 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 "adblockruletextmatchimpl.h"
+
+// Rekonq Includes
+#include "rekonq_defines.h"
+
+AdBlockRuleTextMatchImpl::AdBlockRuleTextMatchImpl(const QString &filter)
+ : AdBlockRuleImpl(filter)
+{
+ Q_ASSERT(AdBlockRuleTextMatchImpl::isTextMatchFilter(filter));
+
+ m_textToMatch = filter;
+ m_textToMatch.remove(QL1C('*'));
+}
+
+bool AdBlockRuleTextMatchImpl::match(const QString &encodedUrl) const
+{
+ return encodedUrl.contains(m_textToMatch, Qt::CaseInsensitive);
+}
+
+bool AdBlockRuleTextMatchImpl::isTextMatchFilter(const QString &filter)
+{
+ // We don't deal with options just yet
+ if (filter.contains(QL1C('$')))
+ return false;
+
+ // We don't deal with element matching
+ if (filter.contains(QL1S("##")))
+ return false;
+
+ // We don't deal with the begin-end matching
+ if (filter.startsWith(QL1C('|')) || filter.endsWith(QL1C('|')))
+ return false;
+
+ // We only handle * at the beginning or the end
+ int starPosition = filter.indexOf(QL1C('*'));
+ while (starPosition >= 0) {
+ if (starPosition != 0 && starPosition != (filter.length() - 1))
+ return false;
+ starPosition = filter.indexOf(QL1C('*'), starPosition + 1);
+ }
+ return true;
+}
diff --git a/src/adblock/adblockruletextmatchimpl.h b/src/adblock/adblockruletextmatchimpl.h
new file mode 100644
index 00000000..f0e78be0
--- /dev/null
+++ b/src/adblock/adblockruletextmatchimpl.h
@@ -0,0 +1,47 @@
+/* ============================================================
+*
+* This file is a part of the rekonq project
+*
+* Copyright (C) 2010 by Benjamin Poulain <ikipou 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 ADBLOCKRULETEXTMATCHIMPL_H
+#define ADBLOCKRULETEXTMATCHIMPL_H
+
+#include "adblockruleimpl.h"
+
+// Qt Includes
+#include <QString>
+
+// Simple rule to find a string in the URL
+class AdBlockRuleTextMatchImpl : public AdBlockRuleImpl
+{
+public:
+ AdBlockRuleTextMatchImpl(const QString &filter);
+ bool match(const QString &encodedUrl) const;
+
+ static bool isTextMatchFilter(const QString &filter);
+
+private:
+ QString m_textToMatch;
+};
+
+#endif // ADBLOCKRULETEXTMATCHIMPL_H