Implemented some optimizations with respect to Google Safe Browsing and browser startup with Qt Help support.

Thu, 25 Jan 2018 18:50:49 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Thu, 25 Jan 2018 18:50:49 +0100
changeset 6093
5ed91fe54bc9
parent 6092
f0d60c3de700
child 6094
01ec5bbb5acd

Implemented some optimizations with respect to Google Safe Browsing and browser startup with Qt Help support.

APIs/Python3/eric6.api file | annotate | diff | comparison | revisions
Documentation/Help/source.qch file | annotate | diff | comparison | revisions
Documentation/Source/eric6.WebBrowser.SafeBrowsing.SafeBrowsingManager.html file | annotate | diff | comparison | revisions
WebBrowser/Download/DownloadManager.py file | annotate | diff | comparison | revisions
WebBrowser/SafeBrowsing/SafeBrowsingManager.py file | annotate | diff | comparison | revisions
WebBrowser/WebBrowserPage.py file | annotate | diff | comparison | revisions
WebBrowser/WebBrowserWindow.py file | annotate | diff | comparison | revisions
--- a/APIs/Python3/eric6.api	Thu Jan 25 17:47:09 2018 +0100
+++ b/APIs/Python3/eric6.api	Thu Jan 25 18:50:49 2018 +0100
@@ -11673,6 +11673,7 @@
 eric6.WebBrowser.SafeBrowsing.SafeBrowsingLabel.SafeBrowsingLabel?1(parent=None)
 eric6.WebBrowser.SafeBrowsing.SafeBrowsingManager.SafeBrowsingManager.close?4()
 eric6.WebBrowser.SafeBrowsing.SafeBrowsingManager.SafeBrowsingManager.configurationChanged?4()
+eric6.WebBrowser.SafeBrowsing.SafeBrowsingManager.SafeBrowsingManager.enabled?7
 eric6.WebBrowser.SafeBrowsing.SafeBrowsingManager.SafeBrowsingManager.fairUseDelayExpired?4()
 eric6.WebBrowser.SafeBrowsing.SafeBrowsingManager.SafeBrowsingManager.fullCacheCleanup?4()
 eric6.WebBrowser.SafeBrowsing.SafeBrowsingManager.SafeBrowsingManager.getIgnoreSchemes?4()
Binary file Documentation/Help/source.qch has changed
--- a/Documentation/Source/eric6.WebBrowser.SafeBrowsing.SafeBrowsingManager.html	Thu Jan 25 17:47:09 2018 +0100
+++ b/Documentation/Source/eric6.WebBrowser.SafeBrowsing.SafeBrowsingManager.html	Thu Jan 25 18:50:49 2018 +0100
@@ -58,13 +58,16 @@
 QObject
 <h3>Class Attributes</h3>
 <table>
-<tr><td>None</td></tr>
+<tr><td>enabled</td></tr>
 </table>
 <h3>Class Methods</h3>
 <table>
 <tr>
 <td><a href="#SafeBrowsingManager.getIgnoreSchemes">getIgnoreSchemes</a></td>
 <td>Class method to get the schemes not to be checked.</td>
+</tr><tr>
+<td><a href="#SafeBrowsingManager.isEnabled">isEnabled</a></td>
+<td>Class method to check, if safe browsing is enabled.</td>
 </tr>
 </table>
 <h3>Methods</h3>
@@ -121,9 +124,6 @@
 <td><a href="#SafeBrowsingManager.getThreatType">getThreatType</a></td>
 <td>Public method to get a display string for a given threat type.</td>
 </tr><tr>
-<td><a href="#SafeBrowsingManager.isEnabled">isEnabled</a></td>
-<td>Public method to check, if safe browsing is enabled.</td>
-</tr><tr>
 <td><a href="#SafeBrowsingManager.isUpdatingThreatLists">isUpdatingThreatLists</a></td>
 <td>Public method to check, if we are in the process of updating the threat lists.</td>
 </tr><tr>
@@ -156,6 +156,21 @@
 <dd>
 list of str
 </dd>
+</dl><a NAME="SafeBrowsingManager.isEnabled" ID="SafeBrowsingManager.isEnabled"></a>
+<h4>SafeBrowsingManager.isEnabled (class method)</h4>
+<b>isEnabled</b>(<i></i>)
+<p>
+        Class method to check, if safe browsing is enabled.
+</p><dl>
+<dt>Returns:</dt>
+<dd>
+flag indicating the enabled state
+</dd>
+</dl><dl>
+<dt>Return Type:</dt>
+<dd>
+bool
+</dd>
 </dl><a NAME="SafeBrowsingManager.__init__" ID="SafeBrowsingManager.__init__"></a>
 <h4>SafeBrowsingManager (Constructor)</h4>
 <b>SafeBrowsingManager</b>(<i></i>)
