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.
11 let EXPORTED_SYMBOLS
= [
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");
24 const iosvc
= Cc
["@mozilla.org/network/io-service;1"].getService(Ci
.nsIIOService
);
27 //////////////////////////////////////////////////////////////////////////////
28 function expungeImageCache (el
, url
) {
29 if (!el
|| typeof(el
.tagName
) !== "string" || el
.tagName
!== "IMG") {
30 if (PREFS
.debugLog
) conlog("WTF! ["+url
+"] is not an image!");
34 //if (PREFS.debugLog) conlog(" converting URL=[", url, "]...");
36 //let uri = iosvc.newURI(url, null, null);
38 //if (PREFS.debugLog) conlog(" URL=[", ourl, "]; URI=[", url, "]");
39 let tools
= Cc
["@mozilla.org/image/tools;1"].getService(Ci
.imgITools
);
40 let cache
= tools
.getImgCacheForDocument(el
.ownerDocument
);
42 if (url
=== undefined) {
43 url
= el
.getAttribute("src");
44 if (PREFS
.debugLog
) conlog(" got URL from image: URL=[", url
, "]...");
46 if (typeof(url
) === "string") {
47 if (PREFS
.debugLog
) conlog(" converting URL=[", url
, "] to URI");
50 if (PREFS
.debugLog
) conlog(" docURI=[", el
.ownerDocument
.documentURI
, "]");
51 baseURI
= iosvc
.newURI(el
.ownerDocument
.documentURI
, null, null);
52 if (PREFS
.debugLog
) conlog(" BASE=[", baseURI
.spec
, "]");
54 url
= iosvc
.newURI(url
, null, baseURI
);
56 if (PREFS
.debugLog
) conlog("got cache object for image with url ", url
.spec
);
58 cache
.removeEntry(url
);
60 if (PREFS
.debugLog
) conlog(" error clearing cache for image with url ", url
.spec
);
61 if (PREFS
.debugLog
) logException("cache error", e
);
64 if (PREFS
.debugLog
) conlog("CAN'T get cache object for document");
67 if (PREFS
.debugLog
) conlog(" some error occuren when clearing cache for image with url ", el
.src
);
68 if (PREFS
.debugLog
) logException("unknown cache error", e
);
73 //////////////////////////////////////////////////////////////////////////////
74 let reloadUrlList
= {};
77 function reloadImage (el
) {
78 if (el
instanceof Ci
.nsIImageLoadingContent
) {
79 if (PREFS
.debugLog
) conlog("forcing reload!");
80 let src
= el
.getAttribute("src");
81 reloadUrlList
[src
] = true;
82 expungeImageCache(el
);
83 oneShotTimer(function () { delete reloadUrlList
[src
]; }, 500);
84 // and for all images in document
85 for (let img
of el
.ownerDocument
.querySelectorAll("img[src]")) {
86 if (img
.getAttribute("src") === src
) {
87 if (img
instanceof Ci
.nsIImageLoadingContent
) {
91 if (PREFS
.debugLog
) logException("reload error", e
);
97 if (PREFS
.debugLog
) conlog("alas...");