youtube: update scraper for youtube.com change
[conkeror.git] / modules / env.js
blob14293f091297a82cd99c9b3dcf18b33f1a7a666a
1 /**
2  * (C) Copyright 2004-2007 Shawn Betts
3  * (C) Copyright 2007-2009 John J. Foerch
4  * (C) Copyright 2007-2008 Jeremy Maitin-Shepard
5  *
6  * Use, modification, and distribution are subject to the terms specified in the
7  * COPYING file.
8 **/
10 in_module(null);
12 /**
13  * get_os returns a string identifying the current OS.
14  * possible values include 'Darwin', 'Linux' and 'WINNT'.
15  */
16 let (xul_runtime = Cc['@mozilla.org/xre/app-info;1']
17          .getService(Ci.nsIXULRuntime)) {
18     function get_os () {
19         return xul_runtime.OS;
20     }
24 /**
25  * getenv returns the value of a named environment variable or null if
26  * the environment variable does not exist.
27  */
28 let (env = Cc['@mozilla.org/process/environment;1']
29          .getService(Ci.nsIEnvironment)) {
30     function getenv (variable) {
31         if (env.exists(variable))
32             return env.get(variable);
33         return null;
34     }
38 /**
39  * get_home_directory returns an nsILocalFile object of the user's
40  * home directory.
41  */
42 function get_home_directory () {
43     var dir = Cc["@mozilla.org/file/local;1"]
44         .createInstance(Ci.nsILocalFile);
45     if (get_os() == "WINNT")
46         dir.initWithPath(getenv('USERPROFILE') ||
47                          getenv('HOMEDRIVE') + getenv('HOMEPATH'));
48     else
49         dir.initWithPath(getenv('HOME'));
50     return dir;
54 /* get_current_profile returns the name of the current profile, or
55  * null if that information cannot be found.  The result is cached for
56  * quick repeat lookup.  This is safe because xulrunner does not
57  * support switching profiles on the fly.
58  *
59  * Profiles don't necessarily have a name--as such this information should
60  * not be depended on for anything important.  It is mainly intended for
61  * decoration of the window title and mode-line.
62  */
63 let (profile_name = null) {
64     function get_current_profile () {
65         if (profile_name)
66             return profile_name;
67         if ("@mozilla.org/profile/manager;1" in Cc) {
68             profile_name = Cc["@mozilla.org/profile/manager;1"]
69                 .getService(Ci.nsIProfile)
70                 .currentProfile;
71             return profile_name;
72         }
73         var current_profile_path = Cc["@mozilla.org/file/directory_service;1"]
74             .getService(Ci.nsIProperties)
75             .get("ProfD", Ci.nsIFile).path;
76         var profile_service = Cc["@mozilla.org/toolkit/profile-service;1"]
77             .getService(Components.interfaces.nsIToolkitProfileService);
78         var profiles = profile_service.profiles;
79         while (profiles.hasMoreElements()) {
80             var p = profiles.getNext().QueryInterface(Ci.nsIToolkitProfile);
81             if (current_profile_path == p.localDir.path ||
82                 current_profile_path == p.rootDir.path)
83             {
84                 profile_name = p.name;
85                 return p.name;
86             }
87         }
88         return null;
89     }
94 function get_locale () {
95     const LOCALE_PREF = "general.useragent.locale";
96     return get_localized_pref(LOCALE_PREF) || get_pref(LOCALE_PREF);
99 provide("env");