[Pkg-mozext-commits] [adblock-plus] 443/464: issue #660 - Switched to HTTP cache API V2 from Firefox 32 and above

David Prévot taffit at moszumanska.debian.org
Tue Jul 22 20:44:42 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository adblock-plus.

commit 25080cfe74d6bf0ce0c2e6dfef76cc938387c297
Author: Manvel Saroyan <manvel at adblockplus.org>
Date:   Thu Jul 3 20:54:25 2014 +0400

    issue #660 - Switched to HTTP cache API V2 from Firefox 32 and above
---
 chrome/content/ui/sidebar.js | 68 ++++++++++++++++++++++++++++----------------
 1 file changed, 44 insertions(+), 24 deletions(-)

diff --git a/chrome/content/ui/sidebar.js b/chrome/content/ui/sidebar.js
index 6197b9d..7f515ea 100644
--- a/chrome/content/ui/sidebar.js
+++ b/chrome/content/ui/sidebar.js
@@ -23,7 +23,7 @@ var mainWin = parent;
 // The window handler currently in use
 var requestNotifier = null;
 
-var cacheSession = null;
+var cacheStorage = null;
 var noFlash = false;
 
 // Matcher for disabled filters
@@ -295,43 +295,63 @@ function fillInTooltip(e) {
   var showPreview = Prefs.previewimages && !("tooltip" in item);
   showPreview = showPreview && item.typeDescr == "IMAGE";
   showPreview = showPreview && (!item.filter || item.filter.disabled || item.filter instanceof WhitelistFilter);
+  E("tooltipPreviewBox").hidden = true;
   if (showPreview)
   {
-    // Check whether image is in cache (stolen from ImgLikeOpera)
-    if (!cacheSession)
+    if (!cacheStorage)
     {
-      var cacheService = Cc["@mozilla.org/network/cache-service;1"].getService(Ci.nsICacheService);
-      cacheSession = cacheService.createSession("HTTP", Ci.nsICache.STORE_ANYWHERE, true);
+      let {Services} = Cu.import("resource://gre/modules/Services.jsm", null);
+      // Cache v2 API is enabled by default starting with Gecko 32
+      if (Services.vc.compare(Utils.platformVersion, "32.0") >= 0)
+      {
+        let {LoadContextInfo} = Cu.import("resource://gre/modules/LoadContextInfo.jsm", null);
+        cacheStorage = Services.cache2.diskCacheStorage(LoadContextInfo.default, true);
+      }
+      else
+        cacheStorage = Services.cache.createSession("HTTP", Ci.nsICache.STORE_ANYWHERE, true);
     }
-
-    let cacheListener =
+    
+    let showTooltipPreview = function ()
     {
-       onCacheEntryAvailable: function(descriptor, accessGranted, status)
-       {
-          if (!descriptor)
-            return;
-
-          descriptor.close();
-          // Show preview here since this is asynchronous now
-          // and we have a valid descriptor
-          E("tooltipPreview").setAttribute("src", item.location);
-          E("tooltipPreviewBox").hidden = false;
-       },
-       onCacheEntryDoomed: function(status)
-       {
-       }
+      E("tooltipPreview").setAttribute("src", item.location);
+      E("tooltipPreviewBox").hidden = false;
     };
     try
     {
-      cacheSession.asyncOpenCacheEntry(item.location, Ci.nsICache.ACCESS_READ, cacheListener);
+      if (Ci.nsICacheStorage && cacheStorage instanceof Ci.nsICacheStorage)
+      {
+        cacheStorage.asyncOpenURI(Utils.makeURI(item.location), "", Ci.nsICacheStorage.OPEN_READONLY, {
+          onCacheEntryCheck: function (entry, appCache)
+          {
+            return Ci.nsICacheEntryOpenCallback.ENTRY_WANTED;
+          },
+          onCacheEntryAvailable: function (entry, isNew, appCache, status) {
+            if (!isNew)
+              showTooltipPreview();
+          }
+        });
+      }
+      else
+      {
+        cacheStorage.asyncOpenCacheEntry(item.location, Ci.nsICache.ACCESS_READ, {
+          onCacheEntryAvailable: function(descriptor, accessGranted, status)
+          {
+            if (!descriptor)
+              return;
+            descriptor.close();
+            showTooltipPreview();
+          },
+          onCacheEntryDoomed: function(status)
+          {
+          }
+        });
+      }
     }
     catch (e)
     {
       Cu.reportError(e);
     }
   }
-
-  E("tooltipPreviewBox").hidden = true;
 }
 
 const visual = {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/adblock-plus.git



More information about the Pkg-mozext-commits mailing list