Continued porting the web browser. QtWebEngine

Tue, 15 Mar 2016 19:47:54 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 15 Mar 2016 19:47:54 +0100
branch
QtWebEngine
changeset 4860
0a44aff88bfa
parent 4859
36c4b21c9f7b
child 4861
d419f153925d

Continued porting the web browser.

- finished porting the AdBlock code

WebBrowser/AdBlock/AdBlockDialog.py file | annotate | diff | comparison | revisions
WebBrowser/AdBlock/AdBlockManager.py file | annotate | diff | comparison | revisions
WebBrowser/AdBlock/AdBlockPage.py file | annotate | diff | comparison | revisions
WebBrowser/AdBlock/AdBlockRule.py file | annotate | diff | comparison | revisions
WebBrowser/AdBlock/AdBlockSubscription.py file | annotate | diff | comparison | revisions
--- a/WebBrowser/AdBlock/AdBlockDialog.py	Mon Mar 14 20:48:01 2016 +0100
+++ b/WebBrowser/AdBlock/AdBlockDialog.py	Tue Mar 15 19:47:54 2016 +0100
@@ -42,9 +42,8 @@
         self.updateSpinBox.setValue(
             Preferences.getWebBrowser("AdBlockUpdatePeriod"))
         
-        self.__useLimited = Preferences.getWebBrowser(
-            "AdBlockUseLimitedEasyList")
-        self.useLimitedEasyListCheckBox.setChecked(self.__useLimited)
+        self.useLimitedEasyListCheckBox.setChecked(Preferences.getWebBrowser(
+            "AdBlockUseLimitedEasyList"))
         
         self.searchEdit.setInactiveText(self.tr("Search..."))
         
@@ -335,16 +334,13 @@
         if state:
             self.__load()
     
-    def closeEvent(self, evt):
-        """
-        Public method handling a close event.
-        
-        @param evt reference to the close event
-        @type QCloseEvent
+    @pyqtSlot(bool)
+    def on_useLimitedEasyListCheckBox_clicked(self, checked):
         """
-        if self.useLimitedEasyListCheckBox.isChecked() != \
-                self.__useLimited:
-            self.__manager.setUseLimitedEasyList(
-                self.useLimitedEasyListCheckBox.isChecked())
+        Private slot handling the selection of the limited EasyList.
         
-        super(AdBlockDialog, self).closeEvent(evt)
+        @param checked flag indicating the state of the check box
+        @type bool
+        """
+        self.__manager.setUseLimitedEasyList(
+            self.useLimitedEasyListCheckBox.isChecked())
--- a/WebBrowser/AdBlock/AdBlockManager.py	Mon Mar 14 20:48:01 2016 +0100
+++ b/WebBrowser/AdBlock/AdBlockManager.py	Tue Mar 15 19:47:54 2016 +0100
@@ -372,13 +372,8 @@
         self.__loaded = True
         
         self.__enabled = Preferences.getWebBrowser("AdBlockEnabled")
-##    if (!m_enabled) {
-##        mApp->networkManager()->removeUrlInterceptor(m_interceptor);
-##        return;
-##    }
         if self.__enabled:
             self.__loadSubscriptions()
-##    mApp->networkManager()->installUrlInterceptor(m_interceptor);
     
     def __loadSubscriptions(self):
         """
--- a/WebBrowser/AdBlock/AdBlockPage.py	Mon Mar 14 20:48:01 2016 +0100
+++ b/WebBrowser/AdBlock/AdBlockPage.py	Tue Mar 15 19:47:54 2016 +0100
@@ -9,7 +9,7 @@
 
 from __future__ import unicode_literals
 
-from PyQt5.QtCore import QObject, QUrl
+from PyQt5.QtCore import QObject
 
 from ..Tools import Scripts
 
@@ -37,67 +37,3 @@
         if elementHiding:
             script = Scripts.setCss(elementHiding)
             page.runJavaScript(script)
