summaryrefslogtreecommitdiff
path: root/kwebapp
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2012-06-05 11:38:19 +0200
committerAndrea Diamantini <adjam7@gmail.com>2012-06-08 00:39:47 +0200
commite4f47b368fe0c3380636ab8ab0cc5706518f8a2b (patch)
treeded3fbc8568870d79ac72445f141e1bd523dda99 /kwebapp
parentFix/improve kwebapp contextual actions (diff)
downloadrekonq-e4f47b368fe0c3380636ab8ab0cc5706518f8a2b.tar.xz
Added an UrlResolver class to let every url work properly here
Diffstat (limited to 'kwebapp')
-rw-r--r--kwebapp/CMakeLists.txt1
-rw-r--r--kwebapp/kwebmain.cpp3
-rw-r--r--kwebapp/rekonqview.cpp2
-rw-r--r--kwebapp/urlresolver.cpp93
-rw-r--r--kwebapp/urlresolver.h46
-rw-r--r--kwebapp/webpage.cpp85
-rw-r--r--kwebapp/webpage.h10
7 files changed, 218 insertions, 22 deletions
diff --git a/kwebapp/CMakeLists.txt b/kwebapp/CMakeLists.txt
index fab9106a..459c5a45 100644
--- a/kwebapp/CMakeLists.txt
+++ b/kwebapp/CMakeLists.txt
@@ -1,6 +1,7 @@
set( kwebapp_SRCS
rekonqview.cpp
searchengine.cpp
+ urlresolver.cpp
walletbar.cpp
webview.cpp
webpage.cpp
diff --git a/kwebapp/kwebmain.cpp b/kwebapp/kwebmain.cpp
index 9e6c7452..08dfbaa5 100644
--- a/kwebapp/kwebmain.cpp
+++ b/kwebapp/kwebmain.cpp
@@ -26,6 +26,7 @@
// Local Includes
#include "rekonqview.h"
+#include "urlresolver.h"
// KDE Includes
#include <KApplication>
@@ -68,7 +69,7 @@ int main(int argc, char **argv)
}
RekonqView *widg = new RekonqView();
- widg->loadUrl(KUrl(QUrl::fromUserInput(args->arg(0))));
+ widg->loadUrl( UrlResolver::urlFromTextTyped(args->arg(0)) );
widg->show();
args->clear();
diff --git a/kwebapp/rekonqview.cpp b/kwebapp/rekonqview.cpp
index b737bc11..ec8ca01d 100644
--- a/kwebapp/rekonqview.cpp
+++ b/kwebapp/rekonqview.cpp
@@ -227,7 +227,7 @@ void RekonqView::notifyMessage(const QString &msg)
}
m_hidePopupTimer->stop();
- m_hidePopupTimer->start(500);
+ m_hidePopupTimer->start(3000);
QString msgToShow = Qt::escape(msg);
diff --git a/kwebapp/urlresolver.cpp b/kwebapp/urlresolver.cpp
new file mode 100644
index 00000000..173dc613
--- /dev/null
+++ b/kwebapp/urlresolver.cpp
@@ -0,0 +1,93 @@
+/* ============================================================
+*
+* This file is a part of the rekonq project
+*
+* Copyright (C) 2012 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 "urlresolver.h"
+
+// Local Includes
+#include "searchengine.h"
+
+// KDE Includes
+#include <KService>
+#include <KProtocolInfo>
+#include <KDebug>
+
+
+// NOTE
+// default kurifilter plugin list (at least in my box):
+// 1. "kshorturifilter"
+// 2. "kurisearchfilter"
+// 3. "localdomainurifilter"
+// 4 ."kuriikwsfilter"
+// 5. "fixhosturifilter"
+
+
+KUrl UrlResolver::urlFromTextTyped(const QString &typedText)
+{
+ QString typedString = typedText.trimmed();
+
+ // Url from KService
+ KService::Ptr engine = SearchEngine::fromString(typedString);
+ if (engine)
+ {
+ QString query = typedString;
+ query = query.remove(0, typedString.indexOf(SearchEngine::delimiter()) + 1);
+
+ QString url = SearchEngine::buildQuery(engine, query);
+
+ kDebug() << "Url from service: " << url;
+ return KUrl(url);
+ }
+
+ // Url from User Input
+ QUrl urlFromUserInput = QUrl::fromUserInput(typedString);
+ if (urlFromUserInput.isValid())
+ {
+ // ensure http(s) hosts are lower cases
+ if (urlFromUserInput.scheme().startsWith("http"))
+ {
+ QString hst = urlFromUserInput.host();
+ urlFromUserInput.setHost(hst.toLower());
+ }
+
+ kDebug() << "(Q)Url from user input: " << urlFromUserInput;
+ return urlFromUserInput;
+ }
+
+ // failed...
+ kDebug() << "KUrl fallback: " << typedText;
+ return KUrl(typedText);
+}
+
+
+bool UrlResolver::isKDEUrl(const QString &urlString)
+{
+ KService::Ptr engine = SearchEngine::fromString(urlString);
+ if (engine)
+ return true;
+
+ return false;
+}
diff --git a/kwebapp/urlresolver.h b/kwebapp/urlresolver.h
new file mode 100644
index 00000000..1c5ad354
--- /dev/null
+++ b/kwebapp/urlresolver.h
@@ -0,0 +1,46 @@
+/* ============================================================
+*
+* This file is a part of the rekonq project
+*
+* Copyright (C) 2012 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 URL_RESOLVER_H
+#define URL_RESOLVER_H
+
+
+// KDE Includes
+#include <KUrl>
+
+// Qt Includes
+#include <QString>
+
+
+namespace UrlResolver
+{
+ KUrl urlFromTextTyped(const QString &);
+
+ bool isKDEUrl(const QString &);
+}
+
+
+#endif // URL_RESOLVER_H
diff --git a/kwebapp/webpage.cpp b/kwebapp/webpage.cpp
index cdca10bd..afe23035 100644
--- a/kwebapp/webpage.cpp
+++ b/kwebapp/webpage.cpp
@@ -28,19 +28,32 @@
#include "webpage.h"
#include "webpage.moc"
+// Local Includes
+#include "urlresolver.h"
+
// KDE Includes
#include <KRun>
+#include <KToolInvocation>
+#include <KProtocolInfo>
+#include <KDebug>
// Qt Includes
#include <QNetworkRequest>
+#include <QNetworkReply>
+#include <QWebFrame>
+
+// Defines
+#define QL1S(x) QLatin1String(x)
WebPage::WebPage(QObject *parent)
: KWebPage(parent)
- , _selfLoading(true)
{
- connect(this, SIGNAL(loadFinished(bool)), this, SLOT(disableSelfLoading()));
+ // ----- handling unsupported content...
+ setForwardUnsupportedContent(true);
+ connect(this, SIGNAL(unsupportedContent(QNetworkReply*)), this, SLOT(handleUnsupportedContent(QNetworkReply*)));
+ // downloads
connect(this, SIGNAL(unsupportedContent(QNetworkReply*)), this, SLOT(downloadResponse(QNetworkReply*)));
connect(this, SIGNAL(downloadRequested(QNetworkRequest)), this, SLOT(downloadRequest(QNetworkRequest)));
}
@@ -48,21 +61,69 @@ WebPage::WebPage(QObject *parent)
bool WebPage::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type)
{
- return KWebPage::acceptNavigationRequest(frame, request, type);
+ QUrl reqUrl = request.url();
+ QString protocol = reqUrl.scheme();
+
+ // javascript handling
+ if (protocol == QL1S("javascript"))
+ {
+ QString scriptSource = QUrl::fromPercentEncoding(reqUrl.toString().mid(11).toUtf8());
+ mainFrame()->evaluateJavaScript(scriptSource);
+ return false;
+ }
- // FIXME
-// (void)new KRun(request.url(), view(), 0);
-// return false;
-}
+ // "mailto" handling: It needs to be handled both here (mail url launched)
+ // and in handleUnsupportedContent (mail links clicked)
+ if (protocol == QL1S("mailto"))
+ {
+ KToolInvocation::invokeMailer(reqUrl);
+ return false;
+ }
+ if (frame && UrlResolver::isKDEUrl(reqUrl.toString()))
+ {
+ QUrl newReqUrl = UrlResolver::urlFromTextTyped(reqUrl.toString());
+ frame->load(newReqUrl);
+ return false;
+ }
-void WebPage::setSelfLoadingEnabled(bool b)
-{
- _selfLoading = b;
+ // don't let webkit try to load an unknown (or missing) protocol...
+ if (!KProtocolInfo::isKnownProtocol(protocol))
+ {
+ kDebug() << "UNKNOWN PROTOCOL: " << protocol;
+ return false;
+ }
+
+ return KWebPage::acceptNavigationRequest(frame, request, type);
}
-void WebPage::disableSelfLoading()
+void WebPage::handleUnsupportedContent(QNetworkReply *reply)
{
- _selfLoading = false;
+ Q_ASSERT(reply);
+
+ if (!reply)
+ {
+ kDebug() << "NO REPLY. Why????";
+ return;
+ }
+
+ QUrl replyUrl = reply->url();
+ QString protocol = replyUrl.scheme();
+
+ // "http(s)" (fast) handling
+ if (protocol == QL1S("http") || protocol == QL1S("https"))
+ {
+ kDebug() << "Error: " << protocol;
+ return;
+ }
+
+ // "mailto" handling.
+ if (protocol == QL1S("mailto"))
+ {
+ KToolInvocation::invokeMailer(replyUrl);
+ return;
+ }
+
+ return;
}
diff --git a/kwebapp/webpage.h b/kwebapp/webpage.h
index 33d06a31..97d7102a 100644
--- a/kwebapp/webpage.h
+++ b/kwebapp/webpage.h
@@ -39,17 +39,11 @@ class WebPage : public KWebPage
public:
WebPage(QObject *parent = 0);
- void setSelfLoadingEnabled(bool);
-
-private Q_SLOTS:
- void disableSelfLoading();
-
protected:
virtual bool acceptNavigationRequest(QWebFrame *, const QNetworkRequest &, NavigationType);
-private:
- bool _selfLoading;
-
+private Q_SLOTS:
+ void handleUnsupportedContent(QNetworkReply *);
};
#endif // _WEB_PAGE_H