Commit 1912a8b9 authored by Alexander Lohnau's avatar Alexander Lohnau 💬
Browse files

Port away from KIO::AccessManager

This was a newly introduced usage, becuase in Qt6 we can no longer disallow external contant

Task: https://phabricator.kde.org/T12472
parent e9b940a1
Pipeline #221101 passed with stage
in 2 minutes and 25 seconds
......@@ -328,6 +328,10 @@ KQuickAddons::QuickViewSharedEngine *UnlockApp::createViewForScreen(QScreen *scr
});
view->engine()->rootContext()->setContextObject(new KLocalizedContext(view->engine()));
auto oldFactory = view->engine()->networkAccessManagerFactory();
view->engine()->setNetworkAccessManagerFactory(nullptr);
delete oldFactory;
view->engine()->setNetworkAccessManagerFactory(new NoAccessNetworkAccessManagerFactory);
if (!m_testing) {
if (QX11Info::isPlatformX11()) {
......@@ -382,12 +386,6 @@ KQuickAddons::QuickViewSharedEngine *UnlockApp::createViewForScreen(QScreen *scr
}
view->setResizeMode(KQuickAddons::QuickViewSharedEngine::SizeRootObjectToView);
// overwrite the factory set by kdeclarative
auto oldFactory = view->engine()->networkAccessManagerFactory();
view->engine()->setNetworkAccessManagerFactory(nullptr);
delete oldFactory;
view->engine()->setNetworkAccessManagerFactory(new NoAccessNetworkAccessManagerFactory);
QQmlProperty lockProperty(view->rootObject(), QStringLiteral("locked"));
lockProperty.write(m_immediateLock || (!m_noLock && !m_delayedLockTimer));
......
......@@ -19,15 +19,63 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "noaccessnetworkaccessmanagerfactory.h"
#include <KIO/AccessManager>
#include <KProtocolInfo>
#include <QNetworkAccessManager>
#include <QNetworkReply>
namespace ScreenLocker
{
class AccessDeniedNetworkReply : public QNetworkReply
{
Q_OBJECT
public:
explicit AccessDeniedNetworkReply(QNetworkAccessManager::Operation op, const QNetworkRequest &req, QObject *parent)
: QNetworkReply(parent)
{
setRequest(req);
setOpenMode(QIODevice::ReadOnly);
setUrl(req.url());
setOperation(op);
setError(QNetworkReply::ContentAccessDenied, QStringLiteral("Blocked request."));
const auto networkError = error();
QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, Q_ARG(QNetworkReply::NetworkError, networkError));
setFinished(true);
Q_EMIT QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection);
}
qint64 readData(char * /*data*/, qint64 /*maxSize*/) override
{
return 0;
}
void abort() override{};
};
class NoAccessNetworkAccessManager : public QNetworkAccessManager
{
Q_OBJECT
using QNetworkAccessManager::QNetworkAccessManager;
public:
QNetworkReply *createRequest(Operation op, const QNetworkRequest &req, QIODevice *outgoingData) override
{
if (!isLocalRequest(req.url())) {
return new ScreenLocker::AccessDeniedNetworkReply(op, req, this);
}
return QNetworkAccessManager::createRequest(op, req, outgoingData);
}
private:
bool isLocalRequest(const QUrl &url)
{
const QString scheme(url.scheme());
return (KProtocolInfo::isKnownProtocol(scheme) && KProtocolInfo::protocolClass(scheme).compare(QStringLiteral(":local"), Qt::CaseInsensitive) == 0);
}
};
QNetworkAccessManager *NoAccessNetworkAccessManagerFactory::create(QObject *parent)
{
auto *manager = new KIO::AccessManager(parent);
manager->setExternalContentAllowed(false);
return manager;
return new NoAccessNetworkAccessManager(parent);
}
}
#include "noaccessnetworkaccessmanagerfactory.moc"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment