Continued porting the web browser. QtWebEngine

Wed, 09 Mar 2016 20:05:24 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 09 Mar 2016 20:05:24 +0100
branch
QtWebEngine
changeset 4825
b5fb58f3830b
parent 4824
08153ef89fc1
child 4826
aa752e6e9eba

Continued porting the web browser.

- started implementing the URL interceptor stuff

Preferences/__init__.py file | annotate | diff | comparison | revisions
WebBrowser/Network/NetworkManager.py file | annotate | diff | comparison | revisions
WebBrowser/Network/NetworkUrlInterceptor.py file | annotate | diff | comparison | revisions
WebBrowser/WebBrowserWindow.py file | annotate | diff | comparison | revisions
eric6.e4p file | annotate | diff | comparison | revisions
--- a/Preferences/__init__.py	Wed Mar 09 19:58:37 2016 +0100
+++ b/Preferences/__init__.py	Wed Mar 09 20:05:24 2016 +0100
@@ -1033,6 +1033,9 @@
         "DiskCacheEnabled": True,
         "DiskCacheSize": 50,        # 50 MB
         "SslExceptionsDB": "{}",    # empty JSON dictionary
+        "DoNotTrack": False,
+        "SendReferer": True,
+        "SendRefererWhitelist": ["qt-apps.org", "kde-apps.org"],
         # Grease Monkey
         "GreaseMonkeyDisabledScripts": [],
         # Downloads
@@ -2801,7 +2804,6 @@
 ##                 "OfflineStorageDatabaseEnabled",
 ##                 "OfflineWebApplicationCacheEnabled", "LocalStorageEnabled",
 ##                 "AccessKeysEnabled",
-##                 "DoNotTrack", "SendReferer",
 ##                 "SiteSpecificQuirksEnabled",
 ##                 "ClickToFlashEnabled",
 ##                 ]:
@@ -2817,13 +2819,14 @@
                  "SyncPasswords", "SyncUserAgents", "SyncSpeedDial",
                  "SyncEncryptData", "SyncEncryptPasswordsOnly",
                  "ShowPreview", "WebInspectorEnabled", "DiskCacheEnabled",
+                 "DoNotTrack", "SendReferer",
                  ]:
         return toBool(prefClass.settings.value(
             "WebBrowser/" + key, prefClass.webBrowserDefaults[key]))
 ##    elif key in ["AdBlockSubscriptions", "AdBlockExceptions",
-##                 "ClickToFlashWhitelist", "SendRefererWhitelist",
+##                 "ClickToFlashWhitelist",
 ##                 "NoCacheHosts",
