Search code examples
firefoxcachingdownloadoffline

Firefox download already cached file


For MS IE, I can dig out a already downloaded file from the browser cache, with this WIN32 API

DownloadFile = URLDownloadToFile(0&, sSourceUrl, sLocalFile, 0, 0) = ERROR_SUCCESS

Is there a simple way for Firefox?

How does Firefox store the link between the original URL and the cache filename?

places.sqlite? which tables and columns?


Solution

  • You call nsICacheService.createSession(), then nsICacheSession.openCacheEntry() on the result. Basically, it's the same code as in How to get images from cache using a XPCOM Component in Firefox but clientID should be "http" rather than "image" (you want to look at the HTTP browsing cache rather than the image cache).

    At least that's how you do it from inside Firefox. I suspect that you want to read the cache from an independent application - well, good luck replicating Firefox code. http://mxr.mozilla.org/mozilla-central/source/netwerk/cache/nsDiskCacheMap.cpp should be a good starting point.