eric6/WebBrowser/WebBrowserPage.py

Sun, 02 Feb 2020 11:04:32 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 02 Feb 2020 11:04:32 +0100
changeset 7380
c99320e859ca
parent 7366
bd743eacfbca
child 7540
7a44cb47054b
permissions
-rw-r--r--

Fixed an issue related to showing the application name in the menu bar of Gnome desktop under Wayland.

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
7360
9190402e4505 Updated copyright for 2020.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7271
diff changeset
3 # Copyright (c) 2008 - 2020 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
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
26 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
27
4788
7076adec8ddd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4787
diff changeset
28 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
29
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
30 from .JavaScript.ExternalJsObject import ExternalJsObject
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
31
4728
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
32 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
33 from .Tools import Scripts
4728
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
34
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 import Preferences
1960
d8c45fe8a1b9 Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1953
diff changeset
36
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 923
diff changeset
37
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
38 class WebBrowserPage(QWebEnginePage):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 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
41
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
42 @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
43 browsing event
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
44 @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
45 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
46 @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
47 shown web page
6149
e611e45a17d6 Fixed a few code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6146
diff changeset
48 @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
49 to signal an accepted navigation request
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 """
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
51 SafeJsWorld = QWebEngineScript.ApplicationWorld
6140
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
52 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
53
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
54 safeBrowsingAbort = pyqtSignal()
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
55 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
56
6656
273a2130adbe WebBrowserPage: added support for the printRequested signal as of Qt 5.12.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
57 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
58 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
59 bool)
6142
304a469455c8 Added support for printing from within a web page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6140
diff changeset
60
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 923
diff changeset
61 def __init__(self, parent=None):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 Constructor
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 @param parent parent widget of this window (QWidget)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 """
4788
7076adec8ddd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4787
diff changeset
67 super(WebBrowserPage, self).__init__(
7076adec8ddd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4787
diff changeset
68 WebBrowserWindow.webProfile(), parent)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69
6695
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
70 self.__printer = None
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
71 self.__badSite = False
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
72 self.__registerProtocolHandlerRequest = None
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
73
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
74 self.featurePermissionRequested.connect(
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
75 self.__featurePermissionRequested)
4743
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4742
diff changeset
76 self.authenticationRequired.connect(
6120
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6093
diff changeset
77 lambda url, auth: WebBrowserWindow.networkManager().authentication(
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6093
diff changeset
78 url, auth, self))
4787
2a19edf4db14 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4768
diff changeset
79 self.proxyAuthenticationRequired.connect(
4788
7076adec8ddd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4787
diff changeset
80 WebBrowserWindow.networkManager().proxyAuthentication)
4884
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
81 self.fullScreenRequested.connect(self.__fullScreenRequested)
4964
a894e8c92369 Implemented the JavaScript status bar icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4925
diff changeset
82 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
83 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
84
6695
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
85 try:
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
86 self.registerProtocolHandlerRequested.connect(
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
87 self.__registerProtocolHandlerRequested)
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
88 except AttributeError:
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
89 # defined for Qt >= 5.11
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
90 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
91
6140
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
92 # Workaround for changing webchannel world inside
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
93 # acceptNavigationRequest not working
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
94 self.__channelUrl = QUrl()
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
95 self.__channelWorldId = -1
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
96 self.__setupChannelTimer = QTimer(self)
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
97 self.__setupChannelTimer.setSingleShot(True)
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
98 self.__setupChannelTimer.setInterval(100)
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
99 self.__setupChannelTimer.timeout.connect(self.__setupChannelTimeout)
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
100
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
101 @pyqtSlot()
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
102 def __setupChannelTimeout(self):
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
103 """
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
104 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
105 """
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
106 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
107
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
108 def acceptNavigationRequest(self, url, type_, isMainFrame):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 """
4726
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
110 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
111
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
112 @param url URL to navigate to
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
113 @type QUrl
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
114 @param type_ type of the navigation request
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
115 @type QWebEnginePage.NavigationType
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
116 @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
117 the main frame
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
118 @type bool
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
119 @return flag indicating acceptance
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
120 @rtype bool
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 """
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
122 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
123 if scheme == "mailto":
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
124 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
125 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
126
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
127 # AdBlock
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
128 if url.scheme() == "abp":
4788
7076adec8ddd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4787
diff changeset
129 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
130 return False
4886
b56735d36159 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
131
5716
27a7c7064686 Improved installion of GreaseMonkey user scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5624
diff changeset
132 # GreaseMonkey
7366
bd743eacfbca Changed code to avoid some obsoleted Qt functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
133 if PYQT_WEBENGINE_VERSION >= 0x50e00: # PyQtWebEngine >= 5.14.0
bd743eacfbca Changed code to avoid some obsoleted Qt functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
134 navigationType = type_ in [
bd743eacfbca Changed code to avoid some obsoleted Qt functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
135 QWebEnginePage.NavigationTypeLinkClicked,
bd743eacfbca Changed code to avoid some obsoleted Qt functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
136 QWebEnginePage.NavigationTypeRedirect
bd743eacfbca Changed code to avoid some obsoleted Qt functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
137 ]
bd743eacfbca Changed code to avoid some obsoleted Qt functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
138 else:
bd743eacfbca Changed code to avoid some obsoleted Qt functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
139 navigationType = type_ == QWebEnginePage.NavigationTypeLinkClicked
bd743eacfbca Changed code to avoid some obsoleted Qt functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
140 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
141 WebBrowserWindow.greaseMonkeyManager().downloadScript(url)
27a7c7064686 Improved installion of GreaseMonkey user scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5624
diff changeset
142 return False
27a7c7064686 Improved installion of GreaseMonkey user scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5624
diff changeset
143
6142
304a469455c8 Added support for printing from within a web page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6140
diff changeset
144 if url.scheme() == "eric":
6174
bb2989d750ce WebBrowser: Fixed some sender() related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6149
diff changeset
145 if url.path() == "AddSearchProvider":
bb2989d750ce WebBrowser: Fixed some sender() related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6149
diff changeset
146 query = QUrlQuery(url)
bb2989d750ce WebBrowser: Fixed some sender() related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6149
diff changeset
147 self.view().mainWindow().openSearchManager().addEngine(
bb2989d750ce WebBrowser: Fixed some sender() related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6149
diff changeset
148 QUrl(query.queryItemValue("url")))
bb2989d750ce WebBrowser: Fixed some sender() related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6149
diff changeset
149 return False
bb2989d750ce WebBrowser: Fixed some sender() related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6149
diff changeset
150 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
151 self.printPageRequested.emit()
6142
304a469455c8 Added support for printing from within a web page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6140
diff changeset
152 return False
304a469455c8 Added support for printing from within a web page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6140
diff changeset
153
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
154 # Safe Browsing
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
155 self.__badSite = False
7271
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
156 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
157 SafeBrowsingManager
7271
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
158 )
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
159 if (
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
160 SafeBrowsingManager.isEnabled() and
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
161 url.scheme() not in SafeBrowsingManager.getIgnoreSchemes()
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
162 ):
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
163 threatLists = (
6234
fb1f9e681848 Web Browser NG, Safe Browsing: improved error handling
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6233
diff changeset
164 WebBrowserWindow.safeBrowsingManager().lookupUrl(url)[0]
7271
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
165 )
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
166 if threatLists:
7271
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
167 threatMessages = (
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
168 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
169 .getThreatMessages(threatLists)
7271
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
170 )
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
171 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
172 WebBrowserWindow.getWindow(),
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
173 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
174 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
175 " 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
176 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
177 E5MessageBox.StandardButtons(
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
178 E5MessageBox.Abort |
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
179 E5MessageBox.Ignore),
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
180 E5MessageBox.Abort)
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
181 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
182 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
183 return False
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
184
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
185 self.__badSite = True
7271
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
186 threatType = (
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
187 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
188 .getThreatType(threatLists[0])
7271
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
189 )
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
190 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
191
7366
bd743eacfbca Changed code to avoid some obsoleted Qt functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
192 result = QWebEnginePage.acceptNavigationRequest(
bd743eacfbca Changed code to avoid some obsoleted Qt functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
193 self, url, type_, isMainFrame)
6137
27962f3f457f Some minor changes in the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6136
diff changeset
194
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
195 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
196 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
197 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
198 "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
199 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
200 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
201 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
202 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
203 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
204 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
205 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
206 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
207
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
208 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
209 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
210 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
211
27962f3f457f Some minor changes in the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6136
diff changeset
212 return result
487
4d41d03d3d00 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 383
diff changeset
213
4964
a894e8c92369 Implemented the JavaScript status bar icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4925
diff changeset
214 @pyqtSlot(QUrl)
a894e8c92369 Implemented the JavaScript status bar icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4925
diff changeset
215 def __urlChanged(self, url):
a894e8c92369 Implemented the JavaScript status bar icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4925
diff changeset
216 """
a894e8c92369 Implemented the JavaScript status bar icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4925
diff changeset
217 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
218
a894e8c92369 Implemented the JavaScript status bar icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4925
diff changeset
219 @param url new URL
a894e8c92369 Implemented the JavaScript status bar icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4925
diff changeset
220 @type QUrl
a894e8c92369 Implemented the JavaScript status bar icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4925
diff changeset
221 """
7271
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
222 if (
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
223 not url.isEmpty() and
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
224 url.scheme() == "eric" and
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
225 not self.isJavaScriptEnabled()
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
226 ):
6136
dfef226f9c7f Removed WebBrowserPage.setJavaScriptEnabled().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6127
diff changeset
227 self.settings().setAttribute(QWebEngineSettings.JavascriptEnabled,
dfef226f9c7f Removed WebBrowserPage.setJavaScriptEnabled().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6127
diff changeset
228 True)
4965
a9a4b632fe48 Some enhancements for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4964
diff changeset
229 self.triggerAction(QWebEnginePage.Reload)
4964
a894e8c92369 Implemented the JavaScript status bar icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4925
diff changeset
230
4906
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
231 @classmethod
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
232 def userAgent(cls, resolveEmpty=False):
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
233 """
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
234 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
235
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
236 @param resolveEmpty flag indicating to resolve an empty
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
237 user agent (boolean)
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
238 @return user agent string (string)
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
239 """
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
240 agent = Preferences.getWebBrowser("UserAgent")
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
241 if agent == "" and resolveEmpty:
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
242 agent = cls.userAgentForUrl(QUrl())
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
243 return agent
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
244
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 setUserAgent(cls, agent):
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 set the global user agent string.
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 agent new current user agent string (string)
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
251 """
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
252 Preferences.setWebBrowser("UserAgent", agent)
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 @classmethod
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
255 def userAgentForUrl(cls, url):
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
256 """
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
257 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
258
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
259 @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
260 @return user agent string (string)
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 agent = WebBrowserWindow.userAgentsManager().userAgentForUrl(url)
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
263 if agent == "":
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
264 # 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
265 agent = Preferences.getWebBrowser("UserAgent")
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
266 if agent == "":
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
267 # no global agent string specified -> use default one
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
268 agent = WebBrowserWindow.webProfile().httpUserAgent()
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
269 return agent
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
270
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
271 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
272 """
493891cbacee Added support for feature permissions to the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4275
diff changeset
273 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
274
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
275 @param url url requesting the feature
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
276 @type QUrl
4316
493891cbacee Added support for feature permissions to the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4275
diff changeset
277 @param feature requested feature
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
278 @type QWebEnginePage.Feature
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
279 """
4788
7076adec8ddd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4787
diff changeset
280 manager = WebBrowserWindow.featurePermissionManager()
4742
f9d1090f6ab9 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
281 manager.requestFeaturePermission(self, url, feature)
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
282
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
283 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
284 timeout=500):
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
285 """
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
286 Public method to execute a JavaScript function synchroneously.
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
287
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
288 @param script JavaScript script source to be executed
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
289 @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
290 @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
291 @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
292 @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
293 @type int
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
294 @return result of the script
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
295 @rtype depending upon script result
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
296 """
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
297 loop = QEventLoop()
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
298 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
299 QTimer.singleShot(timeout, loop.quit)
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
300
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
301 def resultCallback(res, resDict=resultDict):
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
302 if loop and loop.isRunning():
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
303 resDict["res"] = res
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
304 loop.quit()
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
305
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
306 self.runJavaScript(script, worldId, resultCallback)
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
307
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
308 loop.exec_()
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
309 return resultDict["res"]
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
310
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
311 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
312 """
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 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
314
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
315 @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
316 @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
317 @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
318 @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
319 @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
320 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
321 @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
322 """
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
323 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
324 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
325 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
326 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
327 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
328 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
329 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
330 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
331 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
332 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
333
4965
a9a4b632fe48 Some enhancements for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4964
diff changeset
334 def isJavaScriptEnabled(self):
a9a4b632fe48 Some enhancements for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4964
diff changeset
335 """
a9a4b632fe48 Some enhancements for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4964
diff changeset
336 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
337
a9a4b632fe48 Some enhancements for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4964
diff changeset
338 @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
339 @rtype bool
a9a4b632fe48 Some enhancements for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4964
diff changeset
340 """
a9a4b632fe48 Some enhancements for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4964
diff changeset
341 return self.settings().testAttribute(
a9a4b632fe48 Some enhancements for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4964
diff changeset
342 QWebEngineSettings.JavascriptEnabled)
a9a4b632fe48 Some enhancements for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4964
diff changeset
343
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
344 def scroll(self, x, y):
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
345 """
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
346 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
347
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
348 @param x horizontal scroll value
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
349 @type int
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
350 @param y vertical scroll value
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
351 @type int
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
352 """
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
353 self.runJavaScript(
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
354 "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
355 .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
356 WebBrowserPage.SafeJsWorld
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
357 )
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
358
5774
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
359 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
360 """
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
361 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
362
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
363 @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
364 @type QPointF
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
365 """
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
366 self.runJavaScript(
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
367 "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
368 WebBrowserPage.SafeJsWorld
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
369 )
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
370
4925
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
371 def mapToViewport(self, pos):
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
372 """
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
373 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
374
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
375 @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
376 @type QPoint
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
377 @return viewport position
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
378 @rtype QPoint
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
379 """
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
380 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
381 pos.y() // self.zoomFactor())
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
382
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
383 def hitTestContent(self, pos):
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
384 """
4728
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
385 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
386
4728
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
387 @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
388 @type QPoint
4728
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
389 @return test result object
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
390 @rtype WebHitTestResult
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
391 """
4728
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
392 return WebHitTestResult(self, pos)
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
393
6140
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
394 def __setupWebChannelForUrl(self, url):
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
395 """
4745
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4744
diff changeset
396 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
397
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
398 @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
399 @type QUrl
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
400 """
6140
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
401 channel = self.webChannel()
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
402 if channel is None:
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
403 channel = QWebChannel(self)
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
404 ExternalJsObject.setupWebChannel(channel, self)
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
405
6140
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
406 worldId = -1
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
407 if url.scheme() in ("eric", "qthelp"):
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
408 worldId = self.UnsafeJsWorld
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
409 else:
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
410 worldId = self.SafeJsWorld
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
411 if worldId != self.__channelWorldId:
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
412 self.__channelWorldId = worldId
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
413 try:
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
414 self.setWebChannel(channel, self.__channelWorldId)
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
415 except TypeError:
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
416 # pre Qt 5.7.0
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
417 self.setWebChannel(channel)
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4717
diff changeset
418
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4717
diff changeset
419 def certificateError(self, error):
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4717
diff changeset
420 """
4726
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
421 Public method to handle SSL certificate errors.
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4717
diff changeset
422
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4717
diff changeset
423 @param error object containing the certificate error information
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4717
diff changeset
424 @type QWebEngineCertificateError
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4717
diff changeset
425 @return flag indicating to ignore this error
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4717
diff changeset
426 @rtype bool
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4717
diff changeset
427 """
4788
7076adec8ddd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4787
diff changeset
428 return WebBrowserWindow.networkManager().certificateError(
7076adec8ddd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4787
diff changeset
429 error, self.view())
4745
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4744
diff changeset
430
4884
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
431 def __fullScreenRequested(self, request):
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
432 """
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
433 Private slot handling a full screen request.
4917
682750cc7bd5 Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4913
diff changeset
434
682750cc7bd5 Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4913
diff changeset
435 @param request reference to the full screen request
682750cc7bd5 Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4913
diff changeset
436 @type QWebEngineFullScreenRequest
4884
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
437 """
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
438 self.view().requestFullScreen(request.toggleOn())
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
439
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
440 accepted = request.toggleOn() == self.view().isFullScreen()
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
441
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
442 if accepted:
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
443 request.accept()
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
444 else:
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
445 request.reject()
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
446
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
447 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
448 """
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
449 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
450
93f95c4b3153 Started upgrading the new web browser to the Qt 5.8 offerings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
451 @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
452 @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
453 @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
454 @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
455 @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
456 @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
457 """
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
458 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
459 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
460 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
461
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
462 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
463 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
464 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
465 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
466
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 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
468
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 loop.exec_()
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 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
471
6692
c104c120e043 Web Browser (NG): some compatibility changes for Qt 5.12.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6662
diff changeset
472 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
473 """
c104c120e043 Web Browser (NG): some compatibility changes for Qt 5.12.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6662
diff changeset
474 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
475 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
476
c104c120e043 Web Browser (NG): some compatibility changes for Qt 5.12.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6662
diff changeset
477 @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
478 @type QSize
c104c120e043 Web Browser (NG): some compatibility changes for Qt 5.12.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6662
diff changeset
479 """
c104c120e043 Web Browser (NG): some compatibility changes for Qt 5.12.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6662
diff changeset
480 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
481 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
482
4745
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4744
diff changeset
483 ##############################################
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4744
diff changeset
484 ## Methods below deal with JavaScript messages
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4744
diff changeset
485 ##############################################
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4744
diff changeset
486
4917
682750cc7bd5 Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4913
diff changeset
487 def javaScriptConsoleMessage(self, level, message, lineNumber, sourceId):
4822
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
488 """
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
489 Public method to show a console message.
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
490
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
491 @param level severity
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
492 @type QWebEnginePage.JavaScriptConsoleMessageLevel
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
493 @param message message to be shown
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
494 @type str
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
495 @param lineNumber line number of an error
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
496 @type int
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
497 @param sourceId source URL causing the error
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
498 @type str
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
499 """
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
500 self.view().mainWindow().javascriptConsole().javaScriptConsoleMessage(
4917
682750cc7bd5 Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4913
diff changeset
501 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
502
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
503 ###########################################################################
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
504 ## 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
505 ###########################################################################
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
506
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
507 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
508 """
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
509 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
510
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
511 @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
512 @rtype bool
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
513 """
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
514 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
515
5113
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5009
diff changeset
516 ##################################################
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5009
diff changeset
517 ## 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
518 ##################################################
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5009
diff changeset
519
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5009
diff changeset
520 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
521 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
522 """
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5009
diff changeset
523 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
524
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5009
diff changeset
525 @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
526 @rtype QIcon
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5009
diff changeset
527 """
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5009
diff changeset
528 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
529
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
530 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
531 def scrollPosition(self):
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
532 """
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
533 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
534
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
535 @return scroll position
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
536 @rtype QPointF
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
537 """
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
538 pos = self.execJavaScript(
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
539 "(function() {"
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
540 "var res = {"
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
541 " x: 0,"
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
542 " y: 0,"
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 "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
545 "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
546 "return res;"
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
547 "})()",
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
548 WebBrowserPage.SafeJsWorld
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
549 )
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
550 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
551 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
552 else:
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
553 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
554
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
555 return pos
6695
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
556
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
557 #############################################################
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
558 ## Methods below implement protocol handler related functions
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
559 #############################################################
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
560
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
561 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
562 @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
563 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
564 """
6789
6bafe4f7d5f0 Fixed some code style issues (lines too long).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6776
diff changeset
565 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
566 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
567
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
568 @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
569 @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
570 """
7271
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
571 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
572 QWebEngineRegisterProtocolHandlerRequest
7271
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
573 )
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
574
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 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
576 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
577 self.__registerProtocolHandlerRequest = None
7271
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
578 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
579 QWebEngineRegisterProtocolHandlerRequest(request)
7271
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
580 )
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 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
582 # 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
583 pass
6695
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
584
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
585 def registerProtocolHandlerRequestUrl(self):
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
586 """
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
587 Public method to get the registered protocol handler request URL.
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
588
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
589 @return registered protocol handler request URL
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
590 @rtype QUrl
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
591 """
7271
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
592 if (
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
593 self.__registerProtocolHandlerRequest and
6695
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
594 (self.url().host() ==
7271
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
595 self.__registerProtocolHandlerRequest.origin().host())
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
596 ):
6695
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
597 return self.__registerProtocolHandlerRequest.origin()
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
598 else:
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
599 return QUrl()
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 def registerProtocolHandlerRequestScheme(self):
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 Public method to get the registered protocol handler request scheme.
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
604
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
605 @return registered protocol handler request scheme
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
606 @rtype str
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
607 """
7271
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
608 if (
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
609 self.__registerProtocolHandlerRequest and
6695
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
610 (self.url().host() ==
7271
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
611 self.__registerProtocolHandlerRequest.origin().host())
2cac5b7abcce Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7249
diff changeset
612 ):
6695
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
613 return self.__registerProtocolHandlerRequest.scheme()
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
614 else:
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6692
diff changeset
615 return ""

eric ide

mercurial