summaryrefslogtreecommitdiff
path: root/kwebapp/webpage.cpp
diff options
context:
space:
mode:
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;
}