Hi all,
i'm writing a simple MHT Viewer capable of displaying
MHT files received from a servcer with the special content type
text/mht.
I Implemented a SteamConverter 'from=text/mht&to=*/*',
which decodes the MIME and displays the first part.
The StreamConv also decodes all additional parts contained in the MHT
and stores them in my 'MhtCacheService' service.
Then I implemented the mhtcache: protocol, capable of retrieving
cached object from my MhtCacheService, this seems to work fine
with HTML or other String-ish data.
For instance a GIF image wont work, although, when dumping
the cache contents do disk at the time of access, the files
is 100% identical with the original image.
1)
Any idea why GIF's (ie. binary data) won't work?
2)
Would it be possible to get rid of my homebrew-cache and
use nsICache* stuff?
(would save me rewriting the URI's in the main MHT document)
I tried that using sample code from TestAsyncCache.js in mozilla-lxr,
but, altough my data appears in about:cache (client-id 'mhtcache')
when loading the html document, it fetches the image again via
network.
Any hints on getting that to work?
I'd really appreciate any help,
/ karl
----
Here is my implementation for 1):
// 'mhtcache:' protocol creates 'MHTProtocolChannel'
MHTProtocolChannel.prototype.asyncOpen = function (streamListener,
context)
{
this.streamListener = streamListener;
this.context = context;
var cachekey = this.URI.spec.substr(String("mhtcache:").length);
var cachesvc = getService(FSC_MHTCACHESERVICE_CONTRACTID,
"fscIMhtCacheService");
var cacheentry = cachesvc.getContent(cachekey);
cacheentry = cacheentry.wrappedJSObject;
// does decoding from QP or B64 into String
var data = cacheentry.getDecoded();
this.contentType = cacheentry.contenttype;
this.respond(data);
}
MHTProtocolChannel.prototype.respond = function (str)
{
this.stringStream =
createInstance("@mozilla.org/io/string-input-stream;1",
"nsIStringInputStream");
this.streamListener.onStartRequest(this, this.context);
var len = str.length;
/// Here, when dumping 'str' to a file, it's 100% the right image data.
this.stringStream.setData(str, len);
this.streamListener.onDataAvailable(this, this.context,
this.stringStream, 0, len);
this.streamListener.onStopRequest(this, this.context,
Components.results.NS_OK);
/// Firefox shows an Image-placeholder claiming 'image cannot be
displayed
/// because it contains errors'
}
:wq
_______________________________________________
Mozilla-netlib mailing list
[email protected]
http://mail.mozilla.org/listinfo/mozilla-netlib