Revert "Inject JS into the profile"

This reverts commit acfb3aa26f.

The related code doesn't really belong in webenginesettings.py after all, and
for some reason I don't understand right now this breaks tests in
javascript.feature because window._qutebrowser is undefined when running them.
This commit is contained in:
Florian Bruhin 2017-11-03 09:53:45 +01:00
parent 25bda66260
commit be325853d8
2 changed files with 18 additions and 20 deletions

View File

@ -193,24 +193,6 @@ def _set_http_headers(profile):
profile.setHttpAcceptLanguage(accept_language)
def _init_js(profile):
"""Initialize QtWebEngine JavaScript on the given profile."""
js_code = '\n'.join([
'"use strict";',
'window._qutebrowser = {};',
utils.read_file('javascript/scroll.js'),
utils.read_file('javascript/webelem.js'),
])
script = QWebEngineScript()
script.setInjectionPoint(QWebEngineScript.DocumentCreation)
script.setSourceCode(js_code)
script.setWorldId(QWebEngineScript.ApplicationWorld)
# FIXME:qtwebengine What about runsOnSubFrames?
profile.scripts().insert(script)
def _update_settings(option):
"""Update global settings when qwebsettings changed."""
websettings.update_mappings(MAPPINGS, option)
@ -233,13 +215,11 @@ def _init_profiles():
os.path.join(standarddir.data(), 'webengine'))
_init_stylesheet(default_profile)
_set_http_headers(default_profile)
_init_js(default_profile)
private_profile = QWebEngineProfile()
assert private_profile.isOffTheRecord()
_init_stylesheet(private_profile)
_set_http_headers(private_profile)
_init_js(private_profile)
if qtutils.version_check('5.8'):
default_profile.setSpellCheckEnabled(True)

View File

@ -526,9 +526,27 @@ class WebEngineTab(browsertab.AbstractTab):
self._set_widget(widget)
self._connect_signals()
self.backend = usertypes.Backend.QtWebEngine
self._init_js()
self._child_event_filter = None
self._saved_zoom = None
def _init_js(self):
js_code = '\n'.join([
'"use strict";',
'window._qutebrowser = {};',
utils.read_file('javascript/scroll.js'),
utils.read_file('javascript/webelem.js'),
])
script = QWebEngineScript()
script.setInjectionPoint(QWebEngineScript.DocumentCreation)
script.setSourceCode(js_code)
page = self._widget.page()
script.setWorldId(QWebEngineScript.ApplicationWorld)
# FIXME:qtwebengine what about runsOnSubFrames?
page.scripts().insert(script)
def _install_event_filter(self):
self._widget.focusProxy().installEventFilter(self._mouse_event_filter)
self._child_event_filter = mouse.ChildEventFilter(