in src/amo/utils/compatibility.js [154:238]
export function isCompatibleWithUserAgent({
_log = log,
addon,
currentVersion,
maxVersion,
minVersion,
userAgentInfo,
}: IsCompatibleWithUserAgentParams): UserAgentCompatibilityType {
// If the userAgent is false there was likely a programming error.
invariant(userAgentInfo, 'userAgentInfo is required');
const { browser } = userAgentInfo;
// We need a Firefox browser compatible with add-ons (Firefox for iOS does
// not currently support add-ons).
if (isFirefoxForIOS(userAgentInfo)) {
return { compatible: false, reason: INCOMPATIBLE_FIREFOX_FOR_IOS };
}
if (!isFirefox({ userAgentInfo })) {
return { compatible: false, reason: INCOMPATIBLE_NOT_FIREFOX };
}
if (isFirefoxForAndroid(userAgentInfo)) {
// We need to check that the add-on is installable and compatible.
if (
!isAndroidInstallable({ addon }) ||
(currentVersion && !currentVersion.compatibility[CLIENT_APP_ANDROID])
) {
return { compatible: false, reason: INCOMPATIBLE_ANDROID_UNSUPPORTED };
}
}
// At this point we need a currentVersion and a file in order for an
// extension to be marked as compatible.
if (!currentVersion || !currentVersion.file) {
return {
compatible: false,
reason: INCOMPATIBLE_UNSUPPORTED_PLATFORM,
};
}
if (isFirefoxWithOldRootCerts({ userAgentInfo })) {
return { compatible: false, reason: INCOMPATIBLE_OLD_ROOT_CERT_VERSION };
}
// Do version checks, if this add-on has minimum or maximum version
// requirements.
// The addons-moz-compare API is quite strange; a result of
// `1` means the first argument is higher in version than the second.
//
// Being over the maxVersion, oddly, is not actually a reason to
// disable the install button or mark the add-on as incompatible
// with this version of Firefox. But we log the version mismatch
// here so it's not totally silent and a future developer isn't as
// confused by this as tofumatt was.
// See: https://github.com/mozilla/addons-frontend/issues/2074#issuecomment-286983423
if (maxVersion && mozCompare(browser.version, maxVersion) === 1) {
if (currentVersion.isStrictCompatibilityEnabled) {
return { compatible: false, reason: INCOMPATIBLE_OVER_MAX_VERSION };
}
_log.info(oneLine`maxVersion ${maxVersion} for add-on lower than
browser version ${browser.version}, but add-on still marked as
compatible because we largely ignore maxVersion. See:
https://github.com/mozilla/addons-frontend/issues/2074`);
}
// A result of `-1` means the first argument is a lower version than the
// second.
if (minVersion && mozCompare(browser.version, minVersion) === -1) {
if (minVersion === '*') {
_log.error(oneLine`minVersion of "*" was passed to
isCompatibleWithUserAgent(); bad add-on version data (browserVersion:
${browser.version})`);
}
// `minVersion` is always respected, regardless of
// `isStrictCompatibilityEnabled`'s value.
return { compatible: false, reason: INCOMPATIBLE_UNDER_MIN_VERSION };
}
// If we made it here we're compatible (yay!)
return { compatible: true, reason: null };
}