Redirect from nsIChannel

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Redirect from nsIChannel

jefft0
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
_______________________________________________
dev-tech-xpcom mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xpcom
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Redirect from nsIChannel

Boris Zbarsky
On 4/7/13 9:21 PM, [hidden email] 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
_______________________________________________
dev-tech-xpcom mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xpcom
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Redirect from nsIChannel

jefft0
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
_______________________________________________
dev-tech-xpcom mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xpcom
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Redirect from nsIChannel

Boris Zbarsky
On 4/8/13 11:31 AM, [hidden email] 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
_______________________________________________
dev-tech-xpcom mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xpcom
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Redirect from nsIChannel

jefft0
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

_______________________________________________
dev-tech-xpcom mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xpcom
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Redirect from nsIChannel

Boris Zbarsky
On 4/8/13 5:29 PM, [hidden email] 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
_______________________________________________
dev-tech-xpcom mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xpcom
Loading...