Bug 1525762: Part 2b - Migrate selected lightweight theme when installing built-in themes. r=aswan
authorKris Maglione <maglione.k@gmail.com>
Tue, 26 Mar 2019 12:57:30 -0700
changeset 466973 83612982ab33e156ec51052fe86781d7e86e50ad
parent 466972 b62c3bde4bc3f7cba452ad57f8d728b175c15a62
child 466974 5cbbb63ea73d877b4b609ccebf6d6420b27ad14c
push id35789
push userbtara@mozilla.com
push dateSun, 31 Mar 2019 09:00:52 +0000
treeherdermozilla-central@c06dfc552c64 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan
bugs1525762
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1525762: Part 2b - Migrate selected lightweight theme when installing built-in themes. r=aswan Differential Revision: https://phabricator.services.mozilla.com/D24961
browser/app/profile/firefox.js
browser/base/content/test/performance/browser_startup.js
toolkit/mozapps/extensions/internal/XPIInstall.jsm
--- a/browser/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -1206,18 +1206,16 @@ pref("services.sync.prefs.sync.browser.u
 pref("services.sync.prefs.sync.dom.disable_open_during_load", true);
 pref("services.sync.prefs.sync.dom.disable_window_flip", true);
 pref("services.sync.prefs.sync.dom.disable_window_move_resize", true);
 pref("services.sync.prefs.sync.dom.event.contextmenu.enabled", true);
 pref("services.sync.prefs.sync.extensions.personas.current", true);
 pref("services.sync.prefs.sync.extensions.update.enabled", true);
 pref("services.sync.prefs.sync.intl.accept_languages", true);
 pref("services.sync.prefs.sync.layout.spellcheckDefault", true);
-pref("services.sync.prefs.sync.lightweightThemes.selectedThemeID", true);
-pref("services.sync.prefs.sync.lightweightThemes.usedThemes", true);
 pref("services.sync.prefs.sync.media.autoplay.default", true);
 pref("services.sync.prefs.sync.media.eme.enabled", true);
 pref("services.sync.prefs.sync.network.cookie.cookieBehavior", true);
 pref("services.sync.prefs.sync.network.cookie.lifetimePolicy", true);
 pref("services.sync.prefs.sync.network.cookie.thirdparty.sessionOnly", true);
 pref("services.sync.prefs.sync.permissions.default.image", true);
 pref("services.sync.prefs.sync.pref.advanced.images.disable_button.view_image", true);
 pref("services.sync.prefs.sync.pref.advanced.javascript.disable_button.advanced", true);
@@ -1256,24 +1254,16 @@ pref("services.sync.prefs.sync.spellchec
 pref("services.sync.prefs.sync.xpinstall.whitelist.required", true);
 
 // A preference that controls whether we should show the icon for a remote tab.
 // This pref has no UI but exists because some people may be concerned that
 // fetching these icons to show remote tabs may leak information about that
 // user's tabs and bookmarks. Note this pref is also synced.
 pref("services.sync.syncedTabs.showRemoteIcons", true);
 
-// Developer edition preferences
-#ifdef MOZ_DEV_EDITION
-pref("lightweightThemes.selectedThemeID", "firefox-compact-dark@mozilla.org",
-     sticky);
-#else
-pref("lightweightThemes.selectedThemeID", "default-theme@mozilla.org", sticky);
-#endif
-
 // Whether the character encoding menu is under the main Firefox button. This
 // preference is a string so that localizers can alter it.
 pref("browser.menu.showCharacterEncoding", "chrome://browser/locale/browser.properties");
 
 // Allow using tab-modal prompts when possible.
 pref("prompts.tab_modal.enabled", true);
 
 // Activates preloading of the new tab url.
--- a/browser/base/content/test/performance/browser_startup.js
+++ b/browser/base/content/test/performance/browser_startup.js
@@ -111,22 +111,16 @@ const startupPhases = {
     modules: new Set([
       "resource://gre/modules/AsyncPrefs.jsm",
       "resource://gre/modules/LoginManagerContextMenu.jsm",
       "resource://pdf.js/PdfStreamConverter.jsm",
     ]),
   }},
 };
 
