47 const Cc = Components.classes;
48 const Ci = Components.interfaces;
49 const Cr = Components.results
50 const Cu = Components.utils
77 newURI:
function URLUtils_newURI(aSpec, aCharset, aBaseURI) {
78 var
ioService =
Cc[
"@mozilla.org/network/io-service;1"]
79 .getService(
Ci.nsIIOService);
82 uri = ioService.newURI(aSpec, aCharset, aBaseURI);
100 addQuery:
function URLUtils_addQuery(aURL, aQueryParams) {
102 var urlQueryParams = {};
103 this.extractQuery(aURL, urlQueryParams);
106 for (paramName in aQueryParams) {
107 urlQueryParams[paramName] = aQueryParams[paramName];
111 var urlQuery = this.produceQuery(urlQueryParams);
114 var
url =
Cc[
"@mozilla.org/network/standard-url;1"]
115 .createInstance(
Ci.nsIStandardURL);
116 url.init(
Ci.nsIStandardURL.URLTYPE_STANDARD, 0, aURL,
null,
null);
117 url.QueryInterface(
Ci.nsIURL);
118 url.query = urlQuery;
134 produceQuery:
function URLUtils_produceQuery(aParams) {
135 if (typeof aParams !==
'object') {
return null; }
138 for (var param in aParams) {
143 return stack.join(
"&");
158 extractQuery:
function URLUtils_extractQuery(aURLSpec, aQueryParams) {
160 var
url = this.
newURI(aURLSpec).QueryInterface(
Ci.nsIURL);
164 var queryStr = url.query;
169 var queryParamList = queryStr.split(
"&");
170 for (var
i = 0;
i < queryParamList.length;
i++) {
171 var queryParam = queryParamList[
i].split(
"=");
172 if (queryParam.length >= 2) {
173 aQueryParams[queryParam[0]] = decodeURIComponent(queryParam[1]);
175 else if (queryParam.length == 1) {
176 aQueryParams[queryParam[0]] =
true;
184 convertURLToDisplayName:
function URLUtils_convertURLToDisplayName(aURL) {
188 urlDisplay = decodeURI( aURL );
190 dump(
"convertURLToDisplayName, oops! URI decode weirdness: " + err +
"\n");
194 if ( urlDisplay.lastIndexOf(
'/') != -1 )
196 urlDisplay = urlDisplay.substring( urlDisplay.lastIndexOf(
'/') + 1, urlDisplay.length );
198 else if ( aURL.lastIndexOf(
'\\') != -1 )
200 urlDisplay = aURL.substring( aURL.lastIndexOf(
'\\') + 1, aURL.length );
203 if ( ! urlDisplay.length )
nsString encodeURIComponent(const nsString &c)
function newURI(aURLString)
_getSelectedPageStyle s i