remove Applet::hasAuthorization()

authorization will have to be done at QML level to have any hope to work
This commit is contained in:
Marco Martin 2013-02-12 12:18:42 +01:00
parent b9036999f2
commit cb43bb392c
11 changed files with 12 additions and 144 deletions

View File

@ -927,12 +927,6 @@ void Applet::createConfigurationInterface(KConfigDialog *parent)
// do not put anything here ...
}
bool Applet::hasAuthorization(const QString &constraint) const
{
KConfigGroup constraintGroup(KSharedConfig::openConfig(), "Constraints");
return constraintGroup.readEntry(constraint, true);
}
void Applet::setAssociatedApplication(const QString &string)
{
AssociatedApplicationManager::self()->setApplication(this, string);
@ -940,7 +934,6 @@ void Applet::setAssociatedApplication(const QString &string)
QAction *runAssociatedApplication = d->actions->action("run associated application");
if (runAssociatedApplication) {
bool valid = AssociatedApplicationManager::self()->appletHasValidAssociatedApplication(this);
valid = valid && hasAuthorization("LaunchApp"); //obey security!
runAssociatedApplication->setVisible(valid);
runAssociatedApplication->setEnabled(valid);
}
@ -953,7 +946,6 @@ void Applet::setAssociatedApplicationUrls(const QList<QUrl> &urls)
QAction *runAssociatedApplication = d->actions->action("run associated application");
if (runAssociatedApplication) {
bool valid = AssociatedApplicationManager::self()->appletHasValidAssociatedApplication(this);
valid = valid && hasAuthorization("LaunchApp"); //obey security!
runAssociatedApplication->setVisible(valid);
runAssociatedApplication->setEnabled(valid);
}
@ -971,9 +963,7 @@ QList<QUrl> Applet::associatedApplicationUrls() const
void Applet::runAssociatedApplication()
{
if (hasAuthorization("LaunchApp")) {
AssociatedApplicationManager::self()->run(this);
}
AssociatedApplicationManager::self()->run(this);
}
bool Applet::hasValidAssociatedApplication() const

View File

@ -405,13 +405,6 @@ class PLASMA_EXPORT Applet : public QObject
*/
virtual void removeAssociatedWidget(QWidget *widget);
/**
* Returns true if the applet is allowed to perform functions covered by the given constraint
* eg. hasAuthorization("FileDialog") returns true if applets are allowed to show filedialogs.
* @since 4.3
*/
bool hasAuthorization(const QString &constraint) const;
// ASSOCIATED APPLICATION
/**
* Sets an application associated to this applet, that will be

View File

@ -17,7 +17,6 @@ set(declarative_appletscript_SRCS
declarative/packageaccessmanager.cpp
declarative/packageaccessmanagerfactory.cpp
declarative/qmlobject.cpp
plasmoid/appletauthorization.cpp
plasmoid/appletinterface.cpp
plasmoid/declarativeappletscript.cpp
)

View File

@ -21,8 +21,6 @@
#include <QNetworkReply>
#include "plasmoid/appletauthorization.h"
class ErrorReply : public QNetworkReply
{
public:
@ -47,10 +45,9 @@ public:
}
};
PackageAccessManager::PackageAccessManager(const Plasma::Package &package, AppletAuthorization *auth, QObject *parent)
PackageAccessManager::PackageAccessManager(const Plasma::Package &package, QObject *parent)
: KIO::AccessManager(parent),
m_package(package),
m_auth(auth)
m_package(package)
{
}
@ -69,9 +66,8 @@ QNetworkReply *PackageAccessManager::createRequest(QNetworkAccessManager::Operat
reqUrl.setPath(m_package.filePath(0, reqUrl.path()));
request.setUrl(reqUrl);
return QNetworkAccessManager::createRequest(op, request, outgoingData);
} else if ((reqUrl.scheme() == "http" && !m_auth->authorizeRequiredExtension("http")) ||
((reqUrl.scheme() == "file" || reqUrl.scheme() == "desktop") && !m_auth->authorizeRequiredExtension("localio")) ||
(!m_auth->authorizeRequiredExtension("networkio"))) {
} else if ((reqUrl.scheme() == "http") ||
((reqUrl.scheme() == "file" || reqUrl.scheme() == "desktop"))) {
return new ErrorReply(op, req);
} else {
#ifndef PLASMA_NO_KIO

View File

@ -35,8 +35,6 @@ namespace Plasma
class Package;
}
class AppletAuthorization;
class PackageAccessManager :
#ifdef PLASMA_NO_KIO
public QNetworkAccessManager
@ -45,7 +43,7 @@ public KIO::AccessManager
#endif
{
public:
PackageAccessManager(const Plasma::Package &package, AppletAuthorization *auth, QObject *parent = 0);
PackageAccessManager(const Plasma::Package &package, QObject *parent = 0);
~PackageAccessManager();
protected:
@ -53,7 +51,6 @@ protected:
private:
Plasma::Package m_package;
AppletAuthorization *m_auth;
};
#endif

View File

@ -22,10 +22,9 @@
#include "packageaccessmanager.h"
#include "plasmoid/appletauthorization.h"
PackageAccessManagerFactory::PackageAccessManagerFactory(const Plasma::Package &package, AppletAuthorization *auth)
PackageAccessManagerFactory::PackageAccessManagerFactory(const Plasma::Package &package)
: QQmlNetworkAccessManagerFactory(),
m_package(package),
m_auth(auth)
m_package(package)
{
}
@ -35,7 +34,7 @@ PackageAccessManagerFactory::~PackageAccessManagerFactory()
QNetworkAccessManager *PackageAccessManagerFactory::create(QObject *parent)
{
return new PackageAccessManager(m_package, m_auth, parent);
return new PackageAccessManager(m_package, parent);
}

View File

@ -30,13 +30,12 @@ class AppletAuthorization;
class PackageAccessManagerFactory : public QQmlNetworkAccessManagerFactory
{
public:
PackageAccessManagerFactory(const Plasma::Package &package, AppletAuthorization *auth);
PackageAccessManagerFactory(const Plasma::Package &package);
~PackageAccessManagerFactory();
QNetworkAccessManager *create(QObject *parent);
private:
Plasma::Package m_package;
AppletAuthorization *m_auth;
};
#endif

View File

@ -1,58 +0,0 @@
/*
* Copyright 2010 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 <kdemacros.h>
#include <KAuthorized>
#include <klocalizedstring.h>
#include "appletauthorization.h"
#include <Plasma/AppletScript>
#include <Plasma/Applet>
AppletAuthorization::AppletAuthorization(Plasma::AppletScript *scriptEngine)
: Authorization(),
m_scriptEngine(scriptEngine)
{
}
bool AppletAuthorization::authorizeRequiredExtension(const QString &extension)
{
bool ok = m_scriptEngine->applet()->hasAuthorization(extension);
if (!ok) {
m_scriptEngine->setFailedToLaunch(true,
i18n("Authorization for required extension '%1' was denied.",
extension));
}
return ok;
}
bool AppletAuthorization::authorizeOptionalExtension(const QString &extension)
{
return m_scriptEngine->applet()->hasAuthorization(extension);
}
bool AppletAuthorization::authorizeExternalExtensions()
{
return false;
}

View File

@ -1,44 +0,0 @@
/*
* Copyright 2010 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 APPLETAUTHORIZATION_H
#define APPLETAUTHORIZATION_H
#include "authorization.h"
namespace Plasma {
class AppletScript;
}
class SimpleJavaScriptApplet;
class AppletAuthorization : public Authorization
{
public:
AppletAuthorization(Plasma::AppletScript *scriptEngine);
bool authorizeRequiredExtension(const QString &extension);
bool authorizeOptionalExtension(const QString &extension);
bool authorizeExternalExtensions();
private:
Plasma::AppletScript *m_scriptEngine;
};
#endif

View File

@ -58,8 +58,7 @@ DeclarativeAppletScript::DeclarativeAppletScript(QObject *parent, const QVariant
m_qmlObject(0),
m_toolBoxObject(0),
m_interface(0),
m_env(0),
m_auth(this)
m_env(0)
{
qmlRegisterType<AppletInterface>();
Q_UNUSED(args);
@ -86,7 +85,7 @@ bool DeclarativeAppletScript::init()
QQmlNetworkAccessManagerFactory *factory = engine->networkAccessManagerFactory();
engine->setNetworkAccessManagerFactory(0);
delete factory;
engine->setNetworkAccessManagerFactory(new PackageAccessManagerFactory(package(), &m_auth));
engine->setNetworkAccessManagerFactory(new PackageAccessManagerFactory(package()));
m_qmlObject->setQmlPath(mainScript());

View File

@ -26,7 +26,6 @@
#include <QQmlEngine>
#include <Plasma/AppletScript>
#include "plasmoid/appletauthorization.h"
class AppletInterface;
@ -79,7 +78,6 @@ private:
AppletInterface *m_interface;
QObject *m_self;
ScriptEnv *m_env;
AppletAuthorization m_auth;
};
#endif