From b998d27de702ddd1091db3af838f4af0439aaeee Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Sun, 29 Nov 2009 12:34:04 +0100 Subject: Restored QWebElementCollection My qt copy was too old.. --- src/clicktoflash.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/clicktoflash.cpp b/src/clicktoflash.cpp index e3e90996..4ec1a9c1 100644 --- a/src/clicktoflash.cpp +++ b/src/clicktoflash.cpp @@ -105,7 +105,7 @@ void ClickToFlash::load() QWebFrame *frame = frames.takeFirst(); QWebElement docElement = frame->documentElement(); - QList elements; + QWebElementCollection elements; elements.append(docElement.findAll(selector.arg(QLatin1String("object")))); elements.append(docElement.findAll(selector.arg(QLatin1String("embed")))); @@ -119,7 +119,7 @@ void ClickToFlash::load() isRightElement = true; else { - QList collec = element.findAll("param"); + QWebElementCollection collec = element.findAll("param"); int i = 0; while(i < collec.count() && isRightElement == false) { -- cgit v1.2.1 From 88bde6fd1e73f30a9bdb1da5fd4bd24aeb84266b Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Mon, 30 Nov 2009 10:26:43 +0100 Subject: Porting rekonq to last Qt/KDE API adblock (KDE one) fix #1 --- src/CMakeLists.txt | 3 + src/adblock/adblockmanager.cpp | 45 +++++- src/adblock/adblockmanager.h | 11 +- src/adblock/adblocknetworkreply.cpp | 88 ++++++++++++ src/adblock/adblocknetworkreply.h | 81 +++++++++++ src/adblock/khtml_filter.cpp | 266 ++++++++++++++++++++++++++++++++++++ src/adblock/khtml_filter_p.h | 79 +++++++++++ src/networkaccessmanager.cpp | 56 ++++++++ src/networkaccessmanager.h | 49 +++++++ src/webpage.cpp | 9 +- src/webpage.h | 2 +- 11 files changed, 681 insertions(+), 8 deletions(-) create mode 100644 src/adblock/adblocknetworkreply.cpp create mode 100644 src/adblock/adblocknetworkreply.h create mode 100644 src/adblock/khtml_filter.cpp create mode 100644 src/adblock/khtml_filter_p.h create mode 100644 src/networkaccessmanager.cpp create mode 100644 src/networkaccessmanager.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1f9127f4..0233e2d6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -19,6 +19,7 @@ SET( rekonq_KDEINIT_SRCS websnap.cpp webview.cpp clicktoflash.cpp + networkaccessmanager.cpp #---------------------------------------- history/autosaver.cpp history/historymanager.cpp @@ -36,6 +37,8 @@ SET( rekonq_KDEINIT_SRCS bookmarks/bookmarksproxy.cpp #---------------------------------------- adblock/adblockmanager.cpp + adblock/adblocknetworkreply.cpp + adblock/khtml_filter.cpp #---------------------------------------- urlbar/urlbar.cpp urlbar/lineedit.cpp diff --git a/src/adblock/adblockmanager.cpp b/src/adblock/adblockmanager.cpp index b25edcb1..987c793f 100644 --- a/src/adblock/adblockmanager.cpp +++ b/src/adblock/adblockmanager.cpp @@ -24,9 +24,12 @@ * ============================================================ */ +// Self Includes #include "adblockmanager.h" #include "adblockmanager.moc" +// Local Includes +#include "adblocknetworkreply.h" // KDE Includes #include @@ -53,10 +56,48 @@ AdBlockManager::~AdBlockManager() void AdBlockManager::loadSettings() { + KSharedConfig::Ptr config = KSharedConfig::openConfig("khtmlrc", KConfig::NoGlobals); + KConfigGroup cg( config, "Filter Settings" ); + + if ( cg.exists() ) + { + _isAdblockEnabled = cg.readEntry("Enabled", false); + _isHideAdsEnabled = cg.readEntry("Shrink", false); + + _adBlackList.clear(); + _adWhiteList.clear(); + + QMap entryMap = cg.entryMap(); + QMap::ConstIterator it; + for( it = entryMap.constBegin(); it != entryMap.constEnd(); ++it ) + { + QString name = it.key(); + QString url = it.value(); + + if (name.startsWith(QLatin1String("Filter"))) + { + if (url.startsWith(QLatin1String("@@"))) + _adWhiteList.addFilter(url); + else + _adBlackList.addFilter(url); + } + } + } } -bool AdBlockManager::isUrlAllowed(const QUrl &url) +QNetworkReply *AdBlockManager::block(const QNetworkRequest &request) { - return true; + if (!_isAdblockEnabled) + return 0; + + QString urlString = request.url().toString(); + + // Check the blacklist, and only if that matches, the whitelist + if(_adBlackList.isUrlMatched(urlString) && !_adWhiteList.isUrlMatched(urlString)) + { + AdBlockNetworkReply *reply = new AdBlockNetworkReply(request, urlString, this); + return reply; + } + return 0; } diff --git a/src/adblock/adblockmanager.h b/src/adblock/adblockmanager.h index 10f72366..5b47c1da 100644 --- a/src/adblock/adblockmanager.h +++ b/src/adblock/adblockmanager.h @@ -29,12 +29,16 @@ #define ADBLOCK_MANAGER_H +// Local Includes +#include "khtml_filter_p.h" + // Qt Includes #include #include +#include // Forward Includes -class QUrl; +class QNetworkRequest; class AdBlockManager : public QObject @@ -46,11 +50,14 @@ public: ~AdBlockManager(); void loadSettings(); - bool isUrlAllowed(const QUrl &url); + QNetworkReply *block(const QNetworkRequest &request); private: bool _isAdblockEnabled; bool _isHideAdsEnabled; + + khtml::FilterSet _adBlackList; + khtml::FilterSet _adWhiteList; }; #endif diff --git a/src/adblock/adblocknetworkreply.cpp b/src/adblock/adblocknetworkreply.cpp new file mode 100644 index 00000000..1ccca96d --- /dev/null +++ b/src/adblock/adblocknetworkreply.cpp @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2009, Benjamin C. Meyer + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Benjamin Meyer nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ============================================================ + * + * This file is a part of the rekonq project + * + * Copyright (C) 2009 by Andrea Diamantini + * + * + * 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 . + * + * ============================================================ */ + + +// Self Includes +#include "adblocknetworkreply.h" +#include "adblocknetworkreply.moc" + +// KDE Includes +#include + +// Qt Includes +#include +#include + + +AdBlockNetworkReply::AdBlockNetworkReply(const QNetworkRequest &request, const QString &urlString, QObject *parent) + : QNetworkReply(parent) +{ + setOperation(QNetworkAccessManager::GetOperation); + setRequest(request); + setUrl(request.url()); + setError(QNetworkReply::ContentAccessDenied, i18n("Blocked by AdBlockRule: %1").arg(urlString)); + QTimer::singleShot(0, this, SLOT(delayedFinished())); +} + + +qint64 AdBlockNetworkReply::readData(char *data, qint64 maxSize) +{ + Q_UNUSED(data); + Q_UNUSED(maxSize); + return -1; +} + + +void AdBlockNetworkReply::delayedFinished() +{ + emit error(QNetworkReply::ContentAccessDenied); + emit finished(); +} diff --git a/src/adblock/adblocknetworkreply.h b/src/adblock/adblocknetworkreply.h new file mode 100644 index 00000000..b5bb8300 --- /dev/null +++ b/src/adblock/adblocknetworkreply.h @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2009, Benjamin C. Meyer + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Benjamin Meyer nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ============================================================ + * + * This file is a part of the rekonq project + * + * Copyright (C) 2009 by Andrea Diamantini + * + * + * 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 . + * + * ============================================================ */ + + +#ifndef ADBLOCK_NETWORK_REPLY_H +#define ADBLOCK_NETWORK_REPLY_H + + +// Qt Includes +#include +#include + +// Forward Declarations +class AdBlockRule; + + +class AdBlockNetworkReply : public QNetworkReply +{ + Q_OBJECT + +public: + AdBlockNetworkReply(const QNetworkRequest &request, const QString &urlString, QObject *parent = 0); + void abort() {}; + +protected: + qint64 readData(char *data, qint64 maxSize); + +private slots: + void delayedFinished(); + +}; + +#endif // ADBLOCKBLOCKEDNETWORKREPLY_H 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 + Copyright (C) 2008 Maksim Orlovich + Copyright (C) 2008 Vyacheslav Tokarev + + 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 + +// 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 >::iterator it = stringFiltersHash.find(current + 1); + if (it == stringFiltersHash.end()) { + QVector 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 >::iterator it = stringFiltersHash.find(current + 1); + if (it == stringFiltersHash.end()) { + QVector 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 >::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 >::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 + Copyright (C) 2008 Maksim Orlovich + Copyright (C) 2008 Vyacheslav Tokarev + + 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 +#include +#include +#include +#include + +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 stringFilters; + QVector shortStringFilters; + QVector reFilters; + QVector rePrefixes; + QBitArray fastLookUp; + + QHash > 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 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/networkaccessmanager.cpp b/src/networkaccessmanager.cpp new file mode 100644 index 00000000..a2c1fdee --- /dev/null +++ b/src/networkaccessmanager.cpp @@ -0,0 +1,56 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2007-2008 Trolltech ASA. All rights reserved +* Copyright (C) 2008-2009 by Andrea Diamantini * +* +* 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 . +* +* ============================================================ */ + + +// Self Includes +#include "networkaccessmanager.h" +#include "networkaccessmanager.moc" + +// Local Includes +#include "application.h" +#include "adblockmanager.h" + + +NetworkAccessManager::NetworkAccessManager(QObject *parent) + : AccessManager(parent) +{ +} + + +QNetworkReply *NetworkAccessManager::createRequest(Operation op, const QNetworkRequest &req, QIODevice *outgoingData) +{ + QNetworkRequest request(req); + request.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true); + + // Adblock + if (op == QNetworkAccessManager::GetOperation) + { + QNetworkReply *reply = Application::adblockManager()->block(request); + if (reply) + return reply; + } + + return AccessManager::createRequest(op,request,outgoingData); +} diff --git a/src/networkaccessmanager.h b/src/networkaccessmanager.h new file mode 100644 index 00000000..5c34ebd7 --- /dev/null +++ b/src/networkaccessmanager.h @@ -0,0 +1,49 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2007-2008 Trolltech ASA. All rights reserved +* Copyright (C) 2008-2009 by Andrea Diamantini * +* +* 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 . +* +* ============================================================ */ + + +#ifndef NETWORKACCESSMANAGER_H +#define NETWORKACCESSMANAGER_H + + +// KDE Includes +#include + + +using namespace KIO::Integration; + + +class NetworkAccessManager : public AccessManager +{ + Q_OBJECT + +public: + NetworkAccessManager(QObject *parent = 0); + +protected: + virtual QNetworkReply *createRequest(Operation op, const QNetworkRequest &req, QIODevice *outgoingData = 0); +}; + +#endif // NETWORKACCESSMANAGER_H diff --git a/src/webpage.cpp b/src/webpage.cpp index edb7902f..0f214b6d 100644 --- a/src/webpage.cpp +++ b/src/webpage.cpp @@ -41,6 +41,7 @@ #include "mainview.h" #include "webview.h" #include "webpluginfactory.h" +#include "networkaccessmanager.h" // KDE Includes #include @@ -65,14 +66,16 @@ #include -WebPage::WebPage(QObject *parent, qlonglong windowId) - : KWebPage(parent, windowId) +WebPage::WebPage(QObject *parent) + : KWebPage(parent, KWalletIntegration) , m_keyboardModifiers(Qt::NoModifier) , m_pressedButtons(Qt::NoButton) { + // rekonq own classes integration + setNetworkAccessManager(new NetworkAccessManager(this)); setPluginFactory(new WebPluginFactory(this)); - setForwardUnsupportedContent(true); +// FIXME setForwardUnsupportedContent(true); connect(networkAccessManager(), SIGNAL(finished(QNetworkReply*)), this, SLOT(manageNetworkErrors(QNetworkReply*))); diff --git a/src/webpage.h b/src/webpage.h index bb2c8cff..824736c1 100644 --- a/src/webpage.h +++ b/src/webpage.h @@ -48,7 +48,7 @@ class WebPage : public KWebPage Q_OBJECT public: - explicit WebPage(QObject *parent = 0, qlonglong windowId = 0); + explicit WebPage(QObject *parent = 0); ~WebPage(); public slots: -- cgit v1.2.1 From 78da6efbf8a6694cd1f1c11af404b21941099f95 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Mon, 30 Nov 2009 14:57:09 +0100 Subject: We have adblock! (and it works) I had a lot of problems implementing it because I started working on assuming 2 things: 1) konqueror implementation works (it's not true, I found a bug! To guess what, try loading current rekonq vs current konqueror against kde-apps.org) 2) Arora's implementation can be easily ported to kcm technology. Another wrong assumption, based on MVP implementation. Sorry for spamming master branch, guys. --- src/CMakeLists.txt | 2 +- src/adblock/adblockmanager.cpp | 45 +++++-- src/adblock/adblockmanager.h | 6 +- src/adblock/adblockrule.cpp | 173 +++++++++++++++++++++++++++ src/adblock/adblockrule.h | 82 +++++++++++++ src/adblock/khtml_filter.cpp | 266 ----------------------------------------- src/adblock/khtml_filter_p.h | 79 ------------ src/webpage.cpp | 2 +- 8 files changed, 291 insertions(+), 364 deletions(-) create mode 100644 src/adblock/adblockrule.cpp create mode 100644 src/adblock/adblockrule.h delete mode 100644 src/adblock/khtml_filter.cpp delete mode 100644 src/adblock/khtml_filter_p.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0233e2d6..1c452aeb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -38,7 +38,7 @@ SET( rekonq_KDEINIT_SRCS #---------------------------------------- adblock/adblockmanager.cpp adblock/adblocknetworkreply.cpp - adblock/khtml_filter.cpp + adblock/adblockrule.cpp #---------------------------------------- urlbar/urlbar.cpp urlbar/lineedit.cpp diff --git a/src/adblock/adblockmanager.cpp b/src/adblock/adblockmanager.cpp index 987c793f..4f4cff51 100644 --- a/src/adblock/adblockmanager.cpp +++ b/src/adblock/adblockmanager.cpp @@ -30,6 +30,7 @@ // Local Includes #include "adblocknetworkreply.h" +#include "adblockrule.h" // KDE Includes #include @@ -64,9 +65,8 @@ void AdBlockManager::loadSettings() _isAdblockEnabled = cg.readEntry("Enabled", false); _isHideAdsEnabled = cg.readEntry("Shrink", false); - _adBlackList.clear(); - _adWhiteList.clear(); - + filterList.clear(); + QMap entryMap = cg.entryMap(); QMap::ConstIterator it; for( it = entryMap.constBegin(); it != entryMap.constEnd(); ++it ) @@ -76,10 +76,7 @@ void AdBlockManager::loadSettings() if (name.startsWith(QLatin1String("Filter"))) { - if (url.startsWith(QLatin1String("@@"))) - _adWhiteList.addFilter(url); - else - _adBlackList.addFilter(url); + filterList << url; } } } @@ -91,13 +88,37 @@ QNetworkReply *AdBlockManager::block(const QNetworkRequest &request) if (!_isAdblockEnabled) return 0; - QString urlString = request.url().toString(); + // we (ad)block just http traffic + if(request.url().scheme() != QLatin1String("http")) + return 0; - // Check the blacklist, and only if that matches, the whitelist - if(_adBlackList.isUrlMatched(urlString) && !_adWhiteList.isUrlMatched(urlString)) + QString urlString = request.url().toString(); + kDebug() << "****************************** ADBLOCK: Matching url: "<< urlString; + + foreach(const QString &filter, filterList) { - AdBlockNetworkReply *reply = new AdBlockNetworkReply(request, urlString, this); - return reply; + AdBlockRule rule(filter); + if(rule.match(urlString)) + { + kDebug() << "****ADBLOCK: Matched: **************************"; + AdBlockNetworkReply *reply = new AdBlockNetworkReply(request, urlString, this); + return reply; + } } + + + + // Check the blacklist, and only if that matches, the whitelist + + + + + +// if(_adBlackList.isUrlMatched(urlString) && !_adWhiteList.isUrlMatched(urlString)) +// { +// kDebug() << "****ADBLOCK: Matched: **************************"; +// AdBlockNetworkReply *reply = new AdBlockNetworkReply(request, urlString, this); +// return reply; +// } return 0; } diff --git a/src/adblock/adblockmanager.h b/src/adblock/adblockmanager.h index 5b47c1da..32f123fd 100644 --- a/src/adblock/adblockmanager.h +++ b/src/adblock/adblockmanager.h @@ -29,9 +29,6 @@ #define ADBLOCK_MANAGER_H -// Local Includes -#include "khtml_filter_p.h" - // Qt Includes #include #include @@ -56,8 +53,7 @@ private: bool _isAdblockEnabled; bool _isHideAdsEnabled; - khtml::FilterSet _adBlackList; - khtml::FilterSet _adWhiteList; + QStringList filterList; }; #endif diff --git a/src/adblock/adblockrule.cpp b/src/adblock/adblockrule.cpp new file mode 100644 index 00000000..870ad825 --- /dev/null +++ b/src/adblock/adblockrule.cpp @@ -0,0 +1,173 @@ +/* + * Copyright (c) 2009, Zsombor Gegesy + * Copyright (c) 2009, Benjamin C. Meyer + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Benjamin Meyer nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * ============================================================ + * + * This file is a part of the rekonq project + * + * Copyright (C) 2009 by Andrea Diamantini + * + * + * 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 . + * + * ============================================================ */ + + +#include "adblockrule.h" + +#include +#include +#include + + +AdBlockRule::AdBlockRule(const QString &filter) + : m_cssRule(false) + , m_exceptionRule(false) + , m_enabledRule(true) +{ + bool isRegExpRule = false; + + if (filter.startsWith(QLatin1String("!")) || filter.trimmed().isEmpty()) + m_enabledRule = false; + + if (filter.contains(QLatin1String("##"))) + m_cssRule = true; + + QString parsedLine = filter; + if (parsedLine.startsWith(QLatin1String("@@"))) + { + m_exceptionRule = true; + parsedLine = parsedLine.mid(2); + } + + if (parsedLine.startsWith(QLatin1Char('/'))) + { + if (parsedLine.endsWith(QLatin1Char('/'))) + { + parsedLine = parsedLine.mid(1); + parsedLine = parsedLine.left(parsedLine.size() - 1); + isRegExpRule = true; + } + } + + int options = parsedLine.indexOf(QLatin1String("$"), 0); + if (options >= 0) + { + m_options = parsedLine.mid(options + 1).split(QLatin1Char(',')); + parsedLine = parsedLine.left(options); + } + + if(!isRegExpRule) + parsedLine = convertPatternToRegExp(parsedLine); + m_regExp = QRegExp(parsedLine, Qt::CaseInsensitive, QRegExp::RegExp2); + + if (m_options.contains(QLatin1String("match-case"))) + { + m_regExp.setCaseSensitivity(Qt::CaseSensitive); + m_options.removeOne(QLatin1String("match-case")); + } +} + + +// here return false means that rule doesn't match, +// so that url is allowed +// return true means "matched rule", so stop url! +bool AdBlockRule::match(const QString &encodedUrl) const +{ + if (m_cssRule) + return false; + + if (!m_enabledRule) + return false; + + bool matched = m_regExp.indexIn(encodedUrl) != -1; + + if (matched && !m_options.isEmpty()) + { + // we only support domain right now + if (m_options.count() == 1) + { + foreach (const QString &option, m_options) + { + if (option.startsWith(QLatin1String("domain="))) + { + QUrl url = QUrl::fromEncoded(encodedUrl.toUtf8()); + QString host = url.host(); + QStringList domainOptions = option.mid(7).split(QLatin1Char('|')); + foreach (QString domainOption, domainOptions) + { + bool negate = domainOption.at(0) == QLatin1Char('~'); + if (negate) + domainOption = domainOption.mid(1); + bool hostMatched = domainOption == host; + if (hostMatched && !negate) + return true; + if (!hostMatched && negate) + return true; + } + } + } + } + return false; + } + + return matched; +} + + +QString AdBlockRule::convertPatternToRegExp(const QString &wildcardPattern) +{ + QString pattern = wildcardPattern; + return pattern.replace(QRegExp(QLatin1String("\\*+")), QLatin1String("*")) // remove multiple wildcards + .replace(QRegExp(QLatin1String("\\^\\|$")), QLatin1String("^")) // remove anchors following separator placeholder + .replace(QRegExp(QLatin1String("^(\\*)")), QLatin1String("")) // remove leading wildcards + .replace(QRegExp(QLatin1String("(\\*)$")), QLatin1String("")) // remove trailing wildcards + .replace(QRegExp(QLatin1String("(\\W)")), QLatin1String("\\\\1")) // escape special symbols + .replace(QRegExp(QLatin1String("^\\\\\\|\\\\\\|")), + QLatin1String("^[\\w\\-]+:\\/+(?!\\/)(?:[^\\/]+\\.)?")) // process extended anchor at expression start + .replace(QRegExp(QLatin1String("\\\\\\^")), + QLatin1String("(?:[^\\w\\d\\-.%]|$)")) // process separator placeholders + .replace(QRegExp(QLatin1String("^\\\\\\|")), QLatin1String("^")) // process anchor at expression start + .replace(QRegExp(QLatin1String("\\\\\\|$")), QLatin1String("$")) // process anchor at expression end + .replace(QRegExp(QLatin1String("\\\\\\*")), QLatin1String(".*")) // replace wildcards by .* + ; +} diff --git a/src/adblock/adblockrule.h b/src/adblock/adblockrule.h new file mode 100644 index 00000000..3f1bd8bf --- /dev/null +++ b/src/adblock/adblockrule.h @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2009, Benjamin C. Meyer + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Benjamin Meyer nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * ============================================================ + * + * This file is a part of the rekonq project + * + * Copyright (C) 2009 by Andrea Diamantini + * + * + * 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 . + * + * ============================================================ */ + + +#ifndef ADBLOCKRULE_H +#define ADBLOCKRULE_H + +// Qt Includes +#include + +// Forward Includes +class QUrl; +class QRegExp; + + +class AdBlockRule +{ +public: + AdBlockRule(const QString &filter); + + bool match(const QString &encodedUrl) const; + +private: + QString convertPatternToRegExp(const QString &wildcardPattern); + + bool m_cssRule; + bool m_exceptionRule; + bool m_enabledRule; + QRegExp m_regExp; + QStringList m_options; +}; + +#endif // ADBLOCKRULE_H diff --git a/src/adblock/khtml_filter.cpp b/src/adblock/khtml_filter.cpp deleted file mode 100644 index f258d1e7..00000000 --- a/src/adblock/khtml_filter.cpp +++ /dev/null @@ -1,266 +0,0 @@ -/* This file is part of the KDE project - - Copyright (C) 2005 Ivor Hewitt - Copyright (C) 2008 Maksim Orlovich - Copyright (C) 2008 Vyacheslav Tokarev - - 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 - -// 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 >::iterator it = stringFiltersHash.find(current + 1); - if (it == stringFiltersHash.end()) { - QVector 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 >::iterator it = stringFiltersHash.find(current + 1); - if (it == stringFiltersHash.end()) { - QVector 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 >::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 >::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 deleted file mode 100644 index 4490bbd8..00000000 --- a/src/adblock/khtml_filter_p.h +++ /dev/null @@ -1,79 +0,0 @@ -/* This file is part of the KDE project - - Copyright (C) 2005 Ivor Hewitt - Copyright (C) 2008 Maksim Orlovich - Copyright (C) 2008 Vyacheslav Tokarev - - 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 -#include -#include -#include -#include - -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 stringFilters; - QVector shortStringFilters; - QVector reFilters; - QVector rePrefixes; - QBitArray fastLookUp; - - QHash > 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 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/webpage.cpp b/src/webpage.cpp index 0f214b6d..89579c88 100644 --- a/src/webpage.cpp +++ b/src/webpage.cpp @@ -75,7 +75,7 @@ WebPage::WebPage(QObject *parent) setNetworkAccessManager(new NetworkAccessManager(this)); setPluginFactory(new WebPluginFactory(this)); -// FIXME setForwardUnsupportedContent(true); + setForwardUnsupportedContent(true); connect(networkAccessManager(), SIGNAL(finished(QNetworkReply*)), this, SLOT(manageNetworkErrors(QNetworkReply*))); -- cgit v1.2.1 From 9a25b11cc97f453b4c82d68c76a8c4026fd62b21 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Wed, 2 Dec 2009 11:42:10 +0100 Subject: trade-off: speed vs mem saving. This time I decided for speed.. --- src/adblock/adblockmanager.cpp | 24 ++++-------------------- src/adblock/adblockmanager.h | 6 ++++-- src/adblock/adblockrule.h | 1 + 3 files changed, 9 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/adblock/adblockmanager.cpp b/src/adblock/adblockmanager.cpp index 4f4cff51..bfdbd5ad 100644 --- a/src/adblock/adblockmanager.cpp +++ b/src/adblock/adblockmanager.cpp @@ -30,7 +30,6 @@ // Local Includes #include "adblocknetworkreply.h" -#include "adblockrule.h" // KDE Includes #include @@ -76,7 +75,8 @@ void AdBlockManager::loadSettings() if (name.startsWith(QLatin1String("Filter"))) { - filterList << url; + AdBlockRule filter(url); + filterList << filter; } } } @@ -95,30 +95,14 @@ QNetworkReply *AdBlockManager::block(const QNetworkRequest &request) QString urlString = request.url().toString(); kDebug() << "****************************** ADBLOCK: Matching url: "<< urlString; - foreach(const QString &filter, filterList) + foreach(const AdBlockRule &filter, filterList) { - AdBlockRule rule(filter); - if(rule.match(urlString)) + if(filter.match(urlString)) { kDebug() << "****ADBLOCK: Matched: **************************"; AdBlockNetworkReply *reply = new AdBlockNetworkReply(request, urlString, this); return reply; } } - - - - // Check the blacklist, and only if that matches, the whitelist - - - - - -// if(_adBlackList.isUrlMatched(urlString) && !_adWhiteList.isUrlMatched(urlString)) -// { -// kDebug() << "****ADBLOCK: Matched: **************************"; -// AdBlockNetworkReply *reply = new AdBlockNetworkReply(request, urlString, this); -// return reply; -// } return 0; } diff --git a/src/adblock/adblockmanager.h b/src/adblock/adblockmanager.h index 32f123fd..499a0cde 100644 --- a/src/adblock/adblockmanager.h +++ b/src/adblock/adblockmanager.h @@ -28,10 +28,12 @@ #ifndef ADBLOCK_MANAGER_H #define ADBLOCK_MANAGER_H +// Local Includes +#include "adblockrule.h" +typedef QList AdBlockRuleList; // Qt Includes #include -#include #include // Forward Includes @@ -53,7 +55,7 @@ private: bool _isAdblockEnabled; bool _isHideAdsEnabled; - QStringList filterList; + AdBlockRuleList filterList; }; #endif diff --git a/src/adblock/adblockrule.h b/src/adblock/adblockrule.h index 3f1bd8bf..8680942f 100644 --- a/src/adblock/adblockrule.h +++ b/src/adblock/adblockrule.h @@ -79,4 +79,5 @@ private: QStringList m_options; }; + #endif // ADBLOCKRULE_H -- cgit v1.2.1 From b679535011c98e17c97c06c7079efb53f6d89769 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Wed, 2 Dec 2009 12:28:39 +0100 Subject: push startup on disabled adblock (don't load filters) --- src/adblock/adblockmanager.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/adblock/adblockmanager.cpp b/src/adblock/adblockmanager.cpp index bfdbd5ad..209c2ab0 100644 --- a/src/adblock/adblockmanager.cpp +++ b/src/adblock/adblockmanager.cpp @@ -66,6 +66,10 @@ void AdBlockManager::loadSettings() filterList.clear(); + // no need to load filters if adblock is not enabled :) + if(!_isAdblockEnabled) + return; + QMap entryMap = cg.entryMap(); QMap::ConstIterator it; for( it = entryMap.constBegin(); it != entryMap.constEnd(); ++it ) @@ -93,13 +97,12 @@ QNetworkReply *AdBlockManager::block(const QNetworkRequest &request) return 0; QString urlString = request.url().toString(); - kDebug() << "****************************** ADBLOCK: Matching url: "<< urlString; foreach(const AdBlockRule &filter, filterList) { if(filter.match(urlString)) { - kDebug() << "****ADBLOCK: Matched: **************************"; + kDebug() << "****ADBLOCK: Matched: ***********" << urlString; AdBlockNetworkReply *reply = new AdBlockNetworkReply(request, urlString, this); return reply; } -- cgit v1.2.1 From 2e96585d9a36d95a5dd33859365b6047a133a051 Mon Sep 17 00:00:00 2001 From: matgic78 Date: Wed, 2 Dec 2009 18:01:30 +0100 Subject: Docked web inspector --- src/CMakeLists.txt | 2 ++ src/mainwindow.cpp | 47 +++++++++++++-------------- src/mainwindow.h | 14 +++++---- src/webinspectordock.cpp | 82 ++++++++++++++++++++++++++++++++++++++++++++++++ src/webinspectordock.h | 59 ++++++++++++++++++++++++++++++++++ 5 files changed, 172 insertions(+), 32 deletions(-) create mode 100644 src/webinspectordock.cpp create mode 100644 src/webinspectordock.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 23d5595e..78ca3106 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -39,6 +39,8 @@ SET( rekonq_KDEINIT_SRCS #---------------------------------------- urlbar/urlbar.cpp urlbar/lineedit.cpp +#---------------------------------------- + webinspectordock.cpp ) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 628743ee..fc005014 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -42,6 +42,7 @@ #include "findbar.h" #include "sidepanel.h" #include "bookmarkspanel.h" +#include "webinspectordock.h" #include "urlbar.h" #include "tabbar.h" #include "newtabpage.h" @@ -99,7 +100,8 @@ MainWindow::MainWindow() , m_view(new MainView(this)) , m_findBar(new FindBar(this)) , m_sidePanel(0) - , m_bookmarksPanel(0) + , m_bookmarksPanel(0) + , m_webInspectorDock(0) , m_historyBackMenu(0) , m_mainBar( new KToolBar( QString("MainToolBar"), this, Qt::TopToolBarArea, true, false, false) ) , m_bmBar( new KToolBar( QString("BookmarkToolBar"), this, Qt::TopToolBarArea, true, false, false) ) @@ -136,7 +138,8 @@ MainWindow::MainWindow() // setting Side Panel setupSidePanel(); - setupBookmarksPanel(); + setupBookmarksPanel(); + setupWebInspector(); // setting up rekonq tools setupTools(); @@ -336,11 +339,6 @@ void MainWindow::setupActions() actionCollection()->addAction(QLatin1String("page_source"), a); connect(a, SIGNAL(triggered(bool)), this, SLOT(viewPageSource())); - a = new KAction(KIcon("tools-report-bug"), i18n("Web &Inspector"), this); - a->setCheckable(true); - actionCollection()->addAction(QLatin1String("web_inspector"), a); - connect(a, SIGNAL(triggered(bool)), this, SLOT(toggleInspector(bool))); - a = new KAction(KIcon("view-media-artist"), i18n("Private &Browsing"), this); a->setCheckable(true); actionCollection()->addAction(QLatin1String("private_browsing"), a); @@ -490,6 +488,22 @@ void MainWindow::setupBookmarksPanel() } +void MainWindow::setupWebInspector() +{ + m_webInspectorDock = new WebInspectorDock(i18n("Web Inspector"), this); + connect(mainView(), SIGNAL(currentChanged(int)), m_webInspectorDock, SLOT(changeCurrentPage())); + + KAction *a = new KAction(KIcon("tools-report-bug"), i18n("Web &Inspector"), this); + a->setCheckable(true); + actionCollection()->addAction(QLatin1String("web_inspector"), a); + connect(a, SIGNAL(triggered(bool)), m_webInspectorDock, SLOT(toggle(bool))); + + addDockWidget(Qt::BottomDockWidgetArea, m_webInspectorDock); + m_webInspectorDock->hide(); +} + + + void MainWindow::updateConfiguration() { // ============== General ================== @@ -843,25 +857,6 @@ void MainWindow::homePage() } -void MainWindow::toggleInspector(bool enable) -{ - QWebSettings::globalSettings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, enable); - if (enable) - { - int result = KMessageBox::questionYesNo(this, - i18n("The web inspector will only work correctly for pages that were loaded after enabling.\n" \ - "Do you want to reload all pages?"), - i18n("Web Inspector") - ); - - if (result == KMessageBox::Yes) - { - m_view->reloadAllTabs(); - } - } -} - - MainView *MainWindow::mainView() const { return m_view; diff --git a/src/mainwindow.h b/src/mainwindow.h index d47b0d50..f141c5a2 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -48,6 +48,7 @@ class KPassivePopup; class FindBar; class SidePanel; class BookmarksPanel; +class WebInspectorDock; class WebView; class MainView; @@ -81,8 +82,10 @@ private: void setupSidePanel(); SidePanel *sidePanel(); - void setupBookmarksPanel(); - BookmarksPanel *bookmarksPanel(); + void setupBookmarksPanel(); + BookmarksPanel *bookmarksPanel(); + + void setupWebInspector(); public slots: void updateBrowser(); @@ -99,8 +102,7 @@ public slots: void notifyMessage(const QString &msg, Rekonq::Notify status = Rekonq::Info); void printRequested(QWebFrame *frame = 0); - - + signals: // switching tabs void ctrlTabPressed(); @@ -146,7 +148,6 @@ private slots: void viewFullScreen(bool enable); // Tools Menu slots - void toggleInspector(bool enable); void privateBrowsing(bool enable); // Settings Menu slot @@ -162,7 +163,8 @@ private: MainView *m_view; FindBar *m_findBar; SidePanel *m_sidePanel; - BookmarksPanel *m_bookmarksPanel; + BookmarksPanel *m_bookmarksPanel; + WebInspectorDock *m_webInspectorDock; KAction *m_stopReloadAction; KMenu *m_historyBackMenu; diff --git a/src/webinspectordock.cpp b/src/webinspectordock.cpp new file mode 100644 index 00000000..ada3af3f --- /dev/null +++ b/src/webinspectordock.cpp @@ -0,0 +1,82 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009 by Nils Weigel +* +* +* 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 . +* +* ============================================================ */ + +// Self Includes +#include "webinspectordock.h" + +// Local Includes +#include "webview.h" +#include "webpage.h" + +// Qt Includes +#include + +// KDE Includes +#include "KAction" +#include "KDebug" + + +WebInspectorDock::WebInspectorDock(QString title, QWidget *parent) + : QDockWidget(title, parent) +{ + setObjectName("webInspectorDock"); + QWebInspector *inspector = new QWebInspector(this); + setWidget(inspector); +} + +void WebInspectorDock::closeEvent(QCloseEvent *event) +{ + Q_UNUSED(event); + toggle(false); +} + +MainWindow* WebInspectorDock::mainWindow() +{ + return qobject_cast< MainWindow* >(parentWidget()); +} + + +void WebInspectorDock::toggle(bool enable) +{ + mainWindow()->actionByName("web_inspector")->setChecked(enable); + if (enable) + { + mainWindow()->currentTab()->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true); + findChild()->setPage(mainWindow()->currentTab()->page()); + show(); + } + else + { + hide(); + mainWindow()->currentTab()->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, false); + } +} + + +void WebInspectorDock::changeCurrentPage() +{ + bool enable = mainWindow()->currentTab()->settings()->testAttribute(QWebSettings::DeveloperExtrasEnabled); + toggle(enable); +} diff --git a/src/webinspectordock.h b/src/webinspectordock.h new file mode 100644 index 00000000..b8ffa6c3 --- /dev/null +++ b/src/webinspectordock.h @@ -0,0 +1,59 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2008-2009 by Andrea Diamantini +* Copyright (C) 2009 by Lionel Chauvin +* +* +* 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 . +* +* ============================================================ */ + + +#ifndef WEBINSPECTORDOCK_H +#define WEBINSPECTORDOCK_H + + +// Local Includes +#include "mainwindow.h" + +// Qt Includes +#include + +/** + Docked web inspector + behaviour : hide/show by tab, not globally +*/ +class WebInspectorDock : public QDockWidget +{ + Q_OBJECT +public: + WebInspectorDock(QString title, QWidget *parent); + +public slots: + void toggle(bool enable); + void changeCurrentPage(); + +protected: + virtual void closeEvent(QCloseEvent *event); + + MainWindow *mainWindow(); + +}; + +#endif \ No newline at end of file -- cgit v1.2.1 From e466ef7f85267a843f7273351222389a6e498621 Mon Sep 17 00:00:00 2001 From: matgic78 Date: Wed, 2 Dec 2009 18:04:30 +0100 Subject: fix copyright --- src/webinspectordock.cpp | 2 +- src/webinspectordock.h | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/webinspectordock.cpp b/src/webinspectordock.cpp index ada3af3f..51fdbdaf 100644 --- a/src/webinspectordock.cpp +++ b/src/webinspectordock.cpp @@ -2,7 +2,7 @@ * * This file is a part of the rekonq project * -* Copyright (C) 2009 by Nils Weigel +* Copyright (C) 2009 by Matthieu Gicquel * * * This program is free software; you can redistribute it and/or diff --git a/src/webinspectordock.h b/src/webinspectordock.h index b8ffa6c3..c6697361 100644 --- a/src/webinspectordock.h +++ b/src/webinspectordock.h @@ -2,8 +2,7 @@ * * This file is a part of the rekonq project * -* Copyright (C) 2008-2009 by Andrea Diamantini -* Copyright (C) 2009 by Lionel Chauvin +* Copyright (C) 2009 by Matthieu Gicquel * * * This program is free software; you can redistribute it and/or -- cgit v1.2.1 From 404b02976a71fc9740630e2075635f8681c57ead Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Thu, 3 Dec 2009 01:21:45 +0100 Subject: trivial change in src/CMakeLists.txt --- src/CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 66b68664..dcdacd68 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -20,6 +20,7 @@ SET( rekonq_KDEINIT_SRCS webview.cpp clicktoflash.cpp networkaccessmanager.cpp + webinspectordock.cpp #---------------------------------------- history/autosaver.cpp history/historymanager.cpp @@ -42,8 +43,6 @@ SET( rekonq_KDEINIT_SRCS #---------------------------------------- urlbar/urlbar.cpp urlbar/lineedit.cpp -#---------------------------------------- - webinspectordock.cpp ) -- cgit v1.2.1 From 9002b5d3c4f1677e5bc98b77956150a136f83b7f Mon Sep 17 00:00:00 2001 From: megabigbug Date: Sun, 6 Dec 2009 14:30:22 +0100 Subject: Hide findBar after one minute --- src/findbar.cpp | 12 +++++++++--- src/findbar.h | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/findbar.cpp b/src/findbar.cpp index 09cc46f1..bd1a5137 100644 --- a/src/findbar.cpp +++ b/src/findbar.cpp @@ -45,12 +45,14 @@ #include #include #include +#include FindBar::FindBar(KMainWindow *mainwindow) : QWidget(mainwindow) , m_lineEdit(new KLineEdit(this)) , m_matchCase(new QCheckBox(i18n("&Match case"), this)) + , m_hideTimer(new QTimer(this)) { QHBoxLayout *layout = new QHBoxLayout; @@ -65,6 +67,9 @@ FindBar::FindBar(KMainWindow *mainwindow) layout->addWidget(hideButton); layout->setAlignment(hideButton, Qt::AlignLeft | Qt::AlignTop); + // hide timer + connect(m_hideTimer, SIGNAL(timeout()), this, SLOT(hide())); + // label QLabel *label = new QLabel(i18n("Find:")); layout->addWidget(label); @@ -92,7 +97,7 @@ FindBar::FindBar(KMainWindow *mainwindow) layout->addStretch(); setLayout(layout); - + // we start off hidden hide(); } @@ -132,6 +137,7 @@ void FindBar::show() return; QWidget::show(); + m_hideTimer->start(60000); } @@ -140,6 +146,7 @@ void FindBar::keyPressEvent(QKeyEvent* event) if (event->key() == Qt::Key_Escape) { hide(); + m_hideTimer->stop(); return; } if (event->key() == Qt::Key_Return && !m_lineEdit->text().isEmpty()) @@ -171,6 +178,5 @@ void FindBar::notifyMatch(bool match) } } m_lineEdit->setPalette(p); + m_hideTimer->start(60000); } - - diff --git a/src/findbar.h b/src/findbar.h index 0818d010..fa369f66 100644 --- a/src/findbar.h +++ b/src/findbar.h @@ -67,6 +67,7 @@ signals: private: KLineEdit *m_lineEdit; QCheckBox *m_matchCase; + QTimer *m_hideTimer; }; -- cgit v1.2.1 From 5d59512ca2e4a36cf6c4f85537c8fa227c44c1dc Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Mon, 30 Nov 2009 16:34:34 +0100 Subject: kde wallet integration. First bits --- src/mainview.cpp | 8 +++++ src/walletwidget.cpp | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/walletwidget.h | 53 +++++++++++++++++++++++++++++++++ src/webpage.cpp | 6 ++++ 4 files changed, 149 insertions(+) create mode 100644 src/walletwidget.cpp create mode 100644 src/walletwidget.h (limited to 'src') diff --git a/src/mainview.cpp b/src/mainview.cpp index f4598f22..d190507e 100644 --- a/src/mainview.cpp +++ b/src/mainview.cpp @@ -48,6 +48,7 @@ #include #include #include +#include // Qt Includes #include @@ -544,6 +545,13 @@ void MainView::webViewLoadFinished(bool ok) webViewIconChanged(); emit browserTabLoading(false); + // KWallet Integration + // TODO: Add check for sites exempt from automatic form filling... + if (webView->page()->wallet()) + { + webView->page()->wallet()->fillFormData(webView->page()->mainFrame()); + } + // don't display messages for background tabs if (index != currentIndex()) { diff --git a/src/walletwidget.cpp b/src/walletwidget.cpp new file mode 100644 index 00000000..8c68e187 --- /dev/null +++ b/src/walletwidget.cpp @@ -0,0 +1,82 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009 by Andrea Diamantini +* +* +* 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 . +* +* ============================================================ */ + + +#include "walletwidget.h" +#include "walletwidget.moc" + +#include +#include +#include + + +WalletWidget::WalletWidget(QObject *parent) + : QWidget(parent) +{ + QLabel *label = new QLabel( i18n("Do you want rekonq to remember the password for %1 on %2?"), this); + QPushButton *rememberButton = new QPushButton( i18n("remember"), this); + QPushButton *neverHereButton = new QPushButton( i18n("never for this site"), this); + QPushButton *notNowButton = new QPushButton( i18n("not now"), this); + + connect(rememberButton, SIGNAL(clicked()), this, SLOT(rememberData())); + connect(neverHereButton, SIGNAL(clicked()), this, SLOT(neverRememberData())); + connect(notNowButton, SIGNAL(clicked()), this, SLOT(notNowRememberData())); + + // layout + QVBoxLayout *layout = new QVBoxLayout; + layout->addWidget(label); + layout->addWidget(rememberButton); + layout->addWidget(neverHereButton); + layout->addWidget(notNowButton); + + setLayout(layout); +} + + +WalletWidget::~WalletWidget() +{ +} + + +void WalletWidget::rememberData() +{ + WebView *w = Application::instance()->mainWindow()->currentTab(); + w->page()->wallet()->saveFormData(w->page()->currentFrame()); + hide(); +} + + +void WalletWidget::neverRememberData() +{ + hide(); +} + + +void WalletWidget::notNowRememberData() +{ + hide(); +} + + diff --git a/src/walletwidget.h b/src/walletwidget.h new file mode 100644 index 00000000..e9e6ce87 --- /dev/null +++ b/src/walletwidget.h @@ -0,0 +1,53 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009 by Andrea Diamantini +* +* +* 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 . +* +* ============================================================ */ + + +#ifndef WALLET_WIDGET_H +#define WALLET_WIDGET_H + + +// Qt Includes +#include + +// Forward Declarations +class KMainWindow; + + +class WalletWidget : public QWidget +{ + Q_OBJECT + +public: + WalletWidget(QObject *parent); + ~WalletWidget(); + +private slots: + + void rememberData(); + void neverRememberData(); + void notNowRememberData(); +}; + +#endif // WALLET_WIDGET_H diff --git a/src/webpage.cpp b/src/webpage.cpp index 89579c88..42704ab3 100644 --- a/src/webpage.cpp +++ b/src/webpage.cpp @@ -49,6 +49,7 @@ #include #include #include +#include #include @@ -80,6 +81,11 @@ WebPage::WebPage(QObject *parent) connect(networkAccessManager(), SIGNAL(finished(QNetworkReply*)), this, SLOT(manageNetworkErrors(QNetworkReply*))); connect(this, SIGNAL(unsupportedContent(QNetworkReply *)), this, SLOT(handleUnsupportedContent(QNetworkReply *))); + + // kwallet + KWebWallet *w = wallet(); + connect(w, SIGNAL(saveFormDataRequested(const QString &, const QUrl &)), + w, SLOT(acceptSaveFormDataRequest(const QString &))); } -- cgit v1.2.1 From eaa82c1922c7cc133458c65ecbe8eb2ab6adc03d Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Sun, 6 Dec 2009 23:36:15 +0100 Subject: KWebWallet integration --- src/CMakeLists.txt | 1 + src/mainwindow.cpp | 4 ++-- src/mainwindow.h | 2 +- src/networkaccessmanager.cpp | 10 +++++++++- src/walletwidget.cpp | 42 +++++++++++++++++++++++++++++++++--------- src/walletwidget.h | 19 +++++++++++++++---- src/webpage.cpp | 5 ----- src/webview.cpp | 40 +++++++++++++++++++++++++--------------- src/webview.h | 7 +++---- 9 files changed, 89 insertions(+), 41 deletions(-) (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dcdacd68..7f95a1d2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -21,6 +21,7 @@ SET( rekonq_KDEINIT_SRCS clicktoflash.cpp networkaccessmanager.cpp webinspectordock.cpp + walletwidget.cpp #---------------------------------------- history/autosaver.cpp history/historymanager.cpp diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 583825af..6186ebea 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -97,8 +97,8 @@ MainWindow::MainWindow() : KMainWindow() - , m_view(new MainView(this)) - , m_findBar(new FindBar(this)) + , m_view( new MainView(this) ) + , m_findBar( new FindBar(this) ) , m_sidePanel(0) , m_bookmarksPanel(0) , m_webInspectorDock(0) diff --git a/src/mainwindow.h b/src/mainwindow.h index f141c5a2..f07a46da 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -73,7 +73,7 @@ public: virtual KActionCollection *actionCollection () const; bool newTabPage(const KUrl &url = KUrl("about:home")); - + private: void setupActions(); void setupTools(); diff --git a/src/networkaccessmanager.cpp b/src/networkaccessmanager.cpp index a2c1fdee..1f8b8281 100644 --- a/src/networkaccessmanager.cpp +++ b/src/networkaccessmanager.cpp @@ -31,7 +31,7 @@ // Local Includes #include "application.h" #include "adblockmanager.h" - +#include NetworkAccessManager::NetworkAccessManager(QObject *parent) : AccessManager(parent) @@ -41,6 +41,14 @@ NetworkAccessManager::NetworkAccessManager(QObject *parent) QNetworkReply *NetworkAccessManager::createRequest(Operation op, const QNetworkRequest &req, QIODevice *outgoingData) { + if (op == PostOperation && outgoingData) + { + QByteArray outgoingDataByteArray = outgoingData->peek(1024 * 1024); + kDebug() << "*************************************************************************"; + kDebug() << outgoingDataByteArray; + kDebug() << "*************************************************************************"; + } + QNetworkRequest request(req); request.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true); diff --git a/src/walletwidget.cpp b/src/walletwidget.cpp index 8c68e187..efb5af12 100644 --- a/src/walletwidget.cpp +++ b/src/walletwidget.cpp @@ -24,18 +24,22 @@ * ============================================================ */ +// Self Includes #include "walletwidget.h" #include "walletwidget.moc" -#include +// KDE Includes +#include + +// Qt Includes #include -#include +#include -WalletWidget::WalletWidget(QObject *parent) +WalletWidget::WalletWidget(QWidget *parent) : QWidget(parent) + , m_label( new QLabel(this) ) { - QLabel *label = new QLabel( i18n("Do you want rekonq to remember the password for %1 on %2?"), this); QPushButton *rememberButton = new QPushButton( i18n("remember"), this); QPushButton *neverHereButton = new QPushButton( i18n("never for this site"), this); QPushButton *notNowButton = new QPushButton( i18n("not now"), this); @@ -45,13 +49,16 @@ WalletWidget::WalletWidget(QObject *parent) connect(notNowButton, SIGNAL(clicked()), this, SLOT(notNowRememberData())); // layout - QVBoxLayout *layout = new QVBoxLayout; - layout->addWidget(label); + QHBoxLayout *layout = new QHBoxLayout; + layout->addWidget(m_label); layout->addWidget(rememberButton); layout->addWidget(neverHereButton); layout->addWidget(notNowButton); setLayout(layout); + + // we start off hidden + hide(); } @@ -62,21 +69,38 @@ WalletWidget::~WalletWidget() void WalletWidget::rememberData() { - WebView *w = Application::instance()->mainWindow()->currentTab(); - w->page()->wallet()->saveFormData(w->page()->currentFrame()); hide(); + emit saveFormDataAccepted(m_key); } void WalletWidget::neverRememberData() { - hide(); + // TODO: store site url (to remember never bother about) + notNowRememberData(); } void WalletWidget::notNowRememberData() { hide(); + emit saveFormDataRejected (m_key); } +void WalletWidget::onSaveFormData(const QString &key, const QUrl &url) +{ + m_label->setText( i18n("Do you want rekonq to remember the password for %1 on %2?") + .arg(key) + .arg(url.host()) + ); + m_key = key; + m_url = url; + + // TODO: check if url is stored somewhere to not remember pass.. + if(true) + show(); + else + notNowRememberData(); + +} diff --git a/src/walletwidget.h b/src/walletwidget.h index e9e6ce87..7b20ead5 100644 --- a/src/walletwidget.h +++ b/src/walletwidget.h @@ -30,9 +30,9 @@ // Qt Includes #include - -// Forward Declarations -class KMainWindow; +#include +#include +#include class WalletWidget : public QWidget @@ -40,7 +40,7 @@ class WalletWidget : public QWidget Q_OBJECT public: - WalletWidget(QObject *parent); + WalletWidget(QWidget *parent); ~WalletWidget(); private slots: @@ -48,6 +48,17 @@ private slots: void rememberData(); void neverRememberData(); void notNowRememberData(); + void onSaveFormData(const QString &, const QUrl &); + +signals: + void saveFormDataAccepted(const QString &); + void saveFormDataRejected(const QString &); + +private: + QString m_key; + QUrl m_url; + + QLabel *m_label; }; #endif // WALLET_WIDGET_H diff --git a/src/webpage.cpp b/src/webpage.cpp index 42704ab3..92318b36 100644 --- a/src/webpage.cpp +++ b/src/webpage.cpp @@ -81,11 +81,6 @@ WebPage::WebPage(QObject *parent) connect(networkAccessManager(), SIGNAL(finished(QNetworkReply*)), this, SLOT(manageNetworkErrors(QNetworkReply*))); connect(this, SIGNAL(unsupportedContent(QNetworkReply *)), this, SLOT(handleUnsupportedContent(QNetworkReply *))); - - // kwallet - KWebWallet *w = wallet(); - connect(w, SIGNAL(saveFormDataRequested(const QString &, const QUrl &)), - w, SLOT(acceptSaveFormDataRequest(const QString &))); } diff --git a/src/webview.cpp b/src/webview.cpp index c25b8903..78c4caf8 100644 --- a/src/webview.cpp +++ b/src/webview.cpp @@ -38,6 +38,7 @@ #include "mainview.h" #include "webpage.h" #include "bookmarksmanager.h" +#include "walletwidget.h" // KDE Includes #include @@ -45,6 +46,7 @@ #include #include #include +#include // Qt Includes #include @@ -56,22 +58,36 @@ WebView::WebView(QWidget* parent) - : KWebView(parent, false) - , m_page(new WebPage(this)) - , m_progress(0) - , m_mousePos(QPoint(0,0)) + : KWebView(parent, false) + , m_page( new WebPage(this) ) + , m_walletBar( new WalletWidget(this) ) + , m_progress(0) + , m_mousePos(QPoint(0,0)) { setPage(m_page); - connect(page(), SIGNAL(statusBarMessage(const QString&)), this, SLOT(setStatusBarText(const QString&))); + connect(m_page, SIGNAL(statusBarMessage(const QString&)), this, SLOT(setStatusBarText(const QString&))); connect(this, SIGNAL(loadProgress(int)), this, SLOT(updateProgress(int))); connect(this, SIGNAL(loadFinished(bool)), this, SLOT(loadFinished(bool))); connect(this, SIGNAL(linkMiddleOrCtrlClicked(const KUrl &)), this, SLOT(loadInNewTab(const KUrl &)) ); - connect(this, SIGNAL(linkShiftClicked(const KUrl &)), this, SLOT(downloadRequest(const KUrl &))); - connect(page(), SIGNAL(downloadRequested(const QNetworkRequest &)), this, SLOT(downloadRequest(const QNetworkRequest &r))); + // download system + connect(this, SIGNAL(linkShiftClicked(const KUrl &)), m_page, SLOT(downloadUrl(const KUrl &))); + connect(m_page, SIGNAL(downloadRequested(const QNetworkRequest &)), m_page, SLOT(downloadRequest(const QNetworkRequest &r))); + + // kwallet + KWebWallet *w = m_page->wallet(); + if(w) + { + connect (w, SIGNAL(saveFormDataRequested(const QString &, const QUrl &)), + m_walletBar, SLOT(onSaveFormData(const QString &, const QUrl &))); + connect(m_walletBar, SIGNAL(saveFormDataAccepted(const QString &)), + w, SLOT(acceptSaveFormDataRequest(const QString &))); + connect(m_walletBar, SIGNAL(saveFormDataRejected(const QString &)), + w, SLOT(rejectSaveFormDataRequest(const QString &))); + } } @@ -433,15 +449,9 @@ void WebView::loadInNewTab(const KUrl &url) { Application::instance()->loadUrl(url, Rekonq::NewCurrentTab); } - - -void WebView::downloadRequest(const KUrl &url) -{ - m_page->downloadRequest(QNetworkRequest(url)); -} -void WebView::downloadRequest(const QNetworkRequest &request) +QWidget *WebView::walletBar() { - m_page->downloadRequest(request); + return m_walletBar; } diff --git a/src/webview.h b/src/webview.h index 4fa87978..39cc51da 100644 --- a/src/webview.h +++ b/src/webview.h @@ -37,6 +37,7 @@ // Forward Declarations class WebPage; +class WalletWidget; class WebView : public KWebView @@ -52,6 +53,7 @@ public: QString lastStatusBarText() const; int progress(); QPoint mousePos(); + QWidget *walletBar(); protected: void contextMenuEvent(QContextMenuEvent *event); @@ -73,14 +75,11 @@ private slots: void loadInNewTab(const KUrl &url); - void downloadRequest(const KUrl &url); - void downloadRequest(const QNetworkRequest &request); - private: WebPage *m_page; + WalletWidget *m_walletBar; int m_progress; QString m_statusBarText; - QPoint m_mousePos; }; -- cgit v1.2.1 From ecbe1d942e41a29a8d0bffdb328643e4c2a278b1 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Tue, 8 Dec 2009 12:25:54 +0100 Subject: xss attach prevention. I have to say, BRUTE prevention :) Hope this works. Also some fixes in Urlbar class to ensure that a KUrl is a KUrl and a QString is a QString. Removed the annoying "restore url on focus out" feature. No other browsers have it and I really cannot understand gain --- src/application.cpp | 80 ++++++++++++++++----------------------------------- src/application.h | 6 ++-- src/urlbar/urlbar.cpp | 36 +++++++++++------------ src/urlbar/urlbar.h | 1 - src/webpage.cpp | 9 +++--- src/webview.cpp | 2 +- 6 files changed, 49 insertions(+), 85 deletions(-) (limited to 'src') diff --git a/src/application.cpp b/src/application.cpp index 3a0ce638..246d6aa5 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -52,6 +52,7 @@ #include #include #include +#include // Qt Includes #include @@ -265,71 +266,26 @@ KIcon Application::icon(const KUrl &url) } -KUrl Application::guessUrlFromString(const QString &string) -{ - QString urlStr = string.trimmed(); - QRegExp test(QLatin1String("^[a-zA-Z]+\\:.*")); - - // Might be a file. - if (QFile::exists(urlStr)) - { - QFileInfo info(urlStr); - return KUrl::fromPath(info.absoluteFilePath()); - } - - // Check if it looks like a qualified URL. Try parsing it and see. - if (test.exactMatch(urlStr)) - { - KUrl url(urlStr); - - if (url.isValid()) - { - return url; - } - } - else // Might be a shorturl - try to detect the schema. - { - int dotIndex = urlStr.indexOf(QLatin1Char(':')); - - if (dotIndex != -1) - { - QString prefix = urlStr.left(dotIndex).toLower(); - QString schema = (prefix == QLatin1String("ftp")) ? prefix : QLatin1String("http"); - QUrl qurl(schema + QLatin1String("://") + urlStr, QUrl::TolerantMode); - KUrl url(qurl); - - if (url.isValid()) - { - return url; - } - } - } - - // Fall back to QUrl's own tolerant parser. - KUrl url = KUrl(urlStr); - - return url; -} - - void Application::loadUrl(const KUrl& url, const Rekonq::OpenType& type) { if (url.isEmpty()) return; - if ( !url.isValid() ) + KUrl loadingUrl = xssSanitization(url); + + if ( !loadingUrl.isValid() ) { - KMessageBox::error(0, i18n("Malformed URL:\n%1", url.url())); + KMessageBox::error(0, i18n("Malformed URL:\n%1", loadingUrl.url(KUrl::RemoveTrailingSlash))); return; } // loading home pages - if (mainWindow()->newTabPage(url)) + if (mainWindow()->newTabPage(loadingUrl)) return; - if (url.scheme() == QLatin1String("mailto")) + if (loadingUrl.scheme() == QLatin1String("mailto")) { - KToolInvocation::invokeMailer(url); + KToolInvocation::invokeMailer(loadingUrl); return; } @@ -365,8 +321,6 @@ void Application::loadUrl(const KUrl& url, const Rekonq::OpenType& type) // - web shortcuts with space separator // - relative urls // - ... - KUrl loadingUrl(url); - if (loadingUrl.isRelative()) { QString fn = loadingUrl.url(KUrl::RemoveTrailingSlash); @@ -408,7 +362,7 @@ void Application::loadUrl(const KUrl& url, const Rekonq::OpenType& type) void Application::loadUrl(const QString& urlString, const Rekonq::OpenType& type) { - return loadUrl( guessUrlFromString(urlString), type ); + return loadUrl( QUrl::fromUserInput(urlString), type ); } @@ -445,3 +399,19 @@ AdBlockManager *Application::adblockManager() } return s_adblockManager; } + + +KUrl Application::xssSanitization(const KUrl &url) +{ + QString urlString = url.url(); + + QList l; // TODO: learn regular expression + l << '\'' << '\"' << '<' << '>'; + foreach(const QChar &c, l) + { + QStringList list = urlString.split(c); + urlString = list.at(0); + } + return KUrl(urlString); +} + \ No newline at end of file diff --git a/src/application.h b/src/application.h index b15720f5..fa2354f2 100644 --- a/src/application.h +++ b/src/application.h @@ -33,7 +33,6 @@ // KDE Includes #include #include -#include #include #include @@ -135,9 +134,8 @@ private slots: void postLaunch(); private: - - KUrl guessUrlFromString(const QString &url); - + KUrl xssSanitization(const KUrl &url); + static QPointer s_historyManager; static QPointer s_bookmarkProvider; static QPointer s_sessionManager; diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp index 2adfcd17..e9952c01 100644 --- a/src/urlbar/urlbar.cpp +++ b/src/urlbar/urlbar.cpp @@ -138,12 +138,13 @@ void UrlBar::setUrl(const QUrl& url) { if(url.scheme() == "about") { - m_currentUrl = ""; + m_currentUrl = KUrl(); setFocus(); } else - m_currentUrl = url; - + { + m_currentUrl = KUrl(url); + } updateUrl(); } @@ -166,8 +167,14 @@ void UrlBar::updateUrl() } KIcon icon; - if(m_currentUrl.isEmpty()) icon = KIcon("arrow-right"); - else icon = Application::icon(m_currentUrl); + if(m_currentUrl.isEmpty()) + { + icon = KIcon("arrow-right"); + } + else + { + icon = Application::icon(m_currentUrl); + } if (count()) { @@ -190,14 +197,14 @@ void UrlBar::updateUrl() } -void UrlBar::activated(const QString& url) +void UrlBar::activated(const QString& urlString) { - if (url.isEmpty()) + if (urlString.isEmpty()) return; - setUrl(url); + setUrl(urlString); - Application::historyManager()->addHistoryEntry(url); + Application::historyManager()->addHistoryEntry(urlString); emit activated(m_currentUrl); } @@ -260,15 +267,6 @@ void UrlBar::paintEvent(QPaintEvent *event) } -void UrlBar::focusOutEvent(QFocusEvent *event) -{ - // set back last loaded url in case user cleared it - if (!m_currentUrl.equals(KUrl(lineEdit()->text()))) setUrl(m_currentUrl); - - KHistoryComboBox::focusOutEvent(event); -} - - QSize UrlBar::sizeHint() const { return lineEdit()->sizeHint(); @@ -293,7 +291,7 @@ QLinearGradient UrlBar::generateGradient(const QColor &color, int height) void UrlBar::setBackgroundColor(QColor c) { - s_defaultBaseColor=c; + s_defaultBaseColor = c; repaint(); } diff --git a/src/urlbar/urlbar.h b/src/urlbar/urlbar.h index 0e8bab26..8d267b2c 100644 --- a/src/urlbar/urlbar.h +++ b/src/urlbar/urlbar.h @@ -78,7 +78,6 @@ private slots: protected: virtual void paintEvent(QPaintEvent *event); - virtual void focusOutEvent(QFocusEvent *event); virtual void keyPressEvent(QKeyEvent *event); private: diff --git a/src/webpage.cpp b/src/webpage.cpp index 92318b36..a6c37906 100644 --- a/src/webpage.cpp +++ b/src/webpage.cpp @@ -187,7 +187,6 @@ void WebPage::manageNetworkErrors(QNetworkReply* reply) if( reply->error() == QNetworkReply::NoError ) return; - if( reply->url() != m_requestedUrl ) // prevent favicon loading return; @@ -223,6 +222,7 @@ QString WebPage::errorPage(QNetworkReply *reply) // display "not found" page QString notfoundFilePath = KStandardDirs::locate("data", "rekonq/htmls/notfound.html"); QFile file(notfoundFilePath); + bool isOpened = file.open(QIODevice::ReadOnly); if (!isOpened) { @@ -231,18 +231,17 @@ QString WebPage::errorPage(QNetworkReply *reply) } QString title = i18n("Error loading: %1", reply->url().path()); - QString imagesPath = QString("file://") + KGlobal::dirs()->findResourceDir("data", "rekonq/pics/bg.png") + QString("rekonq/pics"); - QString msg = "

" + reply->errorString() + "

"; + QString urlString = reply->url().toString( QUrl::RemoveUserInfo | QUrl::RemoveQuery ); - msg += "

" + i18nc("%1=an URL, e.g.'kde.org'", "When connecting to: %1", reply->url().toString()) + "

"; + msg += "

" + i18nc("%1=an URL, e.g.'kde.org'", "When connecting to: %1", urlString ) + "

"; msg += "
  • " + i18n("Check the address for errors such as ww.kde.org instead of www.kde.org"); msg += "
  • " + i18n("If the address is correct, try to check the network connection.") + "
  • " ; msg += i18n("If your computer or network is protected by a firewall or proxy, make sure that rekonq is permitted to access the network."); msg += "
  • " + i18n("Of course, if rekonq does not work properly, you can always say it is a programmer error ;)"); msg += "


"; - msg += "url().path() + "';\" value=\""; + msg += ""; QString html = QString(QLatin1String(file.readAll())) diff --git a/src/webview.cpp b/src/webview.cpp index 78c4caf8..fede781e 100644 --- a/src/webview.cpp +++ b/src/webview.cpp @@ -75,7 +75,7 @@ WebView::WebView(QWidget* parent) // download system connect(this, SIGNAL(linkShiftClicked(const KUrl &)), m_page, SLOT(downloadUrl(const KUrl &))); - connect(m_page, SIGNAL(downloadRequested(const QNetworkRequest &)), m_page, SLOT(downloadRequest(const QNetworkRequest &r))); + connect(m_page, SIGNAL(downloadRequested(const QNetworkRequest &)), m_page, SLOT(downloadRequest(const QNetworkRequest &))); // kwallet KWebWallet *w = m_page->wallet(); -- cgit v1.2.1