Bug 1399517 - remove CustomizableUI placements for old buttons to avoid saved state corruption, r?mikedeboer draft
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Mon, 18 Sep 2017 17:34:50 +0100
changeset 667015 98440eca116a71d3dc942438fd4f5c17b0f151d7
parent 667014 aaafc2349e7a8984f8fbc4dba161b8d1e4e521b5
child 732275 aaf21c9af3f4dd1b5ec16847d462551f1483ef6c
push id80590
push userbmo:gijskruitbosch+bugs@gmail.com
push dateTue, 19 Sep 2017 15:05:12 +0000
reviewersmikedeboer
bugs1399517
milestone57.0a1
Bug 1399517 - remove CustomizableUI placements for old buttons to avoid saved state corruption, r?mikedeboer MozReview-Commit-ID: 3XKPuz9KwlD
browser/components/customizableui/CustomizableUI.jsm
--- a/browser/components/customizableui/CustomizableUI.jsm
+++ b/browser/components/customizableui/CustomizableUI.jsm
@@ -54,17 +54,17 @@ const kSubviewEvents = [
   "ViewShowing",
   "ViewHiding"
 ];
 
 /**
  * The current version. We can use this to auto-add new default widgets as necessary.
  * (would be const but isn't because of testing purposes)
  */
-var kVersion = 11;
+var kVersion = 12;
 
 /**
  * Buttons removed from built-ins by version they were removed. kVersion must be
  * bumped any time a new id is added to this. Use the button id as key, and
  * version the button is removed in as the value.  e.g. "pocket-button": 5
  */
 var ObsoleteBuiltinButtons = {
 };
@@ -306,25 +306,16 @@ var CustomizableUIInternal = {
           }
           if (shouldSetPref) {
             Services.prefs.setBoolPref(prefId, true);
           }
         }
       }
     }
 
-    if (currentVersion < 2) {
-      // Nuke the old 'loop-call-button' out of orbit.
-      CustomizableUI.removeWidgetFromArea("loop-call-button");
-    }
-
-    if (currentVersion < 4) {
-      CustomizableUI.removeWidgetFromArea("loop-button-throttled");
-    }
-
     if (currentVersion < 7 && gSavedState.placements &&
         gSavedState.placements[CustomizableUI.AREA_NAVBAR]) {
       let placements = gSavedState.placements[CustomizableUI.AREA_NAVBAR];
       let newPlacements = ["back-button", "forward-button", "stop-reload-button", "home-button"];
       for (let button of placements) {
         if (!newPlacements.includes(button)) {
           newPlacements.push(button);
         }
@@ -444,16 +435,28 @@ var CustomizableUIInternal = {
             break;
           }
         }
         // We either found the right spot, or reached the end of the
         // placements, so insert here:
         navbarPlacements.splice(insertionPoint, 0, "downloads-button");
       }
     }
+
+    if (currentVersion < 12 && gSavedState.placements) {
+      const removedButtons = ["loop-call-button", "loop-button-throttled", "pocket-button"];
+      for (let placements of Object.values(gSavedState.placements)) {
+        for (let button of removedButtons) {
+          let buttonIndex = placements.indexOf(button);
+          if (buttonIndex != -1) {
+            placements.splice(buttonIndex, 1);
+          }
+        }
+      }
+    }
   },
 
   /**
    * _markObsoleteBuiltinButtonsSeen
    * when upgrading, ensure obsoleted buttons are in seen state.
    */
   _markObsoleteBuiltinButtonsSeen() {
     if (!gSavedState)