diff options
author | Panagiotis Papadopoulos <pano_90@gmx.net> | 2009-12-09 17:23:35 +0100 |
---|---|---|
committer | Panagiotis Papadopoulos <pano_90@gmx.net> | 2009-12-09 17:23:35 +0100 |
commit | ba21553e2e6ce17fc4ad84b5ab587b4e7bc5345c (patch) | |
tree | 64f7b3a5cec066f06268e954899a78523dcaedf5 /src | |
parent | Change a bit the WebKit settings UI (diff) | |
parent | xss attach prevention. (diff) | |
download | rekonq-ba21553e2e6ce17fc4ad84b5ab587b4e7bc5345c.tar.xz |
Merge branch 'master' of git://gitorious.org/rekonq/mainline into click-to-flash-ui
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 5 | ||||
-rw-r--r-- | src/adblock/adblockmanager.cpp | 53 | ||||
-rw-r--r-- | src/adblock/adblockmanager.h | 11 | ||||
-rw-r--r-- | src/adblock/adblocknetworkreply.cpp | 88 | ||||
-rw-r--r-- | src/adblock/adblocknetworkreply.h | 81 | ||||
-rw-r--r-- | src/adblock/adblockrule.cpp | 173 | ||||
-rw-r--r-- | src/adblock/adblockrule.h | 83 | ||||
-rw-r--r-- | src/application.cpp | 80 | ||||
-rw-r--r-- | src/application.h | 6 | ||||
-rw-r--r-- | src/clicktoflash.cpp | 4 | ||||
-rw-r--r-- | src/findbar.cpp | 12 | ||||
-rw-r--r-- | src/findbar.h | 1 | ||||
-rw-r--r-- | src/mainview.cpp | 8 | ||||
-rw-r--r-- | src/mainwindow.cpp | 51 | ||||
-rw-r--r-- | src/mainwindow.h | 16 | ||||
-rw-r--r-- | src/networkaccessmanager.cpp | 64 | ||||
-rw-r--r-- | src/networkaccessmanager.h | 49 | ||||
-rw-r--r-- | src/urlbar/urlbar.cpp | 36 | ||||
-rw-r--r-- | src/urlbar/urlbar.h | 1 | ||||
-rw-r--r-- | src/walletwidget.cpp | 106 | ||||
-rw-r--r-- | src/walletwidget.h | 64 | ||||
-rw-r--r-- | src/webinspectordock.cpp | 82 | ||||
-rw-r--r-- | src/webinspectordock.h | 58 | ||||
-rw-r--r-- | src/webpage.cpp | 17 | ||||
-rw-r--r-- | src/webpage.h | 2 | ||||
-rw-r--r-- | src/webview.cpp | 40 | ||||
-rw-r--r-- | src/webview.h | 7 |
27 files changed, 1047 insertions, 151 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1f9127f4..7f95a1d2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -19,6 +19,9 @@ SET( rekonq_KDEINIT_SRCS websnap.cpp webview.cpp clicktoflash.cpp + networkaccessmanager.cpp + webinspectordock.cpp + walletwidget.cpp #---------------------------------------- history/autosaver.cpp history/historymanager.cpp @@ -36,6 +39,8 @@ SET( rekonq_KDEINIT_SRCS bookmarks/bookmarksproxy.cpp #---------------------------------------- adblock/adblockmanager.cpp + adblock/adblocknetworkreply.cpp + adblock/adblockrule.cpp #---------------------------------------- urlbar/urlbar.cpp urlbar/lineedit.cpp diff --git a/src/adblock/adblockmanager.cpp b/src/adblock/adblockmanager.cpp index b25edcb1..209c2ab0 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 <KSharedConfig> @@ -53,10 +56,56 @@ 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); + + filterList.clear(); + + // no need to load filters if adblock is not enabled :) + if(!_isAdblockEnabled) + return; + + QMap<QString,QString> entryMap = cg.entryMap(); + QMap<QString,QString>::ConstIterator it; + for( it = entryMap.constBegin(); it != entryMap.constEnd(); ++it ) + { + QString name = it.key(); + QString url = it.value(); + + if (name.startsWith(QLatin1String("Filter"))) + { + AdBlockRule filter(url); + filterList << filter; + } + } + } } -bool AdBlockManager::isUrlAllowed(const QUrl &url) +QNetworkReply *AdBlockManager::block(const QNetworkRequest &request) { - return true; + if (!_isAdblockEnabled) + return 0; + + // we (ad)block just http traffic + if(request.url().scheme() != QLatin1String("http")) + return 0; + + QString urlString = request.url().toString(); + + foreach(const AdBlockRule &filter, filterList) + { + if(filter.match(urlString)) + { + kDebug() << "****ADBLOCK: Matched: ***********" << 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..499a0cde 100644 --- a/src/adblock/adblockmanager.h +++ b/src/adblock/adblockmanager.h @@ -28,13 +28,16 @@ #ifndef ADBLOCK_MANAGER_H #define ADBLOCK_MANAGER_H +// Local Includes +#include "adblockrule.h" +typedef QList<AdBlockRule> AdBlockRuleList; // Qt Includes #include <QObject> -#include <QStringList> +#include <QNetworkReply> // Forward Includes -class QUrl; +class QNetworkRequest; class AdBlockManager : public QObject @@ -46,11 +49,13 @@ public: ~AdBlockManager(); void loadSettings(); - bool isUrlAllowed(const QUrl &url); + QNetworkReply *block(const QNetworkRequest &request); private: bool _isAdblockEnabled; bool _isHideAdsEnabled; + + AdBlockRuleList filterList; }; #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 <ben@meyerhome.net> + * + * 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 <adjam7 at gmail dot com> + * + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License or (at your option) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * ============================================================ */ + + +// Self Includes +#include "adblocknetworkreply.h" +#include "adblocknetworkreply.moc" + +// KDE Includes +#include <klocalizedstring.h> + +// Qt Includes +#include <QNetworkRequest> +#include <QTimer> + + +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 <ben@meyerhome.net> + * + * 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 <adjam7 at gmail dot com> + * + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License or (at your option) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * ============================================================ */ + + +#ifndef ADBLOCK_NETWORK_REPLY_H +#define ADBLOCK_NETWORK_REPLY_H + + +// Qt Includes +#include <QNetworkReply> +#include <QString> + +// 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/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 <gzsombor@gmail.com> + * Copyright (c) 2009, Benjamin C. Meyer <ben@meyerhome.net> + * + * 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 <adjam7 at gmail dot com> + * + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License or (at your option) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * ============================================================ */ + + +#include "adblockrule.h" + +#include <QDebug> +#include <QRegExp> +#include <QUrl> + + +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..8680942f --- /dev/null +++ b/src/adblock/adblockrule.h @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2009, Benjamin C. Meyer <ben@meyerhome.net> + * + * 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 <adjam7 at gmail dot com> + * + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License or (at your option) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * ============================================================ */ + + +#ifndef ADBLOCKRULE_H +#define ADBLOCKRULE_H + +// Qt Includes +#include <QStringList> + +// 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/application.cpp b/src/application.cpp index 3a0ce638..246d6aa5 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -52,6 +52,7 @@ #include <KUriFilter> #include <KMessageBox> #include <KWindowInfo> +#include <KUrl> // Qt Includes #include <QRegExp> @@ -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<QChar> 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 <KUniqueApplication> #include <KIcon> -#include <KUrl> #include <kio/job.h> #include <kio/jobclasses.h> @@ -135,9 +134,8 @@ private slots: void postLaunch(); private: - - KUrl guessUrlFromString(const QString &url); - + KUrl xssSanitization(const KUrl &url); + static QPointer<HistoryManager> s_historyManager; static QPointer<BookmarkProvider> s_bookmarkProvider; static QPointer<SessionManager> s_sessionManager; diff --git a/src/clicktoflash.cpp b/src/clicktoflash.cpp index e5a3c8ad..b6ea1093 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<QWebElement> 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<QWebElement> collec = element.findAll("param"); + QWebElementCollection collec = element.findAll("param"); int i = 0; while(i < collec.count() && isRightElement == false) { 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 <QtGui/QColor> #include <QtGui/QKeyEvent> #include <QtCore/QString> +#include <QtCore/QTimer> 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; }; 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 <KStandardDirs> #include <KPassivePopup> #include <KLocalizedString> +#include <kwebwallet.h> // Qt Includes #include <QtCore/QTimer> @@ -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/mainwindow.cpp b/src/mainwindow.cpp index 8b43f6ae..6186ebea 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" @@ -96,10 +97,11 @@ 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_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 ================== @@ -847,25 +861,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..f07a46da 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; @@ -72,7 +73,7 @@ public: virtual KActionCollection *actionCollection () const; bool newTabPage(const KUrl &url = KUrl("about:home")); - + private: void setupActions(); void setupTools(); @@ -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/networkaccessmanager.cpp b/src/networkaccessmanager.cpp new file mode 100644 index 00000000..1f8b8281 --- /dev/null +++ b/src/networkaccessmanager.cpp @@ -0,0 +1,64 @@ +/* ============================================================ +* +* 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 <adjam7 at gmail dot com>* +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License or (at your option) version 3 or any later version +* accepted by the membership of KDE e.V. (or its successor approved +* by the membership of KDE e.V.), which shall act as a proxy +* defined in Section 14 of version 3 of the license. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +* +* ============================================================ */ + + +// Self Includes +#include "networkaccessmanager.h" +#include "networkaccessmanager.moc" + +// Local Includes +#include "application.h" +#include "adblockmanager.h" +#include <KDebug> + +NetworkAccessManager::NetworkAccessManager(QObject *parent) + : AccessManager(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); + + // 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 <adjam7 at gmail dot com>* +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License or (at your option) version 3 or any later version +* accepted by the membership of KDE e.V. (or its successor approved +* by the membership of KDE e.V.), which shall act as a proxy +* defined in Section 14 of version 3 of the license. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +* +* ============================================================ */ + + +#ifndef NETWORKACCESSMANAGER_H +#define NETWORKACCESSMANAGER_H + + +// KDE Includes +#include <kio/accessmanager.h> + + +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/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/walletwidget.cpp b/src/walletwidget.cpp new file mode 100644 index 00000000..efb5af12 --- /dev/null +++ b/src/walletwidget.cpp @@ -0,0 +1,106 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009 by Andrea Diamantini <adjam7 at gmail dot com> +* +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License or (at your option) version 3 or any later version +* accepted by the membership of KDE e.V. (or its successor approved +* by the membership of KDE e.V.), which shall act as a proxy +* defined in Section 14 of version 3 of the license. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +* +* ============================================================ */ + + +// Self Includes +#include "walletwidget.h" +#include "walletwidget.moc" + +// KDE Includes +#include <klocalizedstring.h> + +// Qt Includes +#include <QPushButton> +#include <QHBoxLayout> + + +WalletWidget::WalletWidget(QWidget *parent) + : QWidget(parent) + , m_label( new QLabel(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 + QHBoxLayout *layout = new QHBoxLayout; + layout->addWidget(m_label); + layout->addWidget(rememberButton); + layout->addWidget(neverHereButton); + layout->addWidget(notNowButton); + + setLayout(layout); + + // we start off hidden + hide(); +} + + +WalletWidget::~WalletWidget() +{ +} + + +void WalletWidget::rememberData() +{ + hide(); + emit saveFormDataAccepted(m_key); +} + + +void WalletWidget::neverRememberData() +{ + // 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 new file mode 100644 index 00000000..7b20ead5 --- /dev/null +++ b/src/walletwidget.h @@ -0,0 +1,64 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009 by Andrea Diamantini <adjam7 at gmail dot com> +* +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License or (at your option) version 3 or any later version +* accepted by the membership of KDE e.V. (or its successor approved +* by the membership of KDE e.V.), which shall act as a proxy +* defined in Section 14 of version 3 of the license. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +* +* ============================================================ */ + + +#ifndef WALLET_WIDGET_H +#define WALLET_WIDGET_H + + +// Qt Includes +#include <QWidget> +#include <QString> +#include <QUrl> +#include <QLabel> + + +class WalletWidget : public QWidget +{ + Q_OBJECT + +public: + WalletWidget(QWidget *parent); + ~WalletWidget(); + +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/webinspectordock.cpp b/src/webinspectordock.cpp new file mode 100644 index 00000000..51fdbdaf --- /dev/null +++ b/src/webinspectordock.cpp @@ -0,0 +1,82 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009 by Matthieu Gicquel<matgic78@gmail.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 "webinspectordock.h" + +// Local Includes +#include "webview.h" +#include "webpage.h" + +// Qt Includes +#include <QWebInspector> + +// 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<QWebInspector *>()->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..c6697361 --- /dev/null +++ b/src/webinspectordock.h @@ -0,0 +1,58 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009 by Matthieu Gicquel<matgic78@gmail.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 WEBINSPECTORDOCK_H +#define WEBINSPECTORDOCK_H + + +// Local Includes +#include "mainwindow.h" + +// Qt Includes +#include <QDockWidget> + +/** + 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 diff --git a/src/webpage.cpp b/src/webpage.cpp index edb7902f..a6c37906 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 <KStandardDirs> @@ -48,6 +49,7 @@ #include <KDebug> #include <KToolInvocation> #include <KProtocolManager> +#include <kwebwallet.h> #include <kparts/browseropenorsavequestion.h> @@ -65,11 +67,13 @@ #include <QtGui/QKeyEvent> -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); @@ -183,7 +187,6 @@ void WebPage::manageNetworkErrors(QNetworkReply* reply) if( reply->error() == QNetworkReply::NoError ) return; - if( reply->url() != m_requestedUrl ) // prevent favicon loading return; @@ -219,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) { @@ -227,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 = "<h1>" + reply->errorString() + "</h1>"; + QString urlString = reply->url().toString( QUrl::RemoveUserInfo | QUrl::RemoveQuery ); - msg += "<h2>" + i18nc("%1=an URL, e.g.'kde.org'", "When connecting to: %1", reply->url().toString()) + "</h2>"; + msg += "<h2>" + i18nc("%1=an URL, e.g.'kde.org'", "When connecting to: %1", urlString ) + "</h2>"; msg += "<ul><li>" + i18n("Check the address for errors such as <b>ww</b>.kde.org instead of <b>www</b>.kde.org"); msg += "</li><li>" + i18n("If the address is correct, try to check the network connection.") + "</li><li>" ; 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 += "</li><li>" + i18n("Of course, if rekonq does not work properly, you can always say it is a programmer error ;)"); msg += "</li></ul><br/><br/>"; - msg += "<input type=\"button\" id=\"reloadButton\" onClick=\"document.location.href='" + reply->url().path() + "';\" value=\""; + msg += "<input type=\"button\" id=\"reloadButton\" onClick=\"document.location.href='" + urlString + "';\" value=\""; msg += i18n("Try Again") + "\" />"; QString html = QString(QLatin1String(file.readAll())) 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: diff --git a/src/webview.cpp b/src/webview.cpp index c25b8903..fede781e 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 <KService> @@ -45,6 +46,7 @@ #include <KStandardShortcut> #include <KMenu> #include <KActionMenu> +#include <kwebwallet.h> // Qt Includes #include <QContextMenuEvent> @@ -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 &))); + + // 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; }; |