better temp blacklister (earlier abort)
[k8imago.git] / code / modules / imgreload.js
blob7f190bfe690df7f74262f82c0bf1e2f26ea5fa2b
1 /* coded by Ketmar // Invisible Vector (psyc://ketmar.no-ip.org/~Ketmar)
2 * Understanding is not required. Only obedience.
4 * This program is free software. It comes without any warranty, to
5 * the extent permitted by applicable law. You can redistribute it
6 * and/or modify it under the terms of the Do What The Fuck You Want
7 * To Public License, Version 2, as published by Sam Hocevar. See
8 * http://www.wtfpl.net/txt/copying/ for more details.
9 */
10 // reload image
11 let EXPORTED_SYMBOLS = [
12 "reloadImage",
13 "reloadUrlList"
16 const {utils:Cu, classes:Cc, interfaces:Ci, results:Cr} = Components;
19 //////////////////////////////////////////////////////////////////////////////
20 Cu.import("chrome://k8-imago-code/content/modules/utils.js");
21 Cu.import(MODULE_PATH+"debuglog.js");
22 Cu.import(MODULE_PATH+"prefs.js");
25 //////////////////////////////////////////////////////////////////////////////
26 function expungeImageCache (el, url) {
27 if (!el || typeof(el.tagName) !== "string" || el.tagName !== "IMG") return;
28 try {
29 let tools = Cc["@mozilla.org/image/tools;1"].getService(Ci.imgITools);
30 let cache = tools.getImgCacheForDocument(el.ownerDocument);
31 if (cache) {
32 if (url === undefined) url = el.getAttribute("src");
33 if (typeof(url) === "string") url = url2uri(url);
34 conlog("got cache object for image with url ", url.spec);
35 try {
36 cache.removeEntry(url);
37 } catch (e) {
38 conlog(" error clearing cache for image with url ", el.src);
39 if (PREFS.debugLog) logException("cache error", e);
42 } catch (e) {}
46 //////////////////////////////////////////////////////////////////////////////
47 let reloadUrlList = {};
50 function reloadImage (el) {
51 if (el instanceof Ci.nsIImageLoadingContent) {
52 conlog("forcing reload!");
53 let src = el.getAttribute("src");
54 expungeImageCache(el);
55 reloadUrlList[src] = true;
56 oneShotTimer(function () { delete reloadUrlList[src]; }, 500);
57 // and for all images in document
58 for (let img of el.ownerDocument.querySelectorAll("img[src]")) {
59 if (img.getAttribute("src") === src) {
60 if (img instanceof Ci.nsIImageLoadingContent) {
61 try {
62 img.forceReload();
63 } catch (e) {
64 logException("reload error", e);
69 } else {
70 conlog("alas...");