Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

custom source, how to?

4 views
Skip to first unread message

Dmitry Dartz

unread,
May 29, 2008, 6:08:56 PM5/29/08
to
Hi all,

Suppose I have custom sources for some html, css, js and images that I can't
save to the files, and I want mozilla browser to use them as memory streams.
Is there a way to intercept URLs/URIs activity and provide my own streams
with content I have? What interfaces/listeners to check? Any ideas?

Thanks in advance,
J


Igor Tandetnik

unread,
May 30, 2008, 2:43:22 PM5/30/08
to

You can register a protocol handler for a custom protocol (as in,
myproto://anything) . You create an XPCOM component implementing
nsIProtocolHandler, and register it under the contractid of
"@mozilla.org/network/protocol;1?name=myproto". The real work happens in
nsIProtocolHandler::NewChannel where you need to create and return an
nsIChannel implementation given a URL. Probably the easiest way is to
use nsIInputStreamChannel component, which is a channel that gets its
data from a stream (specifically nsIInputStream).

Igor Tandetnik


Dmitry Dartz

unread,
May 31, 2008, 9:48:19 AM5/31/08
to

Thanks Igor,
That's a good way indeed.
But I wanted to work with good old http. Is it possible to intercept all
http/https requests, handle all requests with specific host name, and pass
all the other requests to the standard handler? I think it may require
intercepting service that creates nsIOService. Right or there is a simplier
way?
Also I found some info related to nsIURIContentListener, but could not get
DoContent() method called yet, and looks like it unconditionally goes
through the standard network. If so, it is not what I need.
Is there another way?

TIA.


Boris Zbarsky

unread,
May 31, 2008, 10:49:43 AM5/31/08
to
Dmitry Dartz wrote:
> But I wanted to work with good old http. Is it possible to intercept all
> http/https requests, handle all requests with specific host name, and pass
> all the other requests to the standard handler?

Sounds like an HTTP proxy to me.

-Boris

Dmitry Dartz

unread,
May 31, 2008, 11:06:21 AM5/31/08
to

yep, such a crazy HTTP proxy that intercepts one and only one host and is
completely transparent for anything else, including any real proxy if it is
set. Would you please recommend a direction to dig into?

TIA


Boris Zbarsky

unread,
Jun 1, 2008, 2:49:01 PM6/1/08
to
Dmitry Dartz wrote:
> yep, such a crazy HTTP proxy that intercepts one and only one host and is
> completely transparent for anything else, including any real proxy if it is
> set. Would you please recommend a direction to dig into?

As I recall, proxies can be chained. See nsIProtocolProxyService? That lets
you filter the list or proxies based on the URI.

-Boris

Dmitry Dartz

unread,
Jun 1, 2008, 6:22:36 PM6/1/08
to

Thanks. I'll check all stuff around nsIProtocolProxyService.
Before now I thought it would be easier to derive a class from
nsHttpHandler and register it for the http protocol right after xpcom is
initialized and all the modules are loaded and initialized. This class will
create standard channels for all hosts except specified one that I need
to mimic. To me it looks like it is an acceptable way for an application
that embeds Mozilla browser.
What do you think?

Regards


Boris Zbarsky

unread,
Jun 1, 2008, 10:08:28 PM6/1/08
to
Dmitry Dartz wrote:
> Before now I thought it would be easier to derive a class from
> nsHttpHandler and register it for the http protocol right after xpcom is
> initialized and all the modules are loaded and initialized.

That would work as long as the protocol handler caching in nsIOService doesn't
bite you.

-Boris

Dmitry Dartz

unread,
Jun 2, 2008, 5:19:36 AM6/2/08
to

Thanks, I noticed this cache and it looks like nsIOService fills up the
cache upon
requests are comming, so it looks like I'm safe with my approach until at
least one
request with http scheme is made before I register my new handler. Right?
Probably the best place for installing the handler is callback triggered on
the
network-up event. I know tear-down event, probably something like network-up
is implemented too.

On the other hand, it looks like nsIProtocolProxyService is a better way and
I'd
prefer to use it instead of mybrandnewHttpHandler. Still checking
nsIProtocolProxyService
and around to see if it's useful in my case.

Regards.


Boris Zbarsky

unread,
Jun 2, 2008, 11:40:22 AM6/2/08
to
Dmitry Dartz wrote:
> Thanks, I noticed this cache and it looks like nsIOService fills up the
> cache upon
> requests are comming, so it looks like I'm safe with my approach until at
> least one
> request with http scheme is made before I register my new handler. Right?

Not quite. You're safe until someone creates an nsIURI object for an
http:// or https:// URI.

-Boris

Dmitry Dartz

unread,
Jun 4, 2008, 6:24:57 AM6/4/08
to

Well, I checked how nsProtocolProxyService works.
Seems it's possible to intercept access to a particular host or URL and
direct the channel to the proxy. Protocol's channel will connect to the
proxy's host/port
and proxy will have to respond. Great so far.
But I did not find a way on how to intercept URL using
nsProtocolProxyService without
creating any listening sockets. Looks like it's not possible to intercept
protocol channels
in order to supply my own streams without intercepting the protocols
themselves and it's
a bit tricky.

Regards.


0 new messages