Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: chrome/content/ui/sidebar.js

Issue 6241284884791296: issue #660 - Switch to version 2 of the HTTP cache API (Closed)
Patch Set: Created July 1, 2014, 8:12 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/content/ui/sidebar.js
===================================================================
--- a/chrome/content/ui/sidebar.js
+++ b/chrome/content/ui/sidebar.js
@@ -16,6 +16,11 @@
*/
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+let LoadContextInfo = null;
+try
+{
+ ({LoadContextInfo}) = Cu.import("resource://gre/modules/LoadContextInfo.jsm", {});
Wladimir Palant 2014/07/01 11:58:33 Please use null rather than {} for the context par
saroyanm 2014/07/01 16:45:47 Done.
+} catch (e) {}
// Main browser window
var mainWin = parent;
@@ -23,7 +28,7 @@
// The window handler currently in use
var requestNotifier = null;
-var cacheSession = null;
+var cacheStorageSession = null;
saroyanm 2014/07/01 08:37:37 Not sure if I should use more general name for thi
Wladimir Palant 2014/07/01 11:58:33 This variable name is now a mix of the old and new
saroyanm 2014/07/01 16:45:47 Done.
var noFlash = false;
// Matcher for disabled filters
@@ -295,43 +300,58 @@
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;
saroyanm 2014/07/01 08:37:37 Moved tooltip IMG wrapper here because, during the
if (showPreview)
{
- // Check whether image is in cache (stolen from ImgLikeOpera)
- if (!cacheSession)
+ if (!cacheStorageSession)
{
- var cacheService = Cc["@mozilla.org/network/cache-service;1"].getService(Ci.nsICacheService);
- cacheSession = cacheService.createSession("HTTP", Ci.nsICache.STORE_ANYWHERE, true);
+ //Use cache V2 API from Gecko 32
Wladimir Palant 2014/07/01 11:58:33 This implies that a) we will always use Cache v2 A
saroyanm 2014/07/01 16:45:47 Thought to use hardcoding solution after reading c
Wladimir Palant 2014/07/02 05:00:03 Unfortunately, checking for component existence do
+ if (Services.vc.compare(Utils.platformVersion, "32.0") >= 0)
+ {
+ let cacheService = Cc["@mozilla.org/netwerk/cache-storage-service;1"].getService(Ci.nsICacheStorageService);
+ cacheStorageSession = cacheService.diskCacheStorage(LoadContextInfo.default, false);
Wladimir Palant 2014/07/01 11:58:33 You only need LoadContextInfo here, meaning that y
Wladimir Palant 2014/07/01 12:00:46 From the source code it seems that diskCacheStorag
saroyanm 2014/07/01 16:45:47 I tried to avoid loading LoadContextInfo for each
Wladimir Palant 2014/07/02 05:00:03 It won't be loaded for each item - setting the cac
saroyanm 2014/07/02 07:03:41 Ohh yes sure, thanks..
+ }
+ else
+ {
+ let cacheService = Cc["@mozilla.org/network/cache-service;1"].getService(Ci.nsICacheService);
+ cacheStorageSession = cacheService.createSession("HTTP", Ci.nsICache.STORE_ANYWHERE, true);
+ }
}
let cacheListener =
{
- onCacheEntryAvailable: function(descriptor, accessGranted, status)
+ onCacheEntryAvailable: function(entry, accessGranted, status)
{
- if (!descriptor)
+ if (!entry)
return;
- descriptor.close();
+ entry.close();
// Show preview here since this is asynchronous now
- // and we have a valid descriptor
+ // and we have a valid entry
E("tooltipPreview").setAttribute("src", item.location);
E("tooltipPreviewBox").hidden = false;
},
+ onCacheEntryCheck: function (entry, appcache) {
+ return Ci.nsICacheEntryOpenCallback.ENTRY_WANTED;
+ },
onCacheEntryDoomed: function(status)
{
}
};
Wladimir Palant 2014/07/01 11:58:33 I don't think that using the same listener for bot
saroyanm 2014/07/01 16:45:47 What you think do we need onCacheEntryDoomed here
Wladimir Palant 2014/07/02 05:00:03 Yes, it is part of the interface - we might get er
saroyanm 2014/07/02 07:03:41 I see.
+
try
{
- cacheSession.asyncOpenCacheEntry(item.location, Ci.nsICache.ACCESS_READ, cacheListener);
+ //Use cache V2 API from Gecko 32
+ if (Services.vc.compare(Utils.platformVersion, "32.0") >= 0)
Wladimir Palant 2014/07/01 11:58:33 Please don't duplicate the branch condition here.
saroyanm 2014/07/01 16:45:47 Done.
+ cacheStorageSession.asyncOpenURI(Utils.makeURI(item.location), "", Ci.nsICacheStorage.OPEN_READONLY, cacheListener);
+ else
+ cacheStorageSession.asyncOpenCacheEntry(item.location, Ci.nsICache.ACCESS_READ, cacheListener);
}
catch (e)
{
Cu.reportError(e);
}
}
-
- E("tooltipPreviewBox").hidden = true;
}
const visual = {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld