35 |
40 |
36 |
41 |
37 class NetworkManager(QNetworkAccessManager): |
42 class NetworkManager(QNetworkAccessManager): |
38 """ |
43 """ |
39 Class implementing a network manager. |
44 Class implementing a network manager. |
40 |
45 |
41 @signal changed() emitted to indicate a change |
46 @signal changed() emitted to indicate a change |
42 """ |
47 """ |
|
48 |
43 changed = pyqtSignal() |
49 changed = pyqtSignal() |
44 |
50 |
45 def __init__(self, engine, parent=None): |
51 def __init__(self, engine, parent=None): |
46 """ |
52 """ |
47 Constructor |
53 Constructor |
48 |
54 |
49 @param engine reference to the help engine (QHelpEngine) |
55 @param engine reference to the help engine (QHelpEngine) |
50 @param parent reference to the parent object (QObject) |
56 @param parent reference to the parent object (QObject) |
51 """ |
57 """ |
52 super().__init__(parent) |
58 super().__init__(parent) |
53 |
59 |
54 from EricNetwork.EricNetworkProxyFactory import EricNetworkProxyFactory |
60 from EricNetwork.EricNetworkProxyFactory import EricNetworkProxyFactory |
55 |
61 |
56 self.__proxyFactory = EricNetworkProxyFactory() |
62 self.__proxyFactory = EricNetworkProxyFactory() |
57 if Preferences.getUI("UseSystemProxy"): |
63 if Preferences.getUI("UseSystemProxy"): |
58 QNetworkProxyFactory.setUseSystemConfiguration(True) |
64 QNetworkProxyFactory.setUseSystemConfiguration(True) |
59 else: |
65 else: |
60 QNetworkProxyFactory.setApplicationProxyFactory( |
66 QNetworkProxyFactory.setApplicationProxyFactory(self.__proxyFactory) |
61 self.__proxyFactory) |
|
62 QNetworkProxyFactory.setUseSystemConfiguration(False) |
67 QNetworkProxyFactory.setUseSystemConfiguration(False) |
63 |
68 |
64 self.languagesChanged() |
69 self.languagesChanged() |
65 |
70 |
66 if SSL_AVAILABLE: |
71 if SSL_AVAILABLE: |
67 self.__sslErrorHandler = EricSslErrorHandler(self) |
72 self.__sslErrorHandler = EricSslErrorHandler(self) |
68 self.sslErrors.connect(self.__sslErrorHandlingSlot) |
73 self.sslErrors.connect(self.__sslErrorHandlingSlot) |
69 |
74 |
70 self.__temporarilyIgnoredSslErrors = {} |
75 self.__temporarilyIgnoredSslErrors = {} |
71 self.__permanentlyIgnoredSslErrors = {} |
76 self.__permanentlyIgnoredSslErrors = {} |
72 # dictionaries of permanently and temporarily ignored SSL errors |
77 # dictionaries of permanently and temporarily ignored SSL errors |
73 |
78 |
74 self.__insecureHosts = set() |
79 self.__insecureHosts = set() |
75 |
80 |
76 self.__loaded = False |
81 self.__loaded = False |
77 self.__saveTimer = AutoSaver(self, self.__save) |
82 self.__saveTimer = AutoSaver(self, self.__save) |
78 |
83 |
79 self.changed.connect(self.__saveTimer.changeOccurred) |
84 self.changed.connect(self.__saveTimer.changeOccurred) |
80 self.proxyAuthenticationRequired.connect(proxyAuthenticationRequired) |
85 self.proxyAuthenticationRequired.connect(proxyAuthenticationRequired) |
81 self.authenticationRequired.connect( |
86 self.authenticationRequired.connect( |
82 lambda reply, auth: self.authentication(reply.url(), auth)) |
87 lambda reply, auth: self.authentication(reply.url(), auth) |
83 |
88 ) |
|
89 |
84 from .EricSchemeHandler import EricSchemeHandler |
90 from .EricSchemeHandler import EricSchemeHandler |
|
91 |
85 self.__ericSchemeHandler = EricSchemeHandler() |
92 self.__ericSchemeHandler = EricSchemeHandler() |
86 WebBrowserWindow.webProfile().installUrlSchemeHandler( |
93 WebBrowserWindow.webProfile().installUrlSchemeHandler( |
87 QByteArray(b"eric"), self.__ericSchemeHandler) |
94 QByteArray(b"eric"), self.__ericSchemeHandler |
88 |
95 ) |
|
96 |
89 if engine: |
97 if engine: |
90 from .QtHelpSchemeHandler import QtHelpSchemeHandler |
98 from .QtHelpSchemeHandler import QtHelpSchemeHandler |
|
99 |
91 self.__qtHelpSchemeHandler = QtHelpSchemeHandler(engine) |
100 self.__qtHelpSchemeHandler = QtHelpSchemeHandler(engine) |
92 WebBrowserWindow.webProfile().installUrlSchemeHandler( |
101 WebBrowserWindow.webProfile().installUrlSchemeHandler( |
93 QByteArray(b"qthelp"), self.__qtHelpSchemeHandler) |
102 QByteArray(b"qthelp"), self.__qtHelpSchemeHandler |
94 |
103 ) |
|
104 |
95 self.__interceptor = NetworkUrlInterceptor(self) |
105 self.__interceptor = NetworkUrlInterceptor(self) |
96 WebBrowserWindow.webProfile().setUrlRequestInterceptor( |
106 WebBrowserWindow.webProfile().setUrlRequestInterceptor(self.__interceptor) |
97 self.__interceptor) |
107 |
98 |
|
99 WebBrowserWindow.cookieJar() |
108 WebBrowserWindow.cookieJar() |
100 |
109 |
101 def __save(self): |
110 def __save(self): |
102 """ |
111 """ |
103 Private slot to save the permanent SSL error exceptions. |
112 Private slot to save the permanent SSL error exceptions. |
104 """ |
113 """ |
105 if not self.__loaded: |
114 if not self.__loaded: |
106 return |
115 return |
107 |
116 |
108 from WebBrowser.WebBrowserWindow import WebBrowserWindow |
117 from WebBrowser.WebBrowserWindow import WebBrowserWindow |
|
118 |
109 if not WebBrowserWindow.isPrivate(): |
119 if not WebBrowserWindow.isPrivate(): |
110 dbString = json.dumps(self.__permanentlyIgnoredSslErrors) |
120 dbString = json.dumps(self.__permanentlyIgnoredSslErrors) |
111 Preferences.setWebBrowser("SslExceptionsDB", dbString) |
121 Preferences.setWebBrowser("SslExceptionsDB", dbString) |
112 |
122 |
113 def __load(self): |
123 def __load(self): |
114 """ |
124 """ |
115 Private method to load the permanent SSL error exceptions. |
125 Private method to load the permanent SSL error exceptions. |
116 """ |
126 """ |
117 if self.__loaded: |
127 if self.__loaded: |
118 return |
128 return |
119 |
129 |
120 dbString = Preferences.getWebBrowser("SslExceptionsDB") |
130 dbString = Preferences.getWebBrowser("SslExceptionsDB") |
121 if dbString: |
131 if dbString: |
122 with contextlib.suppress(ValueError): |
132 with contextlib.suppress(ValueError): |
123 db = json.loads(dbString) |
133 db = json.loads(dbString) |
124 self.__permanentlyIgnoredSslErrors = db |
134 self.__permanentlyIgnoredSslErrors = db |
125 |
135 |
126 self.__loaded = True |
136 self.__loaded = True |
127 |
137 |
128 def shutdown(self): |
138 def shutdown(self): |
129 """ |
139 """ |
130 Public method to shut down the network manager. |
140 Public method to shut down the network manager. |
131 """ |
141 """ |
132 self.__saveTimer.saveIfNeccessary() |
142 self.__saveTimer.saveIfNeccessary() |
133 self.__loaded = False |
143 self.__loaded = False |
134 self.__temporarilyIgnoredSslErrors = {} |
144 self.__temporarilyIgnoredSslErrors = {} |
135 self.__permanentlyIgnoredSslErrors = {} |
145 self.__permanentlyIgnoredSslErrors = {} |
136 |
146 |
137 # set proxy factory to None to avoid crashes |
147 # set proxy factory to None to avoid crashes |
138 QNetworkProxyFactory.setApplicationProxyFactory(None) |
148 QNetworkProxyFactory.setApplicationProxyFactory(None) |
139 |
149 |
140 def showSslErrorExceptionsDialog(self): |
150 def showSslErrorExceptionsDialog(self): |
141 """ |
151 """ |
142 Public method to show the SSL error exceptions dialog. |
152 Public method to show the SSL error exceptions dialog. |
143 """ |
153 """ |
144 self.__load() |
154 self.__load() |
145 |
155 |
146 from .SslErrorExceptionsDialog import SslErrorExceptionsDialog |
156 from .SslErrorExceptionsDialog import SslErrorExceptionsDialog |
|
157 |
147 dlg = SslErrorExceptionsDialog(self.__permanentlyIgnoredSslErrors) |
158 dlg = SslErrorExceptionsDialog(self.__permanentlyIgnoredSslErrors) |
148 if dlg.exec() == QDialog.DialogCode.Accepted: |
159 if dlg.exec() == QDialog.DialogCode.Accepted: |
149 self.__permanentlyIgnoredSslErrors = dlg.getSslErrorExceptions() |
160 self.__permanentlyIgnoredSslErrors = dlg.getSslErrorExceptions() |
150 self.changed.emit() |
161 self.changed.emit() |
151 |
162 |
152 def clearSslExceptions(self): |
163 def clearSslExceptions(self): |
153 """ |
164 """ |
154 Public method to clear the permanent SSL certificate error exceptions. |
165 Public method to clear the permanent SSL certificate error exceptions. |
155 """ |
166 """ |
156 self.__load() |
167 self.__load() |
157 |
168 |
158 self.__permanentlyIgnoredSslErrors = {} |
169 self.__permanentlyIgnoredSslErrors = {} |
159 self.changed.emit() |
170 self.changed.emit() |
160 self.__saveTimer.saveIfNeccessary() |
171 self.__saveTimer.saveIfNeccessary() |
161 |
172 |
162 def certificateError(self, error, view): |
173 def certificateError(self, error, view): |
163 """ |
174 """ |
164 Public method to handle SSL certificate errors. |
175 Public method to handle SSL certificate errors. |
165 |
176 |
166 @param error object containing the certificate error information |
177 @param error object containing the certificate error information |
167 @type QWebEngineCertificateError |
178 @type QWebEngineCertificateError |
168 @param view reference to a view to be used as parent for the dialog |
179 @param view reference to a view to be used as parent for the dialog |
169 @type QWidget |
180 @type QWidget |
170 @return flag indicating to ignore this error |
181 @return flag indicating to ignore this error |
171 @rtype bool |
182 @rtype bool |
172 """ |
183 """ |
173 if Preferences.getWebBrowser("AlwaysRejectFaultyCertificates"): |
184 if Preferences.getWebBrowser("AlwaysRejectFaultyCertificates"): |
174 return False |
185 return False |
175 |
186 |
176 self.__load() |
187 self.__load() |
177 |
188 |
178 host = error.url().host() |
189 host = error.url().host() |
179 |
190 |
180 self.__insecureHosts.add(host) |
191 self.__insecureHosts.add(host) |
181 |
192 |
182 if ( |
193 if ( |
183 host in self.__temporarilyIgnoredSslErrors and |
194 host in self.__temporarilyIgnoredSslErrors |
184 error.error() in self.__temporarilyIgnoredSslErrors[host] |
195 and error.error() in self.__temporarilyIgnoredSslErrors[host] |
185 ): |
196 ): |
186 return True |
197 return True |
187 |
198 |
188 if ( |
199 if ( |
189 host in self.__permanentlyIgnoredSslErrors and |
200 host in self.__permanentlyIgnoredSslErrors |
190 error.error() in self.__permanentlyIgnoredSslErrors[host] |
201 and error.error() in self.__permanentlyIgnoredSslErrors[host] |
191 ): |
202 ): |
192 return True |
203 return True |
193 |
204 |
194 title = self.tr("SSL Certificate Error") |
205 title = self.tr("SSL Certificate Error") |
195 msgBox = EricMessageBox.EricMessageBox( |
206 msgBox = EricMessageBox.EricMessageBox( |
196 EricMessageBox.Warning, |
207 EricMessageBox.Warning, |
197 title, |
208 title, |
198 self.tr("""<b>{0}</b>""" |
209 self.tr( |
199 """<p>The host <b>{1}</b> you are trying to access has""" |
210 """<b>{0}</b>""" |
200 """ errors in the SSL certificate.</p>""" |
211 """<p>The host <b>{1}</b> you are trying to access has""" |
201 """<ul><li>{2}</li></ul>""" |
212 """ errors in the SSL certificate.</p>""" |
202 """<p>Would you like to make an exception?</p>""") |
213 """<ul><li>{2}</li></ul>""" |
203 .format(title, host, error.errorDescription()), |
214 """<p>Would you like to make an exception?</p>""" |
204 modal=True, parent=view) |
215 ).format(title, host, error.errorDescription()), |
205 permButton = msgBox.addButton(self.tr("&Permanent accept"), |
216 modal=True, |
206 EricMessageBox.AcceptRole) |
217 parent=view, |
207 tempButton = msgBox.addButton(self.tr("&Temporary accept"), |
218 ) |
208 EricMessageBox.AcceptRole) |
219 permButton = msgBox.addButton( |
|
220 self.tr("&Permanent accept"), EricMessageBox.AcceptRole |
|
221 ) |
|
222 tempButton = msgBox.addButton( |
|
223 self.tr("&Temporary accept"), EricMessageBox.AcceptRole |
|
224 ) |
209 msgBox.addButton(self.tr("&Reject"), EricMessageBox.RejectRole) |
225 msgBox.addButton(self.tr("&Reject"), EricMessageBox.RejectRole) |
210 msgBox.exec() |
226 msgBox.exec() |
211 if msgBox.clickedButton() == permButton: |
227 if msgBox.clickedButton() == permButton: |
212 if host not in self.__permanentlyIgnoredSslErrors: |
228 if host not in self.__permanentlyIgnoredSslErrors: |
213 self.__permanentlyIgnoredSslErrors[host] = [] |
229 self.__permanentlyIgnoredSslErrors[host] = [] |
219 self.__temporarilyIgnoredSslErrors[host] = [] |
235 self.__temporarilyIgnoredSslErrors[host] = [] |
220 self.__temporarilyIgnoredSslErrors[host].append(error.error()) |
236 self.__temporarilyIgnoredSslErrors[host].append(error.error()) |
221 return True |
237 return True |
222 else: |
238 else: |
223 return False |
239 return False |
224 |
240 |
225 def __sslErrorHandlingSlot(self, reply, errors): |
241 def __sslErrorHandlingSlot(self, reply, errors): |
226 """ |
242 """ |
227 Private slot to handle SSL errors for a network reply. |
243 Private slot to handle SSL errors for a network reply. |
228 |
244 |
229 @param reply reference to the reply object |
245 @param reply reference to the reply object |
230 @type QNetworkReply |
246 @type QNetworkReply |
231 @param errors list of SSL errors |
247 @param errors list of SSL errors |
232 @type list of QSslError |
248 @type list of QSslError |
233 """ |
249 """ |
234 if Preferences.getWebBrowser("AlwaysRejectFaultyCertificates"): |
250 if Preferences.getWebBrowser("AlwaysRejectFaultyCertificates"): |
235 return |
251 return |
236 |
252 |
237 self.__load() |
253 self.__load() |
238 |
254 |
239 host = reply.url().host() |
255 host = reply.url().host() |
240 if ( |
256 if ( |
241 host in self.__permanentlyIgnoredSslErrors or |
257 host in self.__permanentlyIgnoredSslErrors |
242 host in self.__temporarilyIgnoredSslErrors |
258 or host in self.__temporarilyIgnoredSslErrors |
243 ): |
259 ): |
244 reply.ignoreSslErrors() |
260 reply.ignoreSslErrors() |
245 else: |
261 else: |
246 self.__sslErrorHandler.sslErrorsReply(reply, errors) |
262 self.__sslErrorHandler.sslErrorsReply(reply, errors) |
247 |
263 |
248 def isInsecureHost(self, host): |
264 def isInsecureHost(self, host): |
249 """ |
265 """ |
250 Public method to check a host against the list of insecure hosts. |
266 Public method to check a host against the list of insecure hosts. |
251 |
267 |
252 @param host name of the host to be checked |
268 @param host name of the host to be checked |
253 @type str |
269 @type str |
254 @return flag indicating an insecure host |
270 @return flag indicating an insecure host |
255 @rtype bool |
271 @rtype bool |
256 """ |
272 """ |
257 return host in self.__insecureHosts |
273 return host in self.__insecureHosts |
258 |
274 |
259 def authentication(self, url, auth, page=None): |
275 def authentication(self, url, auth, page=None): |
260 """ |
276 """ |
261 Public slot to handle an authentication request. |
277 Public slot to handle an authentication request. |
262 |
278 |
263 @param url URL requesting authentication |
279 @param url URL requesting authentication |
264 @type QUrl |
280 @type QUrl |
265 @param auth reference to the authenticator object |
281 @param auth reference to the authenticator object |
266 @type QAuthenticator |
282 @type QAuthenticator |
267 @param page reference to the web page |
283 @param page reference to the web page |
268 @type QWebEnginePage or None |
284 @type QWebEnginePage or None |
269 """ |
285 """ |
270 urlRoot = ( |
286 urlRoot = "{0}://{1}".format(url.scheme(), url.authority()) |
271 "{0}://{1}".format(url.scheme(), url.authority()) |
|
272 ) |
|
273 realm = auth.realm() |
287 realm = auth.realm() |
274 if not realm and 'realm' in auth.options(): |
288 if not realm and "realm" in auth.options(): |
275 realm = auth.option("realm") |
289 realm = auth.option("realm") |
276 info = ( |
290 info = ( |
277 self.tr("<b>Enter username and password for '{0}', realm '{1}'</b>" |
291 self.tr("<b>Enter username and password for '{0}', realm '{1}'</b>").format( |
278 ).format(urlRoot, realm) |
292 urlRoot, realm |
279 if realm else |
293 ) |
280 self.tr("<b>Enter username and password for '{0}'</b>" |
294 if realm |
281 ).format(urlRoot) |
295 else self.tr("<b>Enter username and password for '{0}'</b>").format(urlRoot) |
282 ) |
296 ) |
283 |
297 |
284 from UI.AuthenticationDialog import AuthenticationDialog |
298 from UI.AuthenticationDialog import AuthenticationDialog |
285 import WebBrowser.WebBrowserWindow |
299 import WebBrowser.WebBrowserWindow |
286 |
300 |
287 dlg = AuthenticationDialog(info, auth.user(), |
301 dlg = AuthenticationDialog( |
288 Preferences.getUser("SavePasswords"), |
302 info, |
289 Preferences.getUser("SavePasswords")) |
303 auth.user(), |
|
304 Preferences.getUser("SavePasswords"), |
|
305 Preferences.getUser("SavePasswords"), |
|
306 ) |
290 if Preferences.getUser("SavePasswords"): |
307 if Preferences.getUser("SavePasswords"): |
291 username, password = ( |
308 ( |
292 WebBrowser.WebBrowserWindow.WebBrowserWindow |
309 username, |
293 .passwordManager().getLogin(url, realm) |
310 password, |
|
311 ) = WebBrowser.WebBrowserWindow.WebBrowserWindow.passwordManager().getLogin( |
|
312 url, realm |
294 ) |
313 ) |
295 if username: |
314 if username: |
296 dlg.setData(username, password) |
315 dlg.setData(username, password) |
297 if dlg.exec() == QDialog.DialogCode.Accepted: |
316 if dlg.exec() == QDialog.DialogCode.Accepted: |
298 username, password = dlg.getData() |
317 username, password = dlg.getData() |
299 auth.setUser(username) |
318 auth.setUser(username) |
300 auth.setPassword(password) |
319 auth.setPassword(password) |
301 if Preferences.getUser("SavePasswords") and dlg.shallSave(): |
320 if Preferences.getUser("SavePasswords") and dlg.shallSave(): |
302 ( |
321 pm = WebBrowser.WebBrowserWindow.WebBrowserWindow.passwordManager() |
303 WebBrowser.WebBrowserWindow.WebBrowserWindow |
322 pm.setLogin(url, realm, username, password) |
304 .passwordManager().setLogin( |
|
305 url, realm, username, password) |
|
306 ) |
|
307 else: |
323 else: |
308 if page is not None: |
324 if page is not None: |
309 self.__showAuthenticationErrorPage(page, url) |
325 self.__showAuthenticationErrorPage(page, url) |
310 |
326 |
311 def __showAuthenticationErrorPage(self, page, url): |
327 def __showAuthenticationErrorPage(self, page, url): |
312 """ |
328 """ |
313 Private method to show an authentication error page. |
329 Private method to show an authentication error page. |
314 |
330 |
315 @param page reference to the page |
331 @param page reference to the page |
316 @type QWebEnginePage |
332 @type QWebEnginePage |
317 @param url reference to the URL requesting authentication |
333 @param url reference to the URL requesting authentication |
318 @type QUrl |
334 @type QUrl |
319 """ |
335 """ |
320 html = getHtmlPage("authenticationErrorPage.html") |
336 html = getHtmlPage("authenticationErrorPage.html") |
321 html = html.replace("@IMAGE@", pixmapToDataUrl( |
337 html = html.replace( |
322 ericApp().style().standardIcon( |
338 "@IMAGE@", |
323 QStyle.StandardPixmap.SP_MessageBoxCritical).pixmap(48, 48) |
339 pixmapToDataUrl( |
324 ).toString()) |
340 ericApp() |
325 html = html.replace("@FAVICON@", pixmapToDataUrl( |
341 .style() |
326 ericApp().style() .standardIcon( |
342 .standardIcon(QStyle.StandardPixmap.SP_MessageBoxCritical) |
327 QStyle.StandardPixmap.SP_MessageBoxCritical).pixmap(16, 16) |
343 .pixmap(48, 48) |
328 ).toString()) |
344 ).toString(), |
|
345 ) |
|
346 html = html.replace( |
|
347 "@FAVICON@", |
|
348 pixmapToDataUrl( |
|
349 ericApp() |
|
350 .style() |
|
351 .standardIcon(QStyle.StandardPixmap.SP_MessageBoxCritical) |
|
352 .pixmap(16, 16) |
|
353 ).toString(), |
|
354 ) |
329 html = html.replace("@TITLE@", self.tr("Authentication required")) |
355 html = html.replace("@TITLE@", self.tr("Authentication required")) |
330 html = html.replace("@H1@", self.tr("Authentication required")) |
356 html = html.replace("@H1@", self.tr("Authentication required")) |
331 html = html.replace( |
357 html = html.replace("@LI-1@", self.tr("Authentication is required to access:")) |
332 "@LI-1@", |
358 html = html.replace("@LI-2@", '<a href="{0}">{0}</a>'.format(url.toString())) |
333 self.tr("Authentication is required to access:")) |
|
334 html = html.replace( |
|
335 "@LI-2@", |
|
336 '<a href="{0}">{0}</a>'.format(url.toString())) |
|
337 page.setHtml(html, url) |
359 page.setHtml(html, url) |
338 |
360 |
339 def proxyAuthentication(self, requestUrl, auth, proxyHost): |
361 def proxyAuthentication(self, requestUrl, auth, proxyHost): |
340 """ |
362 """ |
341 Public slot to handle a proxy authentication request. |
363 Public slot to handle a proxy authentication request. |
342 |
364 |
343 @param requestUrl requested URL |
365 @param requestUrl requested URL |
344 @type QUrl |
366 @type QUrl |
345 @param auth reference to the authenticator object |
367 @param auth reference to the authenticator object |
346 @type QAuthenticator |
368 @type QAuthenticator |
347 @param proxyHost name of the proxy host |
369 @param proxyHost name of the proxy host |
350 proxy = QNetworkProxy.applicationProxy() |
372 proxy = QNetworkProxy.applicationProxy() |
351 if proxy.user() and proxy.password(): |
373 if proxy.user() and proxy.password(): |
352 auth.setUser(proxy.user()) |
374 auth.setUser(proxy.user()) |
353 auth.setPassword(proxy.password()) |
375 auth.setPassword(proxy.password()) |
354 return |
376 return |
355 |
377 |
356 proxyAuthenticationRequired(proxy, auth) |
378 proxyAuthenticationRequired(proxy, auth) |
357 |
379 |
358 def languagesChanged(self): |
380 def languagesChanged(self): |
359 """ |
381 """ |
360 Public slot to (re-)load the list of accepted languages. |
382 Public slot to (re-)load the list of accepted languages. |
361 """ |
383 """ |
362 from WebBrowser.WebBrowserLanguagesDialog import ( |
384 from WebBrowser.WebBrowserLanguagesDialog import WebBrowserLanguagesDialog |
363 WebBrowserLanguagesDialog |
385 |
364 ) |
|
365 languages = Preferences.toList( |
386 languages = Preferences.toList( |
366 Preferences.getSettings().value( |
387 Preferences.getSettings().value( |
367 "WebBrowser/AcceptLanguages", |
388 "WebBrowser/AcceptLanguages", |
368 WebBrowserLanguagesDialog.defaultAcceptLanguages())) |
389 WebBrowserLanguagesDialog.defaultAcceptLanguages(), |
|
390 ) |
|
391 ) |
369 self.__acceptLanguage = WebBrowserLanguagesDialog.httpString(languages) |
392 self.__acceptLanguage = WebBrowserLanguagesDialog.httpString(languages) |
370 |
393 |
371 WebBrowserWindow.webProfile().setHttpAcceptLanguage( |
394 WebBrowserWindow.webProfile().setHttpAcceptLanguage(self.__acceptLanguage) |
372 self.__acceptLanguage) |
395 |
373 |
|
374 def installUrlInterceptor(self, interceptor): |
396 def installUrlInterceptor(self, interceptor): |
375 """ |
397 """ |
376 Public method to install an URL interceptor. |
398 Public method to install an URL interceptor. |
377 |
399 |
378 @param interceptor URL interceptor to be installed |
400 @param interceptor URL interceptor to be installed |
379 @type UrlInterceptor |
401 @type UrlInterceptor |
380 """ |
402 """ |
381 self.__interceptor.installUrlInterceptor(interceptor) |
403 self.__interceptor.installUrlInterceptor(interceptor) |
382 |
404 |
383 def removeUrlInterceptor(self, interceptor): |
405 def removeUrlInterceptor(self, interceptor): |
384 """ |
406 """ |
385 Public method to remove an URL interceptor. |
407 Public method to remove an URL interceptor. |
386 |
408 |
387 @param interceptor URL interceptor to be removed |
409 @param interceptor URL interceptor to be removed |
388 @type UrlInterceptor |
410 @type UrlInterceptor |
389 """ |
411 """ |
390 self.__interceptor.removeUrlInterceptor(interceptor) |
412 self.__interceptor.removeUrlInterceptor(interceptor) |
391 |
413 |
392 def preferencesChanged(self): |
414 def preferencesChanged(self): |
393 """ |
415 """ |
394 Public slot to handle a change of preferences. |
416 Public slot to handle a change of preferences. |
395 """ |
417 """ |
396 self.__interceptor.preferencesChanged() |
418 self.__interceptor.preferencesChanged() |
397 |
419 |
398 if Preferences.getUI("UseSystemProxy"): |
420 if Preferences.getUI("UseSystemProxy"): |
399 QNetworkProxyFactory.setUseSystemConfiguration(True) |
421 QNetworkProxyFactory.setUseSystemConfiguration(True) |
400 else: |
422 else: |
401 QNetworkProxyFactory.setApplicationProxyFactory( |
423 QNetworkProxyFactory.setApplicationProxyFactory(self.__proxyFactory) |
402 self.__proxyFactory) |
|
403 QNetworkProxyFactory.setUseSystemConfiguration(False) |
424 QNetworkProxyFactory.setUseSystemConfiguration(False) |
404 |
425 |
405 def createRequest(self, op, request, data): |
426 def createRequest(self, op, request, data): |
406 """ |
427 """ |
407 Public method to launch a network action. |
428 Public method to launch a network action. |
408 |
429 |
409 @param op operation to be performed |
430 @param op operation to be performed |
410 @type QNetworkAccessManager.Operation |
431 @type QNetworkAccessManager.Operation |
411 @param request request to be operated on |
432 @param request request to be operated on |
412 @type QNetworkRequest |
433 @type QNetworkRequest |
413 @param data reference to the data to be sent |
434 @param data reference to the data to be sent |
414 @type QIODevice |
435 @type QIODevice |
415 @return reference to the network reply |
436 @return reference to the network reply |
416 @rtype QNetworkReply |
437 @rtype QNetworkReply |
417 """ |
438 """ |
418 req = QNetworkRequest(request) |
439 req = QNetworkRequest(request) |
419 req.setAttribute( |
440 req.setAttribute(QNetworkRequest.Attribute.Http2AllowedAttribute, True) |
420 QNetworkRequest.Attribute.Http2AllowedAttribute, True) |
441 |
421 |
|
422 return super().createRequest(op, req, data) |
442 return super().createRequest(op, req, data) |