-    elif key in ["GreaseMonkeyDisabledScripts",
+    elif key in ["GreaseMonkeyDisabledScripts", "SendRefererWhitelist",
                  ]:
         return toList(prefClass.settings.value(
             "WebBrowser/" + key, prefClass.helpDefaults[key]))
--- a/WebBrowser/Network/NetworkManager.py	Wed Mar 09 19:58:37 2016 +0100
+++ b/WebBrowser/Network/NetworkManager.py	Wed Mar 09 20:05:24 2016 +0100
@@ -25,6 +25,7 @@
     SSL_AVAILABLE = False
 
 from WebBrowser.WebBrowserWindow import WebBrowserWindow
+from .NetworkUrlInterceptor import NetworkUrlInterceptor
 
 from Utilities.AutoSaver import AutoSaver
 import Preferences
@@ -71,6 +72,13 @@
         self.proxyAuthenticationRequired.connect(proxyAuthenticationRequired)
         self.authenticationRequired.connect(
             lambda reply, auth: self.authentication(reply.url(), auth))
+        
+        # TODO: install network scheme handlers
+        
+        self.__interceptor = NetworkUrlInterceptor(self)
+        WebBrowserWindow.webProfile().setRequestInterceptor(self.__interceptor)
+        
+        # TODO: Cookie: create cookie jar
     
     def __save(self):
         """
@@ -258,14 +266,29 @@
         self.__acceptLanguage = WebBrowserLanguagesDialog.httpString(languages)
         
         # TODO: Qt 5.6
-##        from WebBrowser.WebBrowserWindow import WebBrowserWindow
 ##        WebBrowserWindow.webProfile().setHttpAcceptLanguage(
 ##            self.__acceptLanguage)
     
     def installUrlInterceptor(self, interceptor):
-        # TODO: Qt 5.6, URL Interceptor
-        pass
+        """
+        Public method to install an URL interceptor.
+        
+        @param interceptor URL interceptor to be installed
+        @type UrlInterceptor
+        """
+        self.__interceptor.installUrlInterceptor(interceptor)
     
     def removeUrlInterceptor(self, interceptor):
-        # TODO: Qt 5.6, URL Interceptor
-        pass
+        """
+        Public method to remove an URL interceptor.
+        
+        @param interceptor URL interceptor to be removed
+        @type UrlInterceptor
+        """
+        self.__interceptor.removeUrlInterceptor(interceptor)
+    
+    def preferencesChanged(self):
+        """
+        Public slot to handle a change of preferences.
+        """
+        self.__interceptor.preferencesChanged()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/WebBrowser/Network/NetworkUrlInterceptor.py	Wed Mar 09 20:05:24 2016 +0100
@@ -0,0 +1,87 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2016 Detlev Offenbach <detlev@die-offenbachs.de>
+#
+
+"""
+Module implementing a class to handle URL requests before they get processed
+by QtWebEngine.
+"""
+
+from __future__ import unicode_literals
+
+from PyQt5.QtWebEngineWidgets import QWebEngineUrlRequestInterceptor
+
+import Preferences
+
+
+class NetworkUrlInterceptor(QWebEngineUrlRequestInterceptor):
+    """
+    Class implementing an URL request handler.
+    """
+    def __init__(self, parent=None):
+        """
+        Constructor
+        
+        @param parent reference to the parent object
+        @type QObject
+        """
+        super(NetworkUrlInterceptor, self).__init__(parent)
+        
+        self.__interceptors = []
+        
+        self.__loadSettings()
+    
+    def interceptRequest(self, info):
+        """
+        Public method handling an URL request.
+        
+        @param info URL request information
+        @type QWebEngineUrlRequestInfo
+        """
+        # Do Not Track feature
+        if self.__doNotTrack:
+             info.setHttpHeader(b"DNT", b"1")
+             info.setHttpHeader(b"X-Do-Not-Track", b"1")
+        
+        # Send referer header?
+        if not self.__sendReferer and \
+           info.requestUrl().host() not in \
+                Preferences.getWebBrowser("SendRefererWhitelist"):
+            info.setHttpHeader(b"Referer", b"")
+        
+        for interceptor in self.__interceptors:
+            interceptor.interceptRequest(info)
+    
+    def installUrlInterceptor(self, interceptor):
+        """
+        Public method to install an URL interceptor.
+        
+        @param interceptor URL interceptor to be installed
+        @type UrlInterceptor
+        """
+        if interceptor not in self.__interceptors:
+            self.__interceptors.append(interceptor)
+    
+    def removeUrlInterceptor(self,  interceptor):
+        """
+        Public method to remove an URL interceptor.
+        
+        @param interceptor URL interceptor to be removed
+        @type UrlInterceptor
+        """
+        if interceptor in self.__interceptors:
+            self.__interceptors.remove(interceptor)
+    
+    def __loadSettings(self):
+        """
+        Private method to load the Network Manager settings.
+        """
+        self.__doNotTrack = Preferences.getWebBrowser("DoNotTrack")
+        self.__sendReferer = Preferences.getWebBrowser("SendReferer")
+    
+    def preferencesChanged(self):
+        """
+        Public slot to handle a change of preferences.
+        """
+        self.__loadSettings()
--- a/WebBrowser/WebBrowserWindow.py	Wed Mar 09 19:58:37 2016 +0100
+++ b/WebBrowser/WebBrowserWindow.py	Wed Mar 09 20:05:24 2016 +0100
@@ -2819,6 +2819,8 @@
         
         self.__initWebEngineSettings()
         
+        self.networkManager().preferencesChanged()
+        
         self.historyManager().preferencesChanged()
         
         self.__tabWidget.preferencesChanged()
--- a/eric6.e4p	Wed Mar 09 19:58:37 2016 +0100
+++ b/eric6.e4p	Wed Mar 09 20:05:24 2016 +0100
@@ -26,54 +26,6 @@
     <Source>DataViews/PyCoverageDialog.py</Source>
     <Source>DataViews/PyProfileDialog.py</Source>
     <Source>DataViews/__init__.py</Source>
-    <Source>DebugClients/Python/AsyncFile.py</Source>
-    <Source>DebugClients/Python/AsyncIO.py</Source>
-    <Source>DebugClients/Python/DCTestResult.py</Source>
-    <Source>DebugClients/Python/DebugBase.py</Source>
-    <Source>DebugClients/Python/DebugClient.py</Source>
-    <Source>DebugClients/Python/DebugClientBase.py</Source>
-    <Source>DebugClients/Python/DebugClientCapabilities.py</Source>
-    <Source>DebugClients/Python/DebugClientThreads.py</Source>
-    <Source>DebugClients/Python/DebugConfig.py</Source>
-    <Source>DebugClients/Python/DebugProtocol.py</Source>
-    <Source>DebugClients/Python/DebugThread.py</Source>
-    <Source>DebugClients/Python/FlexCompleter.py</Source>
-    <Source>DebugClients/Python/PyProfile.py</Source>
-    <Source>DebugClients/Python/__init__.py</Source>
-    <Source>DebugClients/Python/coverage/__init__.py</Source>
-    <Source>DebugClients/Python/coverage/__main__.py</Source>
-    <Source>DebugClients/Python/coverage/annotate.py</Source>
-    <Source>DebugClients/Python/coverage/backunittest.py</Source>
-    <Source>DebugClients/Python/coverage/backward.py</Source>
-    <Source>DebugClients/Python/coverage/bytecode.py</Source>
-    <Source>DebugClients/Python/coverage/cmdline.py</Source>
-    <Source>DebugClients/Python/coverage/collector.py</Source>
-    <Source>DebugClients/Python/coverage/config.py</Source>
-    <Source>DebugClients/Python/coverage/control.py</Source>
-    <Source>DebugClients/Python/coverage/data.py</Source>
-    <Source>DebugClients/Python/coverage/debug.py</Source>
-    <Source>DebugClients/Python/coverage/env.py</Source>
-    <Source>DebugClients/Python/coverage/execfile.py</Source>
-    <Source>DebugClients/Python/coverage/files.py</Source>
-    <Source>DebugClients/Python/coverage/html.py</Source>
-    <Source>DebugClients/Python/coverage/misc.py</Source>
-    <Source>DebugClients/Python/coverage/monkey.py</Source>
-    <Source>DebugClients/Python/coverage/parser.py</Source>
-    <Source>DebugClients/Python/coverage/phystokens.py</Source>
-    <Source>DebugClients/Python/coverage/pickle2json.py</Source>
-    <Source>DebugClients/Python/coverage/plugin.py</Source>
-    <Source>DebugClients/Python/coverage/plugin_support.py</Source>
-    <Source>DebugClients/Python/coverage/python.py</Source>
-    <Source>DebugClients/Python/coverage/pytracer.py</Source>
-    <Source>DebugClients/Python/coverage/report.py</Source>
-    <Source>DebugClients/Python/coverage/results.py</Source>
-    <Source>DebugClients/Python/coverage/summary.py</Source>
-    <Source>DebugClients/Python/coverage/templite.py</Source>
-    <Source>DebugClients/Python/coverage/test_helpers.py</Source>
-    <Source>DebugClients/Python/coverage/version.py</Source>
-    <Source>DebugClients/Python/coverage/xmlreport.py</Source>
-    <Source>DebugClients/Python/eric6dbgstub.py</Source>
-    <Source>DebugClients/Python/getpass.py</Source>
     <Source>DebugClients/Python3/AsyncFile.py</Source>
     <Source>DebugClients/Python3/AsyncIO.py</Source>
     <Source>DebugClients/Python3/DCTestResult.py</Source>
@@ -123,6 +75,54 @@
     <Source>DebugClients/Python3/coverage/xmlreport.py</Source>
     <Source>DebugClients/Python3/eric6dbgstub.py</Source>
     <Source>DebugClients/Python3/getpass.py</Source>
+    <Source>DebugClients/Python/AsyncFile.py</Source>
+    <Source>DebugClients/Python/AsyncIO.py</Source>
+    <Source>DebugClients/Python/DCTestResult.py</Source>
+    <Source>DebugClients/Python/DebugBase.py</Source>
+    <Source>DebugClients/Python/DebugClient.py</Source>
+    <Source>DebugClients/Python/DebugClientBase.py</Source>
+    <Source>DebugClients/Python/DebugClientCapabilities.py</Source>
+    <Source>DebugClients/Python/DebugClientThreads.py</Source>
+    <Source>DebugClients/Python/DebugConfig.py</Source>
+    <Source>DebugClients/Python/DebugProtocol.py</Source>
+    <Source>DebugClients/Python/DebugThread.py</Source>
+    <Source>DebugClients/Python/FlexCompleter.py</Source>
+    <Source>DebugClients/Python/PyProfile.py</Source>
+    <Source>DebugClients/Python/__init__.py</Source>
+    <Source>DebugClients/Python/coverage/__init__.py</Source>
+    <Source>DebugClients/Python/coverage/__main__.py</Source>
+    <Source>DebugClients/Python/coverage/annotate.py</Source>
+    <Source>DebugClients/Python/coverage/backunittest.py</Source>
+    <Source>DebugClients/Python/coverage/backward.py</Source>
+    <Source>DebugClients/Python/coverage/bytecode.py</Source>
+    <Source>DebugClients/Python/coverage/cmdline.py</Source>
+    <Source>DebugClients/Python/coverage/collector.py</Source>
+    <Source>DebugClients/Python/coverage/config.py</Source>
+    <Source>DebugClients/Python/coverage/control.py</Source>
+    <Source>DebugClients/Python/coverage/data.py</Source>
+    <Source>DebugClients/Python/coverage/debug.py</Source>
+    <Source>DebugClients/Python/coverage/env.py</Source>
+    <Source>DebugClients/Python/coverage/execfile.py</Source>
+    <Source>DebugClients/Python/coverage/files.py</Source>
+    <Source>DebugClients/Python/coverage/html.py</Source>
+    <Source>DebugClients/Python/coverage/misc.py</Source>
+    <Source>DebugClients/Python/coverage/monkey.py</Source>
+    <Source>DebugClients/Python/coverage/parser.py</Source>
+    <Source>DebugClients/Python/coverage/phystokens.py</Source>
+    <Source>DebugClients/Python/coverage/pickle2json.py</Source>
+    <Source>DebugClients/Python/coverage/plugin.py</Source>
+    <Source>DebugClients/Python/coverage/plugin_support.py</Source>
+    <Source>DebugClients/Python/coverage/python.py</Source>
+    <Source>DebugClients/Python/coverage/pytracer.py</Source>
+    <Source>DebugClients/Python/coverage/report.py</Source>
+    <Source>DebugClients/Python/coverage/results.py</Source>
+    <Source>DebugClients/Python/coverage/summary.py</Source>
+    <Source>DebugClients/Python/coverage/templite.py</Source>
+    <Source>DebugClients/Python/coverage/test_helpers.py</Source>
+    <Source>DebugClients/Python/coverage/version.py</Source>
+    <Source>DebugClients/Python/coverage/xmlreport.py</Source>
+    <Source>DebugClients/Python/eric6dbgstub.py</Source>
+    <Source>DebugClients/Python/getpass.py</Source>
     <Source>DebugClients/__init__.py</Source>
     <Source>Debugger/BreakPointModel.py</Source>
     <Source>Debugger/BreakPointViewer.py</Source>
@@ -1337,6 +1337,7 @@
     <Source>WebBrowser/Network/FollowRedirectReply.py</Source>
     <Source>WebBrowser/Network/LoadRequest.py</Source>
     <Source>WebBrowser/Network/NetworkManager.py</Source>
+    <Source>WebBrowser/Network/NetworkUrlInterceptor.py</Source>
     <Source>WebBrowser/Network/SslErrorExceptionsDialog.py</Source>
     <Source>WebBrowser/Network/UrlInterceptor.py</Source>
     <Source>WebBrowser/Network/__init__.py</Source>
@@ -1890,14 +1891,14 @@
   <Interfaces/>
   <Others>
     <Other>.hgignore</Other>
-    <Other>APIs/Python/zope-2.10.7.api</Other>
-    <Other>APIs/Python/zope-2.11.2.api</Other>
-    <Other>APIs/Python/zope-3.3.1.api</Other>
     <Other>APIs/Python3/PyQt4.bas</Other>
     <Other>APIs/Python3/PyQt5.bas</Other>
     <Other>APIs/Python3/QScintilla2.bas</Other>
     <Other>APIs/Python3/eric6.api</Other>
     <Other>APIs/Python3/eric6.bas</Other>
+    <Other>APIs/Python/zope-2.10.7.api</Other>
+    <Other>APIs/Python/zope-2.11.2.api</Other>
+    <Other>APIs/Python/zope-3.3.1.api</Other>
     <Other>APIs/QSS/qss.api</Other>
     <Other>APIs/Ruby/Ruby-1.8.7.api</Other>
     <Other>APIs/Ruby/Ruby-1.8.7.bas</Other>
@@ -1906,8 +1907,8 @@
     <Other>CSSs</Other>
     <Other>CodeTemplates</Other>
     <Other>DTDs</Other>
+    <Other>DebugClients/Python3/coverage/doc</Other>
     <Other>DebugClients/Python/coverage/doc</Other>
-    <Other>DebugClients/Python3/coverage/doc</Other>
     <Other>DesignerTemplates</Other>
     <Other>Dictionaries</Other>
     <Other>Documentation/Help</Other>

eric ide

mercurial