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;
},
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
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"
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
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
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