Change username/password prompt for proxyAuthenticationRequired

Update webview.py to more closely follow the webkit/networkmanager.py
on_proxy_authentication_required().
This commit is contained in:
Ian Walker 2017-09-18 15:55:44 +09:00
parent eaa1bdcddb
commit 9867200c38

View File

@ -20,6 +20,7 @@
"""The main browser widget for QtWebEngine.""" """The main browser widget for QtWebEngine."""
import functools import functools
import html
from PyQt5.QtCore import pyqtSignal, pyqtSlot, QUrl, PYQT_VERSION from PyQt5.QtCore import pyqtSignal, pyqtSlot, QUrl, PYQT_VERSION
from PyQt5.QtGui import QPalette from PyQt5.QtGui import QPalette
@ -147,16 +148,18 @@ class WebEnginePage(QWebEnginePage):
self.setBackgroundColor(col) self.setBackgroundColor(col)
@pyqtSlot(QUrl, 'QAuthenticator*', 'QString') @pyqtSlot(QUrl, 'QAuthenticator*', 'QString')
def _on_proxy_authentication_required(self, url, authenticator, proxyHost): def _on_proxy_authentication_required(self, url, authenticator,
answer = shared.authentication_required(url, authenticator, [self.shutting_down, self.loadStarted]) proxy_host):
if answer is None: """Called when a proxy needs authentication."""
authenticator.setUser(None) msg = "<b>{}</b> requires a username and password.".format(
authenticator.setPassword(None) html.escape(proxy_host))
url_string = url.toDisplayString() answer = message.ask(
error_page = jinja.render( title="Proxy authentication required", text=msg,
'error.html', title="Error loading page: {}".format(url_string), mode=usertypes.PromptMode.user_pwd,
url=url_string, error="Proxy authentication required.", icon='') abort_on=[self.loadStarted, self.shutting_down])
self.setHtml(error_page) if answer is not None:
authenticator.setUser(answer.user)
authenticator.setPassword(answer.password)
@pyqtSlot(QUrl, 'QWebEnginePage::Feature') @pyqtSlot(QUrl, 'QWebEnginePage::Feature')
def _on_feature_permission_requested(self, url, feature): def _on_feature_permission_requested(self, url, feature):