tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

AppInfo.sys.mjs (2139B)


      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 file,
      3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs";
      6 
      7 const ID_FIREFOX = "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}";
      8 const ID_THUNDERBIRD = "{3550f703-e582-4d05-9a08-453d09bdfdc6}";
      9 
     10 /**
     11 * Extends Services.appinfo with further properties that are
     12 * used by different protocols as handled by the Remote Agent.
     13 *
     14 * @typedef {object} AppInfo
     15 * @property {boolean} isAndroid - Whether the application runs on Android.
     16 * @property {boolean} isLinux - Whether the application runs on Linux.
     17 * @property {boolean} isMac - Whether the application runs on Mac OS.
     18 * @property {boolean} isWindows - Whether the application runs on Windows.
     19 * @property {boolean} isFirefox - Whether the application is Firefox.
     20 * @property {boolean} isThunderbird - Whether the application is Thunderbird.
     21 *
     22 * @since 88
     23 */
     24 export const AppInfo = new Proxy(
     25  {},
     26  {
     27    get(target, prop) {
     28      if (target.hasOwnProperty(prop)) {
     29        return target[prop];
     30      }
     31 
     32      return Services.appinfo[prop];
     33    },
     34  }
     35 );
     36 
     37 // Platform support
     38 
     39 ChromeUtils.defineLazyGetter(AppInfo, "isAndroid", () => {
     40  return Services.appinfo.OS === "Android";
     41 });
     42 
     43 ChromeUtils.defineLazyGetter(AppInfo, "isLinux", () => {
     44  return Services.appinfo.OS === "Linux";
     45 });
     46 
     47 ChromeUtils.defineLazyGetter(AppInfo, "isMac", () => {
     48  return Services.appinfo.OS === "Darwin";
     49 });
     50 
     51 ChromeUtils.defineLazyGetter(AppInfo, "isWindows", () => {
     52  return Services.appinfo.OS === "WINNT";
     53 });
     54 
     55 // Application type
     56 
     57 ChromeUtils.defineLazyGetter(AppInfo, "isFirefox", () => {
     58  return Services.appinfo.ID == ID_FIREFOX;
     59 });
     60 
     61 ChromeUtils.defineLazyGetter(AppInfo, "isThunderbird", () => {
     62  return Services.appinfo.ID == ID_THUNDERBIRD;
     63 });
     64 
     65 export function getTimeoutMultiplier() {
     66  if (
     67    AppConstants.DEBUG ||
     68    AppConstants.MOZ_CODE_COVERAGE ||
     69    AppConstants.ASAN
     70  ) {
     71    return 4;
     72  }
     73  if (AppConstants.TSAN) {
     74    return 8;
     75  }
     76 
     77  return 1;
     78 }