Bug 1229123 support for obsoleted buttons, r=Gijs
authorShane Caraveo <scaraveo@mozilla.com>
Mon, 30 Nov 2015 13:57:01 -0800
changeset 308824 97258d49fa0184f98d1b730b463e0d7c3de4145e
parent 308823 996c67a6a11363e13efa4d77a8fe449c3081f221
child 308825 4bc4ce69937d1623df0ca3212d261060c25d0b59
push id5513
push userraliiev@mozilla.com
push dateMon, 25 Jan 2016 13:55:34 +0000
treeherdermozilla-beta@5ee97dd05b5c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs
bugs1229123
milestone45.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 1229123 support for obsoleted buttons, r=Gijs
browser/components/customizableui/CustomizableUI.jsm
--- a/browser/components/customizableui/CustomizableUI.jsm
+++ b/browser/components/customizableui/CustomizableUI.jsm
@@ -51,16 +51,23 @@ const kSubviewEvents = [
 
 /**
  * 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 = 4;
 
 /**
+ * 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 = {};
+
+/**
  * gPalette is a map of every widget that CustomizableUI.jsm knows about, keyed
  * on their IDs.
  */
 var gPalette = new Map();
 
 /**
  * gAreas maps area IDs to Sets of properties about those areas. An area is a
  * place where a widget can be put.
@@ -149,16 +156,17 @@ var gModuleName = "[CustomizableUI]";
 var CustomizableUIInternal = {
   initialize: function() {
     LOG("Initializing");
 
     this.addListener(this);
     this._defineBuiltInWidgets();
     this.loadSavedState();
     this._introduceNewBuiltinWidgets();
+    this._markObsoleteBuiltinButtonsSeen();
 
     let panelPlacements = [
       "edit-controls",
       "zoom-controls",
       "new-window-button",
       "privatebrowsing-button",
       "save-page-button",
       "print-button",
@@ -347,16 +355,36 @@ var CustomizableUIInternal = {
       CustomizableUI.removeWidgetFromArea("loop-call-button");
     }
 
     if (currentVersion < 4) {
       CustomizableUI.removeWidgetFromArea("loop-button-throttled");
     }
   },
 
+  /**
+   * _markObsoleteBuiltinButtonsSeen
+   * when upgrading, ensure obsoleted buttons are in seen state.
+   */
+  _markObsoleteBuiltinButtonsSeen: function() {
+    if (!gSavedState)
+      return;
+    let currentVersion = gSavedState.currentVersion;
+    if (currentVersion >= kVersion)
+      return;
+    // we're upgrading, update state if necessary
+    for (let id in ObsoleteBuiltinButtons) {
+      let version = ObsoleteBuiltinButtons[id]
+      if (version == kVersion) {
+        gSeenWidgets.add(id);
+        gDirty = true;
+      }
+    }
+  },
+
   _placeNewDefaultWidgetsInArea: function(aArea) {
     let futurePlacedWidgets = gFuturePlacements.get(aArea);
     let savedPlacements = gSavedState && gSavedState.placements && gSavedState.placements[aArea];
     let defaultPlacements = gAreas.get(aArea).get("defaultPlacements");
     if (!savedPlacements || !savedPlacements.length || !futurePlacedWidgets || !defaultPlacements ||
         !defaultPlacements.length) {
       return;
     }
@@ -584,17 +612,17 @@ var CustomizableUIInternal = {
     try {
       let placements = gPlacements.get(area);
       if (!placements && areaProperties.has("legacy")) {
         let legacyState = aToolbar.getAttribute("currentset");
         if (legacyState) {
           legacyState = legacyState.split(",").filter(s => s);
         }
 
-        // Manually restore the state here, so the legacy state can be converted. 
+        // Manually restore the state here, so the legacy state can be converted.
         this.restoreStateForArea(area, legacyState);
         placements = gPlacements.get(area);
       }
 
       // Check that the current children and the current placements match. If
       // not, mark it as dirty:
       if (aExistingChildren.length != placements.length ||
           aExistingChildren.every((id, i) => id == placements[i])) {
@@ -1615,17 +1643,17 @@ var CustomizableUIInternal = {
       if (isInteractive) {
         return;
       }
     }
 
     // We can't use event.target because we might have passed a panelview
     // anonymous content boundary as well, and so target points to the
     // panelmultiview in that case. Unfortunately, this means we get
-    // anonymous child nodes instead of the real ones, so looking for the 
+    // anonymous child nodes instead of the real ones, so looking for the
     // 'stoooop, don't close me' attributes is more involved.
     let target = aEvent.originalTarget;
     let closemenu = "auto";
     let widgetType = "button";
     while (target.parentNode && target.localName != "panel") {
       closemenu = target.getAttribute("closemenu");
       widgetType = target.getAttribute("widget-type");
       if (closemenu == "none" || closemenu == "single" ||
@@ -1858,17 +1886,17 @@ var CustomizableUIInternal = {
 
     this.notifyListeners("onWidgetMoved", aWidgetId, oldPlacement.area,
                          oldPlacement.position, aPosition);
   },
 
   // Note that this does not populate gPlacements, which is done lazily so that
   // the legacy state can be migrated, which is only available once a browser
   // window is openned.
-  // The panel area is an exception here, since it has no legacy state and is 
+  // The panel area is an exception here, since it has no legacy state and is
   // built lazily - and therefore wouldn't otherwise result in restoring its
   // state immediately when a browser window opens, which is important for
   // other consumers of this API.
   loadSavedState: function() {
     let state = null;
     try {
       state = Services.prefs.getCharPref(kPrefCustomizationState);
     } catch (e) {
@@ -3838,17 +3866,17 @@ function XULWidgetGroupWrapper(aWidgetId
   this.__defineGetter__("instances", function() {
     return [this.forWindow(win) for ([win,] of gBuildWindows)];
   });
 
   Object.freeze(this);
 }
 
 /**
- * A XULWidgetSingleWrapper is a wrapper around a single instance of a XUL 
+ * A XULWidgetSingleWrapper is a wrapper around a single instance of a XUL
  * widget in a particular window.
  */
 function XULWidgetSingleWrapper(aWidgetId, aNode, aDocument) {
   this.isGroup = false;
 
   this.id = aWidgetId;
   this.type = "custom";
   this.provider = CustomizableUI.PROVIDER_XUL;