~ubuntu-branches/ubuntu/natty/kdebase-runtime/natty-proposed

« back to all changes in this revision

Viewing changes to plasma/scriptengines/javascript/declarative/packageaccessmanager.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-11-24 11:07:10 UTC
  • mto: (0.8.7 upstream)
  • mto: This revision was merged to the branch mainline in revision 129.
  • Revision ID: james.westby@ubuntu.com-20101124110710-6dbsyw0yh21qvn82
Tags: upstream-4.5.80
ImportĀ upstreamĀ versionĀ 4.5.80

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *   Copyright 2010 Marco Martin <notmart@gmail.com>
 
3
 *
 
4
 *   This program is free software; you can redistribute it and/or modify
 
5
 *   it under the terms of the GNU Library General Public License as
 
6
 *   published by the Free Software Foundation; either version 2, or
 
7
 *   (at your option) any later version.
 
8
 *
 
9
 *   This program is distributed in the hope that it will be useful,
 
10
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 *   GNU General Public License for more details
 
13
 *
 
14
 *   You should have received a copy of the GNU Library General Public
 
15
 *   License along with this program; if not, write to the
 
16
 *   Free Software Foundation, Inc.,
 
17
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
18
 */
 
19
 
 
20
#include "packageaccessmanager.h"
 
21
 
 
22
#include <QNetworkReply>
 
23
 
 
24
#include <Plasma/Package>
 
25
 
 
26
#include "plasmoid/appletauthorization.h"
 
27
 
 
28
class ErrorReply : public QNetworkReply
 
29
{
 
30
public:
 
31
    ErrorReply(QNetworkAccessManager::Operation op, const QNetworkRequest &req)
 
32
        : QNetworkReply()
 
33
    {
 
34
        setError(QNetworkReply::ContentOperationNotPermittedError, "The plasmoid has not been authorized to load remote content");
 
35
        setOperation(op);
 
36
        setRequest(req);
 
37
        setUrl(req.url());
 
38
    }
 
39
 
 
40
    qint64 readData(char *data, qint64 maxSize)
 
41
    {
 
42
        return 0;
 
43
    }
 
44
 
 
45
    void abort()
 
46
    {
 
47
    }
 
48
};
 
49
 
 
50
PackageAccessManager::PackageAccessManager(const Plasma::Package *package, AppletAuthorization *auth, QObject *parent)
 
51
    : KIO::AccessManager(parent),
 
52
      m_package(package),
 
53
      m_auth(auth)
 
54
{
 
55
}
 
56
 
 
57
PackageAccessManager::~PackageAccessManager()
 
58
{
 
59
}
 
60
 
 
61
 
 
62
QNetworkReply *PackageAccessManager::createRequest(QNetworkAccessManager::Operation op, const QNetworkRequest &req, QIODevice *outgoingData)
 
63
{
 
64
    QUrl reqUrl(req.url());
 
65
 
 
66
    if (reqUrl.scheme() == "plasmapackage") {
 
67
        QNetworkRequest request = req;
 
68
        reqUrl.setScheme("file");
 
69
        reqUrl.setPath(m_package->filePath(0, reqUrl.path()));
 
70
        request.setUrl(reqUrl);
 
71
        return QNetworkAccessManager::createRequest(op, request, outgoingData);
 
72
    } else if ((reqUrl.scheme() == "http" && !m_auth->authorizeRequiredExtension("http")) ||
 
73
               ((reqUrl.scheme() == "file" || reqUrl.scheme() == "desktop") && !m_auth->authorizeRequiredExtension("localio")) ||
 
74
               (!m_auth->authorizeRequiredExtension("networkio"))) {
 
75
        return new ErrorReply(op, req);
 
76
    } else {
 
77
        return KIO::AccessManager::createRequest(op, req, outgoingData);
 
78
    }
 
79
}
 
80
 
 
81
 
 
82