From 5eff4dc0e52311a298fafd148332832840c00ff1 Mon Sep 17 00:00:00 2001 From: Juraj Oravec Date: Sun, 21 Aug 2022 00:43:37 +0200 Subject: [PATCH] Asdd UI for default HTML5 permission settings - It is a dummy UI, may change in the future. Signed-off-by: Juraj Oravec --- src/lib/CMakeLists.txt | 3 + src/lib/other/sitesettingsmanager.cpp | 32 ++- src/lib/other/sitesettingsmanager.h | 7 +- .../html5permissionsdialog.cpp | 9 + .../html5permissionsdialog.ui | 258 ++++++++++-------- .../html5permissions/html5permissionsitem.cpp | 129 +++++++++ .../html5permissions/html5permissionsitem.h | 54 ++++ .../html5permissions/html5permissionsitem.ui | 57 ++++ 8 files changed, 429 insertions(+), 120 deletions(-) create mode 100644 src/lib/tools/html5permissions/html5permissionsitem.cpp create mode 100644 src/lib/tools/html5permissions/html5permissionsitem.h create mode 100644 src/lib/tools/html5permissions/html5permissionsitem.ui diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 2c661c182..53bfc58fb 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -244,6 +244,7 @@ set(SRCS ${SRCS} tools/headerview.cpp tools/horizontallistwidget.cpp tools/html5permissions/html5permissionsdialog.cpp + tools/html5permissions/html5permissionsitem.cpp tools/html5permissions/html5permissionsmanager.cpp tools/html5permissions/html5permissionsnotification.cpp tools/iconprovider.cpp @@ -475,6 +476,7 @@ set(SRCS ${SRCS} tools/headerview.h tools/horizontallistwidget.h tools/html5permissions/html5permissionsdialog.h + tools/html5permissions/html5permissionsitem.h tools/html5permissions/html5permissionsmanager.h tools/html5permissions/html5permissionsnotification.h tools/iconprovider.h @@ -562,6 +564,7 @@ qt_wrap_ui(SRCS tools/certificateinfowidget.ui tools/docktitlebarwidget.ui tools/html5permissions/html5permissionsdialog.ui + tools/html5permissions/html5permissionsitem.ui tools/html5permissions/html5permissionsnotification.ui webengine/jsalert.ui webengine/jsconfirm.ui diff --git a/src/lib/other/sitesettingsmanager.cpp b/src/lib/other/sitesettingsmanager.cpp index 34f81cf2b..3a94c7aeb 100644 --- a/src/lib/other/sitesettingsmanager.cpp +++ b/src/lib/other/sitesettingsmanager.cpp @@ -21,7 +21,6 @@ #include "settings.h" #include "sqldatabase.h" #include -#include SiteSettingsManager::SiteSettingsManager ( QObject* parent ) : QObject(parent) @@ -191,11 +190,28 @@ QString SiteSettingsManager::optionToSqlColumn(const SiteSettingsManager::PageOp return QSL("allow_desktop_audio_video_capture"); default: + Q_UNREACHABLE(); qWarning() << "Unknown option" << option; return QLatin1String(""); } } +SiteSettingsManager::Permission SiteSettingsManager::getDefaultPermission(const SiteSettingsManager::PageOptions& option) +{ + switch (option) { + case poAllowJavascript: + return testAttribute(QWebEngineSettings::JavascriptEnabled); + + case poAllowImages: + return testAttribute(QWebEngineSettings::AutoLoadImages); + + default: + Q_UNREACHABLE(); + qWarning() << "Unknown option" << option; + return Deny; + } +} + bool SiteSettingsManager::getDefaultOptionValue(const SiteSettingsManager::PageOptions& option) { switch (option) { @@ -213,12 +229,13 @@ bool SiteSettingsManager::getDefaultOptionValue(const SiteSettingsManager::PageO return false; default: + Q_UNREACHABLE(); qWarning() << "Unknown option" << option; return false; } } -SiteSettingsManager::PageOptions SiteSettingsManager::optionFromWebEngineFeature(const QWebEnginePage::Feature& feature) +SiteSettingsManager::PageOptions SiteSettingsManager::optionFromWebEngineFeature(const QWebEnginePage::Feature& feature) const { switch (feature) { case QWebEnginePage::Notifications: @@ -246,6 +263,7 @@ SiteSettingsManager::PageOptions SiteSettingsManager::optionFromWebEngineFeature return poAllowDesktopAudioVideoCapture; default: + Q_UNREACHABLE(); qWarning() << "Unknown feature" << feature; return poAllowNotifications; } @@ -255,3 +273,13 @@ QString SiteSettingsManager::sqlColumnFromWebEngineFeature(const QWebEnginePage: { return optionToSqlColumn(optionFromWebEngineFeature(feature)); } + +SiteSettingsManager::Permission SiteSettingsManager::testAttribute(const QWebEngineSettings::WebAttribute attribute) const +{ + if (mApp->webSettings()->testAttribute(attribute)) { + return Allow; + } + else { + return Deny; + } +} diff --git a/src/lib/other/sitesettingsmanager.h b/src/lib/other/sitesettingsmanager.h index 0bd0489a3..bbfee2233 100644 --- a/src/lib/other/sitesettingsmanager.h +++ b/src/lib/other/sitesettingsmanager.h @@ -20,6 +20,7 @@ #include "qzcommon.h" #include +#include class QUrl; @@ -42,6 +43,7 @@ public: Deny = 2, Ask = 3, }; + Q_ENUM(Permission); enum PageOptions { poAllowJavascript, @@ -57,6 +59,7 @@ public: poAllowDesktopVideoCapture, poAllowDesktopAudioVideoCapture, }; + Q_ENUM(PageOptions); struct SiteSettings { @@ -102,7 +105,9 @@ public: private: QString optionToSqlColumn(const PageOptions &option); bool getDefaultOptionValue(const PageOptions &option); - PageOptions optionFromWebEngineFeature(const QWebEnginePage::Feature &feature); + Permission getDefaultPermission(const PageOptions &option); + PageOptions optionFromWebEngineFeature(const QWebEnginePage::Feature &feature) const; + Permission testAttribute(const QWebEngineSettings::WebAttribute attribute) const; }; diff --git a/src/lib/tools/html5permissions/html5permissionsdialog.cpp b/src/lib/tools/html5permissions/html5permissionsdialog.cpp index eda0bb1fa..e6be295cf 100644 --- a/src/lib/tools/html5permissions/html5permissionsdialog.cpp +++ b/src/lib/tools/html5permissions/html5permissionsdialog.cpp @@ -19,6 +19,7 @@ #include "ui_html5permissionsdialog.h" #include "settings.h" #include "mainapplication.h" +#include "html5permissionsitem.h" #include "html5permissionsmanager.h" #include "sitesettingsmanager.h" @@ -41,6 +42,14 @@ HTML5PermissionsDialog::HTML5PermissionsDialog(QWidget* parent) connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &HTML5PermissionsDialog::saveSettings); showFeaturePermissions(currentFeature()); + + for (int i = 0; i < 8; ++i) { + // Create permission item + auto* listItem = new QListWidgetItem(ui->listWidgetDefaults); + auto* permItem = new HTML5PermissionsItem(indexToFeature(i), SiteSettingsManager::Ask, this); + ui->listWidgetDefaults->setItemWidget(listItem, permItem); + listItem->setSizeHint(permItem->sizeHint()); + } } HTML5PermissionsDialog::~HTML5PermissionsDialog() diff --git a/src/lib/tools/html5permissions/html5permissionsdialog.ui b/src/lib/tools/html5permissions/html5permissionsdialog.ui index bd0b0d785..695ab086f 100644 --- a/src/lib/tools/html5permissions/html5permissionsdialog.ui +++ b/src/lib/tools/html5permissions/html5permissionsdialog.ui @@ -6,39 +6,154 @@ 0 0 - 483 - 332 + 586 + 387 HTML5 Permissions - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - Remove - - - - + + + + 0 + + + + Site permissions + + + + + + + + Qt::Vertical + + + + 20 + 183 + + + + + + + + Remove + + + + + + + + + 0 + + + true + + + true + + + + Site + + + + + Behaviour + + + + + + + + + + Permission for: + + + + + + + + Notifications + + + + + Geolocation + + + + + Microphone + + + + + Camera + + + + + Microphone and Camera + + + + + Hide Pointer + + + + + Display Capture + + + + + Display and Audio Capture + + + + + + + + Qt::Horizontal + + + + 81 + 20 + + + + + + + + + + + Defaults + + + + + + + + - + Qt::Horizontal @@ -48,97 +163,6 @@ - - - - 0 - - - true - - - true - - - - Site - - - - - Behaviour - - - - - - - - - - Permission for: - - - - - - - - Notifications - - - - - Geolocation - - - - - Microphone - - - - - Camera - - - - - Microphone and Camera - - - - - Hide Pointer - - - - - Display Capture - - - - - Display and Audio Capture - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - diff --git a/src/lib/tools/html5permissions/html5permissionsitem.cpp b/src/lib/tools/html5permissions/html5permissionsitem.cpp new file mode 100644 index 000000000..aeaac226c --- /dev/null +++ b/src/lib/tools/html5permissions/html5permissionsitem.cpp @@ -0,0 +1,129 @@ +/* ============================================================ + * Falkon - Qt web browser + * Copyright (C) 2022 Juraj Oravec + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * ============================================================ */ +#include "html5permissionsitem.h" +#include "ui_html5permissionsitem.h" + + +HTML5PermissionsItem::HTML5PermissionsItem(const QWebEnginePage::Feature& feature, const SiteSettingsManager::Permission& permission, QWidget* parent) +: QWidget(parent) +, ui(new Ui::HTML5PermissionsItem()) +, m_feature(feature) +, m_permission(permission) +{ + ui->setupUi(this); + + setLabel(); + setCombo(); + + connect(ui->comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(permissionIndexChanged())); +} + +HTML5PermissionsItem::~HTML5PermissionsItem() noexcept +{ + delete ui; +} + +void HTML5PermissionsItem::permissionIndexChanged() +{ + switch (ui->comboBox->currentIndex()) { + case 0: + m_permission = SiteSettingsManager::Allow; + break; + case 1: + m_permission = SiteSettingsManager::Deny; + break; + case 2: + m_permission = SiteSettingsManager::Ask; + break; + default: + Q_UNREACHABLE(); + qWarning() << "Unknown permission index" << ui->comboBox->currentIndex(); + break; + } +} + +void HTML5PermissionsItem::setLabel() +{ + switch (m_feature) { + case QWebEnginePage::Notifications: + ui->label->setText("Notifications"); + break; + + case QWebEnginePage::Geolocation: + ui->label->setText("Location"); + break; + + case QWebEnginePage::MediaAudioCapture: + ui->label->setText("Microphone"); + break; + + case QWebEnginePage::MediaVideoCapture: + ui->label->setText("Camera"); + break; + + case QWebEnginePage::MediaAudioVideoCapture: + ui->label->setText("Microphone and Camera"); + break; + + case QWebEnginePage::MouseLock: + ui->label->setText("Hide mouse pointer"); + break; + + case QWebEnginePage::DesktopVideoCapture: + ui->label->setText("Screen capture"); + break; + + case QWebEnginePage::DesktopAudioVideoCapture: + ui->label->setText("Screen capture with audio"); + break; + + default: + Q_UNREACHABLE(); + qWarning() << "Unknown feature" << m_feature; + break; + } +} + +void HTML5PermissionsItem::setCombo() +{ + switch (m_permission) { + case SiteSettingsManager::Allow: + ui->comboBox->setCurrentIndex(0); + break; + case SiteSettingsManager::Deny: + ui->comboBox->setCurrentIndex(1); + break; + case SiteSettingsManager::Ask: + ui->comboBox->setCurrentIndex(2); + break; + default: + Q_UNREACHABLE(); + qWarning() << "Unknown permission" << m_permission; + break; + } +} + +QWebEnginePage::Feature HTML5PermissionsItem::getFeature() const +{ + return m_feature; +} + +SiteSettingsManager::Permission HTML5PermissionsItem::getPermission() const +{ + return m_permission; +} diff --git a/src/lib/tools/html5permissions/html5permissionsitem.h b/src/lib/tools/html5permissions/html5permissionsitem.h new file mode 100644 index 000000000..70ed38b19 --- /dev/null +++ b/src/lib/tools/html5permissions/html5permissionsitem.h @@ -0,0 +1,54 @@ +/* ============================================================ + * Falkon - Qt web browser + * Copyright (C) 2022 Juraj Oravec + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * ============================================================ */ +#ifndef HTML5PERMISSIONSITEM_H +#define HTML5PERMISSIONSITEM_H + + +#include "qzcommon.h" +#include "sitesettingsmanager.h" +#include +#include + +namespace Ui +{ +class HTML5PermissionsItem; +} + +class FALKON_EXPORT HTML5PermissionsItem : public QWidget +{ + Q_OBJECT +public: + explicit HTML5PermissionsItem(const QWebEnginePage::Feature &feature, const SiteSettingsManager::Permission &permission, QWidget* parent = nullptr); + ~HTML5PermissionsItem(); + + QWebEnginePage::Feature getFeature() const; + SiteSettingsManager::Permission getPermission() const; + +private Q_SLOTS: + void permissionIndexChanged(); + +private: + void setLabel(); + void setCombo(); + + Ui::HTML5PermissionsItem* ui; + QWebEnginePage::Feature m_feature; + SiteSettingsManager::Permission m_permission; +}; + +#endif // HTML5PERMISSIONSITEM_H diff --git a/src/lib/tools/html5permissions/html5permissionsitem.ui b/src/lib/tools/html5permissions/html5permissionsitem.ui new file mode 100644 index 000000000..da54ac52b --- /dev/null +++ b/src/lib/tools/html5permissions/html5permissionsitem.ui @@ -0,0 +1,57 @@ + + + HTML5PermissionsItem + + + + 0 + 0 + 319 + 38 + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + Allow + + + + + Deny + + + + + Ask + + + + + + + + +