Hello,
I'm trying to add a new protocol to a Java application that use
JavaXPCOM to embed the XULRunner engine. For example, I'd like to
type something like "jres://org/my/intro.html" to retrieve the
resource from a jar file downloaded into a web start cache via jnlp.
If you don't know jnlp, let's just say I want to add a "jres:" handler
in addition to "http:", "file:", "jar:", etc.
I created a class that implement nsIProtocolHandler with a contract id
of
"@mozilla.org/network/protocol;1?name=jres".
The complication begins because I need to get the data from a Java
input stream to the browser.
As seen in the following Java code (hopefully it is quite obvious to C+
+ programmers, too), in the newChannel() method I use nsIPipe and
nsIBinaryOutputStream to feed the binary data to the channel.
So my questions are:
1) It works well for html files and images, but it can't handle flash
files (.swf) and
javascripts (.js), etc., which the "http" and "file" protocols
handle flawlessly.
What else should be doing? Should I register content handlers
somewhere?
2) The pipe (nsIPipe) seem to break when I write more than 64k bytes
into it.
While writing to it in a separate thread pausing from time to time
seem to work,
what would you recommend as a more desirable and elegant way?
Thank you for looking.
-Seong
----
//begin code
public nsIChannel newChannel(nsIURI uri) {
nsIInputStreamChannel isChannel = XPCOMUtils.create(
"@mozilla.org/network/input-stream-channel;1",
nsIInputStreamChannel.class);
isChannel.setURI(uri);
pipe = XPCOMUtils.create(
"@mozilla.org/pipe;1", nsIPipe.class);
pipe.init(true, true, 0, 0, null);
isChannel.setContentStream(pipe.getInputStream());
nsIBinaryOutputStream bout = XPCOMUtils.create(
"@mozilla.org/binaryoutputstream;1",
nsIBinaryOutputStream.class);
bout.setOutputStream(pipe.getOutputStream());
byte[] buf = new byte[8192];
int n = 0;
InputStream inStream = getResourceInputStream(uri);
try {
while ((n = inStream.read(buf)) != -1) {
bout.writeByteArray(buf, n);
}
inStream.close();
} catch (IOException e) {
e.printStackTrace();
}
return (nsIChannel) isChannel.queryInterface
(nsIChannel.NS_ICHANNEL_IID);
}
//end code
----
_______________________________________________
dev-embedding mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-embedding