1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +01:00

Implement html5 permissions for screen sharing

Introduced in QtWebEngine 5.10

BUG: 431004

Signed-off-by: Juraj Oravec <jurajoravec@mailo.com>
This commit is contained in:
Juraj Oravec 2021-04-03 21:49:37 +02:00
parent 2b64efc7f7
commit fb03989114
4 changed files with 70 additions and 0 deletions

View File

@ -21,6 +21,9 @@
#include "mainapplication.h" #include "mainapplication.h"
#include "html5permissionsmanager.h" #include "html5permissionsmanager.h"
#include <QtWebEngineWidgetsVersion>
HTML5PermissionsDialog::HTML5PermissionsDialog(QWidget* parent) HTML5PermissionsDialog::HTML5PermissionsDialog(QWidget* parent)
: QDialog(parent) : QDialog(parent)
, ui(new Ui::HTML5PermissionsDialog) , ui(new Ui::HTML5PermissionsDialog)
@ -37,6 +40,12 @@ HTML5PermissionsDialog::HTML5PermissionsDialog(QWidget* parent)
connect(ui->feature, SIGNAL(currentIndexChanged(int)), this, SLOT(featureIndexChanged())); connect(ui->feature, SIGNAL(currentIndexChanged(int)), this, SLOT(featureIndexChanged()));
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &HTML5PermissionsDialog::saveSettings); connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &HTML5PermissionsDialog::saveSettings);
/* Hide unsupported HTML5 permissions */
#if QTWEBENGINEWIDGETS_VERSION < QT_VERSION_CHECK(5, 10, 0)
ui->feature->removeItem(7);
ui->feature->removeItem(6);
#endif
showFeaturePermissions(currentFeature()); showFeaturePermissions(currentFeature());
} }
@ -110,6 +119,12 @@ QWebEnginePage::Feature HTML5PermissionsDialog::currentFeature() const
return QWebEnginePage::MediaAudioVideoCapture; return QWebEnginePage::MediaAudioVideoCapture;
case 5: case 5:
return QWebEnginePage::MouseLock; return QWebEnginePage::MouseLock;
#if QTWEBENGINEWIDGETS_VERSION >= QT_VERSION_CHECK(5, 10, 0)
case 6:
return QWebEnginePage::DesktopVideoCapture;
case 7:
return QWebEnginePage::DesktopAudioVideoCapture;
#endif
default: default:
Q_UNREACHABLE(); Q_UNREACHABLE();
return QWebEnginePage::Notifications; return QWebEnginePage::Notifications;
@ -139,6 +154,14 @@ void HTML5PermissionsDialog::loadSettings()
m_granted[QWebEnginePage::MouseLock] = settings.value("MouseLockGranted", QStringList()).toStringList(); m_granted[QWebEnginePage::MouseLock] = settings.value("MouseLockGranted", QStringList()).toStringList();
m_denied[QWebEnginePage::MouseLock] = settings.value("MouseLockDenied", QStringList()).toStringList(); m_denied[QWebEnginePage::MouseLock] = settings.value("MouseLockDenied", QStringList()).toStringList();
#if QTWEBENGINEWIDGETS_VERSION >= QT_VERSION_CHECK(5, 10, 0)
m_granted[QWebEnginePage::DesktopVideoCapture] = settings.value("DesktopVideoCaptureGranted", QStringList()).toStringList();
m_denied[QWebEnginePage::DesktopVideoCapture] = settings.value("DesktopVideoCaptureDenied", QStringList()).toStringList();
m_granted[QWebEnginePage::DesktopAudioVideoCapture] = settings.value("DesktopAudioVideoCaptureGranted", QStringList()).toStringList();
m_denied[QWebEnginePage::DesktopAudioVideoCapture] = settings.value("DesktopAudioVideoCaptureDenied", QStringList()).toStringList();
#endif
settings.endGroup(); settings.endGroup();
} }
@ -165,6 +188,14 @@ void HTML5PermissionsDialog::saveSettings()
settings.setValue("MouseLockGranted", m_granted[QWebEnginePage::MouseLock]); settings.setValue("MouseLockGranted", m_granted[QWebEnginePage::MouseLock]);
settings.setValue("MouseLockDenied", m_denied[QWebEnginePage::MouseLock]); settings.setValue("MouseLockDenied", m_denied[QWebEnginePage::MouseLock]);
#if QTWEBENGINEWIDGETS_VERSION >= QT_VERSION_CHECK(5, 10, 0)
settings.setValue("DesktopVideoCaptureGranted", m_granted[QWebEnginePage::DesktopVideoCapture]);
settings.setValue("DesktopVideoCaptureDenied", m_denied[QWebEnginePage::DesktopVideoCapture]);
settings.setValue("DesktopAudioVideoCaptureGranted", m_granted[QWebEnginePage::DesktopAudioVideoCapture]);
settings.setValue("DesktopAudioVideoCaptureDenied", m_denied[QWebEnginePage::DesktopAudioVideoCapture]);
#endif
settings.endGroup(); settings.endGroup();
mApp->html5PermissionsManager()->loadSettings(); mApp->html5PermissionsManager()->loadSettings();

