src/eric7/WebBrowser/Network/NetworkManager.py

Fri, 04 Nov 2022 13:52:26 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Fri, 04 Nov 2022 13:52:26 +0100
branch
eric7
changeset 9473
3f23dbf37dbe
parent 9470
34f2493c1d3f
child 9482
a2bc06a54d9d
permissions
-rw-r--r--

Resorted the import statements using isort.

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
8881
54e42bc2437a Updated copyright for 2022.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8637
diff changeset
3 # Copyright (c) 2016 - 2022 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
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9470
diff changeset
10 import contextlib
4817
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
11 import json
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
12
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9470
diff changeset
13 from PyQt6.QtCore import QByteArray, pyqtSignal
8318
962bce857696 Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8312
diff changeset
14 from PyQt6.QtNetwork import (
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
15 QNetworkAccessManager,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
16 QNetworkProxy,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
17 QNetworkProxyFactory,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
18 QNetworkRequest,
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
19 )
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9470
diff changeset
20 from PyQt6.QtWidgets import QDialog, QStyle
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9470
diff changeset
22 from eric7 import Preferences
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9470
diff changeset
23 from eric7.EricNetwork.EricNetworkProxyFactory import proxyAuthenticationRequired
9413
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
24 from eric7.EricWidgets import EricMessageBox
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
25 from eric7.EricWidgets.EricApplication import ericApp
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9470
diff changeset
26 from eric7.Utilities.AutoSaver import AutoSaver
9470
34f2493c1d3f Prepared the code for isort imports reordering.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
27 from eric7.WebBrowser.WebBrowserWindow import WebBrowserWindow
34f2493c1d3f Prepared the code for isort imports reordering.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
28
4786
b149def67c6e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
29 try:
9413
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
30 from eric7.EricNetwork.EricSslErrorHandler import EricSslErrorHandler
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
31
4786
b149def67c6e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
32 SSL_AVAILABLE = True
b149def67c6e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
33 except ImportError:
b149def67c6e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
34 SSL_AVAILABLE = False
4743
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
35
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9470
diff changeset
36 from ..Tools.WebBrowserTools import getHtmlPage, pixmapToDataUrl
4857
8dba5fb92f12 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4845
diff changeset
37 from .NetworkUrlInterceptor import NetworkUrlInterceptor
4758
c973eef8fef1 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4754
diff changeset
38
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 class NetworkManager(QNetworkAccessManager):
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 """
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 Class implementing a network manager.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
43
4817
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
44 @signal changed() emitted to indicate a change
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
46
4817
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
47 changed = pyqtSignal()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
48
4875
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
49 def __init__(self, engine, parent=None):
4725
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 Constructor
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
52
4875
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
53 @param engine reference to the help engine (QHelpEngine)
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 @param parent reference to the parent object (QObject)
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 """
8218
7c09585bd960 Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8143
diff changeset
56 super().__init__(parent)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
57
9413
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
58 from eric7.EricNetwork.EricNetworkProxyFactory import EricNetworkProxyFactory
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
59
8354
12ebd3934fef Renamed 'E5Utilities' to 'EricUtilities' and 'E5Network' to 'EricNetwork'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
60 self.__proxyFactory = EricNetworkProxyFactory()
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
61 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
62 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
63 else:
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
64 QNetworkProxyFactory.setApplicationProxyFactory(self.__proxyFactory)
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
65 QNetworkProxyFactory.setUseSystemConfiguration(False)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
66
4754
1ff6d0ecb2fd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4745
diff changeset
67 self.languagesChanged()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
68
4786
b149def67c6e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
69 if SSL_AVAILABLE:
8354
12ebd3934fef Renamed 'E5Utilities' to 'EricUtilities' and 'E5Network' to 'EricNetwork'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
70 self.__sslErrorHandler = EricSslErrorHandler(self)
7570
a7a5750aded4 Web Browser: made the URL entry background configurable and harmonized certificate handling for the web page and its web icon (favicon).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7565
diff changeset
71 self.sslErrors.connect(self.__sslErrorHandlingSlot)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
72
4817
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
73 self.__temporarilyIgnoredSslErrors = {}
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
74 self.__permanentlyIgnoredSslErrors = {}
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
75 # dictionaries of permanently and temporarily ignored SSL errors
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
76
7565
928373562e36 Implemented a preliminary fix for issue 328 showing the user an indication, if he made an exception for a certificate issue of a host.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
77 self.__insecureHosts = set()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
78
4817
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
79 self.__loaded = False
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
80 self.__saveTimer = AutoSaver(self, self.__save)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
81
4817
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
82 self.changed.connect(self.__saveTimer.changeOccurred)
4786
b149def67c6e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
83 self.proxyAuthenticationRequired.connect(proxyAuthenticationRequired)
4743
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
84 self.authenticationRequired.connect(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
85 lambda reply, auth: self.authentication(reply.url(), auth)
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
86 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
87
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4857
diff changeset
88 from .EricSchemeHandler import EricSchemeHandler
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
89
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4857
diff changeset
90 self.__ericSchemeHandler = EricSchemeHandler()
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4857
diff changeset
91 WebBrowserWindow.webProfile().installUrlSchemeHandler(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
92 QByteArray(b"eric"), self.__ericSchemeHandler
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
93 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
94
4875
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
95 if engine:
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
96 from .QtHelpSchemeHandler import QtHelpSchemeHandler
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
97
4875
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
98 self.__qtHelpSchemeHandler = QtHelpSchemeHandler(engine)
4ee26909ac0d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
99 WebBrowserWindow.webProfile().installUrlSchemeHandler(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
100 QByteArray(b"qthelp"), self.__qtHelpSchemeHandler
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
101 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
102
4857
8dba5fb92f12 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4845
diff changeset
103 self.__interceptor = NetworkUrlInterceptor(self)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
104 WebBrowserWindow.webProfile().setUrlRequestInterceptor(self.__interceptor)
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
105
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4827
diff changeset
106 WebBrowserWindow.cookieJar()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
107
4817
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
108 def __save(self):
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
109 """
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
110 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
111 """
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
112 if not self.__loaded:
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
113 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
114
9413
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
115 from eric7.WebBrowser.WebBrowserWindow import WebBrowserWindow
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
116
4817
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
117 if not WebBrowserWindow.isPrivate():
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
118 dbString = json.dumps(self.__permanentlyIgnoredSslErrors)
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
119 Preferences.setWebBrowser("SslExceptionsDB", dbString)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
120
4817
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
121 def __load(self):
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
122 """
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
123 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
124 """
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
125 if self.__loaded:
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
126 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
127
4817
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
128 dbString = Preferences.getWebBrowser("SslExceptionsDB")
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
129 if dbString:
8243
cc717c2ae956 Applied some more code simplifications suggested by the new Simplify checker (Y105: use contextlib.suppress) (batch 2).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8218
diff changeset
130 with contextlib.suppress(ValueError):
4817
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
131 db = json.loads(dbString)
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
132 self.__permanentlyIgnoredSslErrors = db
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
133
4817
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
134 self.__loaded = True
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
135
4820
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4819
diff changeset
136 def shutdown(self):
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4819
diff changeset
137 """
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4819
diff changeset
138 Public method to shut down the network manager.
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4819
diff changeset
139 """
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4819
diff changeset
140 self.__saveTimer.saveIfNeccessary()
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4819
diff changeset
141 self.__loaded = False
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4819
diff changeset
142 self.__temporarilyIgnoredSslErrors = {}
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4819
diff changeset
143 self.__permanentlyIgnoredSslErrors = {}
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
144
6708
80fee080d9fe UserInterface, WebBrowser.Network.NetworkManager: added some shutdown code to prevent crashes related to QNetworkProxyFactory on shutdown.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
145 # set proxy factory to None to avoid crashes
80fee080d9fe UserInterface, WebBrowser.Network.NetworkManager: added some shutdown code to prevent crashes related to QNetworkProxyFactory on shutdown.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
146 QNetworkProxyFactory.setApplicationProxyFactory(None)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
147
4817
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
148 def showSslErrorExceptionsDialog(self):
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
149 """
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
150 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
151 """
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
152 self.__load()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
153
4817
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
154 from .SslErrorExceptionsDialog import SslErrorExceptionsDialog
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
155
4817
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
156 dlg = SslErrorExceptionsDialog(self.__permanentlyIgnoredSslErrors)
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
157 if dlg.exec() == QDialog.DialogCode.Accepted:
4817
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
158 self.__permanentlyIgnoredSslErrors = dlg.getSslErrorExceptions()
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
159 self.changed.emit()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
160
4819
cb0672f0fc15 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4817
diff changeset
161 def clearSslExceptions(self):
cb0672f0fc15 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4817
diff changeset
162 """
cb0672f0fc15 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4817
diff changeset
163 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
164 """
cb0672f0fc15 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4817
diff changeset
165 self.__load()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
166
4819
cb0672f0fc15 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4817
diff changeset
167 self.__permanentlyIgnoredSslErrors = {}
cb0672f0fc15 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4817
diff changeset
168 self.changed.emit()
4820
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4819
diff changeset
169 self.__saveTimer.saveIfNeccessary()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
170
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 def certificateError(self, error, view):
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172 """
4726
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
173 Public method to handle SSL certificate errors.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
174
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175 @param error object containing the certificate error information
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176 @type QWebEngineCertificateError
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177 @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
178 @type QWidget
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 @return flag indicating to ignore this error
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180 @rtype bool
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 """
7570
a7a5750aded4 Web Browser: made the URL entry background configurable and harmonized certificate handling for the web page and its web icon (favicon).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7565
diff changeset
182 if Preferences.getWebBrowser("AlwaysRejectFaultyCertificates"):
a7a5750aded4 Web Browser: made the URL entry background configurable and harmonized certificate handling for the web page and its web icon (favicon).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7565
diff changeset
183 return False
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
184
4817
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
185 self.__load()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
186
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 host = error.url().host()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
188
7565
928373562e36 Implemented a preliminary fix for issue 328 showing the user an indication, if he made an exception for a certificate issue of a host.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
189 self.__insecureHosts.add(host)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
190
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
191 if (
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
192 host in self.__temporarilyIgnoredSslErrors
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
193 and error.error() in self.__temporarilyIgnoredSslErrors[host]
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
194 ):
4817
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
195 return True
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
196
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
197 if (
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
198 host in self.__permanentlyIgnoredSslErrors
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
199 and error.error() in self.__permanentlyIgnoredSslErrors[host]
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
200 ):
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
201 return True
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
202
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203 title = self.tr("SSL Certificate Error")
8356
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8354
diff changeset
204 msgBox = EricMessageBox.EricMessageBox(
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8354
diff changeset
205 EricMessageBox.Warning,
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
206 title,
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
207 self.tr(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
208 """<b>{0}</b>"""
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
209 """<p>The host <b>{1}</b> you are trying to access has"""
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
210 """ errors in the SSL certificate.</p>"""
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
211 """<ul><li>{2}</li></ul>"""
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
212 """<p>Would you like to make an exception?</p>"""
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
213 ).format(title, host, error.errorDescription()),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
214 modal=True,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
215 parent=view,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
216 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
217 permButton = msgBox.addButton(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
218 self.tr("&Permanent accept"), EricMessageBox.AcceptRole
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
219 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
220 tempButton = msgBox.addButton(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
221 self.tr("&Temporary accept"), EricMessageBox.AcceptRole
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
222 )
8356
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8354
diff changeset
223 msgBox.addButton(self.tr("&Reject"), EricMessageBox.RejectRole)
7759
51aa6c6b66f7 Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7717
diff changeset
224 msgBox.exec()
4817
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
225 if msgBox.clickedButton() == permButton:
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
226 if host not in self.__permanentlyIgnoredSslErrors:
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
227 self.__permanentlyIgnoredSslErrors[host] = []
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
228 self.__permanentlyIgnoredSslErrors[host].append(error.error())
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
229 self.changed.emit()
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
230 return True
4817
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
231 elif msgBox.clickedButton() == tempButton:
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
232 if host not in self.__temporarilyIgnoredSslErrors:
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
233 self.__temporarilyIgnoredSslErrors[host] = []
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
234 self.__temporarilyIgnoredSslErrors[host].append(error.error())
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
235 return True
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
236 else:
0a4e2fb0e93c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4786
diff changeset
237 return False
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
238
7570
a7a5750aded4 Web Browser: made the URL entry background configurable and harmonized certificate handling for the web page and its web icon (favicon).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7565
diff changeset
239 def __sslErrorHandlingSlot(self, reply, errors):
a7a5750aded4 Web Browser: made the URL entry background configurable and harmonized certificate handling for the web page and its web icon (favicon).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7565
diff changeset
240 """
a7a5750aded4 Web Browser: made the URL entry background configurable and harmonized certificate handling for the web page and its web icon (favicon).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7565
diff changeset
241 Private slot to handle SSL errors for a network reply.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
242
7570
a7a5750aded4 Web Browser: made the URL entry background configurable and harmonized certificate handling for the web page and its web icon (favicon).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7565
diff changeset
243 @param reply reference to the reply object
a7a5750aded4 Web Browser: made the URL entry background configurable and harmonized certificate handling for the web page and its web icon (favicon).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7565
diff changeset
244 @type QNetworkReply
a7a5750aded4 Web Browser: made the URL entry background configurable and harmonized certificate handling for the web page and its web icon (favicon).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7565
diff changeset
245 @param errors list of SSL errors
a7a5750aded4 Web Browser: made the URL entry background configurable and harmonized certificate handling for the web page and its web icon (favicon).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7565
diff changeset
246 @type list of QSslError
a7a5750aded4 Web Browser: made the URL entry background configurable and harmonized certificate handling for the web page and its web icon (favicon).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7565
diff changeset
247 """
a7a5750aded4 Web Browser: made the URL entry background configurable and harmonized certificate handling for the web page and its web icon (favicon).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7565
diff changeset
248 if Preferences.getWebBrowser("AlwaysRejectFaultyCertificates"):
a7a5750aded4 Web Browser: made the URL entry background configurable and harmonized certificate handling for the web page and its web icon (favicon).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7565
diff changeset
249 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
250
7570
a7a5750aded4 Web Browser: made the URL entry background configurable and harmonized certificate handling for the web page and its web icon (favicon).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7565
diff changeset
251 self.__load()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
252
7570
a7a5750aded4 Web Browser: made the URL entry background configurable and harmonized certificate handling for the web page and its web icon (favicon).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7565
diff changeset
253 host = reply.url().host()
a7a5750aded4 Web Browser: made the URL entry background configurable and harmonized certificate handling for the web page and its web icon (favicon).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7565
diff changeset
254 if (
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
255 host in self.__permanentlyIgnoredSslErrors
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
256 or host in self.__temporarilyIgnoredSslErrors
7570
a7a5750aded4 Web Browser: made the URL entry background configurable and harmonized certificate handling for the web page and its web icon (favicon).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7565
diff changeset
257 ):
a7a5750aded4 Web Browser: made the URL entry background configurable and harmonized certificate handling for the web page and its web icon (favicon).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7565
diff changeset
258 reply.ignoreSslErrors()
a7a5750aded4 Web Browser: made the URL entry background configurable and harmonized certificate handling for the web page and its web icon (favicon).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7565
diff changeset
259 else:
a7a5750aded4 Web Browser: made the URL entry background configurable and harmonized certificate handling for the web page and its web icon (favicon).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7565
diff changeset
260 self.__sslErrorHandler.sslErrorsReply(reply, errors)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
261
7565
928373562e36 Implemented a preliminary fix for issue 328 showing the user an indication, if he made an exception for a certificate issue of a host.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
262 def isInsecureHost(self, host):
928373562e36 Implemented a preliminary fix for issue 328 showing the user an indication, if he made an exception for a certificate issue of a host.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
263 """
928373562e36 Implemented a preliminary fix for issue 328 showing the user an indication, if he made an exception for a certificate issue of a host.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
264 Public method to check a host against the list of insecure hosts.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
265
7570
a7a5750aded4 Web Browser: made the URL entry background configurable and harmonized certificate handling for the web page and its web icon (favicon).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7565
diff changeset
266 @param host name of the host to be checked
a7a5750aded4 Web Browser: made the URL entry background configurable and harmonized certificate handling for the web page and its web icon (favicon).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7565
diff changeset
267 @type str
7565
928373562e36 Implemented a preliminary fix for issue 328 showing the user an indication, if he made an exception for a certificate issue of a host.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
268 @return flag indicating an insecure host
928373562e36 Implemented a preliminary fix for issue 328 showing the user an indication, if he made an exception for a certificate issue of a host.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
269 @rtype bool
928373562e36 Implemented a preliminary fix for issue 328 showing the user an indication, if he made an exception for a certificate issue of a host.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
270 """
928373562e36 Implemented a preliminary fix for issue 328 showing the user an indication, if he made an exception for a certificate issue of a host.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
271 return host in self.__insecureHosts
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
272
6120
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
273 def authentication(self, url, auth, page=None):
4743
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
274 """
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
275 Public slot to handle an authentication request.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
276
6120
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
277 @param url URL requesting authentication
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
278 @type QUrl
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
279 @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
280 @type QAuthenticator
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
281 @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
282 @type QWebEnginePage or None
4743
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
283 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
284 urlRoot = "{0}://{1}".format(url.scheme(), url.authority())
4743
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
285 realm = auth.realm()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
286 if not realm and "realm" in auth.options():
4743
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
287 realm = auth.option("realm")
8260
2161475d9639 Applied some more code simplifications suggested by the new Simplify checker (Y108: use ternary operator).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8243
diff changeset
288 info = (
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
289 self.tr("<b>Enter username and password for '{0}', realm '{1}'</b>").format(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
290 urlRoot, realm
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
291 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
292 if realm
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
293 else self.tr("<b>Enter username and password for '{0}'</b>").format(urlRoot)
8260
2161475d9639 Applied some more code simplifications suggested by the new Simplify checker (Y108: use ternary operator).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8243
diff changeset
294 )
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
295
9413
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
296 from eric7.UI.AuthenticationDialog import AuthenticationDialog
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
297 from eric7.WebBrowser.WebBrowserWindow import WebBrowserWindow
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
298
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
299 dlg = AuthenticationDialog(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
300 info,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
301 auth.user(),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
302 Preferences.getUser("SavePasswords"),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
303 Preferences.getUser("SavePasswords"),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
304 )
4745
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4743
diff changeset
305 if Preferences.getUser("SavePasswords"):
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
306 (
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
307 username,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
308 password,
9413
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
309 ) = WebBrowserWindow.passwordManager().getLogin(url, realm)
4745
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4743
diff changeset
310 if username:
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4743
diff changeset
311 dlg.setData(username, password)
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
312 if dlg.exec() == QDialog.DialogCode.Accepted:
4743
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
313 username, password = dlg.getData()
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
314 auth.setUser(username)
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
315 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
316 if Preferences.getUser("SavePasswords") and dlg.shallSave():
9413
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
317 pm = WebBrowserWindow.passwordManager()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
318 pm.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
319 else:
6120
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
320 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
321 self.__showAuthenticationErrorPage(page, url)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
322
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
323 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
324 """
f0cb73e99e54 Added an error page to be shown if an authentication request is cancelled.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
325 Private method to show an authentication error page.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
326
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
327 @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
328 @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
329 @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
330 @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
331 """
7717
f32d7965a17e Changed the code to not rely on the Qt Resource system anymore (no .qrc files and no use of pyrcc5 anymore).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7570
diff changeset
332 html = getHtmlPage("authenticationErrorPage.html")
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
333 html = html.replace(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
334 "@IMAGE@",
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
335 pixmapToDataUrl(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
336 ericApp()
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
337 .style()
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
338 .standardIcon(QStyle.StandardPixmap.SP_MessageBoxCritical)
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
339 .pixmap(48, 48)
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
340 ).toString(),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
341 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
342 html = html.replace(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
343 "@FAVICON@",
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
344 pixmapToDataUrl(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
345 ericApp()
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
346 .style()
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
347 .standardIcon(QStyle.StandardPixmap.SP_MessageBoxCritical)
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
348 .pixmap(16, 16)
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
349 ).toString(),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
350 )
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
351 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
352 html = html.replace("@H1@", self.tr("Authentication required"))
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
353 html = html.replace("@LI-1@", self.tr("Authentication is required to access:"))
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
354 html = html.replace("@LI-2@", '<a href="{0}">{0}</a>'.format(url.toString()))
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
355 page.setHtml(html, url)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
356
4786
b149def67c6e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
357 def proxyAuthentication(self, requestUrl, auth, proxyHost):
4743
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
358 """
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
359 Public slot to handle a proxy authentication request.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
360
4786
b149def67c6e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
361 @param requestUrl requested URL
b149def67c6e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
362 @type QUrl
b149def67c6e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
363 @param auth reference to the authenticator object
b149def67c6e Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4766
diff changeset
364 @type QAuthenticator
4917
682750cc7bd5 Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4902
diff changeset
365 @param proxyHost name of the proxy host
4743
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
366 @type str
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
367 """
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
368 proxy = QNetworkProxy.applicationProxy()
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
369 if proxy.user() and proxy.password():
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
370 auth.setUser(proxy.user())
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
371 auth.setPassword(proxy.password())
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
372 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
373
4743
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
374 proxyAuthenticationRequired(proxy, auth)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
375
4754
1ff6d0ecb2fd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4745
diff changeset
376 def languagesChanged(self):
1ff6d0ecb2fd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4745
diff changeset
377 """
1ff6d0ecb2fd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4745
diff changeset
378 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
379 """
9413
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
380 from eric7.WebBrowser.WebBrowserLanguagesDialog import WebBrowserLanguagesDialog
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
381
4754
1ff6d0ecb2fd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4745
diff changeset
382 languages = Preferences.toList(
8637
394377638256 Replaced the direct access to 'Preferences.Prefs.settings' with 'Preferences.getSettings()'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8556
diff changeset
383 Preferences.getSettings().value(
4754
1ff6d0ecb2fd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4745
diff changeset
384 "WebBrowser/AcceptLanguages",
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
385 WebBrowserLanguagesDialog.defaultAcceptLanguages(),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
386 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
387 )
4754
1ff6d0ecb2fd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4745
diff changeset
388 self.__acceptLanguage = WebBrowserLanguagesDialog.httpString(languages)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
389
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
390 WebBrowserWindow.webProfile().setHttpAcceptLanguage(self.__acceptLanguage)
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
391
4766
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4758
diff changeset
392 def installUrlInterceptor(self, interceptor):
4825
b5fb58f3830b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4820
diff changeset
393 """
b5fb58f3830b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4820
diff changeset
394 Public method to install an URL interceptor.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
395
4825
b5fb58f3830b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4820
diff changeset
396 @param interceptor URL interceptor to be installed
b5fb58f3830b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4820
diff changeset
397 @type UrlInterceptor
b5fb58f3830b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4820
diff changeset
398 """
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4857
diff changeset
399 self.__interceptor.installUrlInterceptor(interceptor)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
400
4766
5f8d08aa2217 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4758
diff changeset
401 def removeUrlInterceptor(self, interceptor):
4825
b5fb58f3830b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4820
diff changeset
402 """
b5fb58f3830b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4820
diff changeset
403 Public method to remove an URL interceptor.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
404
4825
b5fb58f3830b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4820
diff changeset
405 @param interceptor URL interceptor to be removed
b5fb58f3830b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4820
diff changeset
406 @type UrlInterceptor
b5fb58f3830b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4820
diff changeset
407 """
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4857
diff changeset
408 self.__interceptor.removeUrlInterceptor(interceptor)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
409
4825
b5fb58f3830b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4820
diff changeset
410 def preferencesChanged(self):
b5fb58f3830b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4820
diff changeset
411 """
b5fb58f3830b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4820
diff changeset
412 Public slot to handle a change of preferences.
b5fb58f3830b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4820
diff changeset
413 """
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4857
diff changeset
414 self.__interceptor.preferencesChanged()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
415
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
416 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
417 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
418 else:
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
419 QNetworkProxyFactory.setApplicationProxyFactory(self.__proxyFactory)
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
420 QNetworkProxyFactory.setUseSystemConfiguration(False)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
421
4902
7a49807e493c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4886
diff changeset
422 def createRequest(self, op, request, data):
7a49807e493c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4886
diff changeset
423 """
7a49807e493c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4886
diff changeset
424 Public method to launch a network action.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
425
4902
7a49807e493c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4886
diff changeset
426 @param op operation to be performed
7a49807e493c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4886
diff changeset
427 @type QNetworkAccessManager.Operation
7a49807e493c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4886
diff changeset
428 @param request request to be operated on
7a49807e493c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4886
diff changeset
429 @type QNetworkRequest
7a49807e493c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4886
diff changeset
430 @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
431 @type QIODevice
7a49807e493c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4886
diff changeset
432 @return reference to the network reply
7a49807e493c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4886
diff changeset
433 @rtype QNetworkReply
7a49807e493c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4886
diff changeset
434 """
7a49807e493c Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4886
diff changeset
435 req = QNetworkRequest(request)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
436 req.setAttribute(QNetworkRequest.Attribute.Http2AllowedAttribute, True)
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
437
8218
7c09585bd960 Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8143
diff changeset
438 return super().createRequest(op, req, data)

eric ide

mercurial