Bug 1964281 - Drop obsolete _processedColors when reading addonStartup.json.lz4, r=robwu

Differential Revision: https://phabricator.services.mozilla.com/D247706
This commit is contained in:
Andrea Marchesini
2025-05-07 12:27:14 +00:00
committed by amarchesini@mozilla.com
parent f62a5351bf
commit 2a18809de5
4 changed files with 112 additions and 9 deletions

View File

@@ -474,15 +474,6 @@ this.theme = class extends ExtensionAPIPersistent {
experiment: manifest.theme_experiment,
startupData: extension.startupData,
});
if (extension.startupData.lwtData?._processedColors) {
// We should ideally not be modifying startupData, but we did so before,
// before bug 1830136 was fixed. startupData persists across browser
// updates and is only erased when the theme is updated or uninstalled.
// To prevent this stale _processedColors from bloating the database
// unnecessarily, we delete it here.
delete extension.startupData.lwtData._processedColors;
extension.saveStartupData();
}
}
onShutdown(isAppShutdown) {

View File

@@ -1445,6 +1445,22 @@ var XPIStates = {
logger.warn("Error parsing extensions state: ${error}", { error: e });
}
// Let's remove invalid `_processedColors` properties in the theme add-ons.
for (let location of Object.values(state || {})) {
for (let data of Object.values(location.addons || {})) {
if (data.type === "theme" && data.startupData) {
// Some profiles have an outdated version of `startupData` containing
// `_processedColors` properties, which in certain cases prevent the
// data from being updated correctly. These properties are removed
// here. See bug 1830136.
delete data.startupData.lwtData?.darkTheme?._processedColors;
delete data.startupData.lwtData?.theme?._processedColors;
delete data.startupData.lwtDarkStyles?._processedColors;
delete data.startupData.lwtStyles?._processedColors;
}
}
}
// When upgrading from a build prior to bug 857456, convert startup
// metadata.
let done = false;

View File

@@ -0,0 +1,93 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const THEME_ID = "theme@tests.mozilla.org";
const { JSONFile } = ChromeUtils.importESModule(
"resource://gre/modules/JSONFile.sys.mjs"
);
Services.prefs.setIntPref(
"extensions.enabledScopes",
AddonManager.SCOPE_PROFILE | AddonManager.SCOPE_APPLICATION
);
add_task(async function test_cleanup_theme_processedColors() {
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
const profileDir = gProfD.clone();
profileDir.append("extensions");
await promiseWriteWebManifestForExtension(
{
author: "Some author",
manifest_version: 2,
name: "Web Extension Name",
version: "1.0",
theme: {},
browser_specific_settings: {
gecko: {
id: THEME_ID,
},
},
},
profileDir
);
await promiseStartupManager();
const addon = await AddonManager.getAddonByID(THEME_ID);
Assert.ok(!!addon, "Theme addon should exist");
await AddonTestUtils.promiseShutdownManager();
const data = aomStartup.readStartupData();
const themeEntry = data["app-profile"].addons[THEME_ID];
themeEntry.startupData = {
lwtData: {
theme: {
_processedColors: 42,
foo: "bar",
},
},
lwtStyles: {
_processedColors: 42,
foo: "bar",
},
};
const jsonFile = new JSONFile({
path: PathUtils.join(gProfD.path, "addonStartup.json.lz4"),
compression: "lz4",
});
jsonFile.data = data;
await jsonFile._save();
await AddonTestUtils.promiseStartupManager();
await AddonTestUtils.loadAddonsList(true);
const startupData = aomStartup.readStartupData();
const themeFromFile = startupData["app-profile"].addons[THEME_ID];
Assert.ok(themeFromFile.startupData, "We have startupData");
Assert.equal(
themeFromFile.startupData.lwtData.theme.foo,
"bar",
"The sentinel value is found"
);
Assert.ok(
!("_processedColors" in themeFromFile.startupData.lwtData.theme),
"No _processedColor property"
);
Assert.equal(
themeFromFile.startupData.lwtStyles.foo,
"bar",
"The sentinel value is found"
);
Assert.ok(
!("_processedColors" in themeFromFile.startupData.lwtStyles),
"No _processedColor property"
);
});

View File

@@ -76,6 +76,9 @@ skip-if = ["os == 'android'"] # Built-in Static Theme add-ons are not supported
["test_childprocess.js"]
head = ""
["test_cleanup_theme_processedColors.js"]
skip-if = ["os == 'android'"] # Non-extension add-ons are not supported on Android, but test installs static theme.
["test_cookies.js"]
["test_corrupt.js"]