summaryrefslogtreecommitdiffstats
path: root/toolkit/modules/OsEnvironment.sys.mjs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /toolkit/modules/OsEnvironment.sys.mjs
parentInitial commit. (diff)
downloadfirefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz
firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/modules/OsEnvironment.sys.mjs')
-rw-r--r--toolkit/modules/OsEnvironment.sys.mjs98
1 files changed, 98 insertions, 0 deletions
diff --git a/toolkit/modules/OsEnvironment.sys.mjs b/toolkit/modules/OsEnvironment.sys.mjs
new file mode 100644
index 0000000000..6af5d9db0c
--- /dev/null
+++ b/toolkit/modules/OsEnvironment.sys.mjs
@@ -0,0 +1,98 @@
+/* -*- js-indent-level: 2; indent-tabs-mode: nil -*- */
+/* 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/. */
+
+import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
+
+import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs";
+
+const lazy = {};
+
+ChromeUtils.defineESModuleGetters(lazy, {
+ WindowsRegistry: "resource://gre/modules/WindowsRegistry.sys.mjs",
+});
+
+XPCOMUtils.defineLazyModuleGetters(lazy, {
+ WindowsVersionInfo:
+ "resource://gre/modules/components-utils/WindowsVersionInfo.jsm",
+});
+
+export let OsEnvironment = {
+ /**
+ * This is a policy object used to override behavior for testing.
+ */
+ Policy: {
+ getAllowedAppSources: () =>
+ lazy.WindowsRegistry.readRegKey(
+ Ci.nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE,
+ "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer",
+ "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;
+ },
+ },
+
+ reportAllowedAppSources() {
+ if (AppConstants.platform != "win") {
+ // This is currently a windows-only feature.
+ return;
+ }
+
+ const appSourceScalar = "os.environment.allowed_app_sources";
+
+ let haveAppSourcesFeature;
+ try {
+ haveAppSourcesFeature = OsEnvironment.Policy.windowsVersionHasAppSourcesFeature();
+ } catch (ex) {
+ Cu.reportError(ex);
+ Services.telemetry.scalarSet(appSourceScalar, "Error");
+ return;
+ }
+ if (!haveAppSourcesFeature) {
+ Services.telemetry.scalarSet(appSourceScalar, "NoSuchFeature");
+ return;
+ }
+
+ let allowedAppSources;
+ try {
+ allowedAppSources = OsEnvironment.Policy.getAllowedAppSources();
+ } catch (ex) {
+ Cu.reportError(ex);
+ Services.telemetry.scalarSet(appSourceScalar, "Error");
+ return;
+ }
+ if (allowedAppSources === undefined) {
+ // A return value of undefined means that the registry value didn't
+ // exist. Windows treats a missing registry entry the same as if the
+ // value is "Anywhere". Make sure to differentiate a missing registry
+ // entry from one containing an empty string, since it is unclear how
+ // Windows would treat such a setting, but it may not be the same as
+ // if the value is missing.
+ allowedAppSources = "Anywhere";
+ }
+
+ const expectedValues = [
+ "Anywhere",
+ "Recommendations",
+ "PreferStore",
+ "StoreOnly",
+ ];
+ if (!expectedValues.includes(allowedAppSources)) {
+ allowedAppSources = "Error";
+ }
+
+ Services.telemetry.scalarSet(appSourceScalar, allowedAppSources);
+ },
+};