WebBrowser/Network/NetworkManager.py

Sun, 03 Feb 2019 16:10:39 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 03 Feb 2019 16:10:39 +0100
changeset 6695
0a51887c13cd
parent 6645
ad476851d7e0
child 6646
51eefa621de4
child 6708
80fee080d9fe
permissions
-rw-r--r--

Web Browser (NG):
- added a site info widget that is show when the site icon in the URL entry is clicked
- added code to register custom protocol handlers (upon request of the user via the site info widget)

4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
6645
ad476851d7e0 Updated copyright for 2019.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6625
diff changeset
3 # Copyright (c) 2016 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a network manager class.
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
4726
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
10 from __future__ import unicode_literals
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
11
4817
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
12 import json
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
13
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4857
diff changeset
14 from PyQt5.QtCore import pyqtSignal, QByteArray
5365
f0cb73e99e54 Added an error page to be shown if an authentication request is cancelled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
15 from PyQt5.QtWidgets import qApp, QStyle, QDialog
4902
7a49807e493c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4886
diff changeset
16 from PyQt5.QtNetwork import QNetworkAccessManager, QNetworkProxy, \
5720
fc72c0c81a0f Fixed using the system proxy configuration in the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
17 QNetworkProxyFactory, QNetworkRequest
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 from E5Gui import E5MessageBox
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20
4743
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
21 from E5Network.E5NetworkProxyFactory import proxyAuthenticationRequired
4786
b149def67c6e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
22 try:
b149def67c6e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
23 from E5Network.E5SslErrorHandler import E5SslErrorHandler
b149def67c6e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
24 SSL_AVAILABLE = True
b149def67c6e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
25 except ImportError:
b149def67c6e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
26 SSL_AVAILABLE = False
4743
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
27
4758
c973eef8fef1 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4754
diff changeset
28 from WebBrowser.WebBrowserWindow import WebBrowserWindow
4857
8dba5fb92f12 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4845
diff changeset
29 from .NetworkUrlInterceptor import NetworkUrlInterceptor
5365
f0cb73e99e54 Added an error page to be shown if an authentication request is cancelled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
30 from ..Tools.WebBrowserTools import readAllFileContents, pixmapToDataUrl
4758
c973eef8fef1 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4754
diff changeset
31
4817
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
32 from Utilities.AutoSaver import AutoSaver
4743
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
33 import Preferences
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
34
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 class NetworkManager(QNetworkAccessManager):
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 """
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 Class implementing a network manager.
4817
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
39
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
40 @signal changed() emitted to indicate a change
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 """
4817
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
42 changed = pyqtSignal()
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
43
4875
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
44 def __init__(self, engine, parent=None):
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 """
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 Constructor
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47
4875
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
48 @param engine reference to the help engine (QHelpEngine)
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 @param parent reference to the parent object (QObject)
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 """
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 super(NetworkManager, self).__init__(parent)
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52
6625
a67fee7bc09c Web Browser: changed the web browser logic inside eric to use a remote controlled web browser process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6555
diff changeset
53 from E5Network.E5NetworkProxyFactory import E5NetworkProxyFactory
a67fee7bc09c Web Browser: changed the web browser logic inside eric to use a remote controlled web browser process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6555
diff changeset
54
a67fee7bc09c Web Browser: changed the web browser logic inside eric to use a remote controlled web browser process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6555
diff changeset
55 self.__proxyFactory = E5NetworkProxyFactory()
a67fee7bc09c Web Browser: changed the web browser logic inside eric to use a remote controlled web browser process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6555
diff changeset
56 if Preferences.getUI("UseSystemProxy"):
a67fee7bc09c Web Browser: changed the web browser logic inside eric to use a remote controlled web browser process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6555
diff changeset
57 QNetworkProxyFactory.setUseSystemConfiguration(True)
a67fee7bc09c Web Browser: changed the web browser logic inside eric to use a remote controlled web browser process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6555
diff changeset
58 else:
a67fee7bc09c Web Browser: changed the web browser logic inside eric to use a remote controlled web browser process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6555
diff changeset
59 QNetworkProxyFactory.setApplicationProxyFactory(
a67fee7bc09c Web Browser: changed the web browser logic inside eric to use a remote controlled web browser process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6555
diff changeset
60 self.__proxyFactory)
a67fee7bc09c Web Browser: changed the web browser logic inside eric to use a remote controlled web browser process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6555
diff changeset
61 QNetworkProxyFactory.setUseSystemConfiguration(False)
4758
c973eef8fef1 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4754
diff changeset
62
4754
1ff6d0ecb2fd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4745
diff changeset
63 self.languagesChanged()
1ff6d0ecb2fd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4745
diff changeset
64
4786
b149def67c6e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
65 if SSL_AVAILABLE:
b149def67c6e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
66 self.__sslErrorHandler = E5SslErrorHandler(self)
b149def67c6e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
67 self.sslErrors.connect(self.__sslErrorHandler.sslErrorsReplySlot)
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68
4817
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
69 self.__temporarilyIgnoredSslErrors = {}
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
70 self.__permanentlyIgnoredSslErrors = {}
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
71 # dictionaries of permanently and temporarily ignored SSL errors
4786
b149def67c6e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
72
4817
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
73 self.__loaded = False
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
74 self.__saveTimer = AutoSaver(self, self.__save)
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
75
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
76 self.changed.connect(self.__saveTimer.changeOccurred)
4786
b149def67c6e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
77 self.proxyAuthenticationRequired.connect(proxyAuthenticationRequired)
4743
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
78 self.authenticationRequired.connect(
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
79 lambda reply, auth: self.authentication(reply.url(), auth))
4825
b5fb58f3830b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4820
diff changeset
80
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4857
diff changeset
81 from .EricSchemeHandler import EricSchemeHandler
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4857
diff changeset
82 self.__ericSchemeHandler = EricSchemeHandler()
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4857
diff changeset
83 WebBrowserWindow.webProfile().installUrlSchemeHandler(
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4857
diff changeset
84 QByteArray(b"eric"), self.__ericSchemeHandler)
4825
b5fb58f3830b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4820
diff changeset
85
4875
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
86 if engine:
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
87 from .QtHelpSchemeHandler import QtHelpSchemeHandler
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
88 self.__qtHelpSchemeHandler = QtHelpSchemeHandler(engine)
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
89 WebBrowserWindow.webProfile().installUrlSchemeHandler(
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
90 QByteArray(b"qthelp"), self.__qtHelpSchemeHandler)
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
91
4857
8dba5fb92f12 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4845
diff changeset
92 self.__interceptor = NetworkUrlInterceptor(self)
8dba5fb92f12 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4845
diff changeset
93 WebBrowserWindow.webProfile().setRequestInterceptor(self.__interceptor)
4825
b5fb58f3830b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4820
diff changeset
94
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4827
diff changeset
95 WebBrowserWindow.cookieJar()
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96
4817
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
97 def __save(self):
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
98 """
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
99 Private slot to save the permanent SSL error exceptions.
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
100 """
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
101 if not self.__loaded:
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
102 return
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
103
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
104 from WebBrowser.WebBrowserWindow import WebBrowserWindow
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
105 if not WebBrowserWindow.isPrivate():
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
106 dbString = json.dumps(self.__permanentlyIgnoredSslErrors)
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
107 Preferences.setWebBrowser("SslExceptionsDB", dbString)
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
108
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
109 def __load(self):
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
110 """
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
111 Private method to load the permanent SSL error exceptions.
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
112 """
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
113 if self.__loaded:
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
114 return
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
115
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
116 dbString = Preferences.getWebBrowser("SslExceptionsDB")
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
117 if dbString:
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
118 try:
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
119 db = json.loads(dbString)
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
120 self.__permanentlyIgnoredSslErrors = db
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
121 except ValueError:
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
122 # ignore silently
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
123 pass
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
124
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
125 self.__loaded = True
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
126
4820
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4819
diff changeset
127 def shutdown(self):
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4819
diff changeset
128 """
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4819
diff changeset
129 Public method to shut down the network manager.
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4819
diff changeset
130 """
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4819
diff changeset
131 self.__saveTimer.saveIfNeccessary()
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4819
diff changeset
132 self.__loaded = False
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4819
diff changeset
133 self.__temporarilyIgnoredSslErrors = {}
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4819
diff changeset
134 self.__permanentlyIgnoredSslErrors = {}
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4819
diff changeset
135
4817
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
136 def showSslErrorExceptionsDialog(self):
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
137 """
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
138 Public method to show the SSL error exceptions dialog.
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
139 """
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
140 self.__load()
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
141
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
142 from .SslErrorExceptionsDialog import SslErrorExceptionsDialog
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
143 dlg = SslErrorExceptionsDialog(self.__permanentlyIgnoredSslErrors)
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
144 if dlg.exec_() == QDialog.Accepted:
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
145 self.__permanentlyIgnoredSslErrors = dlg.getSslErrorExceptions()
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
146 self.changed.emit()
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
147
4819
cb0672f0fc15 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4817
diff changeset
148 def clearSslExceptions(self):
cb0672f0fc15 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4817
diff changeset
149 """
cb0672f0fc15 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4817
diff changeset
150 Public method to clear the permanent SSL certificate error exceptions.
cb0672f0fc15 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4817
diff changeset
151 """
cb0672f0fc15 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4817
diff changeset
152 self.__load()
cb0672f0fc15 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4817
diff changeset
153
cb0672f0fc15 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4817
diff changeset
154 self.__permanentlyIgnoredSslErrors = {}
cb0672f0fc15 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4817
diff changeset
155 self.changed.emit()
4820
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4819
diff changeset
156 self.__saveTimer.saveIfNeccessary()
4819
cb0672f0fc15 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4817
diff changeset
157
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 def certificateError(self, error, view):
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 """
4726
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
160 Public method to handle SSL certificate errors.
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 @param error object containing the certificate error information
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 @type QWebEngineCertificateError
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 @param view reference to a view to be used as parent for the dialog
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 @type QWidget
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 @return flag indicating to ignore this error
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 @rtype bool
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 """
4817
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
169 self.__load()
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
170
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 host = error.url().host()
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172
4817
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
173 if host in self.__temporarilyIgnoredSslErrors and \
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
174 error.error() in self.__temporarilyIgnoredSslErrors[host]:
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
175 return True
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
176
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
177 if host in self.__permanentlyIgnoredSslErrors and \
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
178 error.error() in self.__permanentlyIgnoredSslErrors[host]:
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 return True
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 title = self.tr("SSL Certificate Error")
4817
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
182 msgBox = E5MessageBox.E5MessageBox(
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
183 E5MessageBox.Warning,
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 title,
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185 self.tr("""<b>{0}</b>"""
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 """<p>The page you are trying to access has errors"""
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 """ in the SSL certificate.</p>"""
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 """<ul><li>{1}</li></ul>"""
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189 """<p>Would you like to make an exception?</p>""")
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190 .format(title, error.errorDescription()),
4817
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
191 modal=True, parent=view)
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
192 permButton = msgBox.addButton(self.tr("&Permanent accept"),
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
193 E5MessageBox.AcceptRole)
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
194 tempButton = msgBox.addButton(self.tr("&Temporary accept"),
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
195 E5MessageBox.AcceptRole)
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
196 msgBox.addButton(self.tr("&Reject"), E5MessageBox.RejectRole)
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
197 msgBox.exec_()
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
198 if msgBox.clickedButton() == permButton:
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
199 if host not in self.__permanentlyIgnoredSslErrors:
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
200 self.__permanentlyIgnoredSslErrors[host] = []
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
201 self.__permanentlyIgnoredSslErrors[host].append(error.error())
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
202 self.changed.emit()
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203 return True
4817
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
204 elif msgBox.clickedButton() == tempButton:
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
205 if host not in self.__temporarilyIgnoredSslErrors:
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
206 self.__temporarilyIgnoredSslErrors[host] = []
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
207 self.__temporarilyIgnoredSslErrors[host].append(error.error())
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
208 return True
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
209 else:
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
210 return False
4743
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
211
6120
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
212 def authentication(self, url, auth, page=None):
4743
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
213 """
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
214 Public slot to handle an authentication request.
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
215
6120
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
216 @param url URL requesting authentication
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
217 @type QUrl
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
218 @param auth reference to the authenticator object
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
219 @type QAuthenticator
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
220 @param page reference to the web page
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
221 @type QWebEnginePage or None
4743
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
222 """
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
223 urlRoot = "{0}://{1}"\
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
224 .format(url.scheme(), url.authority())
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
225 realm = auth.realm()
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
226 if not realm and 'realm' in auth.options():
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
227 realm = auth.option("realm")
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
228 if realm:
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
229 info = self.tr("<b>Enter username and password for '{0}', "
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
230 "realm '{1}'</b>").format(urlRoot, realm)
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
231 else:
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
232 info = self.tr("<b>Enter username and password for '{0}'</b>")\
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
233 .format(urlRoot)
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
234
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
235 from UI.AuthenticationDialog import AuthenticationDialog
4745
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4743
diff changeset
236 import WebBrowser.WebBrowserWindow
4743
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
237
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
238 dlg = AuthenticationDialog(info, auth.user(),
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
239 Preferences.getUser("SavePasswords"),
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
240 Preferences.getUser("SavePasswords"))
4745
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4743
diff changeset
241 if Preferences.getUser("SavePasswords"):
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4743
diff changeset
242 username, password = \
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4743
diff changeset
243 WebBrowser.WebBrowserWindow.WebBrowserWindow.passwordManager()\
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4743
diff changeset
244 .getLogin(url, realm)
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4743
diff changeset
245 if username:
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4743
diff changeset
246 dlg.setData(username, password)
4743
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
247 if dlg.exec_() == QDialog.Accepted:
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
248 username, password = dlg.getData()
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
249 auth.setUser(username)
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
250 auth.setPassword(password)
5366
001edc0a0807 Fixed a little issue using the authentication dialog from the old and new web browsers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5365
diff changeset
251 if Preferences.getUser("SavePasswords") and dlg.shallSave():
4745
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4743
diff changeset
252 WebBrowser.WebBrowserWindow.WebBrowserWindow.passwordManager()\
4917
682750cc7bd5 Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4902
diff changeset
253 .setLogin(url, realm, username, password)
5365
f0cb73e99e54 Added an error page to be shown if an authentication request is cancelled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
254 else:
6120
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
255 if page is not None:
5365
f0cb73e99e54 Added an error page to be shown if an authentication request is cancelled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
256 self.__showAuthenticationErrorPage(page, url)
f0cb73e99e54 Added an error page to be shown if an authentication request is cancelled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
257
f0cb73e99e54 Added an error page to be shown if an authentication request is cancelled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
258 def __showAuthenticationErrorPage(self, page, url):
f0cb73e99e54 Added an error page to be shown if an authentication request is cancelled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
259 """
f0cb73e99e54 Added an error page to be shown if an authentication request is cancelled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
260 Private method to show an authentication error page.
f0cb73e99e54 Added an error page to be shown if an authentication request is cancelled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
261
f0cb73e99e54 Added an error page to be shown if an authentication request is cancelled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
262 @param page reference to the page
f0cb73e99e54 Added an error page to be shown if an authentication request is cancelled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
263 @type QWebEnginePage
f0cb73e99e54 Added an error page to be shown if an authentication request is cancelled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
264 @param url reference to the URL requesting authentication
f0cb73e99e54 Added an error page to be shown if an authentication request is cancelled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
265 @type QUrl
f0cb73e99e54 Added an error page to be shown if an authentication request is cancelled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
266 """
f0cb73e99e54 Added an error page to be shown if an authentication request is cancelled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
267 html = readAllFileContents(":/html/authenticationErrorPage.html")
f0cb73e99e54 Added an error page to be shown if an authentication request is cancelled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
268 html = html.replace("@IMAGE@", pixmapToDataUrl(
f0cb73e99e54 Added an error page to be shown if an authentication request is cancelled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
269 qApp.style().standardIcon(QStyle.SP_MessageBoxCritical).pixmap(
f0cb73e99e54 Added an error page to be shown if an authentication request is cancelled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
270 48, 48)).toString())
f0cb73e99e54 Added an error page to be shown if an authentication request is cancelled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
271 html = html.replace("@FAVICON@", pixmapToDataUrl(
f0cb73e99e54 Added an error page to be shown if an authentication request is cancelled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
272 qApp.style() .standardIcon(QStyle.SP_MessageBoxCritical).pixmap(
f0cb73e99e54 Added an error page to be shown if an authentication request is cancelled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
273 16, 16)).toString())
f0cb73e99e54 Added an error page to be shown if an authentication request is cancelled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
274 html = html.replace("@TITLE@", self.tr("Authentication required"))
f0cb73e99e54 Added an error page to be shown if an authentication request is cancelled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
275 html = html.replace("@H1@", self.tr("Authentication required"))
f0cb73e99e54 Added an error page to be shown if an authentication request is cancelled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
276 html = html.replace(
f0cb73e99e54 Added an error page to be shown if an authentication request is cancelled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
277 "@LI-1@",
f0cb73e99e54 Added an error page to be shown if an authentication request is cancelled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
278 self.tr("Authentication is required to access:"))
f0cb73e99e54 Added an error page to be shown if an authentication request is cancelled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
279 html = html.replace(
f0cb73e99e54 Added an error page to be shown if an authentication request is cancelled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
280 "@LI-2@",
f0cb73e99e54 Added an error page to be shown if an authentication request is cancelled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
281 '<a href="{0}">{0}</a>'.format(url.toString()))
f0cb73e99e54 Added an error page to be shown if an authentication request is cancelled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
282 page.setHtml(html, url)
4743
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
283
4786
b149def67c6e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
284 def proxyAuthentication(self, requestUrl, auth, proxyHost):
4743
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
285 """
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
286 Public slot to handle a proxy authentication request.
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
287
4786
b149def67c6e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
288 @param requestUrl requested URL
b149def67c6e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
289 @type QUrl
b149def67c6e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
290 @param auth reference to the authenticator object
b149def67c6e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
291 @type QAuthenticator
4917
682750cc7bd5 Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4902
diff changeset
292 @param proxyHost name of the proxy host
4743
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
293 @type str
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
294 """
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
295 proxy = QNetworkProxy.applicationProxy()
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
296 if proxy.user() and proxy.password():
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
297 auth.setUser(proxy.user())
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
298 auth.setPassword(proxy.password())
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
299 return
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
300
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
301 proxyAuthenticationRequired(proxy, auth)
4754
1ff6d0ecb2fd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4745
diff changeset
302
1ff6d0ecb2fd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4745
diff changeset
303 def languagesChanged(self):
1ff6d0ecb2fd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4745
diff changeset
304 """
1ff6d0ecb2fd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4745
diff changeset
305 Public slot to (re-)load the list of accepted languages.
1ff6d0ecb2fd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4745
diff changeset
306 """
1ff6d0ecb2fd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4745
diff changeset
307 from WebBrowser.WebBrowserLanguagesDialog import \
1ff6d0ecb2fd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4745
diff changeset
308 WebBrowserLanguagesDialog
1ff6d0ecb2fd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4745
diff changeset
309 languages = Preferences.toList(
1ff6d0ecb2fd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4745
diff changeset
310 Preferences.Prefs.settings.value(
1ff6d0ecb2fd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4745
diff changeset
311 "WebBrowser/AcceptLanguages",
1ff6d0ecb2fd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4745
diff changeset
312 WebBrowserLanguagesDialog.defaultAcceptLanguages()))
1ff6d0ecb2fd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4745
diff changeset
313 self.__acceptLanguage = WebBrowserLanguagesDialog.httpString(languages)
1ff6d0ecb2fd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4745
diff changeset
314
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4857
diff changeset
315 WebBrowserWindow.webProfile().setHttpAcceptLanguage(
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4857
diff changeset
316 self.__acceptLanguage)
4766
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4758
diff changeset
317
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4758
diff changeset
318 def installUrlInterceptor(self, interceptor):
4825
b5fb58f3830b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4820
diff changeset
319 """
b5fb58f3830b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4820
diff changeset
320 Public method to install an URL interceptor.
b5fb58f3830b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4820
diff changeset
321
b5fb58f3830b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4820
diff changeset
322 @param interceptor URL interceptor to be installed
b5fb58f3830b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4820
diff changeset
323 @type UrlInterceptor
b5fb58f3830b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4820
diff changeset
324 """
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4857
diff changeset
325 self.__interceptor.installUrlInterceptor(interceptor)
4766
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4758
diff changeset
326
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4758
diff changeset
327 def removeUrlInterceptor(self, interceptor):
4825
b5fb58f3830b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4820
diff changeset
328 """
b5fb58f3830b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4820
diff changeset
329 Public method to remove an URL interceptor.
b5fb58f3830b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4820
diff changeset
330
b5fb58f3830b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4820
diff changeset
331 @param interceptor URL interceptor to be removed
b5fb58f3830b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4820
diff changeset
332 @type UrlInterceptor
b5fb58f3830b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4820
diff changeset
333 """
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4857
diff changeset
334 self.__interceptor.removeUrlInterceptor(interceptor)
4825
b5fb58f3830b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4820
diff changeset
335
b5fb58f3830b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4820
diff changeset
336 def preferencesChanged(self):
b5fb58f3830b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4820
diff changeset
337 """
b5fb58f3830b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4820
diff changeset
338 Public slot to handle a change of preferences.
b5fb58f3830b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4820
diff changeset
339 """
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4857
diff changeset
340 self.__interceptor.preferencesChanged()
5720
fc72c0c81a0f Fixed using the system proxy configuration in the web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
341
6625
a67fee7bc09c Web Browser: changed the web browser logic inside eric to use a remote controlled web browser process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6555
diff changeset
342 if Preferences.getUI("UseSystemProxy"):
a67fee7bc09c Web Browser: changed the web browser logic inside eric to use a remote controlled web browser process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6555
diff changeset
343 QNetworkProxyFactory.setUseSystemConfiguration(True)
a67fee7bc09c Web Browser: changed the web browser logic inside eric to use a remote controlled web browser process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6555
diff changeset
344 else:
a67fee7bc09c Web Browser: changed the web browser logic inside eric to use a remote controlled web browser process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6555
diff changeset
345 QNetworkProxyFactory.setApplicationProxyFactory(
a67fee7bc09c Web Browser: changed the web browser logic inside eric to use a remote controlled web browser process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6555
diff changeset
346 self.__proxyFactory)
a67fee7bc09c Web Browser: changed the web browser logic inside eric to use a remote controlled web browser process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6555
diff changeset
347 QNetworkProxyFactory.setUseSystemConfiguration(False)
4902
7a49807e493c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4886
diff changeset
348
7a49807e493c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4886
diff changeset
349 def createRequest(self, op, request, data):
7a49807e493c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4886
diff changeset
350 """
7a49807e493c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4886
diff changeset
351 Public method to launch a network action.
7a49807e493c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4886
diff changeset
352
7a49807e493c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4886
diff changeset
353 @param op operation to be performed
7a49807e493c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4886
diff changeset
354 @type QNetworkAccessManager.Operation
7a49807e493c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4886
diff changeset
355 @param request request to be operated on
7a49807e493c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4886
diff changeset
356 @type QNetworkRequest
7a49807e493c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4886
diff changeset
357 @param data reference to the data to be sent
7a49807e493c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4886
diff changeset
358 @type QIODevice
7a49807e493c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4886
diff changeset
359 @return reference to the network reply
7a49807e493c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4886
diff changeset
360 @rtype QNetworkReply
7a49807e493c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4886
diff changeset
361 """
7a49807e493c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4886
diff changeset
362 req = QNetworkRequest(request)
7a49807e493c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4886
diff changeset
363 req.setAttribute(QNetworkRequest.SpdyAllowedAttribute, True)
7a49807e493c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4886
diff changeset
364 req.setAttribute(QNetworkRequest.FollowRedirectsAttribute, True)
7a49807e493c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4886
diff changeset
365
7a49807e493c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4886
diff changeset
366 return super(NetworkManager, self).createRequest(op, req, data)

eric ide

mercurial