WebBrowser/WebBrowserPage.py

branch
QtWebEngine
changeset 4717
5841f229baf7
parent 4715
79009bc4acd5
child 4725
b19ff70ba509
equal deleted inserted replaced
4715:79009bc4acd5 4717:5841f229baf7
8 Module implementing the helpbrowser using QWebView. 8 Module implementing the helpbrowser using QWebView.
9 """ 9 """
10 10
11 from __future__ import unicode_literals 11 from __future__ import unicode_literals
12 try: 12 try:
13 str = unicode 13 str = unicode # __IGNORE_EXCEPTION__
14 except NameError: 14 except NameError:
15 pass 15 pass
16 16
17 from PyQt5.QtCore import pyqtSlot, pyqtSignal, QObject, QT_TRANSLATE_NOOP, \ 17 from PyQt5.QtCore import pyqtSlot, pyqtSignal, QObject, QT_TRANSLATE_NOOP, \
18 QUrl, QBuffer, QIODevice, QFileInfo, Qt, QTimer, QEvent, \ 18 QUrl, QBuffer, QIODevice, QFileInfo, Qt, QTimer, QEvent, \
19 QRect, QFile, QPoint, QByteArray, qVersion 19 QRect, QFile, QPoint, QByteArray, QEventLoop, qVersion
20 from PyQt5.QtGui import QDesktopServices, QClipboard, QMouseEvent, QColor, \ 20 from PyQt5.QtGui import QDesktopServices, QClipboard, QMouseEvent, QColor, \
21 QPalette 21 QPalette
22 from PyQt5.QtWidgets import qApp, QStyle, QMenu, QApplication, QInputDialog, \ 22 from PyQt5.QtWidgets import qApp, QStyle, QMenu, QApplication, QInputDialog, \
23 QLineEdit, QLabel, QToolTip, QFrame, QDialog 23 QLineEdit, QLabel, QToolTip, QFrame, QDialog
24 from PyQt5.QtPrintSupport import QPrinter, QPrintDialog 24 from PyQt5.QtPrintSupport import QPrinter, QPrintDialog
25 ##from PyQt5.QtWebKit import QWebSettings
26 ##from PyQt5.QtWebKitWidgets import QWebView, QWebPage
27 from PyQt5.QtWebEngineWidgets import QWebEnginePage 25 from PyQt5.QtWebEngineWidgets import QWebEnginePage
28 try: 26 from PyQt5.QtWebChannel import QWebChannel
29 from PyQt5.QtWebKit import QWebElement
30 except ImportError:
31 pass
32 from PyQt5.QtNetwork import QNetworkReply, QNetworkRequest 27 from PyQt5.QtNetwork import QNetworkReply, QNetworkRequest
33 import sip 28 import sip
34 29
35 from E5Gui import E5MessageBox, E5FileDialog 30 from E5Gui import E5MessageBox, E5FileDialog
36 31
37 import WebBrowser 32 import WebBrowser
38 import WebBrowser.WebBrowserWindow 33 import WebBrowser.WebBrowserWindow
34
35 from .JavaScript.ExternalJsObject import ExternalJsObject
39 36
40 import Preferences 37 import Preferences
41 import UI.PixmapCache 38 import UI.PixmapCache
42 import Globals 39 import Globals
43 40
171 168
172 @param parent parent widget of this window (QWidget) 169 @param parent parent widget of this window (QWidget)
173 """ 170 """
174 super(WebBrowserPage, self).__init__(parent) 171 super(WebBrowserPage, self).__init__(parent)
175 172
173 self.setupWebChannel()
174
176 ## self.setPluginFactory(self.webPluginFactory()) 175 ## self.setPluginFactory(self.webPluginFactory())
177 ## 176 ##
178 ## self.__lastRequest = None 177 ## self.__lastRequest = None
179 ## self.__lastRequestType = QWebPage.NavigationTypeOther 178 ## self.__lastRequestType = QWebPage.NavigationTypeOther
180 ## 179 ##
184 ## self.__proxy = NetworkAccessManagerProxy(self) 183 ## self.__proxy = NetworkAccessManagerProxy(self)
185 ## self.__proxy.setWebPage(self) 184 ## self.__proxy.setWebPage(self)
186 ## self.__proxy.setPrimaryNetworkAccessManager( 185 ## self.__proxy.setPrimaryNetworkAccessManager(
187 ## Helpviewer.HelpWindow.HelpWindow.networkAccessManager()) 186 ## Helpviewer.HelpWindow.HelpWindow.networkAccessManager())
188 ## self.setNetworkAccessManager(self.__proxy) 187 ## self.setNetworkAccessManager(self.__proxy)
189 ## 188
190 ## self.__sslConfiguration = None 189 self.__sslConfiguration = None
191 ## self.__proxy.finished.connect(self.__managerFinished) 190 ## self.__proxy.finished.connect(self.__managerFinished)
192 ## 191 ##
193 self.__adBlockedEntries = [] 192 self.__adBlockedEntries = []
194 self.loadStarted.connect(self.__loadStarted) 193 self.loadStarted.connect(self.__loadStarted)
195 ## 194 ##
585 ## E5MessageBox.warning( 584 ## E5MessageBox.warning(
586 ## self.view(), 585 ## self.view(),
587 ## self.tr("SSL Info"), 586 ## self.tr("SSL Info"),
588 ## self.tr("""This site does not contain SSL information.""")) 587 ## self.tr("""This site does not contain SSL information."""))
589 ## 588 ##
590 ## def hasValidSslInfo(self): 589 def hasValidSslInfo(self):
591 ## """ 590 """
592 ## Public method to check, if the page has a valid SSL certificate. 591 Public method to check, if the page has a valid SSL certificate.
593 ## 592
594 ## @return flag indicating a valid SSL certificate (boolean) 593 @return flag indicating a valid SSL certificate (boolean)
595 ## """ 594 """
596 ## if self.__sslConfiguration is None: 595 if self.__sslConfiguration is None:
597 ## return False 596 return False
598 ## 597
599 ## certList = self.__sslConfiguration.peerCertificateChain() 598 certList = self.__sslConfiguration.peerCertificateChain()
600 ## if not certList: 599 if not certList:
601 ## return False 600 return False
602 ## 601
603 ## certificateDict = Globals.toDict( 602 certificateDict = Globals.toDict(
604 ## Preferences.Prefs.settings.value("Ssl/CaCertificatesDict")) 603 Preferences.Prefs.settings.value("Ssl/CaCertificatesDict"))
605 ## for server in certificateDict: 604 for server in certificateDict:
606 ## localCAList = QSslCertificate.fromData(certificateDict[server]) 605 localCAList = QSslCertificate.fromData(certificateDict[server])
607 ## for cert in certList: 606 for cert in certList:
608 ## if cert in localCAList: 607 if cert in localCAList:
609 ## return True 608 return True
610 ## 609
611 ## if qVersion() >= "5.0.0": 610 for cert in certList:
612 ## for cert in certList: 611 if cert.isBlacklisted():
613 ## if cert.isBlacklisted(): 612 return False
614 ## return False 613
615 ## else: 614 return True
616 ## for cert in certList:
617 ## if not cert.isValid():
618 ## return False
619 ##
620 ## return True
621 615
622 ## @classmethod 616 ## @classmethod
623 ## def webPluginFactory(cls): 617 ## def webPluginFactory(cls):
624 ## """ 618 ## """
625 ## Class method to get a reference to the web plug-in factory 619 ## Class method to get a reference to the web plug-in factory
709 @param url url requesting the feature 703 @param url url requesting the feature
710 @type QUrl 704 @type QUrl
711 @param feature requested feature 705 @param feature requested feature
712 @type QWebEnginePage.Feature 706 @type QWebEnginePage.Feature
713 """ 707 """
714 manager = WebBrowser.WebBrowserWindow.WebBrowserWindow\ 708 # TODO: Feature Permission
715 .featurePermissionManager() 709 ## manager = WebBrowser.WebBrowserWindow.WebBrowserWindow\
716 manager.requestFeaturePermission(self, frame, feature) 710 ## .featurePermissionManager()
711 ## manager.requestFeaturePermission(self, frame, feature)
712
713 def execJavaScript(self, script):
714 """
715 Public method to execute a JavaScript function synchroneously.
716
717 @param script JavaScript script source to be executed
718 @type str
719 @return result of the script
720 @rtype depending upon script result
721 """
722 loop = QEventLoop()
723 resultDict = {"res": None}
724
725 def resultCallback(res, resDict=resultDict):
726 if loop and loop.isRunning():
727 resDict["res"] = res
728 loop.quit()
729
730 self.previewView.page().runJavaScript(
731 script, resultCallback)
732
733 loop.exec_()
734 return resultDict["res"]
735
736 def scroll(self, x, y):
737 """
738 Public method to scroll by the given amount of pixels.
739
740 @param x horizontal scroll value
741 @type int
742 @param y vertical scroll value
743 @type int
744 """
745 self.runJavaScript(
746 "window.scrollTo(window.scrollX + {0}, window.scrollY + {1})"
747 .format(x, y)
748 )
749
750 def hitTestContent(self, pos):
751 """
752 Public method to test the contents at a given position.
753
754 @param pos position to be tested
755 @type QPoint
756 @return object containing the test results
757 @rtype WebBrowserHitTestResult
758 """
759 # TODO: WebBrowserHitTestResult
760 ## return WebBrowserHitTestResult(self, pos)
761
762 def setupWebChannel(self):
763 """
764 Public method to setup a web channel to our external object.
765 """
766 oldChannel = self.webChannel()
767 newChannel = QWebChannel()
768 newChannel.registerObject("eric_object", ExternalJsObject(self))
769 self.setWebChannel(newChannel)
770
771 if oldChannel:
772 del oldChannel.registeredObjects["eric_object"]
773 del oldChannel

eric ide

mercurial