mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 09:32:12 +01:00
A small step to add full nice Attribute support
Signed-off-by: Juraj Oravec <jurajoravec@mailo.com>
This commit is contained in:
parent
bbad4d86a8
commit
4c9213bc30
|
@ -125,8 +125,8 @@ SiteInfo::SiteInfo(WebView *view)
|
||||||
});
|
});
|
||||||
|
|
||||||
// Permissions
|
// Permissions
|
||||||
addPermissionOption(SiteSettingsManager::poAllowJavascript);
|
addPermissionOption(SiteSettingsManager::poJavascriptEnabled);
|
||||||
addPermissionOption(SiteSettingsManager::poAllowImages);
|
addPermissionOption(SiteSettingsManager::poAutoloadImages);
|
||||||
addPermissionOption(SiteSettingsManager::poAllowNotifications);
|
addPermissionOption(SiteSettingsManager::poAllowNotifications);
|
||||||
addPermissionOption(SiteSettingsManager::poAllowGeolocation);
|
addPermissionOption(SiteSettingsManager::poAllowGeolocation);
|
||||||
addPermissionOption(SiteSettingsManager::poAllowMediaAudioCapture);
|
addPermissionOption(SiteSettingsManager::poAllowMediaAudioCapture);
|
||||||
|
@ -346,8 +346,8 @@ void SiteInfo::addPermissionOption(const SiteSettingsManager::PageOptions option
|
||||||
auto* optionItem = new SiteInfoPermissionItem(option, perm, this);
|
auto* optionItem = new SiteInfoPermissionItem(option, perm, this);
|
||||||
|
|
||||||
switch (option) {
|
switch (option) {
|
||||||
case SiteSettingsManager::poAllowJavascript:
|
case SiteSettingsManager::poJavascriptEnabled:
|
||||||
case SiteSettingsManager::poAllowImages:
|
case SiteSettingsManager::poAutoloadImages:
|
||||||
case SiteSettingsManager::poAllowCookies:
|
case SiteSettingsManager::poAllowCookies:
|
||||||
optionItem->setHasOptionAsk(false);
|
optionItem->setHasOptionAsk(false);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -39,12 +39,29 @@ void SiteSettingsManager::loadSettings()
|
||||||
// m_isSaving = settings.value("allowPerDomainZoom", true).toBool();
|
// m_isSaving = settings.value("allowPerDomainZoom", true).toBool();
|
||||||
// settings.endGroup();
|
// settings.endGroup();
|
||||||
|
|
||||||
|
// TODO Maybe change to Default HTML5 Permissions
|
||||||
settings.beginGroup("Site-Settings");
|
settings.beginGroup("Site-Settings");
|
||||||
/* These are handled by already existing parts of Falkon */
|
/* These are handled by already existing parts of Falkon */
|
||||||
// m_defaults[poAllowJavascript] = settings.value("allowJavascript", Default).toInt();
|
|
||||||
// m_defaults[poAllowImages] = settings.value("allowImages", Default).toInt();
|
|
||||||
// m_defaults[poAllowCookies] = settings.value("allowCookies", Default).toInt();
|
// m_defaults[poAllowCookies] = settings.value("allowCookies", Default).toInt();
|
||||||
// m_defaults[poZoomLevel] = settings.value("defaultZoomLevel", Default).toInt(); // fail
|
// m_defaults[poZoomLevel] = settings.value("defaultZoomLevel", Default).toInt(); // fail
|
||||||
|
//
|
||||||
|
// m_defaults[poAutoloadImages] = intToPermission(settings.value("AllowImages", Ask).toInt());
|
||||||
|
//
|
||||||
|
// m_defaults[poJavascriptEnabled] = intToPermission(settings.value("JavascriptEnabled", Ask).toInt());
|
||||||
|
// m_defaults[poJavascriptCanOpenWindows] = intToPermission(settings.value("JavascriptCanOpenWindows", Ask).toInt());
|
||||||
|
// m_defaults[poJavascriptCanAccessClipboard] = intToPermission(settings.value("JavascriptCanAccessClipboard", Ask).toInt());
|
||||||
|
// m_defaults[poJavascriptCanPaste] = intToPermission(settings.value("JavascriptCanPaste", Ask).toInt());
|
||||||
|
// m_defaults[poAllowWindowActivationFromJavaScript] = intToPermission(settings.value("AllowWindowActivationFromJavaScript", Ask).toInt());
|
||||||
|
//
|
||||||
|
// m_defaults[poLocalStorageEnabled] = intToPermission(settings.value("LocalStorageEnabled", Ask).toInt());
|
||||||
|
// m_defaults[poScrollAnimatorEnabled] = intToPermission(settings.value("ScrollAnimatorEnabled", Ask).toInt());
|
||||||
|
// m_defaults[poFullScreenSupportEnabled] = intToPermission(settings.value("FullScreenSupportEnabled", Ask).toInt());
|
||||||
|
// m_defaults[poAllowRunningInsecureContent] = intToPermission(settings.value("AllowRunningInsecureContent", Ask).toInt());
|
||||||
|
// m_defaults[poAllowGeolocationOnInsecureOrigins] = intToPermission(settings.value("AllowGeolocationOnInsecureOrigins", Ask).toInt());
|
||||||
|
// m_defaults[poPlaybackRequiresUserGesture] = intToPermission(settings.value("PlaybackRequiresUserGesture", Ask).toInt());
|
||||||
|
// m_defaults[poWebRTCPublicInterfacesOnly] = intToPermission(settings.value("WebRTCPublicInterfacesOnly", Ask).toInt());
|
||||||
|
|
||||||
|
|
||||||
m_defaults[poAllowNotifications] = intToPermission(settings.value("allowNotifications", Ask).toInt());
|
m_defaults[poAllowNotifications] = intToPermission(settings.value("allowNotifications", Ask).toInt());
|
||||||
m_defaults[poAllowGeolocation] = intToPermission(settings.value("allowGealocation", Ask).toInt());
|
m_defaults[poAllowGeolocation] = intToPermission(settings.value("allowGealocation", Ask).toInt());
|
||||||
m_defaults[poAllowMediaAudioCapture] = intToPermission(settings.value("allowMicrophone", Ask).toInt());
|
m_defaults[poAllowMediaAudioCapture] = intToPermission(settings.value("allowMicrophone", Ask).toInt());
|
||||||
|
@ -61,8 +78,8 @@ void SiteSettingsManager::saveSettings()
|
||||||
Settings settings;
|
Settings settings;
|
||||||
settings.beginGroup("Site-Settings");
|
settings.beginGroup("Site-Settings");
|
||||||
/* These are handled by already existing parts of Falkon */
|
/* These are handled by already existing parts of Falkon */
|
||||||
// settings.setValue("allowJavascript", m_defaults[poAllowJavascript]);
|
// settings.setValue("allowJavascript", m_defaults[poJavascriptEnabled]);
|
||||||
// settings.setValue("allowIbutmages", m_defaults[poAllowImages]);
|
// settings.setValue("allowIbutmages", m_defaults[poAutoloadImages]);
|
||||||
// settings.setValue("allowCookies", m_defaults[poAllowCookies]);
|
// settings.setValue("allowCookies", m_defaults[poAllowCookies]);
|
||||||
// settings.setValue("defaultZoomLevel", m_defaults[poZoomLevel]);
|
// settings.setValue("defaultZoomLevel", m_defaults[poZoomLevel]);
|
||||||
settings.setValue("allowNotifications", m_defaults[poAllowNotifications]);
|
settings.setValue("allowNotifications", m_defaults[poAllowNotifications]);
|
||||||
|
@ -113,59 +130,40 @@ SiteWebEngineSettings SiteSettingsManager::getWebEngineSettings(const QUrl& url)
|
||||||
|
|
||||||
QHash<QWebEngineSettings::WebAttribute, bool> SiteSettingsManager::getWebAttributes(const QUrl& url)
|
QHash<QWebEngineSettings::WebAttribute, bool> SiteSettingsManager::getWebAttributes(const QUrl& url)
|
||||||
{
|
{
|
||||||
QHash<QWebEngineSettings::WebAttribute, bool> attribute;
|
QHash<QWebEngineSettings::WebAttribute, bool> attributes;
|
||||||
|
|
||||||
QSqlQuery query(SqlDatabase::instance()->database());
|
QSqlQuery query(SqlDatabase::instance()->database());
|
||||||
query.prepare(QSL("SELECT allow_images, allow_javascript FROM site_settings WHERE server=?"));
|
query.prepare(QSL("SELECT allow_images, allow_javascript FROM site_settings WHERE server=?"));
|
||||||
query.addBindValue(url.host());
|
query.addBindValue(url.host());
|
||||||
query.exec();
|
query.exec();
|
||||||
|
|
||||||
// Fill the default values
|
|
||||||
// Might not be required
|
|
||||||
// TODO I hope the defaults are set with default webengine profile settings, needs testing
|
|
||||||
attribute[QWebEngineSettings::AutoLoadImages] = getDefaultPermission(poAllowImages) == Allow;
|
|
||||||
attribute[QWebEngineSettings::JavascriptEnabled] = getDefaultPermission(poAllowJavascript) == Allow;
|
|
||||||
|
|
||||||
if (query.next()) {
|
if (query.next()) {
|
||||||
Permission perm;
|
auto permToBool = [&attributes](Permission perm, QWebEngineSettings::WebAttribute attribute) {
|
||||||
|
|
||||||
auto paerToBool = [&perm, &attribute]() {
|
|
||||||
if (perm == Allow) {
|
if (perm == Allow) {
|
||||||
attribute[QWebEngineSettings::AutoLoadImages] = true;
|
attributes[attribute] = true;
|
||||||
}
|
}
|
||||||
else if (perm == Deny) {
|
else if (perm == Deny) {
|
||||||
attribute[QWebEngineSettings::AutoLoadImages] = false;
|
attributes[attribute] = false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
perm = intToPermission(query.value(QSL("allow_images")).toInt());
|
for (int i = 0; i < query.record().count(); ++i) {
|
||||||
if (perm == Allow) {
|
SiteSettingsManager::PageOptions option = static_cast<SiteSettingsManager::PageOptions>(i);
|
||||||
attribute[QWebEngineSettings::AutoLoadImages] = true;
|
permToBool(intToPermission(query.value(i).toInt()), optionToAttribute(option));
|
||||||
}
|
|
||||||
else if (perm == Deny) {
|
|
||||||
attribute[QWebEngineSettings::AutoLoadImages] = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
perm = intToPermission(query.value(QSL("allow_javascript")).toInt());
|
|
||||||
if (perm == Allow) {
|
|
||||||
attribute[QWebEngineSettings::JavascriptEnabled] = true;
|
|
||||||
}
|
|
||||||
else if (perm == Deny) {
|
|
||||||
attribute[QWebEngineSettings::JavascriptEnabled] = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return attribute;
|
return attributes;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SiteSettingsManager::setJavascript(const QUrl& url, const int value)
|
void SiteSettingsManager::setJavascript(const QUrl& url, const int value)
|
||||||
{
|
{
|
||||||
setOption(poAllowJavascript, url, value);
|
setOption(poJavascriptEnabled, url, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SiteSettingsManager::setImages(const QUrl& url, const int value)
|
void SiteSettingsManager::setImages(const QUrl& url, const int value)
|
||||||
{
|
{
|
||||||
setOption(poAllowImages, url, value);
|
setOption(poAutoloadImages, url, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SiteSettingsManager::setOption(const PageOptions option, const QUrl& url, const int value)
|
void SiteSettingsManager::setOption(const PageOptions option, const QUrl& url, const int value)
|
||||||
|
@ -227,9 +225,9 @@ SiteSettingsManager::Permission SiteSettingsManager::getPermission(const QWebEng
|
||||||
QString SiteSettingsManager::optionToSqlColumn(const SiteSettingsManager::PageOptions &option)
|
QString SiteSettingsManager::optionToSqlColumn(const SiteSettingsManager::PageOptions &option)
|
||||||
{
|
{
|
||||||
switch (option) {
|
switch (option) {
|
||||||
case poAllowJavascript:
|
case poJavascriptEnabled:
|
||||||
return QSL("allow_javascript");
|
return QSL("allow_javascript");
|
||||||
case poAllowImages:
|
case poAutoloadImages:
|
||||||
return QSL("allow_images");
|
return QSL("allow_images");
|
||||||
case poAllowCookies:
|
case poAllowCookies:
|
||||||
return QSL("allow_cookies");
|
return QSL("allow_cookies");
|
||||||
|
@ -260,9 +258,9 @@ QString SiteSettingsManager::optionToSqlColumn(const SiteSettingsManager::PageOp
|
||||||
SiteSettingsManager::Permission SiteSettingsManager::getDefaultPermission(const SiteSettingsManager::PageOptions& option)
|
SiteSettingsManager::Permission SiteSettingsManager::getDefaultPermission(const SiteSettingsManager::PageOptions& option)
|
||||||
{
|
{
|
||||||
switch (option) {
|
switch (option) {
|
||||||
case poAllowJavascript:
|
case poJavascriptEnabled:
|
||||||
return testAttribute(QWebEngineSettings::JavascriptEnabled);
|
return testAttribute(QWebEngineSettings::JavascriptEnabled);
|
||||||
case poAllowImages:
|
case poAutoloadImages:
|
||||||
return testAttribute(QWebEngineSettings::AutoLoadImages);
|
return testAttribute(QWebEngineSettings::AutoLoadImages);
|
||||||
case poAllowNotifications:
|
case poAllowNotifications:
|
||||||
return m_defaults[poAllowNotifications];
|
return m_defaults[poAllowNotifications];
|
||||||
|
@ -312,8 +310,8 @@ void SiteSettingsManager::setDefaultPermission(const SiteSettingsManager::PageOp
|
||||||
|
|
||||||
case poZoomLevel:
|
case poZoomLevel:
|
||||||
case poAllowCookies:
|
case poAllowCookies:
|
||||||
case poAllowJavascript:
|
case poJavascriptEnabled:
|
||||||
case poAllowImages:
|
case poAutoloadImages:
|
||||||
default:
|
default:
|
||||||
qWarning() << "Unknown option" << option;
|
qWarning() << "Unknown option" << option;
|
||||||
break;
|
break;
|
||||||
|
@ -325,8 +323,8 @@ void SiteSettingsManager::setDefaultPermission(const SiteSettingsManager::PageOp
|
||||||
switch (option) {
|
switch (option) {
|
||||||
case poZoomLevel:
|
case poZoomLevel:
|
||||||
case poAllowCookies:
|
case poAllowCookies:
|
||||||
case poAllowJavascript:
|
case poJavascriptEnabled:
|
||||||
case poAllowImages:
|
case poAutoloadImages:
|
||||||
qWarning() << "So far not implemented" << option;
|
qWarning() << "So far not implemented" << option;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -409,9 +407,9 @@ SiteSettingsManager::Permission SiteSettingsManager::intToPermission(const int p
|
||||||
QString SiteSettingsManager::getOptionName(const SiteSettingsManager::PageOptions& option)
|
QString SiteSettingsManager::getOptionName(const SiteSettingsManager::PageOptions& option)
|
||||||
{
|
{
|
||||||
switch (option) {
|
switch (option) {
|
||||||
case poAllowJavascript:
|
case poJavascriptEnabled:
|
||||||
return QSL("JavaScript");
|
return QSL("JavaScript");
|
||||||
case poAllowImages:
|
case poAutoloadImages:
|
||||||
return QSL("Autoload Images");
|
return QSL("Autoload Images");
|
||||||
case poZoomLevel:
|
case poZoomLevel:
|
||||||
return QSL("Zoom level");
|
return QSL("Zoom level");
|
||||||
|
@ -460,3 +458,39 @@ QString SiteSettingsManager::getPermissionName(const SiteSettingsManager::Permis
|
||||||
return QSL("Unknown");
|
return QSL("Unknown");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QWebEngineSettings::WebAttribute SiteSettingsManager::optionToAttribute(const SiteSettingsManager::PageOptions& option) const
|
||||||
|
{
|
||||||
|
switch (option) {
|
||||||
|
case poAutoloadImages:
|
||||||
|
return QWebEngineSettings::AutoLoadImages;
|
||||||
|
|
||||||
|
case poJavascriptEnabled:
|
||||||
|
return QWebEngineSettings::JavascriptEnabled;
|
||||||
|
case poJavascriptCanOpenWindows:
|
||||||
|
return QWebEngineSettings::JavascriptCanOpenWindows;
|
||||||
|
case poJavascriptCanAccessClipboard:
|
||||||
|
return QWebEngineSettings::JavascriptCanAccessClipboard;
|
||||||
|
case poJavascriptCanPaste:
|
||||||
|
return QWebEngineSettings::JavascriptCanPaste;
|
||||||
|
case poAllowWindowActivationFromJavaScript:
|
||||||
|
return QWebEngineSettings::AllowWindowActivationFromJavaScript;
|
||||||
|
|
||||||
|
case poLocalStorageEnabled:
|
||||||
|
return QWebEngineSettings::LocalStorageEnabled;
|
||||||
|
case poScrollAnimatorEnabled:
|
||||||
|
return QWebEngineSettings::ScrollAnimatorEnabled;
|
||||||
|
case poFullScreenSupportEnabled:
|
||||||
|
return QWebEngineSettings::FullScreenSupportEnabled;
|
||||||
|
case poAllowRunningInsecureContent:
|
||||||
|
return QWebEngineSettings::AllowRunningInsecureContent;
|
||||||
|
case poAllowGeolocationOnInsecureOrigins:
|
||||||
|
return QWebEngineSettings::AllowGeolocationOnInsecureOrigins;
|
||||||
|
case poPlaybackRequiresUserGesture:
|
||||||
|
return QWebEngineSettings::PlaybackRequiresUserGesture;
|
||||||
|
case poWebRTCPublicInterfacesOnly:
|
||||||
|
return QWebEngineSettings::WebRTCPublicInterfacesOnly;
|
||||||
|
default:
|
||||||
|
return QWebEngineSettings::JavascriptEnabled;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -45,11 +45,12 @@ public:
|
||||||
};
|
};
|
||||||
Q_ENUM(Permission);
|
Q_ENUM(Permission);
|
||||||
|
|
||||||
|
/* Keep the attributes at the top */
|
||||||
enum PageOptions {
|
enum PageOptions {
|
||||||
poAllowImages,
|
poAutoloadImages,
|
||||||
|
|
||||||
/* Javascript stuff */
|
/* Javascript stuff */
|
||||||
poAllowJavascript,
|
poJavascriptEnabled,
|
||||||
poJavascriptCanOpenWindows,
|
poJavascriptCanOpenWindows,
|
||||||
poJavascriptCanAccessClipboard,
|
poJavascriptCanAccessClipboard,
|
||||||
poJavascriptCanPaste,
|
poJavascriptCanPaste,
|
||||||
|
@ -65,6 +66,7 @@ public:
|
||||||
|
|
||||||
poAllowCookies,
|
poAllowCookies,
|
||||||
poZoomLevel,
|
poZoomLevel,
|
||||||
|
|
||||||
poAllowNotifications,
|
poAllowNotifications,
|
||||||
poAllowGeolocation,
|
poAllowGeolocation,
|
||||||
poAllowMediaAudioCapture,
|
poAllowMediaAudioCapture,
|
||||||
|
@ -78,18 +80,10 @@ public:
|
||||||
|
|
||||||
struct SiteSettings
|
struct SiteSettings
|
||||||
{
|
{
|
||||||
Permission AllowJavascript;
|
|
||||||
Permission AllowImages;
|
|
||||||
Permission AllowCookies;
|
Permission AllowCookies;
|
||||||
int ZoomLevel;
|
int ZoomLevel;
|
||||||
Permission AllowNotifications;
|
QHash<QWebEngineSettings::WebAttribute, Permission> attributes; /* Enable disable soem feature eg. Javascript, Images etc */
|
||||||
Permission AllowGeolocation;
|
QHash<QWebEnginePage::Feature, Permission> features; /* HTML permissions */
|
||||||
Permission AllowMediaAudioCapture;
|
|
||||||
Permission AllowMediaVideoCapture;
|
|
||||||
Permission AllowMediaAudioVideoCapture;
|
|
||||||
Permission AllowMouseLock;
|
|
||||||
Permission AllowDesktopVideoCapture;
|
|
||||||
Permission AllowDesktopAudioVideoCapture;
|
|
||||||
QString server;
|
QString server;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -136,6 +130,7 @@ private:
|
||||||
PageOptions optionFromWebEngineFeature(const QWebEnginePage::Feature &feature) const;
|
PageOptions optionFromWebEngineFeature(const QWebEnginePage::Feature &feature) const;
|
||||||
Permission testAttribute(const QWebEngineSettings::WebAttribute attribute) const;
|
Permission testAttribute(const QWebEngineSettings::WebAttribute attribute) const;
|
||||||
Permission intToPermission(const int permission) const;
|
Permission intToPermission(const int permission) const;
|
||||||
|
QWebEngineSettings::WebAttribute optionToAttribute(const PageOptions &option) const;
|
||||||
|
|
||||||
QMap<PageOptions, Permission> m_defaults;
|
QMap<PageOptions, Permission> m_defaults;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user