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() void ClearPrivateData::showNotifsPerms()
{ {
HTML5PermissionsDialog* dialog = new HTML5PermissionsDialog(this); HTML5PermissionsDialog* dialog = new HTML5PermissionsDialog(this);
dialog->showFeaturePermissions(QWebEnginePage::Notifications);
dialog->open(); dialog->open();
} }
void ClearPrivateData::showGeolocPerms() void ClearPrivateData::showGeolocPerms()
{ {
HTML5PermissionsDialog* dialog = new HTML5PermissionsDialog(this); HTML5PermissionsDialog* dialog = new HTML5PermissionsDialog(this);
dialog->setCurrentTab(1); dialog->showFeaturePermissions(QWebEnginePage::Geolocation);
dialog->open(); dialog->open();
} }

View File

@ -21,9 +21,9 @@
#include "mainapplication.h" #include "mainapplication.h"
#include "html5permissionsmanager.h" #include "html5permissionsmanager.h"
HTML5PermissionsDialog::HTML5PermissionsDialog(QWidget* parent) : HTML5PermissionsDialog::HTML5PermissionsDialog(QWidget* parent)
QDialog(parent), : QDialog(parent)
ui(new Ui::HTML5PermissionsDialog) , ui(new Ui::HTML5PermissionsDialog)
{ {
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
@ -31,103 +31,112 @@ HTML5PermissionsDialog::HTML5PermissionsDialog(QWidget* parent) :
loadSettings(); loadSettings();
foreach (const QString &site, m_notificationsGranted) { ui->treeWidget->header()->resizeSection(0, 220);
QTreeWidgetItem* item = new QTreeWidgetItem(ui->notifTree);
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(0, site);
item->setText(1, tr("Allow")); item->setText(1, tr("Allow"));
item->setData(0, Qt::UserRole + 10, Allow); item->setData(0, Qt::UserRole + 10, Allow);
ui->treeWidget->addTopLevelItem(item);
ui->notifTree->addTopLevelItem(item);
} }
foreach (const QString &site, m_notificationsDenied) { foreach (const QString &site, m_denied.value(feature)) {
QTreeWidgetItem* item = new QTreeWidgetItem(ui->notifTree); QTreeWidgetItem* item = new QTreeWidgetItem(ui->treeWidget);
item->setText(0, site); item->setText(0, site);
item->setText(1, tr("Deny")); item->setText(1, tr("Deny"));
item->setData(0, Qt::UserRole + 10, Deny); item->setData(0, Qt::UserRole + 10, Deny);
ui->treeWidget->addTopLevelItem(item);
ui->notifTree->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) { if (!item) {
return; return;
} }
Role role = static_cast<Role>(item->data(0, Qt::UserRole + 10).toInt()); 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) { if (role == Allow)
m_notificationsGranted.removeOne(site); m_granted[currentFeature()].removeOne(origin);
} else
else { m_denied[currentFeature()].removeOne(origin);
m_notificationsDenied.removeOne(site);
}
delete item; delete item;
} }
void HTML5PermissionsDialog::removeGeoEntry() QWebEnginePage::Feature HTML5PermissionsDialog::currentFeature() const
{ {
QTreeWidgetItem* item = ui->geoTree->currentItem(); switch (ui->feature->currentIndex()) {
if (!item) { case 0:
return; 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() void HTML5PermissionsDialog::loadSettings()
{ {
Settings settings; Settings settings;
settings.beginGroup("HTML5Notifications"); settings.beginGroup("HTML5Notifications");
m_notificationsGranted = settings.value("NotificationsGranted", QStringList()).toStringList();
m_notificationsDenied = settings.value("NotificationsDenied", QStringList()).toStringList(); m_granted[QWebEnginePage::Notifications] = settings.value("NotificationsGranted", QStringList()).toStringList();
m_geolocationGranted = settings.value("GeolocationGranted", QStringList()).toStringList(); m_denied[QWebEnginePage::Notifications] = settings.value("NotificationsDenied", QStringList()).toStringList();
m_geolocationDenied = settings.value("GeolocationDenied", 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(); settings.endGroup();
} }
@ -135,16 +144,26 @@ void HTML5PermissionsDialog::saveSettings()
{ {
Settings settings; Settings settings;
settings.beginGroup("HTML5Notifications"); settings.beginGroup("HTML5Notifications");
settings.setValue("NotificationsGranted", m_notificationsGranted);
settings.setValue("NotificationsDenied", m_notificationsDenied); settings.setValue("NotificationsGranted", m_granted[QWebEnginePage::Notifications]);
settings.setValue("GeolocationGranted", m_geolocationGranted); settings.setValue("NotificationsDenied", m_denied[QWebEnginePage::Notifications]);
settings.setValue("GeolocationDenied", m_geolocationDenied);
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(); settings.endGroup();
mApp->html5PermissionsManager()->loadSettings(); mApp->html5PermissionsManager()->loadSettings();
} }
HTML5PermissionsDialog::~HTML5PermissionsDialog()
{
delete ui;
}

View File

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

View File

@ -13,123 +13,32 @@
<property name="windowTitle"> <property name="windowTitle">
<string>HTML5 Permissions</string> <string>HTML5 Permissions</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QGridLayout" name="gridLayout">
<item> <item row="1" column="1">
<widget class="QTabWidget" name="tabWidget"> <layout class="QVBoxLayout" name="verticalLayout_2">
<property name="currentIndex"> <item>
<number>0</number> <spacer name="verticalSpacer">
</property> <property name="orientation">
<widget class="QWidget" name="tab"> <enum>Qt::Vertical</enum>
<attribute name="title"> </property>
<string>Notifications</string> <property name="sizeHint" stdset="0">
</attribute> <size>
<layout class="QHBoxLayout" name="horizontalLayout_2"> <width>20</width>
<item> <height>40</height>
<widget class="QTreeWidget" name="notifTree"> </size>
<property name="indentation"> </property>
<number>0</number> </spacer>
</property> </item>
<property name="sortingEnabled"> <item>
<bool>true</bool> <widget class="QPushButton" name="remove">
</property> <property name="text">
<property name="allColumnsShowFocus"> <string>Remove</string>
<bool>true</bool> </property>
</property> </widget>
<column> </item>
<property name="text"> </layout>
<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>
</item> </item>
<item> <item row="2" column="0" colspan="2">
<widget class="QDialogButtonBox" name="buttonBox"> <widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
@ -139,6 +48,87 @@
</property> </property>
</widget> </widget>
</item> </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> </layout>
</widget> </widget>
<resources/> <resources/>

View File

@ -1,6 +1,6 @@
/* ============================================================ /* ============================================================
* QupZilla - WebKit based browser * 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 * 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 * it under the terms of the GNU General Public License as published by
@ -27,102 +27,77 @@ HTML5PermissionsManager::HTML5PermissionsManager(QObject* parent)
loadSettings(); loadSettings();
} }
#if QTWEBENGINE_DISABLED void HTML5PermissionsManager::requestPermissions(WebPage* page, const QUrl &origin, const QWebEnginePage::Feature &feature)
void HTML5PermissionsManager::requestPermissions(WebPage* page, QWebEngineFrame* frame, const QWebEnginePage::Feature &feature)
{ {
if (!frame || !page) { if (!page) {
return; return;
} }
const QString host = page->url().host(); if (!m_granted.contains(feature) || !m_denied.contains(feature)) {
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:
qWarning() << "HTML5PermissionsManager: Unknown feature" << 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) const QWebEnginePage::PermissionPolicy &policy)
{ {
if (host.isEmpty()) { if (origin.isEmpty()) {
return; return;
} }
switch (feature) { if (policy == QWebEnginePage::PermissionGrantedByUser) {
case QWebEnginePage::Notifications: m_granted[feature].append(origin.toString());
if (policy == QWebEnginePage::PermissionGrantedByUser) { }
m_notificationsGranted.append(host); else {
} m_denied[feature].append(origin.toString());
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;
} }
saveSettings(); saveSettings();
} }
#endif
void HTML5PermissionsManager::loadSettings() void HTML5PermissionsManager::loadSettings()
{ {
Settings settings; Settings settings;
settings.beginGroup("HTML5Notifications"); settings.beginGroup("HTML5Notifications");
m_notificationsGranted = settings.value("NotificationsGranted", QStringList()).toStringList();
m_notificationsDenied = settings.value("NotificationsDenied", QStringList()).toStringList(); m_granted[QWebEnginePage::Notifications] = settings.value("NotificationsGranted", QStringList()).toStringList();
m_geolocationGranted = settings.value("GeolocationGranted", QStringList()).toStringList(); m_denied[QWebEnginePage::Notifications] = settings.value("NotificationsDenied", QStringList()).toStringList();
m_geolocationDenied = settings.value("GeolocationDenied", 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(); settings.endGroup();
} }
@ -130,14 +105,24 @@ void HTML5PermissionsManager::saveSettings()
{ {
Settings settings; Settings settings;
settings.beginGroup("HTML5Notifications"); settings.beginGroup("HTML5Notifications");
settings.setValue("NotificationsGranted", m_notificationsGranted);
settings.setValue("NotificationsDenied", m_notificationsDenied); settings.setValue("NotificationsGranted", m_granted[QWebEnginePage::Notifications]);
settings.setValue("GeolocationGranted", m_geolocationGranted); settings.setValue("NotificationsDenied", m_denied[QWebEnginePage::Notifications]);
settings.setValue("GeolocationDenied", m_geolocationDenied);
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(); settings.endGroup();
} }
void HTML5PermissionsManager::showSettingsDialog()
{
}

View File

@ -1,6 +1,6 @@
/* ============================================================ /* ============================================================
* QupZilla - WebKit based browser * 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 * 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 * it under the terms of the GNU General Public License as published by
@ -32,23 +32,17 @@ class QUPZILLA_EXPORT HTML5PermissionsManager : public QObject
public: public:
explicit HTML5PermissionsManager(QObject* parent); explicit HTML5PermissionsManager(QObject* parent);
#if QTWEBENGINE_DISABLED void requestPermissions(WebPage* page, const QUrl &origin, const QWebEnginePage::Feature &feature);
void requestPermissions(WebPage* page, QWebEngineFrame* frame, const QWebEnginePage::Feature &feature); void rememberPermissions(const QUrl &origin, const QWebEnginePage::Feature &feature,
void rememberPermissions(const QString &host, const QWebEnginePage::Feature &feature,
const QWebEnginePage::PermissionPolicy &policy); const QWebEnginePage::PermissionPolicy &policy);
#endif
void loadSettings(); void loadSettings();
void showSettingsDialog();
private: private:
void saveSettings(); void saveSettings();
QStringList m_notificationsGranted; QHash<QWebEnginePage::Feature, QStringList> m_granted;
QStringList m_notificationsDenied; QHash<QWebEnginePage::Feature, QStringList> m_denied;
QStringList m_geolocationGranted;
QStringList m_geolocationDenied;
}; };
#endif // HTML5PERMISSIONSMANAGER_H #endif // HTML5PERMISSIONSMANAGER_H

View File

@ -1,6 +1,6 @@
/* ============================================================ /* ============================================================
* QupZilla - WebKit based browser * 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 * 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 * it under the terms of the GNU General Public License as published by
@ -21,15 +21,13 @@
#include "mainapplication.h" #include "mainapplication.h"
#include "iconprovider.h" #include "iconprovider.h"
#if QTWEBENGINE_DISABLED #include <QWebEnginePage>
#include <QWebEngineFrame>
#ifdef USE_QTWEBKIT_2_2 HTML5PermissionsNotification::HTML5PermissionsNotification(const QUrl &origin, QWebEnginePage* page, const QWebEnginePage::Feature &feature)
HTML5PermissionsNotification::HTML5PermissionsNotification(const QString &host, QWebEngineFrame* frame, const QWebEnginePage::Feature &feature)
: AnimatedWidget(AnimatedWidget::Down, 300, 0) : AnimatedWidget(AnimatedWidget::Down, 300, 0)
, ui(new Ui::HTML5PermissionsNotification) , ui(new Ui::HTML5PermissionsNotification)
, m_host(host) , m_origin(origin)
, m_frame(frame) , m_page(page)
, m_feature(feature) , m_feature(feature)
{ {
setAutoFillBackground(true); setAutoFillBackground(true);
@ -37,19 +35,43 @@ HTML5PermissionsNotification::HTML5PermissionsNotification(const QString &host,
ui->close->setIcon(IconProvider::standardIcon(QStyle::SP_DialogCloseButton)); ui->close->setIcon(IconProvider::standardIcon(QStyle::SP_DialogCloseButton));
QString message; const QString site = m_origin.host().isEmpty() ? tr("this site") : QString("<b>%1</b>").arg(m_origin.host());
QString site = m_host.isEmpty() ? tr("this site") : QString("<b>%1</b>").arg(m_host);
if (feature == QWebEnginePage::Notifications) { switch (feature) {
case QWebEnginePage::Notifications:
ui->iconLabel->setPixmap(QPixmap(":icons/other/notification.png")); ui->iconLabel->setPixmap(QPixmap(":icons/other/notification.png"));
message = tr("Allow %1 to show desktop notifications?").arg(site); ui->textLabel->setText(tr("Allow %1 to show desktop notifications?").arg(site));
} break;
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(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->allow, SIGNAL(clicked()), this, SLOT(grantPermissions()));
connect(ui->deny, SIGNAL(clicked()), this, SLOT(denyPermissions())); connect(ui->deny, SIGNAL(clicked()), this, SLOT(denyPermissions()));
@ -60,15 +82,14 @@ HTML5PermissionsNotification::HTML5PermissionsNotification(const QString &host,
void HTML5PermissionsNotification::grantPermissions() void HTML5PermissionsNotification::grantPermissions()
{ {
if (!m_frame || !m_frame->page()) { if (!m_page) {
return; return;
} }
QWebEnginePage* page = m_frame->page(); m_page->setFeaturePermission(m_origin, m_feature, QWebEnginePage::PermissionGrantedByUser);
page->setFeaturePermission(m_frame, m_feature, QWebEnginePage::PermissionGrantedByUser);
if (ui->remember->isChecked()) { if (ui->remember->isChecked()) {
mApp->html5PermissionsManager()->rememberPermissions(m_host, m_feature, QWebEnginePage::PermissionGrantedByUser); mApp->html5PermissionsManager()->rememberPermissions(m_origin, m_feature, QWebEnginePage::PermissionGrantedByUser);
} }
hide(); hide();
@ -76,15 +97,14 @@ void HTML5PermissionsNotification::grantPermissions()
void HTML5PermissionsNotification::denyPermissions() void HTML5PermissionsNotification::denyPermissions()
{ {
if (!m_frame || !m_frame->page()) { if (!m_page) {
return; return;
} }
QWebEnginePage* page = m_frame->page(); m_page->setFeaturePermission(m_origin, m_feature, QWebEnginePage::PermissionDeniedByUser);
page->setFeaturePermission(m_frame, m_feature, QWebEnginePage::PermissionDeniedByUser);
if (ui->remember->isChecked()) { if (ui->remember->isChecked()) {
mApp->html5PermissionsManager()->rememberPermissions(m_host, m_feature, QWebEnginePage::PermissionDeniedByUser); mApp->html5PermissionsManager()->rememberPermissions(m_origin, m_feature, QWebEnginePage::PermissionDeniedByUser);
} }
hide(); hide();
@ -94,6 +114,3 @@ HTML5PermissionsNotification::~HTML5PermissionsNotification()
{ {
delete ui; delete ui;
} }
#endif // USE_QTWEBKIT_2_2
#endif

View File

@ -1,6 +1,6 @@
/* ============================================================ /* ============================================================
* QupZilla - WebKit based browser * 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 * 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 * it under the terms of the GNU General Public License as published by
@ -32,9 +32,8 @@ class HTML5PermissionsNotification : public AnimatedWidget
{ {
Q_OBJECT Q_OBJECT
#ifdef USE_QTWEBKIT_2_2
public: public:
explicit HTML5PermissionsNotification(const QString &host, QWebEngineFrame* frame, const QWebEnginePage::Feature &feature); explicit HTML5PermissionsNotification(const QUrl &origin, QWebEnginePage* page, const QWebEnginePage::Feature &feature);
~HTML5PermissionsNotification(); ~HTML5PermissionsNotification();
private slots: private slots:
@ -44,10 +43,9 @@ private slots:
private: private:
Ui::HTML5PermissionsNotification* ui; Ui::HTML5PermissionsNotification* ui;
QString m_host; QUrl m_origin;
QWebEngineFrame* m_frame; QWebEnginePage* m_page;
QWebEnginePage::Feature m_feature; QWebEnginePage::Feature m_feature;
#endif
}; };
#endif // HTML5PERMISSIONSNOTIFICATION_H #endif // HTML5PERMISSIONSNOTIFICATION_H

View File

@ -1,6 +1,6 @@
/* ============================================================ /* ============================================================
* QupZilla - WebKit based browser * 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 * 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 * 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_secureStatus(false)
, m_adjustingScheduled(false) , m_adjustingScheduled(false)
{ {
connect(this, &QWebEnginePage::featurePermissionRequested, this, &WebPage::featurePermissionRequested);
#if QTWEBENGINE_DISABLED #if QTWEBENGINE_DISABLED
m_javaScriptEnabled = QWebEngineSettings::globalSettings()->testAttribute(QWebEngineSettings::JavascriptEnabled); 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 #ifdef USE_QTWEBKIT_2_2
void WebPage::appCacheQuotaExceeded(QWebSecurityOrigin* origin, quint64 originalQuota) void WebPage::appCacheQuotaExceeded(QWebSecurityOrigin* origin, quint64 originalQuota)
{ {
@ -660,11 +667,6 @@ void WebPage::appCacheQuotaExceeded(QWebSecurityOrigin* origin, quint64 original
origin->setApplicationCacheQuota(originalQuota * 2); origin->setApplicationCacheQuota(originalQuota * 2);
} }
void WebPage::featurePermissionRequested(QWebEngineFrame* frame, const QWebEnginePage::Feature &feature)
{
mApp->html5PermissionsManager()->requestPermissions(this, frame, feature);
}
#endif // USE_QTWEBKIT_2_2 #endif // USE_QTWEBKIT_2_2
bool WebPage::event(QEvent* event) bool WebPage::event(QEvent* event)

View File

@ -1,6 +1,6 @@
/* ============================================================ /* ============================================================
* QupZilla - WebKit based browser * 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 * 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 * it under the terms of the GNU General Public License as published by
@ -113,10 +113,10 @@ private slots:
#endif #endif
void doWebSearch(const QString &text); void doWebSearch(const QString &text);
void featurePermissionRequested(const QUrl &origin, const QWebEnginePage::Feature &feature);
#ifdef USE_QTWEBKIT_2_2 #ifdef USE_QTWEBKIT_2_2
void appCacheQuotaExceeded(QWebSecurityOrigin* origin, quint64 originalQuota); void appCacheQuotaExceeded(QWebSecurityOrigin* origin, quint64 originalQuota);
void featurePermissionRequested(QWebFrame* frame, const QWebPage::Feature &feature);
#endif #endif
protected: protected: