fix a small hole whereby a JS applet could load any SVG from disk (or any file, for that matter, though not gain any access to the data therein) instead of being confined just to its package(s) and the Plasma::Theme

svn path=/trunk/KDE/kdebase/runtime/; revision=1179255
This commit is contained in:
Aaron J. Seigo 2010-09-24 22:51:16 +00:00
parent de289177d9
commit f968cb8033
4 changed files with 135 additions and 30 deletions

View File

@ -6,6 +6,7 @@ set(simple_javascript_engine_SRCS
plasmoid/appletauthorization.cpp
plasmoid/appletinterface.cpp
plasmoid/simplejavascriptapplet.cpp
plasmoid/themedsvg.cpp
simplebindings/animationgroup.cpp
simplebindings/anchorlayout.cpp
simplebindings/dataenginereceiver.cpp

View File

@ -59,11 +59,12 @@
#include "appletinterface.h"
#include "scriptenv.h"
#include "simplebindings/animationgroup.h"
#include "simplebindings/bytearrayclass.h"
#include "simplebindings/dataengine.h"
#include "simplebindings/dataenginereceiver.h"
#include "simplebindings/i18n.h"
#include "simplebindings/bytearrayclass.h"
#include "simplebindings/variant.h"
#include "themedsvg.h"
using namespace Plasma;
@ -698,25 +699,6 @@ QScriptValue SimpleJavaScriptApplet::loadui(QScriptContext *context, QScriptEngi
return engine->newQObject(w, QScriptEngine::AutoOwnership);
}
QString SimpleJavaScriptApplet::findSvg(QScriptContext *context, QScriptEngine *engine, const QString &file)
{
AppletInterface *interface = AppletInterface::extract(engine);
if (!interface) {
return file;
}
QString path = interface->file("images", file + ".svg");
if (path.isEmpty()) {
path = interface->file("images", file + ".svgz");
if (path.isEmpty()) {
return file;
}
}
return path;
}
QScriptValue SimpleJavaScriptApplet::newPlasmaSvg(QScriptContext *context, QScriptEngine *engine)
{
if (context->argumentCount() == 0) {
@ -726,11 +708,13 @@ QScriptValue SimpleJavaScriptApplet::newPlasmaSvg(QScriptContext *context, QScri
const QString filename = context->argument(0).toString();
bool parentedToApplet = false;
QGraphicsWidget *parent = extractParent(context, engine, 1, &parentedToApplet);
Svg *svg = new Svg(parent);
svg->setImagePath(parentedToApplet ? findSvg(context, engine, filename) : filename);
QScriptValue fun = engine->newQObject(svg);
ScriptEnv::registerEnums(fun, *svg->metaObject());
return fun;
Svg *svg = new ThemedSvg(parent);
svg->setImagePath(ThemedSvg::findSvg(engine, filename));
QScriptValue obj = engine->newQObject(svg);
ScriptEnv::registerEnums(obj, *svg->metaObject());
return obj;
}
QScriptValue SimpleJavaScriptApplet::newPlasmaFrameSvg(QScriptContext *context, QScriptEngine *engine)
@ -743,12 +727,13 @@ QScriptValue SimpleJavaScriptApplet::newPlasmaFrameSvg(QScriptContext *context,
bool parentedToApplet = false;
QGraphicsWidget *parent = extractParent(context, engine, 1, &parentedToApplet);
FrameSvg *frameSvg = new FrameSvg(parent);
frameSvg->setImagePath(parentedToApplet ? filename : findSvg(context, engine, filename));
FrameSvg *frameSvg = new ThemedFrameSvg(parent);
frameSvg->setImagePath(ThemedSvg::findSvg(engine, filename));
QScriptValue fun = engine->newQObject(frameSvg);
ScriptEnv::registerEnums(fun, *frameSvg->metaObject());
return fun;
QScriptValue obj = engine->newQObject(frameSvg);
ScriptEnv::registerEnums(obj, *frameSvg->metaObject());
return obj;
}
QScriptValue SimpleJavaScriptApplet::newPlasmaExtenderItem(QScriptContext *context, QScriptEngine *engine)

View File

@ -0,0 +1,66 @@
/*
* Copyright 2007-2008,2010 Richard J. Moore <rich@kde.org>
* Copyright 2009 Aaron J. Seigo <aseigo@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License version 2 as
* published by the Free Software Foundation
*
* 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 "themedsvg.h"
#include <KDebug>
#include "appletinterface.h"
ThemedSvg::ThemedSvg(QObject *parent)
: Plasma::Svg(parent)
{
}
void ThemedSvg::setThemedImagePath(const QString &path)
{
setImagePath(findSvg(engine(), path));
}
QString ThemedSvg::findSvg(QScriptEngine *engine, const QString &file)
{
AppletInterface *interface = AppletInterface::extract(engine);
if (!interface) {
return QString();
}
QString path = interface->file("images", file + ".svg");
if (path.isEmpty()) {
path = interface->file("images", file + ".svgz");
if (path.isEmpty()) {
path = Plasma::Theme::defaultTheme()->imagePath(file);
}
}
return path;
}
ThemedFrameSvg::ThemedFrameSvg(QObject *parent)
: Plasma::FrameSvg(parent)
{
}
void ThemedFrameSvg::setThemedImagePath(const QString &path)
{
setImagePath(ThemedSvg::findSvg(engine(), path));
}
#include "themedsvg.moc"

View File

@ -0,0 +1,53 @@
/*
* Copyright 2007-2008,2010 Richard J. Moore <rich@kde.org>
* Copyright 2009 Aaron J. Seigo <aseigo@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License version 2 as
* published by the Free Software Foundation
*
* 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 THEMEDSVG_H
#define THEMEDSVG_H
#include <QScriptable>
#include <Plasma/Svg>
#include <Plasma/FrameSvg>
class ThemedSvg : public Plasma::Svg, public QScriptable
{
Q_OBJECT
Q_PROPERTY(QString imagePath READ imagePath WRITE setThemedImagePath)
public:
ThemedSvg(QObject *parent = 0);
void setThemedImagePath(const QString &path);
static QString findSvg(QScriptEngine *engine, const QString &file);
};
class ThemedFrameSvg : public Plasma::FrameSvg, public QScriptable
{
Q_OBJECT
Q_PROPERTY(QString imagePath READ imagePath WRITE setThemedImagePath)
public:
ThemedFrameSvg(QObject *parent = 0);
void setThemedImagePath(const QString &path);
};
#endif