system.js (6215B)
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"; 5 6 loader.lazyRequireGetter( 7 this, 8 "DevToolsServer", 9 "resource://devtools/server/devtools-server.js", 10 true 11 ); 12 loader.lazyRequireGetter(this, "flags", "resource://devtools/shared/flags.js"); 13 const lazy = {}; 14 ChromeUtils.defineESModuleGetters( 15 lazy, 16 { 17 AppConstants: "resource://gre/modules/AppConstants.sys.mjs", 18 }, 19 { global: "contextual" } 20 ); 21 loader.lazyGetter(this, "hostname", () => { 22 try { 23 // On some platforms (Linux according to try), this service does not exist and fails. 24 return Services.dns.myHostName; 25 } catch (e) { 26 return ""; 27 } 28 }); 29 loader.lazyGetter(this, "endianness", () => { 30 if (new Uint32Array(new Uint8Array([1, 2, 3, 4]).buffer)[0] === 0x04030201) { 31 return "LE"; 32 } 33 return "BE"; 34 }); 35 36 const APP_MAP = { 37 "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}": "firefox", 38 "{3550f703-e582-4d05-9a08-453d09bdfdc6}": "thunderbird", 39 "{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}": "seamonkey", 40 "{718e30fb-e89b-41dd-9da7-e25a45638b28}": "sunbird", 41 "{aa3c5121-dab2-40e2-81ca-7ea25febc110}": "mobile/android", 42 }; 43 44 var CACHED_INFO = null; 45 46 function getSystemInfo() { 47 if (CACHED_INFO) { 48 return CACHED_INFO; 49 } 50 51 const appInfo = Services.appinfo; 52 const win = Services.wm.getMostRecentWindow(DevToolsServer.chromeWindowType); 53 const [processor, compiler] = appInfo.XPCOMABI.split("-"); 54 let dpi, useragent, width, height, physicalWidth, physicalHeight, brandName; 55 const appid = appInfo.ID; 56 const apptype = APP_MAP[appid]; 57 const geckoVersion = appInfo.platformVersion; 58 const hardware = "unknown"; 59 let version = "unknown"; 60 61 const os = appInfo.OS; 62 version = appInfo.version; 63 64 const bundle = Services.strings.createBundle( 65 "chrome://branding/locale/brand.properties" 66 ); 67 if (bundle) { 68 brandName = bundle.GetStringFromName("brandFullName"); 69 } else { 70 brandName = null; 71 } 72 73 if (win) { 74 const utils = win.windowUtils; 75 dpi = utils.displayDPI; 76 useragent = win.navigator.userAgent; 77 width = win.screen.width; 78 height = win.screen.height; 79 physicalWidth = win.screen.width * win.devicePixelRatio; 80 physicalHeight = win.screen.height * win.devicePixelRatio; 81 } 82 83 const info = { 84 /** 85 * Information from nsIXULAppInfo, regarding 86 * the application itself. 87 */ 88 89 // The XUL application's UUID. 90 appid, 91 92 // Name of the app, "firefox", "thunderbird", etc., listed in APP_MAP 93 apptype, 94 95 // Mixed-case or empty string of vendor, like "Mozilla" 96 vendor: appInfo.vendor, 97 98 // Name of the application, like "Firefox", "Thunderbird". 99 name: appInfo.name, 100 101 // The application's version, for example "0.8.0+" or "3.7a1pre". 102 // Typically, the version of Firefox, for example. 103 // It is different than the version of Gecko or the XULRunner platform. 104 version, 105 106 // The application's build ID/date, for example "2004051604". 107 appbuildid: appInfo.appBuildID, 108 109 // The build ID/date of Gecko and the XULRunner platform. 110 platformbuildid: appInfo.platformBuildID, 111 geckobuildid: appInfo.platformBuildID, 112 113 // The version of Gecko or XULRunner platform, for example "1.8.1.19" or 114 // "1.9.3pre". In "Firefox 3.7 alpha 1" the application version is "3.7a1pre" 115 // while the platform version is "1.9.3pre" 116 platformversion: geckoVersion, 117 geckoversion: geckoVersion, 118 119 // Locale used in this build 120 locale: Services.locale.appLocaleAsBCP47, 121 122 /** 123 * Information regarding the operating system. 124 */ 125 126 // Returns the endianness of the architecture: either "LE" or "BE" 127 endianness, 128 129 // Returns the hostname of the machine 130 hostname, 131 132 // Name of the OS type. Typically the same as `uname -s`. Possible values: 133 // https://developer.mozilla.org/en/OS_TARGET 134 os, 135 platform: os, 136 137 // hardware and version info from `deviceinfo.hardware` 138 // and `deviceinfo.os`. 139 hardware, 140 141 // Device name. This property is only available on Android. 142 // e.g. "Pixel 2" 143 deviceName: getDeviceName(), 144 145 // Type of process architecture running: 146 // "arm", "ia32", "x86", "x64" 147 // Alias to both `arch` and `processor` for node/deviceactor compat 148 arch: processor, 149 processor, 150 151 // Name of compiler used for build: 152 // `'msvc', 'n32', 'gcc2', 'gcc3', 'sunc', 'ibmc'...` 153 compiler, 154 155 // Location for the current profile 156 profile: getProfileLocation(), 157 158 // Update channel 159 channel: lazy.AppConstants.MOZ_UPDATE_CHANNEL, 160 161 // Timeout multiplier for tests. 162 timeoutMultiplier: getTimeoutMultiplier(), 163 164 dpi, 165 useragent, 166 width, 167 height, 168 physicalWidth, 169 physicalHeight, 170 brandName, 171 }; 172 173 CACHED_INFO = info; 174 return info; 175 } 176 177 function getDeviceName() { 178 try { 179 // Will throw on other platforms than Firefox for Android. 180 return Services.sysinfo.getProperty("device"); 181 } catch (e) { 182 return null; 183 } 184 } 185 186 function getProfileLocation() { 187 // In child processes, we cannot access the profile location. 188 try { 189 // For some reason this line must come first or in xpcshell tests 190 // nsXREDirProvider never gets initialised and so the profile service 191 // crashes on initialisation. 192 const profd = Services.dirsvc.get("ProfD", Ci.nsIFile); 193 const profservice = Cc["@mozilla.org/toolkit/profile-service;1"].getService( 194 Ci.nsIToolkitProfileService 195 ); 196 if (profservice.currentProfile) { 197 return profservice.currentProfile.name; 198 } 199 200 return profd.leafName; 201 } catch (e) { 202 return ""; 203 } 204 } 205 206 /** 207 * Retrieve a timeout multiplier based on the platform. Slow platforms should 208 * use a bigger multiplier. 209 */ 210 function getTimeoutMultiplier() { 211 // Slow platform checks are only relevant to avoid issues in mochitests. 212 if (!flags.testing) { 213 return 1; 214 } 215 216 if ( 217 lazy.AppConstants.DEBUG || 218 lazy.AppConstants.MOZ_CODE_COVERAGE || 219 lazy.AppConstants.ASAN 220 ) { 221 return 4; 222 } 223 if (lazy.AppConstants.TSAN) { 224 return 8; 225 } 226 227 return 1; 228 } 229 exports.getSystemInfo = getSystemInfo;