On Thu, Dec 30, 2004 at 03:05:14PM +0100, Marc Gueury wrote:
> Any idea or pointer on how to do in C or javascript ? There is maybe a
> simple way that I miss completely.
Use normal Necko nsIIOService/nsIChannel APIs, passing the
LOAD_ONLY_FROM_CACHE load flag. (note: this is only respected for HTTP
loads; if you have FTP urls they will be loaded from network.)
Something like:
var url = window.content.document.URL;
var urlCharset = window.content.document.characterSet;
var ios = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
var chan = ios.newChannel(url, urlCharset, null);
chan.loadFlags |=
Components.interfaces.nsICachingChannel.LOAD_ONLY_FROM_CACHE;
var stream = chan.open();
Then you can wrap stream with a scriptable input stream and do whatever
you want to do with it. Do note that this blocks the UI (unlikely to be
an issue when loading from cache), and that it does not resolve your
problems with non-ASCII data. You may want to use
nsIScriptableUnicodeConverter for that, but it requires you to know the
charset. chan.contentCharset may help here, but only if the server did
send a charset.
oh... you got the URL from the content window... in that case, you can
use document.characterSet.
-biesi
--
_______________________________________________
Mozilla-netlib mailing list
[email protected]
http://mail.mozilla.org/listinfo/mozilla-netlib