Don't treat page load as failed with blocked hosts.

Fixes #315.
This commit is contained in:
Florian Bruhin 2014-12-11 18:05:01 +01:00
parent 5eeb89ec86
commit 4e6cedb1f7
2 changed files with 14 additions and 6 deletions

View File

@ -117,16 +117,21 @@ class BrowserPage(QWebPage):
info.error))
return False
else:
self._ignore_load_started = True
self.error_occured = True
error_str = info.errorString
if error_str == networkmanager.HOSTBLOCK_ERROR_STRING:
error_str = "Request blocked by host blocker."
# we don't set error_occured in this case.
else:
self._ignore_load_started = True
self.error_occured = True
log.webview.error("Error while loading {}: {}".format(
urlstr, info.errorString))
urlstr, error_str))
log.webview.debug("Error domain: {}, error code: {}".format(
info.domain, info.error))
title = "Error loading page: {}".format(urlstr)
template = jinja.env.get_template('error.html')
html = template.render( # pylint: disable=maybe-no-member
title=title, url=urlstr, error=info.errorString, icon='')
title=title, url=urlstr, error=error_str, icon='')
errpage.content = html.encode('utf-8')
errpage.encoding = 'utf-8'
return True

View File

@ -35,6 +35,9 @@ from qutebrowser.network import qutescheme, networkreply
from qutebrowser.browser import cookies
HOSTBLOCK_ERROR_STRING = '%HOSTBLOCK%'
class NetworkManager(QNetworkAccessManager):
"""Our own QNetworkAccessManager.
@ -228,8 +231,8 @@ class NetworkManager(QNetworkAccessManager):
log.webview.info("Request to {} blocked by host blocker.".format(
req.url().host()))
return networkreply.ErrorNetworkReply(
req, "Request was blocked by host blocker.",
QNetworkReply.ContentAccessDenied, self)
req, HOSTBLOCK_ERROR_STRING, QNetworkReply.ContentAccessDenied,
self)
if config.get('network', 'do-not-track'):
dnt = '1'.encode('ascii')
else: