summaryrefslogtreecommitdiffstats
path: root/src/webview.cpp
diff options
context:
space:
mode:
authorSimon Rettberg2024-06-19 13:39:47 +0200
committerSimon Rettberg2024-06-19 13:39:47 +0200
commit13441ee8d8dc3f11effb3c5ebca7728ad4ec8e14 (patch)
treefab02c0fec059ef66aa16f599f99340c1117a776 /src/webview.cpp
parentFix reading UTF8 strings from settings (diff)
downloadslxgreeter-13441ee8d8dc3f11effb3c5ebca7728ad4ec8e14.tar.gz
slxgreeter-13441ee8d8dc3f11effb3c5ebca7728ad4ec8e14.tar.xz
slxgreeter-13441ee8d8dc3f11effb3c5ebca7728ad4ec8e14.zip
Add allowed-shibboleth-domains config option to inject in website
This will inject a piece of JS code on page load that sets slxIdpFilter to this value, to be used by the IdP selector to filter the list.
Diffstat (limited to 'src/webview.cpp')
-rw-r--r--src/webview.cpp30
1 files changed, 24 insertions, 6 deletions
diff --git a/src/webview.cpp b/src/webview.cpp
index 9ebc1ba..4fb8511 100644
--- a/src/webview.cpp
+++ b/src/webview.cpp
@@ -1,6 +1,7 @@
#include "webview.h"
#include "nam.h"
#include "global.h"
+#include "settings.h"
#include <QWebFrame>
#include <QNetworkReply>
@@ -14,6 +15,7 @@
#include <QWebElement>
#include <QRegularExpression>
#include <QWebPage>
+#include <QWebFrame>
static QRegularExpression urlListToRegExp(const QStringList &list);
@@ -32,13 +34,21 @@ QRegularExpression UaWebPage::re("(\\S+)$");
WebView::WebView(QWidget* parent)
: QWebView(parent),
- _timerAbortMessage(new QTimer(this)),
- _abortedDownload(false),
- _inErrorState(false),
- _timerReset(new QTimer(this)),
- _firstLoad(false)
+ _timerAbortMessage(new QTimer(this)),
+ _abortedDownload(false),
+ _inErrorState(false),
+ _timerReset(new QTimer(this)),
+ _firstLoad(false)
{
- this->setPage(new UaWebPage);
+ auto p = new UaWebPage;
+ if (!Settings::allowedShibbolethDomains().trimmed().isEmpty()) {
+ QObject::connect(p, &UaWebPage::frameCreated, [this](QWebFrame *frame) {
+ QObject::connect(frame, &QWebFrame::javaScriptWindowObjectCleared, [this, frame]() {
+ this->jsInjector(frame);
+ });
+ });
+ }
+ this->setPage(p);
_timerAbortMessage->setSingleShot(true);
_timerReset->setSingleShot(true);
connect(page(), SIGNAL(windowCloseRequested()), this, SLOT(windowCloseRequested()));
@@ -60,6 +70,14 @@ WebView::WebView(QWidget* parent)
connect(this, &QWebView::loadFinished, this, &WebView::onLoadFinished);
}
+void WebView::jsInjector(QWebFrame *frame)
+{
+ QString str = Settings::allowedShibbolethDomains().replace(
+ QRegularExpression("[^\\w. -]", QRegularExpression::UseUnicodePropertiesOption),
+ QStringLiteral(""));
+ frame->evaluateJavaScript(QStringLiteral("var slxIdpFilter ='") + str + QStringLiteral("'"));
+}
+
void WebView::windowCloseRequested()
{
// If we have an old URL stored on the stack, navigate back to it, otherwise we return and nothing happens