Temporarily set JavascriptCanOpenWindows for hints
This partially reverts ba21fb3784
.
Fixes #2311.
This commit is contained in:
parent
399b02a367
commit
410b56447a
@ -406,12 +406,7 @@ class AbstractWebElement(collections.abc.MutableMapping):
|
|||||||
|
|
||||||
href_tags = ['a', 'area', 'link']
|
href_tags = ['a', 'area', 'link']
|
||||||
if click_target == usertypes.ClickTarget.normal:
|
if click_target == usertypes.ClickTarget.normal:
|
||||||
if self.tag_name() in href_tags and self.get('target') == '_blank':
|
if self.tag_name() in href_tags:
|
||||||
log.webelem.debug("target _blank -> Clicking via href")
|
|
||||||
# FIXME:qtwebengine Should we use tab_bg here with
|
|
||||||
# background-tabs set?
|
|
||||||
self._click_href(usertypes.ClickTarget.tab)
|
|
||||||
elif self.tag_name() in href_tags:
|
|
||||||
log.webelem.debug("Clicking via JS click()")
|
log.webelem.debug("Clicking via JS click()")
|
||||||
self._click_js(click_target)
|
self._click_js(click_target)
|
||||||
elif self.is_editable(strict=True):
|
elif self.is_editable(strict=True):
|
||||||
|
@ -22,8 +22,10 @@
|
|||||||
|
|
||||||
"""QtWebEngine specific part of the web element API."""
|
"""QtWebEngine specific part of the web element API."""
|
||||||
|
|
||||||
from PyQt5.QtCore import QRect, Qt, QPoint
|
from PyQt5.QtCore import QRect, Qt, QPoint, QEventLoop
|
||||||
from PyQt5.QtGui import QMouseEvent
|
from PyQt5.QtGui import QMouseEvent
|
||||||
|
from PyQt5.QtWidgets import QApplication
|
||||||
|
from PyQt5.QtWebEngineWidgets import QWebEngineSettings
|
||||||
|
|
||||||
from qutebrowser.utils import log, javascript
|
from qutebrowser.utils import log, javascript
|
||||||
from qutebrowser.browser import webelem
|
from qutebrowser.browser import webelem
|
||||||
@ -169,5 +171,21 @@ class WebEngineElement(webelem.AbstractWebElement):
|
|||||||
self._tab.run_js_async(js_code)
|
self._tab.run_js_async(js_code)
|
||||||
|
|
||||||
def _click_js(self, _click_target):
|
def _click_js(self, _click_target):
|
||||||
|
settings = QWebEngineSettings.globalSettings()
|
||||||
|
attribute = QWebEngineSettings.JavascriptCanOpenWindows
|
||||||
|
could_open_windows = settings.testAttribute(attribute)
|
||||||
|
settings.setAttribute(attribute, True)
|
||||||
|
|
||||||
|
# Get QtWebEngine do apply the settings
|
||||||
|
# (it does so with a 0ms QTimer...)
|
||||||
|
# This is also used in Qt's tests:
|
||||||
|
# https://github.com/qt/qtwebengine/commit/5e572e88efa7ba7c2b9138ec19e606d3e345ac90
|
||||||
|
qapp = QApplication.instance()
|
||||||
|
qapp.processEvents(QEventLoop.ExcludeSocketNotifiers |
|
||||||
|
QEventLoop.ExcludeUserInputEvents)
|
||||||
|
|
||||||
|
def reset_setting(_arg):
|
||||||
|
settings.setAttribute(attribute, could_open_windows)
|
||||||
|
|
||||||
js_code = javascript.assemble('webelem', 'click', self._id)
|
js_code = javascript.assemble('webelem', 'click', self._id)
|
||||||
self._tab.run_js_async(js_code)
|
self._tab.run_js_async(js_code, reset_setting)
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
"""QtWebKit specific part of the web element API."""
|
"""QtWebKit specific part of the web element API."""
|
||||||
|
|
||||||
from PyQt5.QtCore import QRect
|
from PyQt5.QtCore import QRect
|
||||||
from PyQt5.QtWebKit import QWebElement
|
from PyQt5.QtWebKit import QWebElement, QWebSettings
|
||||||
|
|
||||||
from qutebrowser.config import config
|
from qutebrowser.config import config
|
||||||
from qutebrowser.utils import log, utils, javascript
|
from qutebrowser.utils import log, utils, javascript
|
||||||
@ -301,11 +301,12 @@ class WebKitElement(webelem.AbstractWebElement):
|
|||||||
self._elem.evaluateJavaScript('this.focus();')
|
self._elem.evaluateJavaScript('this.focus();')
|
||||||
|
|
||||||
def _click_js(self, click_target):
|
def _click_js(self, click_target):
|
||||||
if self.get('target') == '_blank':
|
settings = QWebSettings.globalSettings()
|
||||||
# QtWebKit does nothing in this case for some reason...
|
attribute = QWebSettings.JavascriptCanOpenWindows
|
||||||
self._click_fake_event(click_target)
|
could_open_windows = settings.testAttribute(attribute)
|
||||||
else:
|
settings.setAttribute(attribute, True)
|
||||||
self._elem.evaluateJavaScript('this.click();')
|
self._elem.evaluateJavaScript('this.click();')
|
||||||
|
settings.setAttribute(attribute, could_open_windows)
|
||||||
|
|
||||||
def _click_fake_event(self, click_target):
|
def _click_fake_event(self, click_target):
|
||||||
self._tab.data.override_target = click_target
|
self._tab.data.override_target = click_target
|
||||||
|
Loading…
Reference in New Issue
Block a user