0001-Reintroduce-the-username-field-reading-with-webkit-o.patch 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. From 90890e7d27c544e3557bed2f6624614141db0fc4 Mon Sep 17 00:00:00 2001
  2. From: Fabian Vogt <fabian@ritter-vogt.de>
  3. Date: Sat, 29 Sep 2018 15:34:43 +0200
  4. Subject: [PATCH] Reintroduce the username field reading with webkit-options.d
  5. Use WebChannel to spy on the input fields.
  6. Use the old UserAgent to make sure the selectors match.
  7. ---
  8. src/browser-request.cpp | 11 +++++++++++
  9. src/qml/WebView.qml | 36 ++++++++++++++++++++++++++++++++++++
  10. 2 files changed, 47 insertions(+)
  11. diff --git a/src/browser-request.cpp b/src/browser-request.cpp
  12. index 1895d59..e58f302 100644
  13. --- a/src/browser-request.cpp
  14. +++ b/src/browser-request.cpp
  15. @@ -31,6 +31,7 @@
  16. #include <QStandardPaths>
  17. #include <QTimer>
  18. #include <SignOn/uisessiondata_priv.h>
  19. +#include <QSettings>
  20. using namespace SignOnUi;
  21. using namespace SignOnUi::QQuick;
  22. @@ -43,8 +44,10 @@ class BrowserRequestPrivate: public QObject
  23. Q_DECLARE_PUBLIC(BrowserRequest)
  24. Q_PROPERTY(QUrl pageComponentUrl READ pageComponentUrl CONSTANT)
  25. Q_PROPERTY(QUrl currentUrl READ currentUrl WRITE setCurrentUrl)
  26. + Q_PROPERTY(QString username MEMBER m_username)
  27. Q_PROPERTY(QUrl startUrl READ startUrl CONSTANT)
  28. Q_PROPERTY(QUrl finalUrl READ finalUrl CONSTANT)
  29. + Q_PROPERTY(QString usernameSelector READ usernameSelector CONSTANT)
  30. public:
  31. BrowserRequestPrivate(BrowserRequest *request);
  32. @@ -58,6 +61,7 @@ public:
  33. QUrl startUrl() const { return m_startUrl; }
  34. QUrl finalUrl() const { return m_finalUrl; }
  35. QUrl responseUrl() const { return m_responseUrl; }
  36. + QString usernameSelector() const { return m_settings->value("UsernameField").toString(); }
  37. public Q_SLOTS:
  38. void cancel();
  39. @@ -77,6 +81,8 @@ private:
  40. QUrl m_startUrl;
  41. QUrl m_finalUrl;
  42. QUrl m_responseUrl;
  43. + QString m_username;
  44. + QSettings *m_settings;
  45. QTimer m_failTimer;
  46. mutable BrowserRequest *q_ptr;
  47. };
  48. @@ -116,6 +122,9 @@ void BrowserRequestPrivate::start()
  49. m_finalUrl = params.value(SSOUI_KEY_FINALURL).toString();
  50. m_startUrl = params.value(SSOUI_KEY_OPENURL).toString();
  51. +
  52. + m_settings = new QSettings("signon-ui/webkit-options.d/" + m_startUrl.host(), QString(), this);
  53. +
  54. buildDialog(params);
  55. QObject::connect(m_dialog, SIGNAL(finished(int)),
  56. @@ -231,6 +240,8 @@ void BrowserRequestPrivate::onFinished()
  57. QVariantMap reply;
  58. QUrl url = m_responseUrl.isEmpty() ? m_currentUrl : m_responseUrl;
  59. reply[SSOUI_KEY_URLRESPONSE] = url.toString();
  60. + if (!m_username.isEmpty())
  61. + reply[SSOUI_KEY_USERNAME] = m_username;
  62. m_dialog->close();
  63. diff --git a/src/qml/WebView.qml b/src/qml/WebView.qml
  64. index 33462b8..3af0239 100644
  65. --- a/src/qml/WebView.qml
  66. +++ b/src/qml/WebView.qml
  67. @@ -1,4 +1,5 @@
  68. import QtQuick 2.0
  69. +import QtWebChannel 1.0
  70. import QtWebEngine 1.1
  71. WebEngineView {
  72. @@ -25,8 +26,43 @@ WebEngineView {
  73. profile: WebEngineProfile {
  74. cachePath: rootDir
  75. persistentStoragePath: rootDir
  76. + // For compatibility with the webkit-options.d values
  77. + httpUserAgent: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.21 (KHTML, like Gecko) Safari/537.21"
  78. }
  79. + QtObject {
  80. + id: commProxy
  81. + WebChannel.id: "comm"
  82. + property string username: ""
  83. + property string selector: signonRequest.usernameSelector
  84. + onUsernameChanged: signonRequest.username = username
  85. + }
  86. +
  87. + WebChannel {
  88. + id: chan
  89. + registeredObjects: [commProxy]
  90. + }
  91. + webChannel: chan
  92. +
  93. + WebEngineScript {
  94. + id: qwebchannel
  95. + injectionPoint: WebEngineScript.DocumentCreation
  96. + sourceUrl: "qrc:/qtwebchannel/qwebchannel.js"
  97. + worldId: WebEngineScript.MainWorld
  98. + }
  99. +
  100. + WebEngineScript {
  101. + id: commScript
  102. + injectionPoint: WebEngineScript.DocumentReady
  103. + sourceCode: "new QWebChannel(window.qt.webChannelTransport, function(channel) {" +
  104. + " var elem = document.querySelector(channel.objects.comm.selector);" +
  105. + " elem.addEventListener('keyup', function() { channel.objects.comm.username = elem.value; });" +
  106. + "});"
  107. + worldId: WebEngineScript.MainWorld
  108. + }
  109. +
  110. + userScripts: [qwebchannel, commScript]
  111. +
  112. ProgressBar {
  113. anchors.top: parent.top
  114. anchors.left: parent.left
  115. --
  116. 2.18.0