mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 02:36:34 +01:00
Ask user to allow site to use notifications/geolocation.
With option to remmber the choice for page.
This commit is contained in:
parent
8cc303a355
commit
81ac819746
@ -51,6 +51,7 @@
|
||||
#include "restoremanager.h"
|
||||
#include "proxystyle.h"
|
||||
#include "registerqappassociation.h"
|
||||
#include "html5permissions/html5permissionsmanager.h"
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
#include <QFileOpenEvent>
|
||||
@ -86,6 +87,7 @@ MainApplication::MainApplication(int &argc, char** argv)
|
||||
, m_searchEnginesManager(0)
|
||||
, m_restoreManager(0)
|
||||
, m_proxyStyle(0)
|
||||
, m_html5permissions(0)
|
||||
, m_dbWriter(new DatabaseWriter(this))
|
||||
, m_uaManager(new UserAgentManager)
|
||||
, m_isPrivateSession(false)
|
||||
@ -802,6 +804,14 @@ DesktopNotificationsFactory* MainApplication::desktopNotifications()
|
||||
return m_desktopNotifications;
|
||||
}
|
||||
|
||||
HTML5PermissionsManager *MainApplication::html5permissions()
|
||||
{
|
||||
if (!m_html5permissions) {
|
||||
m_html5permissions = new HTML5PermissionsManager(this);
|
||||
}
|
||||
return m_html5permissions;
|
||||
}
|
||||
|
||||
void MainApplication::startPrivateBrowsing()
|
||||
{
|
||||
QStringList args;
|
||||
|
@ -50,6 +50,7 @@ class DatabaseWriter;
|
||||
class UserAgentManager;
|
||||
class ProxyStyle;
|
||||
class RegisterQAppAssociation;
|
||||
class HTML5PermissionsManager;
|
||||
|
||||
class QT_QUPZILLA_EXPORT MainApplication : public QtSingleApplication
|
||||
{
|
||||
@ -105,6 +106,7 @@ public:
|
||||
SearchEnginesManager* searchEnginesManager();
|
||||
QNetworkDiskCache* networkCache();
|
||||
DesktopNotificationsFactory* desktopNotifications();
|
||||
HTML5PermissionsManager* html5permissions();
|
||||
|
||||
DatabaseWriter* dbWriter() { return m_dbWriter; }
|
||||
UserAgentManager* uaManager() { return m_uaManager; }
|
||||
@ -161,6 +163,7 @@ private:
|
||||
SearchEnginesManager* m_searchEnginesManager;
|
||||
RestoreManager* m_restoreManager;
|
||||
ProxyStyle* m_proxyStyle;
|
||||
HTML5PermissionsManager* m_html5permissions;
|
||||
DatabaseWriter* m_dbWriter;
|
||||
UserAgentManager* m_uaManager;
|
||||
|
||||
|
@ -70,5 +70,7 @@
|
||||
<file>icons/sites/youtube.png</file>
|
||||
<file>icons/preferences/preferences-desktop-keyboard-shortcuts.png</file>
|
||||
<file>icons/menu/tab.png</file>
|
||||
<file>icons/other/geolocation.png</file>
|
||||
<file>icons/other/notification.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
BIN
src/lib/data/icons/other/geolocation.png
Normal file
BIN
src/lib/data/icons/other/geolocation.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.0 KiB |
BIN
src/lib/data/icons/other/notification.png
Normal file
BIN
src/lib/data/icons/other/notification.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
@ -197,7 +197,9 @@ SOURCES += \
|
||||
network/schemehandlers/fileschemehandler.cpp \
|
||||
other/registerqappassociation.cpp \
|
||||
tools/listitemdelegate.cpp \
|
||||
bookmarks/bookmarkstree.cpp
|
||||
bookmarks/bookmarkstree.cpp \
|
||||
tools/html5permissions/html5permissionsmanager.cpp \
|
||||
tools/html5permissions/html5permissionsnotification.cpp
|
||||
|
||||
HEADERS += \
|
||||
webview/tabpreview.h \
|
||||
@ -357,7 +359,9 @@ HEADERS += \
|
||||
network/schemehandlers/fileschemehandler.h \
|
||||
other/registerqappassociation.h \
|
||||
tools/listitemdelegate.h \
|
||||
bookmarks/bookmarkstree.h
|
||||
bookmarks/bookmarkstree.h \
|
||||
tools/html5permissions/html5permissionsmanager.h \
|
||||
tools/html5permissions/html5permissionsnotification.h
|
||||
|
||||
FORMS += \
|
||||
preferences/autofillmanager.ui \
|
||||
@ -403,7 +407,8 @@ FORMS += \
|
||||
other/iconchooser.ui \
|
||||
adblock/adblockaddsubscriptiondialog.ui \
|
||||
preferences/useragentdialog.ui \
|
||||
session/recoverywidget.ui
|
||||
session/recoverywidget.ui \
|
||||
tools/html5permissions/html5permissionsnotification.ui
|
||||
|
||||
RESOURCES += \
|
||||
data/icons.qrc \
|
||||
|
126
src/lib/tools/html5permissions/html5permissionsmanager.cpp
Normal file
126
src/lib/tools/html5permissions/html5permissionsmanager.cpp
Normal file
@ -0,0 +1,126 @@
|
||||
#include "html5permissionsmanager.h"
|
||||
#include "html5permissionsnotification.h"
|
||||
#include "settings.h"
|
||||
#include "webpage.h"
|
||||
#include "webview.h"
|
||||
|
||||
#include <QWebFrame>
|
||||
#include <QDebug>
|
||||
|
||||
HTML5PermissionsManager::HTML5PermissionsManager(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
loadSettings();
|
||||
}
|
||||
|
||||
void HTML5PermissionsManager::requestPermissions(WebPage* page, QWebFrame *frame, const QWebPage::Feature &feature)
|
||||
{
|
||||
if (!frame || !page) {
|
||||
return;
|
||||
}
|
||||
|
||||
const QString &host = page->url().host();
|
||||
WebView* view = qobject_cast<WebView*>(page->view());
|
||||
|
||||
switch (feature) {
|
||||
case QWebPage::Notifications:
|
||||
if (m_notificationsGranted.contains(host)) {
|
||||
page->setFeaturePermission(frame, feature, QWebPage::PermissionGrantedByUser);
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_notificationsDenied.contains(host)) {
|
||||
page->setFeaturePermission(frame, feature, QWebPage::PermissionDeniedByUser);
|
||||
return;
|
||||
}
|
||||
|
||||
if (view) {
|
||||
HTML5PermissionsNotification* notif = new HTML5PermissionsNotification(host, frame, feature);
|
||||
view->addNotification(notif);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case QWebPage::Geolocation:
|
||||
if (m_geolocationGranted.contains(host)) {
|
||||
page->setFeaturePermission(frame, feature, QWebPage::PermissionGrantedByUser);
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_geolocationDenied.contains(host)) {
|
||||
page->setFeaturePermission(frame, feature, QWebPage::PermissionDeniedByUser);
|
||||
return;
|
||||
}
|
||||
|
||||
if (view) {
|
||||
HTML5PermissionsNotification* notif = new HTML5PermissionsNotification(host, frame, feature);
|
||||
view->addNotification(notif);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
qWarning() << "HTML5PermissionsManager: Unknown feature" << feature;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void HTML5PermissionsManager::rememberPermissions(const QString &host, const QWebPage::Feature &feature,
|
||||
const QWebPage::PermissionPolicy &policy)
|
||||
{
|
||||
if (host.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (feature) {
|
||||
case QWebPage::Notifications:
|
||||
if (policy == QWebPage::PermissionGrantedByUser) {
|
||||
m_notificationsGranted.append(host);
|
||||
}
|
||||
else {
|
||||
m_notificationsDenied.append(host);
|
||||
}
|
||||
break;
|
||||
|
||||
case QWebPage::Geolocation:
|
||||
if (policy == QWebPage::PermissionGrantedByUser) {
|
||||
m_geolocationGranted.append(host);
|
||||
}
|
||||
else {
|
||||
m_geolocationDenied.append(host);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
qWarning() << "HTML5PermissionsManager: Unknown feature" << feature;
|
||||
break;
|
||||
}
|
||||
|
||||
saveSettings();
|
||||
}
|
||||
|
||||
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();
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
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.endGroup();
|
||||
}
|
||||
|
||||
void HTML5PermissionsManager::showSettingsDialog()
|
||||
{
|
||||
}
|
35
src/lib/tools/html5permissions/html5permissionsmanager.h
Normal file
35
src/lib/tools/html5permissions/html5permissionsmanager.h
Normal file
@ -0,0 +1,35 @@
|
||||
#ifndef HTML5PERMISSIONSMANAGER_H
|
||||
#define HTML5PERMISSIONSMANAGER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QStringList>
|
||||
#include <QWebPage>
|
||||
|
||||
#include "qz_namespace.h"
|
||||
|
||||
class QUrl;
|
||||
class WebPage;
|
||||
|
||||
class QT_QUPZILLA_EXPORT HTML5PermissionsManager : public QObject
|
||||
{
|
||||
public:
|
||||
explicit HTML5PermissionsManager(QObject* parent);
|
||||
|
||||
void requestPermissions(WebPage* page, QWebFrame* frame, const QWebPage::Feature &feature);
|
||||
void rememberPermissions(const QString &host, const QWebPage::Feature &feature,
|
||||
const QWebPage::PermissionPolicy &policy);
|
||||
|
||||
void loadSettings();
|
||||
void showSettingsDialog();
|
||||
|
||||
private:
|
||||
void saveSettings();
|
||||
|
||||
QStringList m_notificationsGranted;
|
||||
QStringList m_notificationsDenied;
|
||||
|
||||
QStringList m_geolocationGranted;
|
||||
QStringList m_geolocationDenied;
|
||||
};
|
||||
|
||||
#endif // HTML5PERMISSIONSMANAGER_H
|
@ -0,0 +1,76 @@
|
||||
#include "ui_html5permissionsnotification.h"
|
||||
#include "html5permissionsnotification.h"
|
||||
#include "html5permissionsmanager.h"
|
||||
#include "mainapplication.h"
|
||||
#include "iconprovider.h"
|
||||
|
||||
#include <QWebFrame>
|
||||
|
||||
HTML5PermissionsNotification::HTML5PermissionsNotification(const QString &host, QWebFrame *frame, const QWebPage::Feature &feature)
|
||||
: AnimatedWidget(AnimatedWidget::Down, 300, 0)
|
||||
, ui(new Ui::HTML5PermissionsNotification)
|
||||
, m_host(host)
|
||||
, m_frame(frame)
|
||||
, m_feature(feature)
|
||||
{
|
||||
ui->setupUi(widget());
|
||||
|
||||
ui->close->setIcon(qIconProvider->standardIcon(QStyle::SP_DialogCloseButton));
|
||||
|
||||
QString message;
|
||||
QString site = m_host.isEmpty() ? tr("this site") : QString("<b>%1</b>").arg(m_host);
|
||||
|
||||
if (feature == QWebPage::Notifications) {
|
||||
ui->iconLabel->setPixmap(QPixmap(":icons/other/notification.png"));
|
||||
message = tr("Allow %1 to show desktop notifications?").arg(site);
|
||||
}
|
||||
else if (feature == QWebPage::Geolocation) {
|
||||
ui->iconLabel->setPixmap(QPixmap(":icons/other/geolocation.png"));
|
||||
message = tr("Allow %1 to locate your position?").arg(site);
|
||||
}
|
||||
|
||||
ui->textLabel->setText(message);
|
||||
|
||||
connect(ui->allow, SIGNAL(clicked()), this, SLOT(grantPermissions()));
|
||||
connect(ui->deny, SIGNAL(clicked()), this, SLOT(denyPermissions()));
|
||||
connect(ui->close, SIGNAL(clicked()), this, SLOT(denyPermissions()));
|
||||
|
||||
startAnimation();
|
||||
}
|
||||
|
||||
void HTML5PermissionsNotification::grantPermissions()
|
||||
{
|
||||
if (!m_frame || !m_frame->page()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QWebPage* page = m_frame->page();
|
||||
page->setFeaturePermission(m_frame, m_feature, QWebPage::PermissionGrantedByUser);
|
||||
|
||||
if (ui->remember->isChecked()) {
|
||||
mApp->html5permissions()->rememberPermissions(m_host, m_feature, QWebPage::PermissionGrantedByUser);
|
||||
}
|
||||
|
||||
hide();
|
||||
}
|
||||
|
||||
void HTML5PermissionsNotification::denyPermissions()
|
||||
{
|
||||
if (!m_frame || !m_frame->page()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QWebPage* page = m_frame->page();
|
||||
page->setFeaturePermission(m_frame, m_feature, QWebPage::PermissionDeniedByUser);
|
||||
|
||||
if (ui->remember->isChecked()) {
|
||||
mApp->html5permissions()->rememberPermissions(m_host, m_feature, QWebPage::PermissionDeniedByUser);
|
||||
}
|
||||
|
||||
hide();
|
||||
}
|
||||
|
||||
HTML5PermissionsNotification::~HTML5PermissionsNotification()
|
||||
{
|
||||
delete ui;
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
#ifndef HTML5PERMISSIONSNOTIFICATION_H
|
||||
#define HTML5PERMISSIONSNOTIFICATION_H
|
||||
|
||||
#include <QWebPage>
|
||||
#include <QString>
|
||||
|
||||
#include "animatedwidget.h"
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class HTML5PermissionsNotification;
|
||||
}
|
||||
|
||||
class HTML5PermissionsNotification : public AnimatedWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit HTML5PermissionsNotification(const QString &host, QWebFrame* frame, const QWebPage::Feature &feature);
|
||||
~HTML5PermissionsNotification();
|
||||
|
||||
private slots:
|
||||
void grantPermissions();
|
||||
void denyPermissions();
|
||||
|
||||
private:
|
||||
Ui::HTML5PermissionsNotification* ui;
|
||||
|
||||
QString m_host;
|
||||
QWebFrame* m_frame;
|
||||
QWebPage::Feature m_feature;
|
||||
};
|
||||
|
||||
#endif // HTML5PERMISSIONSNOTIFICATION_H
|
@ -0,0 +1,94 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>HTML5PermissionsNotification</class>
|
||||
<widget class="QWidget" name="HTML5PermissionsNotification">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>820</width>
|
||||
<height>36</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="iconLabel">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>24</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>24</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="scaledContents">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="textLabel">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</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>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="remember">
|
||||
<property name="text">
|
||||
<string>Remember</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="allow">
|
||||
<property name="text">
|
||||
<string>Allow</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="deny">
|
||||
<property name="text">
|
||||
<string>Deny</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="close">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="autoRaise">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
@ -36,6 +36,7 @@
|
||||
#include "qzsettings.h"
|
||||
#include "useragentmanager.h"
|
||||
#include "recoverywidget.h"
|
||||
#include "html5permissions/html5permissionsmanager.h"
|
||||
#include "schemehandlers/fileschemehandler.h"
|
||||
|
||||
#ifdef NONBLOCK_JS_DIALOGS
|
||||
@ -394,8 +395,7 @@ void WebPage::windowCloseRequested()
|
||||
#ifdef USE_QTWEBKIT_2_2
|
||||
void WebPage::featurePermissionRequested(QWebFrame* frame, const QWebPage::Feature &feature)
|
||||
{
|
||||
// We should probably ask user here ... -,-
|
||||
setFeaturePermission(frame, feature, PermissionGrantedByUser);
|
||||
mApp->html5permissions()->requestPermissions(this, frame, feature);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -53,8 +53,6 @@ public:
|
||||
void setWebView(TabbedWebView* view);
|
||||
void populateNetworkRequest(QNetworkRequest &request);
|
||||
|
||||
TabbedWebView* getView() { return m_view; }
|
||||
|
||||
void setSSLCertificate(const QSslCertificate &cert);
|
||||
QSslCertificate sslCertificate();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user