WebBrowser/WebBrowserPage.py

branch
maintenance
changeset 6826
c6dda2cbe081
parent 6789
6bafe4f7d5f0
equal deleted inserted replaced
6764:d14ddbfbbd36 6826:c6dda2cbe081
68 @param parent parent widget of this window (QWidget) 68 @param parent parent widget of this window (QWidget)
69 """ 69 """
70 super(WebBrowserPage, self).__init__( 70 super(WebBrowserPage, self).__init__(
71 WebBrowserWindow.webProfile(), parent) 71 WebBrowserWindow.webProfile(), parent)
72 72
73 self.__printer = None
74 self.__badSite = False
75 self.__registerProtocolHandlerRequest = None
76
73 self.featurePermissionRequested.connect( 77 self.featurePermissionRequested.connect(
74 self.__featurePermissionRequested) 78 self.__featurePermissionRequested)
75
76 self.authenticationRequired.connect( 79 self.authenticationRequired.connect(
77 lambda url, auth: WebBrowserWindow.networkManager().authentication( 80 lambda url, auth: WebBrowserWindow.networkManager().authentication(
78 url, auth, self)) 81 url, auth, self))
79
80 self.proxyAuthenticationRequired.connect( 82 self.proxyAuthenticationRequired.connect(
81 WebBrowserWindow.networkManager().proxyAuthentication) 83 WebBrowserWindow.networkManager().proxyAuthentication)
82
83 self.fullScreenRequested.connect(self.__fullScreenRequested) 84 self.fullScreenRequested.connect(self.__fullScreenRequested)
84
85 self.urlChanged.connect(self.__urlChanged) 85 self.urlChanged.connect(self.__urlChanged)
86 86
87 try: 87 try:
88 self.contentsSizeChanged.connect(self.__contentsSizeChanged) 88 self.contentsSizeChanged.connect(self.__contentsSizeChanged)
89 except AttributeError: 89 except AttributeError:
90 # defined for Qt >= 5.7 90 # defined for Qt >= 5.7
91 pass 91 pass
92 92
93 self.__printer = None 93 try:
94 self.__badSite = False 94 self.registerProtocolHandlerRequested.connect(
95 95 self.__registerProtocolHandlerRequested)
96 if qVersionTuple() >= (5, 10, 0): 96 except AttributeError:
97 # Workaround for broken load started/finished signals in 97 # defined for Qt >= 5.11
98 # QtWebEngine 5.10, 5.11 98 pass
99 self.loadProgress.connect(self.__loadProgress)
100 99
101 # Workaround for changing webchannel world inside 100 # Workaround for changing webchannel world inside
102 # acceptNavigationRequest not working 101 # acceptNavigationRequest not working
103 self.__channelUrl = QUrl() 102 self.__channelUrl = QUrl()
104 self.__channelWorldId = -1 103 self.__channelWorldId = -1
105 self.__setupChannelTimer = QTimer(self) 104 self.__setupChannelTimer = QTimer(self)
106 self.__setupChannelTimer.setSingleShot(True) 105 self.__setupChannelTimer.setSingleShot(True)
107 self.__setupChannelTimer.setInterval(100) 106 self.__setupChannelTimer.setInterval(100)
108 self.__setupChannelTimer.timeout.connect(self.__setupChannelTimeout) 107 self.__setupChannelTimer.timeout.connect(self.__setupChannelTimeout)
109
110 @pyqtSlot(int)
111 def __loadProgress(self, progress):
112 """
113 Private slot to send the loadFinished signal for broken Qt versions.
114
115 @param progress load progress in percent
116 @type int
117 """
118 if progress == 100:
119 self.loadFinished.emit(True)
120 108
121 @pyqtSlot() 109 @pyqtSlot()
122 def __setupChannelTimeout(self): 110 def __setupChannelTimeout(self):
123 """ 111 """
124 Private slot to initiate the setup of the web channel. 112 Private slot to initiate the setup of the web channel.
555 pos = QPointF(pos["x"], pos["y"]) 543 pos = QPointF(pos["x"], pos["y"])
556 else: 544 else:
557 pos = QPointF(0.0, 0.0) 545 pos = QPointF(0.0, 0.0)
558 546
559 return pos 547 return pos
548
549 #############################################################
550 ## Methods below implement protocol handler related functions
551 #############################################################
552
553 try:
554 @pyqtSlot("QWebEngineRegisterProtocolHandlerRequest")
555 def __registerProtocolHandlerRequested(self, request):
556 """
557 Private slot to handle the registration of a custom protocol
558 handler.
559
560 @param request reference to the registration request
561 @type QWebEngineRegisterProtocolHandlerRequest
562 """
563 from PyQt5.QtWebEngineCore import \
564 QWebEngineRegisterProtocolHandlerRequest
565
566 if self.__registerProtocolHandlerRequest:
567 del self.__registerProtocolHandlerRequest
568 self.__registerProtocolHandlerRequest = None
569 self.__registerProtocolHandlerRequest = \
570 QWebEngineRegisterProtocolHandlerRequest(request)
571 except TypeError:
572 # this is supported with Qt 5.12 and later
573 pass
574
575 def registerProtocolHandlerRequestUrl(self):
576 """
577 Public method to get the registered protocol handler request URL.
578
579 @return registered protocol handler request URL
580 @rtype QUrl
581 """
582 if self.__registerProtocolHandlerRequest and \
583 (self.url().host() ==
584 self.__registerProtocolHandlerRequest.origin().host()):
585 return self.__registerProtocolHandlerRequest.origin()
586 else:
587 return QUrl()
588
589 def registerProtocolHandlerRequestScheme(self):
590 """
591 Public method to get the registered protocol handler request scheme.
592
593 @return registered protocol handler request scheme
594 @rtype str
595 """
596 if self.__registerProtocolHandlerRequest and \
597 (self.url().host() ==
598 self.__registerProtocolHandlerRequest.origin().host()):
599 return self.__registerProtocolHandlerRequest.scheme()
600 else:
601 return ""

eric ide

mercurial