Bug 1365706: Use a special set of startup data when running in safe mode. r?rhelmer
MozReview-Commit-ID: DcRnYu3rNot
--- a/toolkit/mozapps/extensions/internal/XPIProvider.jsm
+++ b/toolkit/mozapps/extensions/internal/XPIProvider.jsm
@@ -247,16 +247,18 @@ const DIR_TRASH =
const FILE_XPI_STATES = "addonStartup.json.lz4";
const FILE_DATABASE = "extensions.json";
const FILE_OLD_CACHE = "extensions.cache";
const FILE_RDF_MANIFEST = "install.rdf";
const FILE_WEB_MANIFEST = "manifest.json";
const FILE_XPI_ADDONS_LIST = "extensions.ini";
+const ADDON_ID_DEFAULT_THEME = "{972ce4c6-7e08-4474-a285-3208198ce6fd}";
+
const KEY_PROFILEDIR = "ProfD";
const KEY_ADDON_APP_DIR = "XREAddonAppDir";
const KEY_TEMPDIR = "TmpD";
const KEY_APP_DISTRIBUTION = "XREAppDist";
const KEY_APP_FEATURES = "XREAppFeat";
const KEY_APP_PROFILE = "app-profile";
const KEY_APP_SYSTEM_ADDONS = "app-system-addons";
@@ -4075,16 +4077,40 @@ this.XPIProvider = {
},
getDependentAddons(aAddon) {
return Array.from(XPIDatabase.getAddons())
.filter(addon => addon.dependencies.includes(aAddon.id));
},
/**
+ * Returns the add-on state data for the restartful extensions which
+ * should be available in safe mode. In particular, this means the
+ * default theme, and only the default theme.
+ *
+ * @returns {object}
+ */
+ getSafeModeExtensions() {
+ let loc = XPIStates.getLocation(KEY_APP_GLOBAL);
+ let state = loc.get(ADDON_ID_DEFAULT_THEME);
+
+ // Use the default state data for the default theme, but always mark
+ // it enabled, in case another theme is enabled in normal mode.
+ let addonData = state.toJSON();
+ addonData.enabled = true;
+
+ return {
+ [KEY_APP_GLOBAL]: {
+ path: loc.path,
+ addons: { [ADDON_ID_DEFAULT_THEME]: addonData },
+ },
+ };
+ },
+
+ /**
* Checks for any changes that have occurred since the last time the
* application was launched.
*
* @param aAppChanged
* A tri-state value. Undefined means the current profile was created
* for this session, true means the profile already existed but was
* last used with an application with a different version number,
* false means that the profile was last used by this version of the
@@ -4193,16 +4219,22 @@ this.XPIProvider = {
try {
if (oldCache.exists())
oldCache.remove(true);
} catch (e) {
logger.warn("Unable to remove old extension cache " + oldCache.path, e);
}
}
+ if (Services.appinfo.inSafeMode) {
+ aomStartup.initializeExtensions(this.getSafeModeExtensions());
+ logger.debug("Initialized safe mode add-ons");
+ return false;
+ }
+
// If the application crashed before completing any pending operations then
// we should perform them now.
if (extensionListChanged || hasPendingChanges) {
this._updateActiveAddons();
// Serialize and deserialize so we get the expected JSON data.
let state = JSON.parse(JSON.stringify(XPIStates));
aomStartup.initializeExtensions(state);