20 #include <QApplication>
21 #include <QWebEngineView>
22 #include <QWebEngineProfile>
23 #include <QWebEngineUrlScheme>
24 #include <QWebEngineUrlSchemeHandler>
25 #include <QWebEngineUrlRequestJob>
30 #include <winpr/string.h>
31 #include <winpr/assert.h>
32 #include <freerdp/log.h>
33 #include <freerdp/build-config.h>
35 #include "../webview_impl.hpp"
37 #define TAG CLIENT_TAG("sdl.webview")
39 class SchemeHandler :
public QWebEngineUrlSchemeHandler
42 explicit SchemeHandler(QObject* parent =
nullptr) : QWebEngineUrlSchemeHandler(parent)
46 void requestStarted(QWebEngineUrlRequestJob* request)
override
48 QUrl url = request->requestUrl();
51 for (
auto& param : url.query().split(
'&'))
53 QStringList pair = param.split(
'=');
55 if (pair.size() != 2 || pair[0] != QLatin1String(
"code"))
59 m_code = qc.toStdString();
66 [[nodiscard]] std::string code()
const
75 bool webview_impl_run(
const std::string& title,
const std::string& url, std::string& code)
78 const auto vendor = QLatin1String(FREERDP_VENDOR_STRING);
79 const auto product = QLatin1String(FREERDP_PRODUCT_STRING);
80 QWebEngineUrlScheme::registerScheme(QWebEngineUrlScheme(
"ms-appx-web"));
82 std::string wtitle = title;
83 char* argv[] = { wtitle.data() };
84 QCoreApplication::setOrganizationName(vendor);
85 QCoreApplication::setApplicationName(product);
86 QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
87 QApplication app(argc, argv);
89 SchemeHandler handler;
90 QWebEngineProfile::defaultProfile()->installUrlSchemeHandler(
"ms-appx-web", &handler);
92 QWebEngineView webview;
93 webview.load(QUrl(QString::fromStdString(url)));
99 auto val = handler.code();
104 return !code.empty();