WebBrowser/WebBrowserPage.py

Sun, 20 Mar 2016 14:09:05 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 20 Mar 2016 14:09:05 +0100
branch
QtWebEngine
changeset 4884
6983af705a7f
parent 4864
00a215a67f25
child 4886
b56735d36159
permissions
-rw-r--r--

Continued porting the web browser.

- added full screen support

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
4631
5c1a96925da4 Updated copyright for 2016.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4612
diff changeset
3 # Copyright (c) 2008 - 2016 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:
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
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
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3636
diff changeset
17 from PyQt5.QtCore import pyqtSlot, pyqtSignal, QObject, QT_TRANSLATE_NOOP, \
3776
ccb6eacb50e5 Started adding code to make eric6 usable with PyQt5 and PyQt4.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3747
diff changeset
18 QUrl, QBuffer, QIODevice, QFileInfo, Qt, QTimer, QEvent, \
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
19 QRect, QFile, QPoint, QByteArray, QEventLoop, qVersion
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3636
diff changeset
20 from PyQt5.QtGui import QDesktopServices, QClipboard, QMouseEvent, QColor, \
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3636
diff changeset
21 QPalette
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3636
diff changeset
22 from PyQt5.QtWidgets import qApp, QStyle, QMenu, QApplication, QInputDialog, \
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3636
diff changeset
23 QLineEdit, QLabel, QToolTip, QFrame, QDialog
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3636
diff changeset
24 from PyQt5.QtPrintSupport import QPrinter, QPrintDialog
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
25 from PyQt5.QtWebEngineWidgets import QWebEnginePage
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
26 from PyQt5.QtWebChannel import QWebChannel
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3636
diff changeset
27 from PyQt5.QtNetwork import QNetworkReply, QNetworkRequest
260
21f7999b7abe Fixed an issue causing the web browser not to show an error page due to a changed Qt API (>= 4.6; needs a patch to PyQt4).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 256
diff changeset
28 import sip
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29
1934
ad6b7c30fb9f Added context menu entries for HTML5 media elements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1823
diff changeset
30 from E5Gui import E5MessageBox, E5FileDialog
537
72b32daeb8d6 Continued replacing QMessageBox methods with own methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 535
diff changeset
31
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
32 import WebBrowser
4788
7076adec8ddd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4787
diff changeset
33 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
34
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
35 from .JavaScript.ExternalJsObject import ExternalJsObject
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
36
4728
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
37 from .Tools.WebHitTestResult import WebHitTestResult
4741
f9e1adc69076 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4728
diff changeset
38 from .Tools import Scripts
4728
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
39
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 import Preferences
978
11f8adbcac97 Added an interface to VirusTotal to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 952
diff changeset
41 import UI.PixmapCache
4241
545629046c45 Fixed a bug in the message filter causing a traceback when no message filters are configured.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
42 import Globals
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43
923
e224bdbf88ad Fixed an issue related to the non-availability of SSL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 826
diff changeset
44 try:
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3636
diff changeset
45 from PyQt5.QtNetwork import QSslCertificate
923
e224bdbf88ad Fixed an issue related to the non-availability of SSL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 826
diff changeset
46 SSL_AVAILABLE = True
e224bdbf88ad Fixed an issue related to the non-availability of SSL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 826
diff changeset
47 except ImportError:
e224bdbf88ad Fixed an issue related to the non-availability of SSL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 826
diff changeset
48 SSL_AVAILABLE = False
1960
d8c45fe8a1b9 Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1953
diff changeset
49
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 923
diff changeset
50
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
51 class WebBrowserPage(QWebEnginePage):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 Class implementing an enhanced web page.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 """
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
55 ## _webPluginFactory = None
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
56 ##
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 923
diff changeset
57 def __init__(self, parent=None):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 Constructor
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 @param parent parent widget of this window (QWidget)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 """
4788
7076adec8ddd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4787
diff changeset
63 super(WebBrowserPage, self).__init__(
7076adec8ddd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4787
diff changeset
64 WebBrowserWindow.webProfile(), parent)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65
4745
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4744
diff changeset
66 self.__setupWebChannel()
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
67
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
68 ## self.setPluginFactory(self.webPluginFactory())
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
69 ##
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
70 ## self.__lastRequest = None
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
71 ## self.__lastRequestType = QWebPage.NavigationTypeOther
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
72 ##
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
73 ## from .Network.NetworkAccessManagerProxy import \
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
74 ## NetworkAccessManagerProxy
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
75 ## self.__proxy = NetworkAccessManagerProxy(self)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
76 ## self.__proxy.setWebPage(self)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
77 ## self.__proxy.setPrimaryNetworkAccessManager(
4788
7076adec8ddd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4787
diff changeset
78 ## WebBrowserWindow.networkManager())
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
79 ## self.setNetworkAccessManager(self.__proxy)
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
80
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
81 self.__sslConfiguration = None
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
82 ## self.__proxy.finished.connect(self.__managerFinished)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
83 ##
4847
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4822
diff changeset
84 ## self.__adBlockedEntries = []
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4822
diff changeset
85 ## self.loadStarted.connect(self.__loadStarted)
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
86 self.featurePermissionRequested.connect(
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
87 self.__featurePermissionRequested)
4743
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4742
diff changeset
88
f9e2e536d130 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4742
diff changeset
89 self.authenticationRequired.connect(
4788
7076adec8ddd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4787
diff changeset
90 WebBrowserWindow.networkManager().authentication)
4787
2a19edf4db14 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4768
diff changeset
91
2a19edf4db14 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4768
diff changeset
92 self.proxyAuthenticationRequired.connect(
4788
7076adec8ddd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4787
diff changeset
93 WebBrowserWindow.networkManager().proxyAuthentication)
4884
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
94
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
95 self.fullScreenRequested.connect(self.__fullScreenRequested)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
97 def acceptNavigationRequest(self, url, type_, isMainFrame):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 """
4726
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
99 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
100
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
101 @param url URL to navigate to
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
102 @type QUrl
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
103 @param type_ type of the navigation request
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
104 @type QWebEnginePage.NavigationType
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
105 @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
106 the main frame
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
107 @type bool
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
108 @return flag indicating acceptance
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
109 @rtype bool
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 """
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
111 ## self.__lastRequest = request
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
112 ## if self.__lastRequest.url() != request.url() or \
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
113 ## type_ != QWebPage.NavigationTypeOther:
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
114 ## self.__lastRequestType = type_
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
116 # TODO: Qt 5.6: move to handleUnknownProtocol
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
117 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
118 if scheme == "mailto":
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
119 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
120 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
121
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
122 # AdBlock
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
123 if url.scheme() == "abp":
4788
7076adec8ddd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4787
diff changeset
124 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
125 return False
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
126 ##
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
127 ## if type_ == QWebPage.NavigationTypeFormResubmitted:
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
128 ## res = E5MessageBox.yesNo(
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
129 ## self.view(),
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
130 ## self.tr("Resending POST request"),
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
131 ## self.tr(
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
132 ## """In order to display the site, the request along with"""
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
133 ## """ all the data must be sent once again, which may lead"""
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
134 ## """ to some unexpected behaviour of the site e.g. the"""
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
135 ## """ same action might be performed once again. Do you"""
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
136 ## """ want to continue anyway?"""),
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
137 ## icon=E5MessageBox.Warning)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
138 ## if not res:
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
139 ## return False
1934
ad6b7c30fb9f Added context menu entries for HTML5 media elements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1823
diff changeset
140
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
141 return QWebEnginePage.acceptNavigationRequest(self, url, type_,
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
142 isMainFrame)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
143 ##
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
144 ## def populateNetworkRequest(self, request):
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
145 ## """
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
146 ## Public method to add data to a network request.
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
147 ##
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
148 ## @param request reference to the network request object
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
149 ## (QNetworkRequest)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
150 ## """
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
151 ## try:
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
152 ## request.setAttribute(QNetworkRequest.User + 100, self)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
153 ## if self.__lastRequest.url() == request.url():
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
154 ## request.setAttribute(QNetworkRequest.User + 101,
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
155 ## self.__lastRequestType)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
156 ## if self.__lastRequestType == \
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
157 ## QWebPage.NavigationTypeLinkClicked:
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
158 ## request.setRawHeader(b"X-Eric6-UserLoadAction",
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
159 ## QByteArray(b"1"))
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
160 ## except TypeError:
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
161 ## pass
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
162 ##
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
163 ## def pageAttributeId(self):
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
164 ## """
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
165 ## Public method to get the attribute id of the page attribute.
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
166 ##
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
167 ## @return attribute id of the page attribute (integer)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
168 ## """
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
169 ## return QNetworkRequest.User + 100
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
170 ##
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
171 ## def supportsExtension(self, extension):
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
172 ## """
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
173 ## Public method to check the support for an extension.
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
174 ##
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
175 ## @param extension extension to test for (QWebPage.Extension)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
176 ## @return flag indicating the support of extension (boolean)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
177 ## """
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
178 ## try:
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
179 ## if extension in [QWebPage.ErrorPageExtension,
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
180 ## QWebPage.ChooseMultipleFilesExtension]:
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
181 ## return True
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
182 ## except AttributeError:
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
183 ## pass
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
184 ##
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
185 ## return QWebPage.supportsExtension(self, extension)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
186 ##
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
187 ## def extension(self, extension, option, output):
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
188 ## """
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
189 ## Public method to implement a specific extension.
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
190 ##
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
191 ## @param extension extension to be executed (QWebPage.Extension)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
192 ## @param option provides input to the extension
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
193 ## (QWebPage.ExtensionOption)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
194 ## @param output stores the output results (QWebPage.ExtensionReturn)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
195 ## @return flag indicating a successful call of the extension (boolean)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
196 ## """
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
197 ## if extension == QWebPage.ChooseMultipleFilesExtension:
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
198 ## info = sip.cast(option,
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
199 ## QWebPage.ChooseMultipleFilesExtensionOption)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
200 ## files = sip.cast(output,
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
201 ## QWebPage.ChooseMultipleFilesExtensionReturn)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
202 ## if info is None or files is None:
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
203 ## return super(HelpWebPage, self).extension(
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
204 ## extension, option, output)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
205 ##
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
206 ## suggestedFileName = ""
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
207 ## if info.suggestedFileNames:
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
208 ## suggestedFileName = info.suggestedFileNames[0]
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
209 ##
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
210 ## files.fileNames = E5FileDialog.getOpenFileNames(
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
211 ## None,
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
212 ## self.tr("Select files to upload..."),
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
213 ## suggestedFileName)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
214 ## return True
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
215 ##
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
216 ## if extension == QWebPage.ErrorPageExtension:
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
217 ## info = sip.cast(option, QWebPage.ErrorPageExtensionOption)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
218 ##
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
219 ## errorPage = sip.cast(output, QWebPage.ErrorPageExtensionReturn)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
220 ## urlString = bytes(info.url.toEncoded()).decode()
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
221 ## errorPage.baseUrl = info.url
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
222 ## if info.domain == QWebPage.QtNetwork and \
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
223 ## info.error == QNetworkReply.ProtocolUnknownError:
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
224 ## url = QUrl(info.url)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
225 ## res = E5MessageBox.yesNo(
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
226 ## None,
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
227 ## self.tr("Protocol Error"),
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
228 ## self.tr("""Open external application for {0}-link?\n"""
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
229 ## """URL: {1}""").format(
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
230 ## url.scheme(), url.toString(
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
231 ## QUrl.PrettyDecoded | QUrl.RemovePassword)),
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
232 ## yesDefault=True)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
233 ##
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
234 ## if res:
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
235 ## QDesktopServices.openUrl(url)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
236 ## return True
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
237 ## elif info.domain == QWebPage.QtNetwork and \
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
238 ## info.error == QNetworkReply.ContentAccessDenied and \
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
239 ## info.errorString.startswith("AdBlockRule:"):
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
240 ## if info.frame != info.frame.page().mainFrame():
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
241 ## # content in <iframe>
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
242 ## docElement = info.frame.page().mainFrame()\
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
243 ## .documentElement()
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
244 ## for element in docElement.findAll("iframe"):
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
245 ## src = element.attribute("src")
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
246 ## if src in info.url.toString():
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
247 ## element.setAttribute("style", "display:none;")
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
248 ## return False
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
249 ## else:
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
250 ## # the whole page is blocked
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
251 ## rule = info.errorString.replace("AdBlockRule:", "")
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
252 ## title = self.tr("Content blocked by AdBlock Plus")
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
253 ## message = self.tr(
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
254 ## "Blocked by rule: <i>{0}</i>").format(rule)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
255 ##
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
256 ## htmlFile = QFile(":/html/adblockPage.html")
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
257 ## htmlFile.open(QFile.ReadOnly)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
258 ## html = htmlFile.readAll()
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
259 ## html = html.replace(
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
260 ## "@FAVICON@", "qrc:icons/adBlockPlus16.png")
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
261 ## html = html.replace(
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
262 ## "@IMAGE@", "qrc:icons/adBlockPlus64.png")
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
263 ## html = html.replace("@TITLE@", title.encode("utf8"))
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
264 ## html = html.replace("@MESSAGE@", message.encode("utf8"))
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
265 ## errorPage.content = html
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
266 ## return True
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
267 ##
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
268 ## if info.domain == QWebPage.QtNetwork and \
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
269 ## info.error == QNetworkReply.OperationCanceledError and \
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
270 ## info.errorString == "eric6:No Error":
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
271 ## return False
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
272 ##
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
273 ## if info.domain == QWebPage.WebKit and info.error == 203:
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
274 ## # "Loading is handled by the media engine"
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
275 ## return False
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
276 ##
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
277 ## title = self.tr("Error loading page: {0}").format(urlString)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
278 ## htmlFile = QFile(":/html/notFoundPage.html")
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
279 ## htmlFile.open(QFile.ReadOnly)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
280 ## html = htmlFile.readAll()
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
281 ## pixmap = qApp.style()\
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
282 ## .standardIcon(QStyle.SP_MessageBoxWarning).pixmap(48, 48)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
283 ## imageBuffer = QBuffer()
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
284 ## imageBuffer.open(QIODevice.ReadWrite)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
285 ## if pixmap.save(imageBuffer, "PNG"):
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
286 ## html = html.replace("@IMAGE@", imageBuffer.buffer().toBase64())
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
287 ## pixmap = qApp.style()\
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
288 ## .standardIcon(QStyle.SP_MessageBoxWarning).pixmap(16, 16)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
289 ## imageBuffer = QBuffer()
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
290 ## imageBuffer.open(QIODevice.ReadWrite)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
291 ## if pixmap.save(imageBuffer, "PNG"):
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
292 ## html = html.replace(
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
293 ## "@FAVICON@", imageBuffer.buffer().toBase64())
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
294 ## html = html.replace("@TITLE@", title.encode("utf8"))
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
295 ## html = html.replace("@H1@", info.errorString.encode("utf8"))
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
296 ## html = html.replace(
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
297 ## "@H2@", self.tr("When connecting to: {0}.")
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
298 ## .format(urlString).encode("utf8"))
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
299 ## html = html.replace(
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
300 ## "@LI-1@",
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
301 ## self.tr("Check the address for errors such as "
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
302 ## "<b>ww</b>.example.org instead of "
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
303 ## "<b>www</b>.example.org").encode("utf8"))
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
304 ## html = html.replace(
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
305 ## "@LI-2@",
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
306 ## self.tr(
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
307 ## "If the address is correct, try checking the network "
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
308 ## "connection.").encode("utf8"))
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
309 ## html = html.replace(
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
310 ## "@LI-3@",
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
311 ## self.tr(
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
312 ## "If your computer or network is protected by a firewall "
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
313 ## "or proxy, make sure that the browser is permitted to "
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
314 ## "access the network.").encode("utf8"))
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
315 ## html = html.replace(
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
316 ## "@LI-4@",
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
317 ## self.tr("If your cache policy is set to offline browsing,"
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
318 ## "only pages in the local cache are available.")
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
319 ## .encode("utf8"))
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
320 ## html = html.replace(
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
321 ## "@BUTTON@", self.tr("Try Again").encode("utf8"))
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
322 ## errorPage.content = html
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
323 ## return True
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
324 ##
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
325 ## return QWebPage.extension(self, extension, option, output)
4847
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4822
diff changeset
326 ##
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4822
diff changeset
327 ## def __loadStarted(self):
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4822
diff changeset
328 ## """
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4822
diff changeset
329 ## Private slot to handle the loadStarted signal.
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4822
diff changeset
330 ## """
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4822
diff changeset
331 ## self.__adBlockedEntries = []
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
332 ##
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
333 ## def addAdBlockRule(self, rule, url):
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
334 ## """
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
335 ## Public slot to add an AdBlock rule to the page.
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
336 ##
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
337 ## @param rule AdBlock rule to add (AdBlockRule)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
338 ## @param url URL that matched the rule (QUrl)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
339 ## """
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
340 ## from .AdBlock.AdBlockPage import AdBlockedPageEntry
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
341 ## entry = AdBlockedPageEntry(rule, url)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
342 ## if entry not in self.__adBlockedEntries:
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
343 ## self.__adBlockedEntries.append(entry)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
344 ##
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
345 ## def getAdBlockedPageEntries(self):
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
346 ## """
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
347 ## Public method to get the list of AdBlock page entries.
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
348 ##
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
349 ## @return list of AdBlock page entries (list of AdBlockedPageEntry)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
350 ## """
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
351 ## return self.__adBlockedEntries
487
4d41d03d3d00 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 383
diff changeset
352
4715
79009bc4acd5 Continued getting the basic web browser functions going.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4710
diff changeset
353 # TODO: User Agent Manager
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
354 ## def userAgent(self, resolveEmpty=False):
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
355 ## """
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
356 ## Public method to get the global user agent setting.
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
357 ##
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
358 ## @param resolveEmpty flag indicating to resolve an empty
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
359 ## user agent (boolean)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
360 ## @return user agent string (string)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
361 ## """
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
362 ## agent = Preferences.getWebBrowser("UserAgent")
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
363 ## if agent == "" and resolveEmpty:
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
364 ## agent = self.userAgentForUrl(QUrl())
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
365 ## return agent
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
366 ##
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
367 ## def setUserAgent(self, agent):
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
368 ## """
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
369 ## Public method to set the global user agent string.
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
370 ##
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
371 ## @param agent new current user agent string (string)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
372 ## """
4768
57da9217196b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4758
diff changeset
373 ## Preferences.setWebBrowser("UserAgent", agent)
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
374 ##
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
375 ## def userAgentForUrl(self, url):
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
376 ## """
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
377 ## Public method to determine the user agent for the given URL.
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
378 ##
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
379 ## @param url URL to determine user agent for (QUrl)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
380 ## @return user agent string (string)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
381 ## """
4788
7076adec8ddd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4787
diff changeset
382 ## agent = WebBrowserWindow.userAgentsManager().userAgentForUrl(url)
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
383 ## if agent == "":
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
384 ## # no agent string specified for the given host -> use global one
4726
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
385 ## agent = Preferences.getWebBrowser("UserAgent")
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
386 ## if agent == "":
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
387 ## # no global agent string specified -> use default one
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
388 ## agent = QWebPage.userAgentForUrl(self, url)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
389 ## return agent
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
390 ##
4753
8d2ea02ed785 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4752
diff changeset
391 # TODO: SSL
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
392 ## def __managerFinished(self, reply):
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
393 ## """
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
394 ## Private slot to handle a finished reply.
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
395 ##
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
396 ## This slot is used to get SSL related information for a reply.
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
397 ##
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
398 ## @param reply reference to the finished reply (QNetworkReply)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
399 ## """
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
400 ## try:
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
401 ## frame = reply.request().originatingObject()
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
402 ## except AttributeError:
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
403 ## frame = None
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
404 ##
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
405 ## mainFrameRequest = frame == self.mainFrame()
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
406 ##
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
407 ## if mainFrameRequest and \
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
408 ## self.__sslConfiguration is not None and \
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
409 ## reply.url() == self.mainFrame().url():
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
410 ## self.__sslConfiguration = None
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
411 ##
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
412 ## if reply.error() == QNetworkReply.NoError and \
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
413 ## mainFrameRequest and \
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
414 ## self.__sslConfiguration is None and \
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
415 ## reply.url().scheme().lower() == "https" and \
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
416 ## reply.url() == self.mainFrame().url():
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
417 ## self.__sslConfiguration = reply.sslConfiguration()
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
418 ## self.__sslConfiguration.url = QUrl(reply.url())
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
419 ##
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
420 ## if reply.error() == QNetworkReply.NoError and \
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
421 ## mainFrameRequest and \
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
422 ## reply.url() == self.mainFrame().url():
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
423 ## modified = reply.header(QNetworkRequest.LastModifiedHeader)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
424 ## if modified and modified.isValid():
4788
7076adec8ddd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4787
diff changeset
425 ## manager = WebBrowserWindow.bookmarksManager()
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
426 ## from .Bookmarks.BookmarkNode import BookmarkNode
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
427 ## for bookmark in manager.bookmarksForUrl(reply.url()):
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
428 ## manager.setTimestamp(bookmark, BookmarkNode.TsModified,
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
429 ## modified)
1934
ad6b7c30fb9f Added context menu entries for HTML5 media elements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1823
diff changeset
430
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
431 ## def getSslCertificate(self):
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
432 ## """
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
433 ## Public method to get a reference to the SSL certificate.
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
434 ##
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
435 ## @return amended SSL certificate (QSslCertificate)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
436 ## """
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
437 ## if self.__sslConfiguration is None:
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
438 ## return None
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
439 ##
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
440 ## sslInfo = self.__sslConfiguration.peerCertificate()
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
441 ## sslInfo.url = QUrl(self.__sslConfiguration.url)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
442 ## return sslInfo
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
443 ##
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
444 ## def getSslCertificateChain(self):
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
445 ## """
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
446 ## Public method to get a reference to the SSL certificate chain.
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
447 ##
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
448 ## @return SSL certificate chain (list of QSslCertificate)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
449 ## """
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
450 ## if self.__sslConfiguration is None:
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
451 ## return []
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
452 ##
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
453 ## chain = self.__sslConfiguration.peerCertificateChain()
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
454 ## return chain
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
455 ##
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
456 ## def getSslConfiguration(self):
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
457 ## """
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
458 ## Public method to return a reference to the current SSL configuration.
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
459 ##
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
460 ## @return reference to the SSL configuration in use (QSslConfiguration)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
461 ## """
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
462 ## return self.__sslConfiguration
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
463 ##
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
464 ## def showSslInfo(self, pos):
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
465 ## """
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
466 ## Public slot to show some SSL information for the loaded page.
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
467 ##
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
468 ## @param pos position to show the info at (QPoint)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
469 ## """
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
470 ## if SSL_AVAILABLE and self.__sslConfiguration is not None:
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
471 ## from E5Network.E5SslInfoWidget import E5SslInfoWidget
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
472 ## widget = E5SslInfoWidget(
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
473 ## self.mainFrame().url(), self.__sslConfiguration, self.view())
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
474 ## widget.showAt(pos)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
475 ## else:
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
476 ## E5MessageBox.warning(
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
477 ## self.view(),
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
478 ## self.tr("SSL Info"),
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
479 ## self.tr("""This site does not contain SSL information."""))
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
480 ##
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
481 def hasValidSslInfo(self):
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
482 """
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
483 Public method to check, if the page has a valid SSL certificate.
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
484
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
485 @return flag indicating a valid SSL certificate (boolean)
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
486 """
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
487 if self.__sslConfiguration is None:
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
488 return False
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
489
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
490 certList = self.__sslConfiguration.peerCertificateChain()
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
491 if not certList:
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
492 return False
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
493
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
494 certificateDict = Globals.toDict(
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
495 Preferences.Prefs.settings.value("Ssl/CaCertificatesDict"))
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
496 for server in certificateDict:
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
497 localCAList = QSslCertificate.fromData(certificateDict[server])
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
498 for cert in certList:
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
499 if cert in localCAList:
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
500 return True
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
501
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
502 for cert in certList:
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
503 if cert.isBlacklisted():
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
504 return False
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
505
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
506 return True
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
507
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
508 ## @classmethod
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
509 ## def webPluginFactory(cls):
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
510 ## """
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
511 ## Class method to get a reference to the web plug-in factory
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
512 ## instance.
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
513 ##
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
514 ## @return reference to the web plug-in factory instance (WebPluginFactory
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
515 ## """
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
516 ## if cls._webPluginFactory is None:
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
517 ## from .WebPlugins.WebPluginFactory import WebPluginFactory
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
518 ## cls._webPluginFactory = WebPluginFactory()
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
519 ##
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
520 ## return cls._webPluginFactory
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
521 ##
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
522 ## def event(self, evt):
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
523 ## """
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
524 ## Public method implementing the event handler.
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
525 ##
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
526 ## @param evt reference to the event (QEvent)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
527 ## @return flag indicating that the event was handled (boolean)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
528 ## """
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
529 ## if evt.type() == QEvent.Leave:
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
530 ## # Fake a mouse move event just outside of the widget to trigger
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
531 ## # the WebKit event handler's mouseMoved function. This implements
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
532 ## # the interesting mouse-out behavior like invalidating scrollbars.
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
533 ## fakeEvent = QMouseEvent(QEvent.MouseMove, QPoint(0, -1),
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
534 ## Qt.NoButton, Qt.NoButton, Qt.NoModifier)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
535 ## return super(HelpWebPage, self).event(fakeEvent)
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
536 ##
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
537 ## return super(HelpWebPage, self).event(evt)
1518
e6e21910210d Added capability to zoom by a pinch gesture to the editor, the shell, the terminal, the web browser and various graphics related windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
538
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
539 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
540 """
493891cbacee Added support for feature permissions to the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4275
diff changeset
541 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
542
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
543 @param url url requesting the feature
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
544 @type QUrl
4316
493891cbacee Added support for feature permissions to the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4275
diff changeset
545 @param feature requested feature
4710
370a38e03efe Started with the web browser page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
546 @type QWebEnginePage.Feature
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
547 """
4788
7076adec8ddd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4787
diff changeset
548 manager = WebBrowserWindow.featurePermissionManager()
4742
f9d1090f6ab9 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4741
diff changeset
549 manager.requestFeaturePermission(self, url, feature)
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
550
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
551 def execJavaScript(self, script):
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
552 """
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
553 Public method to execute a JavaScript function synchroneously.
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
554
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
555 @param script JavaScript script source to be executed
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
556 @type str
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
557 @return result of the script
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
558 @rtype depending upon script result
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
559 """
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
560 loop = QEventLoop()
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
561 resultDict = {"res": None}
4728
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
562 QTimer.singleShot(500, loop.quit);
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
563
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
564 def resultCallback(res, resDict=resultDict):
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
565 if loop and loop.isRunning():
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
566 resDict["res"] = res
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
567 loop.quit()
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
568
4728
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
569 self.runJavaScript(script, resultCallback)
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
570
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
571 loop.exec_()
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
572 return resultDict["res"]
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
573
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
574 def scroll(self, x, y):
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
575 """
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
576 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
577
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
578 @param x horizontal scroll value
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
579 @type int
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
580 @param y vertical scroll value
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
581 @type int
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
582 """
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
583 self.runJavaScript(
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
584 "window.scrollTo(window.scrollX + {0}, window.scrollY + {1})"
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
585 .format(x, y)
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
586 )
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
587
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
588 def hitTestContent(self, pos):
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
589 """
4728
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
590 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
591
4728
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
592 @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
593 @type QPoint
4728
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
594 @return test result object
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
595 @rtype WebHitTestResult
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
596 """
4728
0367675d783d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
597 return WebHitTestResult(self, pos)
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
598
4745
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4744
diff changeset
599 def __setupWebChannel(self):
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
600 """
4745
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4744
diff changeset
601 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
602 """
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
603 oldChannel = self.webChannel()
4744
ad3f6c1caf8d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4743
diff changeset
604 newChannel = QWebChannel(self)
4749
750577d35452 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4745
diff changeset
605 newChannel.registerObject("eric_object", ExternalJsObject(self))
4717
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
606 self.setWebChannel(newChannel)
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
607
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
608 if oldChannel:
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
609 del oldChannel.registeredObjects["eric_object"]
5841f229baf7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4715
diff changeset
610 del oldChannel
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4717
diff changeset
611
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4717
diff changeset
612 def certificateError(self, error):
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4717
diff changeset
613 """
4726
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4725
diff changeset
614 Public method to handle SSL certificate errors.
4725
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4717
diff changeset
615
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4717
diff changeset
616 @param error object containing the certificate error information
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4717
diff changeset
617 @type QWebEngineCertificateError
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4717
diff changeset
618 @return flag indicating to ignore this error
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4717
diff changeset
619 @rtype bool
b19ff70ba509 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4717
diff changeset
620 """
4788
7076adec8ddd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4787
diff changeset
621 return WebBrowserWindow.networkManager().certificateError(
7076adec8ddd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4787
diff changeset
622 error, self.view())
4745
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4744
diff changeset
623
4884
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
624 def __fullScreenRequested(self, request):
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
625 """
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
626 Private slot handling a full screen request.
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
627 """
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
628 self.view().requestFullScreen(request.toggleOn())
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
629
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
630 accepted = request.toggleOn() == self.view().isFullScreen()
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
631
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
632 if accepted:
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
633 request.accept()
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
634 else:
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
635 request.reject()
6983af705a7f Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4864
diff changeset
636
4745
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4744
diff changeset
637 ##############################################
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4744
diff changeset
638 ## Methods below deal with JavaScript messages
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4744
diff changeset
639 ##############################################
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4744
diff changeset
640
285bfd224a1b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4744
diff changeset
641 def javaScriptConsoleMessage(self, level, message, lineNumber, sourceId):
4822
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
642 """
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
643 Public method to show a console message.
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
644
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
645 @param level severity
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
646 @type QWebEnginePage.JavaScriptConsoleMessageLevel
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
647 @param message message to be shown
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
648 @type str
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
649 @param lineNumber line number of an error
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
650 @type int
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
651 @param sourceId source URL causing the error
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
652 @type str
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
653 """
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
654 self.view().mainWindow().javascriptConsole().javaScriptConsoleMessage(
f1b9899847dc Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4801
diff changeset
655 level, message, lineNumber, sourceId)

eric ide

mercurial