@@ -380,21 +395,6 @@
 <dd>
 str
 </dd>
-</dl><a NAME="SafeBrowsingManager.isEnabled" ID="SafeBrowsingManager.isEnabled"></a>
-<h4>SafeBrowsingManager.isEnabled</h4>
-<b>isEnabled</b>(<i></i>)
-<p>
-        Public method to check, if safe browsing is enabled.
-</p><dl>
-<dt>Returns:</dt>
-<dd>
-flag indicating the enabled state
-</dd>
-</dl><dl>
-<dt>Return Type:</dt>
-<dd>
-bool
-</dd>
 </dl><a NAME="SafeBrowsingManager.isUpdatingThreatLists" ID="SafeBrowsingManager.isUpdatingThreatLists"></a>
 <h4>SafeBrowsingManager.isUpdatingThreatLists</h4>
 <b>isUpdatingThreatLists</b>(<i></i>)
--- a/WebBrowser/Download/DownloadManager.py	Thu Jan 25 17:47:09 2018 +0100
+++ b/WebBrowser/Download/DownloadManager.py	Thu Jan 25 18:50:49 2018 +0100
@@ -173,23 +173,26 @@
             return
         
         # Safe Browsing
-        threatLists = WebBrowserWindow.safeBrowsingManager().lookupUrl(url)
-        if threatLists:
-            threatMessages = WebBrowserWindow.safeBrowsingManager()\
-                .getThreatMessages(threatLists)
-            res = E5MessageBox.warning(
-                WebBrowserWindow.getWindow(),
-                self.tr("Suspicuous URL detected"),
-                self.tr("<p>The URL <b>{0}</b> was found in the Safe Browsing"
-                        " database.</p>{1}").format(url.toString(),
-                                                    "".join(threatMessages)),
-                E5MessageBox.StandardButtons(
-                    E5MessageBox.Abort |
-                    E5MessageBox.Ignore),
-                E5MessageBox.Abort)
-            if res == E5MessageBox.Abort:
-                downloadItem.cancel()
-                return
+        from WebBrowser.SafeBrowsing.SafeBrowsingManager import \
+            SafeBrowsingManager
+        if SafeBrowsingManager.isEnabled():
+            threatLists = WebBrowserWindow.safeBrowsingManager().lookupUrl(url)
+            if threatLists:
+                threatMessages = WebBrowserWindow.safeBrowsingManager()\
+                    .getThreatMessages(threatLists)
+                res = E5MessageBox.warning(
+                    WebBrowserWindow.getWindow(),
+                    self.tr("Suspicuous URL detected"),
+                    self.tr("<p>The URL <b>{0}</b> was found in the Safe"
+                            " Browsing database.</p>{1}").format(
+                        url.toString(), "".join(threatMessages)),
+                    E5MessageBox.StandardButtons(
+                        E5MessageBox.Abort |
+                        E5MessageBox.Ignore),
+                    E5MessageBox.Abort)
+                if res == E5MessageBox.Abort:
+                    downloadItem.cancel()
+                    return
         
         from .DownloadItem import DownloadItem
         itm = DownloadItem(downloadItem, parent=self)
--- a/WebBrowser/SafeBrowsing/SafeBrowsingManager.py	Thu Jan 25 17:47:09 2018 +0100
+++ b/WebBrowser/SafeBrowsing/SafeBrowsingManager.py	Thu Jan 25 18:50:49 2018 +0100
@@ -44,6 +44,11 @@
     progressMessage = pyqtSignal(str, int)
     progress = pyqtSignal(int)
     
+    enabled = (
+        Preferences.getWebBrowser("SafeBrowsingEnabled") and
+        bool(Preferences.getWebBrowser("SafeBrowsingApiKey"))
+    )
+    
     def __init__(self):
         """
         Constructor
@@ -57,10 +62,6 @@
         else:
             self.__apiClient = None
         
-        self.__enabled = (
-            Preferences.getWebBrowser("SafeBrowsingEnabled") and
-            bool(self.__apiKey))
-        
         gsbCachePath = os.path.join(
             Utilities.getConfigDir(), "web_browser", "safe_browsing")
         self.__cache = SafeBrowsingCache(gsbCachePath, self)
@@ -89,7 +90,7 @@
                     self.__apiClient = SafeBrowsingAPIClient(self.__apiKey,
                                                              parent=self)
         
-        self.__enabled = (
+        SafeBrowsingManager.enabled = (
             Preferences.getWebBrowser("SafeBrowsingEnabled") and
             bool(self.__apiKey))
         
@@ -111,14 +112,15 @@
                 platform = "linux"
             self.__platforms = SafeBrowsingAPIClient.getPlatformTypes(platform)
     
-    def isEnabled(self):
+    @classmethod
+    def isEnabled(cls):
         """
