Bug 563241 Support dynamic skin switching preference r=Mossop
authorNeil Rashbrook <neil@parkwaycc.co.uk>
Fri, 28 May 2010 10:07:21 +0100
changeset 42890 61984c0c4e5ffa8112950b68aa6ae90d41177399
parent 42889 fadb38356e0f08f777670e24456b60dec362d108
child 42891 aa20e4f73d81e5cf9e7f2efb5f0e7b73084a24f2
push idunknown
push userunknown
push dateunknown
reviewersMossop
bugs563241
milestone1.9.3a5pre
Bug 563241 Support dynamic skin switching preference r=Mossop
toolkit/mozapps/extensions/XPIProvider.jsm
--- a/toolkit/mozapps/extensions/XPIProvider.jsm
+++ b/toolkit/mozapps/extensions/XPIProvider.jsm
@@ -1951,17 +1951,18 @@ var XPIProvider = {
    * @param  aAddon
    *         The add-on to test
    * @return true if the operation requires a restart
    */
   enableRequiresRestart: function XPI_enableRequiresRestart(aAddon) {
     // If the theme we're enabling is the skin currently selected then it doesn't
     // require a restart to enable it.
     if (aAddon.type == "theme")
-      return aAddon.internalName != this.currentSkin;
+      return aAddon.internalName != this.currentSkin &&
+             !Prefs.getBoolPref(PREF_EM_DSS_ENABLED);
 
     return !aAddon.bootstrap;
   },
 
   /**
    * Tests whether disabling an add-on will require a restart.
    *
    * @param  aAddon
@@ -1969,47 +1970,50 @@ var XPIProvider = {
    * @return true if the operation requires a restart
    */
   disableRequiresRestart: function XPI_disableRequiresRestart(aAddon) {
     // This sounds odd but it is correct. Themes are only ever asked to disable
     // after another theme has been enabled. Disabling the theme only requires
     // a restart if enabling the other theme does too. If the selected skin doesn't
     // match the current skin then a restart is necessary.
     if (aAddon.type == "theme")
-      return this.selectedSkin != this.currentSkin;
+      return this.selectedSkin != this.currentSkin &&
+             !Prefs.getBoolPref(PREF_EM_DSS_ENABLED);
 
     return !aAddon.bootstrap;
   },
 
   /**
    * Tests whether installing an add-on will require a restart.
    *
    * @param  aAddon
    *         The add-on to test
    * @return true if the operation requires a restart
    */
   installRequiresRestart: function XPI_installRequiresRestart(aAddon) {
     // Themes not currently in use can be installed immediately
     if (aAddon.type == "theme")
-      return aAddon.internalName == this.currentSkin;
+      return aAddon.internalName == this.currentSkin ||
+             Prefs.getBoolPref(PREF_EM_DSS_ENABLED);
 
     return !aAddon.bootstrap;
   },
 
   /**
    * Tests whether uninstalling an add-on will require a restart.
    *
    * @param  aAddon
    *         The add-on to test
    * @return true if the operation requires a restart
    */
   uninstallRequiresRestart: function XPI_uninstallRequiresRestart(aAddon) {
     // Themes not currently in use can be uninstalled immediately
     if (aAddon.type == "theme")
-      return aAddon.internalName == this.currentSkin;
+      return aAddon.internalName == this.currentSkin ||
+             Prefs.getBoolPref(PREF_EM_DSS_ENABLED);
 
     return !aAddon.bootstrap;
   },
 
   /**
    * Loads a bootstrapped add-on's bootstrap.js into a sandbox and the reason
    * values as constants in the scope. This will also add information about the
    * add-on to the bootstrappedAddons dictionary and notify the crash reporter
@@ -2461,16 +2465,17 @@ var XPIDatabase = {
     clearVisibleAddons: "UPDATE addon SET visible=0 WHERE id=:id",
     updateAddonActive: "UPDATE addon SET active=:active WHERE " +
                        "internal_id=:internal_id",
 
     getActiveAddons: "SELECT " + FIELDS_ADDON + " FROM addon WHERE active=1 AND " +
                      "type<>'theme' AND bootstrap=0",
     getActiveTheme: "SELECT " + FIELDS_ADDON + " FROM addon WHERE " +
                     "internalName=:internalName AND type='theme'",
+    getThemes: "SELECT " + FIELDS_ADDON + " FROM addon WHERE type='theme'",
 
     getAddonInLocation: "SELECT " + FIELDS_ADDON + " FROM addon WHERE id=:id " +
                         "AND location=:location",
     getAddons: "SELECT " + FIELDS_ADDON + " FROM addon",
     getAddonsByType: "SELECT " + FIELDS_ADDON + " FROM addon WHERE type=:type",
     getAddonsInLocation: "SELECT " + FIELDS_ADDON + " FROM addon WHERE " +
                          "location=:location",
     getInstallLocations: "SELECT DISTINCT location FROM addon",
@@ -3440,17 +3445,17 @@ var XPIDatabase = {
    * Synchronously pdates an add-on's active flag in the database.
    *
    * @param  aAddon
    *         The DBAddonInternal to update
    */
   updateAddonActive: function XPIDB_updateAddonActive(aAddon) {
     LOG("Updating add-on state");
 
-    stmt = this.getStatement("updateAddonActive");
+    let stmt = this.getStatement("updateAddonActive");
     stmt.params.internal_id = aAddon._internal_id;
     stmt.params.active = aAddon.active ? 1 : 0;
     executeStatement(stmt);
   },
 
   /**
    * Synchronously calculates and updates all the active flags in the database.
    */
@@ -3485,18 +3490,23 @@ var XPIDatabase = {
         continue;
       text += "Extension" + (count++) + "=" + row.descriptor + "\r\n";
       enabledAddons.push(row.id + ":" + row.version);
     }
 
     // The selected skin may come from an inactive theme (the default theme
     // when a lightweight theme is applied for example)
     text += "\r\n[ThemeDirs]\r\n";
-    stmt = this.getStatement("getActiveTheme");
-    stmt.params.internalName = XPIProvider.selectedSkin;
+    if (Prefs.getBoolPref(PREF_EM_DSS_ENABLED)) {
+      stmt = this.getStatement("getThemes");
+    }
+    else {
+      stmt = this.getStatement("getActiveTheme");
+      stmt.params.internalName = XPIProvider.selectedSkin;
+    }
     count = 0;
     for (let row in resultRows(stmt)) {
       // Don't include add-ons that are waiting to be updated
       if (aPendingUpdateIDs.indexOf(row.id) != -1)
         continue;
       text += "Extension" + (count++) + "=" + row.descriptor + "\r\n";
       enabledAddons.push(row.id + ":" + row.version);
     }