Revert "Fix Qt 5.11 issues with clicking invalid links"

This reverts commit 1956590df84a72c7f9a516e805d01529291fccf8.

Turns out the actual issue wasn't due to *invalid* links - it's with links
which have an unknown scheme.

There's still a change in behavior between Qt 5.10 and 5.11 though: Invalid
links are apparently not passed to acceptNavigationRequest (sometimes?) so we
don't show an error message. Instead, we just load about:blank. However,
Chromium does that too and we can't handle a real click easily, so let's just
ignore that one.

See #3661
This commit is contained in:
Florian Bruhin 2018-06-07 12:43:05 +02:00
parent 3d53d0d2c5
commit 0e9159e8e8
3 changed files with 3 additions and 31 deletions

View File

@ -33,8 +33,7 @@ from PyQt5.QtGui import QMouseEvent
from qutebrowser.config import config
from qutebrowser.keyinput import modeman
from qutebrowser.mainwindow import mainwindow
from qutebrowser.utils import (log, usertypes, utils, qtutils, objreg,
urlutils, message)
from qutebrowser.utils import log, usertypes, utils, qtutils, objreg
Group = enum.Enum('Group', ['all', 'links', 'images', 'url', 'inputs'])
@ -276,13 +275,11 @@ class AbstractWebElement(collections.abc.MutableMapping):
"""Remove target from link."""
raise NotImplementedError
def resolve_url(self, baseurl, *, return_invalid=False):
def resolve_url(self, baseurl):
"""Resolve the URL in the element's src/href attribute.
Args:
baseurl: The URL to base relative URLs on as QUrl.
return_invalid: Whether to return an invalid QUrl.
If False, None is returned for invalid URLs.
Return:
A QUrl with the absolute URL, or None.
@ -299,7 +296,7 @@ class AbstractWebElement(collections.abc.MutableMapping):
url = QUrl(text)
if not url.isValid():
return url if return_invalid else None
return None
if url.isRelative():
url = baseurl.resolved(url)
qtutils.ensure_valid(url)
@ -407,15 +404,6 @@ class AbstractWebElement(collections.abc.MutableMapping):
self._click_fake_event(click_target)
return
if qtutils.version_check('5.11', compiled=False):
# WORKAROUND for https://bugreports.qt.io/browse/QTBUG-63378
baseurl = self._tab.url()
url = self.resolve_url(baseurl, return_invalid=True)
if url is not None and not url.isValid():
msg = urlutils.get_errstring(url, "Invalid link clicked")
message.error(msg)
return
if click_target == usertypes.ClickTarget.normal:
if self.is_link():
log.webelem.debug("Clicking via JS click()")

View File

@ -342,11 +342,6 @@ class WebEnginePage(QWebEnginePage):
navigation_type=type_map[typ],
is_main_frame=is_main_frame)
self.navigation_request.emit(navigation)
if not url.isValid() and qtutils.version_check('5.11', compiled=False):
# WORKAROUND for https://bugreports.qt.io/browse/QTBUG-63378
return True
return navigation.accepted
@pyqtSlot('QUrl')

View File

@ -872,14 +872,3 @@ def test_resolve_url_relative_base():
elem = get_webelem(attributes={'href': 'foo'})
with pytest.raises(ValueError):
elem.resolve_url(QUrl('base'))
@pytest.mark.parametrize('return_invalid', [True, False])
def test_resolve_url_invalid(return_invalid):
elem = get_webelem(attributes={'href': 'what://::'})
baseurl = QUrl('http://www.example.com/')
resolved = elem.resolve_url(baseurl, return_invalid=return_invalid)
if return_invalid:
assert not resolved.isValid()
else:
assert resolved is None