1 /* -*- js-indent-level: 2; indent-tabs-mode: nil -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs";
10 ChromeUtils.defineESModuleGetters(lazy, {
11 WindowsRegistry: "resource://gre/modules/WindowsRegistry.sys.mjs",
13 "resource://gre/modules/components-utils/WindowsVersionInfo.sys.mjs",
16 export let OsEnvironment = {
18 * This is a policy object used to override behavior for testing.
21 getAllowedAppSources: () =>
22 lazy.WindowsRegistry.readRegKey(
23 Ci.nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE,
24 "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer",
27 windowsVersionHasAppSourcesFeature: () => {
28 let windowsVersion = parseFloat(Services.sysinfo.getProperty("version"));
29 if (isNaN(windowsVersion)) {
30 throw new Error("Unable to parse Windows version");
32 if (windowsVersion < 10) {
36 // The App Sources feature was added in Windows 10, build 15063.
37 const { buildNumber } = lazy.WindowsVersionInfo.get();
38 return buildNumber >= 15063;
42 reportAllowedAppSources() {
43 if (AppConstants.platform != "win") {
44 // This is currently a windows-only feature.
48 const appSourceScalar = "os.environment.allowed_app_sources";
50 let haveAppSourcesFeature;
52 haveAppSourcesFeature =
53 OsEnvironment.Policy.windowsVersionHasAppSourcesFeature();
56 Services.telemetry.scalarSet(appSourceScalar, "Error");
59 if (!haveAppSourcesFeature) {
60 Services.telemetry.scalarSet(appSourceScalar, "NoSuchFeature");
64 let allowedAppSources;
66 allowedAppSources = OsEnvironment.Policy.getAllowedAppSources();
69 Services.telemetry.scalarSet(appSourceScalar, "Error");
72 if (allowedAppSources === undefined) {
73 // A return value of undefined means that the registry value didn't
74 // exist. Windows treats a missing registry entry the same as if the
75 // value is "Anywhere". Make sure to differentiate a missing registry
76 // entry from one containing an empty string, since it is unclear how
77 // Windows would treat such a setting, but it may not be the same as
78 // if the value is missing.
79 allowedAppSources = "Anywhere";
82 const expectedValues = [
88 if (!expectedValues.includes(allowedAppSources)) {
89 allowedAppSources = "Error";
92 Services.telemetry.scalarSet(appSourceScalar, allowedAppSources);