working package redirection for qml files
This commit is contained in:
parent
930c8647e6
commit
b1c49c5d44
|
@ -20,10 +20,12 @@
|
|||
#include "packageurlinterceptor.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QQmlEngine>
|
||||
|
||||
PackageUrlInterceptor::PackageUrlInterceptor(const Plasma::Package &p)
|
||||
PackageUrlInterceptor::PackageUrlInterceptor(QQmlEngine *engine, const Plasma::Package &p)
|
||||
: QQmlAbstractUrlInterceptor(),
|
||||
m_package(p)
|
||||
m_package(p),
|
||||
m_engine(engine)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -35,6 +37,44 @@ QUrl PackageUrlInterceptor::intercept(const QUrl &path, QQmlAbstractUrlIntercept
|
|||
{
|
||||
//qDebug() << "Intercepted URL:" << path;
|
||||
|
||||
//TODO: security: permission for remote urls
|
||||
if (!path.isLocalFile() ) {
|
||||
return path;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case QQmlAbstractUrlInterceptor::QmlFile:
|
||||
if (path.path().startsWith(m_package.path())) {
|
||||
//qDebug() << "Found URL in package" << path;
|
||||
QStringList components = path.toLocalFile().split("/");
|
||||
if (components.count() < 2) {
|
||||
return path;
|
||||
}
|
||||
QString filename = components.last();
|
||||
components.pop_back();
|
||||
QString type = components.last();
|
||||
if (type == "ui" || type == "config") {
|
||||
//qDebug() << "Returning" << QUrl::fromLocalFile(m_package.filePath(type.toLatin1(), filename));
|
||||
return QUrl::fromLocalFile(m_package.filePath(type.toLatin1(), filename));
|
||||
}
|
||||
//forbid to load random absolute paths
|
||||
} else {
|
||||
foreach (const QString &import, m_engine->importPathList()) {
|
||||
//it's from an import, good
|
||||
//TODO: implement imports whitelist?
|
||||
if (path.path().startsWith(import)) {
|
||||
// qDebug() << "Found import, access granted";
|
||||
return path;
|
||||
}
|
||||
}
|
||||
qWarning() << "Access denied for url" << path;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,16 +24,19 @@
|
|||
|
||||
#include <Plasma/Package>
|
||||
|
||||
class QQmlEngine;
|
||||
|
||||
class PackageUrlInterceptor: public QQmlAbstractUrlInterceptor
|
||||
{
|
||||
public:
|
||||
PackageUrlInterceptor(const Plasma::Package &p);
|
||||
PackageUrlInterceptor(QQmlEngine *engine, const Plasma::Package &p);
|
||||
virtual ~PackageUrlInterceptor();
|
||||
|
||||
virtual QUrl intercept(const QUrl &path, QQmlAbstractUrlInterceptor::DataType type);
|
||||
|
||||
private:
|
||||
Plasma::Package m_package;
|
||||
QQmlEngine *m_engine;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -115,7 +115,7 @@ void AppletInterface::init()
|
|||
|
||||
//Hook generic url resolution to the applet package as well
|
||||
//TODO: same thing will have to be done for every qqmlengine: PackageUrlInterceptor is material for plasmaquick?
|
||||
engine->setUrlInterceptor(new PackageUrlInterceptor(m_appletScriptEngine->package()));
|
||||
engine->setUrlInterceptor(new PackageUrlInterceptor(engine, m_appletScriptEngine->package()));
|
||||
|
||||
m_qmlObject->setSource(QUrl::fromLocalFile(m_appletScriptEngine->mainScript()));
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user