Continued porting the web browser. QtWebEngine

Mon, 28 Mar 2016 15:31:47 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 28 Mar 2016 15:31:47 +0200
branch
QtWebEngine
changeset 4902
7a49807e493c
parent 4901
38393e4d0ca3
child 4903
10910764454a

Continued porting the web browser.

- got rid of the FollowRedirect Reply because QNetworkAccessManager can handle this right now.

WebBrowser/AdBlock/AdBlockSubscription.py file | annotate | diff | comparison | revisions
WebBrowser/GreaseMonkey/GreaseMonkeyDownloader.py file | annotate | diff | comparison | revisions
WebBrowser/Network/FollowRedirectReply.py file | annotate | diff | comparison | revisions
WebBrowser/Network/NetworkManager.py file | annotate | diff | comparison | revisions
WebBrowser/Tools/WebIconLoader.py file | annotate | diff | comparison | revisions
eric6.e4p file | annotate | diff | comparison | revisions
--- a/WebBrowser/AdBlock/AdBlockSubscription.py	Mon Mar 28 13:49:24 2016 +0200
+++ b/WebBrowser/AdBlock/AdBlockSubscription.py	Mon Mar 28 15:31:47 2016 +0200
@@ -17,7 +17,7 @@
 from PyQt5.QtCore import pyqtSignal, Qt, QObject, QByteArray, QDateTime, \
     QUrl, QUrlQuery, QCryptographicHash, QFile, QIODevice, QTextStream, \
     QDate, QTime
-from PyQt5.QtNetwork import QNetworkReply
+from PyQt5.QtNetwork import QNetworkReply, QNetworkRequest
 
 from E5Gui import E5MessageBox
 
@@ -362,10 +362,8 @@
             return
         
         from WebBrowser.WebBrowserWindow import WebBrowserWindow
-        from WebBrowser.Network.FollowRedirectReply import FollowRedirectReply
-        self.__downloading = FollowRedirectReply(
-            self.location(),
-            WebBrowserWindow.networkManager())
+        self.__downloading = WebBrowserWindow.networkManager().get(
+            QNetworkRequest(self.location()))
         self.__downloading.finished.connect(self.__rulesDownloaded)
     
     def __rulesDownloaded(self):
--- a/WebBrowser/GreaseMonkey/GreaseMonkeyDownloader.py	Mon Mar 28 13:49:24 2016 +0200
+++ b/WebBrowser/GreaseMonkey/GreaseMonkeyDownloader.py	Mon Mar 28 15:31:47 2016 +0200
@@ -13,12 +13,11 @@
 
 from PyQt5.QtCore import pyqtSignal, QObject, QSettings, QRegExp, QUrl
 from PyQt5.QtWidgets import QDialog
-from PyQt5.QtNetwork import QNetworkReply
+from PyQt5.QtNetwork import QNetworkReply, QNetworkRequest
 
 from E5Gui import E5MessageBox
 
 from WebBrowser.WebBrowserWindow import WebBrowserWindow
-from WebBrowser.Network.FollowRedirectReply import FollowRedirectReply
 
 
 class GreaseMonkeyDownloader(QObject):
@@ -40,8 +39,8 @@
         
         self.__manager = manager
         
-        self.__reply = FollowRedirectReply(
-            url, WebBrowserWindow.networkManager())
+        self.__reply = WebBrowserWindow.networkManager().get(
+            QNetworkRequest(url))
         self.__reply.finished.connect(self.__scriptDownloaded)
         
         self.__fileName = ""
