This repository has been archived on 2023-02-02. You can view files and clone it, but cannot push or open issues or pull requests.
barkshark-web/barkshark_web/component/web_settings.py
2022-04-16 06:23:04 -04:00

385 lines
10 KiB
Python

from .. import __version__ as version
default_settings = {
'allow-file-access-from-file-urls': {
'default': False,
'name': 'Local file access',
'description': 'Allow requests in local html files access other local files'
},
'allow-modal-dialogs': {
'default': False,
'name': 'Javascript modal dialogs',
'description': 'Allow the window.showModalDialog javascript function to be executed'
},
'allow-top-navigation-to-data-urls': {
'default': False,
'name': 'Data url access',
'description': 'Allow navigation to data urls'
},
'allow-universal-access-from-file-urls': {
'default': False,
'name': 'Javascript local file access',
'description': 'Allow javascript on local pages to access local files'
},
'auto-load-images': {
'default': True,
'name': 'Load images',
'description': 'Auto-load images on pages'
},
'cursive-font-family': {
'default': 'serif',
'name': 'Cursive font',
'description': 'Font to use for cursive text'
},
'default-charset': {
'default': 'iso-8859-1',
'name': 'Charset',
'description': 'Character set to use on pages'
},
'default-font-family': {
'default': 'sans-serif',
'name': 'Default font',
'description': 'Font to use for normal text'
},
'default-font-size': {
'default': 16,
'name': 'Font size',
'description': 'Font size to use when the page does not specify a font size'
},
'default-monospace-font-size': {
'default': 16,
'name': 'Monospace font size',
'description': 'Font size to use when the page does not specify a font size for monospace fonts'
},
'draw-compositing-indicators': {
'default': False,
'name': 'Compositing indicators',
'description': 'Whether to draw compositing borders and repaint counters on layers drawn with accelerated compositing'
},
'enable-accelerated-2d-canvas': {
'default': True,
'name': 'GPU acceleration',
'description': 'For the GPU to render the page'
},
'enable-back-forward-navigation-gestures': {
'default': False,
'name': 'Back/forward gestures',
'description': 'Enable swiping horizontally to go back or forward'
},
'enable-caret-browsing': {
'default': False,
'name': 'Caret browsing',
'description': 'Enable navigating text in pages via arrow keys'
},
'enable-developer-extras': {
'default': True,
'name': 'Developer extras',
'description': 'Enable extra developer tools'
},
'enable-dns-prefetching': {
'default': False,
'name': 'DNS prefetching',
'description': 'Attempt to resolve domain names when a link is hovered'
},
'enable-encrypted-media': {
'default': True,
'name': 'Encrypted media',
'description': 'Enable the EncryptedMedia API'
},
'enable-frame-flattening': {
'default': False,
'name': 'Frame flattening',
'description': 'Merge frames into the main page to create one big page'
},
'enable-fullscreen': {
'default': True,
'name': 'Allow fullscreen',
'description': 'Allow pages to force the browser to go fullscreen'
},
'enable-html5-database': {
'default': True,
'name': 'IndexDB support',
'description': 'Enable client-side Sqlite database support'
},
'enable-html5-local-storage': {
'default': True,
'name': 'Local storage support',
'description': 'Allow page access to window.localStorage'
},
'enable-hyperlink-auditing': {
'default': False,
'name': 'Hyperlink auditing',
'description': 'Enable hyperlink auditing' #not sure what this is tbh
},
'enable-java': {
'default': False,
'name': 'Enable Java',
'description': 'Allow Java applets to run if the Java browser plugin is installed'
},
'enable-javascript': {
'default': True,
'name': 'Enable Javascript',
'description': 'Allow Javascript to be executed on pages'
},
'enable-javascript-markup': {
'default': True,
'name': 'Enable Javascript tags and attributes',
'description': 'Allows the Javascript tag and element attributes'
},
'enable-media': {
'default': True,
'name': 'Allow media',
'description': 'Enable support for the "audio", "track", and "video" tags'
},
'enable-media-capabilities': {
'default': True,
'name': 'MediaCapabilities API',
'description': 'Allow web pages to determine the right media formats to use'
},
'enable-media-stream': {
'default': True,
'name': 'Media device access',
'description': 'Allow pages to access media devices such as a mic or webcam'
},
'enable-mediasource': {
'default': True,
'name': 'MediaSource API',
'description': 'Enable the MediaSource API'
},
'enable-mock-capture-devices': {
'default': False,
'name': 'Fake capture devices',
'description': 'Create fake capture devices for the MediaStream API'
},
'enable-offline-web-application-cache': {
'default': True,
'name': 'Offline web app cache',
'description': 'Cache application resources for offline use'
},
'enable-page-cache': {
'default': True,
'name': 'Page caching',
'description': 'Cache pages to make going back/forward faster'
},
'enable-plugins': {
'default': False,
'name': 'Enable plugins',
'description': 'Allow browser plugins to be executed'
},
'enable-resizable-text-areas': {
'default': True,
'name': 'Resizable text areas',
'description': 'Allow text areas to be resized via a handle in the bottom right'
},
'enable-site-specific-quirks': {
'default': True,
'name': 'Enable site workarounds',
'description': 'Allow the browser to workaround site-specific issues'
},
'enable-smooth-scrolling': {
'default': True,
'name': 'Smooth scrolling',
'description': 'Animate page scrolling to avoid jumpiness'
},
'enable-spatial-navigation': {
'default': False,
'name': 'Spatial navigation',
'description': 'Allow navigating page elements via arrow keys'
},
'enable-tabs-to-links': {
'default': True,
'name': 'Tab to links',
'description': 'Use the tab key to cycle through links on the page'
},
'enable-webaudio': {
'default': True,
'name': 'WebAudio API',
'description': 'Enable the WebAudio API which allows pages to process or synthesize audio'
},
'enable-webgl': {
'default': True,
'name': 'WebGL',
'description': 'Allow page access to OpenGL'
},
'enable-write-console-messages-to-stdout': {
'default': False,
'name': 'Console messages to stdout',
'description': 'All console messages are send to stdout'
},
'enable-xss-auditor': {
'default': True,
'name': 'XSS auditor',
'description': 'Filter some kinds of reflective XSS attacks'
},
'fantasy-font-family': {
'default': 'serif',
'name': 'Fantasy font',
'description': 'Font to use when the page does not specify a font for fantasy fonts'
},
'hardware-acceleration-policy': {
'default': 'demand',
'name': 'Hardware acceleration',
'description': 'Allow GPU rendering of pages'
},
'javascript-can-access-clipboard': {
'default': False,
'name': 'Javascript clipboard access',
'description': 'Allow Javascript to access the clipboard'
},
'javascript-can-open-windows-automatically': {
'default': False,
'name': 'Javascript auto-popups',
'description': 'Allow Javascript to open new tabs without user intervention'
},
'load-icons-ignoring-image-load-setting': {
'default': True,
'name': 'Force load favicon',
'description': 'If image loading is disabled, allow favicons to be loaded'
},
'media-content-types-requiring-hardware-support': {
'default': None,
'name': 'Media requiring hardware support',
'description': 'Force certan media types to use hardware decoding'
},
'media-playback-allows-inline': {
'default': True,
'name': 'Inline media playback',
'description': 'Allow media to play without being fullscreened'
},
'media-playback-requires-user-gesture': {
'default': False,
'name': 'Prevent media autoplay',
'description': 'Prevent media from playing without user interaction'
},
'minimum-font-size': {
'default': 2,
'name': 'Minimum font size',
'description': 'The smallest size for text'
},
'monospace-font-family': {
'default': 'monospace',
'name': 'Monospace font',
'description': 'Font to use when the page does not specify a font for monospace fonts'
},
'pictograph-font-family': {
'default': 'serif',
'name': 'Pictograph font',
'description': 'Font to use when the page does not specify a font for pictograph fonts'
},
'print-backgrounds': {
'default': True,
'name': 'Print background',
'description': 'Include background images when printing a page'
},
'sans-serif-font-family': {
'default': 'sans-serif',
'name': 'Sans-serif font',
'description': 'Font to use when the page does not specify a font for sans-serif fonts'
},
'serif-font-family': {
'default': 'serif',
'name': 'Serif font',
'description': 'Font to use when the page does not specify a font for pictograph fonts'
},
'user-agent': {
'default': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:99.0) Gecko/20100101 Firefox/99.0',
'name': 'User Agent',
'description': 'How the browser identifies itself when connecting to web servers'
},
'zoom-text-only': {
'default': False,
'name': 'Only zoom text',
'description': 'When zooming a page, only change the size of the text'
}
}
accel_policy = dict(
demand = 0,
always = 1,
never = 2
)
class WebSettings(WebKit2.Settings):
def __init__(self, tab):
super().__init__()
self.tab = tab
#self.set_user_agent_with_application_details('pyWeb', version)
for k,v in default_settings.items():
self[k] = v['default']
def __getitem__(self, key):
return self.get_property(key)
def __setitem__(self, key, value):
if key not in default_settings:
logging.error('Invalid setting:', key)
return
if key == 'hardware-acceleration-policy':
value = accel_policy.get(value.lower(), value)
self.set_property(key, value)
def __delitem__(self, key):
self[key] = default_settings[key]['default']
def apply(self):
try:
self.tab.webview.set_settings(self)
except AttributeError:
logging.warning('Tried to apply settings before webview setup')
def set(self, key, value):
if key not in default_settings.keys():
logging.error('Invalid setting:', key)
return
if key == 'hardware-acceleration-policy':
value = accel_policy.get(value.lower(), value)
self.set_property(key, value)
self.apply()
def set_default(self, key):
del self[key]
self.apply()
## dict functions
def get(self, key, default=None):
try:
return self[key]
except TypeError:
return default
def items(self):
return tuple(tuple(k, self[k]) for k in self.keys())
def keys(self):
return tuple(default_settings.keys())
def update(self, data):
for k,v in data.items():
self[k] = v
self.apply()
def values(self):
return tuple(self[k] for k in self.keys())