-##        docElement = page.mainFrame().documentElement()
-##        
-##        for entry in page.getAdBlockedPageEntries():
-##            urlString = entry.urlString()
-##            if urlString.endswith((".js", ".css")):
-##                continue
-##            
-##            urlEnd = ""
-##            pos = urlString.rfind("/")
-##            if pos >= 0:
-##                urlEnd = urlString[pos + 1:]
-##            if urlString.endswith("/"):
-##                urlEnd = urlString[:-1]
-##            
-##            selector = \
-##                'img[src$="{0}"], iframe[src$="{0}"], embed[src$="{0}"]'\
-##                .format(urlEnd)
-##            elements = docElement.findAll(selector)
-##            
-##            for element in elements:
-##                src = element.attribute("src")
-##                src = src.replace("../", "")
-##                if src in urlString:
-##                    element.setStyleProperty("display", "none")
-##        
-##        
-##        elementHiding += "{display: none !important;}\n</style>"
-##        
-##        bodyElement = docElement.findFirst("body")
-##        bodyElement.appendInside(
-##            '<style type="text/css">\n/* AdBlock for eric */\n' +
-##            elementHiding)
-##
-##
-##class AdBlockedPageEntry(object):
-##    """
-##    Class implementing a data structure for web page rules.
-##    """
-##    def __init__(self, rule, url):
-##        """
-##        Constructor
-##        
-##        @param rule AdBlock rule to add (AdBlockRule)
-##        @param url URL that matched the rule (QUrl)
-##        """
-##        self.rule = rule
-##        self.url = QUrl(url)
-##    
-##    def __eq__(self, other):
-##        """
-##        Special method to test equality.
-##        
-##        @param other reference to the other entry (AdBlockedPageEntry)
-##        @return flag indicating equality (boolean)
-##        """
-##        return self.rule == other.rule and self.url == other.url
-##    
-##    def urlString(self):
-##        """
-##        Public method to get the URL as a string.
-##        
-##        @return URL as a string (string)
-##        """
-##        return self.url.toString()
--- a/WebBrowser/AdBlock/AdBlockRule.py	Mon Mar 14 20:48:01 2016 +0100
+++ b/WebBrowser/AdBlock/AdBlockRule.py	Tue Mar 15 19:47:54 2016 +0100
@@ -11,7 +11,7 @@
 
 import re
 
-from PyQt5.QtCore import Qt, QRegExp, QUrl
+from PyQt5.QtCore import Qt, QRegExp
 from PyQt5.QtNetwork import QNetworkRequest
 from PyQt5.QtWebEngineCore import QWebEngineUrlRequestInfo
 
--- a/WebBrowser/AdBlock/AdBlockSubscription.py	Mon Mar 14 20:48:01 2016 +0100
+++ b/WebBrowser/AdBlock/AdBlockSubscription.py	Tue Mar 15 19:47:54 2016 +0100
@@ -16,7 +16,7 @@
 
 from PyQt5.QtCore import pyqtSignal, Qt, QObject, QByteArray, QDateTime, \
     QUrl, QUrlQuery, QCryptographicHash, QFile, QIODevice, QTextStream, \
-    QDate, QTime, qVersion
+    QDate, QTime
 from PyQt5.QtNetwork import QNetworkReply
 
 from E5Gui import E5MessageBox
@@ -412,28 +412,31 @@
                 .file(fileName))
             return
         
-        # ToDo:AdBlock debug this
         from WebBrowser.WebBrowserWindow import WebBrowserWindow
         if WebBrowserWindow.adBlockManager().useLimitedEasyList() and \
             self.url().toString().startswith(
                 WebBrowserWindow.adBlockManager().getDefaultSubscriptionUrl()):
+            limited = True
             # ignore Third-party advertisers rules for performance
             # whitelist rules at the end will be used
-            part1 = response.left(response.indexOf(
+            index = response.indexOf(
                 "!---------------------------"
                 "Third-party advertisers"
-                "---------------------------!"))
-            part2 = response.mid(response.indexOf(
+                "---------------------------!")
+            part1 = response.left(index)
+            index = response.indexOf(
                 "!-----------------------"
                 "Whitelists to fix broken sites"
-                "------------------------!"))
+                "------------------------!")
+            part2 = response.mid(index)
             f.write(part1)
             f.write(part2)
         else:
+            limited = False
             f.write(response)
         f.close()
         self.__lastUpdate = QDateTime.currentDateTime()
-        if self.__validateCheckSum(fileName):
+        if limited or self.__validateCheckSum(fileName):
             self.__loadRules()
         else:
             QFile.remove(fileName)
@@ -446,8 +449,9 @@
         
         @param fileName name of the file containing the subscription (string)
         @return flag indicating a valid file (boolean). A file is considered
-            valid, if the checksum is OK or the file does not contain a
-            checksum (i.e. cannot be checked).
+            valid, if the checksum is OK, the file does not contain a
+            checksum (i.e. cannot be checked) or we are using the limited
+            EasyList (because we fiddled with the original).
         """
         try:
             f = open(fileName, "r", encoding="utf-8")

eric ide

mercurial