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/. */
7 var EXPORTED_SYMBOLS = [
15 const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
16 const { AppConstants } = ChromeUtils.import(
17 "resource://gre/modules/AppConstants.jsm"
19 const { UpdateUtils } = ChromeUtils.import(
20 "resource://gre/modules/UpdateUtils.jsm"
24 const OPEN_H264_ID = "gmp-gmpopenh264";
25 const WIDEVINE_ID = "gmp-widevinecdm";
26 const GMP_PLUGIN_IDS = [OPEN_H264_ID, WIDEVINE_ID];
30 * Checks whether or not a given plugin is hidden. Hidden plugins are neither
31 * downloaded nor displayed in the addons manager.
33 * The plugin to check.
35 isPluginHidden(aPlugin) {
36 if (this._is32bitModeMacOS()) {
37 // GMPs are hidden on MacOS when running in 32 bit mode.
42 if (!this._isPluginSupported(aPlugin) || !this._isPluginVisible(aPlugin)) {
50 if (!GMPPrefs.getBool(GMPPrefs.KEY_EME_ENABLED, true)) {
58 * Checks whether or not a given plugin is supported by the current OS.
60 * The plugin to check.
62 _isPluginSupported(aPlugin) {
63 if (this._isPluginForceSupported(aPlugin)) {
66 if (aPlugin.id == WIDEVINE_ID) {
67 // The Widevine plugin is available for Windows versions Vista and later,
68 // Mac OSX, and Linux.
70 AppConstants.platform == "win" ||
71 AppConstants.platform == "macosx" ||
72 AppConstants.platform == "linux"
80 if (AppConstants.platform != "macosx") {
83 return Services.appinfo.XPCOMABI.split("-")[0] == "x86";
87 * Checks whether or not a given plugin is visible in the addons manager
88 * UI and the "enable DRM" notification box. This can be used to test
89 * plugins that aren't yet turned on in the mozconfig.
91 * The plugin to check.
93 _isPluginVisible(aPlugin) {
94 return GMPPrefs.getBool(GMPPrefs.KEY_PLUGIN_VISIBLE, false, aPlugin.id);
98 * Checks whether or not a given plugin is forced-supported. This is used
99 * in automated tests to override the checks that prevent GMPs running on an
100 * unsupported platform.
102 * The plugin to check.
104 _isPluginForceSupported(aPlugin) {
105 return GMPPrefs.getBool(
106 GMPPrefs.KEY_PLUGIN_FORCE_SUPPORTED,
112 _isWindowsOnARM64() {
113 return AppConstants.platform == "win" && UpdateUtils.ABI.match(/aarch64/);
116 _expectedABI(aPlugin) {
117 let defaultABI = UpdateUtils.ABI;
118 if (aPlugin.id == WIDEVINE_ID && this._isWindowsOnARM64()) {
119 // On Windows on aarch64, we need the x86 plugin,
120 // as there's no native aarch64 plugins yet.
121 defaultABI = defaultABI.replace(/aarch64/g, "x86");
128 * Manages preferences for GMP addons
131 KEY_EME_ENABLED: "media.eme.enabled",
132 KEY_PLUGIN_ENABLED: "media.{0}.enabled",
133 KEY_PLUGIN_LAST_UPDATE: "media.{0}.lastUpdate",
134 KEY_PLUGIN_VERSION: "media.{0}.version",
135 KEY_PLUGIN_AUTOUPDATE: "media.{0}.autoupdate",
136 KEY_PLUGIN_VISIBLE: "media.{0}.visible",
137 KEY_PLUGIN_ABI: "media.{0}.abi",
138 KEY_PLUGIN_FORCE_SUPPORTED: "media.{0}.forceSupported",
139 KEY_URL: "media.gmp-manager.url",
140 KEY_URL_OVERRIDE: "media.gmp-manager.url.override",
141 KEY_CERT_CHECKATTRS: "media.gmp-manager.cert.checkAttributes",
142 KEY_CERT_REQUIREBUILTIN: "media.gmp-manager.cert.requireBuiltIn",
143 KEY_UPDATE_LAST_CHECK: "media.gmp-manager.lastCheck",
144 KEY_SECONDS_BETWEEN_CHECKS: "media.gmp-manager.secondsBetweenChecks",
145 KEY_UPDATE_ENABLED: "media.gmp-manager.updateEnabled",
146 KEY_APP_DISTRIBUTION: "distribution.id",
147 KEY_APP_DISTRIBUTION_VERSION: "distribution.version",
148 KEY_BUILDID: "media.gmp-manager.buildID",
149 KEY_CERTS_BRANCH: "media.gmp-manager.certs.",
150 KEY_PROVIDER_ENABLED: "media.gmp-provider.enabled",
151 KEY_LOG_BASE: "media.gmp.log.",
152 KEY_LOGGING_LEVEL: "media.gmp.log.level",
153 KEY_LOGGING_DUMP: "media.gmp.log.dump",
156 * Obtains the specified string preference in relation to the specified plugin.
157 * @param aKey The preference key value to use.
158 * @param aDefaultValue The default value if no preference exists.
159 * @param aPlugin The plugin to scope the preference to.
160 * @return The obtained preference value, or the defaultValue if none exists.
162 getString(aKey, aDefaultValue, aPlugin) {
164 aKey === this.KEY_APP_DISTRIBUTION ||
165 aKey === this.KEY_APP_DISTRIBUTION_VERSION
167 return Services.prefs.getDefaultBranch(null).getCharPref(aKey, "default");
169 return Services.prefs.getStringPref(
170 this.getPrefKey(aKey, aPlugin),
176 * Obtains the specified int preference in relation to the specified plugin.
177 * @param aKey The preference key value to use.
178 * @param aDefaultValue The default value if no preference exists.
179 * @param aPlugin The plugin to scope the preference to.
180 * @return The obtained preference value, or the defaultValue if none exists.
182 getInt(aKey, aDefaultValue, aPlugin) {
183 return Services.prefs.getIntPref(
184 this.getPrefKey(aKey, aPlugin),
190 * Obtains the specified bool preference in relation to the specified plugin.
191 * @param aKey The preference key value to use.
192 * @param aDefaultValue The default value if no preference exists.
193 * @param aPlugin The plugin to scope the preference to.
194 * @return The obtained preference value, or the defaultValue if none exists.
196 getBool(aKey, aDefaultValue, aPlugin) {
197 return Services.prefs.getBoolPref(
198 this.getPrefKey(aKey, aPlugin),
204 * Sets the specified string preference in relation to the specified plugin.
205 * @param aKey The preference key value to use.
206 * @param aVal The value to set.
207 * @param aPlugin The plugin to scope the preference to.
209 setString(aKey, aVal, aPlugin) {
210 Services.prefs.setStringPref(this.getPrefKey(aKey, aPlugin), aVal);
214 * Sets the specified bool preference in relation to the specified plugin.
215 * @param aKey The preference key value to use.
216 * @param aVal The value to set.
217 * @param aPlugin The plugin to scope the preference to.
219 setBool(aKey, aVal, aPlugin) {
220 Services.prefs.setBoolPref(this.getPrefKey(aKey, aPlugin), aVal);
224 * Sets the specified int preference in relation to the specified plugin.
225 * @param aKey The preference key value to use.
226 * @param aVal The value to set.
227 * @param aPlugin The plugin to scope the preference to.
229 setInt(aKey, aVal, aPlugin) {
230 Services.prefs.setIntPref(this.getPrefKey(aKey, aPlugin), aVal);
234 * Checks whether or not the specified preference is set in relation to the
236 * @param aKey The preference key value to use.
237 * @param aPlugin The plugin to scope the preference to.
238 * @return true if the preference is set, false otherwise.
240 isSet(aKey, aPlugin) {
241 return Services.prefs.prefHasUserValue(this.getPrefKey(aKey, aPlugin));
245 * Resets the specified preference in relation to the specified plugin to its
247 * @param aKey The preference key value to use.
248 * @param aPlugin The plugin to scope the preference to.
250 reset(aKey, aPlugin) {
251 Services.prefs.clearUserPref(this.getPrefKey(aKey, aPlugin));
255 * Scopes the specified preference key to the specified plugin.
256 * @param aKey The preference key value to use.
257 * @param aPlugin The plugin to scope the preference to.
258 * @return A preference key scoped to the specified plugin.
260 getPrefKey(aKey, aPlugin) {
261 return aKey.replace("{0}", aPlugin || "");