Boris Zbarsky wrote:
> Fabrice Desr� wrote:
>
>> In a mozembed application, I need to provide support for custom URI
>> schemes, in addition to the standard http://...
>> How can I achieve this ?
>
> You need to implement the relevant nsIProtocolHandler and register it.
> See
>
http://lxr.mozilla.org/seamonkey/source/netwerk/base/public/nsIProtocolHandler.idl
> You may also need to implement an nsIChannel implementation for that
> protocol (the channel that newChannel() will return).
I had lots of problems when doing this. To save you some time, I enclose a
bit of the code I used to write the channel.
Hope it helps,
YA
--
The early bird gets the worm.
The early worm gets eaten.
NS_IMETHODIMP MozillaProtocolHandler::NewChannel(nsIURI *aURI, nsIChannel **_retval)
{
nsresult rv;
URI wx_provided_uri = ConvertURI(aURI);
//Converting from nsIURI to my string format
ProtocolChannel* input_channel = mProtocolHandler->OpenChannel(wx_provided_uri);
//Determines input_channel->GetContentType() and input_channel->GetCharset()
if(!input_channel)
return NS_ERROR_FILE_NOT_FOUND;
/**
* This might be made more Mozilla-like (i.e. no "new"), but it seems to work,
including cleanup.
*
* Is this too much implementation-dependent ? I don't think so, but could be.
*/
nsCOMPtr<nsIInputStream> embedder_stream = new MozillaStream(input_channel);
//Translates a stream from the library I'm using to a MozillaStream
const nsCString content_type((const char*)(input_channel->GetContentType()));
const nsCString charset ((const char*)(input_channel->GetCharset()));
rv = NS_NewInputStreamChannel(_retval, aURI, embedder_stream, content_type, charset,
-1);//<This is the important line
return NS_OK;
}