2015-03-20 05:59:38 +03:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2018-02-23 22:50:01 +03:00
|
|
|
var EXPORTED_SYMBOLS = [
|
|
|
|
"GMP_PLUGIN_IDS",
|
|
|
|
"GMPPrefs",
|
|
|
|
"GMPUtils",
|
|
|
|
"OPEN_H264_ID",
|
|
|
|
"WIDEVINE_ID",
|
|
|
|
];
|
2019-07-05 12:15:43 +03:00
|
|
|
|
2019-01-17 21:18:31 +03:00
|
|
|
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
|
|
|
const { AppConstants } = ChromeUtils.import(
|
|
|
|
"resource://gre/modules/AppConstants.jsm"
|
|
|
|
);
|
2019-02-15 00:46:23 +03:00
|
|
|
const { UpdateUtils } = ChromeUtils.import(
|
|
|
|
"resource://gre/modules/UpdateUtils.jsm"
|
|
|
|
);
|
2015-03-20 05:59:38 +03:00
|
|
|
|
|
|
|
// GMP IDs
|
|
|
|
const OPEN_H264_ID = "gmp-gmpopenh264";
|
2016-02-26 01:24:13 +03:00
|
|
|
const WIDEVINE_ID = "gmp-widevinecdm";
|
2017-01-14 11:37:59 +03:00
|
|
|
const GMP_PLUGIN_IDS = [OPEN_H264_ID, WIDEVINE_ID];
|
2015-03-20 05:59:38 +03:00
|
|
|
|
2018-02-23 22:50:01 +03:00
|
|
|
var GMPUtils = {
|
2015-03-20 05:59:38 +03:00
|
|
|
/**
|
|
|
|
* Checks whether or not a given plugin is hidden. Hidden plugins are neither
|
|
|
|
* downloaded nor displayed in the addons manager.
|
|
|
|
* @param aPlugin
|
|
|
|
* The plugin to check.
|
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
isPluginHidden(aPlugin) {
|
2016-08-03 06:19:00 +03:00
|
|
|
if (this._is32bitModeMacOS()) {
|
|
|
|
// GMPs are hidden on MacOS when running in 32 bit mode.
|
|
|
|
// See bug 1291537.
|
|
|
|
return true;
|
|
|
|
}
|
2015-09-01 08:31:48 +03:00
|
|
|
|
2016-05-31 01:59:44 +03:00
|
|
|
if (!this._isPluginSupported(aPlugin) || !this._isPluginVisible(aPlugin)) {
|
2015-09-01 08:31:48 +03:00
|
|
|
return true;
|
2015-03-20 05:59:38 +03:00
|
|
|
}
|
2015-09-01 08:31:48 +03:00
|
|
|
|
2019-02-15 03:25:38 +03:00
|
|
|
if (!aPlugin.isEME) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-07-05 16:06:29 +03:00
|
|
|
if (!GMPPrefs.getBool(GMPPrefs.KEY_EME_ENABLED, true)) {
|
2015-09-01 08:31:48 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-03-20 05:59:38 +03:00
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks whether or not a given plugin is supported by the current OS.
|
|
|
|
* @param aPlugin
|
|
|
|
* The plugin to check.
|
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
_isPluginSupported(aPlugin) {
|
2016-05-31 01:59:44 +03:00
|
|
|
if (this._isPluginForceSupported(aPlugin)) {
|
|
|
|
return true;
|
|
|
|
}
|
2017-01-14 11:37:59 +03:00
|
|
|
if (aPlugin.id == WIDEVINE_ID) {
|
2016-07-22 05:21:19 +03:00
|
|
|
// The Widevine plugin is available for Windows versions Vista and later,
|
|
|
|
// Mac OSX, and Linux.
|
2018-04-25 00:00:53 +03:00
|
|
|
return (
|
|
|
|
AppConstants.platform == "win" ||
|
2016-07-22 05:21:19 +03:00
|
|
|
AppConstants.platform == "macosx" ||
|
|
|
|
AppConstants.platform == "linux"
|
|
|
|
);
|
2015-03-20 05:59:38 +03:00
|
|
|
}
|
2015-09-01 08:31:48 +03:00
|
|
|
|
2015-03-20 05:59:38 +03:00
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
_is32bitModeMacOS() {
|
2016-08-03 06:19:00 +03:00
|
|
|
if (AppConstants.platform != "macosx") {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return Services.appinfo.XPCOMABI.split("-")[0] == "x86";
|
|
|
|
},
|
|
|
|
|
2015-03-20 05:59:38 +03:00
|
|
|
/**
|
2016-05-31 01:59:44 +03:00
|
|
|
* Checks whether or not a given plugin is visible in the addons manager
|
|
|
|
* UI and the "enable DRM" notification box. This can be used to test
|
|
|
|
* plugins that aren't yet turned on in the mozconfig.
|
|
|
|
* @param aPlugin
|
|
|
|
* The plugin to check.
|
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
_isPluginVisible(aPlugin) {
|
2017-07-05 16:06:29 +03:00
|
|
|
return GMPPrefs.getBool(GMPPrefs.KEY_PLUGIN_VISIBLE, false, aPlugin.id);
|
2016-05-31 01:59:44 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks whether or not a given plugin is forced-supported. This is used
|
|
|
|
* in automated tests to override the checks that prevent GMPs running on an
|
|
|
|
* unsupported platform.
|
2015-03-20 05:59:38 +03:00
|
|
|
* @param aPlugin
|
|
|
|
* The plugin to check.
|
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
_isPluginForceSupported(aPlugin) {
|
2017-07-05 16:06:29 +03:00
|
|
|
return GMPPrefs.getBool(
|
|
|
|
GMPPrefs.KEY_PLUGIN_FORCE_SUPPORTED,
|
|
|
|
false,
|
|
|
|
aPlugin.id
|
|
|
|
);
|
2015-03-20 05:59:38 +03:00
|
|
|
},
|
2019-02-15 00:46:23 +03:00
|
|
|
|
|
|
|
_isWindowsOnARM64() {
|
|
|
|
return AppConstants.platform == "win" && UpdateUtils.ABI.match(/aarch64/);
|
|
|
|
},
|
2019-02-12 05:56:08 +03:00
|
|
|
|
|
|
|
_expectedABI(aPlugin) {
|
|
|
|
let defaultABI = UpdateUtils.ABI;
|
|
|
|
if (aPlugin.id == WIDEVINE_ID && this._isWindowsOnARM64()) {
|
|
|
|
// On Windows on aarch64, we need the x86 plugin,
|
|
|
|
// as there's no native aarch64 plugins yet.
|
|
|
|
defaultABI = defaultABI.replace(/aarch64/g, "x86");
|
|
|
|
}
|
|
|
|
return defaultABI;
|
|
|
|
},
|
2015-03-20 05:59:38 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Manages preferences for GMP addons
|
|
|
|
*/
|
2018-02-23 22:50:01 +03:00
|
|
|
var GMPPrefs = {
|
2015-03-20 05:59:38 +03:00
|
|
|
KEY_EME_ENABLED: "media.eme.enabled",
|
|
|
|
KEY_PLUGIN_ENABLED: "media.{0}.enabled",
|
|
|
|
KEY_PLUGIN_LAST_UPDATE: "media.{0}.lastUpdate",
|
|
|
|
KEY_PLUGIN_VERSION: "media.{0}.version",
|
|
|
|
KEY_PLUGIN_AUTOUPDATE: "media.{0}.autoupdate",
|
2016-05-31 01:59:44 +03:00
|
|
|
KEY_PLUGIN_VISIBLE: "media.{0}.visible",
|
2015-09-17 04:28:48 +03:00
|
|
|
KEY_PLUGIN_ABI: "media.{0}.abi",
|
2016-05-31 01:59:44 +03:00
|
|
|
KEY_PLUGIN_FORCE_SUPPORTED: "media.{0}.forceSupported",
|
2015-03-20 05:59:38 +03:00
|
|
|
KEY_URL: "media.gmp-manager.url",
|
|
|
|
KEY_URL_OVERRIDE: "media.gmp-manager.url.override",
|
|
|
|
KEY_CERT_CHECKATTRS: "media.gmp-manager.cert.checkAttributes",
|
|
|
|
KEY_CERT_REQUIREBUILTIN: "media.gmp-manager.cert.requireBuiltIn",
|
|
|
|
KEY_UPDATE_LAST_CHECK: "media.gmp-manager.lastCheck",
|
|
|
|
KEY_SECONDS_BETWEEN_CHECKS: "media.gmp-manager.secondsBetweenChecks",
|
2016-09-27 13:57:41 +03:00
|
|
|
KEY_UPDATE_ENABLED: "media.gmp-manager.updateEnabled",
|
2015-03-20 05:59:38 +03:00
|
|
|
KEY_APP_DISTRIBUTION: "distribution.id",
|
|
|
|
KEY_APP_DISTRIBUTION_VERSION: "distribution.version",
|
|
|
|
KEY_BUILDID: "media.gmp-manager.buildID",
|
|
|
|
KEY_CERTS_BRANCH: "media.gmp-manager.certs.",
|
|
|
|
KEY_PROVIDER_ENABLED: "media.gmp-provider.enabled",
|
|
|
|
KEY_LOG_BASE: "media.gmp.log.",
|
2015-05-15 02:50:40 +03:00
|
|
|
KEY_LOGGING_LEVEL: "media.gmp.log.level",
|
|
|
|
KEY_LOGGING_DUMP: "media.gmp.log.dump",
|
2015-03-20 05:59:38 +03:00
|
|
|
|
|
|
|
/**
|
2017-07-05 16:06:29 +03:00
|
|
|
* Obtains the specified string preference in relation to the specified plugin.
|
2015-03-20 05:59:38 +03:00
|
|
|
* @param aKey The preference key value to use.
|
|
|
|
* @param aDefaultValue The default value if no preference exists.
|
|
|
|
* @param aPlugin The plugin to scope the preference to.
|
|
|
|
* @return The obtained preference value, or the defaultValue if none exists.
|
|
|
|
*/
|
2017-07-05 16:06:29 +03:00
|
|
|
getString(aKey, aDefaultValue, aPlugin) {
|
2015-03-20 05:59:38 +03:00
|
|
|
if (
|
|
|
|
aKey === this.KEY_APP_DISTRIBUTION ||
|
|
|
|
aKey === this.KEY_APP_DISTRIBUTION_VERSION
|
|
|
|
) {
|
2017-03-07 17:29:48 +03:00
|
|
|
return Services.prefs.getDefaultBranch(null).getCharPref(aKey, "default");
|
2015-03-20 05:59:38 +03:00
|
|
|
}
|
2017-07-05 16:06:29 +03:00
|
|
|
return Services.prefs.getStringPref(
|
|
|
|
this.getPrefKey(aKey, aPlugin),
|
|
|
|
aDefaultValue
|
|
|
|
);
|
2015-03-20 05:59:38 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2017-07-05 16:06:29 +03:00
|
|
|
* Obtains the specified int preference in relation to the specified plugin.
|
|
|
|
* @param aKey The preference key value to use.
|
|
|
|
* @param aDefaultValue The default value if no preference exists.
|
|
|
|
* @param aPlugin The plugin to scope the preference to.
|
|
|
|
* @return The obtained preference value, or the defaultValue if none exists.
|
|
|
|
*/
|
|
|
|
getInt(aKey, aDefaultValue, aPlugin) {
|
|
|
|
return Services.prefs.getIntPref(
|
|
|
|
this.getPrefKey(aKey, aPlugin),
|
|
|
|
aDefaultValue
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Obtains the specified bool preference in relation to the specified plugin.
|
|
|
|
* @param aKey The preference key value to use.
|
|
|
|
* @param aDefaultValue The default value if no preference exists.
|
|
|
|
* @param aPlugin The plugin to scope the preference to.
|
|
|
|
* @return The obtained preference value, or the defaultValue if none exists.
|
|
|
|
*/
|
|
|
|
getBool(aKey, aDefaultValue, aPlugin) {
|
|
|
|
return Services.prefs.getBoolPref(
|
|
|
|
this.getPrefKey(aKey, aPlugin),
|
|
|
|
aDefaultValue
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the specified string preference in relation to the specified plugin.
|
|
|
|
* @param aKey The preference key value to use.
|
|
|
|
* @param aVal The value to set.
|
|
|
|
* @param aPlugin The plugin to scope the preference to.
|
|
|
|
*/
|
|
|
|
setString(aKey, aVal, aPlugin) {
|
|
|
|
Services.prefs.setStringPref(this.getPrefKey(aKey, aPlugin), aVal);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the specified bool preference in relation to the specified plugin.
|
|
|
|
* @param aKey The preference key value to use.
|
|
|
|
* @param aVal The value to set.
|
|
|
|
* @param aPlugin The plugin to scope the preference to.
|
|
|
|
*/
|
|
|
|
setBool(aKey, aVal, aPlugin) {
|
|
|
|
Services.prefs.setBoolPref(this.getPrefKey(aKey, aPlugin), aVal);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the specified int preference in relation to the specified plugin.
|
2015-03-20 05:59:38 +03:00
|
|
|
* @param aKey The preference key value to use.
|
|
|
|
* @param aVal The value to set.
|
|
|
|
* @param aPlugin The plugin to scope the preference to.
|
|
|
|
*/
|
2017-07-05 16:06:29 +03:00
|
|
|
setInt(aKey, aVal, aPlugin) {
|
|
|
|
Services.prefs.setIntPref(this.getPrefKey(aKey, aPlugin), aVal);
|
2015-03-20 05:59:38 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks whether or not the specified preference is set in relation to the
|
|
|
|
* specified plugin.
|
|
|
|
* @param aKey The preference key value to use.
|
|
|
|
* @param aPlugin The plugin to scope the preference to.
|
|
|
|
* @return true if the preference is set, false otherwise.
|
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
isSet(aKey, aPlugin) {
|
2017-07-05 16:06:29 +03:00
|
|
|
return Services.prefs.prefHasUserValue(this.getPrefKey(aKey, aPlugin));
|
2015-03-20 05:59:38 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resets the specified preference in relation to the specified plugin to its
|
|
|
|
* default.
|
|
|
|
* @param aKey The preference key value to use.
|
|
|
|
* @param aPlugin The plugin to scope the preference to.
|
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
reset(aKey, aPlugin) {
|
2017-07-05 16:06:29 +03:00
|
|
|
Services.prefs.clearUserPref(this.getPrefKey(aKey, aPlugin));
|
2015-03-20 05:59:38 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Scopes the specified preference key to the specified plugin.
|
|
|
|
* @param aKey The preference key value to use.
|
|
|
|
* @param aPlugin The plugin to scope the preference to.
|
|
|
|
* @return A preference key scoped to the specified plugin.
|
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
getPrefKey(aKey, aPlugin) {
|
2015-03-20 05:59:38 +03:00
|
|
|
return aKey.replace("{0}", aPlugin || "");
|
|
|
|
},
|
2015-09-01 08:31:48 +03:00
|
|
|
};
|