WebBrowser/WebBrowserPage.py

Sun, 11 Feb 2018 19:51:10 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 11 Feb 2018 19:51:10 +0100
changeset 6137
27962f3f457f
parent 6136
dfef226f9c7f
child 6139
d24997c47244
permissions
-rw-r--r--

Some minor changes in the web browser.

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
6048
82ad8ec9548c Updated copyright for 2018.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5829
diff changeset
3 # Copyright (c) 2008 - 2018 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
3145
a9de05d4a22f # __IGNORE_WARNING__ added/ removed.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3080
diff changeset
11 from __future__ import unicode_literals
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
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
17 from PyQt5.QtCore import pyqtSlot, pyqtSignal, QUrl, QTimer, QEventLoop, \
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
18 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
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 """
5736
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5716
diff changeset
45 if qVersionTuple() >= (5, 7, 0):
5009
8b1ca3c1da22 Some little enhancements to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5001
diff changeset
46 # SafeJsWorld = QWebEngineScript.ApplicationWorld
8b1ca3c1da22 Some little enhancements to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5001
diff changeset
47 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
48 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
49 SafeJsWorld = 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
50
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
51 safeBrowsingAbort = pyqtSignal()
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
52 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
53
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 923
diff changeset
54 def __init__(self, parent=None):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 Constructor
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 @param parent parent widget of this window (QWidget)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 """
4788
7076adec8ddd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4787
diff changeset
60 super(WebBrowserPage, self).__init__(
7076adec8ddd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4787
diff changeset
61 WebBrowserWindow.webProfile(), parent)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62
4745
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4744
diff changeset
63 self.__setupWebChannel()
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
64
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
65 self.featurePermissionRequested.connect(
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
66 self.__featurePermissionRequested)
4743
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4742
diff changeset
67
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4742
diff changeset
68 self.authenticationRequired.connect(
6120
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6093
diff changeset
69 lambda url, auth: WebBrowserWindow.networkManager().authentication(
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6093
diff changeset
70 url, auth, self))
4787
2a19edf4db14 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4768
diff changeset
71
2a19edf4db14 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4768
diff changeset
72 self.proxyAuthenticationRequired.connect(
4788
7076adec8ddd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4787
diff changeset
73 WebBrowserWindow.networkManager().proxyAuthentication)
4884
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
74
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
75 self.fullScreenRequested.connect(self.__fullScreenRequested)
4964
a894e8c92369 Implemented the JavaScript status bar icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4925
diff changeset
76
a894e8c92369 Implemented the JavaScript status bar icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4925
diff changeset
77 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
78
93f95c4b3153 Started upgrading the new web browser to the Qt 5.8 offerings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
79 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
80 self.__badSite = False
6137
27962f3f457f Some minor changes in the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6136
diff changeset
81
27962f3f457f Some minor changes in the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6136
diff changeset
82 ## // Workaround for broken load started/finished signals in QtWebEngine 5.10
27962f3f457f Some minor changes in the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6136
diff changeset
83 ## if (qstrcmp(qVersion(), "5.10.0") == 0) {
27962f3f457f Some minor changes in the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6136
diff changeset
84 ## connect(this, &QWebEnginePage::loadProgress, this, [this](int progress) {
27962f3f457f Some minor changes in the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6136
diff changeset
85 ## if (progress == 100) {
27962f3f457f Some minor changes in the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6136
diff changeset
86 ## emit loadFinished(true);
27962f3f457f Some minor changes in the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6136
diff changeset
87 ## }
27962f3f457f Some minor changes in the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6136
diff changeset
88 ## });
27962f3f457f Some minor changes in the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6136
diff changeset
89 ## }
27962f3f457f Some minor changes in the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6136
diff changeset
90 ##
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
92 def acceptNavigationRequest(self, url, type_, isMainFrame):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 """
4726
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
94 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
95
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
96 @param url URL to navigate to
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
97 @type QUrl
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
98 @param type_ type of the navigation request
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
99 @type QWebEnginePage.NavigationType
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
100 @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
101 the main frame
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
102 @type bool
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
103 @return flag indicating acceptance
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
104 @rtype bool
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 """
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
106 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
107 if scheme == "mailto":
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
108 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
109 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
110
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
111 # AdBlock
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
112 if url.scheme() == "abp":
4788
7076adec8ddd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4787
diff changeset
113 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
114 return False
4886
b56735d36159 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4884
diff changeset
115
5716
27a7c7064686 Improved installion of GreaseMonkey user scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5624
diff changeset
116 # GreaseMonkey
27a7c7064686 Improved installion of GreaseMonkey user scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5624
diff changeset
117 if type_ == QWebEnginePage.NavigationTypeLinkClicked and \
27a7c7064686 Improved installion of GreaseMonkey user scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5624
diff changeset
118 url.toString().endswith(".user.js"):
27a7c7064686 Improved installion of GreaseMonkey user scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5624
diff changeset
119 WebBrowserWindow.greaseMonkeyManager().downloadScript(url)
27a7c7064686 Improved installion of GreaseMonkey user scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5624
diff changeset
120 return False
27a7c7064686 Improved installion of GreaseMonkey user scripts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5624
diff changeset
121
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
122 # Safe Browsing
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
123 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
124 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
125 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
126 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
127 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
128 SafeBrowsingManager.getIgnoreSchemes():
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
129 threatLists = WebBrowserWindow.safeBrowsingManager().lookupUrl(url)
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
130 if threatLists:
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
131 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
132 .getThreatMessages(threatLists)
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
133 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
134 WebBrowserWindow.getWindow(),
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
135 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
136 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
137 " 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
138 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
139 E5MessageBox.StandardButtons(
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
140 E5MessageBox.Abort |
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
141 E5MessageBox.Ignore),
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
142 E5MessageBox.Abort)
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
143 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
144 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
145 return False
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
146
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
147 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
148 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
149 .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
150 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
151
6137
27962f3f457f Some minor changes in the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6136
diff changeset
152 result = QWebEnginePage.acceptNavigationRequest(self, url, type_,
27962f3f457f Some minor changes in the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6136
diff changeset
153 isMainFrame)
27962f3f457f Some minor changes in the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6136
diff changeset
154
27962f3f457f Some minor changes in the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6136
diff changeset
155 if result and isMainFrame:
27962f3f457f Some minor changes in the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6136
diff changeset
156 isWeb = url.scheme() in ("http", "https", "ftp", "ftps", "file")
27962f3f457f Some minor changes in the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6136
diff changeset
157 globalJsEnabled = WebBrowserWindow.webSettings().testAttribute(
27962f3f457f Some minor changes in the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6136
diff changeset
158 QWebEngineSettings.JavascriptEnabled)
27962f3f457f Some minor changes in the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6136
diff changeset
159 if isWeb:
27962f3f457f Some minor changes in the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6136
diff changeset
160 enable = globalJsEnabled
27962f3f457f Some minor changes in the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6136
diff changeset
161 else:
27962f3f457f Some minor changes in the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6136
diff changeset
162 enable = True
27962f3f457f Some minor changes in the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6136
diff changeset
163 self.settings().setAttribute(
27962f3f457f Some minor changes in the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6136
diff changeset
164 QWebEngineSettings.JavascriptEnabled, enable)
27962f3f457f Some minor changes in the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6136
diff changeset
165
27962f3f457f Some minor changes in the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6136
diff changeset
166 return result
487
4d41d03d3d00 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 383
diff changeset
167
4964
a894e8c92369 Implemented the JavaScript status bar icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4925
diff changeset
168 @pyqtSlot(QUrl)
a894e8c92369 Implemented the JavaScript status bar icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4925
diff changeset
169 def __urlChanged(self, url):
a894e8c92369 Implemented the JavaScript status bar icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4925
diff changeset
170 """
a894e8c92369 Implemented the JavaScript status bar icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4925
diff changeset
171 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
172
a894e8c92369 Implemented the JavaScript status bar icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4925
diff changeset
173 @param url new URL
a894e8c92369 Implemented the JavaScript status bar icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4925
diff changeset
174 @type QUrl
a894e8c92369 Implemented the JavaScript status bar icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4925
diff changeset
175 """
4965
a9a4b632fe48 Some enhancements for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4964
diff changeset
176 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
177 not self.isJavaScriptEnabled():
6136
dfef226f9c7f Removed WebBrowserPage.setJavaScriptEnabled().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6127
diff changeset
178 self.settings().setAttribute(QWebEngineSettings.JavascriptEnabled,
dfef226f9c7f Removed WebBrowserPage.setJavaScriptEnabled().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6127
diff changeset
179 True)
4965
a9a4b632fe48 Some enhancements for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4964
diff changeset
180 self.triggerAction(QWebEnginePage.Reload)
4964
a894e8c92369 Implemented the JavaScript status bar icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4925
diff changeset
181
4906
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
182 @classmethod
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
183 def userAgent(cls, resolveEmpty=False):
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
184 """
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
185 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
186
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
187 @param resolveEmpty flag indicating to resolve an empty
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
188 user agent (boolean)
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
189 @return user agent string (string)
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
190 """
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
191 agent = Preferences.getWebBrowser("UserAgent")
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
192 if agent == "" and resolveEmpty:
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
193 agent = cls.userAgentForUrl(QUrl())
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
194 return agent
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
195
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
196 @classmethod
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
197 def setUserAgent(cls, agent):
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
198 """
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
199 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
200
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
201 @param agent new current user agent string (string)
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
202 """
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
203 Preferences.setWebBrowser("UserAgent", agent)
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
204
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
205 @classmethod
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
206 def userAgentForUrl(cls, url):
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
207 """
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
208 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
209
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
210 @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
211 @return user agent string (string)
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
212 """
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
213 agent = WebBrowserWindow.userAgentsManager().userAgentForUrl(url)
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
214 if agent == "":
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
215 # 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
216 agent = Preferences.getWebBrowser("UserAgent")
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
217 if agent == "":
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
218 # no global agent string specified -> use default one
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
219 agent = WebBrowserWindow.webProfile().httpUserAgent()
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4905
diff changeset
220 return agent
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
221
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
222 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
223 """
493891cbacee Added support for feature permissions to the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4275
diff changeset
224 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
225
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
226 @param url url requesting the feature
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
227 @type QUrl
4316
493891cbacee Added support for feature permissions to the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4275
diff changeset
228 @param feature requested feature
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
229 @type QWebEnginePage.Feature
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
230 """
4788
7076adec8ddd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4787
diff changeset
231 manager = WebBrowserWindow.featurePermissionManager()
4742
f9d1090f6ab9 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
232 manager.requestFeaturePermission(self, url, feature)
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
233
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
234 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
235 timeout=500):
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
236 """
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
237 Public method to execute a JavaScript function synchroneously.
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
238
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
239 @param script JavaScript script source to be executed
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
240 @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
241 @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
242 @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
243 @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
244 @type int
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
245 @return result of the script
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
246 @rtype depending upon script result
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
247 """
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
248 loop = QEventLoop()
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
249 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
250 QTimer.singleShot(timeout, loop.quit)
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
251
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
252 def resultCallback(res, resDict=resultDict):
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
253 if loop and loop.isRunning():
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
254 resDict["res"] = res
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
255 loop.quit()
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
256
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
257 self.runJavaScript(script, worldId, resultCallback)
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
258
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
259 loop.exec_()
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
260 return resultDict["res"]
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
261
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
262 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
263 """
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
264 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
265
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
266 @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
267 @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
268 @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
269 @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
270 @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
271 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
272 @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
273 """
5736
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5716
diff changeset
274 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
275 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
276 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
277 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
278 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
279 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
280 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
281 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
282 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
283 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
284
4965
a9a4b632fe48 Some enhancements for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4964
diff changeset
285 def isJavaScriptEnabled(self):
a9a4b632fe48 Some enhancements for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4964
diff changeset
286 """
a9a4b632fe48 Some enhancements for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4964
diff changeset
287 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
288
a9a4b632fe48 Some enhancements for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4964
diff changeset
289 @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
290 @rtype bool
a9a4b632fe48 Some enhancements for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4964
diff changeset
291 """
a9a4b632fe48 Some enhancements for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4964
diff changeset
292 return self.settings().testAttribute(
a9a4b632fe48 Some enhancements for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4964
diff changeset
293 QWebEngineSettings.JavascriptEnabled)
a9a4b632fe48 Some enhancements for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4964
diff changeset
294
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
295 def scroll(self, x, y):
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
296 """
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
297 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
298
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
299 @param x horizontal scroll value
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
300 @type int
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
301 @param y vertical scroll value
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
302 @type int
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
303 """
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
304 self.runJavaScript(
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
305 "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
306 .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
307 WebBrowserPage.SafeJsWorld
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
308 )
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
309
5774
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
310 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
311 """
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
312 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
313
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
314 @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
315 @type QPointF
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
316 """
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
317 self.runJavaScript(
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
318 "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
319 WebBrowserPage.SafeJsWorld
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
320 )
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
321
4925
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
322 def mapToViewport(self, pos):
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
323 """
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
324 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
325
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
326 @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
327 @type QPoint
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
328 @return viewport position
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
329 @rtype QPoint
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
330 """
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
331 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
332 pos.y() // self.zoomFactor())
6534062014dc Mapped the webhit test position to the viewport.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
333
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
334 def hitTestContent(self, pos):
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
335 """
4728
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
336 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
337
4728
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
338 @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
339 @type QPoint
4728
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
340 @return test result object
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
341 @rtype WebHitTestResult
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
342 """
4728
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
343 return WebHitTestResult(self, pos)
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
344
4745
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4744
diff changeset
345 def __setupWebChannel(self):
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
346 """
4745
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4744
diff changeset
347 Private method to setup a web channel to our external object.
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
348 """
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
349 oldChannel = self.webChannel()
4744
ad3f6c1caf8d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4743
diff changeset
350 newChannel = QWebChannel(self)
6127
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
351 ExternalJsObject.setupWebChannel(newChannel, self)
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
352 self.setWebChannel(newChannel)
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
353
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
354 if oldChannel:
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
355 del oldChannel.registeredObjects["eric_object"]
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
356 del oldChannel
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4717
diff changeset
357
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4717
diff changeset
358 def certificateError(self, error):
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4717
diff changeset
359 """
4726
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
360 Public method to handle SSL certificate errors.
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4717
diff changeset
361
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4717
diff changeset
362 @param error object containing the certificate error information
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4717
diff changeset
363 @type QWebEngineCertificateError
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4717
diff changeset
364 @return flag indicating to ignore this error
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4717
diff changeset
365 @rtype bool
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4717
diff changeset
366 """
4788
7076adec8ddd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4787
diff changeset
367 return WebBrowserWindow.networkManager().certificateError(
7076adec8ddd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4787
diff changeset
368 error, self.view())
4745
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4744
diff changeset
369
4884
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
370 def __fullScreenRequested(self, request):
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
371 """
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
372 Private slot handling a full screen request.
4917
682750cc7bd5 Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4913
diff changeset
373
682750cc7bd5 Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4913
diff changeset
374 @param request reference to the full screen request
682750cc7bd5 Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4913
diff changeset
375 @type QWebEngineFullScreenRequest
4884
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
376 """
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
377 self.view().requestFullScreen(request.toggleOn())
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
378
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
379 accepted = request.toggleOn() == self.view().isFullScreen()
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
380
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
381 if accepted:
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
382 request.accept()
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
383 else:
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
384 request.reject()
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
385
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
386 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
387 """
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
388 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
389
93f95c4b3153 Started upgrading the new web browser to the Qt 5.8 offerings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
390 @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
391 @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
392 @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
393 @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
394 @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
395 @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
396 """
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
397 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
398 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
399 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
400
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
401 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
402 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
403 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
404 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
405
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
406 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
407
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
408 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
409 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
410
4745
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4744
diff changeset
411 ##############################################
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4744
diff changeset
412 ## Methods below deal with JavaScript messages
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4744
diff changeset
413 ##############################################
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4744
diff changeset
414
4917
682750cc7bd5 Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4913
diff changeset
415 def javaScriptConsoleMessage(self, level, message, lineNumber, sourceId):
4822
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
416 """
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
417 Public method to show a console message.
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
418
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
419 @param level severity
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
420 @type QWebEnginePage.JavaScriptConsoleMessageLevel
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
421 @param message message to be shown
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
422 @type str
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
423 @param lineNumber line number of an error
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
424 @type int
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
425 @param sourceId source URL causing the error
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
426 @type str
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
427 """
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
428 self.view().mainWindow().javascriptConsole().javaScriptConsoleMessage(
4917
682750cc7bd5 Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4913
diff changeset
429 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
430
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
431 ###########################################################################
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
432 ## 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
433 ###########################################################################
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
434
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
435 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
436 """
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
437 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
438
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
439 @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
440 @rtype bool
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
441 """
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5785
diff changeset
442 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
443
5113
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5009
diff changeset
444 ##################################################
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5009
diff changeset
445 ## 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
446 ##################################################
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5009
diff changeset
447
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5009
diff changeset
448 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
449 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
450 """
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5009
diff changeset
451 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
452
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5009
diff changeset
453 @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
454 @rtype QIcon
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5009
diff changeset
455 """
d394e20f7467 Added support for audio per tab to the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5009
diff changeset
456 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
457
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
458 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
459 def scrollPosition(self):
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
460 """
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
461 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
462
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
463 @return scroll position
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
464 @rtype QPointF
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
465 """
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
466 pos = self.execJavaScript(
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
467 "(function() {"
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
468 "var res = {"
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
469 " x: 0,"
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
470 " y: 0,"
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
471 "};"
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
472 "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
473 "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
474 "return res;"
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
475 "})()",
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
476 WebBrowserPage.SafeJsWorld
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
477 )
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
478 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
479 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
480 else:
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
481 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
482
a559df54a729 Started to implement session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5736
diff changeset
483 return pos

eric ide

mercurial