Bug 1700051: part 11) Change `mozInlineSpellStatus::InitForRange` to static factory...
[gecko.git] / devtools / shared / system.js
blobf58e89ba1c29baa2e9022b874e6070b205b70e5d
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 "use strict";
6 const { Cc, Ci } = require("chrome");
8 loader.lazyRequireGetter(this, "Services");
9 loader.lazyRequireGetter(
10   this,
11   "DevToolsServer",
12   "devtools/server/devtools-server",
13   true
15 loader.lazyRequireGetter(
16   this,
17   "AppConstants",
18   "resource://gre/modules/AppConstants.jsm",
19   true
21 loader.lazyGetter(this, "hostname", () => {
22   try {
23     // On some platforms (Linux according to try), this service does not exist and fails.
24     return Cc["@mozilla.org/network/dns-service;1"].getService(Ci.nsIDNSService)
25       .myHostName;
26   } catch (e) {
27     return "";
28   }
29 });
30 loader.lazyGetter(this, "endianness", () => {
31   if (new Uint32Array(new Uint8Array([1, 2, 3, 4]).buffer)[0] === 0x04030201) {
32     return "LE";
33   }
34   return "BE";
35 });
37 const APP_MAP = {
38   "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}": "firefox",
39   "{3550f703-e582-4d05-9a08-453d09bdfdc6}": "thunderbird",
40   "{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}": "seamonkey",
41   "{718e30fb-e89b-41dd-9da7-e25a45638b28}": "sunbird",
42   "{aa3c5121-dab2-40e2-81ca-7ea25febc110}": "mobile/android",
45 var CACHED_INFO = null;
47 function getSystemInfo() {
48   if (CACHED_INFO) {
49     return CACHED_INFO;
50   }
52   const appInfo = Services.appinfo;
53   const win = Services.wm.getMostRecentWindow(DevToolsServer.chromeWindowType);
54   const [processor, compiler] = appInfo.XPCOMABI.split("-");
55   let dpi, useragent, width, height, physicalWidth, physicalHeight, brandName;
56   const appid = appInfo.ID;
57   const apptype = APP_MAP[appid];
58   const geckoVersion = appInfo.platformVersion;
59   const hardware = "unknown";
60   let version = "unknown";
62   const os = appInfo.OS;
63   version = appInfo.version;
65   const bundle = Services.strings.createBundle(
66     "chrome://branding/locale/brand.properties"
67   );
68   if (bundle) {
69     brandName = bundle.GetStringFromName("brandFullName");
70   } else {
71     brandName = null;
72   }
74   if (win) {
75     const utils = win.windowUtils;
76     dpi = utils.displayDPI;
77     useragent = win.navigator.userAgent;
78     width = win.screen.width;
79     height = win.screen.height;
80     physicalWidth = win.screen.width * win.devicePixelRatio;
81     physicalHeight = win.screen.height * win.devicePixelRatio;
82   }
84   const info = {
85     /**
86      * Information from nsIXULAppInfo, regarding
87      * the application itself.
88      */
90     // The XUL application's UUID.
91     appid,
93     // Name of the app, "firefox", "thunderbird", etc., listed in APP_MAP
94     apptype,
96     // Mixed-case or empty string of vendor, like "Mozilla"
97     vendor: appInfo.vendor,
99     // Name of the application, like "Firefox", "Thunderbird".
100     name: appInfo.name,
102     // The application's version, for example "0.8.0+" or "3.7a1pre".
103     // Typically, the version of Firefox, for example.
104     // It is different than the version of Gecko or the XULRunner platform.
105     version,
107     // The application's build ID/date, for example "2004051604".
108     appbuildid: appInfo.appBuildID,
110     // The build ID/date of Gecko and the XULRunner platform.
111     platformbuildid: appInfo.platformBuildID,
112     geckobuildid: appInfo.platformBuildID,
114     // The version of Gecko or XULRunner platform, for example "1.8.1.19" or
115     // "1.9.3pre". In "Firefox 3.7 alpha 1" the application version is "3.7a1pre"
116     // while the platform version is "1.9.3pre"
117     platformversion: geckoVersion,
118     geckoversion: geckoVersion,
120     // Locale used in this build
121     locale: Services.locale.appLocaleAsBCP47,
123     /**
124      * Information regarding the operating system.
125      */
127     // Returns the endianness of the architecture: either "LE" or "BE"
128     endianness: endianness,
130     // Returns the hostname of the machine
131     hostname: hostname,
133     // Name of the OS type. Typically the same as `uname -s`. Possible values:
134     // https://developer.mozilla.org/en/OS_TARGET
135     os,
136     platform: os,
138     // hardware and version info from `deviceinfo.hardware`
139     // and `deviceinfo.os`.
140     hardware,
142     // Device name. This property is only available on Android.
143     // e.g. "Pixel 2"
144     deviceName: getDeviceName(),
146     // Type of process architecture running:
147     // "arm", "ia32", "x86", "x64"
148     // Alias to both `arch` and `processor` for node/deviceactor compat
149     arch: processor,
150     processor,
152     // Name of compiler used for build:
153     // `'msvc', 'n32', 'gcc2', 'gcc3', 'sunc', 'ibmc'...`
154     compiler,
156     // Location for the current profile
157     profile: getProfileLocation(),
159     // Update channel
160     channel: AppConstants.MOZ_UPDATE_CHANNEL,
162     dpi,
163     useragent,
164     width,
165     height,
166     physicalWidth,
167     physicalHeight,
168     brandName,
169   };
171   CACHED_INFO = info;
172   return info;
175 function getDeviceName() {
176   try {
177     // Will throw on other platforms than Firefox for Android.
178     return Services.sysinfo.getProperty("device");
179   } catch (e) {
180     return null;
181   }
184 function getProfileLocation() {
185   // In child processes, we cannot access the profile location.
186   try {
187     // For some reason this line must come first or in xpcshell tests
188     // nsXREDirProvider never gets initialised and so the profile service
189     // crashes on initialisation.
190     const profd = Services.dirsvc.get("ProfD", Ci.nsIFile);
191     const profservice = Cc["@mozilla.org/toolkit/profile-service;1"].getService(
192       Ci.nsIToolkitProfileService
193     );
194     if (profservice.currentProfile) {
195       return profservice.currentProfile.name;
196     }
198     return profd.leafName;
199   } catch (e) {
200     return "";
201   }
204 exports.getSystemInfo = getSystemInfo;