2 * (C) Copyright 2004-2007 Shawn Betts
3 * (C) Copyright 2007-2009 John J. Foerch
4 * (C) Copyright 2007-2008 Jeremy Maitin-Shepard
6 * Use, modification, and distribution are subject to the terms specified in the
11 * get_os returns a string identifying the current OS.
12 * possible values include 'Darwin', 'Linux' and 'WINNT'.
14 let (xul_runtime = Cc['@mozilla.org/xre/app-info;1']
15 .getService(Ci.nsIXULRuntime)) {
17 return xul_runtime.OS;
23 * getenv returns the value of a named environment variable or null if
24 * the environment variable does not exist.
26 let (env = Cc['@mozilla.org/process/environment;1']
27 .getService(Ci.nsIEnvironment)) {
28 function getenv (variable) {
29 if (env.exists(variable))
30 return env.get(variable);
37 * get_home_directory returns an nsILocalFile object of the user's
40 function get_home_directory () {
41 var dir = Cc["@mozilla.org/file/local;1"]
42 .createInstance(Ci.nsILocalFile);
43 if (get_os() == "WINNT")
44 dir.initWithPath(getenv('USERPROFILE') ||
45 getenv('HOMEDRIVE') + getenv('HOMEPATH'));
47 dir.initWithPath(getenv('HOME'));
52 /* get_current_profile returns the name of the current profile, or
53 * null if that information cannot be found. The result is cached for
54 * quick repeat lookup. This is safe because xulrunner does not
55 * support switching profiles on the fly.
57 * Profiles don't necessarily have a name--as such this information should
58 * not be depended on for anything important. It is mainly intended for
59 * decoration of the window title and mode-line.
61 let (profile_name = null) {
62 function get_current_profile () {
65 if ("@mozilla.org/profile/manager;1" in Cc) {
66 profile_name = Cc["@mozilla.org/profile/manager;1"]
67 .getService(Ci.nsIProfile)
71 var current_profile_path = Cc["@mozilla.org/file/directory_service;1"]
72 .getService(Ci.nsIProperties)
73 .get("ProfD", Ci.nsIFile).path;
74 var profile_service = Cc["@mozilla.org/toolkit/profile-service;1"]
75 .getService(Components.interfaces.nsIToolkitProfileService);
76 var profiles = profile_service.profiles;
77 while (profiles.hasMoreElements()) {
78 var p = profiles.getNext().QueryInterface(Ci.nsIToolkitProfile);
79 if (current_profile_path == p.localDir.path ||
80 current_profile_path == p.rootDir.path)
82 profile_name = p.name;
92 function get_locale () {
93 const LOCALE_PREF = "general.useragent.locale";
94 return get_localized_pref(LOCALE_PREF) || get_pref(LOCALE_PREF);