Changeset 140676 in webkit


Ignore:
Timestamp:
Jan 24, 2013 4:25:19 AM (11 years ago)
Author:
michael.bruning@digia.com
Message:

[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:
Location:
trunk/Source/WebKit2
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r140667 r140676  
     12013-01-24  Michael Brüning  <michael.bruning@digia.com>
     2
     3        [Qt][WK2] Pages / resources cannot be loaded from qrc files.
     4        https://bugs.webkit.org/show_bug.cgi?id=107031
     5
     6        Reviewed by Jocelyn Turcotte.
     7
     8        Enables WebKit2 Qt applications to load files from the bundled
     9        qrc files. This is achieved by adding a url scheme handler for
     10        the "qrc" scheme using the application scheme handler and ignoring
     11        all handlers for the qrc application scheme that the application might
     12        set.
     13
     14        * UIProcess/API/qt/qquickurlschemedelegate.cpp:
     15        (QQuickQrcSchemeDelegate::QQuickQrcSchemeDelegate):
     16        (QQuickQrcSchemeDelegate::readResourceAndSend):
     17        * UIProcess/API/qt/qquickurlschemedelegate_p.h:
     18        (QQuickQrcSchemeDelegate):
     19        * UIProcess/API/qt/qquickwebview.cpp:
     20        (QQuickWebViewPrivate::initialize):
     21        (QQuickWebViewExperimental::schemeDelegates_Append):
     22        (QQuickWebViewExperimental::invokeApplicationSchemeHandler):
     23        * UIProcess/API/qt/tests/qmltests/WebView/tst_applicationScheme.qml:
     24        * UIProcess/API/qt/tests/qmltests/common/qrctest.html: Added.
     25        * UIProcess/API/qt/tests/qmltests/resources.qrc:
     26
    1272013-01-24  Krzysztof Czech  <k.czech@samsung.com>
    228
  • trunk/Source/WebKit2/UIProcess/API/qt/qquickurlschemedelegate.cpp

    r104193 r140676  
    2424#include "qquicknetworkreply_p.h"
    2525#include "qquicknetworkrequest_p.h"
     26
     27#include <QtCore/QFile>
     28#include <QtCore/QFileInfo>
     29#include <QtCore/QMimeDatabase>
     30#include <QtCore/QUrl>
    2631
    2732QQuickUrlSchemeDelegate::QQuickUrlSchemeDelegate(QObject* parent)
     
    5257}
    5358
     59QQuickQrcSchemeDelegate::QQuickQrcSchemeDelegate(const QUrl& url)
     60    : QQuickUrlSchemeDelegate()
     61    , m_fileName(QLatin1Char(':') + url.path())
     62{
     63}
     64
     65void QQuickQrcSchemeDelegate::readResourceAndSend()
     66{
     67    QFile file(m_fileName);
     68    QFileInfo fileInfo(file);
     69    if (fileInfo.isDir() || !file.open(QIODevice::ReadOnly | QIODevice::Unbuffered))
     70        return;
     71
     72    QByteArray fileData(file.readAll());
     73    QMimeDatabase mimeDb;
     74    QMimeType mimeType = mimeDb.mimeTypeForFileNameAndData(m_fileName, fileData);
     75    file.close();
     76
     77    reply()->setData(fileData);
     78    reply()->setContentType(mimeType.name());
     79    reply()->send();
     80}
     81
    5482#include "moc_qquickurlschemedelegate_p.cpp"
  • trunk/Source/WebKit2/UIProcess/API/qt/qquickurlschemedelegate_p.h

    r104193 r140676  
    2828class QQuickNetworkRequest;
    2929class QQuickNetworkReply;
     30class QUrl;
    3031
    3132class QWEBKIT_EXPORT QQuickUrlSchemeDelegate : public QObject {
     
    5455QML_DECLARE_TYPE(QQuickUrlSchemeDelegate)
    5556
     57class QQuickQrcSchemeDelegate : public QQuickUrlSchemeDelegate {
     58    Q_OBJECT
     59public:
     60    QQuickQrcSchemeDelegate(const QUrl& url);
     61    void readResourceAndSend();
     62
     63private:
     64    QString m_fileName;
     65};
     66
    5667#endif // qquickurlschemedelegate_p_h
    5768
  • trunk/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp

    r138723 r140676  
    329329    pageClient.initialize(q_ptr, pageViewPrivate->eventHandler.data(), &undoController);
    330330    webPageProxy->initializeWebPage();
     331    webPageProxy->registerApplicationScheme(ASCIILiteral("qrc"));
    331332
    332333    q_ptr->setAcceptedMouseButtons(Qt::MouseButtonMask);
     
    13131314void QQuickWebViewExperimental::schemeDelegates_Append(QQmlListProperty<QQuickUrlSchemeDelegate>* property, QQuickUrlSchemeDelegate *scheme)
    13141315{
     1316    if (!scheme->scheme().compare(QLatin1String("qrc"), Qt::CaseInsensitive)) {
     1317        qWarning("WARNING: The qrc scheme is reserved to be handled internally. The handler will be ignored.");
     1318        delete scheme;
     1319        return;
     1320    }
     1321
    13151322    QObject* schemeParent = property->object;
    13161323    scheme->setParent(schemeParent);
     
    13501357{
    13511358    RefPtr<QtRefCountedNetworkRequestData> req = request;
     1359    if (req->data().m_scheme.startsWith("qrc", false)) {
     1360        QQuickQrcSchemeDelegate qrcDelegate(QUrl(QString(req->data().m_urlString)));
     1361        qrcDelegate.request()->setNetworkRequestData(req);
     1362        qrcDelegate.reply()->setNetworkRequestData(req);
     1363        qrcDelegate.reply()->setWebViewExperimental(this);
     1364        qrcDelegate.readResourceAndSend();
     1365        return;
     1366    }
     1367
    13521368    const QObjectList children = schemeParent->children();
    13531369    for (int index = 0; index < children.count(); index++) {
  • trunk/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_applicationScheme.qml

    r114129 r140676  
    114114            compare(webView.title, "title with copyright ©")
    115115        }
     116
     117        function test_qrcScheme() {
     118            var testUrl = "qrc:///common/qrctest.html"
     119            webView.url = testUrl
     120            verify(webView.waitForLoadSucceeded())
     121            compare(webView.title, "Loaded from qrc.")
     122
     123        }
    116124    }
    117125}
  • trunk/Source/WebKit2/UIProcess/API/qt/tests/qmltests/resources.qrc

    r118756 r140676  
    22    <qresource prefix="/">
    33        <file>common/change-document-title.js</file>
     4        <file>common/qrctest.html</file>
    45    </qresource>
    56</RCC>
Note: See TracChangeset for help on using the changeset viewer.