WebBrowser/Network/NetworkManager.py

changeset 5365
f0cb73e99e54
parent 4917
682750cc7bd5
child 5366
001edc0a0807
--- a/WebBrowser/Network/NetworkManager.py	Tue Dec 06 18:50:10 2016 +0100
+++ b/WebBrowser/Network/NetworkManager.py	Tue Dec 06 19:41:38 2016 +0100
@@ -12,9 +12,10 @@
 import json
 
 from PyQt5.QtCore import pyqtSignal, QByteArray
-from PyQt5.QtWidgets import QDialog
+from PyQt5.QtWidgets import qApp, QStyle, QDialog
 from PyQt5.QtNetwork import QNetworkAccessManager, QNetworkProxy, \
     QNetworkRequest
+from PyQt5.QtWebEngineWidgets import QWebEnginePage
 
 from E5Gui import E5MessageBox
 
@@ -27,6 +28,7 @@
 
 from WebBrowser.WebBrowserWindow import WebBrowserWindow
 from .NetworkUrlInterceptor import NetworkUrlInterceptor
+from ..Tools.WebBrowserTools import readAllFileContents, pixmapToDataUrl
 
 from Utilities.AutoSaver import AutoSaver
 import Preferences
@@ -244,6 +246,36 @@
             if Preferences.getUser("SavePasswords"):
                 WebBrowser.WebBrowserWindow.WebBrowserWindow.passwordManager()\
                     .setLogin(url, realm, username, password)
+        else:
+            page = self.sender()
+            if isinstance(page, QWebEnginePage):
+                self.__showAuthenticationErrorPage(page, url)
+    
+    def __showAuthenticationErrorPage(self, page, url):
+        """
+        Private method to show an authentication error page.
+        
+        @param page reference to the page
+        @type QWebEnginePage
+        @param url reference to the URL requesting authentication
+        @type QUrl
+        """
+        html = readAllFileContents(":/html/authenticationErrorPage.html")
+        html = html.replace("@IMAGE@", pixmapToDataUrl(
+            qApp.style().standardIcon(QStyle.SP_MessageBoxCritical).pixmap(
+                48, 48)).toString())
+        html = html.replace("@FAVICON@", pixmapToDataUrl(
+            qApp.style() .standardIcon(QStyle.SP_MessageBoxCritical).pixmap(
+                16, 16)).toString())
+        html = html.replace("@TITLE@", self.tr("Authentication required"))
+        html = html.replace("@H1@", self.tr("Authentication required"))
+        html = html.replace(
+            "@LI-1@",
+            self.tr("Authentication is required to access:"))
+        html = html.replace(
+            "@LI-2@",
+            '<a href="{0}">{0}</a>'.format(url.toString()))
+        page.setHtml(html, url)
     
     def proxyAuthentication(self, requestUrl, auth, proxyHost):
         """

eric ide

mercurial