1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-01-03 19:14:11 +01:00

Update :pageinfo to use the new HTTP cache API.

This commit is contained in:
Doug Kearns
2014-10-02 14:59:05 +10:00
parent 5b4d9dceae
commit 53c7cc118d
2 changed files with 16 additions and 19 deletions

View File

@@ -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");

View File

@@ -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");