Replace uses of co_call/continuation API with uses of spawn/Promise API
[conkeror.git] / modules / user-agent.js
blob52b05771e669383cbbc6a5de3762a9df8427d86e
1 /**
2  * (C) Copyright 2007-2011,2013 John J. Foerch
3  * (C) Copyright 2007-2008 Jeremy Maitin-Shepard
4  *
5  * Use, modification, and distribution are subject to the terms specified in the
6  * COPYING file.
7 **/
9 default_pref("general.useragent.extra.conkeror", "Conkeror/"+version);
11 /**
12  * set_user_agent overrides the user agent string globally with whatever
13  * string is passed to it.  If called with null or no argument, any
14  * current override is undone, reverting to Conkeror's default user agent
15  * string.  The override is performed (rather non-conventionally) with a
16  * default pref instead of a user pref, which allows the override to be
17  * done cleanly from the rc, without interference by persisting prefs in
18  * the profile.
19  */
20 function set_user_agent (str) {
21     const p = "general.useragent.override";
22     if (str == null) {
23         clear_default_pref(p);
24         user_pref(p, "");
25         clear_pref(p);
26     } else
27         session_pref(p, str);
31 /**
32  * user_agent_firefox returns a Firefox-like user agent string.  It is
33  * alas, not perfect in all configurations, but should suffice for most
34  * ua-spoofing purposes.
35  */
36 function user_agent_firefox () {
37     var appinfo = Cc['@mozilla.org/xre/app-info;1']
38         .getService(Ci.nsIXULAppInfo);
39     var platform = { Darwin: "Macintosh",
40                      Linux: "X11",
41                      OpenBSD: "X11",
42                      WINNT: "Windows NT"
43                    }[get_os()] || get_os();
44     var geckoversion = appinfo.platformVersion;
45     var dot = geckoversion.indexOf(".");
46     var ldot = geckoversion.indexOf(".", dot + 1);
47     if (ldot > dot)
48         geckoversion = geckoversion.substring(0, ldot);
49     var geckotrail = appinfo.platformBuildID.substr(0, 8);
50     var firefoxversion = geckoversion;
51     return "Mozilla/5.0 "+
52         "("+platform+"; rv:"+geckoversion+") "+
53         "Gecko/"+geckotrail+" Firefox/"+firefoxversion;