1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 18:56:34 +01:00

WebPage: Port feature permission notifications to QtWebEngine

Currently there are missing icons for new permission types
This commit is contained in:
David Rosca 2015-05-22 23:18:25 +02:00
parent bbc7628de0
commit 014d0d50ab
10 changed files with 344 additions and 338 deletions

View File

@ -204,13 +204,14 @@ void ClearPrivateData::showCookieManager()
void ClearPrivateData::showNotifsPerms()
{
HTML5PermissionsDialog* dialog = new HTML5PermissionsDialog(this);
dialog->showFeaturePermissions(QWebEnginePage::Notifications);
dialog->open();
}
void ClearPrivateData::showGeolocPerms()
{
HTML5PermissionsDialog* dialog = new HTML5PermissionsDialog(this);
dialog->setCurrentTab(1);
dialog->showFeaturePermissions(QWebEnginePage::Geolocation);
dialog->open();
}

View File

@ -21,9 +21,9 @@
#include "mainapplication.h"
#include "html5permissionsmanager.h"
HTML5PermissionsDialog::HTML5PermissionsDialog(QWidget* parent) :
QDialog(parent),
ui(new Ui::HTML5PermissionsDialog)
HTML5PermissionsDialog::HTML5PermissionsDialog(QWidget* parent)
: QDialog(parent)
, ui(new Ui::HTML5PermissionsDialog)
{
setAttribute(Qt::WA_DeleteOnClose);
@ -31,103 +31,112 @@ HTML5PermissionsDialog::HTML5PermissionsDialog(QWidget* parent) :
loadSettings();
foreach (const QString &site, m_notificationsGranted) {
QTreeWidgetItem* item = new QTreeWidgetItem(ui->notifTree);
ui->treeWidget->header()->resizeSection(0, 220);
connect(ui->remove, &QPushButton::clicked, this, &HTML5PermissionsDialog::removeEntry);
connect(ui->feature, SIGNAL(currentIndexChanged(int)), this, SLOT(featureIndexChanged()));
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &HTML5PermissionsDialog::saveSettings);
showFeaturePermissions(currentFeature());
}
HTML5PermissionsDialog::~HTML5PermissionsDialog()
{
delete ui;
}
void HTML5PermissionsDialog::showFeaturePermissions(QWebEnginePage::Feature feature)
{
if (!m_granted.contains(feature) || !m_denied.contains(feature)) {
return;
}
ui->treeWidget->clear();
foreach (const QString &site, m_granted.value(feature)) {
QTreeWidgetItem* item = new QTreeWidgetItem(ui->treeWidget);
item->setText(0, site);
item->setText(1, tr("Allow"));
item->setData(0, Qt::UserRole + 10, Allow);
ui->notifTree->addTopLevelItem(item);
ui->treeWidget->addTopLevelItem(item);
}
foreach (const QString &site, m_notificationsDenied) {
QTreeWidgetItem* item = new QTreeWidgetItem(ui->notifTree);
foreach (const QString &site, m_denied.value(feature)) {
QTreeWidgetItem* item = new QTreeWidgetItem(ui->treeWidget);
item->setText(0, site);
item->setText(1, tr("Deny"));
item->setData(0, Qt::UserRole + 10, Deny);
ui->notifTree->addTopLevelItem(item);
ui->treeWidget->addTopLevelItem(item);
}
foreach (const QString &site, m_geolocationGranted) {
QTreeWidgetItem* item = new QTreeWidgetItem(ui->geoTree);
item->setText(0, site);
item->setText(1, tr("Allow"));
item->setData(0, Qt::UserRole + 10, Allow);
ui->geoTree->addTopLevelItem(item);
}
foreach (const QString &site, m_geolocationDenied) {
QTreeWidgetItem* item = new QTreeWidgetItem(ui->geoTree);
item->setText(0, site);
item->setText(1, tr("Deny"));
item->setData(0, Qt::UserRole + 10, Deny);
ui->geoTree->addTopLevelItem(item);
}
ui->notifTree->header()->resizeSection(0, 220);
ui->geoTree->header()->resizeSection(0, 220);
connect(ui->notifRemove, SIGNAL(clicked()), this, SLOT(removeNotifEntry()));
connect(ui->geoRemove, SIGNAL(clicked()), this, SLOT(removeGeoEntry()));
connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(saveSettings()));
}
void HTML5PermissionsDialog::setCurrentTab(int index)
void HTML5PermissionsDialog::featureIndexChanged()
{
ui->tabWidget->setCurrentIndex(index);
showFeaturePermissions(currentFeature());
}
void HTML5PermissionsDialog::removeNotifEntry()
void HTML5PermissionsDialog::removeEntry()
{
QTreeWidgetItem* item = ui->notifTree->currentItem();
QTreeWidgetItem* item = ui->treeWidget->currentItem();
if (!item) {
return;
}
Role role = static_cast<Role>(item->data(0, Qt::UserRole + 10).toInt());
QString site = item->text(0);
const QString origin = item->text(0);
if (role == Allow) {
m_notificationsGranted.removeOne(site);
}
else {
m_notificationsDenied.removeOne(site);
}
if (role == Allow)
m_granted[currentFeature()].removeOne(origin);
else
m_denied[currentFeature()].removeOne(origin);
delete item;
}
void HTML5PermissionsDialog::removeGeoEntry()
QWebEnginePage::Feature HTML5PermissionsDialog::currentFeature() const
{
QTreeWidgetItem* item = ui->geoTree->currentItem();
if (!item) {
return;
switch (ui->feature->currentIndex()) {
case 0:
return QWebEnginePage::Notifications;
case 1:
return QWebEnginePage::Geolocation;
case 2:
return QWebEnginePage::MediaAudioCapture;
case 3:
return QWebEnginePage::MediaVideoCapture;
case 4:
return QWebEnginePage::MediaAudioVideoCapture;
case 5:
return QWebEnginePage::MouseLock;
default:
Q_UNREACHABLE();
return QWebEnginePage::Notifications;
}
Role role = static_cast<Role>(item->data(0, Qt::UserRole + 10).toInt());
QString site = item->text(0);
if (role == Allow) {
m_geolocationGranted.removeOne(site);
}
else {
m_geolocationDenied.removeOne(site);
}
delete item;
}
void HTML5PermissionsDialog::loadSettings()
{
Settings settings;
settings.beginGroup("HTML5Notifications");
m_notificationsGranted = settings.value("NotificationsGranted", QStringList()).toStringList();
m_notificationsDenied = settings.value("NotificationsDenied", QStringList()).toStringList();
m_geolocationGranted = settings.value("GeolocationGranted", QStringList()).toStringList();
m_geolocationDenied = settings.value("GeolocationDenied", QStringList()).toStringList();
m_granted[QWebEnginePage::Notifications] = settings.value("NotificationsGranted", QStringList()).toStringList();
m_denied[QWebEnginePage::Notifications] = settings.value("NotificationsDenied", QStringList()).toStringList();
m_granted[QWebEnginePage::Geolocation] = settings.value("GeolocationGranted", QStringList()).toStringList();
m_denied[QWebEnginePage::Geolocation] = settings.value("GeolocationDenied", QStringList()).toStringList();
m_granted[QWebEnginePage::MediaAudioCapture] = settings.value("MediaAudioCaptureGranted", QStringList()).toStringList();
m_denied[QWebEnginePage::MediaAudioCapture] = settings.value("MediaAudioCaptureDenied", QStringList()).toStringList();
m_granted[QWebEnginePage::MediaVideoCapture] = settings.value("MediaVideoCaptureGranted", QStringList()).toStringList();
m_denied[QWebEnginePage::MediaVideoCapture] = settings.value("MediaVideoCaptureDenied", QStringList()).toStringList();
m_granted[QWebEnginePage::MediaAudioVideoCapture] = settings.value("MediaAudioVideoCaptureGranted", QStringList()).toStringList();
m_denied[QWebEnginePage::MediaAudioVideoCapture] = settings.value("MediaAudioVideoCaptureDenied", QStringList()).toStringList();
m_granted[QWebEnginePage::MouseLock] = settings.value("MouseLockGranted", QStringList()).toStringList();
m_denied[QWebEnginePage::MouseLock] = settings.value("MouseLockDenied", QStringList()).toStringList();
settings.endGroup();
}
@ -135,16 +144,26 @@ void HTML5PermissionsDialog::saveSettings()
{
Settings settings;
settings.beginGroup("HTML5Notifications");
settings.setValue("NotificationsGranted", m_notificationsGranted);
settings.setValue("NotificationsDenied", m_notificationsDenied);
settings.setValue("GeolocationGranted", m_geolocationGranted);
settings.setValue("GeolocationDenied", m_geolocationDenied);
settings.setValue("NotificationsGranted", m_granted[QWebEnginePage::Notifications]);
settings.setValue("NotificationsDenied", m_denied[QWebEnginePage::Notifications]);
settings.setValue("GeolocationGranted", m_granted[QWebEnginePage::Geolocation]);
settings.setValue("GeolocationDenied", m_denied[QWebEnginePage::Geolocation]);
settings.setValue("MediaAudioCaptureGranted", m_granted[QWebEnginePage::MediaAudioCapture]);
settings.setValue("MediaAudioCaptureDenied", m_denied[QWebEnginePage::MediaAudioCapture]);
settings.setValue("MediaVideoCaptureGranted", m_granted[QWebEnginePage::MediaVideoCapture]);
settings.setValue("MediaVideoCaptureDenied", m_denied[QWebEnginePage::MediaVideoCapture]);
settings.setValue("MediaAudioVideoCaptureGranted", m_granted[QWebEnginePage::MediaAudioVideoCapture]);
settings.setValue("MediaAudioVideoCaptureDenied", m_denied[QWebEnginePage::MediaAudioVideoCapture]);
settings.setValue("MouseLockGranted", m_granted[QWebEnginePage::MouseLock]);
settings.setValue("MouseLockDenied", m_denied[QWebEnginePage::MouseLock]);
settings.endGroup();
mApp->html5PermissionsManager()->loadSettings();
}
HTML5PermissionsDialog::~HTML5PermissionsDialog()
{
delete ui;
}

View File

@ -20,6 +20,7 @@
#include <QDialog>
#include <QStringList>
#include <QWebEnginePage>
namespace Ui
{
@ -33,11 +34,12 @@ class HTML5PermissionsDialog : public QDialog
public:
explicit HTML5PermissionsDialog(QWidget* parent = 0);
~HTML5PermissionsDialog();
void setCurrentTab(int index);
void showFeaturePermissions(QWebEnginePage::Feature feature);
private slots:
void removeNotifEntry();
void removeGeoEntry();
void removeEntry();
void featureIndexChanged();
void saveSettings();
@ -45,14 +47,12 @@ private:
enum Role { Allow, Deny };
void loadSettings();
QWebEnginePage::Feature currentFeature() const;
Ui::HTML5PermissionsDialog* ui;
QStringList m_notificationsGranted;
QStringList m_notificationsDenied;
QStringList m_geolocationGranted;
QStringList m_geolocationDenied;
QHash<QWebEnginePage::Feature, QStringList> m_granted;
QHash<QWebEnginePage::Feature, QStringList> m_denied;
};
#endif // HTML5PERMISSIONSDIALOG_H

View File

@ -13,123 +13,32 @@
<property name="windowTitle">
<string>HTML5 Permissions</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Notifications</string>
</attribute>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QTreeWidget" name="notifTree">
<property name="indentation">
<number>0</number>
</property>
<property name="sortingEnabled">
<bool>true</bool>
</property>
<property name="allColumnsShowFocus">
<bool>true</bool>
</property>
<column>
<property name="text">
<string>Site</string>
</property>
</column>
<column>
<property name="text">
<string>Behaviour</string>
</property>
</column>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="notifRemove">
<property name="text">
<string>Remove</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Geolocation</string>
</attribute>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QTreeWidget" name="geoTree">
<property name="indentation">
<number>0</number>
</property>
<property name="sortingEnabled">
<bool>true</bool>
</property>
<property name="allColumnsShowFocus">
<bool>true</bool>
</property>
<column>
<property name="text">
<string>Site</string>
</property>
</column>
<column>
<property name="text">
<string>Behaviour</string>
</property>
</column>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="geoRemove">
<property name="text">
<string>Remove</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="1">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="remove">
<property name="text">
<string>Remove</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<item row="2" column="0" colspan="2">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@ -139,6 +48,87 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QTreeWidget" name="treeWidget">
<property name="indentation">
<number>0</number>
</property>
<property name="sortingEnabled">
<bool>true</bool>
</property>
<property name="allColumnsShowFocus">
<bool>true</bool>
</property>
<column>
<property name="text">
<string>Site</string>
</property>
</column>
<column>
<property name="text">
<string>Behaviour</string>
</property>
</column>
</widget>
</item>
<item row="0" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Permission for:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="feature">
<item>
<property name="text">
<string>Notifications</string>
</property>
</item>
<item>
<property name="text">
<string>Geolocation</string>
</property>
</item>
<item>
<property name="text">
<string>Microphone</string>
</property>
</item>
<item>
<property name="text">
<string>Web Camera</string>
</property>
</item>
<item>
<property name="text">
<string>Microphone and Web Camera</string>
</property>
</item>
<item>
<property name="text">
<string>Hide Pointer</string>
</property>
</item>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>

View File

@ -1,6 +1,6 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2013-2014 David Rosca <nowrep@gmail.com>
* Copyright (C) 2013-2015 David Rosca <nowrep@gmail.com>
*
* 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
@ -27,102 +27,77 @@ HTML5PermissionsManager::HTML5PermissionsManager(QObject* parent)
loadSettings();
}
#if QTWEBENGINE_DISABLED
void HTML5PermissionsManager::requestPermissions(WebPage* page, QWebEngineFrame* frame, const QWebEnginePage::Feature &feature)
void HTML5PermissionsManager::requestPermissions(WebPage* page, const QUrl &origin, const QWebEnginePage::Feature &feature)
{
if (!frame || !page) {
if (!page) {
return;
}
const QString host = page->url().host();
WebView* view = qobject_cast<WebView*>(page->view());
switch (feature) {
case QWebEnginePage::Notifications:
if (m_notificationsGranted.contains(host)) {
page->setFeaturePermission(frame, feature, QWebEnginePage::PermissionGrantedByUser);
return;
}
if (m_notificationsDenied.contains(host)) {
page->setFeaturePermission(frame, feature, QWebEnginePage::PermissionDeniedByUser);
return;
}
if (view) {
HTML5PermissionsNotification* notif = new HTML5PermissionsNotification(host, frame, feature);
view->addNotification(notif);
}
break;
case QWebEnginePage::Geolocation:
if (m_geolocationGranted.contains(host)) {
page->setFeaturePermission(frame, feature, QWebEnginePage::PermissionGrantedByUser);
return;
}
if (m_geolocationDenied.contains(host)) {
page->setFeaturePermission(frame, feature, QWebEnginePage::PermissionDeniedByUser);
return;
}
if (view) {
HTML5PermissionsNotification* notif = new HTML5PermissionsNotification(host, frame, feature);
view->addNotification(notif);
}
break;
default:
if (!m_granted.contains(feature) || !m_denied.contains(feature)) {
qWarning() << "HTML5PermissionsManager: Unknown feature" << feature;
break;
return;
}
// Permission granted
if (m_granted.value(feature).contains(origin.toString())) {
page->setFeaturePermission(origin, feature, QWebEnginePage::PermissionGrantedByUser);
return;
}
// Permission denied
if (m_denied.value(feature).contains(origin.toString())) {
page->setFeaturePermission(origin, feature, QWebEnginePage::PermissionDeniedByUser);
return;
}
// Ask user for permission
WebView* view = qobject_cast<WebView*>(page->view());
if (view) {
HTML5PermissionsNotification* notif = new HTML5PermissionsNotification(origin, page, feature);
view->addNotification(notif);
}
}
void HTML5PermissionsManager::rememberPermissions(const QString &host, const QWebEnginePage::Feature &feature,
void HTML5PermissionsManager::rememberPermissions(const QUrl &origin, const QWebEnginePage::Feature &feature,
const QWebEnginePage::PermissionPolicy &policy)
{
if (host.isEmpty()) {
if (origin.isEmpty()) {
return;
}
switch (feature) {
case QWebEnginePage::Notifications:
if (policy == QWebEnginePage::PermissionGrantedByUser) {
m_notificationsGranted.append(host);
}
else {
m_notificationsDenied.append(host);
}
break;
case QWebEnginePage::Geolocation:
if (policy == QWebEnginePage::PermissionGrantedByUser) {
m_geolocationGranted.append(host);
}
else {
m_geolocationDenied.append(host);
}
break;
default:
qWarning() << "HTML5PermissionsManager: Unknown feature" << feature;
break;
if (policy == QWebEnginePage::PermissionGrantedByUser) {
m_granted[feature].append(origin.toString());
}
else {
m_denied[feature].append(origin.toString());
}
saveSettings();
}
#endif
void HTML5PermissionsManager::loadSettings()
{
Settings settings;
settings.beginGroup("HTML5Notifications");
m_notificationsGranted = settings.value("NotificationsGranted", QStringList()).toStringList();
m_notificationsDenied = settings.value("NotificationsDenied", QStringList()).toStringList();
m_geolocationGranted = settings.value("GeolocationGranted", QStringList()).toStringList();
m_geolocationDenied = settings.value("GeolocationDenied", QStringList()).toStringList();
m_granted[QWebEnginePage::Notifications] = settings.value("NotificationsGranted", QStringList()).toStringList();
m_denied[QWebEnginePage::Notifications] = settings.value("NotificationsDenied", QStringList()).toStringList();
m_granted[QWebEnginePage::Geolocation] = settings.value("GeolocationGranted", QStringList()).toStringList();
m_denied[QWebEnginePage::Geolocation] = settings.value("GeolocationDenied", QStringList()).toStringList();
m_granted[QWebEnginePage::MediaAudioCapture] = settings.value("MediaAudioCaptureGranted", QStringList()).toStringList();
m_denied[QWebEnginePage::MediaAudioCapture] = settings.value("MediaAudioCaptureDenied", QStringList()).toStringList();
m_granted[QWebEnginePage::MediaVideoCapture] = settings.value("MediaVideoCaptureGranted", QStringList()).toStringList();
m_denied[QWebEnginePage::MediaVideoCapture] = settings.value("MediaVideoCaptureDenied", QStringList()).toStringList();
m_granted[QWebEnginePage::MediaAudioVideoCapture] = settings.value("MediaAudioVideoCaptureGranted", QStringList()).toStringList();
m_denied[QWebEnginePage::MediaAudioVideoCapture] = settings.value("MediaAudioVideoCaptureDenied", QStringList()).toStringList();
m_granted[QWebEnginePage::MouseLock] = settings.value("MouseLockGranted", QStringList()).toStringList();
m_denied[QWebEnginePage::MouseLock] = settings.value("MouseLockDenied", QStringList()).toStringList();
settings.endGroup();
}
@ -130,14 +105,24 @@ void HTML5PermissionsManager::saveSettings()
{
Settings settings;
settings.beginGroup("HTML5Notifications");
settings.setValue("NotificationsGranted", m_notificationsGranted);
settings.setValue("NotificationsDenied", m_notificationsDenied);
settings.setValue("GeolocationGranted", m_geolocationGranted);
settings.setValue("GeolocationDenied", m_geolocationDenied);
settings.setValue("NotificationsGranted", m_granted[QWebEnginePage::Notifications]);
settings.setValue("NotificationsDenied", m_denied[QWebEnginePage::Notifications]);
settings.setValue("GeolocationGranted", m_granted[QWebEnginePage::Geolocation]);
settings.setValue("GeolocationDenied", m_denied[QWebEnginePage::Geolocation]);
settings.setValue("MediaAudioCaptureGranted", m_granted[QWebEnginePage::MediaAudioCapture]);
settings.setValue("MediaAudioCaptureDenied", m_denied[QWebEnginePage::MediaAudioCapture]);
settings.setValue("MediaVideoCaptureGranted", m_granted[QWebEnginePage::MediaVideoCapture]);
settings.setValue("MediaVideoCaptureDenied", m_denied[QWebEnginePage::MediaVideoCapture]);
settings.setValue("MediaAudioVideoCaptureGranted", m_granted[QWebEnginePage::MediaAudioVideoCapture]);
settings.setValue("MediaAudioVideoCaptureDenied", m_denied[QWebEnginePage::MediaAudioVideoCapture]);
settings.setValue("MouseLockGranted", m_granted[QWebEnginePage::MouseLock]);
settings.setValue("MouseLockDenied", m_denied[QWebEnginePage::MouseLock]);
settings.endGroup();
}
void HTML5PermissionsManager::showSettingsDialog()
{
}

View File

@ -1,6 +1,6 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2013-2014 David Rosca <nowrep@gmail.com>
* Copyright (C) 2013-2015 David Rosca <nowrep@gmail.com>
*
* 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
@ -32,23 +32,17 @@ class QUPZILLA_EXPORT HTML5PermissionsManager : public QObject
public:
explicit HTML5PermissionsManager(QObject* parent);
#if QTWEBENGINE_DISABLED
void requestPermissions(WebPage* page, QWebEngineFrame* frame, const QWebEnginePage::Feature &feature);
void rememberPermissions(const QString &host, const QWebEnginePage::Feature &feature,
void requestPermissions(WebPage* page, const QUrl &origin, const QWebEnginePage::Feature &feature);
void rememberPermissions(const QUrl &origin, const QWebEnginePage::Feature &feature,
const QWebEnginePage::PermissionPolicy &policy);
#endif
void loadSettings();
void showSettingsDialog();
private:
void saveSettings();
QStringList m_notificationsGranted;
QStringList m_notificationsDenied;
QStringList m_geolocationGranted;
QStringList m_geolocationDenied;
QHash<QWebEnginePage::Feature, QStringList> m_granted;
QHash<QWebEnginePage::Feature, QStringList> m_denied;
};
#endif // HTML5PERMISSIONSMANAGER_H

View File

@ -1,6 +1,6 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2013-2014 David Rosca <nowrep@gmail.com>
* Copyright (C) 2013-2015 David Rosca <nowrep@gmail.com>
*
* 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
@ -21,15 +21,13 @@
#include "mainapplication.h"
#include "iconprovider.h"
#if QTWEBENGINE_DISABLED
#include <QWebEngineFrame>
#include <QWebEnginePage>
#ifdef USE_QTWEBKIT_2_2
HTML5PermissionsNotification::HTML5PermissionsNotification(const QString &host, QWebEngineFrame* frame, const QWebEnginePage::Feature &feature)
HTML5PermissionsNotification::HTML5PermissionsNotification(const QUrl &origin, QWebEnginePage* page, const QWebEnginePage::Feature &feature)
: AnimatedWidget(AnimatedWidget::Down, 300, 0)
, ui(new Ui::HTML5PermissionsNotification)
, m_host(host)
, m_frame(frame)
, m_origin(origin)
, m_page(page)
, m_feature(feature)
{
setAutoFillBackground(true);
@ -37,19 +35,43 @@ HTML5PermissionsNotification::HTML5PermissionsNotification(const QString &host,
ui->close->setIcon(IconProvider::standardIcon(QStyle::SP_DialogCloseButton));
QString message;
QString site = m_host.isEmpty() ? tr("this site") : QString("<b>%1</b>").arg(m_host);
const QString site = m_origin.host().isEmpty() ? tr("this site") : QString("<b>%1</b>").arg(m_origin.host());
if (feature == QWebEnginePage::Notifications) {
switch (feature) {
case QWebEnginePage::Notifications:
ui->iconLabel->setPixmap(QPixmap(":icons/other/notification.png"));
message = tr("Allow %1 to show desktop notifications?").arg(site);
}
else if (feature == QWebEnginePage::Geolocation) {
ui->iconLabel->setPixmap(QPixmap(":icons/other/geolocation.png"));
message = tr("Allow %1 to locate your position?").arg(site);
}
ui->textLabel->setText(tr("Allow %1 to show desktop notifications?").arg(site));
break;
ui->textLabel->setText(message);
case QWebEnginePage::Geolocation:
ui->iconLabel->setPixmap(QPixmap(":icons/other/geolocation.png"));
ui->textLabel->setText(tr("Allow %1 to locate your position?").arg(site));
break;
case QWebEnginePage::MediaAudioCapture:
ui->iconLabel->setPixmap(QPixmap(":icons/other/audiocapture.png"));
ui->textLabel->setText(tr("Allow %1 to use your microphone?").arg(site));
break;
case QWebEnginePage::MediaVideoCapture:
ui->iconLabel->setPixmap(QPixmap(":icons/other/webcam.png"));
ui->textLabel->setText(tr("Allow %1 to use your web camera?").arg(site));
break;
case QWebEnginePage::MediaAudioVideoCapture:
ui->iconLabel->setPixmap(QPixmap(":icons/other/microphone-webcam.png"));
ui->textLabel->setText(tr("Allow %1 to use your microphone and web camera?").arg(site));
break;
case QWebEnginePage::MouseLock:
ui->iconLabel->setPixmap(QPixmap(":icons/other/mouselock.png"));
ui->textLabel->setText(tr("Allow %1 to hide your pointer?").arg(site));
break;
default:
qWarning() << "Unknown feature" << feature;
break;
}
connect(ui->allow, SIGNAL(clicked()), this, SLOT(grantPermissions()));
connect(ui->deny, SIGNAL(clicked()), this, SLOT(denyPermissions()));
@ -60,15 +82,14 @@ HTML5PermissionsNotification::HTML5PermissionsNotification(const QString &host,
void HTML5PermissionsNotification::grantPermissions()
{
if (!m_frame || !m_frame->page()) {
if (!m_page) {
return;
}
QWebEnginePage* page = m_frame->page();
page->setFeaturePermission(m_frame, m_feature, QWebEnginePage::PermissionGrantedByUser);
m_page->setFeaturePermission(m_origin, m_feature, QWebEnginePage::PermissionGrantedByUser);
if (ui->remember->isChecked()) {
mApp->html5PermissionsManager()->rememberPermissions(m_host, m_feature, QWebEnginePage::PermissionGrantedByUser);
mApp->html5PermissionsManager()->rememberPermissions(m_origin, m_feature, QWebEnginePage::PermissionGrantedByUser);
}
hide();
@ -76,15 +97,14 @@ void HTML5PermissionsNotification::grantPermissions()
void HTML5PermissionsNotification::denyPermissions()
{
if (!m_frame || !m_frame->page()) {
if (!m_page) {
return;
}
QWebEnginePage* page = m_frame->page();
page->setFeaturePermission(m_frame, m_feature, QWebEnginePage::PermissionDeniedByUser);
m_page->setFeaturePermission(m_origin, m_feature, QWebEnginePage::PermissionDeniedByUser);
if (ui->remember->isChecked()) {
mApp->html5PermissionsManager()->rememberPermissions(m_host, m_feature, QWebEnginePage::PermissionDeniedByUser);
mApp->html5PermissionsManager()->rememberPermissions(m_origin, m_feature, QWebEnginePage::PermissionDeniedByUser);
}
hide();
@ -94,6 +114,3 @@ HTML5PermissionsNotification::~HTML5PermissionsNotification()
{
delete ui;
}
#endif // USE_QTWEBKIT_2_2
#endif

View File

@ -1,6 +1,6 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2013-2014 David Rosca <nowrep@gmail.com>
* Copyright (C) 2013-2015 David Rosca <nowrep@gmail.com>
*
* 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
@ -32,9 +32,8 @@ class HTML5PermissionsNotification : public AnimatedWidget
{
Q_OBJECT
#ifdef USE_QTWEBKIT_2_2
public:
explicit HTML5PermissionsNotification(const QString &host, QWebEngineFrame* frame, const QWebEnginePage::Feature &feature);
explicit HTML5PermissionsNotification(const QUrl &origin, QWebEnginePage* page, const QWebEnginePage::Feature &feature);
~HTML5PermissionsNotification();
private slots:
@ -44,10 +43,9 @@ private slots:
private:
Ui::HTML5PermissionsNotification* ui;
QString m_host;
QWebEngineFrame* m_frame;
QUrl m_origin;
QWebEnginePage* m_page;
QWebEnginePage::Feature m_feature;
#endif
};
#endif // HTML5PERMISSIONSNOTIFICATION_H

View File

@ -1,6 +1,6 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
* Copyright (C) 2010-2015 David Rosca <nowrep@gmail.com>
*
* 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
@ -79,6 +79,8 @@ WebPage::WebPage(QObject* parent)
, m_secureStatus(false)
, m_adjustingScheduled(false)
{
connect(this, &QWebEnginePage::featurePermissionRequested, this, &WebPage::featurePermissionRequested);
#if QTWEBENGINE_DISABLED
m_javaScriptEnabled = QWebEngineSettings::globalSettings()->testAttribute(QWebEngineSettings::JavascriptEnabled);
@ -651,6 +653,11 @@ void WebPage::doWebSearch(const QString &text)
}
}
void WebPage::featurePermissionRequested(const QUrl &origin, const QWebEnginePage::Feature &feature)
{
mApp->html5PermissionsManager()->requestPermissions(this, origin, feature);
}
#ifdef USE_QTWEBKIT_2_2
void WebPage::appCacheQuotaExceeded(QWebSecurityOrigin* origin, quint64 originalQuota)
{
@ -660,11 +667,6 @@ void WebPage::appCacheQuotaExceeded(QWebSecurityOrigin* origin, quint64 original
origin->setApplicationCacheQuota(originalQuota * 2);
}
void WebPage::featurePermissionRequested(QWebEngineFrame* frame, const QWebEnginePage::Feature &feature)
{
mApp->html5PermissionsManager()->requestPermissions(this, frame, feature);
}
#endif // USE_QTWEBKIT_2_2
bool WebPage::event(QEvent* event)

View File

@ -1,6 +1,6 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
* Copyright (C) 2010-2015 David Rosca <nowrep@gmail.com>
*
* 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
@ -113,10 +113,10 @@ private slots:
#endif
void doWebSearch(const QString &text);
void featurePermissionRequested(const QUrl &origin, const QWebEnginePage::Feature &feature);
#ifdef USE_QTWEBKIT_2_2
void appCacheQuotaExceeded(QWebSecurityOrigin* origin, quint64 originalQuota);
void featurePermissionRequested(QWebFrame* frame, const QWebPage::Feature &feature);
#endif
protected: