Keep websettings.py untouched
- Keep changes related to UnknownUrlSchemePolicy to webengine - Use content.unknown_url_scheme_policy
This commit is contained in:
parent
9bc9c5cd51
commit
3524a8d7ca
|
|
@ -173,6 +173,7 @@
|
|||
|<<content.register_protocol_handler,content.register_protocol_handler>>|Allow websites to register protocol handlers via `navigator.registerProtocolHandler`.
|
||||
|<<content.site_specific_quirks,content.site_specific_quirks>>|Enable quirks (such as faked user agent headers) needed to get specific sites to work properly.
|
||||
|<<content.ssl_strict,content.ssl_strict>>|Validate SSL handshakes.
|
||||
|<<content.unknown_url_scheme_policy,content.unknown_url_scheme_policy>>|How navigation requests to URLs with unknown schemes are handled.
|
||||
|<<content.user_stylesheets,content.user_stylesheets>>|List of user stylesheet filenames to use.
|
||||
|<<content.webgl,content.webgl>>|Enable WebGL.
|
||||
|<<content.webrtc_ip_handling_policy,content.webrtc_ip_handling_policy>>|Which interfaces to expose via WebRTC.
|
||||
|
|
@ -296,7 +297,6 @@
|
|||
|<<tabs.undo_stack_size,tabs.undo_stack_size>>|Number of close tab actions to remember, per window (-1 for no maximum).
|
||||
|<<tabs.width,tabs.width>>|Width (in pixels or as percentage of the window) of the tab bar if it's vertical.
|
||||
|<<tabs.wrap,tabs.wrap>>|Wrap when changing tabs.
|
||||
|<<unknown_url.scheme.policy,unknown_url.scheme.policy>>|Set UnknownUrlSchemePolicy.
|
||||
|<<url.auto_search,url.auto_search>>|What search to start when something else than a URL is entered.
|
||||
|<<url.default_page,url.default_page>>|Page to open if :open -t/-b/-w is used without URL.
|
||||
|<<url.incdec_segments,url.incdec_segments>>|URL segments where `:navigate increment/decrement` will search for a number.
|
||||
|
|
@ -2284,6 +2284,25 @@ Valid values:
|
|||
|
||||
Default: +pass:[ask]+
|
||||
|
||||
[[content.unknown_url_scheme_policy]]
|
||||
=== content.unknown_url_scheme_policy
|
||||
How navigation requests to URLs with unknown schemes are handled.
|
||||
Only valid for webengine backend (Qt > 5.10). See https://doc.qt.io/qt-5/qwebenginesettings.html#UnknownUrlSchemePolicy-enum.
|
||||
|
||||
Type: <<types,String>>
|
||||
|
||||
Valid values:
|
||||
|
||||
* +DisallowUnknownUrlSchemes+: Disallows all navigation requests to URLs with unknown schemes.
|
||||
* +AllowUnknownUrlSchemesFromUserInteraction+: Allows navigation requests to URLs with unknown schemes that are issued from user-interaction (like a mouse-click), whereas other navigation requests (for example from JavaScript) are suppressed.
|
||||
* +AllowAllUnknownUrlSchemes+: Allows all navigation requests to URLs with unknown schemes.
|
||||
|
||||
Default: +pass:[AllowUnknownUrlSchemesFromUserInteraction]+
|
||||
|
||||
On QtWebEngine, this setting requires Qt 5.11 or newer.
|
||||
|
||||
On QtWebKit, this setting is unavailable.
|
||||
|
||||
[[content.user_stylesheets]]
|
||||
=== content.user_stylesheets
|
||||
List of user stylesheet filenames to use.
|
||||
|
|
@ -3702,15 +3721,6 @@ Type: <<types,Bool>>
|
|||
|
||||
Default: +pass:[true]+
|
||||
|
||||
[[unknown_url.scheme.policy]]
|
||||
=== unknown_url.scheme.policy
|
||||
Set UnknownUrlSchemePolicy.
|
||||
Only valid for webengine backend (Qt > 5.10). 1: DisallowUnknownUrlSchemes, 2: AllowUnknownUrlSchemesFromUserInteraction, 3: AllowAllUnknownUrlSchemes.
|
||||
|
||||
Type: <<types,Int>>
|
||||
|
||||
Default: +pass:[1]+
|
||||
|
||||
[[url.auto_search]]
|
||||
=== url.auto_search
|
||||
What search to start when something else than a URL is entered.
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ from qutebrowser.browser.webengine import spell, webenginequtescheme
|
|||
from qutebrowser.config import config, websettings
|
||||
from qutebrowser.config.websettings import AttributeInfo as Attr
|
||||
from qutebrowser.utils import (utils, standarddir, qtutils, message, log,
|
||||
urlmatch)
|
||||
urlmatch, usertypes)
|
||||
|
||||
# The default QWebEngineProfile
|
||||
default_profile = typing.cast(QWebEngineProfile, None)
|
||||
|
|
@ -138,11 +138,6 @@ class WebEngineSettings(websettings.AbstractSettings):
|
|||
Attr(QWebEngineSettings.ScrollAnimatorEnabled),
|
||||
}
|
||||
|
||||
# 2: AllowUnknownUrlSchemesFromUserInteraction
|
||||
_UnknownUrlSchemePolicy = {
|
||||
'unknown_url.scheme.policy': 2,
|
||||
}
|
||||
|
||||
_FONT_SIZES = {
|
||||
'fonts.web.size.minimum':
|
||||
QWebEngineSettings.MinimumFontSize,
|
||||
|
|
@ -163,6 +158,19 @@ class WebEngineSettings(websettings.AbstractSettings):
|
|||
'fonts.web.family.fantasy': QWebEngineSettings.FantasyFont,
|
||||
}
|
||||
|
||||
# Only Qt >= 5.11 support UnknownUrlSchemePolicy
|
||||
try:
|
||||
_UNKNOWN_URL_SCHEME_POLICY = {
|
||||
'DisallowUnknownUrlSchemes':
|
||||
QWebEngineSettings.DisallowUnknownUrlSchemes,
|
||||
'AllowUnknownUrlSchemesFromUserInteraction':
|
||||
QWebEngineSettings.AllowUnknownUrlSchemesFromUserInteraction,
|
||||
'AllowAllUnknownUrlSchemes':
|
||||
QWebEngineSettings.AllowAllUnknownUrlSchemes,
|
||||
}
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Mapping from WebEngineSettings::initDefaults in
|
||||
# qtwebengine/src/core/web_engine_settings.cpp
|
||||
_FONT_TO_QFONT = {
|
||||
|
|
@ -174,6 +182,30 @@ class WebEngineSettings(websettings.AbstractSettings):
|
|||
QWebEngineSettings.FantasyFont: QFont.Fantasy,
|
||||
}
|
||||
|
||||
|
||||
def set_unknown_url_scheme_policy(self, policy: str) -> bool:
|
||||
"""Set the UnknownUrlSchemePolicy to use.
|
||||
|
||||
Return:
|
||||
True if there was a change, False otherwise.
|
||||
"""
|
||||
assert policy is not usertypes.UNSET # type: ignore
|
||||
old_value = self._settings.unknownUrlSchemePolicy()
|
||||
policy = self._UNKNOWN_URL_SCHEME_POLICY[policy]
|
||||
self._settings.setUnknownUrlSchemePolicy(policy)
|
||||
return old_value != policy
|
||||
|
||||
def _update_setting(self, setting, value):
|
||||
if setting == 'content.unknown_url_scheme_policy':
|
||||
if hasattr(self, '_UNKNOWN_URL_SCHEME_POLICY'):
|
||||
return self.set_unknown_url_scheme_policy(value)
|
||||
return False
|
||||
return super()._update_setting(setting, value)
|
||||
|
||||
def init_settings(self):
|
||||
super().init_settings()
|
||||
self.update_setting('content.unknown_url_scheme_policy')
|
||||
|
||||
def __init__(self, settings):
|
||||
super().__init__(settings)
|
||||
# Attributes which don't exist in all Qt versions.
|
||||
|
|
|
|||
|
|
@ -370,6 +370,23 @@ content.default_encoding:
|
|||
The encoding must be a string describing an encoding such as _utf-8_,
|
||||
_iso-8859-1_, etc.
|
||||
|
||||
content.unknown_url_scheme_policy:
|
||||
type:
|
||||
name: String
|
||||
valid_values:
|
||||
- DisallowUnknownUrlSchemes: Disallows all navigation requests to URLs with unknown schemes.
|
||||
- AllowUnknownUrlSchemesFromUserInteraction: Allows navigation requests to URLs with unknown schemes that are issued from user-interaction (like a mouse-click), whereas other navigation requests (for example from JavaScript) are suppressed.
|
||||
- AllowAllUnknownUrlSchemes: Allows all navigation requests to URLs with unknown schemes.
|
||||
default: AllowUnknownUrlSchemesFromUserInteraction
|
||||
backend:
|
||||
QtWebEngine: Qt 5.11
|
||||
QtWebKit: false
|
||||
desc: >-
|
||||
How navigation requests to URLs with unknown schemes are handled.
|
||||
|
||||
Only valid for webengine backend (Qt > 5.10). See
|
||||
https://doc.qt.io/qt-5/qwebenginesettings.html#UnknownUrlSchemePolicy-enum.
|
||||
|
||||
content.windowed_fullscreen:
|
||||
type: Bool
|
||||
default: false
|
||||
|
|
@ -2512,22 +2529,6 @@ colors.webpage.prefers_color_scheme_dark:
|
|||
|
||||
# emacs: '
|
||||
|
||||
## unkown_url
|
||||
|
||||
unknown_url.scheme.policy:
|
||||
default: 1
|
||||
type:
|
||||
name: Int
|
||||
minval: 1
|
||||
maxval: 3
|
||||
desc: >-
|
||||
Set UnknownUrlSchemePolicy.
|
||||
|
||||
Only valid for webengine backend (Qt > 5.10).
|
||||
1: DisallowUnknownUrlSchemes, 2: AllowUnknownUrlSchemesFromUserInteraction, 3: AllowAllUnknownUrlSchemes.
|
||||
|
||||
|
||||
|
||||
## fonts
|
||||
|
||||
fonts.default_family:
|
||||
|
|
|
|||
|
|
@ -99,7 +99,6 @@ class AbstractSettings:
|
|||
_FONT_SIZES = {} # type: typing.Dict[str, typing.Any]
|
||||
_FONT_FAMILIES = {} # type: typing.Dict[str, typing.Any]
|
||||
_FONT_TO_QFONT = {} # type: typing.Dict[typing.Any, QFont.StyleHint]
|
||||
_UnknownUrlSchemePolicy = {} # type: typing.Dict[str, typing.Any]
|
||||
|
||||
def __init__(self, settings: typing.Any) -> None:
|
||||
self._settings = settings
|
||||
|
|
@ -178,17 +177,6 @@ class AbstractSettings:
|
|||
self._settings.setDefaultTextEncoding(encoding)
|
||||
return old_value != encoding
|
||||
|
||||
def set_unknown_url_scheme_policy(self, policy: int) -> bool:
|
||||
"""Set the UnknownUrlSchemePolicy to use.
|
||||
|
||||
Return:
|
||||
True if there was a change, False otherwise.
|
||||
"""
|
||||
assert policy is not usertypes.UNSET # type: ignore
|
||||
old_value = self._settings.unknownUrlSchemePolicy()
|
||||
self._settings.setUnknownUrlSchemePolicy(policy)
|
||||
return old_value != policy
|
||||
|
||||
def _update_setting(self, setting: str, value: typing.Any) -> bool:
|
||||
"""Update the given setting/value.
|
||||
|
||||
|
|
@ -205,15 +193,6 @@ class AbstractSettings:
|
|||
return self.set_font_family(setting, value)
|
||||
elif setting == 'content.default_encoding':
|
||||
return self.set_default_text_encoding(value)
|
||||
elif setting == 'unknown_url.scheme.policy':
|
||||
# QtWebKit and QWebEngine < 5.11 doesn't provide interfaces
|
||||
# for processing UnknownUrlSchemePolicy.
|
||||
#
|
||||
# AttributeError is expected for such cases.
|
||||
try:
|
||||
return self.set_unknown_url_scheme_policy(value)
|
||||
except AttributeError:
|
||||
pass
|
||||
return False
|
||||
|
||||
def update_setting(self, setting: str) -> None:
|
||||
|
|
@ -246,8 +225,7 @@ class AbstractSettings:
|
|||
def init_settings(self) -> None:
|
||||
"""Set all supported settings correctly."""
|
||||
for setting in (list(self._ATTRIBUTES) + list(self._FONT_SIZES) +
|
||||
list(self._FONT_FAMILIES) +
|
||||
list(self._UnknownUrlSchemePolicy)):
|
||||
list(self._FONT_FAMILIES)):
|
||||
self.update_setting(setting)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue