From fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 03:14:29 +0200 Subject: Merging upstream version 125.0.1. Signed-off-by: Daniel Baumann --- .../ReportBrokenSiteParent.sys.mjs | 310 ++++++++++----------- 1 file changed, 151 insertions(+), 159 deletions(-) (limited to 'toolkit/components/reportbrokensite/ReportBrokenSiteParent.sys.mjs') diff --git a/toolkit/components/reportbrokensite/ReportBrokenSiteParent.sys.mjs b/toolkit/components/reportbrokensite/ReportBrokenSiteParent.sys.mjs index d6363a4ee1..c9b38b233f 100644 --- a/toolkit/components/reportbrokensite/ReportBrokenSiteParent.sys.mjs +++ b/toolkit/components/reportbrokensite/ReportBrokenSiteParent.sys.mjs @@ -3,118 +3,9 @@ * 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 { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs"; - -function getSysinfoProperty(propertyName, defaultValue) { - try { - return Services.sysinfo.getProperty(propertyName); - } catch (e) {} - return defaultValue; -} - -function getSecurityInfo() { - const keys = [ - ["registeredAntiVirus", "antivirus"], - ["registeredAntiSpyware", "antispyware"], - ["registeredFirewall", "firewall"], - ]; - - let result = {}; - - for (let [inKey, outKey] of keys) { - const str = getSysinfoProperty(inKey, null); - result[outKey] = !str ? null : str.split(";"); - } - - // Right now, security data is only available for Windows builds, and - // we might as well not return anything at all if no data is available. - if (!Object.values(result).filter(e => e).length) { - return undefined; - } - - return result; -} - -class DriverInfo { - constructor(gl, ext) { - try { - this.extensions = ext.getParameter(ext.EXTENSIONS); - } catch (e) {} - - try { - this.renderer = ext.getParameter(gl.RENDERER); - } catch (e) {} - - try { - this.vendor = ext.getParameter(gl.VENDOR); - } catch (e) {} - - try { - this.version = ext.getParameter(gl.VERSION); - } catch (e) {} - - try { - this.wsiInfo = ext.getParameter(ext.WSI_INFO); - } catch (e) {} - } - - equals(info2) { - return this.renderer == info2.renderer && this.version == info2.version; - } - - static getByType(driver) { - const doc = new DOMParser().parseFromString("", "text/html"); - const canvas = doc.createElement("canvas"); - canvas.width = 1; - canvas.height = 1; - let error; - canvas.addEventListener("webglcontextcreationerror", function (e) { - error = true; - }); - let gl = null; - try { - gl = canvas.getContext(driver); - } catch (e) { - error = true; - } - if (error || !gl?.getExtension) { - return undefined; - } - - let ext = null; - try { - ext = gl.getExtension("MOZ_debug"); - } catch (e) {} - if (!ext) { - return undefined; - } - - const data = new DriverInfo(gl, ext); - - try { - gl.getExtension("WEBGL_lose_context").loseContext(); - } catch (e) {} - - return data; - } - - static getAll() { - const drivers = []; - - function tryDriver(type) { - const driver = DriverInfo.getByType(type); - if (driver) { - drivers.push(driver); - } - } - - tryDriver("webgl"); - tryDriver("webgl2"); - tryDriver("webgpu"); +import { Troubleshoot } from "resource://gre/modules/Troubleshoot.sys.mjs"; - return drivers; - } -} +import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs"; export class ReportBrokenSiteParent extends JSWindowActorParent { #getAntitrackingBlockList() { @@ -145,10 +36,10 @@ export class ReportBrokenSiteParent extends JSWindowActorParent { }; } - #getBasicGraphicsInfo(gfxInfo) { + #parseGfxInfo(info) { const get = name => { try { - return gfxInfo[name]; + return info[name]; } catch (e) {} return undefined; }; @@ -183,63 +74,165 @@ export class ReportBrokenSiteParent extends JSWindowActorParent { direct2DEnabled: get("direct2DEnabled"), directWriteEnabled: get("directWriteEnabled"), directWriteVersion: get("directWriteVersion"), - hasTouchScreen: gfxInfo.getInfo().ApzTouchInput == 1, - cleartypeParameters: get("clearTypeParameters"), + hasTouchScreen: info.ApzTouchInput == 1, + clearTypeParameters: get("clearTypeParameters"), targetFrameRate: get("targetFrameRate"), devices, }); } - #getGraphicsInfo() { - const gfxInfo = Cc["@mozilla.org/gfx/info;1"].getService(Ci.nsIGfxInfo); + #parseCodecSupportInfo(codecSupportInfo) { + if (!codecSupportInfo) { + return undefined; + } - const data = this.#getBasicGraphicsInfo(gfxInfo); + const codecs = {}; + for (const item of codecSupportInfo.split("\n")) { + const [codec, ...types] = item.split(" "); + if (!codecs[codec]) { + codecs[codec] = { hardware: false, software: false }; + } + codecs[codec].software ||= types.includes("SW"); + codecs[codec].hardware ||= types.includes("HW"); + } + return codecs; + } - data.drivers = DriverInfo.getAll().map(({ renderer, vendor, version }) => { - return { renderer: `${vendor} -- ${renderer}`, version }; - }); + #parseFeatureLog(featureLog = {}) { + const { features } = featureLog; + if (!features) { + return undefined; + } - try { - const info = gfxInfo.CodecSupportInfo; - if (info) { - const codecs = {}; - for (const item of gfxInfo.CodecSupportInfo.split("\n")) { - const [codec, ...types] = item.split(" "); - if (!codecs[codec]) { - codecs[codec] = { software: false, hardware: false }; - } - if (types.includes("SW")) { - codecs[codec].software = true; - } - if (types.includes("HW")) { - codecs[codec].hardware = true; - } + const parsedFeatures = {}; + for (let { name, log, status } of features) { + for (const item of log.reverse()) { + if (!item.failureId || item.status != status) { + continue; } - data.codecSupport = codecs; + status = `${status} (${item.message || item.failureId})`; } - } catch (e) {} + parsedFeatures[name] = status; + } + return parsedFeatures; + } - try { - const { features } = gfxInfo.getFeatureLog(); - data.features = {}; - for (let { name, log, status } of features) { - for (const item of log.reverse()) { - if (!item.failureId || item.status != status) { - continue; - } - status = `${status} (${item.message || item.failureId})`; - } - data.features[name] = status; - } - } catch (e) {} + #getGraphicsInfo(troubleshoot) { + const { graphics, media } = troubleshoot; + const { featureLog } = graphics; + const data = this.#parseGfxInfo(graphics); + data.drivers = [ + { + renderer: graphics.webgl1Renderer, + version: graphics.webgl1Version, + }, + { + renderer: graphics.webgl2Renderer, + version: graphics.webgl2Version, + }, + ].filter(({ version }) => version && version != "-"); + + data.codecSupport = this.#parseCodecSupportInfo(media.codecSupportInfo); + data.features = this.#parseFeatureLog(featureLog); + const gfxInfo = Cc["@mozilla.org/gfx/info;1"].getService(Ci.nsIGfxInfo); + data.monitors = gfxInfo.getMonitors(); + + return data; + } + + #getAppInfo(troubleshootingInfo) { + const { application } = troubleshootingInfo; + return { + applicationName: application.name, + buildId: application.buildID, + defaultUserAgent: application.userAgent, + updateChannel: application.updateChannel, + version: application.version, + }; + } + + #getSysinfoProperty(propertyName, defaultValue) { try { - if (AppConstants.platform !== "android") { - data.monitors = gfxInfo.getMonitors(); - } + return Services.sysinfo.getProperty(propertyName); } catch (e) {} + return defaultValue; + } - return data; + #getPrefs() { + const prefs = {}; + for (const name of [ + "layers.acceleration.force-enabled", + "gfx.webrender.software", + "browser.opaqueResponseBlocking", + "extensions.InstallTrigger.enabled", + "privacy.resistFingerprinting", + "privacy.globalprivacycontrol.enabled", + ]) { + prefs[name] = Services.prefs.getBoolPref(name, undefined); + } + const cookieBehavior = "network.cookie.cookieBehavior"; + prefs[cookieBehavior] = Services.prefs.getIntPref(cookieBehavior, -1); + return prefs; + } + + async #getPlatformInfo(troubleshootingInfo) { + const { application } = troubleshootingInfo; + const { memorySizeBytes, fissionAutoStart } = application; + + let memoryMB = memorySizeBytes; + if (memoryMB) { + memoryMB = Math.round(memoryMB / 1024 / 1024); + } + + const info = { + fissionEnabled: fissionAutoStart, + memoryMB, + osArchitecture: this.#getSysinfoProperty("arch", null), + osName: this.#getSysinfoProperty("name", null), + osVersion: this.#getSysinfoProperty("version", null), + name: AppConstants.platform, + }; + if (info.os === "android") { + info.device = this.#getSysinfoProperty("device", null); + info.isTablet = this.#getSysinfoProperty("tablet", false); + } + if ( + info.osName == "Windows_NT" && + (await Services.sysinfo.processInfo).isWindowsSMode + ) { + info.osVersion += " S"; + } + return info; + } + + #getSecurityInfo(troubleshootingInfo) { + const result = {}; + for (const [k, v] of Object.entries(troubleshootingInfo.securitySoftware)) { + result[k.replace("registered", "").toLowerCase()] = v + ? v.split(";") + : null; + } + + // Right now, security data is only available for Windows builds, and + // we might as well not return anything at all if no data is available. + if (!Object.values(result).filter(e => e).length) { + return undefined; + } + + return result; + } + + async #getBrowserInfo() { + const troubleshootingInfo = await Troubleshoot.snapshot(); + return { + app: this.#getAppInfo(troubleshootingInfo), + graphics: this.#getGraphicsInfo(troubleshootingInfo), + locales: troubleshootingInfo.intl.localeService.available, + prefs: this.#getPrefs(), + platform: await this.#getPlatformInfo(troubleshootingInfo), + security: this.#getSecurityInfo(troubleshootingInfo), + }; } async #getScreenshot(browsingContext, format, quality) { @@ -268,7 +261,7 @@ export class ReportBrokenSiteParent extends JSWindowActorParent { async receiveMessage(msg) { switch (msg.name) { - case "GetWebcompatInfoOnlyAvailableInParentProcess": { + case "GetWebcompatInfoFromParentProcess": { const { format, quality } = msg.data; const screenshot = await this.#getScreenshot( msg.target.browsingContext, @@ -278,12 +271,11 @@ export class ReportBrokenSiteParent extends JSWindowActorParent { console.error("Report Broken Site: getting a screenshot failed", e); return Promise.resolve(undefined); }); + return { antitracking: this.#getAntitrackingInfo(msg.target.browsingContext), - graphics: this.#getGraphicsInfo(), - locales: Services.locale.availableLocales, + browser: await this.#getBrowserInfo(), screenshot, - security: getSecurityInfo(), }; } } -- cgit v1.2.3