@@ -148,9 +147,8 @@
         Private slot to initiate the download of required scripts.
         """
         if self.__requireUrls:
-            self.__reply = FollowRedirectReply(
-                self.__requireUrls.pop(0),
-                WebBrowserWindow.networkManager())
+            self.__reply = WebBrowserWindow.networkManager().get(
+                QNetworkRequest(self.__requireUrls.pop(0)))
             self.__reply.finished.connect(self.__requireDownloaded)
         else:
             from .GreaseMonkeyScript import GreaseMonkeyScript
--- a/WebBrowser/Network/FollowRedirectReply.py	Mon Mar 28 13:49:24 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,114 +0,0 @@
-# -*- coding: utf-8 -*-
-
-# Copyright (c) 2012 - 2016 Detlev Offenbach <detlev@die-offenbachs.de>
-#
-
-"""
-Module implementing a network reply delegate allowing to check redirects.
-"""
-
-from __future__ import unicode_literals
-
-from PyQt5.QtCore import pyqtSignal, QObject
-from PyQt5.QtNetwork import QNetworkRequest
-
-
-class FollowRedirectReply(QObject):
-    """
-    Class implementing a network reply delegate allowing to check redirects.
-    """
-    finished = pyqtSignal()
-    
-    def __init__(self, url, manager, maxRedirects=5):
-        """
-        Constructor
-        
-        @param url URL to get (QUrl)
-        @param manager reference to the network access manager
-            (QNetworkAccessManager)
-        @keyparam maxRedirects maximum allowed redirects (integer)
-        """
-        super(FollowRedirectReply, self).__init__()
-        
-        self.__manager = manager
-        self.__maxRedirects = maxRedirects
-        self.__redirectCount = 0
-        
-        self.__reply = self.__manager.get(QNetworkRequest(url))
-        self.__reply.finished.connect(self.__replyFinished)
-    
-    def reply(self):
-        """
-        Public method to get the reply object.
-        
-        @return reference to the reply object (QNetworkReply)
-        """
-        return self.__reply
-    
-    def originalUrl(self):
-        """
-        Public method to get the original URL.
-        
-        @return original URL (QUrl)
-        """
-        return self.__reply.request().url()
-    
-    def url(self):
-        """
-        Public method to get the final URL (after redirects).
-        
-        @return final URL (QUrl)
-        """
-        return self.__reply.url()
-    
-    def error(self):
-        """
-        Public method to get the error information.
-        
-        @return error code (QNetworkReply.NetworkError)
-        """
-        return self.__reply.error()
-    
-    def errorString(self):
-        """
-        Public method to get the error message.
-        
-        @return error message (string)
-        """
-        return self.__reply.errorString()
-    
-    def readAll(self):
-        """
-        Public method to read all received data.
-        
-        @return received raw data (QByteArray)
-        """
-        return self.__reply.readAll()
-    
-    def close(self):
-        """
-        Public method to close the data stream.
-        """
-        self.__reply.close()
-    
-    def __replyFinished(self):
-        """
-        Private slot handling the receipt of the requested data.
-        """
-        replyStatus = self.__reply.attribute(
-            QNetworkRequest.HttpStatusCodeAttribute)
-        if (replyStatus != 301 and replyStatus != 302) or \
-           self.__redirectCount == self.__maxRedirects:
-            self.finished.emit()
-            return
-        
-        self.__redirectCount += 1
-        
-        redirectUrl = self.__reply.attribute(
-            QNetworkRequest.RedirectionTargetAttribute)
-        self.__reply.close()
-        self.__reply.deleteLater()
-        self.__reply = None
-        
-        self.__reply = self.__manager.get(QNetworkRequest(redirectUrl))
-        self.__reply.finished.connect(self.__replyFinished)
--- a/WebBrowser/Network/NetworkManager.py	Mon Mar 28 13:49:24 2016 +0200
+++ b/WebBrowser/Network/NetworkManager.py	Mon Mar 28 15:31:47 2016 +0200
@@ -13,7 +13,8 @@
 
 from PyQt5.QtCore import pyqtSignal, QByteArray
 from PyQt5.QtWidgets import QDialog
-from PyQt5.QtNetwork import QNetworkAccessManager, QNetworkProxy
+from PyQt5.QtNetwork import QNetworkAccessManager, QNetworkProxy, \
+    QNetworkRequest
 
 from E5Gui import E5MessageBox
 
@@ -301,3 +302,22 @@
         Public slot to handle a change of preferences.
         """
         self.__interceptor.preferencesChanged()
+    
+    def createRequest(self, op, request, data):
+        """
+        Public method to launch a network action.
+        
+        @param op operation to be performed
+        @type QNetworkAccessManager.Operation
+        @param request request to be operated on
+        @type QNetworkRequest
+        @param data reference to the data to be sent
+        @type QIODevice
+        @return reference to the network reply
+        @rtype QNetworkReply
+        """
+        req = QNetworkRequest(request)
+        req.setAttribute(QNetworkRequest.SpdyAllowedAttribute, True)
+        req.setAttribute(QNetworkRequest.FollowRedirectsAttribute, True)
+        
+        return super(NetworkManager, self).createRequest(op, req, data)
--- a/WebBrowser/Tools/WebIconLoader.py	Mon Mar 28 13:49:24 2016 +0200
+++ b/WebBrowser/Tools/WebIconLoader.py	Mon Mar 28 15:31:47 2016 +0200
@@ -11,8 +11,7 @@
 
 from PyQt5.QtCore import pyqtSignal, pyqtSlot, QObject
 from PyQt5.QtGui import QIcon, QPixmap, QImage
-
-from ..Network.FollowRedirectReply import FollowRedirectReply
+from PyQt5.QtNetwork import QNetworkRequest
 
 import WebBrowser.WebBrowserWindow
 
@@ -38,7 +37,7 @@
         
         networkManager = \
             WebBrowser.WebBrowserWindow.WebBrowserWindow.networkManager()
-        self.__reply = FollowRedirectReply(url, networkManager)
+        self.__reply = networkManager.get(QNetworkRequest(url))
         self.__reply.finished.connect(self.__finished)
     
     @pyqtSlot()
--- a/eric6.e4p	Mon Mar 28 13:49:24 2016 +0200
+++ b/eric6.e4p	Mon Mar 28 15:31:47 2016 +0200
@@ -1355,7 +1355,6 @@
     <Source>WebBrowser/JavaScript/StartPageJsObject.py</Source>
     <Source>WebBrowser/JavaScript/__init__.py</Source>
     <Source>WebBrowser/Network/EricSchemeHandler.py</Source>
-    <Source>WebBrowser/Network/FollowRedirectReply.py</Source>
     <Source>WebBrowser/Network/LoadRequest.py</Source>
     <Source>WebBrowser/Network/NetworkManager.py</Source>
     <Source>WebBrowser/Network/NetworkUrlInterceptor.py</Source>

eric ide

mercurial