2014-06-19 09:04:37 +02:00
|
|
|
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
|
|
|
|
|
2016-01-04 07:12:39 +01:00
|
|
|
# Copyright 2014-2016 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
|
2014-04-16 15:49:56 +02:00
|
|
|
#
|
|
|
|
# This file is part of qutebrowser.
|
|
|
|
#
|
|
|
|
# qutebrowser is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# qutebrowser is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2014-04-17 17:44:27 +02:00
|
|
|
"""Bridge from QWebSettings to our own settings.
|
|
|
|
|
|
|
|
Module attributes:
|
2014-05-03 16:13:32 +02:00
|
|
|
ATTRIBUTES: A mapping from internal setting names to QWebSetting enum
|
|
|
|
constants.
|
2014-04-17 17:44:27 +02:00
|
|
|
"""
|
2014-04-16 15:49:56 +02:00
|
|
|
|
2014-09-01 21:56:30 +02:00
|
|
|
import os.path
|
|
|
|
|
2014-04-16 15:49:56 +02:00
|
|
|
from PyQt5.QtWebKit import QWebSettings
|
|
|
|
|
2014-08-26 19:10:14 +02:00
|
|
|
from qutebrowser.config import config
|
2015-03-13 07:58:04 +01:00
|
|
|
from qutebrowser.utils import standarddir, objreg, log, utils, debug
|
|
|
|
|
|
|
|
UNSET = object()
|
|
|
|
|
|
|
|
|
|
|
|
class Base:
|
|
|
|
|
|
|
|
"""Base class for QWebSetting wrappers.
|
|
|
|
|
|
|
|
Attributes:
|
|
|
|
_default: The default value of this setting.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
self._default = UNSET
|
|
|
|
|
|
|
|
def _get_qws(self, qws):
|
|
|
|
"""Get the QWebSettings object to use.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
qws: The QWebSettings instance to use, or None to use the global
|
|
|
|
instance.
|
|
|
|
"""
|
|
|
|
if qws is None:
|
|
|
|
return QWebSettings.globalSettings()
|
|
|
|
else:
|
|
|
|
return qws
|
|
|
|
|
|
|
|
def save_default(self, qws=None):
|
|
|
|
"""Save the default value based on the currently set one.
|
|
|
|
|
|
|
|
This does nothing if no getter is configured for this setting.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
qws: The QWebSettings instance to use, or None to use the global
|
|
|
|
instance.
|
2015-03-16 15:41:51 +01:00
|
|
|
|
|
|
|
Return:
|
|
|
|
The saved default value.
|
2015-03-13 07:58:04 +01:00
|
|
|
"""
|
|
|
|
try:
|
|
|
|
self._default = self.get(qws)
|
2015-03-16 15:41:51 +01:00
|
|
|
return self._default
|
2015-03-13 07:58:04 +01:00
|
|
|
except AttributeError:
|
2015-03-16 15:41:51 +01:00
|
|
|
return None
|
2015-03-13 07:58:04 +01:00
|
|
|
|
|
|
|
def restore_default(self, qws=None):
|
|
|
|
"""Restore the default value from the saved one.
|
|
|
|
|
|
|
|
This does nothing if the default has never been set.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
qws: The QWebSettings instance to use, or None to use the global
|
|
|
|
instance.
|
|
|
|
"""
|
|
|
|
if self._default is not UNSET:
|
2015-05-10 14:50:56 +02:00
|
|
|
log.config.vdebug("Restoring default {!r}.".format(self._default))
|
2015-03-13 07:58:04 +01:00
|
|
|
self._set(self._default, qws=qws)
|
|
|
|
|
|
|
|
def get(self, qws=None):
|
|
|
|
"""Get the value of this setting.
|
|
|
|
|
|
|
|
Must be overridden by subclasses.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
qws: The QWebSettings instance to use, or None to use the global
|
|
|
|
instance.
|
|
|
|
"""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
def set(self, value, qws=None):
|
|
|
|
"""Set the value of this setting.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
value: The value to set.
|
|
|
|
qws: The QWebSettings instance to use, or None to use the global
|
|
|
|
instance.
|
|
|
|
"""
|
|
|
|
if value is None:
|
|
|
|
self.restore_default(qws)
|
|
|
|
else:
|
|
|
|
self._set(value, qws=qws)
|
|
|
|
|
|
|
|
def _set(self, value, qws):
|
|
|
|
"""Inner function to set the value of this setting.
|
|
|
|
|
|
|
|
Must be overridden by subclasses.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
value: The value to set.
|
|
|
|
qws: The QWebSettings instance to use, or None to use the global
|
|
|
|
instance.
|
|
|
|
"""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
|
|
|
|
class Attribute(Base):
|
|
|
|
|
|
|
|
"""A setting set via QWebSettings::setAttribute.
|
|
|
|
|
|
|
|
Attributes:
|
|
|
|
self._attribute: A QWebSettings::WebAttribute instance.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, attribute):
|
|
|
|
super().__init__()
|
|
|
|
self._attribute = attribute
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return utils.get_repr(
|
|
|
|
self, attribute=debug.qenum_key(QWebSettings, self._attribute),
|
|
|
|
constructor=True)
|
|
|
|
|
|
|
|
def get(self, qws=None):
|
|
|
|
return self._get_qws(qws).attribute(self._attribute)
|
|
|
|
|
|
|
|
def _set(self, value, qws=None):
|
|
|
|
self._get_qws(qws).setAttribute(self._attribute, value)
|
2014-04-16 15:49:56 +02:00
|
|
|
|
2015-03-13 07:58:04 +01:00
|
|
|
|
|
|
|
class Setter(Base):
|
|
|
|
|
|
|
|
"""A setting set via QWebSettings getter/setter methods.
|
|
|
|
|
|
|
|
This will pass the QWebSettings instance ("self") as first argument to the
|
|
|
|
methods, so self._getter/self._setter are the *unbound* methods.
|
|
|
|
|
|
|
|
Attributes:
|
|
|
|
_getter: The unbound QWebSettings method to get this value, or None.
|
|
|
|
_setter: The unbound QWebSettings method to set this value.
|
|
|
|
_args: An iterable of the arguments to pass to the setter/getter
|
|
|
|
(before the value, for the setter).
|
|
|
|
_unpack: Whether to unpack args (True) or pass them directly (False).
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, getter, setter, args=(), unpack=False):
|
|
|
|
super().__init__()
|
|
|
|
self._getter = getter
|
|
|
|
self._setter = setter
|
|
|
|
self._args = args
|
|
|
|
self._unpack = unpack
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return utils.get_repr(self, getter=self._getter, setter=self._setter,
|
|
|
|
args=self._args, unpack=self._unpack,
|
|
|
|
constructor=True)
|
|
|
|
|
|
|
|
def get(self, qws=None):
|
|
|
|
if self._getter is None:
|
|
|
|
raise AttributeError("No getter set!")
|
|
|
|
return self._getter(self._get_qws(qws), *self._args)
|
|
|
|
|
|
|
|
def _set(self, value, qws=None):
|
|
|
|
args = [self._get_qws(qws)]
|
|
|
|
args.extend(self._args)
|
|
|
|
if self._unpack:
|
|
|
|
args.extend(value)
|
|
|
|
else:
|
|
|
|
args.append(value)
|
|
|
|
self._setter(*args)
|
|
|
|
|
|
|
|
|
|
|
|
class NullStringSetter(Setter):
|
|
|
|
|
|
|
|
"""A setter for settings requiring a null QString as default.
|
|
|
|
|
|
|
|
This overrides save_default so None is saved for an empty string. This is
|
|
|
|
needed for the CSS media type, because it returns an empty Python string
|
|
|
|
when getting the value, but setting it to the default requires passing None
|
|
|
|
(a null QString) instead of an empty string.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def save_default(self, qws=None):
|
|
|
|
try:
|
|
|
|
val = self.get(qws)
|
|
|
|
except AttributeError:
|
2015-03-16 15:41:51 +01:00
|
|
|
return None
|
2015-03-13 07:58:04 +01:00
|
|
|
if val == '':
|
|
|
|
self._set(None, qws=qws)
|
|
|
|
else:
|
|
|
|
self._set(val, qws=qws)
|
2015-03-16 15:41:51 +01:00
|
|
|
return val
|
2015-03-13 07:58:04 +01:00
|
|
|
|
|
|
|
|
|
|
|
class GlobalSetter(Setter):
|
|
|
|
|
|
|
|
"""A setting set via static QWebSettings getter/setter methods.
|
|
|
|
|
|
|
|
self._getter/self._setter are the *bound* methods.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def get(self, qws=None):
|
|
|
|
if qws is not None:
|
|
|
|
raise ValueError("qws may not be set with GlobalSetters!")
|
|
|
|
if self._getter is None:
|
|
|
|
raise AttributeError("No getter set!")
|
|
|
|
return self._getter(*self._args)
|
|
|
|
|
|
|
|
def _set(self, value, qws=None):
|
|
|
|
if qws is not None:
|
|
|
|
raise ValueError("qws may not be set with GlobalSetters!")
|
|
|
|
args = list(self._args)
|
|
|
|
if self._unpack:
|
|
|
|
args.extend(value)
|
|
|
|
else:
|
|
|
|
args.append(value)
|
|
|
|
self._setter(*args)
|
2014-04-16 15:49:56 +02:00
|
|
|
|
2014-05-04 01:50:37 +02:00
|
|
|
|
2015-06-05 15:57:43 +02:00
|
|
|
class CookiePolicy(Base):
|
Add setting: 'content.third-party-cookie-policy', fixes #607
This sets the third-party cookie policy.
- I created a new ThirdPartyCookiePolicy() class, since this setting seems to be
unique in the way it is set...
- I set the default to 'never', which is the most secure/private setting, but
*may* break *some* features of a (very) limited number of sites; these are
usually "non-critical" features.
For example, on Stack Exchange sites you're logged in all 200+ sites if you
sign in on one of them, this features required 3rd party cookies. You can
still sign in with out, but you have to do so 200+ times (this is actually the
only example I've ever noticed).
AFAIK all "major" browsers accept 3rd-party cookies by default, except for
Safari. Firefox also made this change, but reversed it (see:
https://brendaneich.com/2013/05/c-is-for-cookie/), but they don't offer any
good arguments to *not* have it IMHO, at least not that I could find.
In any case, in my humble opinion "secure and private by default" is the best
way to ship. But you're of course free to change it if you disagree ;-)
2015-06-03 23:59:24 +02:00
|
|
|
|
|
|
|
"""The ThirdPartyCookiePolicy setting is different from other settings."""
|
|
|
|
|
2015-06-05 15:57:43 +02:00
|
|
|
MAPPING = {
|
|
|
|
'all': QWebSettings.AlwaysAllowThirdPartyCookies,
|
|
|
|
'no-3rdparty': QWebSettings.AlwaysBlockThirdPartyCookies,
|
|
|
|
'never': QWebSettings.AlwaysBlockThirdPartyCookies,
|
|
|
|
'no-unknown-3rdparty': QWebSettings.AllowThirdPartyWithExistingCookies,
|
|
|
|
}
|
Add setting: 'content.third-party-cookie-policy', fixes #607
This sets the third-party cookie policy.
- I created a new ThirdPartyCookiePolicy() class, since this setting seems to be
unique in the way it is set...
- I set the default to 'never', which is the most secure/private setting, but
*may* break *some* features of a (very) limited number of sites; these are
usually "non-critical" features.
For example, on Stack Exchange sites you're logged in all 200+ sites if you
sign in on one of them, this features required 3rd party cookies. You can
still sign in with out, but you have to do so 200+ times (this is actually the
only example I've ever noticed).
AFAIK all "major" browsers accept 3rd-party cookies by default, except for
Safari. Firefox also made this change, but reversed it (see:
https://brendaneich.com/2013/05/c-is-for-cookie/), but they don't offer any
good arguments to *not* have it IMHO, at least not that I could find.
In any case, in my humble opinion "secure and private by default" is the best
way to ship. But you're of course free to change it if you disagree ;-)
2015-06-03 23:59:24 +02:00
|
|
|
|
|
|
|
def get(self, qws=None):
|
2015-06-05 15:57:43 +02:00
|
|
|
return config.get('content', 'cookies-accept')
|
Add setting: 'content.third-party-cookie-policy', fixes #607
This sets the third-party cookie policy.
- I created a new ThirdPartyCookiePolicy() class, since this setting seems to be
unique in the way it is set...
- I set the default to 'never', which is the most secure/private setting, but
*may* break *some* features of a (very) limited number of sites; these are
usually "non-critical" features.
For example, on Stack Exchange sites you're logged in all 200+ sites if you
sign in on one of them, this features required 3rd party cookies. You can
still sign in with out, but you have to do so 200+ times (this is actually the
only example I've ever noticed).
AFAIK all "major" browsers accept 3rd-party cookies by default, except for
Safari. Firefox also made this change, but reversed it (see:
https://brendaneich.com/2013/05/c-is-for-cookie/), but they don't offer any
good arguments to *not* have it IMHO, at least not that I could find.
In any case, in my humble opinion "secure and private by default" is the best
way to ship. But you're of course free to change it if you disagree ;-)
2015-06-03 23:59:24 +02:00
|
|
|
|
|
|
|
def _set(self, value, qws=None):
|
2015-06-05 15:57:43 +02:00
|
|
|
QWebSettings.globalSettings().setThirdPartyCookiePolicy(
|
|
|
|
self.MAPPING[value])
|
Add setting: 'content.third-party-cookie-policy', fixes #607
This sets the third-party cookie policy.
- I created a new ThirdPartyCookiePolicy() class, since this setting seems to be
unique in the way it is set...
- I set the default to 'never', which is the most secure/private setting, but
*may* break *some* features of a (very) limited number of sites; these are
usually "non-critical" features.
For example, on Stack Exchange sites you're logged in all 200+ sites if you
sign in on one of them, this features required 3rd party cookies. You can
still sign in with out, but you have to do so 200+ times (this is actually the
only example I've ever noticed).
AFAIK all "major" browsers accept 3rd-party cookies by default, except for
Safari. Firefox also made this change, but reversed it (see:
https://brendaneich.com/2013/05/c-is-for-cookie/), but they don't offer any
good arguments to *not* have it IMHO, at least not that I could find.
In any case, in my humble opinion "secure and private by default" is the best
way to ship. But you're of course free to change it if you disagree ;-)
2015-06-03 23:59:24 +02:00
|
|
|
|
|
|
|
|
2014-05-04 01:50:37 +02:00
|
|
|
MAPPINGS = {
|
2014-11-26 21:16:27 +01:00
|
|
|
'content': {
|
2014-06-03 20:28:51 +02:00
|
|
|
'allow-images':
|
2015-03-13 07:58:04 +01:00
|
|
|
Attribute(QWebSettings.AutoLoadImages),
|
2014-06-03 20:28:51 +02:00
|
|
|
'allow-javascript':
|
2015-03-13 07:58:04 +01:00
|
|
|
Attribute(QWebSettings.JavascriptEnabled),
|
2014-06-03 20:28:51 +02:00
|
|
|
'javascript-can-open-windows':
|
2015-03-13 07:58:04 +01:00
|
|
|
Attribute(QWebSettings.JavascriptCanOpenWindows),
|
2014-06-03 20:28:51 +02:00
|
|
|
'javascript-can-close-windows':
|
2015-03-13 07:58:04 +01:00
|
|
|
Attribute(QWebSettings.JavascriptCanCloseWindows),
|
2014-06-03 20:28:51 +02:00
|
|
|
'javascript-can-access-clipboard':
|
2015-03-13 07:58:04 +01:00
|
|
|
Attribute(QWebSettings.JavascriptCanAccessClipboard),
|
2014-06-03 20:28:51 +02:00
|
|
|
#'allow-java':
|
2015-03-13 07:58:04 +01:00
|
|
|
# Attribute(QWebSettings.JavaEnabled),
|
2014-06-03 20:28:51 +02:00
|
|
|
'allow-plugins':
|
2015-03-13 07:58:04 +01:00
|
|
|
Attribute(QWebSettings.PluginsEnabled),
|
2015-05-16 00:31:13 +02:00
|
|
|
'webgl':
|
|
|
|
Attribute(QWebSettings.WebGLEnabled),
|
2015-05-16 00:39:20 +02:00
|
|
|
'css-regions':
|
|
|
|
Attribute(QWebSettings.CSSRegionsEnabled),
|
2015-05-16 00:42:26 +02:00
|
|
|
'hyperlink-auditing':
|
|
|
|
Attribute(QWebSettings.HyperlinkAuditingEnabled),
|
2014-06-03 20:28:51 +02:00
|
|
|
'local-content-can-access-remote-urls':
|
2015-03-13 07:58:04 +01:00
|
|
|
Attribute(QWebSettings.LocalContentCanAccessRemoteUrls),
|
2014-06-03 20:28:51 +02:00
|
|
|
'local-content-can-access-file-urls':
|
2015-03-13 07:58:04 +01:00
|
|
|
Attribute(QWebSettings.LocalContentCanAccessFileUrls),
|
2015-06-05 15:57:43 +02:00
|
|
|
'cookies-accept':
|
|
|
|
CookiePolicy(),
|
2014-06-03 20:28:51 +02:00
|
|
|
},
|
|
|
|
'network': {
|
|
|
|
'dns-prefetch':
|
2015-03-13 07:58:04 +01:00
|
|
|
Attribute(QWebSettings.DnsPrefetchEnabled),
|
2014-06-03 20:28:51 +02:00
|
|
|
},
|
|
|
|
'input': {
|
|
|
|
'spatial-navigation':
|
2015-03-13 07:58:04 +01:00
|
|
|
Attribute(QWebSettings.SpatialNavigationEnabled),
|
2014-06-03 20:28:51 +02:00
|
|
|
'links-included-in-focus-chain':
|
2015-03-13 07:58:04 +01:00
|
|
|
Attribute(QWebSettings.LinksIncludedInFocusChain),
|
2014-06-03 20:28:51 +02:00
|
|
|
},
|
|
|
|
'fonts': {
|
|
|
|
'web-family-standard':
|
2015-03-13 07:58:04 +01:00
|
|
|
Setter(getter=QWebSettings.fontFamily,
|
|
|
|
setter=QWebSettings.setFontFamily,
|
|
|
|
args=[QWebSettings.StandardFont]),
|
2014-06-03 20:28:51 +02:00
|
|
|
'web-family-fixed':
|
2015-03-13 07:58:04 +01:00
|
|
|
Setter(getter=QWebSettings.fontFamily,
|
|
|
|
setter=QWebSettings.setFontFamily,
|
|
|
|
args=[QWebSettings.FixedFont]),
|
2014-06-03 20:28:51 +02:00
|
|
|
'web-family-serif':
|
2015-03-13 07:58:04 +01:00
|
|
|
Setter(getter=QWebSettings.fontFamily,
|
|
|
|
setter=QWebSettings.setFontFamily,
|
|
|
|
args=[QWebSettings.SerifFont]),
|
2014-06-03 20:28:51 +02:00
|
|
|
'web-family-sans-serif':
|
2015-03-13 07:58:04 +01:00
|
|
|
Setter(getter=QWebSettings.fontFamily,
|
|
|
|
setter=QWebSettings.setFontFamily,
|
|
|
|
args=[QWebSettings.SansSerifFont]),
|
2014-06-03 20:28:51 +02:00
|
|
|
'web-family-cursive':
|
2015-03-13 07:58:04 +01:00
|
|
|
Setter(getter=QWebSettings.fontFamily,
|
|
|
|
setter=QWebSettings.setFontFamily,
|
|
|
|
args=[QWebSettings.CursiveFont]),
|
2014-06-03 20:28:51 +02:00
|
|
|
'web-family-fantasy':
|
2015-03-13 07:58:04 +01:00
|
|
|
Setter(getter=QWebSettings.fontFamily,
|
|
|
|
setter=QWebSettings.setFontFamily,
|
|
|
|
args=[QWebSettings.FantasyFont]),
|
2014-06-03 20:28:51 +02:00
|
|
|
'web-size-minimum':
|
2015-03-13 07:58:04 +01:00
|
|
|
Setter(getter=QWebSettings.fontSize,
|
|
|
|
setter=QWebSettings.setFontSize,
|
|
|
|
args=[QWebSettings.MinimumFontSize]),
|
2014-06-03 20:28:51 +02:00
|
|
|
'web-size-minimum-logical':
|
2015-03-13 07:58:04 +01:00
|
|
|
Setter(getter=QWebSettings.fontSize,
|
|
|
|
setter=QWebSettings.setFontSize,
|
|
|
|
args=[QWebSettings.MinimumLogicalFontSize]),
|
2014-06-03 20:28:51 +02:00
|
|
|
'web-size-default':
|
2015-03-13 07:58:04 +01:00
|
|
|
Setter(getter=QWebSettings.fontSize,
|
|
|
|
setter=QWebSettings.setFontSize,
|
|
|
|
args=[QWebSettings.DefaultFontSize]),
|
2014-06-03 20:28:51 +02:00
|
|
|
'web-size-default-fixed':
|
2015-03-13 07:58:04 +01:00
|
|
|
Setter(getter=QWebSettings.fontSize,
|
|
|
|
setter=QWebSettings.setFontSize,
|
|
|
|
args=[QWebSettings.DefaultFixedFontSize]),
|
2014-06-03 20:28:51 +02:00
|
|
|
},
|
|
|
|
'ui': {
|
|
|
|
'zoom-text-only':
|
2015-03-13 07:58:04 +01:00
|
|
|
Attribute(QWebSettings.ZoomTextOnly),
|
2014-06-03 20:28:51 +02:00
|
|
|
'frame-flattening':
|
2015-03-13 07:58:04 +01:00
|
|
|
Attribute(QWebSettings.FrameFlatteningEnabled),
|
2014-06-03 20:28:51 +02:00
|
|
|
'user-stylesheet':
|
2015-04-02 14:56:42 +02:00
|
|
|
Setter(getter=QWebSettings.userStyleSheetUrl,
|
|
|
|
setter=QWebSettings.setUserStyleSheetUrl),
|
2014-06-03 20:28:51 +02:00
|
|
|
'css-media-type':
|
2015-03-13 07:58:04 +01:00
|
|
|
NullStringSetter(getter=QWebSettings.cssMediaType,
|
|
|
|
setter=QWebSettings.setCSSMediaType),
|
2015-05-15 23:53:08 +02:00
|
|
|
'smooth-scrolling':
|
|
|
|
Attribute(QWebSettings.ScrollAnimatorEnabled),
|
2014-06-03 20:28:51 +02:00
|
|
|
#'accelerated-compositing':
|
2015-03-13 07:58:04 +01:00
|
|
|
# Attribute(QWebSettings.AcceleratedCompositingEnabled),
|
2014-06-03 20:28:51 +02:00
|
|
|
#'tiled-backing-store':
|
2015-03-13 07:58:04 +01:00
|
|
|
# Attribute(QWebSettings.TiledBackingStoreEnabled),
|
2014-06-03 20:28:51 +02:00
|
|
|
},
|
|
|
|
'storage': {
|
|
|
|
'offline-storage-database':
|
2015-03-13 07:58:04 +01:00
|
|
|
Attribute(QWebSettings.OfflineStorageDatabaseEnabled),
|
2014-06-03 20:28:51 +02:00
|
|
|
'offline-web-application-storage':
|
2015-03-13 07:58:04 +01:00
|
|
|
Attribute(QWebSettings.OfflineWebApplicationCacheEnabled),
|
2014-06-03 20:28:51 +02:00
|
|
|
'local-storage':
|
2015-03-13 07:58:04 +01:00
|
|
|
Attribute(QWebSettings.LocalStorageEnabled),
|
2014-06-03 20:28:51 +02:00
|
|
|
'maximum-pages-in-cache':
|
2015-03-13 07:58:04 +01:00
|
|
|
GlobalSetter(getter=QWebSettings.maximumPagesInCache,
|
|
|
|
setter=QWebSettings.setMaximumPagesInCache),
|
2014-06-03 20:28:51 +02:00
|
|
|
'object-cache-capacities':
|
2015-03-13 07:58:04 +01:00
|
|
|
GlobalSetter(getter=None,
|
|
|
|
setter=QWebSettings.setObjectCacheCapacities,
|
|
|
|
unpack=True),
|
2014-06-03 20:28:51 +02:00
|
|
|
'offline-storage-default-quota':
|
2015-03-13 07:58:04 +01:00
|
|
|
GlobalSetter(getter=QWebSettings.offlineStorageDefaultQuota,
|
|
|
|
setter=QWebSettings.setOfflineStorageDefaultQuota),
|
2014-06-03 20:28:51 +02:00
|
|
|
'offline-web-application-cache-quota':
|
2015-03-13 07:58:04 +01:00
|
|
|
GlobalSetter(
|
|
|
|
getter=QWebSettings.offlineWebApplicationCacheQuota,
|
|
|
|
setter=QWebSettings.setOfflineWebApplicationCacheQuota),
|
2014-06-03 20:28:51 +02:00
|
|
|
},
|
|
|
|
'general': {
|
|
|
|
'private-browsing':
|
2015-03-13 07:58:04 +01:00
|
|
|
Attribute(QWebSettings.PrivateBrowsingEnabled),
|
2014-06-03 20:28:51 +02:00
|
|
|
'developer-extras':
|
2015-03-13 07:58:04 +01:00
|
|
|
Attribute(QWebSettings.DeveloperExtrasEnabled),
|
2014-06-03 20:28:51 +02:00
|
|
|
'print-element-backgrounds':
|
2015-03-13 07:58:04 +01:00
|
|
|
Attribute(QWebSettings.PrintElementBackgrounds),
|
2014-06-03 20:28:51 +02:00
|
|
|
'xss-auditing':
|
2015-03-13 07:58:04 +01:00
|
|
|
Attribute(QWebSettings.XSSAuditingEnabled),
|
2014-06-03 20:28:51 +02:00
|
|
|
'site-specific-quirks':
|
2015-03-13 07:58:04 +01:00
|
|
|
Attribute(QWebSettings.SiteSpecificQuirksEnabled),
|
2014-06-03 20:28:51 +02:00
|
|
|
'default-encoding':
|
2015-03-13 07:58:04 +01:00
|
|
|
Setter(getter=QWebSettings.defaultTextEncoding,
|
|
|
|
setter=QWebSettings.setDefaultTextEncoding),
|
2014-06-03 20:28:51 +02:00
|
|
|
}
|
2014-05-04 01:06:52 +02:00
|
|
|
}
|
|
|
|
|
2014-05-04 01:33:01 +02:00
|
|
|
|
2014-05-08 22:33:24 +02:00
|
|
|
def init():
|
|
|
|
"""Initialize the global QWebSettings."""
|
2015-05-16 22:12:27 +02:00
|
|
|
cache_path = standarddir.cache()
|
|
|
|
data_path = standarddir.data()
|
|
|
|
if config.get('general', 'private-browsing') or cache_path is None:
|
2015-01-08 18:09:55 +01:00
|
|
|
QWebSettings.setIconDatabasePath('')
|
|
|
|
else:
|
2015-05-16 22:12:27 +02:00
|
|
|
QWebSettings.setIconDatabasePath(cache_path)
|
|
|
|
if cache_path is not None:
|
|
|
|
QWebSettings.setOfflineWebApplicationCachePath(
|
|
|
|
os.path.join(cache_path, 'application-cache'))
|
|
|
|
if data_path is not None:
|
|
|
|
QWebSettings.globalSettings().setLocalStoragePath(
|
|
|
|
os.path.join(data_path, 'local-storage'))
|
|
|
|
QWebSettings.setOfflineStoragePath(
|
|
|
|
os.path.join(data_path, 'offline-storage'))
|
2014-09-01 21:56:30 +02:00
|
|
|
|
2014-06-03 20:28:51 +02:00
|
|
|
for sectname, section in MAPPINGS.items():
|
2014-12-30 00:56:53 +01:00
|
|
|
for optname, mapping in section.items():
|
2015-03-16 15:41:51 +01:00
|
|
|
default = mapping.save_default()
|
2015-04-13 08:49:04 +02:00
|
|
|
log.config.vdebug("Saved default for {} -> {}: {!r}".format(
|
2015-03-16 15:41:51 +01:00
|
|
|
sectname, optname, default))
|
2014-06-03 20:28:51 +02:00
|
|
|
value = config.get(sectname, optname)
|
2015-04-13 08:49:04 +02:00
|
|
|
log.config.vdebug("Setting {} -> {} to {!r}".format(
|
2015-03-16 15:41:51 +01:00
|
|
|
sectname, optname, value))
|
2015-03-13 07:58:04 +01:00
|
|
|
mapping.set(value)
|
2014-10-18 19:50:10 +02:00
|
|
|
objreg.get('config').changed.connect(update_settings)
|
2014-04-16 15:49:56 +02:00
|
|
|
|
|
|
|
|
2014-09-28 11:27:52 +02:00
|
|
|
def update_settings(section, option):
|
2014-04-16 15:49:56 +02:00
|
|
|
"""Update global settings when qwebsettings changed."""
|
2015-05-16 22:12:27 +02:00
|
|
|
cache_path = standarddir.cache()
|
2015-03-18 20:20:04 +01:00
|
|
|
if (section, option) == ('general', 'private-browsing'):
|
2015-05-16 22:12:27 +02:00
|
|
|
if config.get('general', 'private-browsing') or cache_path is None:
|
2015-03-18 20:20:04 +01:00
|
|
|
QWebSettings.setIconDatabasePath('')
|
|
|
|
else:
|
2015-05-16 22:12:27 +02:00
|
|
|
QWebSettings.setIconDatabasePath(cache_path)
|
2015-03-18 20:20:04 +01:00
|
|
|
else:
|
|
|
|
try:
|
|
|
|
mapping = MAPPINGS[section][option]
|
|
|
|
except KeyError:
|
|
|
|
return
|
|
|
|
value = config.get(section, option)
|
|
|
|
mapping.set(value)
|