-if (Services.prefs.getBoolPref("browser.startup.blankWindow") &&
-    Services.prefs.getCharPref("lightweightThemes.selectedThemeID") ==
-      "default-theme@mozilla.org") {
-  startupPhases["before profile selection"].whitelist.components.add("XULStore.js");
-}
-
 if (!gBrowser.selectedBrowser.isRemoteBrowser) {
   // With e10s disabled, Places and BrowserWindowTracker.jsm (from a
   // SessionSaver.jsm timer) intermittently get loaded earlier. Likely
   // due to messages from the 'content' process arriving synchronously
   // instead of crossing a process boundary.
   info("merging the 'before handling user events' blacklist into the " +
        "'before first paint' one when e10s is disabled.");
   let from = startupPhases["before handling user events"].blacklist;
--- a/toolkit/mozapps/extensions/internal/XPIInstall.jsm
+++ b/toolkit/mozapps/extensions/internal/XPIInstall.jsm
@@ -77,16 +77,18 @@ XPCOMUtils.defineLazyServiceGetters(this
 const PREF_INSTALL_REQUIRESECUREORIGIN = "extensions.install.requireSecureOrigin";
 const PREF_PENDING_OPERATIONS         = "extensions.pendingOperations";
 const PREF_SYSTEM_ADDON_UPDATE_URL    = "extensions.systemAddon.update.url";
 const PREF_XPI_ENABLED                = "xpinstall.enabled";
 const PREF_XPI_DIRECT_WHITELISTED     = "xpinstall.whitelist.directRequest";
 const PREF_XPI_FILE_WHITELISTED       = "xpinstall.whitelist.fileRequest";
 const PREF_XPI_WHITELIST_REQUIRED     = "xpinstall.whitelist.required";
 
+const PREF_SELECTED_LWT               = "lightweightThemes.selectedThemeID";
+
 const TOOLKIT_ID                      = "toolkit@mozilla.org";
 
 const DEFAULT_THEME_ID = "default-theme@mozilla.org";
 
 /* globals BOOTSTRAP_REASONS, KEY_APP_SYSTEM_ADDONS, KEY_APP_SYSTEM_DEFAULTS, PREF_BRANCH_INSTALLED_ADDON, PREF_SYSTEM_ADDON_SET, TEMPORARY_ADDON_SUFFIX, XPI_PERMISSION, XPIStates, getURIForResourceInFile, iterDirectory */
 const XPI_INTERNAL_SYMBOLS = [
   "BOOTSTRAP_REASONS",
   "KEY_APP_SYSTEM_ADDONS",
@@ -174,16 +176,21 @@ var gIDTest = /^(\{[0-9a-f]{8}-[0-9a-f]{
 
 const {Log} = ChromeUtils.import("resource://gre/modules/Log.jsm");
 const LOGGER_ID = "addons.xpi";
 
 // Create a new logger for use by all objects in this Addons XPI Provider module
 // (Requires AddonManager.jsm)
 var logger = Log.repository.getLogger(LOGGER_ID);
 
+// Stores the ID of the lightweight theme which was selected during the
+// last session, if any. When installing a new built-in theme with this
+// ID, it will be automatically enabled.
+let lastLightweightTheme = null;
+
 function getJarURI(file, path = "") {
   if (file instanceof Ci.nsIFile) {
     file = Services.io.newFileURI(file);
   }
   if (file instanceof Ci.nsIURI) {
     file = file.spec;
   }
   return Services.io.newURI(`jar:${file}!/${path}`);
@@ -3641,16 +3648,21 @@ var XPIInstall = {
    *  (ie a resource: url referencing assets shipped with the application)
    *
    * @param  {string} base
    *         A string containing the base URL.  Must be a resource: URL.
    * @returns {Promise}
    *          A Promise that resolves when the addon is installed.
    */
   async installBuiltinAddon(base) {
+    if (lastLightweightTheme === null) {
+      lastLightweightTheme = Services.prefs.getCharPref(PREF_SELECTED_LWT, "");
+      Services.prefs.clearUserPref(PREF_SELECTED_LWT);
+    }
+
     let baseURL = Services.io.newURI(base);
 
     // WebExtensions need to be able to iterate through the contents of
     // an extension (for localization).  It knows how to do this with
     // jar: and file: URLs, so translate the provided base URL to
     // something it can use.
     if (baseURL.scheme !== "resource") {
       throw new Error("Built-in addons must use resource: URLS");
@@ -3675,25 +3687,36 @@ var XPIInstall = {
           return false;
         }
       },
     };
 
     let addon = await loadManifest(pkg, XPIInternal.BuiltInLocation);
     addon.rootURI = base;
 
-    // Themes are disabled by default at install time. However, we
-    // always want one theme to be active, falling back to the default
-    // theme when the active theme is disabled. The first time we
-    // install the default theme, though, there likely aren't any other
-    // theme add-ons installed yet, in which case we want to enable it
-    // immediately.
-    if (addon.id === DEFAULT_THEME_ID &&
-        !XPIDatabase.getAddonsByType("theme").some(theme => !theme.disabled)) {
-      addon.userDisabled = false;
+    // If this is a theme, decide whether to enable it. Themes are
+    // disabled by default. However:
+    //
+    // If a lightweight theme was selected in the last session, and this
+    // theme has the same ID, then we clearly want to enable it.
+    //
+    // If it is the default theme, more specialized behavior applies:
+    //
+    // We always want one theme to be active, falling back to the
+    // default theme when the active theme is disabled. The first time
+    // we install the default theme, though, there likely aren't any
+    // other theme add-ons installed yet, in which case we want to
+    // enable it immediately.
+    if (addon.type === "theme") {
+      if (addon.id === lastLightweightTheme ||
+          (!lastLightweightTheme.endsWith("@mozilla.org") &&
+           addon.id === DEFAULT_THEME_ID &&
+           !XPIDatabase.getAddonsByType("theme").some(theme => !theme.disabled))) {
+        addon.userDisabled = false;
+      }
     }
     await this._activateAddon(addon);
   },
 
   /**
    * Activate a newly installed addon.
    * This function handles all the bookkeeping related to a new addon
    * and invokes whatever bootstrap methods are necessary.