summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormichael.bruning@digia.com <michael.bruning@digia.com>2013-01-24 12:25:19 +0000
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-02-13 15:31:39 +0100
commitca9b6836810d2f9535810790fcca86ab35834caa (patch)
tree42506fd66a9d9190d97bdff4822d639a0f84d9cc
parent11a7cbc1a9dc5df9a63e0102c589a6f05d4a39fa (diff)
downloadqtwebkit-ca9b6836810d2f9535810790fcca86ab35834caa.tar.gz
[Qt][WK2] Pages / resources cannot be loaded from qrc files.
https://bugs.webkit.org/show_bug.cgi?id=107031 Reviewed by Jocelyn Turcotte. Enables WebKit2 Qt applications to load files from the bundled qrc files. This is achieved by adding a url scheme handler for the "qrc" scheme using the application scheme handler and ignoring all handlers for the qrc application scheme that the application might set. * UIProcess/API/qt/qquickurlschemedelegate.cpp: (QQuickQrcSchemeDelegate::QQuickQrcSchemeDelegate): (QQuickQrcSchemeDelegate::readResourceAndSend): * UIProcess/API/qt/qquickurlschemedelegate_p.h: (QQuickQrcSchemeDelegate): * UIProcess/API/qt/qquickwebview.cpp: (QQuickWebViewPrivate::initialize): (QQuickWebViewExperimental::schemeDelegates_Append): (QQuickWebViewExperimental::invokeApplicationSchemeHandler): * UIProcess/API/qt/tests/qmltests/WebView/tst_applicationScheme.qml: * UIProcess/API/qt/tests/qmltests/common/qrctest.html: Added. * UIProcess/API/qt/tests/qmltests/resources.qrc: git-svn-id: http://svn.webkit.org/repository/webkit/trunk@140676 268f45cc-cd09-0410-ab3c-d52691b4dbfc Change-Id: Ia1cbd499ff9d1ca03373f6fb542d41f25231d656 Reviewed-by: Andras Becsi <andras.becsi@digia.com>
-rw-r--r--Source/WebKit2/ChangeLog29
-rw-r--r--Source/WebKit2/UIProcess/API/qt/qquickurlschemedelegate.cpp27
-rw-r--r--Source/WebKit2/UIProcess/API/qt/qquickurlschemedelegate_p.h11
-rw-r--r--Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp16
-rw-r--r--Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_applicationScheme.qml8
-rw-r--r--Source/WebKit2/UIProcess/API/qt/tests/qmltests/common/qrctest.html6
-rw-r--r--Source/WebKit2/UIProcess/API/qt/tests/qmltests/resources.qrc1
7 files changed, 98 insertions, 0 deletions
diff --git a/Source/WebKit2/ChangeLog b/Source/WebKit2/ChangeLog
index 4a63d2ce4..f6c99bedf 100644
--- a/Source/WebKit2/ChangeLog
+++ b/Source/WebKit2/ChangeLog
@@ -1,3 +1,32 @@
+2013-01-24 Michael Brüning <michael.bruning@digia.com>
+
+ [Qt][WK2] Pages / resources cannot be loaded from qrc files.
+ https://bugs.webkit.org/show_bug.cgi?id=107031
+
+ Reviewed by Jocelyn Turcotte.
+
+ Enables WebKit2 Qt applications to load files from the bundled
+ qrc files. This is achieved by adding a url scheme handler for
+ the "qrc" scheme using the application scheme handler and ignoring
+ all handlers for the qrc application scheme that the application might
+ set.
+
+ * UIProcess/API/qt/qquickurlschemedelegate.cpp:
+ (QQuickQrcSchemeDelegate::QQuickQrcSchemeDelegate):
+ (QQuickQrcSchemeDelegate::readResourceAndSend):
+ * UIProcess/API/qt/qquickurlschemedelegate_p.h:
+ (QQuickQrcSchemeDelegate):
+ * UIProcess/API/qt/qquickwebview.cpp:
+ (QQuickWebViewPrivate::initialize):
+ (QQuickWebViewExperimental::schemeDelegates_Append):
+ (QQuickWebViewExperimental::invokeApplicationSchemeHandler):
+ * UIProcess/API/qt/tests/qmltests/WebView/tst_applicationScheme.qml:
+ * UIProcess/API/qt/tests/qmltests/common/qrctest.html: Added.
+ * UIProcess/API/qt/tests/qmltests/resources.qrc:
+
+ (WebKit::NetworkResourceLoader::connectionToWebProcessDidClose):
+ * NetworkProcess/NetworkResourceLoader.h:
+
2013-01-17 Poul Sysolyatin <psytonx@gmail.com>
32-bit build for Qt5 on Mac OS fails.
diff --git a/Source/WebKit2/UIProcess/API/qt/qquickurlschemedelegate.cpp b/Source/WebKit2/UIProcess/API/qt/qquickurlschemedelegate.cpp
index e5d63043b..19f14d5c4 100644
--- a/Source/WebKit2/UIProcess/API/qt/qquickurlschemedelegate.cpp
+++ b/Source/WebKit2/UIProcess/API/qt/qquickurlschemedelegate.cpp
@@ -24,6 +24,10 @@
#include "qquicknetworkreply_p.h"
#include "qquicknetworkrequest_p.h"
+#include <QtCore/QFile>
+#include <QtCore/QFileInfo>
+#include <QtCore/QMimeDatabase>
+
QQuickUrlSchemeDelegate::QQuickUrlSchemeDelegate(QObject* parent)
: QObject(parent)
, m_request(new QQuickNetworkRequest(this))
@@ -51,4 +55,27 @@ QQuickNetworkReply* QQuickUrlSchemeDelegate::reply() const
return m_reply;
}
+QQuickQrcSchemeDelegate::QQuickQrcSchemeDelegate(const QUrl& url)
+ : QQuickUrlSchemeDelegate()
+ , m_fileName(QLatin1Char(':') + url.path())
+{
+}
+
+void QQuickQrcSchemeDelegate::readResourceAndSend()
+{
+ QFile file(m_fileName);
+ QFileInfo fileInfo(file);
+ if (fileInfo.isDir() || !file.open(QIODevice::ReadOnly | QIODevice::Unbuffered))
+ return;
+
+ QByteArray fileData(file.readAll());
+ QMimeDatabase mimeDb;
+ QMimeType mimeType = mimeDb.mimeTypeForFileNameAndData(m_fileName, fileData);
+ file.close();
+
+ reply()->setData(fileData);
+ reply()->setContentType(mimeType.name());
+ reply()->send();
+}
+
#include "moc_qquickurlschemedelegate_p.cpp"
diff --git a/Source/WebKit2/UIProcess/API/qt/qquickurlschemedelegate_p.h b/Source/WebKit2/UIProcess/API/qt/qquickurlschemedelegate_p.h
index 6ee602754..596d3c266 100644
--- a/Source/WebKit2/UIProcess/API/qt/qquickurlschemedelegate_p.h
+++ b/Source/WebKit2/UIProcess/API/qt/qquickurlschemedelegate_p.h
@@ -23,6 +23,7 @@
#include "qwebkitglobal.h"
#include <QObject>
+#include <QtCore/QUrl>
#include <QtQuick/qquickitem.h>
class QQuickNetworkRequest;
@@ -53,6 +54,16 @@ private:
QML_DECLARE_TYPE(QQuickUrlSchemeDelegate)
+class QQuickQrcSchemeDelegate : public QQuickUrlSchemeDelegate {
+ Q_OBJECT
+public:
+ QQuickQrcSchemeDelegate(const QUrl& url);
+ void readResourceAndSend();
+
+private:
+ QString m_fileName;
+};
+
#endif // qquickurlschemedelegate_p_h
diff --git a/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp b/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp
index 437d08b94..bf742ad11 100644
--- a/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp
+++ b/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp
@@ -323,6 +323,7 @@ void QQuickWebViewPrivate::initialize(WKContextRef contextRef, WKPageGroupRef pa
pageClient.initialize(q_ptr, pageViewPrivate->eventHandler.data(), &undoController);
webPageProxy->initializeWebPage();
+ webPageProxy->registerApplicationScheme(ASCIILiteral("qrc"));
q_ptr->setAcceptedMouseButtons(Qt::MouseButtonMask);
q_ptr->setAcceptHoverEvents(true);
@@ -1291,6 +1292,12 @@ QQuickUrlSchemeDelegate* QQuickWebViewExperimental::schemeDelegates_At(QQmlListP
void QQuickWebViewExperimental::schemeDelegates_Append(QQmlListProperty<QQuickUrlSchemeDelegate>* property, QQuickUrlSchemeDelegate *scheme)
{
+ if (!scheme->scheme().compare(QLatin1String("qrc"), Qt::CaseInsensitive)) {
+ qWarning("WARNING: The qrc scheme is reserved to be handled internally. The handler will be ignored.");
+ delete scheme;
+ return;
+ }
+
QObject* schemeParent = property->object;
scheme->setParent(schemeParent);
QQuickWebViewExperimental* webViewExperimental = qobject_cast<QQuickWebViewExperimental*>(property->object->parent());
@@ -1328,6 +1335,15 @@ QQmlListProperty<QQuickUrlSchemeDelegate> QQuickWebViewExperimental::schemeDeleg
void QQuickWebViewExperimental::invokeApplicationSchemeHandler(PassRefPtr<QtRefCountedNetworkRequestData> request)
{
RefPtr<QtRefCountedNetworkRequestData> req = request;
+ if (req->data().m_scheme.startsWith("qrc", false)) {
+ QQuickQrcSchemeDelegate qrcDelegate(QUrl(QString(req->data().m_urlString)));
+ qrcDelegate.request()->setNetworkRequestData(req);
+ qrcDelegate.reply()->setNetworkRequestData(req);
+ qrcDelegate.reply()->setWebViewExperimental(this);
+ qrcDelegate.readResourceAndSend();
+ return;
+ }
+
const QObjectList children = schemeParent->children();
for (int index = 0; index < children.count(); index++) {
QQuickUrlSchemeDelegate* delegate = qobject_cast<QQuickUrlSchemeDelegate*>(children.at(index));
diff --git a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_applicationScheme.qml b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_applicationScheme.qml
index 4fe081298..e561e1a32 100644
--- a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_applicationScheme.qml
+++ b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_applicationScheme.qml
@@ -113,5 +113,13 @@ TestWebView {
verify(webView.waitForLoadSucceeded())
compare(webView.title, "title with copyright ©")
}
+
+ function test_qrcScheme() {
+ var testUrl = "qrc:///common/qrctest.html"
+ webView.url = testUrl
+ verify(webView.waitForLoadSucceeded())
+ compare(webView.title, "Loaded from qrc.")
+
+ }
}
}
diff --git a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/common/qrctest.html b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/common/qrctest.html
new file mode 100644
index 000000000..98f25fb7e
--- /dev/null
+++ b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/common/qrctest.html
@@ -0,0 +1,6 @@
+<html>
+<head><title>Loaded from qrc.</title></head>
+<body>
+Hello. I was loaded from a qrc file. Amazing.
+</body>
+</html>
diff --git a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/resources.qrc b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/resources.qrc
index 1696aaac1..f251865ef 100644
--- a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/resources.qrc
+++ b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/resources.qrc
@@ -1,5 +1,6 @@
<RCC>
<qresource prefix="/">
<file>common/change-document-title.js</file>
+ <file>common/qrctest.html</file>
</qresource>
</RCC>