File indexing completed on 2024-12-22 04:43:20
0001 /* 0002 This file is part of the KDE project. 0003 0004 SPDX-FileCopyrightText: 2018 Stefano Crocco <stefano.crocco@alice.it> 0005 0006 SPDX-License-Identifier: LGPL-2.1-or-later 0007 */ 0008 0009 #include "schemehandlers/execschemehandler.h" 0010 0011 #include <webenginepart_debug.h> 0012 0013 #include <QWebEngineUrlRequestJob> 0014 0015 #include <KIO/CommandLauncherJob> 0016 #include <KDialogJobUiDelegate> 0017 0018 #include <QDebug> 0019 0020 using namespace WebEngine; 0021 0022 ExecSchemeHandler::ExecSchemeHandler(QObject* parent): QWebEngineUrlSchemeHandler(parent) 0023 { 0024 } 0025 0026 ExecSchemeHandler::~ExecSchemeHandler() noexcept 0027 { 0028 } 0029 0030 void ExecSchemeHandler::requestStarted(QWebEngineUrlRequestJob* job) 0031 { 0032 //TODO: devise a more fine-grained approach to allowing which URLs can request URLs with the exec scheme 0033 if (job->initiator().scheme() != QStringLiteral("konq")) { 0034 qCDebug(WEBENGINEPART_LOG) << "Exec URL not initiated from konq URL"; 0035 job->fail(QWebEngineUrlRequestJob::RequestDenied); 0036 return; 0037 } 0038 //The path must start with / 0039 const QString cmdline = job->requestUrl().path(); 0040 const QString exec = cmdline.left(cmdline.indexOf(' ')); 0041 KIO::CommandLauncherJob *launcherJob = new KIO::CommandLauncherJob(cmdline, this); 0042 launcherJob->setExecutable(exec); 0043 launcherJob->setUiDelegate(new KDialogJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, nullptr)); 0044 launcherJob->start(); 0045 //It's not really a failure, but there's no other way to tell QtWebEngine that the request will be handled by someone else 0046 job->fail(QWebEngineUrlRequestJob::NoError); 0047 }