diff --git a/qutebrowser/browser/webengine/webenginetab.py b/qutebrowser/browser/webengine/webenginetab.py index 7dd8b0629..5c2533422 100644 --- a/qutebrowser/browser/webengine/webenginetab.py +++ b/qutebrowser/browser/webengine/webenginetab.py @@ -22,6 +22,7 @@ import os import math import functools +import html as html_utils import sip from PyQt5.QtCore import pyqtSlot, Qt, QEvent, QPoint, QUrl, QTimer @@ -37,7 +38,7 @@ from qutebrowser.browser.webengine import (webview, webengineelem, tabhistory, webenginesettings) from qutebrowser.misc import miscwidgets from qutebrowser.utils import (usertypes, qtutils, log, javascript, utils, - objreg, jinja, debug, version) + message, objreg, jinja, debug, version) _qute_scheme_handler = None @@ -678,6 +679,32 @@ class WebEngineTab(browsertab.AbstractTab): self.add_history_item.emit(url, requested_url, title) + @pyqtSlot(QUrl, 'QAuthenticator*', 'QString') + def _on_proxy_authentication_required(self, url, authenticator, + proxy_host): + """Called when a proxy needs authentication.""" + msg = "{} requires a username and password.".format( + html_utils.escape(proxy_host)) + answer = message.ask( + title="Proxy authentication required", text=msg, + mode=usertypes.PromptMode.user_pwd, + abort_on=[self.shutting_down, self.load_started]) + if answer is not None: + authenticator.setUser(answer.user) + authenticator.setPassword(answer.password) + else: + try: + # pylint: disable=no-member, useless-suppression + sip.assign(authenticator, QAuthenticator()) + except AttributeError: + url_string = url.toDisplayString() + error_page = jinja.render( + 'error.html', + title="Error loading page: {}".format(url_string), + url=url_string, error="Proxy authentication required", + icon='') + self.set_html(error_page) + @pyqtSlot(QUrl, 'QAuthenticator*') def _on_authentication_required(self, url, authenticator): # FIXME:qtwebengine support .netrc @@ -755,6 +782,8 @@ class WebEngineTab(browsertab.AbstractTab): page.loadFinished.connect(self._on_load_finished) page.certificate_error.connect(self._on_ssl_errors) page.authenticationRequired.connect(self._on_authentication_required) + page.proxyAuthenticationRequired.connect( + self._on_proxy_authentication_required) page.fullScreenRequested.connect(self._on_fullscreen_requested) page.contentsSizeChanged.connect(self.contents_size_changed)