eric6/WebBrowser/WebBrowserPage.py

Wed, 30 Dec 2020 11:00:44 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 30 Dec 2020 11:00:44 +0100
branch
maintenance
changeset 7924
8a96736d465e
parent 7766
0af772bc14c4
child 8143
2c730d5fd177
permissions
-rw-r--r--

Updated copyright for 2021.

0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7924
8a96736d465e Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7766
diff changeset
3 # Copyright (c) 2008 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 Module implementing the helpbrowser using QWebView.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10
7271
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
11 from PyQt5.QtCore import (
7366
bd743eacfbca Changed code to avoid some obsoleted Qt functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
12 pyqtSlot, pyqtSignal, QUrl, QUrlQuery, QTimer, QEventLoop, QPoint, QPointF,
bd743eacfbca Changed code to avoid some obsoleted Qt functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
13 QT_VERSION
7271
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
14 )
4913
e16573640cb8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4910
diff changeset
15 from PyQt5.QtGui import QDesktopServices
7271
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
16 from PyQt5.QtWebEngineWidgets import (
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
17 QWebEnginePage, QWebEngineSettings, QWebEngineScript
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
18 )
7366
bd743eacfbca Changed code to avoid some obsoleted Qt functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
19 try:
bd743eacfbca Changed code to avoid some obsoleted Qt functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
20 from PyQt5.QtWebEngine import PYQT_WEBENGINE_VERSION
7380
c99320e859ca Fixed an issue related to showing the application name in the menu bar of Gnome desktop under Wayland.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7366
diff changeset
21 # __IGNORE_EXCEPTION__
c99320e859ca Fixed an issue related to showing the application name in the menu bar of Gnome desktop under Wayland.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7366
diff changeset
22 except (AttributeError, ImportError):
7366
bd743eacfbca Changed code to avoid some obsoleted Qt functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
23 PYQT_WEBENGINE_VERSION = QT_VERSION
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
24 from PyQt5.QtWebChannel import QWebChannel
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25
7766
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
26 try:
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
27 from PyQt5.QtNetwork import QSslConfiguration, QSslCertificate
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
28 SSL_AVAILABLE = True
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
29 except ImportError:
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
30 SSL_AVAILABLE = False
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
31
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
32 from E5Gui import E5MessageBox
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
33
4788
7076adec8ddd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4787
diff changeset
34 from WebBrowser.WebBrowserWindow import WebBrowserWindow
4355
40ec6bef4c22 Started to implement the HTML5 feature permission manager and associated dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4353
diff changeset
35
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
36 from .JavaScript.ExternalJsObject import ExternalJsObject
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
37
4728
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
38 from .Tools.WebHitTestResult import WebHitTestResult
6692
c104c120e043 Web Browser (NG): some compatibility changes for Qt 5.12.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6662
diff changeset
39 from .Tools import Scripts
4728
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
40
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 import Preferences
7766
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
42 import Globals
1960
d8c45fe8a1b9 Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1953
diff changeset
43
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 923
diff changeset
44
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
45 class WebBrowserPage(QWebEnginePage):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 Class implementing an enhanced web page.
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
48
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
49 @signal safeBrowsingAbort() emitted to indicate an abort due to a safe
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
50 browsing event
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
51 @signal safeBrowsingBad(threatType, threatMessages) emitted to indicate a
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
52 malicious web site as determined by safe browsing
6656
273a2130adbe WebBrowserPage: added support for the printRequested signal as of Qt 5.12.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
53 @signal printPageRequested() emitted to indicate a print request of the
273a2130adbe WebBrowserPage: added support for the printRequested signal as of Qt 5.12.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
54 shown web page
6149
e611e45a17d6 Fixed a few code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6146
diff changeset
55 @signal navigationRequestAccepted(url, navigation type, main frame) emitted
e611e45a17d6 Fixed a few code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6146
diff changeset
56 to signal an accepted navigation request
7766
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
57 @signal sslConfigurationChanged() emitted to indicate a change of the
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
58 stored SSL configuration data
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 """
7201
6b42677d7043 Modified sources to be in line with the minimum Qt/PyQt requirement (v 5.9.0).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7192
diff changeset
60 SafeJsWorld = QWebEngineScript.ApplicationWorld
6140
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
61 UnsafeJsWorld = QWebEngineScript.MainWorld
5001
08eaee907686 Prepared the QWebEingine based web browser for the new runJavaScript() method as of Qt 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4978
diff changeset
62
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
63 safeBrowsingAbort = pyqtSignal()
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
64 safeBrowsingBad = pyqtSignal(str, str)
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
65
6656
273a2130adbe WebBrowserPage: added support for the printRequested signal as of Qt 5.12.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
66 printPageRequested = pyqtSignal()
6146
94a4e8d1ac4f WebBrowserPage: Made it emit a navigationRequestAccepted signal when the request was in the main frame and accepted by the underlying engine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6142
diff changeset
67 navigationRequestAccepted = pyqtSignal(QUrl, QWebEnginePage.NavigationType,
94a4e8d1ac4f WebBrowserPage: Made it emit a navigationRequestAccepted signal when the request was in the main frame and accepted by the underlying engine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6142
diff changeset
68 bool)
6142
304a469455c8 Added support for printing from within a web page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6140
diff changeset
69
7766
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
70 sslConfigurationChanged = pyqtSignal()
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
71
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 923
diff changeset
72 def __init__(self, parent=None):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 Constructor
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 @param parent parent widget of this window (QWidget)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 """
4788
7076adec8ddd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4787
diff changeset
78 super(WebBrowserPage, self).__init__(
7076adec8ddd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4787
diff changeset
79 WebBrowserWindow.webProfile(), parent)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80
6695
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
81 self.__printer = None
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
82 self.__badSite = False
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
83 self.__registerProtocolHandlerRequest = None
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
84
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
85 self.featurePermissionRequested.connect(
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
86 self.__featurePermissionRequested)
4743
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4742
diff changeset
87 self.authenticationRequired.connect(
6120
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6093
diff changeset
88 lambda url, auth: WebBrowserWindow.networkManager().authentication(
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6093
diff changeset
89 url, auth, self))
4787
2a19edf4db14 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4768
diff changeset
90 self.proxyAuthenticationRequired.connect(
4788
7076adec8ddd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4787
diff changeset
91 WebBrowserWindow.networkManager().proxyAuthentication)
4884
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
92 self.fullScreenRequested.connect(self.__fullScreenRequested)
4964
a894e8c92369 Implemented the JavaScript status bar icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4925
diff changeset
93 self.urlChanged.connect(self.__urlChanged)
7201
6b42677d7043 Modified sources to be in line with the minimum Qt/PyQt requirement (v 5.9.0).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7192
diff changeset
94 self.contentsSizeChanged.connect(self.__contentsSizeChanged)
6692
c104c120e043 Web Browser (NG): some compatibility changes for Qt 5.12.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6662
diff changeset
95
6695
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
96 try:
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
97 self.registerProtocolHandlerRequested.connect(
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
98 self.__registerProtocolHandlerRequested)
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
99 except AttributeError:
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
100 # defined for Qt >= 5.11
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
101 pass
6268
eb6e49388114 WebBrowserPage: reintroduced the workaround for the loadFinished signale not working in Qt 5.10 and 5.11.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6234
diff changeset
102
7766
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
103 self.__sslConfiguration = None
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
104
6140
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
105 # Workaround for changing webchannel world inside
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
106 # acceptNavigationRequest not working
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
107 self.__channelUrl = QUrl()
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
108 self.__channelWorldId = -1
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
109 self.__setupChannelTimer = QTimer(self)
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
110 self.__setupChannelTimer.setSingleShot(True)
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
111 self.__setupChannelTimer.setInterval(100)
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
112 self.__setupChannelTimer.timeout.connect(self.__setupChannelTimeout)
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
113
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
114 @pyqtSlot()
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
115 def __setupChannelTimeout(self):
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
116 """
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
117 Private slot to initiate the setup of the web channel.
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
118 """
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
119 self.__setupWebChannelForUrl(self.__channelUrl)
6139
d24997c47244 Fixed an issue in the new web browser with Qt 5.10.0
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6137
diff changeset
120
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
121 def acceptNavigationRequest(self, url, type_, isMainFrame):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 """
4726
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
123 Public method to determine, if a request may be accepted.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
125 @param url URL to navigate to
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
126 @type QUrl
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
127 @param type_ type of the navigation request
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
128 @type QWebEnginePage.NavigationType
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
129 @param isMainFrame flag indicating, that the request originated from
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
130 the main frame
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
131 @type bool
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
132 @return flag indicating acceptance
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
133 @rtype bool
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 """
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
135 scheme = url.scheme()
757
d3daf1d8f058 Fixed the handling of 'javascript' schemes in the web browser and enhanced the download manager a bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 748
diff changeset
136 if scheme == "mailto":
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
137 QDesktopServices.openUrl(url)
757
d3daf1d8f058 Fixed the handling of 'javascript' schemes in the web browser and enhanced the download manager a bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 748
diff changeset
138 return False
d3daf1d8f058 Fixed the handling of 'javascript' schemes in the web browser and enhanced the download manager a bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 748
diff changeset
139
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
140 # AdBlock
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
141 if url.scheme() == "abp":
4788
7076adec8ddd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4787
diff changeset
142 if WebBrowserWindow.adBlockManager().addSubscriptionFromUrl(url):
675
2f626dcab902 Added check for a form resubmission to the web page class of the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 668
diff changeset
143 return False
4886
b56735d36159 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
144
5716
27a7c7064686 Improved installion of GreaseMonkey user scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5624
diff changeset
145 # GreaseMonkey
7540
7a44cb47054b WebBrowserPage: fixed an AttributeError caused by using PyQtWebEngine 5.14 with older Qt variants.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7380
diff changeset
146 try:
7a44cb47054b WebBrowserPage: fixed an AttributeError caused by using PyQtWebEngine 5.14 with older Qt variants.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7380
diff changeset
147 # PyQtWebEngine >= 5.14.0
7366
bd743eacfbca Changed code to avoid some obsoleted Qt functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
148 navigationType = type_ in [
bd743eacfbca Changed code to avoid some obsoleted Qt functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
149 QWebEnginePage.NavigationTypeLinkClicked,
bd743eacfbca Changed code to avoid some obsoleted Qt functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
150 QWebEnginePage.NavigationTypeRedirect
bd743eacfbca Changed code to avoid some obsoleted Qt functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
151 ]
7540
7a44cb47054b WebBrowserPage: fixed an AttributeError caused by using PyQtWebEngine 5.14 with older Qt variants.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7380
diff changeset
152 except AttributeError:
7366
bd743eacfbca Changed code to avoid some obsoleted Qt functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
153 navigationType = type_ == QWebEnginePage.NavigationTypeLinkClicked
bd743eacfbca Changed code to avoid some obsoleted Qt functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
154 if navigationType and url.toString().endswith(".user.js"):
5716
27a7c7064686 Improved installion of GreaseMonkey user scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5624
diff changeset
155 WebBrowserWindow.greaseMonkeyManager().downloadScript(url)
27a7c7064686 Improved installion of GreaseMonkey user scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5624
diff changeset
156 return False
27a7c7064686 Improved installion of GreaseMonkey user scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5624
diff changeset
157
6142
304a469455c8 Added support for printing from within a web page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6140
diff changeset
158 if url.scheme() == "eric":
6174
bb2989d750ce WebBrowser: Fixed some sender() related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6149
diff changeset
159 if url.path() == "AddSearchProvider":
bb2989d750ce WebBrowser: Fixed some sender() related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6149
diff changeset
160 query = QUrlQuery(url)
bb2989d750ce WebBrowser: Fixed some sender() related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6149
diff changeset
161 self.view().mainWindow().openSearchManager().addEngine(
bb2989d750ce WebBrowser: Fixed some sender() related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6149
diff changeset
162 QUrl(query.queryItemValue("url")))
bb2989d750ce WebBrowser: Fixed some sender() related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6149
diff changeset
163 return False
bb2989d750ce WebBrowser: Fixed some sender() related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6149
diff changeset
164 elif url.path() == "PrintPage":
6656
273a2130adbe WebBrowserPage: added support for the printRequested signal as of Qt 5.12.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
165 self.printPageRequested.emit()
6142
304a469455c8 Added support for printing from within a web page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6140
diff changeset
166 return False
304a469455c8 Added support for printing from within a web page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6140
diff changeset
167
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
168 # Safe Browsing
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
169 self.__badSite = False
7271
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
170 from WebBrowser.SafeBrowsing.SafeBrowsingManager import (
6093
5ed91fe54bc9 Implemented some optimizations with respect to Google Safe Browsing and browser startup with Qt Help support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
171 SafeBrowsingManager
7271
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
172 )
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
173 if (
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
174 SafeBrowsingManager.isEnabled() and
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
175 url.scheme() not in SafeBrowsingManager.getIgnoreSchemes()
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
176 ):
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
177 threatLists = (
6234
fb1f9e681848 Web Browser NG, Safe Browsing: improved error handling
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6233
diff changeset
178 WebBrowserWindow.safeBrowsingManager().lookupUrl(url)[0]
7271
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
179 )
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
180 if threatLists:
7271
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
181 threatMessages = (
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
182 WebBrowserWindow.safeBrowsingManager()
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
183 .getThreatMessages(threatLists)
7271
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
184 )
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
185 res = E5MessageBox.warning(
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
186 WebBrowserWindow.getWindow(),
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
187 self.tr("Suspicuous URL detected"),
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
188 self.tr("<p>The URL <b>{0}</b> was found in the Safe"
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
189 " Browsing database.</p>{1}").format(
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
190 url.toString(), "".join(threatMessages)),
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
191 E5MessageBox.StandardButtons(
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
192 E5MessageBox.Abort |
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
193 E5MessageBox.Ignore),
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
194 E5MessageBox.Abort)
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
195 if res == E5MessageBox.Abort:
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
196 self.safeBrowsingAbort.emit()
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
197 return False
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
198
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
199 self.__badSite = True
7271
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
200 threatType = (
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
201 WebBrowserWindow.safeBrowsingManager()
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
202 .getThreatType(threatLists[0])
7271
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
203 )
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
204 self.safeBrowsingBad.emit(threatType, "".join(threatMessages))
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
205
7366
bd743eacfbca Changed code to avoid some obsoleted Qt functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
206 result = QWebEnginePage.acceptNavigationRequest(
bd743eacfbca Changed code to avoid some obsoleted Qt functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
207 self, url, type_, isMainFrame)
6137
27962f3f457f Some minor changes in the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6136
diff changeset
208
6146
94a4e8d1ac4f WebBrowserPage: Made it emit a navigationRequestAccepted signal when the request was in the main frame and accepted by the underlying engine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6142
diff changeset
209 if result:
94a4e8d1ac4f WebBrowserPage: Made it emit a navigationRequestAccepted signal when the request was in the main frame and accepted by the underlying engine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6142
diff changeset
210 if isMainFrame:
94a4e8d1ac4f WebBrowserPage: Made it emit a navigationRequestAccepted signal when the request was in the main frame and accepted by the underlying engine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6142
diff changeset
211 isWeb = url.scheme() in ("http", "https", "ftp", "ftps",
94a4e8d1ac4f WebBrowserPage: Made it emit a navigationRequestAccepted signal when the request was in the main frame and accepted by the underlying engine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6142
diff changeset
212 "file")
94a4e8d1ac4f WebBrowserPage: Made it emit a navigationRequestAccepted signal when the request was in the main frame and accepted by the underlying engine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6142
diff changeset
213 globalJsEnabled = WebBrowserWindow.webSettings().testAttribute(
94a4e8d1ac4f WebBrowserPage: Made it emit a navigationRequestAccepted signal when the request was in the main frame and accepted by the underlying engine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6142
diff changeset
214 QWebEngineSettings.JavascriptEnabled)
94a4e8d1ac4f WebBrowserPage: Made it emit a navigationRequestAccepted signal when the request was in the main frame and accepted by the underlying engine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6142
diff changeset
215 if isWeb:
94a4e8d1ac4f WebBrowserPage: Made it emit a navigationRequestAccepted signal when the request was in the main frame and accepted by the underlying engine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6142
diff changeset
216 enable = globalJsEnabled
94a4e8d1ac4f WebBrowserPage: Made it emit a navigationRequestAccepted signal when the request was in the main frame and accepted by the underlying engine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6142
diff changeset
217 else:
94a4e8d1ac4f WebBrowserPage: Made it emit a navigationRequestAccepted signal when the request was in the main frame and accepted by the underlying engine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6142
diff changeset
218 enable = True
94a4e8d1ac4f WebBrowserPage: Made it emit a navigationRequestAccepted signal when the request was in the main frame and accepted by the underlying engine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6142
diff changeset
219 self.settings().setAttribute(
94a4e8d1ac4f WebBrowserPage: Made it emit a navigationRequestAccepted signal when the request was in the main frame and accepted by the underlying engine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6142
diff changeset
220 QWebEngineSettings.JavascriptEnabled, enable)
94a4e8d1ac4f WebBrowserPage: Made it emit a navigationRequestAccepted signal when the request was in the main frame and accepted by the underlying engine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6142
diff changeset
221
94a4e8d1ac4f WebBrowserPage: Made it emit a navigationRequestAccepted signal when the request was in the main frame and accepted by the underlying engine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6142
diff changeset
222 self.__channelUrl = url
94a4e8d1ac4f WebBrowserPage: Made it emit a navigationRequestAccepted signal when the request was in the main frame and accepted by the underlying engine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6142
diff changeset
223 self.__setupChannelTimer.start()
94a4e8d1ac4f WebBrowserPage: Made it emit a navigationRequestAccepted signal when the request was in the main frame and accepted by the underlying engine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6142
diff changeset
224 self.navigationRequestAccepted.emit(url, type_, isMainFrame)
6137
27962f3f457f Some minor changes in the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6136
diff changeset
225
27962f3f457f Some minor changes in the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6136
diff changeset
226 return result
487
4d41d03d3d00 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 383
diff changeset
227
4964
a894e8c92369 Implemented the JavaScript status bar icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4925
diff changeset
228 @pyqtSlot(QUrl)
a894e8c92369 Implemented the JavaScript status bar icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4925
diff changeset
229 def __urlChanged(self, url):
a894e8c92369 Implemented the JavaScript status bar icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4925
diff changeset
230 """
a894e8c92369 Implemented the JavaScript status bar icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4925
diff changeset
231 Private slot to handle changes of the URL.
a894e8c92369 Implemented the JavaScript status bar icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4925
diff changeset
232
a894e8c92369 Implemented the JavaScript status bar icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4925
diff changeset
233 @param url new URL
a894e8c92369 Implemented the JavaScript status bar icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4925
diff changeset
234 @type QUrl
a894e8c92369 Implemented the JavaScript status bar icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4925
diff changeset
235 """
7271
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
236 if (
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
237 not url.isEmpty() and
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
238 url.scheme() == "eric" and
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
239 not self.isJavaScriptEnabled()
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
240 ):
6136
dfef226f9c7f Removed WebBrowserPage.setJavaScriptEnabled().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6127
diff changeset
241 self.settings().setAttribute(QWebEngineSettings.JavascriptEnabled,
dfef226f9c7f Removed WebBrowserPage.setJavaScriptEnabled().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6127
diff changeset
242 True)
4965
a9a4b632fe48 Some enhancements for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4964
diff changeset
243 self.triggerAction(QWebEnginePage.Reload)
4964
a894e8c92369 Implemented the JavaScript status bar icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4925
diff changeset
244
4906
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
245 @classmethod
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
246 def userAgent(cls, resolveEmpty=False):
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
247 """
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
248 Class method to get the global user agent setting.
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
249
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
250 @param resolveEmpty flag indicating to resolve an empty
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
251 user agent (boolean)
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
252 @return user agent string (string)
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
253 """
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
254 agent = Preferences.getWebBrowser("UserAgent")
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
255 if agent == "" and resolveEmpty:
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
256 agent = cls.userAgentForUrl(QUrl())
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
257 return agent
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
258
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
259 @classmethod
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
260 def setUserAgent(cls, agent):
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
261 """
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
262 Class method to set the global user agent string.
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
263
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
264 @param agent new current user agent string (string)
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
265 """
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
266 Preferences.setWebBrowser("UserAgent", agent)
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
267
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
268 @classmethod
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
269 def userAgentForUrl(cls, url):
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
270 """
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
271 Class method to determine the user agent for the given URL.
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
272
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
273 @param url URL to determine user agent for (QUrl)
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
274 @return user agent string (string)
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
275 """
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
276 agent = WebBrowserWindow.userAgentsManager().userAgentForUrl(url)
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
277 if agent == "":
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
278 # no agent string specified for the given host -> use global one
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
279 agent = Preferences.getWebBrowser("UserAgent")
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
280 if agent == "":
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
281 # no global agent string specified -> use default one
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
282 agent = WebBrowserWindow.webProfile().httpUserAgent()
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
283 return agent
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
284
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
285 def __featurePermissionRequested(self, url, feature):
4316
493891cbacee Added support for feature permissions to the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4275
diff changeset
286 """
493891cbacee Added support for feature permissions to the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4275
diff changeset
287 Private slot handling a feature permission request.
493891cbacee Added support for feature permissions to the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4275
diff changeset
288
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
289 @param url url requesting the feature
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
290 @type QUrl
4316
493891cbacee Added support for feature permissions to the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4275
diff changeset
291 @param feature requested feature
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
292 @type QWebEnginePage.Feature
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
293 """
4788
7076adec8ddd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4787
diff changeset
294 manager = WebBrowserWindow.featurePermissionManager()
4742
f9d1090f6ab9 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
295 manager.requestFeaturePermission(self, url, feature)
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
296
5001
08eaee907686 Prepared the QWebEingine based web browser for the new runJavaScript() method as of Qt 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4978
diff changeset
297 def execJavaScript(self, script, worldId=QWebEngineScript.MainWorld,
08eaee907686 Prepared the QWebEingine based web browser for the new runJavaScript() method as of Qt 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4978
diff changeset
298 timeout=500):
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
299 """
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
300 Public method to execute a JavaScript function synchroneously.
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
301
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
302 @param script JavaScript script source to be executed
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
303 @type str
5001
08eaee907686 Prepared the QWebEingine based web browser for the new runJavaScript() method as of Qt 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4978
diff changeset
304 @param worldId ID to run the script under
08eaee907686 Prepared the QWebEingine based web browser for the new runJavaScript() method as of Qt 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4978
diff changeset
305 @type int
08eaee907686 Prepared the QWebEingine based web browser for the new runJavaScript() method as of Qt 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4978
diff changeset
306 @param timeout max. time the script is given to execute
08eaee907686 Prepared the QWebEingine based web browser for the new runJavaScript() method as of Qt 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4978
diff changeset
307 @type int
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
308 @return result of the script
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
309 @rtype depending upon script result
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
310 """
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
311 loop = QEventLoop()
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
312 resultDict = {"res": None}
5001
08eaee907686 Prepared the QWebEingine based web browser for the new runJavaScript() method as of Qt 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4978
diff changeset
313 QTimer.singleShot(timeout, loop.quit)
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
314
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
315 def resultCallback(res, resDict=resultDict):
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
316 if loop and loop.isRunning():
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
317 resDict["res"] = res
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
318 loop.quit()
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
319
5001
08eaee907686 Prepared the QWebEingine based web browser for the new runJavaScript() method as of Qt 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4978
diff changeset
320 self.runJavaScript(script, worldId, resultCallback)
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
321
7759
51aa6c6b66f7 Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7540
diff changeset
322 loop.exec()
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
323 return resultDict["res"]
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
324
5001
08eaee907686 Prepared the QWebEingine based web browser for the new runJavaScript() method as of Qt 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4978
diff changeset
325 def runJavaScript(self, script, worldId=-1, callback=None):
08eaee907686 Prepared the QWebEingine based web browser for the new runJavaScript() method as of Qt 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4978
diff changeset
326 """
08eaee907686 Prepared the QWebEingine based web browser for the new runJavaScript() method as of Qt 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4978
diff changeset
327 Public method to run a script in the context of the page.
08eaee907686 Prepared the QWebEingine based web browser for the new runJavaScript() method as of Qt 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4978
diff changeset
328
08eaee907686 Prepared the QWebEingine based web browser for the new runJavaScript() method as of Qt 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4978
diff changeset
329 @param script JavaScript script source to be executed
08eaee907686 Prepared the QWebEingine based web browser for the new runJavaScript() method as of Qt 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4978
diff changeset
330 @type str
08eaee907686 Prepared the QWebEingine based web browser for the new runJavaScript() method as of Qt 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4978
diff changeset
331 @param worldId ID to run the script under
08eaee907686 Prepared the QWebEingine based web browser for the new runJavaScript() method as of Qt 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4978
diff changeset
332 @type int
08eaee907686 Prepared the QWebEingine based web browser for the new runJavaScript() method as of Qt 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4978
diff changeset
333 @param callback callback function to be executed when the script has
08eaee907686 Prepared the QWebEingine based web browser for the new runJavaScript() method as of Qt 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4978
diff changeset
334 ended
08eaee907686 Prepared the QWebEingine based web browser for the new runJavaScript() method as of Qt 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4978
diff changeset
335 @type function
08eaee907686 Prepared the QWebEingine based web browser for the new runJavaScript() method as of Qt 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4978
diff changeset
336 """
7201
6b42677d7043 Modified sources to be in line with the minimum Qt/PyQt requirement (v 5.9.0).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7192
diff changeset
337 if worldId > -1:
5001
08eaee907686 Prepared the QWebEingine based web browser for the new runJavaScript() method as of Qt 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4978
diff changeset
338 if callback is None:
08eaee907686 Prepared the QWebEingine based web browser for the new runJavaScript() method as of Qt 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4978
diff changeset
339 QWebEnginePage.runJavaScript(self, script, worldId)
08eaee907686 Prepared the QWebEingine based web browser for the new runJavaScript() method as of Qt 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4978
diff changeset
340 else:
08eaee907686 Prepared the QWebEingine based web browser for the new runJavaScript() method as of Qt 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4978
diff changeset
341 QWebEnginePage.runJavaScript(self, script, worldId, callback)
08eaee907686 Prepared the QWebEingine based web browser for the new runJavaScript() method as of Qt 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4978
diff changeset
342 else:
08eaee907686 Prepared the QWebEingine based web browser for the new runJavaScript() method as of Qt 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4978
diff changeset
343 if callback is None:
08eaee907686 Prepared the QWebEingine based web browser for the new runJavaScript() method as of Qt 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4978
diff changeset
344 QWebEnginePage.runJavaScript(self, script)
08eaee907686 Prepared the QWebEingine based web browser for the new runJavaScript() method as of Qt 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4978
diff changeset
345 else:
08eaee907686 Prepared the QWebEingine based web browser for the new runJavaScript() method as of Qt 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4978
diff changeset
346 QWebEnginePage.runJavaScript(self, script, callback)
08eaee907686 Prepared the QWebEingine based web browser for the new runJavaScript() method as of Qt 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4978
diff changeset
347
4965
a9a4b632fe48 Some enhancements for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4964
diff changeset
348 def isJavaScriptEnabled(self):
a9a4b632fe48 Some enhancements for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4964
diff changeset
349 """
a9a4b632fe48 Some enhancements for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4964
diff changeset
350 Public method to test, if JavaScript is enabled.
a9a4b632fe48 Some enhancements for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4964
diff changeset
351
a9a4b632fe48 Some enhancements for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4964
diff changeset
352 @return flag indicating the state of the JavaScript support
a9a4b632fe48 Some enhancements for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4964
diff changeset
353 @rtype bool
a9a4b632fe48 Some enhancements for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4964
diff changeset
354 """
a9a4b632fe48 Some enhancements for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4964
diff changeset
355 return self.settings().testAttribute(
a9a4b632fe48 Some enhancements for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4964
diff changeset
356 QWebEngineSettings.JavascriptEnabled)
a9a4b632fe48 Some enhancements for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4964
diff changeset
357
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
358 def scroll(self, x, y):
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
359 """
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
360 Public method to scroll by the given amount of pixels.
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
361
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
362 @param x horizontal scroll value
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
363 @type int
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
364 @param y vertical scroll value
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
365 @type int
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
366 """
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
367 self.runJavaScript(
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
368 "window.scrollTo(window.scrollX + {0}, window.scrollY + {1})"
5001
08eaee907686 Prepared the QWebEingine based web browser for the new runJavaScript() method as of Qt 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4978
diff changeset
369 .format(x, y),
08eaee907686 Prepared the QWebEingine based web browser for the new runJavaScript() method as of Qt 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4978
diff changeset
370 WebBrowserPage.SafeJsWorld
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
371 )
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
372
5774
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
373 def scrollTo(self, pos):
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
374 """
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
375 Public method to scroll to the given position.
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
376
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
377 @param pos position to scroll to
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
378 @type QPointF
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
379 """
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
380 self.runJavaScript(
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
381 "window.scrollTo({0}, {1});".format(pos.x(), pos.y()),
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
382 WebBrowserPage.SafeJsWorld
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
383 )
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
384
4925
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
385 def mapToViewport(self, pos):
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
386 """
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
387 Public method to map a position to the viewport.
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
388
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
389 @param pos position to be mapped
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
390 @type QPoint
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
391 @return viewport position
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
392 @rtype QPoint
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
393 """
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
394 return QPoint(pos.x() // self.zoomFactor(),
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
395 pos.y() // self.zoomFactor())
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
396
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
397 def hitTestContent(self, pos):
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
398 """
4728
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
399 Public method to test the content at a specified position.
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
400
4728
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
401 @param pos position to execute the test at
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
402 @type QPoint
4728
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
403 @return test result object
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
404 @rtype WebHitTestResult
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
405 """
4728
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
406 return WebHitTestResult(self, pos)
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
407
6140
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
408 def __setupWebChannelForUrl(self, url):
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
409 """
4745
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4744
diff changeset
410 Private method to setup a web channel to our external object.
6140
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
411
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
412 @param url URL for which to setup the web channel
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
413 @type QUrl
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
414 """
6140
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
415 channel = self.webChannel()
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
416 if channel is None:
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
417 channel = QWebChannel(self)
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
418 ExternalJsObject.setupWebChannel(channel, self)
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
419
6140
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
420 worldId = -1
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
421 if url.scheme() in ("eric", "qthelp"):
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
422 worldId = self.UnsafeJsWorld
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
423 else:
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
424 worldId = self.SafeJsWorld
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
425 if worldId != self.__channelWorldId:
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
426 self.__channelWorldId = worldId
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
427 try:
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
428 self.setWebChannel(channel, self.__channelWorldId)
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
429 except TypeError:
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
430 # pre Qt 5.7.0
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
431 self.setWebChannel(channel)
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4717
diff changeset
432
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4717
diff changeset
433 def certificateError(self, error):
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4717
diff changeset
434 """
4726
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
435 Public method to handle SSL certificate errors.
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4717
diff changeset
436
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4717
diff changeset
437 @param error object containing the certificate error information
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4717
diff changeset
438 @type QWebEngineCertificateError
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4717
diff changeset
439 @return flag indicating to ignore this error
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4717
diff changeset
440 @rtype bool
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4717
diff changeset
441 """
4788
7076adec8ddd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4787
diff changeset
442 return WebBrowserWindow.networkManager().certificateError(
7076adec8ddd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4787
diff changeset
443 error, self.view())
4745
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4744
diff changeset
444
4884
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
445 def __fullScreenRequested(self, request):
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
446 """
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
447 Private slot handling a full screen request.
4917
682750cc7bd5 Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4913
diff changeset
448
682750cc7bd5 Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4913
diff changeset
449 @param request reference to the full screen request
682750cc7bd5 Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4913
diff changeset
450 @type QWebEngineFullScreenRequest
4884
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
451 """
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
452 self.view().requestFullScreen(request.toggleOn())
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
453
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
454 accepted = request.toggleOn() == self.view().isFullScreen()
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
455
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
456 if accepted:
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
457 request.accept()
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
458 else:
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
459 request.reject()
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
460
5534
f9368ecf153a Re-enabled the print preview function for all platforms and the print for Windows platforms for the new web browser and Qt >= 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5530
diff changeset
461 def execPrintPage(self, printer, timeout=1000):
5530
93f95c4b3153 Started upgrading the new web browser to the Qt 5.8 offerings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
462 """
5534
f9368ecf153a Re-enabled the print preview function for all platforms and the print for Windows platforms for the new web browser and Qt >= 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5530
diff changeset
463 Public method to execute a synchronous print.
5530
93f95c4b3153 Started upgrading the new web browser to the Qt 5.8 offerings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
464
93f95c4b3153 Started upgrading the new web browser to the Qt 5.8 offerings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
465 @param printer reference to the printer object
93f95c4b3153 Started upgrading the new web browser to the Qt 5.8 offerings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
466 @type QPrinter
5534
f9368ecf153a Re-enabled the print preview function for all platforms and the print for Windows platforms for the new web browser and Qt >= 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5530
diff changeset
467 @param timeout timeout value in milliseconds
f9368ecf153a Re-enabled the print preview function for all platforms and the print for Windows platforms for the new web browser and Qt >= 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5530
diff changeset
468 @type int
f9368ecf153a Re-enabled the print preview function for all platforms and the print for Windows platforms for the new web browser and Qt >= 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5530
diff changeset
469 @return flag indicating a successful print job
f9368ecf153a Re-enabled the print preview function for all platforms and the print for Windows platforms for the new web browser and Qt >= 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5530
diff changeset
470 @rtype bool
5530
93f95c4b3153 Started upgrading the new web browser to the Qt 5.8 offerings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
471 """
5534
f9368ecf153a Re-enabled the print preview function for all platforms and the print for Windows platforms for the new web browser and Qt >= 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5530
diff changeset
472 loop = QEventLoop()
f9368ecf153a Re-enabled the print preview function for all platforms and the print for Windows platforms for the new web browser and Qt >= 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5530
diff changeset
473 resultDict = {"res": None}
f9368ecf153a Re-enabled the print preview function for all platforms and the print for Windows platforms for the new web browser and Qt >= 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5530
diff changeset
474 QTimer.singleShot(timeout, loop.quit)
5530
93f95c4b3153 Started upgrading the new web browser to the Qt 5.8 offerings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
475
5534
f9368ecf153a Re-enabled the print preview function for all platforms and the print for Windows platforms for the new web browser and Qt >= 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5530
diff changeset
476 def printCallback(res, resDict=resultDict):
f9368ecf153a Re-enabled the print preview function for all platforms and the print for Windows platforms for the new web browser and Qt >= 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5530
diff changeset
477 if loop and loop.isRunning():
f9368ecf153a Re-enabled the print preview function for all platforms and the print for Windows platforms for the new web browser and Qt >= 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5530
diff changeset
478 resDict["res"] = res
f9368ecf153a Re-enabled the print preview function for all platforms and the print for Windows platforms for the new web browser and Qt >= 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5530
diff changeset
479 loop.quit()
f9368ecf153a Re-enabled the print preview function for all platforms and the print for Windows platforms for the new web browser and Qt >= 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5530
diff changeset
480
f9368ecf153a Re-enabled the print preview function for all platforms and the print for Windows platforms for the new web browser and Qt >= 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5530
diff changeset
481 self.print(printer, printCallback)
f9368ecf153a Re-enabled the print preview function for all platforms and the print for Windows platforms for the new web browser and Qt >= 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5530
diff changeset
482
7759
51aa6c6b66f7 Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7540
diff changeset
483 loop.exec()
5534
f9368ecf153a Re-enabled the print preview function for all platforms and the print for Windows platforms for the new web browser and Qt >= 5.8.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5530
diff changeset
484 return resultDict["res"]
5530
93f95c4b3153 Started upgrading the new web browser to the Qt 5.8 offerings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
485
6692
c104c120e043 Web Browser (NG): some compatibility changes for Qt 5.12.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6662
diff changeset
486 def __contentsSizeChanged(self, size):
c104c120e043 Web Browser (NG): some compatibility changes for Qt 5.12.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6662
diff changeset
487 """
c104c120e043 Web Browser (NG): some compatibility changes for Qt 5.12.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6662
diff changeset
488 Private slot to work around QWebEnginePage not scrolling to anchors
c104c120e043 Web Browser (NG): some compatibility changes for Qt 5.12.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6662
diff changeset
489 when opened in a background tab.
c104c120e043 Web Browser (NG): some compatibility changes for Qt 5.12.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6662
diff changeset
490
c104c120e043 Web Browser (NG): some compatibility changes for Qt 5.12.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6662
diff changeset
491 @param size changed contents size (unused)
c104c120e043 Web Browser (NG): some compatibility changes for Qt 5.12.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6662
diff changeset
492 @type QSize
c104c120e043 Web Browser (NG): some compatibility changes for Qt 5.12.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6662
diff changeset
493 """
c104c120e043 Web Browser (NG): some compatibility changes for Qt 5.12.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6662
diff changeset
494 fragment = self.url().fragment()
c104c120e043 Web Browser (NG): some compatibility changes for Qt 5.12.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6662
diff changeset
495 self.runJavaScript(Scripts.scrollToAnchor(fragment))
c104c120e043 Web Browser (NG): some compatibility changes for Qt 5.12.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6662
diff changeset
496
4745
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4744
diff changeset
497 ##############################################
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4744
diff changeset
498 ## Methods below deal with JavaScript messages
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4744
diff changeset
499 ##############################################
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4744
diff changeset
500
4917
682750cc7bd5 Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4913
diff changeset
501 def javaScriptConsoleMessage(self, level, message, lineNumber, sourceId):
4822
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
502 """
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
503 Public method to show a console message.
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
504
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
505 @param level severity
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
506 @type QWebEnginePage.JavaScriptConsoleMessageLevel
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
507 @param message message to be shown
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
508 @type str
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
509 @param lineNumber line number of an error
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
510 @type int
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
511 @param sourceId source URL causing the error
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
512 @type str
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
513 """
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
514 self.view().mainWindow().javascriptConsole().javaScriptConsoleMessage(
4917
682750cc7bd5 Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4913
diff changeset
515 level, message, lineNumber, sourceId)
5113
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5009
diff changeset
516
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
517 ###########################################################################
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
518 ## Methods below implement safe browsing related functions
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
519 ###########################################################################
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
520
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
521 def getSafeBrowsingStatus(self):
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
522 """
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
523 Public method to get the safe browsing status of the current page.
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
524
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
525 @return flag indicating a safe site
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
526 @rtype bool
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
527 """
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
528 return not self.__badSite
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
529
5113
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5009
diff changeset
530 ##################################################
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5009
diff changeset
531 ## Methods below implement compatibility functions
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5009
diff changeset
532 ##################################################
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5009
diff changeset
533
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5009
diff changeset
534 if not hasattr(QWebEnginePage, "icon"):
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5009
diff changeset
535 def icon(self):
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5009
diff changeset
536 """
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5009
diff changeset
537 Public method to get the web site icon.
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5009
diff changeset
538
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5009
diff changeset
539 @return web site icon
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5009
diff changeset
540 @rtype QIcon
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5009
diff changeset
541 """
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5009
diff changeset
542 return self.view().icon()
5774
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
543
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
544 if not hasattr(QWebEnginePage, "scrollPosition"):
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
545 def scrollPosition(self):
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
546 """
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
547 Public method to get the scroll position of the web page.
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
548
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
549 @return scroll position
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
550 @rtype QPointF
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
551 """
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
552 pos = self.execJavaScript(
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
553 "(function() {"
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
554 "var res = {"
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
555 " x: 0,"
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
556 " y: 0,"
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
557 "};"
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
558 "res.x = window.scrollX;"
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
559 "res.y = window.scrollY;"
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
560 "return res;"
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
561 "})()",
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
562 WebBrowserPage.SafeJsWorld
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
563 )
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
564 if pos is not None:
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
565 pos = QPointF(pos["x"], pos["y"])
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
566 else:
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
567 pos = QPointF(0.0, 0.0)
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
568
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
569 return pos
6695
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
570
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
571 #############################################################
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
572 ## Methods below implement protocol handler related functions
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
573 #############################################################
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
574
6776
298b03ba2990 WebBrowserPage: fixed a TypeError caused by code specific to Qt 5.12 and newer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6695
diff changeset
575 try:
298b03ba2990 WebBrowserPage: fixed a TypeError caused by code specific to Qt 5.12 and newer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6695
diff changeset
576 @pyqtSlot("QWebEngineRegisterProtocolHandlerRequest")
298b03ba2990 WebBrowserPage: fixed a TypeError caused by code specific to Qt 5.12 and newer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6695
diff changeset
577 def __registerProtocolHandlerRequested(self, request):
298b03ba2990 WebBrowserPage: fixed a TypeError caused by code specific to Qt 5.12 and newer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6695
diff changeset
578 """
6789
6bafe4f7d5f0 Fixed some code style issues (lines too long).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6776
diff changeset
579 Private slot to handle the registration of a custom protocol
6bafe4f7d5f0 Fixed some code style issues (lines too long).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6776
diff changeset
580 handler.
6776
298b03ba2990 WebBrowserPage: fixed a TypeError caused by code specific to Qt 5.12 and newer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6695
diff changeset
581
298b03ba2990 WebBrowserPage: fixed a TypeError caused by code specific to Qt 5.12 and newer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6695
diff changeset
582 @param request reference to the registration request
298b03ba2990 WebBrowserPage: fixed a TypeError caused by code specific to Qt 5.12 and newer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6695
diff changeset
583 @type QWebEngineRegisterProtocolHandlerRequest
298b03ba2990 WebBrowserPage: fixed a TypeError caused by code specific to Qt 5.12 and newer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6695
diff changeset
584 """
7271
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
585 from PyQt5.QtWebEngineCore import (
6776
298b03ba2990 WebBrowserPage: fixed a TypeError caused by code specific to Qt 5.12 and newer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6695
diff changeset
586 QWebEngineRegisterProtocolHandlerRequest
7271
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
587 )
6776
298b03ba2990 WebBrowserPage: fixed a TypeError caused by code specific to Qt 5.12 and newer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6695
diff changeset
588
298b03ba2990 WebBrowserPage: fixed a TypeError caused by code specific to Qt 5.12 and newer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6695
diff changeset
589 if self.__registerProtocolHandlerRequest:
298b03ba2990 WebBrowserPage: fixed a TypeError caused by code specific to Qt 5.12 and newer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6695
diff changeset
590 del self.__registerProtocolHandlerRequest
298b03ba2990 WebBrowserPage: fixed a TypeError caused by code specific to Qt 5.12 and newer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6695
diff changeset
591 self.__registerProtocolHandlerRequest = None
7271
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
592 self.__registerProtocolHandlerRequest = (
6776
298b03ba2990 WebBrowserPage: fixed a TypeError caused by code specific to Qt 5.12 and newer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6695
diff changeset
593 QWebEngineRegisterProtocolHandlerRequest(request)
7271
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
594 )
6776
298b03ba2990 WebBrowserPage: fixed a TypeError caused by code specific to Qt 5.12 and newer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6695
diff changeset
595 except TypeError:
298b03ba2990 WebBrowserPage: fixed a TypeError caused by code specific to Qt 5.12 and newer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6695
diff changeset
596 # this is supported with Qt 5.12 and later
298b03ba2990 WebBrowserPage: fixed a TypeError caused by code specific to Qt 5.12 and newer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6695
diff changeset
597 pass
6695
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
598
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
599 def registerProtocolHandlerRequestUrl(self):
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
600 """
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
601 Public method to get the registered protocol handler request URL.
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
602
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
603 @return registered protocol handler request URL
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
604 @rtype QUrl
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
605 """
7271
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
606 if (
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
607 self.__registerProtocolHandlerRequest and
6695
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
608 (self.url().host() ==
7271
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
609 self.__registerProtocolHandlerRequest.origin().host())
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
610 ):
6695
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
611 return self.__registerProtocolHandlerRequest.origin()
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
612 else:
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
613 return QUrl()
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
614
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
615 def registerProtocolHandlerRequestScheme(self):
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
616 """
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
617 Public method to get the registered protocol handler request scheme.
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
618
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
619 @return registered protocol handler request scheme
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
620 @rtype str
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
621 """
7271
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
622 if (
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
623 self.__registerProtocolHandlerRequest and
6695
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
624 (self.url().host() ==
7271
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
625 self.__registerProtocolHandlerRequest.origin().host())
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
626 ):
6695
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
627 return self.__registerProtocolHandlerRequest.scheme()
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
628 else:
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
629 return ""
7766
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
630
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
631 #############################################################
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
632 ## SSL configuration handling below
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
633 #############################################################
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
634
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
635 def setSslConfiguration(self, sslConfiguration):
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
636 """
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
637 Public slot to set the SSL configuration data of the page.
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
638
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
639 @param sslConfiguration SSL configuration to be set
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
640 @type QSslConfiguration
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
641 """
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
642 self.__sslConfiguration = QSslConfiguration(sslConfiguration)
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
643 self.__sslConfiguration.url = self.url()
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
644 self.sslConfigurationChanged.emit()
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
645
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
646 def getSslConfiguration(self):
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
647 """
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
648 Public method to return a reference to the current SSL configuration.
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
649
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
650 @return reference to the SSL configuration in use
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
651 @rtype QSslConfiguration
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
652 """
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
653 return self.__sslConfiguration
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
654
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
655 def clearSslConfiguration(self):
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
656 """
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
657 Public slot to clear the stored SSL configuration data.
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
658 """
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
659 self.__sslConfiguration = None
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
660 self.sslConfigurationChanged.emit()
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
661
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
662 def getSslCertificate(self):
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
663 """
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
664 Public method to get a reference to the SSL certificate.
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
665
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
666 @return amended SSL certificate
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
667 @rtype QSslCertificate
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
668 """
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
669 if self.__sslConfiguration is None:
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
670 return None
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
671
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
672 sslCertificate = self.__sslConfiguration.peerCertificate()
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
673 sslCertificate.url = QUrl(self.__sslConfiguration.url)
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
674 return sslCertificate
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
675
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
676 def getSslCertificateChain(self):
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
677 """
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
678 Public method to get a reference to the SSL certificate chain.
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
679
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
680 @return SSL certificate chain
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
681 @rtype list of QSslCertificate
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
682 """
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
683 if self.__sslConfiguration is None:
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
684 return []
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
685
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
686 chain = self.__sslConfiguration.peerCertificateChain()
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
687 return chain
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
688
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
689 def showSslInfo(self, pos):
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
690 """
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
691 Public slot to show some SSL information for the loaded page.
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
692
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
693 @param pos position to show the info at
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
694 @type QPoint
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
695 """
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
696 if SSL_AVAILABLE and self.__sslConfiguration is not None:
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
697 from E5Network.E5SslInfoWidget import E5SslInfoWidget
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
698 widget = E5SslInfoWidget(self.url(), self.__sslConfiguration,
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
699 self.view())
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
700 widget.showAt(pos)
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
701 else:
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
702 E5MessageBox.warning(
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
703 self.view(),
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
704 self.tr("SSL Info"),
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
705 self.tr("""This site does not contain SSL information."""))
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
706
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
707 def hasValidSslInfo(self):
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
708 """
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
709 Public method to check, if the page has a valid SSL certificate.
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
710
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
711 @return flag indicating a valid SSL certificate
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
712 @rtype bool
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
713 """
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
714 if self.__sslConfiguration is None:
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
715 return False
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
716
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
717 certList = self.__sslConfiguration.peerCertificateChain()
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
718 if not certList:
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
719 return False
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
720
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
721 certificateDict = Globals.toDict(
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
722 Preferences.Prefs.settings.value("Ssl/CaCertificatesDict"))
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
723 for server in certificateDict:
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
724 localCAList = QSslCertificate.fromData(certificateDict[server])
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
725 for cert in certList:
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
726 if cert in localCAList:
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
727 return True
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
728
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
729 for cert in certList:
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
730 if cert.isBlacklisted():
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
731 return False
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
732
0af772bc14c4 Web Browser
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
733 return True

eric ide

mercurial