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

firefox protocol handler

32 views
Skip to first unread message

ianop...@gmail.com

unread,
Oct 30, 2007, 11:37:22 AM10/30/07
to
G'day everyone,

I'm trying to write a new protocol handler for firefox. At the first
level it will take a nereus://machine@domain/path url and rearrange
this to a http://domain/machine/path URL.
This works fine. However I don't want it to change the actual
displayed address in the addressbar? Any ideas are very welcome. Thank
you very much for your help.

I was also wondering if it is possible in javascript to hook in the
firefox functions to use rsa encryption of a channel?

The relevant method (i think) is included here:
newChannel: function(aURI)
{
//alert("here we are2");
var ios =
Components.classes[kIOSERVICE_CONTRACTID].getService(nsIIOService);
//hack against crash by providing a correct return channel
var dumbnsiURI = ios.newURI("chrome://nereus/locale/
formatError.html", null, null);
var dumbChannel =
ios.newChannelFromURI(dumbnsiURI).QueryInterface(Components.interfaces.nsIChannel);

var uri = Components.classes["@mozilla.org/network/standard-url;
1"].createInstance(nsIURI);
var partURI = aURI.spec.split("@");
var machine = partURI[0].substring(9);
var rest = partURI[1];
var index = rest.indexOf("/");
var domain = rest.substring(0, index);
var path = rest.substring(index + 1);
uri.spec = "http://" + domain + "/" + machine + "/" + path + path;
myURI = uri.resolve(uri.spec);

try
{
// rewrites the url in the location bar back to http
// try not to rewrite .. and it works ..
nsiURI = ios.newURI("http:" + myURI.substring(7), null, null);
}
catch(e)
{
// it isn't a valid url
return dumbChannel;
}

// if it doesnt come from a link the ref is written here
var myChannel =
ios.newChannelFromURI(nsiURI).QueryInterface(Components.interfaces.nsIHttpChannel);

// else if it comes from a link we call "http-on-modify-request"
this.observe(null,"app-startup",null)

return myChannel;
},

Boris Zbarsky

unread,
Oct 30, 2007, 10:37:41 PM10/30/07
to
ianop...@gmail.com wrote:
> uri.spec = "http://" + domain + "/" + machine + "/" + path + path;
> myURI = uri.resolve(uri.spec);

Uh.... Why, exactly?

> // rewrites the url in the location bar back to http
> // try not to rewrite .. and it works ..
> nsiURI = ios.newURI("http:" + myURI.substring(7), null, null);

Why not just create the URI using newURI to start with, without worrying about
myURI and |uri|?

> // if it doesnt come from a link the ref is written here
> var myChannel =
> ios.newChannelFromURI(nsiURI).QueryInterface(Components.interfaces.nsIHttpChannel);

Now set the originalURI of the channel to aURI, if that's what you want to
appear in the URL bar.

-Boris

ianop...@gmail.com

unread,
Oct 31, 2007, 6:25:44 AM10/31/07
to
Thank boris. You're awesome! I put in your changes and tidied it up a
little. However it still changes the url in the address bar. Is there
some other thing I need to notify when I change the originalURI?

here's the current code:

newChannel: function(aURI)
{


var ios =
Components.classes[kIOSERVICE_CONTRACTID].getService(nsIIOService);

var partURI = aURI.spec.split("@");


var machine = partURI[0].substring(9);
var rest = partURI[1];
var index = rest.indexOf("/");
var domain = rest.substring(0, index);
var path = rest.substring(index + 1);

nsiURI = ios.newURI("http://" + domain + "/" + machine + "/" +
path, null, null);

var myChannel =
ios.newChannelFromURI(nsiURI).QueryInterface(Components.interfaces.nsIHttpChannel);
myChannel.originalURI = aURI;

// if it comes from a link we call "http-on-modify-request"

Boris Zbarsky

unread,
Oct 31, 2007, 12:12:34 PM10/31/07
to
ianop...@gmail.com wrote:
> However it still changes the url in the address bar.

Maybe I misunderstood your original question? I assumed that you wanted the
address bar to show the "nereus://machine@domain/path" URI. Is that not the
case? If not, what do you want it to show?

-Boris

ianop...@gmail.com

unread,
Oct 31, 2007, 2:23:28 PM10/31/07
to
On Oct 31, 4:12 pm, Boris Zbarsky <bzbar...@mit.edu> wrote:

Yep that's exactly right. I want someone to type in nereus://machine@domain/path
and for that to remain in the address bar, while the content displayed
is from http://domain/machine/path
At the moment it gets the correct content, but displays the http url.

thanks again,
Ian

Boris Zbarsky

unread,
Oct 31, 2007, 3:11:46 PM10/31/07
to
ianop...@gmail.com wrote:
> Yep that's exactly right. I want someone to type in nereus://machine@domain/path
> and for that to remain in the address bar, while the content displayed
> is from http://domain/machine/path
> At the moment it gets the correct content, but displays the http url.

Even though you set the originalURI for the channel to the nereus://
URL? That shouldn't be happening. Which Gecko version is this?

For that matter, any load in a docshell will set the channel's
originalURI to the URI actually being loaded. So I'm really not sure
what's going on here.... unless the http:// URI you load does an HTTP
redirect?

-Boris

0 new messages