summaryrefslogtreecommitdiff
path: root/kwebapp/webpage.cpp
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/webpage.cpp
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/webpage.cpp')
-rw-r--r--kwebapp/webpage.cpp85
1 files changed, 73 insertions, 12 deletions
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;
}