use a custom network access manager, based on the kio one, but has a
special handling for package:/foo urls svn path=/trunk/KDE/kdebase/runtime/; revision=1188205
This commit is contained in:
parent
2586f3ecb8
commit
155dc2d056
@ -114,6 +114,8 @@ install(FILES data/plasma-javascriptaddon.desktop DESTINATION ${SERVICETYPES_INS
|
||||
set(declarative_appletscript_SRCS
|
||||
common/javascriptaddonpackagestructure.cpp
|
||||
common/declarativescriptenv.cpp
|
||||
declarative/packageaccessmanager.cpp
|
||||
declarative/packageaccessmanagerfactory.cpp
|
||||
plasmoid/abstractjsappletscript.cpp
|
||||
plasmoid/appletauthorization.cpp
|
||||
plasmoid/appletinterface.cpp
|
||||
|
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2010 Marco Martin <notmart@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "packageaccessmanager.h"
|
||||
|
||||
#include <Plasma/Package>
|
||||
|
||||
PackageAccessManager::PackageAccessManager(const Plasma::Package *package, QObject *parent)
|
||||
: KIO::AccessManager(parent),
|
||||
m_package(package)
|
||||
{
|
||||
}
|
||||
|
||||
PackageAccessManager::~PackageAccessManager()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
QNetworkReply *PackageAccessManager::createRequest(Operation op, const QNetworkRequest &req, QIODevice *outgoingData)
|
||||
{
|
||||
QUrl reqUrl(req.url());
|
||||
|
||||
if (reqUrl.scheme() == "plasmapackage") {
|
||||
QNetworkRequest request = req;
|
||||
reqUrl.setScheme("file");
|
||||
reqUrl.setPath(m_package->path()+"/contents/"+reqUrl.path());
|
||||
request.setUrl(reqUrl);
|
||||
return KIO::AccessManager::createRequest(op, request, outgoingData);
|
||||
} else {
|
||||
return KIO::AccessManager::createRequest(op, req, outgoingData);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
43
scriptengines/javascript/declarative/packageaccessmanager.h
Normal file
43
scriptengines/javascript/declarative/packageaccessmanager.h
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2010 Marco Martin <notmart@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef PACKAGEACCESSMANAGER_H
|
||||
#define PACKAGEACCESSMANAGER_H
|
||||
|
||||
#include <kio/accessmanager.h>
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
class Package;
|
||||
}
|
||||
|
||||
class PackageAccessManager : public KIO::AccessManager
|
||||
{
|
||||
public:
|
||||
PackageAccessManager(const Plasma::Package *package, QObject *parent = 0);
|
||||
~PackageAccessManager();
|
||||
|
||||
protected:
|
||||
QNetworkReply *createRequest(Operation op, const QNetworkRequest &req, QIODevice *outgoingData = 0);
|
||||
|
||||
private:
|
||||
const Plasma::Package *m_package;
|
||||
};
|
||||
|
||||
#endif
|
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2010 Marco Martin <notmart@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "packageaccessmanagerfactory.h"
|
||||
|
||||
#include <Plasma/Package>
|
||||
|
||||
#include "packageaccessmanager.h"
|
||||
|
||||
PackageAccessManagerFactory::PackageAccessManagerFactory(const Plasma::Package *package)
|
||||
: QDeclarativeNetworkAccessManagerFactory(),
|
||||
m_package(package)
|
||||
{
|
||||
}
|
||||
|
||||
PackageAccessManagerFactory::~PackageAccessManagerFactory()
|
||||
{
|
||||
}
|
||||
|
||||
QNetworkAccessManager *PackageAccessManagerFactory::create(QObject *parent)
|
||||
{
|
||||
return new PackageAccessManager(m_package, parent);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2010 Marco Martin <notmart@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef PACKAGEACCESSMANAGERFACTORY_H
|
||||
#define PACKAGEACCESSMANAGERFACTORY_H
|
||||
|
||||
#include <QDeclarativeNetworkAccessManagerFactory>
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
class Package;
|
||||
}
|
||||
|
||||
class PackageAccessManagerFactory : public QDeclarativeNetworkAccessManagerFactory
|
||||
{
|
||||
public:
|
||||
PackageAccessManagerFactory(const Plasma::Package *package);
|
||||
~PackageAccessManagerFactory();
|
||||
QNetworkAccessManager *create(QObject *parent);
|
||||
|
||||
private:
|
||||
const Plasma::Package *m_package;
|
||||
};
|
||||
|
||||
#endif
|
@ -49,6 +49,7 @@
|
||||
#include "plasmoid/themedsvg.h"
|
||||
|
||||
#include "common/scriptenv.h"
|
||||
#include "declarative/packageaccessmanagerfactory.h"
|
||||
#include "simplebindings/bytearrayclass.h"
|
||||
#include "simplebindings/dataenginereceiver.h"
|
||||
#include "simplebindings/i18n.h"
|
||||
@ -78,8 +79,13 @@ bool DeclarativeAppletScript::init()
|
||||
m_declarativeWidget = new Plasma::DeclarativeWidget(applet());
|
||||
m_declarativeWidget->setInitializationDelayed(true);
|
||||
|
||||
//make possible to import extensions from the package
|
||||
//FIXME: probably to be removed, would make possible to use native code from within the package :/
|
||||
m_declarativeWidget->engine()->addImportPath(package()->path()+"/contents/script");
|
||||
|
||||
//use our own custom network access manager that will acces Plasma packages and to manage security (i.e. deny access to remote stuff when the proper extension isn't enabled
|
||||
m_declarativeWidget->engine()->setNetworkAccessManagerFactory(new PackageAccessManagerFactory(package()));
|
||||
|
||||
m_declarativeWidget->setQmlPath(mainScript());
|
||||
|
||||
if (!m_declarativeWidget->engine() || !m_declarativeWidget->engine()->rootContext() || !m_declarativeWidget->engine()->rootContext()->isValid() || m_declarativeWidget->mainComponent()->isError()) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user