зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1628409 p2 - Make OS data available in filter context during FirstStartup r=rhelmer
Differential Revision: https://phabricator.services.mozilla.com/D70452 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
9a2ad7fe12
Коммит
8e6825fa97
|
@ -6,52 +6,16 @@
|
|||
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
"ShellService",
|
||||
"resource:///modules/ShellService.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
"AddonManager",
|
||||
"resource://gre/modules/AddonManager.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
"TelemetryArchive",
|
||||
"resource://gre/modules/TelemetryArchive.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
"TelemetryController",
|
||||
"resource://gre/modules/TelemetryController.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
"TelemetryEnvironment",
|
||||
"resource://gre/modules/TelemetryEnvironment.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
"UpdateUtils",
|
||||
"resource://gre/modules/UpdateUtils.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
"AppConstants",
|
||||
"resource://gre/modules/AppConstants.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
"FirstStartup",
|
||||
"resource://gre/modules/FirstStartup.jsm"
|
||||
);
|
||||
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
"AttributionCode",
|
||||
"resource:///modules/AttributionCode.jsm"
|
||||
);
|
||||
/* eslint-disable prettier/prettier */
|
||||
ChromeUtils.defineModuleGetter(this, "ShellService", "resource:///modules/ShellService.jsm");
|
||||
ChromeUtils.defineModuleGetter(this, "AddonManager", "resource://gre/modules/AddonManager.jsm");
|
||||
ChromeUtils.defineModuleGetter(this, "TelemetryArchive", "resource://gre/modules/TelemetryArchive.jsm");
|
||||
ChromeUtils.defineModuleGetter(this, "TelemetryController", "resource://gre/modules/TelemetryController.jsm");
|
||||
ChromeUtils.defineModuleGetter(this, "UpdateUtils", "resource://gre/modules/UpdateUtils.jsm");
|
||||
ChromeUtils.defineModuleGetter(this, "AppConstants", "resource://gre/modules/AppConstants.jsm");
|
||||
ChromeUtils.defineModuleGetter(this, "AttributionCode", "resource:///modules/AttributionCode.jsm");
|
||||
ChromeUtils.defineModuleGetter(this, "WindowsVersionInfo", "resource://gre/modules/components-utils/WindowsVersionInfo.jsm");
|
||||
/* eslint-enable prettier/prettier */
|
||||
|
||||
var EXPORTED_SYMBOLS = ["ClientEnvironmentBase"];
|
||||
|
||||
|
@ -139,15 +103,9 @@ class ClientEnvironmentBase {
|
|||
}
|
||||
|
||||
static get searchEngine() {
|
||||
// Telemetry Environment is not available in early first-startup.
|
||||
if (FirstStartup.state === FirstStartup.IN_PROGRESS) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return (async () => {
|
||||
await TelemetryEnvironment.onInitialized();
|
||||
return TelemetryEnvironment.currentEnvironment.settings
|
||||
.defaultSearchEngine;
|
||||
const defaultEngineInfo = await Services.search.getDefaultEngineInfo();
|
||||
return defaultEngineInfo.defaultSearchEngine;
|
||||
})();
|
||||
}
|
||||
|
||||
|
@ -212,48 +170,72 @@ class ClientEnvironmentBase {
|
|||
}
|
||||
|
||||
static get os() {
|
||||
// Telemetry Environment is not available in early first-startup.
|
||||
if (FirstStartup.state === FirstStartup.IN_PROGRESS) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function coerceToNumber(version) {
|
||||
const parts = version.split(".");
|
||||
return parseFloat(parts.slice(0, 2).join("."));
|
||||
}
|
||||
|
||||
return (async () => {
|
||||
await TelemetryEnvironment.onInitialized();
|
||||
function getOsVersion() {
|
||||
let version = null;
|
||||
try {
|
||||
version = Services.sysinfo.getProperty("version", null);
|
||||
} catch (_e) {
|
||||
// getProperty can throw if the version does not exist
|
||||
}
|
||||
if (version) {
|
||||
version = coerceToNumber(version);
|
||||
}
|
||||
return version;
|
||||
}
|
||||
|
||||
const { system } = TelemetryEnvironment.currentEnvironment;
|
||||
const rv = {
|
||||
isWindows: AppConstants.platform === "win",
|
||||
let osInfo = {
|
||||
isWindows: AppConstants.platform == "win",
|
||||
isMac: AppConstants.platform === "macosx",
|
||||
isLinux: AppConstants.platform === "linux",
|
||||
windowsVersion: null,
|
||||
windowsBuildNumber: null,
|
||||
macVersion: null,
|
||||
darwinVersion: null,
|
||||
};
|
||||
|
||||
if (rv.isWindows) {
|
||||
rv.windowsVersion = coerceToNumber(system.os.version);
|
||||
rv.windowsBuildNumber = system.os.windowsBuildNumber;
|
||||
} else if (rv.isMac) {
|
||||
rv.darwinVersion = coerceToNumber(system.os.version);
|
||||
get windowsVersion() {
|
||||
if (!osInfo.isWindows) {
|
||||
return null;
|
||||
}
|
||||
return getOsVersion();
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets the windows build number by querying the OS directly. The initial
|
||||
* version was copied from toolkit/components/telemetry/app/TelemetryEnvironment.jsm
|
||||
* @returns {number | null} The build number, or null on non-Windows platform or if there is an error.
|
||||
*/
|
||||
get windowsBuildNumber() {
|
||||
if (!osInfo.isWindows) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return WindowsVersionInfo.get({ throwOnError: false }).buildNumber;
|
||||
},
|
||||
|
||||
get macVersion() {
|
||||
const darwinVersion = osInfo.darwinVersion;
|
||||
// Versions of OSX with Darwin < 5 don't follow this pattern
|
||||
if (rv.darwinVersion >= 5) {
|
||||
if (darwinVersion >= 5) {
|
||||
// OSX 10.1 used Darwin 5, OSX 10.2 used Darwin 6, and so on.
|
||||
const intPart = Math.floor(rv.darwinVersion);
|
||||
rv.macVersion = 10 + 0.1 * (intPart - 4);
|
||||
const intPart = Math.floor(darwinVersion);
|
||||
return 10 + 0.1 * (intPart - 4);
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
||||
get darwinVersion() {
|
||||
if (!osInfo.isMac) {
|
||||
return null;
|
||||
}
|
||||
return getOsVersion();
|
||||
},
|
||||
|
||||
// Version information on linux is a lot harder and a lot less useful, so
|
||||
// don't do anything about it here.
|
||||
};
|
||||
|
||||
return rv;
|
||||
})();
|
||||
return osInfo;
|
||||
}
|
||||
|
||||
static get attribution() {
|
||||
|
|
|
@ -15,11 +15,8 @@ const { AppConstants } = ChromeUtils.import(
|
|||
|
||||
// OS Data
|
||||
add_task(async () => {
|
||||
const os = await ClientEnvironmentBase.os;
|
||||
ok(
|
||||
ClientEnvironmentBase.os !== undefined,
|
||||
"OS data should be available in the context"
|
||||
);
|
||||
const os = ClientEnvironmentBase.os;
|
||||
ok(os !== undefined, "OS data should be available in the context");
|
||||
|
||||
let osCount = 0;
|
||||
if (os.isWindows) {
|
||||
|
|
|
@ -580,7 +580,7 @@ XPCOMUtils.defineLazyGetter(UpdateUtils, "OSVersion", function() {
|
|||
if (ubr !== undefined) {
|
||||
osVersion += `.${ubr}`;
|
||||
} else {
|
||||
osVersion += ".undefined;";
|
||||
osVersion += ".unknown";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче