From 4c751d8081cd3a72e9c39b129b9a7839e47ea9ca Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 16 Apr 2014 13:32:55 +0200 Subject: [PATCH] Add webkit settings to config --- qutebrowser/app.py | 1 + qutebrowser/config/config.py | 50 ++++++++++++ qutebrowser/config/configdata.py | 130 +++++++++++++++++++++++++++++++ 3 files changed, 181 insertions(+) diff --git a/qutebrowser/app.py b/qutebrowser/app.py index fd4c3ae86..46d6286b4 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -137,6 +137,7 @@ class QuteBrowser(QApplication): self.mainwindow.completion.on_config_changed) self.config.changed.connect(self.mainwindow.on_config_changed) self.config.changed.connect(config.cmd_history.on_config_changed) + self.config.changed.connect(config.qwebsetting_on_config_changed) self.mainwindow.show() self._python_hacks() diff --git a/qutebrowser/config/config.py b/qutebrowser/config/config.py index 11a7ba1ec..191ed96bc 100644 --- a/qutebrowser/config/config.py +++ b/qutebrowser/config/config.py @@ -31,6 +31,7 @@ from configparser import ConfigParser, ExtendedInterpolation from collections.abc import MutableMapping from PyQt5.QtCore import pyqtSignal, pyqtSlot, QObject +from PyQt5.QtWebKit import QWebSettings #from qutebrowser.utils.misc import read_file import qutebrowser.config.configdata as configdata @@ -43,6 +44,40 @@ state = None cmd_history = None +WEBSETTINGS_MAPPING = { + 'auto_load_images': QWebSettings.AutoLoadImages, + 'dns_prefetch_enabled': QWebSettings.DnsPrefetchEnabled, + 'javascript_enabled': QWebSettings.JavascriptEnabled, + #'java_enabled': #QWebSettings.JavaEnabled, + 'plugins_enabled': QWebSettings.PluginsEnabled, + 'private_browsing_enabled': QWebSettings.PrivateBrowsingEnabled, + 'javascript_can_open_windows': QWebSettings.JavascriptCanOpenWindows, + 'javascript_can_close_windows': QWebSettings.JavascriptCanCloseWindows, + 'javascript_can_access_clipboard': + QWebSettings.JavascriptCanAccessClipboard, + 'developer_extras_enabled': QWebSettings.DeveloperExtrasEnabled, + 'spatial_navigation_enabled': QWebSettings.SpatialNavigationEnabled, + 'links_included_in_focus_chain': QWebSettings.LinksIncludedInFocusChain, + 'zoom_text_only': QWebSettings.ZoomTextOnly, + 'print_element_backgrounds': QWebSettings.PrintElementBackgrounds, + 'offline_storage_database_enabled': + QWebSettings.OfflineStorageDatabaseEnabled, + 'offline_web_application_storage_enabled': + QWebSettings.OfflineWebApplicationCacheEnabled, + 'local_storage_enabled': QWebSettings.LocalStorageEnabled, + 'local_content_can_access_remote_urls': + QWebSettings.LocalContentCanAccessRemoteUrls, + 'local_content_can_access_file_urls': + QWebSettings.LocalContentCanAccessFileUrls, + 'xss_auditing_enabled': QWebSettings.XSSAuditingEnabled, + #'accelerated_compositing_enabled': + # QWebSettings.AcceleratedCompositingEnabled, + #'tiled_backing_store_enabled': QWebSettings.TiledBackingStoreEnabled, + 'frame_flattening_enabled': QWebSettings.FrameFlatteningEnabled, + 'site_specific_quirks_enabled': QWebSettings.SiteSpecificQuirksEnabled, +} + + class NoSectionError(configparser.NoSectionError): """Exception raised when a section was not found.""" @@ -71,6 +106,21 @@ def init(configdir): state = ReadWriteConfigParser(configdir, 'state') cmd_history = LineConfigParser(configdir, 'cmd_history', ('general', 'cmd_histlen')) + init_qwebsettings() + +def init_qwebsettings(): + """Initialize the global QWebSettings.""" + settings = QWebSettings.globalSettings() + for name, item in WEBSETTINGS_MAPPING.items(): + settings.setAttribute(item, config.get('webkit', name)) + + +@pyqtSlot(str, str, object) +def qwebsetting_on_config_changed(section, option, value): + """Update global settings when qwebsettings changed.""" + if section == 'webkit': + settings = QWebSettings.globalSettings() + settings.setAttribute(WEBSETTINGS_MAPPING[option], value) class Config(QObject): diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index 5a520b431..95ef31b20 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -48,6 +48,7 @@ FIRST_COMMENT = """ SECTION_DESC = { 'general': 'General/misc. options', 'tabbar': 'Configuration of the tab bar.', + 'webkit': 'Webkit settings.', 'searchengines': ( 'Definitions of search engines which can be used via the address ' 'bar.\n' @@ -172,6 +173,135 @@ def configdata(): "Behaviour when the last tab is closed."), )), + ('webkit', sect.KeyValue( + ('auto_load_images', + SettingValue(types.Bool, "true"), + "Specifies whether images are automatically loaded in web " + "pages."), + + ('dns_prefetch_enabled', + SettingValue(types.Bool, "false"), + "Specifies whether QtWebkit will try to pre-fetch DNS entries to " + "speed up browsing."), + + ('javascript_enabled', + SettingValue(types.Bool, "true"), + "Enables or disables the running of JavaScript programs."), + + #('java_enabled', + # SettingValue(types.Bool, "true"), + # "Enables or disables Java applets. Currently Java applets are " + # "not supported"), + + ('plugins_enabled', + SettingValue(types.Bool, "false"), + "Enables or disables plugins in Web pages"), + + ('private_browsing_enabled', + SettingValue(types.Bool, "false"), + "Private browsing prevents WebKit from recording visited pages " + "in the history and storing web page icons."), + + ('javascript_can_open_windows', + SettingValue(types.Bool, "false"), + "Specifies whether JavaScript programs can open new windows."), + + ('javascript_can_close_windows', + SettingValue(types.Bool, "false"), + "Specifies whether JavaScript programs can close windows."), + + ('javascript_can_access_clipboard', + SettingValue(types.Bool, "false"), + "Specifies whether JavaScript programs can read or write to the " + "clipboard."), + + ('developer_extras_enabled', + SettingValue(types.Bool, "false"), + "Enables extra tools for Web developers (e.g. webinspector)"), + + ('spatial_navigation_enabled', + SettingValue(types.Bool, "false"), + "Enables or disables the Spatial Navigation feature, which " + "consists in the ability to navigate between focusable elements " + "in a Web page, such as hyperlinks and form controls, by using " + "Left, Right, Up and Down arrow keys."), + + ('links_included_in_focus_chain', + SettingValue(types.Bool, "true"), + "Specifies whether hyperlinks should be included in the keyboard " + "focus chain."), + + ('zoom_text_only', + SettingValue(types.Bool, "false"), + "Specifies whether the zoom factor on a frame applies only to " + "the text or to all content."), + + ('print_element_backgrounds', + SettingValue(types.Bool, "true"), + "Specifies whether the background color and images are also " + "drawn when the page is printed. "), + + ('offline_storage_database_enabled', + SettingValue(types.Bool, "false"), + "Specifies whether support for the HTML 5 offline storage " + "feature is enabled or not. "), + + ('offline_web_application_storage_enabled', + SettingValue(types.Bool, "false"), + "Specifies whether support for the HTML 5 web application cache " + "feature is enabled or not. "), + + ('local_storage_enabled', + SettingValue(types.Bool, "false"), + "Specifies whether support for the HTML 5 local storage feature " + "is enabled or not."), + + ('local_content_can_access_remote_urls', + SettingValue(types.Bool, "false"), + "Specifies whether locally loaded documents are allowed to " + "access remote urls."), + + ('local_content_can_access_file_urls', + SettingValue(types.Bool, "true"), + "Specifies whether locally loaded documents are allowed to " + "access other local urls."), + + ('xss_auditing_enabled', + SettingValue(types.Bool, "false"), + "Specifies whether load requests should be monitored for " + "cross-site scripting attempts. Suspicious scripts will be " + "blocked and reported in the inspector's JavaScript console. " + "Enabling this feature might have an impact on performance."), + + #('accelerated_compositing_enabled', + # SettingValue(types.Bool, "true"), + # "This feature, when used in conjunction with QGraphicsWebView, " + # "accelerates animations of web content. CSS animations of the " + # "transform and opacity properties will be rendered by composing " + # "the cached content of the animated elements. "), + + #('tiled_backing_store_enabled', + # SettingValue(types.Bool, "false"), + # "This setting enables the tiled backing store feature for a " + # "QGraphicsWebView. With the tiled backing store enabled, the web " + # "page contents in and around the current visible area is " + # "speculatively cached to bitmap tiles. The tiles are " + # "automatically kept in sync with the web page as it changes. " + # "Enabling tiling can significantly speed up painting heavy " + # "operations like scrolling. Enabling the feature increases " + # "memory consumption. "), + + ('frame_flattening_enabled', + SettingValue(types.Bool, "false"), + "With this setting each subframe is expanded to its contents. " + "This will flatten all the frames to become one scrollable " + "page."), + + ('site_specific_quirks_enabled', + SettingValue(types.Bool, "true"), + "This setting enables WebKit's workaround for broken sites."), + )), + ('searchengines', sect.ValueList( types.SearchEngineName, types.SearchEngineUrl, ('DEFAULT', '${duckduckgo}'),