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

Redirect from nsIChannel

63 views
Skip to first unread message

jef...@gmail.com

unread,
Apr 7, 2013, 9:21:42 PM4/7/13
to
Hello. I have a protocol handler where newChannel returns an nsIChannel. When the channel's asyncOpen is called, I need to redirect to a new channel with a new URI. (My protocol handler handles images and other resources, not just the top-level window, so I can't use a hack to update the URL bar.)

Is there a way in JavaScript for a channel to tell Firefox to redirect to a new channel?

Thank you,
- Jeff Thompson

Boris Zbarsky

unread,
Apr 8, 2013, 7:56:37 AM4/8/13
to
On 4/7/13 9:21 PM, jef...@gmail.com wrote:
> Hello. I have a protocol handler where newChannel returns an nsIChannel. When the channel's asyncOpen is called, I need to redirect to a new channel with a new URI.

Is there a reason you're not just returning said new channel from your
newChannel implementation?

-Boris

jef...@gmail.com

unread,
Apr 8, 2013, 11:31:17 AM4/8/13
to
On Monday, April 8, 2013 4:56:37 AM UTC-7, Boris Zbarsky wrote:
> On 4/7/13 9:21 PM, jefft0 wrote:
>
> > Hello. I have a protocol handler where newChannel returns an nsIChannel. When the channel's asyncOpen is called, I need to redirect to a new channel with a new URI.
>
>
>
> Is there a reason you're not just returning said new channel from your
>
> newChannel implementation?
>
>
>
> -Boris

Hi Boris. I would like to return the new channel, but newChannel is not asynchronous, but the call to nsIChannel asyncOpen is asynchronous. I need to use the initial URI to look up on the network which can take a few seconds, and then redirect so that Firefox can asynchronously load from the new URI.

Is it OK for newChannel to block for a few seconds while looking up the new URI? If not, then I need to do something inside asyncOpen. Is that right?

Thanks,
- Jeff T

Boris Zbarsky

unread,
Apr 8, 2013, 4:34:36 PM4/8/13
to
On 4/8/13 11:31 AM, jef...@gmail.com wrote:
> Hi Boris. I would like to return the new channel, but newChannel is not asynchronous, but the call to nsIChannel asyncOpen is asynchronous. I need to use the initial URI to look up on the network which can take a few seconds, and then redirect so that Firefox can asynchronously load from the new URI.

OK. In that case, you probably want to do an actual redirect from your
old channel to the new one.

That mainly consists of the following:

1) Creating the new channel and setting it up correctly.
2) Notifying redirect observers that you're redirecting and waiting
for them to respond.
3) calling asyncOpen on the new channel with your request observer.

I don't see any JS examples offhand, unfortunately, but this should all
be doable from JS, yes.

> Is it OK for newChannel to block for a few seconds while looking up the new URI?

No, it's not. ;)

-Boris

jef...@gmail.com

unread,
Apr 8, 2013, 5:29:43 PM4/8/13
to
On Monday, April 8, 2013 1:34:36 PM UTC-7, Boris Zbarsky wrote:
> OK. In that case, you probably want to do an actual redirect from your
> old channel to the new one.
>
> That mainly consists of the following:
>
> 1) Creating the new channel and setting it up correctly.
> 2) Notifying redirect observers that you're redirecting and waiting
> for them to respond.
> 3) calling asyncOpen on the new channel with your request observer.
>
> I don't see any JS examples offhand, unfortunately, but this should all
> be doable from JS, yes.

Thanks for the reply. Is there C++ sample code for doing a redirect?

- Jeff T

Boris Zbarsky

unread,
Apr 8, 2013, 10:17:34 PM4/8/13
to
On 4/8/13 5:29 PM, jef...@gmail.com wrote:
> Thanks for the reply. Is there C++ sample code for doing a redirect?

http://mxr.mozilla.org/mozilla-central/source/netwerk/protocol/http/nsHttpChannel.cpp
has a nsHttpChannel::StartRedirectChannelToURI, but this calls the
redirect observers in a kinda complicated way....

Not sure anything else really does the right thing, though.

-Boris
0 new messages