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 5"use strict"; 6 7var EXPORTED_SYMBOLS = ["AddonSettings"]; 8 9const { XPCOMUtils } = ChromeUtils.import( 10 "resource://gre/modules/XPCOMUtils.jsm" 11); 12const { AppConstants } = ChromeUtils.import( 13 "resource://gre/modules/AppConstants.jsm" 14); 15const { AddonManager } = ChromeUtils.import( 16 "resource://gre/modules/AddonManager.jsm" 17); 18 19const PREF_SIGNATURES_REQUIRED = "xpinstall.signatures.required"; 20const PREF_LANGPACK_SIGNATURES = "extensions.langpacks.signatures.required"; 21const PREF_ALLOW_EXPERIMENTS = "extensions.experiments.enabled"; 22const PREF_EM_SIDELOAD_SCOPES = "extensions.sideloadScopes"; 23const PREF_IS_EMBEDDED = "extensions.isembedded"; 24const PREF_UPDATE_REQUIREBUILTINCERTS = "extensions.update.requireBuiltInCerts"; 25const PREF_INSTALL_REQUIREBUILTINCERTS = 26 "extensions.install.requireBuiltInCerts"; 27 28var AddonSettings = {}; 29 30// Make a non-changable property that can't be manipulated from other 31// code in the app. 32function makeConstant(name, value) { 33 Object.defineProperty(AddonSettings, name, { 34 configurable: false, 35 enumerable: false, 36 writable: false, 37 value, 38 }); 39} 40 41if (AppConstants.MOZ_REQUIRE_SIGNING && !Cu.isInAutomation) { 42 makeConstant("REQUIRE_SIGNING", true); 43 makeConstant("LANGPACKS_REQUIRE_SIGNING", true); 44} else { 45 XPCOMUtils.defineLazyPreferenceGetter( 46 AddonSettings, 47 "REQUIRE_SIGNING", 48 PREF_SIGNATURES_REQUIRED, 49 false 50 ); 51 XPCOMUtils.defineLazyPreferenceGetter( 52 AddonSettings, 53 "LANGPACKS_REQUIRE_SIGNING", 54 PREF_LANGPACK_SIGNATURES, 55 false 56 ); 57} 58 59/** 60 * Require the use of certs shipped with Firefox for 61 * addon install and update, if the distribution does 62 * not require addon signing and is not ESR. 63 */ 64XPCOMUtils.defineLazyPreferenceGetter( 65 AddonSettings, 66 "INSTALL_REQUIREBUILTINCERTS", 67 PREF_INSTALL_REQUIREBUILTINCERTS, 68 !AppConstants.MOZ_REQUIRE_SIGNING && 69 !AppConstants.MOZ_APP_VERSION_DISPLAY.endsWith("esr") 70); 71 72XPCOMUtils.defineLazyPreferenceGetter( 73 AddonSettings, 74 "UPDATE_REQUIREBUILTINCERTS", 75 PREF_UPDATE_REQUIREBUILTINCERTS, 76 !AppConstants.MOZ_REQUIRE_SIGNING && 77 !AppConstants.MOZ_APP_VERSION_DISPLAY.endsWith("esr") 78); 79 80// Whether or not we're running in GeckoView embedded in an Android app 81if (Cu.isInAutomation) { 82 XPCOMUtils.defineLazyPreferenceGetter( 83 AddonSettings, 84 "IS_EMBEDDED", 85 PREF_IS_EMBEDDED, 86 false 87 ); 88} else { 89 makeConstant("IS_EMBEDDED", AppConstants.platform === "android"); 90} 91 92/** 93 * AddonSettings.EXPERIMENTS_ENABLED 94 * 95 * Experimental APIs are always available to privileged signed addons. 96 * This constant makes an optional preference available to enable experimental 97 * APIs for developement purposes. 98 * 99 * Two features are toggled with this preference: 100 * 101 * 1. The ability to load an extension that contains an experimental 102 * API but is not privileged. 103 * 2. The ability to load an unsigned extension that gains privilege 104 * if it is temporarily loaded (e.g. via about:debugging). 105 * 106 * MOZ_REQUIRE_SIGNING is set to zero in unbranded builds, we also 107 * ensure nightly, dev-ed and our test infrastructure have access to 108 * the preference. 109 * 110 * Official releases ignore this preference. 111 */ 112if ( 113 !AppConstants.MOZ_REQUIRE_SIGNING || 114 AppConstants.NIGHTLY_BUILD || 115 AppConstants.MOZ_DEV_EDITION || 116 Cu.isInAutomation 117) { 118 XPCOMUtils.defineLazyPreferenceGetter( 119 AddonSettings, 120 "EXPERIMENTS_ENABLED", 121 PREF_ALLOW_EXPERIMENTS, 122 true 123 ); 124} else { 125 makeConstant("EXPERIMENTS_ENABLED", false); 126} 127 128if (AppConstants.MOZ_DEV_EDITION) { 129 makeConstant("DEFAULT_THEME_ID", "firefox-compact-dark@mozilla.org"); 130} else { 131 makeConstant("DEFAULT_THEME_ID", "default-theme@mozilla.org"); 132} 133 134// SCOPES_SIDELOAD is a bitflag for what scopes we will load new extensions from when we scan the directories. 135// If a build allows sideloading, or we're in automation, we'll also allow use of the preference. 136if (AppConstants.MOZ_ALLOW_ADDON_SIDELOAD || Cu.isInAutomation) { 137 XPCOMUtils.defineLazyPreferenceGetter( 138 AddonSettings, 139 "SCOPES_SIDELOAD", 140 PREF_EM_SIDELOAD_SCOPES, 141 AppConstants.MOZ_ALLOW_ADDON_SIDELOAD 142 ? AddonManager.SCOPE_ALL 143 : AddonManager.SCOPE_PROFILE 144 ); 145} else { 146 makeConstant("SCOPES_SIDELOAD", AddonManager.SCOPE_PROFILE); 147} 148