WebBrowser/WebBrowserPage.py

Thu, 10 Jan 2019 14:18:48 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Thu, 10 Jan 2019 14:18:48 +0100
changeset 6645
ad476851d7e0
parent 6496
191c2289593e
child 6656
273a2130adbe
permissions
-rw-r--r--

Updated copyright for 2019.

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
6645
ad476851d7e0 Updated copyright for 2019.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6496
diff changeset
3 # Copyright (c) 2008 - 2019 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
6496
191c2289593e WebBrowserPage: added 'print_function' to the future statement to get rid of a (false) syntax error on Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6410
diff changeset
11 from __future__ import unicode_literals, print_function
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2432
diff changeset
12 try:
5624
cdd346d8858b Removed a bunch of __IGNORE_WARNING_M131__ markers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
13 str = unicode # __IGNORE_EXCEPTION__
3484
645c12de6b0c Merge with default branch.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3178 3190
diff changeset
14 except NameError:
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2432
diff changeset
15 pass
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2432
diff changeset
16
6174
bb2989d750ce WebBrowser: Fixed some sender() related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6149
diff changeset
17 from PyQt5.QtCore import pyqtSlot, pyqtSignal, QUrl, QUrlQuery, QTimer, \
bb2989d750ce WebBrowser: Fixed some sender() related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6149
diff changeset
18 QEventLoop, QPoint, QPointF
4913
e16573640cb8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4910
diff changeset
19 from PyQt5.QtGui import QDesktopServices
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
20 from PyQt5.QtWebEngineWidgets import QWebEnginePage, QWebEngineSettings, \
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
21 QWebEngineScript
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
22 from PyQt5.QtWebChannel import QWebChannel
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
24 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
25
4788
7076adec8ddd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4787
diff changeset
26 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
27
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
28 from .JavaScript.ExternalJsObject import ExternalJsObject
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
29
4728
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
30 from .Tools.WebHitTestResult import WebHitTestResult
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
31
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 import Preferences
5736
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5716
diff changeset
33 from Globals import qVersionTuple
1960
d8c45fe8a1b9 Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1953
diff changeset
34
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 923
diff changeset
35
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
36 class WebBrowserPage(QWebEnginePage):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 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
39
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
40 @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
41 browsing event
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
42 @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
43 malicious web site as determined by safe browsing
6142
304a469455c8 Added support for printing from within a web page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6140
diff changeset
44 @signal printRequested() emitted to indicate a print request of the shown
304a469455c8 Added support for printing from within a web page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6140
diff changeset
45 web page
6149
e611e45a17d6 Fixed a few code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6146
diff changeset
46 @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
47 to signal an accepted navigation request
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 """
5736
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5716
diff changeset
49 if qVersionTuple() >= (5, 7, 0):
6140
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
50 SafeJsWorld = QWebEngineScript.ApplicationWorld
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
51 # SafeJsWorld = 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
52 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
53 SafeJsWorld = QWebEngineScript.MainWorld
6140
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
54 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
55
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
56 safeBrowsingAbort = pyqtSignal()
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
57 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
58
6142
304a469455c8 Added support for printing from within a web page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6140
diff changeset
59 printRequested = 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
60 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
61 bool)
6142
304a469455c8 Added support for printing from within a web page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6140
diff changeset
62
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 923
diff changeset
63 def __init__(self, parent=None):
0
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 Constructor
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 @param parent parent widget of this window (QWidget)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 """
4788
7076adec8ddd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4787
diff changeset
69 super(WebBrowserPage, self).__init__(
7076adec8ddd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4787
diff changeset
70 WebBrowserWindow.webProfile(), parent)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
72 self.featurePermissionRequested.connect(
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
73 self.__featurePermissionRequested)
4743
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4742
diff changeset
74
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4742
diff changeset
75 self.authenticationRequired.connect(
6120
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6093
diff changeset
76 lambda url, auth: WebBrowserWindow.networkManager().authentication(
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6093
diff changeset
77 url, auth, self))
4787
2a19edf4db14 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4768
diff changeset
78
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
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
82 self.fullScreenRequested.connect(self.__fullScreenRequested)
4964
a894e8c92369 Implemented the JavaScript status bar icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4925
diff changeset
83
a894e8c92369 Implemented the JavaScript status bar icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4925
diff changeset
84 self.urlChanged.connect(self.__urlChanged)
5530
93f95c4b3153 Started upgrading the new web browser to the Qt 5.8 offerings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
85
93f95c4b3153 Started upgrading the new web browser to the Qt 5.8 offerings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
86 self.__printer = None
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
87 self.__badSite = False
6137
27962f3f457f Some minor changes in the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6136
diff changeset
88
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
89 if qVersionTuple() >= (5, 10, 0):
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
90 # Workaround for broken load started/finished signals in
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 # QtWebEngine 5.10, 5.11
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
92 self.loadProgress.connect(self.__loadProgress)
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
93
6140
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
94 # Workaround for changing webchannel world inside
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
95 # acceptNavigationRequest not working
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
96 self.__channelUrl = QUrl()
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
97 self.__channelWorldId = -1
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
98 self.__setupChannelTimer = QTimer(self)
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
99 self.__setupChannelTimer.setSingleShot(True)
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
100 self.__setupChannelTimer.setInterval(100)
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
101 self.__setupChannelTimer.timeout.connect(self.__setupChannelTimeout)
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
102
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
103 @pyqtSlot(int)
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
104 def __loadProgress(self, progress):
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
105 """
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
106 Private slot to send the loadFinished signal for broken Qt versions.
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
107
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
108 @param progress load progress in percent
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
109 @type int
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
110 """
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
111 if progress == 100:
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
112 self.loadFinished.emit(True)
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
113
6140
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
114 @pyqtSlot()
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
115 def __setupChannelTimeout(self):
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
116 """
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
117 Private slot to initiate the setup of the web channel.
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
118 """
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
119 self.__setupWebChannelForUrl(self.__channelUrl)
6139
d24997c47244 Fixed an issue in the new web browser with Qt 5.10.0
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6137
diff changeset
120
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
121 def acceptNavigationRequest(self, url, type_, isMainFrame):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 """
4726
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
123 Public method to determine, if a request may be accepted.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
125 @param url URL to navigate to
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
126 @type QUrl
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
127 @param type_ type of the navigation request
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
128 @type QWebEnginePage.NavigationType
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
129 @param isMainFrame flag indicating, that the request originated from
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
130 the main frame
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
131 @type bool
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
132 @return flag indicating acceptance
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
133 @rtype bool
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 """
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
135 scheme = url.scheme()
757
d3daf1d8f058 Fixed the handling of 'javascript' schemes in the web browser and enhanced the download manager a bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 748
diff changeset
136 if scheme == "mailto":
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
137 QDesktopServices.openUrl(url)
757
d3daf1d8f058 Fixed the handling of 'javascript' schemes in the web browser and enhanced the download manager a bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 748
diff changeset
138 return False
d3daf1d8f058 Fixed the handling of 'javascript' schemes in the web browser and enhanced the download manager a bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 748
diff changeset
139
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
140 # AdBlock
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
141 if url.scheme() == "abp":
4788
7076adec8ddd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4787
diff changeset
142 if WebBrowserWindow.adBlockManager().addSubscriptionFromUrl(url):
675
2f626dcab902 Added check for a form resubmission to the web page class of the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 668
diff changeset
143 return False
4886
b56735d36159 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
144
5716
27a7c7064686 Improved installion of GreaseMonkey user scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5624
diff changeset
145 # GreaseMonkey
27a7c7064686 Improved installion of GreaseMonkey user scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5624
diff changeset
146 if type_ == QWebEnginePage.NavigationTypeLinkClicked and \
27a7c7064686 Improved installion of GreaseMonkey user scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5624
diff changeset
147 url.toString().endswith(".user.js"):
27a7c7064686 Improved installion of GreaseMonkey user scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5624
diff changeset
148 WebBrowserWindow.greaseMonkeyManager().downloadScript(url)
27a7c7064686 Improved installion of GreaseMonkey user scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5624
diff changeset
149 return False
27a7c7064686 Improved installion of GreaseMonkey user scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5624
diff changeset
150
6142
304a469455c8 Added support for printing from within a web page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6140
diff changeset
151 if url.scheme() == "eric":
6174
bb2989d750ce WebBrowser: Fixed some sender() related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6149
diff changeset
152 if url.path() == "AddSearchProvider":
bb2989d750ce WebBrowser: Fixed some sender() related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6149
diff changeset
153 query = QUrlQuery(url)
bb2989d750ce WebBrowser: Fixed some sender() related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6149
diff changeset
154 self.view().mainWindow().openSearchManager().addEngine(
bb2989d750ce WebBrowser: Fixed some sender() related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6149
diff changeset
155 QUrl(query.queryItemValue("url")))
bb2989d750ce WebBrowser: Fixed some sender() related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6149
diff changeset
156 return False
bb2989d750ce WebBrowser: Fixed some sender() related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6149
diff changeset
157 elif url.path() == "PrintPage":
6142
304a469455c8 Added support for printing from within a web page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6140
diff changeset
158 self.printRequested.emit()
304a469455c8 Added support for printing from within a web page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6140
diff changeset
159 return False
304a469455c8 Added support for printing from within a web page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6140
diff changeset
160
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
161 # Safe Browsing
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
162 self.__badSite = False
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
163 from WebBrowser.SafeBrowsing.SafeBrowsingManager import \
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
164 SafeBrowsingManager
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
165 if SafeBrowsingManager.isEnabled() and \
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
166 url.scheme() not in \
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
167 SafeBrowsingManager.getIgnoreSchemes():
6234
fb1f9e681848 Web Browser NG, Safe Browsing: improved error handling
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6233
diff changeset
168 threatLists = \
fb1f9e681848 Web Browser NG, Safe Browsing: improved error handling
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6233
diff changeset
169 WebBrowserWindow.safeBrowsingManager().lookupUrl(url)[0]
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
170 if threatLists:
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
171 threatMessages = WebBrowserWindow.safeBrowsingManager()\
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
172 .getThreatMessages(threatLists)
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
173 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
174 WebBrowserWindow.getWindow(),
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
175 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
176 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
177 " 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
178 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
179 E5MessageBox.StandardButtons(
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 E5MessageBox.Ignore),
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
182 E5MessageBox.Abort)
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
183 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
184 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
185 return False
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
186
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
187 self.__badSite = True
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
188 threatType = WebBrowserWindow.safeBrowsingManager()\
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
189 .getThreatType(threatLists[0])
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
6137
27962f3f457f Some minor changes in the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6136
diff changeset
192 result = QWebEnginePage.acceptNavigationRequest(self, url, type_,
27962f3f457f Some minor changes in the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6136
diff changeset
193 isMainFrame)
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 """
4965
a9a4b632fe48 Some enhancements for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4964
diff changeset
222 if not url.isEmpty() and url.scheme() == "eric" and \
a9a4b632fe48 Some enhancements for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4964
diff changeset
223 not self.isJavaScriptEnabled():
6136
dfef226f9c7f Removed WebBrowserPage.setJavaScriptEnabled().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6127
diff changeset
224 self.settings().setAttribute(QWebEngineSettings.JavascriptEnabled,
dfef226f9c7f Removed WebBrowserPage.setJavaScriptEnabled().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6127
diff changeset
225 True)
4965
a9a4b632fe48 Some enhancements for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4964
diff changeset
226 self.triggerAction(QWebEnginePage.Reload)
4964
a894e8c92369 Implemented the JavaScript status bar icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4925
diff changeset
227
4906
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
228 @classmethod
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
229 def userAgent(cls, resolveEmpty=False):
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
230 """
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
231 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
232
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
233 @param resolveEmpty flag indicating to resolve an empty
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
234 user agent (boolean)
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
235 @return user agent string (string)
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
236 """
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
237 agent = Preferences.getWebBrowser("UserAgent")
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
238 if agent == "" and resolveEmpty:
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
239 agent = cls.userAgentForUrl(QUrl())
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
240 return agent
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
241
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
242 @classmethod
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
243 def setUserAgent(cls, 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 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
246
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
247 @param agent new current user agent string (string)
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
248 """
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
249 Preferences.setWebBrowser("UserAgent", agent)
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
250
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
251 @classmethod
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
252 def userAgentForUrl(cls, url):
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 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
255
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
256 @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
257 @return user agent string (string)
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 agent = WebBrowserWindow.userAgentsManager().userAgentForUrl(url)
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
260 if agent == "":
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
261 # 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
262 agent = Preferences.getWebBrowser("UserAgent")
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 global agent string specified -> use default one
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
265 agent = WebBrowserWindow.webProfile().httpUserAgent()
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
266 return agent
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
267
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
268 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
269 """
493891cbacee Added support for feature permissions to the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4275
diff changeset
270 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
271
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
272 @param url url requesting the feature
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
273 @type QUrl
4316
493891cbacee Added support for feature permissions to the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4275
diff changeset
274 @param feature requested feature
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
275 @type QWebEnginePage.Feature
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
276 """
4788
7076adec8ddd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4787
diff changeset
277 manager = WebBrowserWindow.featurePermissionManager()
4742
f9d1090f6ab9 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
278 manager.requestFeaturePermission(self, url, feature)
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
279
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
280 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
281 timeout=500):
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
282 """
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
283 Public method to execute a JavaScript function synchroneously.
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
284
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
285 @param script JavaScript script source to be executed
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
286 @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
287 @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
288 @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
289 @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
290 @type int
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
291 @return result of the script
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
292 @rtype depending upon script result
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
293 """
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
294 loop = QEventLoop()
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
295 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
296 QTimer.singleShot(timeout, loop.quit)
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
297
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
298 def resultCallback(res, resDict=resultDict):
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
299 if loop and loop.isRunning():
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
300 resDict["res"] = res
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
301 loop.quit()
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
302
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
303 self.runJavaScript(script, worldId, resultCallback)
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
304
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
305 loop.exec_()
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
306 return resultDict["res"]
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
307
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
308 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
309 """
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
310 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
311
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 @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
313 @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
314 @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
315 @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
316 @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
317 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
318 @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
319 """
5736
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5716
diff changeset
320 if qVersionTuple() >= (5, 7, 0) and 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
321 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
322 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
323 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
324 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
325 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
326 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
327 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
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 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
330
4965
a9a4b632fe48 Some enhancements for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4964
diff changeset
331 def isJavaScriptEnabled(self):
a9a4b632fe48 Some enhancements for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4964
diff changeset
332 """
a9a4b632fe48 Some enhancements for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4964
diff changeset
333 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
334
a9a4b632fe48 Some enhancements for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4964
diff changeset
335 @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
336 @rtype bool
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 self.settings().testAttribute(
a9a4b632fe48 Some enhancements for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4964
diff changeset
339 QWebEngineSettings.JavascriptEnabled)
a9a4b632fe48 Some enhancements for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4964
diff changeset
340
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
341 def scroll(self, x, y):
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
342 """
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
343 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
344
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
345 @param x horizontal scroll value
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
346 @type int
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
347 @param y vertical scroll value
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
348 @type int
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
349 """
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
350 self.runJavaScript(
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
351 "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
352 .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
353 WebBrowserPage.SafeJsWorld
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
354 )
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
355
5774
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
356 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
357 """
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
358 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
359
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
360 @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
361 @type QPointF
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 self.runJavaScript(
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
364 "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
365 WebBrowserPage.SafeJsWorld
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
366 )
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
367
4925
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
368 def mapToViewport(self, pos):
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
369 """
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
370 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
371
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
372 @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
373 @type QPoint
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
374 @return viewport position
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
375 @rtype QPoint
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
376 """
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
377 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
378 pos.y() // self.zoomFactor())
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
379
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
380 def hitTestContent(self, pos):
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
381 """
4728
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
382 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
383
4728
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
384 @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
385 @type QPoint
4728
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
386 @return test result object
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
387 @rtype WebHitTestResult
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
388 """
4728
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
389 return WebHitTestResult(self, pos)
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
390
6140
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
391 def __setupWebChannelForUrl(self, url):
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
392 """
4745
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4744
diff changeset
393 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
394
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
395 @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
396 @type QUrl
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
397 """
6140
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
398 channel = self.webChannel()
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
399 if channel is None:
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
400 channel = QWebChannel(self)
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
401 ExternalJsObject.setupWebChannel(channel, self)
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
402
6140
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
403 worldId = -1
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
404 if url.scheme() in ("eric", "qthelp"):
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
405 worldId = self.UnsafeJsWorld
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
406 else:
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
407 worldId = self.SafeJsWorld
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
408 if worldId != self.__channelWorldId:
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
409 self.__channelWorldId = worldId
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
410 try:
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
411 self.setWebChannel(channel, self.__channelWorldId)
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
412 except TypeError:
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
413 # pre Qt 5.7.0
c20e2d414d0d Register QWebChannel on isolated ApplicationWorld
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6139
diff changeset
414 self.setWebChannel(channel)
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4717
diff changeset
415
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4717
diff changeset
416 def certificateError(self, error):
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4717
diff changeset
417 """
4726
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
418 Public method to handle SSL certificate errors.
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4717
diff changeset
419
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4717
diff changeset
420 @param error object containing the certificate error information
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4717
diff changeset
421 @type QWebEngineCertificateError
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4717
diff changeset
422 @return flag indicating to ignore this error
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4717
diff changeset
423 @rtype bool
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4717
diff changeset
424 """
4788
7076adec8ddd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4787
diff changeset
425 return WebBrowserWindow.networkManager().certificateError(
7076adec8ddd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4787
diff changeset
426 error, self.view())
4745
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4744
diff changeset
427
4884
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
428 def __fullScreenRequested(self, request):
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
429 """
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
430 Private slot handling a full screen request.
4917
682750cc7bd5 Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4913
diff changeset
431
682750cc7bd5 Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4913
diff changeset
432 @param request reference to the full screen request
682750cc7bd5 Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4913
diff changeset
433 @type QWebEngineFullScreenRequest
4884
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
434 """
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
435 self.view().requestFullScreen(request.toggleOn())
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
436
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
437 accepted = request.toggleOn() == self.view().isFullScreen()
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
438
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
439 if accepted:
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
440 request.accept()
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
441 else:
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
442 request.reject()
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
443
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
444 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
445 """
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
446 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
447
93f95c4b3153 Started upgrading the new web browser to the Qt 5.8 offerings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
448 @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
449 @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
450 @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
451 @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
452 @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
453 @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
454 """
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
455 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
456 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
457 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
458
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
459 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
460 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
461 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
462 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
463
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 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
465
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 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
467 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
468
4745
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4744
diff changeset
469 ##############################################
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4744
diff changeset
470 ## Methods below deal with JavaScript messages
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4744
diff changeset
471 ##############################################
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4744
diff changeset
472
4917
682750cc7bd5 Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4913
diff changeset
473 def javaScriptConsoleMessage(self, level, message, lineNumber, sourceId):
4822
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
474 """
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
475 Public method to show a console message.
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
476
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
477 @param level severity
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
478 @type QWebEnginePage.JavaScriptConsoleMessageLevel
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
479 @param message message to be shown
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
480 @type str
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
481 @param lineNumber line number of an error
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
482 @type int
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
483 @param sourceId source URL causing the error
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
484 @type str
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
485 """
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
486 self.view().mainWindow().javascriptConsole().javaScriptConsoleMessage(
4917
682750cc7bd5 Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4913
diff changeset
487 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
488
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
489 ###########################################################################
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
490 ## 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
491 ###########################################################################
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
492
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
493 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
494 """
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
495 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
496
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
497 @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
498 @rtype bool
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
499 """
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
500 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
501
5113
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5009
diff changeset
502 ##################################################
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5009
diff changeset
503 ## 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
504 ##################################################
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5009
diff changeset
505
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5009
diff changeset
506 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
507 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
508 """
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5009
diff changeset
509 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
510
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5009
diff changeset
511 @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
512 @rtype QIcon
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5009
diff changeset
513 """
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5009
diff changeset
514 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
515
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
516 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
517 def scrollPosition(self):
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
518 """
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
519 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
520
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
521 @return scroll position
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
522 @rtype QPointF
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
523 """
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
524 pos = self.execJavaScript(
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
525 "(function() {"
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
526 "var res = {"
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
527 " x: 0,"
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
528 " y: 0,"
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 "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
531 "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
532 "return res;"
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
533 "})()",
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
534 WebBrowserPage.SafeJsWorld
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
535 )
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
536 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
537 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
538 else:
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
539 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
540
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
541 return pos

eric ide

mercurial