WebBrowser/WebBrowserPage.py

changeset 6695
0a51887c13cd
parent 6692
c104c120e043
child 6776
298b03ba2990
diff -r c104c120e043 -r 0a51887c13cd WebBrowser/WebBrowserPage.py
--- a/WebBrowser/WebBrowserPage.py	Fri Feb 01 20:15:03 2019 +0100
+++ b/WebBrowser/WebBrowserPage.py	Sun Feb 03 16:10:39 2019 +0100
@@ -70,18 +70,18 @@
         super(WebBrowserPage, self).__init__(
             WebBrowserWindow.webProfile(), parent)
         
+        self.__printer = None
+        self.__badSite = False
+        self.__registerProtocolHandlerRequest = None
+        
         self.featurePermissionRequested.connect(
             self.__featurePermissionRequested)
-        
         self.authenticationRequired.connect(
             lambda url, auth: WebBrowserWindow.networkManager().authentication(
                 url, auth, self))
-        
         self.proxyAuthenticationRequired.connect(
             WebBrowserWindow.networkManager().proxyAuthentication)
-        
         self.fullScreenRequested.connect(self.__fullScreenRequested)
-        
         self.urlChanged.connect(self.__urlChanged)
         
         try:
@@ -90,13 +90,12 @@
             # defined for Qt >= 5.7
             pass
         
-        self.__printer = None
-        self.__badSite = False
-        
-        if qVersionTuple() >= (5, 10, 0):
-            # Workaround for broken load started/finished signals in
-            # QtWebEngine 5.10, 5.11
-            self.loadProgress.connect(self.__loadProgress)
+        try:
+            self.registerProtocolHandlerRequested.connect(
+                self.__registerProtocolHandlerRequested)
+        except AttributeError:
+            # defined for Qt >= 5.11
+            pass
         
         # Workaround for changing webchannel world inside
         # acceptNavigationRequest not working
@@ -107,17 +106,6 @@
         self.__setupChannelTimer.setInterval(100)
         self.__setupChannelTimer.timeout.connect(self.__setupChannelTimeout)
     
-    @pyqtSlot(int)
-    def __loadProgress(self, progress):
-        """
-        Private slot to send the loadFinished signal for broken Qt versions.
-        
-        @param progress load progress in percent
-        @type int
-        """
-        if progress == 100:
-            self.loadFinished.emit(True)
-    
     @pyqtSlot()
     def __setupChannelTimeout(self):
         """
@@ -557,3 +545,52 @@
                 pos = QPointF(0.0, 0.0)
             
             return pos
+    
+    #############################################################
+    ## Methods below implement protocol handler related functions
+    #############################################################
+    
+    @pyqtSlot("QWebEngineRegisterProtocolHandlerRequest")
+    def __registerProtocolHandlerRequested(self, request):
+        """
+        Private slot to handle the registration of a custom protocol handler.
+        
+        @param request reference to the registration request
+        @type QWebEngineRegisterProtocolHandlerRequest
+        """
+        from PyQt5.QtWebEngineCore import \
+            QWebEngineRegisterProtocolHandlerRequest
+        
+        if self.__registerProtocolHandlerRequest:
+            del self.__registerProtocolHandlerRequest
+            self.__registerProtocolHandlerRequest = None
+        self.__registerProtocolHandlerRequest = \
+            QWebEngineRegisterProtocolHandlerRequest(request)
+    
+    def registerProtocolHandlerRequestUrl(self):
+        """
+        Public method to get the registered protocol handler request URL.
+        
+        @return registered protocol handler request URL
+        @rtype QUrl
+        """
+        if self.__registerProtocolHandlerRequest and \
+            (self.url().host() ==
+             self.__registerProtocolHandlerRequest.origin().host()):
+            return self.__registerProtocolHandlerRequest.origin()
+        else:
+            return QUrl()
+    
+    def registerProtocolHandlerRequestScheme(self):
+        """
+        Public method to get the registered protocol handler request scheme.
+        
+        @return registered protocol handler request scheme
+        @rtype str
+        """
+        if self.__registerProtocolHandlerRequest and \
+            (self.url().host() ==
+             self.__registerProtocolHandlerRequest.origin().host()):
+            return self.__registerProtocolHandlerRequest.scheme()
+        else:
+            return ""

eric ide

mercurial