WebBrowser/Network/NetworkManager.py

branch
maintenance
changeset 5391
5e79ebb03b10
parent 5369
69705ef2a0af
parent 5389
9b1c800daff3
child 5730
6422afc7adc4
--- a/WebBrowser/Network/NetworkManager.py	Sat Dec 10 17:16:38 2016 +0100
+++ b/WebBrowser/Network/NetworkManager.py	Sat Dec 31 13:44:13 2016 +0100
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 
-# Copyright (c) 2016 Detlev Offenbach <detlev@die-offenbachs.de>
+# Copyright (c) 2016 - 2017 Detlev Offenbach <detlev@die-offenbachs.de>
 #
 
 """
@@ -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") and dlg.shallSave():
                 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