Bug 1906087 - Port bug 1830144: startupData lost whenever theme.update is called. r=john.bieling
Differential Revision: https://phabricator.services.mozilla.com/D215628 --HG-- extra : amend_source : 44662e1273a628fe633b6aaf4e920841c1653faf
This commit is contained in:
Родитель
f9d382cf1f
Коммит
d8d8e58bd4
|
@ -32,8 +32,13 @@ class Theme {
|
||||||
/**
|
/**
|
||||||
* Creates a theme instance.
|
* Creates a theme instance.
|
||||||
*
|
*
|
||||||
* @param {string} extension - Extension that created the theme.
|
* @param {object} options
|
||||||
* @param {Integer} windowId - The windowId where the theme is applied.
|
* @param {string} options.extension - Extension that created the theme.
|
||||||
|
* @param {Integer} options.windowId - The windowId where the theme is applied.
|
||||||
|
* @param {object} options.details
|
||||||
|
* @param {object} options.darkDetails
|
||||||
|
* @param {object} options.experiment
|
||||||
|
* @param {object} options.startupData - startupData if this is a static theme.
|
||||||
*/
|
*/
|
||||||
constructor({
|
constructor({
|
||||||
extension,
|
extension,
|
||||||
|
@ -48,15 +53,30 @@ class Theme {
|
||||||
this.darkDetails = darkDetails;
|
this.darkDetails = darkDetails;
|
||||||
this.windowId = windowId;
|
this.windowId = windowId;
|
||||||
|
|
||||||
if (startupData && startupData.lwtData) {
|
if (startupData?.lwtData) {
|
||||||
Object.assign(this, startupData);
|
// Parsed theme from a previous load() already available in startupData
|
||||||
|
// of parsed theme. We assume that reparsing the theme will yield the same
|
||||||
|
// result, and therefore reuse the value of startupData. This is a minor
|
||||||
|
// optimization; the more important use of startupData is before startup,
|
||||||
|
// by Extension.sys.mjs for LightweightThemeManager.fallbackThemeData.
|
||||||
|
//
|
||||||
|
// Note: the assumption "yield the same result" is not obviously true: the
|
||||||
|
// startupData persists across application updates, so it is possible for
|
||||||
|
// a browser update to occur that interprets the static theme differently.
|
||||||
|
// In this case we would still be using the old interpretation instead of
|
||||||
|
// the new one, until the user disables and re-enables/installs the theme.
|
||||||
|
this.lwtData = startupData.lwtData;
|
||||||
|
this.lwtStyles = startupData.lwtStyles;
|
||||||
|
this.lwtDarkStyles = startupData.lwtDarkStyles;
|
||||||
|
this.experiment = startupData.experiment;
|
||||||
} else {
|
} else {
|
||||||
|
// lwtData will be populated by load().
|
||||||
|
this.lwtData = null;
|
||||||
// TODO: Update this part after bug 1550090.
|
// TODO: Update this part after bug 1550090.
|
||||||
this.lwtStyles = {};
|
this.lwtStyles = {};
|
||||||
this.lwtDarkStyles = null;
|
this.lwtDarkStyles = darkDetails ? {} : null;
|
||||||
if (darkDetails) {
|
|
||||||
this.lwtDarkStyles = {};
|
this.experiment = null;
|
||||||
}
|
|
||||||
|
|
||||||
if (experiment) {
|
if (experiment) {
|
||||||
if (extension.canUseThemeExperiment()) {
|
if (extension.canUseThemeExperiment()) {
|
||||||
|
@ -101,6 +121,7 @@ class Theme {
|
||||||
* This method will override any currently applied theme.
|
* This method will override any currently applied theme.
|
||||||
*/
|
*/
|
||||||
load() {
|
load() {
|
||||||
|
// this.lwtData is usually null, unless populated from startupData.
|
||||||
if (!this.lwtData) {
|
if (!this.lwtData) {
|
||||||
this.loadDetails(this.details, this.lwtStyles);
|
this.loadDetails(this.details, this.lwtStyles);
|
||||||
if (this.darkDetails) {
|
if (this.darkDetails) {
|
||||||
|
@ -116,6 +137,11 @@ class Theme {
|
||||||
this.lwtData.experiment = this.experiment;
|
this.lwtData.experiment = this.experiment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.extension.type === "theme") {
|
||||||
|
// Store the parsed theme in startupData, so it is available early at
|
||||||
|
// browser startup, to use as LightweightThemeManager.fallbackThemeData,
|
||||||
|
// which is assigned from Extension.sys.mjs to avoid having to wait for
|
||||||
|
// this ext-theme.js file to be loaded.
|
||||||
this.extension.startupData = {
|
this.extension.startupData = {
|
||||||
lwtData: this.lwtData,
|
lwtData: this.lwtData,
|
||||||
lwtStyles: this.lwtStyles,
|
lwtStyles: this.lwtStyles,
|
||||||
|
@ -124,6 +150,7 @@ class Theme {
|
||||||
};
|
};
|
||||||
this.extension.saveStartupData();
|
this.extension.saveStartupData();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (this.windowId) {
|
if (this.windowId) {
|
||||||
this.lwtData.window = windowTracker.getWindow(
|
this.lwtData.window = windowTracker.getWindow(
|
||||||
|
@ -450,6 +477,8 @@ this.theme = class extends ExtensionAPIPersistent {
|
||||||
const { extension } = this;
|
const { extension } = this;
|
||||||
const { manifest } = extension;
|
const { manifest } = extension;
|
||||||
|
|
||||||
|
// Note: only static themes are processed here; extensions with the "theme"
|
||||||
|
// permission do not enter this code path.
|
||||||
defaultTheme = new Theme({
|
defaultTheme = new Theme({
|
||||||
extension,
|
extension,
|
||||||
details: manifest.theme,
|
details: manifest.theme,
|
||||||
|
@ -457,6 +486,15 @@ this.theme = class extends ExtensionAPIPersistent {
|
||||||
experiment: manifest.theme_experiment,
|
experiment: manifest.theme_experiment,
|
||||||
startupData: extension.startupData,
|
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) {
|
onShutdown(isAppShutdown) {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче