How construct nsIURI aBaseURI object?

Talk about add-ons and extension development.
Post Reply
Diamanti
Posts: 778
Joined: June 12th, 2008, 9:02 am

How construct nsIURI aBaseURI object?

Post by Diamanti »

How pass. aBaseURI parameter to newChannel2 nsIIOService?
morat
Posts: 6403
Joined: February 3rd, 2009, 6:29 pm

Re: How construct nsIURI aBaseURI object?

Post by morat »

If you are using the spec param, then just use null for the baseURI param.

Try these newURI(aSpec, aOriginCharset, aBaseURI) code snippets in the browser console.

Code: Select all

(function () {
  var io = Components.classes["@mozilla.org/network/io-service;1"].
    getService(Components.interfaces.nsIIOService);
  var uri = io.newURI("http://www.example.com/alpha/?beta=gamma#delta", null, null);
  console.log("example 1: " + uri.spec);
  console.log(uri);
})();

(function () {
  var io = Components.classes["@mozilla.org/network/io-service;1"].
    getService(Components.interfaces.nsIIOService);
  var baseURI = io.newURI("http://www.example.com/alpha/?beta=gamma#delta", null, null);
  var uri = io.newURI(null, null, baseURI);
  console.log("example 2: " + uri.spec);
  console.log(uri);
})();

(function () {
  var io = Components.classes["@mozilla.org/network/io-service;1"].
    getService(Components.interfaces.nsIIOService);
  var baseURI = io.newURI("http://www.test.com/aaa/?bbb=ggg#ddd", null, null);
  var uri = io.newURI("http://www.example.com/alpha/?beta=gamma#delta", null, baseURI);
  console.log("example 3: " + uri.spec);
  console.log(uri);
})();
The second example removes the reference portion of the url. (part after "#")

The third example uses the spec param so ignores the baseURI param.

Reference
http://searchfox.org/mozilla-release/so ... ervice.idl
http://searchfox.org/mozilla-release/so ... nsIURI.idl
Diamanti
Posts: 778
Joined: June 12th, 2008, 9:02 am

Re: How construct nsIURI aBaseURI object?

Post by Diamanti »

When, to handle a protocol, I use

Code: Select all

var url="chrome://extpath/content/Email.htm?mailto=mailto:"
let ch=ios.newChannel2(url+aURI.spec.substr(aURI.spec.indexOf(":")+1), null, null, null, Cc["@mozilla.org/scriptsecuritymanager;1"].getService(Ci.nsIScriptSecurityManager).getSystemPrincipal(), null, Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL, Ci.nsIContentPolicy.TYPE_OTHER);
I get chrome protocol transformed to file protocol.
Do it not is possible to mantain the chrome protocol?
morat
Posts: 6403
Joined: February 3rd, 2009, 6:29 pm

Re: How construct nsIURI aBaseURI object?

Post by morat »

I don't know how to mantain that.

Maybe you could convert the file url to a chrome url.

Protocol conversion example
http://forums.mozillazine.org/viewtopic ... &t=2999471
Post Reply