Bug 2036942 - Part 2: Add nsSystemInfo::IsWindows10BuildOrLater and use it for most version comparisons from JS. r=xpcom-reviewers,beth,Gijs
This again tries to get away from actually using the version number and GetVersionEx. It's a thin wrapper over mozilla::IsWindows10BuildOrLater, which itself calls VerifyVersionInfoW, which is also deprecated; however, it makes it harder to mess up the check, and that API is used internally by Microsoft's recommended version helper functions. Differential Revision: https://phabricator.services.mozilla.com/D314483
This commit is contained in:
committed by
dmcintosh@mozilla.com
parent
183298efc4
commit
d315f1e081
@@ -11,8 +11,6 @@ const { AppConstants } = ChromeUtils.importESModule(
|
||||
|
||||
const lazy = {};
|
||||
ChromeUtils.defineESModuleGetters(lazy, {
|
||||
WindowsVersionInfo:
|
||||
"resource://gre/modules/components-utils/WindowsVersionInfo.sys.mjs",
|
||||
ICON_CATALOG: "moz-src:///browser/components/shell/CustomIconManager.sys.mjs",
|
||||
resolvePreview:
|
||||
"moz-src:///browser/components/shell/CustomIconManager.sys.mjs",
|
||||
@@ -39,10 +37,7 @@ function isAutoTouchModeAvailable() {
|
||||
if (AppConstants.MOZ_WIDGET_GTK) {
|
||||
return true;
|
||||
}
|
||||
return (
|
||||
isWindows &&
|
||||
lazy.WindowsVersionInfo.get({ throwOnError: false }).buildNumber < 22000
|
||||
);
|
||||
return isWindows && !Services.sysinfo.isWindows10BuildOrLater(22000);
|
||||
}
|
||||
|
||||
// The custom browser-icon picker is gated behind a feature pref, is
|
||||
|
||||
@@ -129,10 +129,7 @@ function autoTouchModeAvailable() {
|
||||
if (AppConstants.platform != "win") {
|
||||
return false;
|
||||
}
|
||||
const { WindowsVersionInfo } = ChromeUtils.importESModule(
|
||||
"resource://gre/modules/components-utils/WindowsVersionInfo.sys.mjs"
|
||||
);
|
||||
return WindowsVersionInfo.get({ throwOnError: false }).buildNumber < 22000;
|
||||
return !Services.sysinfo.isWindows10BuildOrLater(22000);
|
||||
}
|
||||
|
||||
async function withWindowDensityPane(callback) {
|
||||
|
||||
@@ -7,11 +7,6 @@
|
||||
|
||||
const CC = Components.Constructor;
|
||||
|
||||
ChromeUtils.defineESModuleGetters(this, {
|
||||
WindowsVersionInfo:
|
||||
"resource://gre/modules/components-utils/WindowsVersionInfo.sys.mjs",
|
||||
});
|
||||
|
||||
let expectedResults;
|
||||
|
||||
const osVersion = Services.sysinfo.get("version");
|
||||
@@ -50,7 +45,7 @@ const WindowsOscpuPromise = (async () => {
|
||||
let WindowsOscpu = null;
|
||||
if (AppConstants.platform == "win") {
|
||||
let cpuArch = Services.sysinfo.get("arch");
|
||||
let isWin11 = WindowsVersionInfo.get().buildNumber >= 22000;
|
||||
let isWin11 = Services.sysinfo.isWindows10BuildOrLater(22000);
|
||||
let isWow64 = (await Services.sysinfo.processInfo).isWow64;
|
||||
WindowsOscpu =
|
||||
cpuArch == "x86-64" || isWow64 || (cpuArch == "aarch64" && isWin11)
|
||||
|
||||
@@ -25,8 +25,6 @@
|
||||
|
||||
ChromeUtils.defineESModuleGetters(this, {
|
||||
AppConstants: "resource://gre/modules/AppConstants.sys.mjs",
|
||||
WindowsVersionInfo:
|
||||
"resource://gre/modules/components-utils/WindowsVersionInfo.sys.mjs",
|
||||
});
|
||||
|
||||
const osVersion = Services.sysinfo.get("version");
|
||||
@@ -62,7 +60,7 @@ const WindowsOscpuPromise = (async () => {
|
||||
let WindowsOscpu = null;
|
||||
if (AppConstants.platform == "win") {
|
||||
let cpuArch = Services.sysinfo.get("arch");
|
||||
let isWin11 = WindowsVersionInfo.get().buildNumber >= 22000;
|
||||
let isWin11 = Services.sysinfo.isWindows10BuildOrLater(22000);
|
||||
let isWow64 = (await Services.sysinfo.processInfo).isWow64;
|
||||
WindowsOscpu =
|
||||
cpuArch == "x86-64" || isWow64 || (cpuArch == "aarch64" && isWin11)
|
||||
|
||||
@@ -14,8 +14,6 @@ ChromeUtils.defineESModuleGetters(lazy, {
|
||||
Subprocess: "resource://gre/modules/Subprocess.sys.mjs",
|
||||
WindowsSetDefaultRedirect:
|
||||
"moz-src:///browser/components/shell/WindowsSetDefaultRedirect.sys.mjs",
|
||||
WindowsVersionInfo:
|
||||
"resource://gre/modules/components-utils/WindowsVersionInfo.sys.mjs",
|
||||
});
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(
|
||||
@@ -429,10 +427,13 @@ let ShellServiceInternal = {
|
||||
Glean.browser.setDefaultError[setAsDefaultError ? "true" : "false"].add();
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns whether the current operating system is Windows 11.
|
||||
*
|
||||
* This is used so it can be mocked out in tests.
|
||||
*/
|
||||
_isWindows11() {
|
||||
return (
|
||||
lazy.WindowsVersionInfo.get({ throwOnError: false }).buildNumber >= 22000
|
||||
);
|
||||
return Services.sysinfo.isWindows10BuildOrLater(22000);
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,11 +8,6 @@ const SHEET = document.querySelector('style');
|
||||
|
||||
let lazy = {};
|
||||
|
||||
ChromeUtils.defineESModuleGetters(lazy, {
|
||||
WindowsVersionInfo:
|
||||
"resource://gre/modules/components-utils/WindowsVersionInfo.sys.mjs",
|
||||
});
|
||||
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
@@ -101,7 +96,7 @@ expectUnkown("(-moz-platform: )");
|
||||
await testMozPref('-moz-pref("foo.bar.int", 1)', "foo.bar.int", 1, 2);
|
||||
await testMozPref('-moz-pref("foo.bar.int")', "foo.bar.int", 1, 0);
|
||||
|
||||
let supportsMica = matchMedia('(-moz-platform: windows)').matches && lazy.WindowsVersionInfo.get().buildNumber >= 22621;
|
||||
let supportsMica = matchMedia('(-moz-platform: windows)').matches && Services.sysinfo.isWindows10BuildOrLater(22621);
|
||||
info(`Mica supported: ${supportsMica}`);
|
||||
for (let [query, pref] of [['(-moz-windows-mica)', 'widget.windows.mica'], ['(-moz-windows-mica-popups)', 'widget.windows.mica.popups']]) {
|
||||
let prefIsBool = pref == 'widget.windows.mica';
|
||||
|
||||
@@ -8,8 +8,6 @@ const lazy = {};
|
||||
|
||||
ChromeUtils.defineESModuleGetters(lazy, {
|
||||
WindowsRegistry: "resource://gre/modules/WindowsRegistry.sys.mjs",
|
||||
WindowsVersionInfo:
|
||||
"resource://gre/modules/components-utils/WindowsVersionInfo.sys.mjs",
|
||||
});
|
||||
|
||||
export let OsEnvironment = {
|
||||
@@ -24,17 +22,8 @@ export let OsEnvironment = {
|
||||
"AicEnabled"
|
||||
),
|
||||
windowsVersionHasAppSourcesFeature: () => {
|
||||
let windowsVersion = parseFloat(Services.sysinfo.getProperty("version"));
|
||||
if (isNaN(windowsVersion)) {
|
||||
throw new Error("Unable to parse Windows version");
|
||||
}
|
||||
if (windowsVersion < 10) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// The App Sources feature was added in Windows 10, build 15063.
|
||||
const { buildNumber } = lazy.WindowsVersionInfo.get();
|
||||
return buildNumber >= 15063;
|
||||
return Services.sysinfo.isWindows10BuildOrLater(15063);
|
||||
},
|
||||
},
|
||||
|
||||
|
||||
@@ -12,11 +12,6 @@ add_task(async () => {
|
||||
);
|
||||
|
||||
await SpecialPowers.spawn(tab.linkedBrowser, [], () => {
|
||||
ChromeUtils.defineESModuleGetters(this, {
|
||||
WindowsVersionInfo:
|
||||
"resource://gre/modules/components-utils/WindowsVersionInfo.sys.mjs",
|
||||
});
|
||||
|
||||
Services.scriptloader.loadSubScript(
|
||||
"chrome://mochikit/content/tests/SimpleTest/WindowSnapshot.js",
|
||||
this
|
||||
@@ -94,7 +89,7 @@ add_task(async () => {
|
||||
let stats = countPixels(canvas);
|
||||
let references;
|
||||
if (content.navigator.platform.startsWith("Win")) {
|
||||
if (WindowsVersionInfo.get().buildNumber >= 22000) {
|
||||
if (Services.sysinfo.isWindows10BuildOrLater(22000)) {
|
||||
// Windows 11
|
||||
references = WIN11_REFERENCES;
|
||||
} else {
|
||||
|
||||
@@ -2354,3 +2354,14 @@ nsSystemInfo::GetProcessInfo(JSContext* aCx, Promise** aResult) {
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSystemInfo::IsWindows10BuildOrLater(uint32_t aBuildNumber, bool* aResult) {
|
||||
#ifdef XP_WIN
|
||||
NS_ENSURE_ARG_POINTER(aResult);
|
||||
*aResult = mozilla::IsWindows10BuildOrLater(aBuildNumber);
|
||||
return NS_OK;
|
||||
#else
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -37,4 +37,13 @@ interface nsISystemInfo : nsISupports
|
||||
*/
|
||||
[implicit_jscontext]
|
||||
readonly attribute Promise processInfo;
|
||||
|
||||
/**
|
||||
* Checks whether the Windows build number is at least the requested value.
|
||||
*
|
||||
* @param aBuildNumber - The desired build number.
|
||||
* @returns Whether the current system has at least this build number.
|
||||
* @throws NS_ERROR_NOT_AVAILABLE on non-Windows systems.
|
||||
*/
|
||||
boolean isWindows10BuildOrLater(in uint32_t aBuildNumber);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user