View File

@ -112,6 +112,16 @@
<string>Hide Pointer</string> <string>Hide Pointer</string>
</property> </property>
</item> </item>
<item>
<property name="text">
<string>Display Capture</string>
</property>
</item>
<item>
<property name="text">
<string>Display and Audio Capture</string>
</property>
</item>
</widget> </widget>
</item> </item>
<item> <item>

View File

@ -20,6 +20,8 @@
#include "settings.h" #include "settings.h"
#include "webview.h" #include "webview.h"
#include <QtWebEngineWidgetsVersion>
HTML5PermissionsManager::HTML5PermissionsManager(QObject* parent) HTML5PermissionsManager::HTML5PermissionsManager(QObject* parent)
: QObject(parent) : QObject(parent)
@ -95,6 +97,14 @@ void HTML5PermissionsManager::loadSettings()
m_granted[QWebEnginePage::MouseLock] = settings.value("MouseLockGranted", QStringList()).toStringList(); m_granted[QWebEnginePage::MouseLock] = settings.value("MouseLockGranted", QStringList()).toStringList();
m_denied[QWebEnginePage::MouseLock] = settings.value("MouseLockDenied", QStringList()).toStringList(); m_denied[QWebEnginePage::MouseLock] = settings.value("MouseLockDenied", QStringList()).toStringList();
#if QTWEBENGINEWIDGETS_VERSION >= QT_VERSION_CHECK(5, 10, 0)
m_granted[QWebEnginePage::DesktopVideoCapture] = settings.value("DesktopVideoCaptureGranted", QStringList()).toStringList();
m_denied[QWebEnginePage::DesktopVideoCapture] = settings.value("DesktopVideoCaptureDenied", QStringList()).toStringList();
m_granted[QWebEnginePage::DesktopAudioVideoCapture] = settings.value("DesktopAudioVideoCaptureGranted", QStringList()).toStringList();
m_denied[QWebEnginePage::DesktopAudioVideoCapture] = settings.value("DesktopAudioVideoCaptureDenied", QStringList()).toStringList();
#endif
settings.endGroup(); settings.endGroup();
} }
@ -121,5 +131,13 @@ void HTML5PermissionsManager::saveSettings()
settings.setValue("MouseLockGranted", m_granted[QWebEnginePage::MouseLock]); settings.setValue("MouseLockGranted", m_granted[QWebEnginePage::MouseLock]);
settings.setValue("MouseLockDenied", m_denied[QWebEnginePage::MouseLock]); settings.setValue("MouseLockDenied", m_denied[QWebEnginePage::MouseLock]);
#if QTWEBENGINEWIDGETS_VERSION >= QT_VERSION_CHECK(5, 10, 0)
settings.setValue("DesktopVideoCaptureGranted", m_granted[QWebEnginePage::DesktopVideoCapture]);
settings.setValue("DesktopVideoCaptureDenied", m_denied[QWebEnginePage::DesktopVideoCapture]);
settings.setValue("DesktopAudioVideoCaptureGranted", m_granted[QWebEnginePage::DesktopAudioVideoCapture]);
settings.setValue("DesktopAudioVideoCaptureDenied", m_denied[QWebEnginePage::DesktopAudioVideoCapture]);
#endif
settings.endGroup(); settings.endGroup();
} }

View File

@ -23,6 +23,8 @@
#include <QTimer> #include <QTimer>
#include <QWebEnginePage> #include <QWebEnginePage>
#include <QtWebEngineWidgetsVersion>
HTML5PermissionsNotification::HTML5PermissionsNotification(const QUrl &origin, QWebEnginePage* page, const QWebEnginePage::Feature &feature) HTML5PermissionsNotification::HTML5PermissionsNotification(const QUrl &origin, QWebEnginePage* page, const QWebEnginePage::Feature &feature)
: AnimatedWidget(AnimatedWidget::Down, 300, 0) : AnimatedWidget(AnimatedWidget::Down, 300, 0)
@ -63,6 +65,15 @@ HTML5PermissionsNotification::HTML5PermissionsNotification(const QUrl &origin, Q
ui->textLabel->setText(tr("Allow %1 to hide your pointer?").arg(site)); ui->textLabel->setText(tr("Allow %1 to hide your pointer?").arg(site));
break; break;
#if QTWEBENGINEWIDGETS_VERSION >= QT_VERSION_CHECK(5, 10, 0)
case QWebEnginePage::DesktopVideoCapture:
ui->textLabel->setText(tr("Allow %1 to capture your screen?").arg(site));
break;
case QWebEnginePage::DesktopAudioVideoCapture:
ui->textLabel->setText(tr("Allow %1 to capture your screen and audio?").arg(site));
break;
#endif
default: default:
qWarning() << "Unknown feature" << feature; qWarning() << "Unknown feature" << feature;
break; break;