-        Public method to check, if safe browsing is enabled.
+        Class method to check, if safe browsing is enabled.
         
         @return flag indicating the enabled state
         @rtype bool
         """
-        return self.__enabled
+        return cls.enabled
     
     def close(self):
         """
@@ -133,7 +135,7 @@
         @return flag indicating expiration
         @rtype bool
         """
-        return self.__enabled and self.__apiClient.fairUseDelayExpired()
+        return self.isEnabled() and self.__apiClient.fairUseDelayExpired()
     
     def __showNotificationMessage(self, message, timeout=5):
         """
@@ -168,7 +170,7 @@
         Private method to set auto update for the threat lists.
         """
         autoUpdateEnabled = Preferences.getWebBrowser("SafeBrowsingAutoUpdate")
-        if autoUpdateEnabled and self.__enabled:
+        if autoUpdateEnabled and self.isEnabled():
             nextUpdateDateTime = Preferences.getWebBrowser(
                 "SafeBrowsingUpdateDateTime")
             if nextUpdateDateTime.isValid():
@@ -193,7 +195,7 @@
         Private slot to perform the auto update of the threat lists.
         """
         ok = False
-        if self.__enabled:
+        if self.isEnabled():
             self.__showNotificationMessage(
                 self.tr("Updating threat lists..."), 0)
             ok = self.updateHashPrefixCache()[0]
@@ -224,7 +226,7 @@
         @return flag indicating success and an error message
         @rtype tuple of (bool, str)
         """
-        if not self.__enabled:
+        if not self.isEnabled():
             return False, self.tr("Safe Browsing is disabled.")
         
         if not self.__apiClient.fairUseDelayExpired():
@@ -369,7 +371,7 @@
         @rtype list of ThreatList
         @exception ValueError raised for an invalid URL
         """
-        if self.__enabled:
+        if self.isEnabled():
             if isinstance(url, QUrl):
                 urlStr = url.toString().strip()
             else:
--- a/WebBrowser/WebBrowserPage.py	Thu Jan 25 17:47:09 2018 +0100
+++ b/WebBrowser/WebBrowserPage.py	Thu Jan 25 18:50:49 2018 +0100
@@ -110,8 +110,11 @@
         
         # Safe Browsing
         self.__badSite = False
-        if url.scheme() not in \
-           WebBrowserWindow.safeBrowsingManager().getIgnoreSchemes():
+        from WebBrowser.SafeBrowsing.SafeBrowsingManager import \
+            SafeBrowsingManager
+        if SafeBrowsingManager.isEnabled() and \
+            url.scheme() not in \
+                SafeBrowsingManager.getIgnoreSchemes():
             threatLists = WebBrowserWindow.safeBrowsingManager().lookupUrl(url)
             if threatLists:
                 threatMessages = WebBrowserWindow.safeBrowsingManager()\
--- a/WebBrowser/WebBrowserWindow.py	Thu Jan 25 17:47:09 2018 +0100
+++ b/WebBrowser/WebBrowserWindow.py	Thu Jan 25 18:50:49 2018 +0100
@@ -458,11 +458,6 @@
             
             self.flashCookieManager()
             
-            if WebBrowserWindow._useQtHelp:
-                QTimer.singleShot(0, self.__lookForNewDocumentation)
-                if self.__searchWord is not None:
-                    QTimer.singleShot(0, self.__searchForWord)
-            
             e5App().focusChanged.connect(self.__appFocusChanged)
             
             self.__toolbarStates = self.saveState()
@@ -481,6 +476,11 @@
             self.sessionManager().activateTimer()
             
             QTimer.singleShot(0, syncMgr.loadSettings)
+            
+            if WebBrowserWindow._useQtHelp:
+                QTimer.singleShot(50, self.__lookForNewDocumentation)
+                if self.__searchWord is not None:
+                    QTimer.singleShot(0, self.__searchForWord)
     
     def __del__(self):
         """
@@ -2985,7 +2985,8 @@
         
         self.networkManager().shutdown()
         
-        self.safeBrowsingManager().close()
+        if WebBrowserWindow._safeBrowsingManager:
+            self.safeBrowsingManager().close()
         
         for browser in WebBrowserWindow.BrowserWindows:
             if browser != self:

eric ide

mercurial