Add support for storage -> cache-size with QtWebEngine
This commit is contained in:
parent
bd0b62ab80
commit
4518afbde2
@ -26,6 +26,7 @@ Added
|
|||||||
- Printing support for QtWebEngine with Qt >= 5.8
|
- Printing support for QtWebEngine with Qt >= 5.8
|
||||||
- Proxy support for QtWebEngine with Qt >= 5.8
|
- Proxy support for QtWebEngine with Qt >= 5.8
|
||||||
- Support for the `content -> cookies-store` option with QtWebEngine
|
- Support for the `content -> cookies-store` option with QtWebEngine
|
||||||
|
- Support for the `storage -> cache-size` option with QtWebEngine
|
||||||
|
|
||||||
Changed
|
Changed
|
||||||
~~~~~~~
|
~~~~~~~
|
||||||
|
@ -65,16 +65,40 @@ class StaticSetter(websettings.StaticSetter):
|
|||||||
GLOBAL_SETTINGS = QWebEngineSettings.globalSettings
|
GLOBAL_SETTINGS = QWebEngineSettings.globalSettings
|
||||||
|
|
||||||
|
|
||||||
class PersistentCookiePolicy(websettings.Base):
|
class ProfileSetter(websettings.Base):
|
||||||
|
|
||||||
|
"""A setting set on the QWebEngineProfile."""
|
||||||
|
|
||||||
|
def __init__(self, getter, setter):
|
||||||
|
super().__init__()
|
||||||
|
profile = QWebEngineProfile.defaultProfile()
|
||||||
|
self._getter = getattr(profile, getter)
|
||||||
|
self._setter = getattr(profile, setter)
|
||||||
|
|
||||||
|
def get(self, settings=None):
|
||||||
|
utils.unused(settings)
|
||||||
|
return self._getter()
|
||||||
|
|
||||||
|
def _set(self, value, settings=None):
|
||||||
|
utils.unused(settings)
|
||||||
|
self._setter(value)
|
||||||
|
|
||||||
|
|
||||||
|
class PersistentCookiePolicy(ProfileSetter):
|
||||||
|
|
||||||
"""The cookies -> store setting is different from other settings."""
|
"""The cookies -> store setting is different from other settings."""
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__(getter='persistentCookiesPolicy',
|
||||||
|
setter='setPersistentCookiesPolicy')
|
||||||
|
|
||||||
def get(self, settings=None):
|
def get(self, settings=None):
|
||||||
|
utils.unused(settings)
|
||||||
return config.get('content', 'cookies-store')
|
return config.get('content', 'cookies-store')
|
||||||
|
|
||||||
def _set(self, value, settings=None):
|
def _set(self, value, settings=None):
|
||||||
utils.unused(settings)
|
utils.unused(settings)
|
||||||
QWebEngineProfile.defaultProfile().setPersistentCookiesPolicy(
|
self._setter(
|
||||||
QWebEngineProfile.AllowPersistentCookies if value else
|
QWebEngineProfile.AllowPersistentCookies if value else
|
||||||
QWebEngineProfile.NoPersistentCookies
|
QWebEngineProfile.NoPersistentCookies
|
||||||
)
|
)
|
||||||
@ -246,6 +270,9 @@ MAPPINGS = {
|
|||||||
'storage': {
|
'storage': {
|
||||||
'local-storage':
|
'local-storage':
|
||||||
Attribute(QWebEngineSettings.LocalStorageEnabled),
|
Attribute(QWebEngineSettings.LocalStorageEnabled),
|
||||||
|
'cache-size':
|
||||||
|
ProfileSetter(getter='httpCacheMaximumSize',
|
||||||
|
setter='setHttpCacheMaximumSize')
|
||||||
},
|
},
|
||||||
'general': {
|
'general': {
|
||||||
'xss-auditing':
|
'xss-auditing':
|
||||||
|
@ -48,6 +48,13 @@ class DiskCache(QNetworkDiskCache):
|
|||||||
maxsize=self.maximumCacheSize(),
|
maxsize=self.maximumCacheSize(),
|
||||||
path=self.cacheDirectory())
|
path=self.cacheDirectory())
|
||||||
|
|
||||||
|
def _set_cache_size(self):
|
||||||
|
"""Set the cache size based on the config."""
|
||||||
|
size = config.get('storage', 'cache-size')
|
||||||
|
if size is None:
|
||||||
|
size = 1024 * 1024 * 50 # default from QNetworkDiskCachePrivate
|
||||||
|
self.setMaximumCacheSize(size)
|
||||||
|
|
||||||
def _maybe_activate(self):
|
def _maybe_activate(self):
|
||||||
"""Activate/deactivate the cache based on the config."""
|
"""Activate/deactivate the cache based on the config."""
|
||||||
if config.get('general', 'private-browsing'):
|
if config.get('general', 'private-browsing'):
|
||||||
@ -55,13 +62,13 @@ class DiskCache(QNetworkDiskCache):
|
|||||||
else:
|
else:
|
||||||
self._activated = True
|
self._activated = True
|
||||||
self.setCacheDirectory(os.path.join(self._cache_dir, 'http'))
|
self.setCacheDirectory(os.path.join(self._cache_dir, 'http'))
|
||||||
self.setMaximumCacheSize(config.get('storage', 'cache-size'))
|
self._set_cache_size()
|
||||||
|
|
||||||
@pyqtSlot(str, str)
|
@pyqtSlot(str, str)
|
||||||
def on_config_changed(self, section, option):
|
def on_config_changed(self, section, option):
|
||||||
"""Update cache size/activated if the config was changed."""
|
"""Update cache size/activated if the config was changed."""
|
||||||
if (section, option) == ('storage', 'cache-size'):
|
if (section, option) == ('storage', 'cache-size'):
|
||||||
self.setMaximumCacheSize(config.get('storage', 'cache-size'))
|
self._set_cache_size()
|
||||||
elif (section, option) == ('general', # pragma: no branch
|
elif (section, option) == ('general', # pragma: no branch
|
||||||
'private-browsing'):
|
'private-browsing'):
|
||||||
self._maybe_activate()
|
self._maybe_activate()
|
||||||
|
@ -443,6 +443,7 @@ class ConfigManager(QObject):
|
|||||||
'html > ::-webkit-scrollbar { width: 0px; height: 0px; }': '',
|
'html > ::-webkit-scrollbar { width: 0px; height: 0px; }': '',
|
||||||
'::-webkit-scrollbar { width: 0px; height: 0px; }': '',
|
'::-webkit-scrollbar { width: 0px; height: 0px; }': '',
|
||||||
}),
|
}),
|
||||||
|
('contents', 'cache-size'): _get_value_transformer({'52428800': ''}),
|
||||||
}
|
}
|
||||||
|
|
||||||
changed = pyqtSignal(str, str)
|
changed = pyqtSignal(str, str)
|
||||||
|
@ -795,9 +795,9 @@ def data(readonly=False):
|
|||||||
"enabled."),
|
"enabled."),
|
||||||
|
|
||||||
('cache-size',
|
('cache-size',
|
||||||
SettingValue(typ.Int(minval=0, maxval=MAXVALS['int64']),
|
SettingValue(typ.Int(none_ok=True, minval=0,
|
||||||
'52428800'),
|
maxval=MAXVALS['int64']), ''),
|
||||||
"Size of the HTTP network cache."),
|
"Size of the HTTP network cache. Empty to use the default value."),
|
||||||
|
|
||||||
readonly=readonly
|
readonly=readonly
|
||||||
)),
|
)),
|
||||||
|
Loading…
Reference in New Issue
Block a user