!import
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
1 //@line 37 "/home/visbrero/mnt/roisin/rev_control/hg/mozilla/toolkit/components/urlformatter/src/nsURLFormatter.js"
2 /**
3 * @class nsURLFormatterService
4 *
5 * nsURLFormatterService exposes methods to substitute variables in URL formats.
6 *
7 * Mozilla Applications linking to Mozilla websites are strongly encouraged to use
8 * URLs of the following format:
9 *
10 * http[s]://%LOCALE%.%SERVICE%.mozilla.[com|org]/%LOCALE%/
11 */
12
13 const Cc = Components.classes;
14 const Ci = Components.interfaces;
15 const Cu = Components.utils;
16
17 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
18
nsURLFormatterService
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
19 function nsURLFormatterService() {}
20 nsURLFormatterService.prototype = {
21 classDescription: "Application URL Formatter Service",
22 contractID: "@mozilla.org/toolkit/URLFormatterService;1",
23 classID: Components.ID("{e6156350-2be8-11db-a98b-0800200c9a66}"),
24 QueryInterface: XPCOMUtils.generateQI([Ci.nsIURLFormatter]),
25
26 _defaults: {
get_appInfo
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
27 get appInfo() {
28 if (!this._appInfo)
29 this._appInfo = Cc["@mozilla.org/xre/app-info;1"].
30 getService(Ci.nsIXULAppInfo).
31 QueryInterface(Ci.nsIXULRuntime);
32 return this._appInfo;
33 },
34
LOCALE
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
35 LOCALE: function() Cc["@mozilla.org/chrome/chrome-registry;1"].
36 getService(Ci.nsIXULChromeRegistry).getSelectedLocale('global'),
VENDOR
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
37 VENDOR: function() this.appInfo.vendor,
NAME
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
38 NAME: function() this.appInfo.name,
ID
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
39 ID: function() this.appInfo.ID,
VERSION
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
40 VERSION: function() this.appInfo.version,
APPBUILDID
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
41 APPBUILDID: function() this.appInfo.appBuildID,
PLATFORMVERSION
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
42 PLATFORMVERSION: function() this.appInfo.platformVersion,
PLATFORMBUILDID
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
43 PLATFORMBUILDID: function() this.appInfo.platformBuildID,
APP
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
44 APP: function() this.appInfo.name.toLowerCase().replace(/ /, ""),
OS
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
45 OS: function() this.appInfo.OS,
XPCOMABI
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
46 XPCOMABI: function() this.appInfo.XPCOMABI
47 },
48
uf_formatURL
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
49 formatURL: function uf_formatURL(aFormat) {
50 var _this = this;
anon:51:30
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
51 var replacementCallback = function(aMatch, aKey) {
52 if (aKey in _this._defaults) // supported defaults
53 return _this._defaults[aKey]();
54 Cu.reportError("formatURL: Couldn't find value for key: " + aKey);
55 return '';
56 }
57 return aFormat.replace(/%([A-Z]+)%/g, replacementCallback);
58 },
59
uf_formatURLPref
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
60 formatURLPref: function uf_formatURLPref(aPref) {
61 var format = null;
62 var PS = Cc['@mozilla.org/preferences-service;1'].
63 getService(Ci.nsIPrefBranch);
64
65 try {
66 format = PS.getComplexValue(aPref, Ci.nsISupportsString).data;
67 } catch(ex) {
68 Cu.reportError("formatURLPref: Couldn't get pref: " + aPref);
69 return "about:blank";
70 }
71
72 if (!PS.prefHasUserValue(aPref) &&
73 /^chrome:\/\/.+\/locale\/.+\.properties$/.test(format)) {
74 // This looks as if it might be a localised preference
75 try {
76 format = PS.getComplexValue(aPref, Ci.nsIPrefLocalizedString).data;
77 } catch(ex) {}
78 }
79
80 return this.formatURL(format);
81 }
82 };
83
NSGetModule
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
84 function NSGetModule(aCompMgr, aFileSpec)
85 XPCOMUtils.generateModule([nsURLFormatterService]);