From 53c7cc118d45f3eeee6f3aa94f798f475a61fde3 Mon Sep 17 00:00:00 2001 From: Doug Kearns Date: Thu, 2 Oct 2014 14:59:05 +1000 Subject: [PATCH] Update :pageinfo to use the new HTTP cache API. --- common/modules/buffer.jsm | 33 +++++++++++++++------------------ common/modules/services.jsm | 2 +- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/common/modules/buffer.jsm b/common/modules/buffer.jsm index 3ba53d3a..69d26c7f 100644 --- a/common/modules/buffer.jsm +++ b/common/modules/buffer.jsm @@ -2661,25 +2661,22 @@ Buffer.addPageInfoSection("g", "General Info", function (verbose) { let doc = this.focusedFrame.document; // get file size - const ACCESS_READ = Ci.nsICache.ACCESS_READ; - let cacheKey = doc.documentURI; - - for (let proto in array.iterValues(["HTTP", "FTP"])) { - try { - var cacheEntryDescriptor = services.cache.createSession(proto, 0, true) - .openCacheEntry(cacheKey, ACCESS_READ, false); - break; - } - catch (e) {} - } - + let { LoadContextInfo } = Cu.import("resource://gre/modules/LoadContextInfo.jsm", {}); + let contextInfo = LoadContextInfo.fromLoadContext(sanitizer.getContext(doc), false); + let storage = services.cache.diskCacheStorage(contextInfo, false); let pageSize = []; // [0] bytes; [1] kbytes - if (cacheEntryDescriptor) { - pageSize[0] = util.formatBytes(cacheEntryDescriptor.dataSize, 0, false); - pageSize[1] = util.formatBytes(cacheEntryDescriptor.dataSize, 2, true); - if (pageSize[1] == pageSize[0]) - pageSize.length = 1; // don't output "xx Bytes" twice - } + + storage.asyncOpenURI(util.createURI(doc.documentURI), "", + Ci.nsICacheStorage.OPEN_NORMALLY, + { + onCacheEntryCheck: () => Ci.nsICacheEntryOpenCallback.ENTRY_WANTED, + onCacheEntryAvailable: entry => { + pageSize[0] = util.formatBytes(entry.dataSize, 0, false); + pageSize[1] = util.formatBytes(entry.dataSize, 2, true); + if (pageSize[1] == pageSize[0]) + pageSize.length = 1; // don't output "xx Bytes" twice + } + }); let lastModVerbose = new Date(doc.lastModified).toLocaleString(); let lastMod = new Date(doc.lastModified).toLocaleFormat("%x %X"); diff --git a/common/modules/services.jsm b/common/modules/services.jsm index 9629fe71..c0f229d1 100644 --- a/common/modules/services.jsm +++ b/common/modules/services.jsm @@ -32,7 +32,7 @@ var Services = Module("Services", { this.add("appStartup", "@mozilla.org/toolkit/app-startup;1", "nsIAppStartup"); this.add("bookmarks", "@mozilla.org/browser/nav-bookmarks-service;1", "nsINavBookmarksService"); this.add("browserSearch", "@mozilla.org/browser/search-service;1", "nsIBrowserSearchService"); - this.add("cache", "@mozilla.org/network/cache-service;1", "nsICacheService"); + this.add("cache", "@mozilla.org/netwerk/cache-storage-service;1", "nsICacheStorageService"); this.add("chromeRegistry", "@mozilla.org/chrome/chrome-registry;1", "nsIXULChromeRegistry"); this.add("clipboard", "@mozilla.org/widget/clipboard;1", "nsIClipboard"); this.add("clipboardHelper", "@mozilla.org/widget/clipboardhelper;1", "nsIClipboardHelper");