Bug 989289 - only migrate builtin toolbars, also migrate toolbox, r=mconley a=sylvestre
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Wed, 09 Apr 2014 23:56:38 +0100
changeset 183730 e946bc71ae2b6940d26607f2455c154efe7581f8
parent 183729 8e6041de3ce7c9475ddb236293355a5e95d5a7bd
child 183731 915700dc51980eaef319a2193b519e4f593f39e2
push id3461
push usermozilla@noorenberghe.ca
push dateMon, 14 Apr 2014 00:29:54 +0000
treeherdermozilla-beta@e946bc71ae2b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmconley, sylvestre
bugs989289
milestone29.0
Bug 989289 - only migrate builtin toolbars, also migrate toolbox, r=mconley a=sylvestre
browser/components/customizableui/content/toolbar.xml
browser/components/customizableui/src/CustomizableUI.jsm
--- a/browser/components/customizableui/content/toolbar.xml
+++ b/browser/components/customizableui/content/toolbar.xml
@@ -40,16 +40,35 @@
       ]]></constructor>
 
       <method name="_init">
         <body><![CDATA[
           let scope = {};
           Cu.import("resource:///modules/CustomizableUI.jsm", scope);
           let CustomizableUI = scope.CustomizableUI;
 
+          // Bug 989289: Forcibly set the now unsupported "mode" and "iconsize"
+          // attributes, just in case they accidentally get restored from
+          // persistence from a user that's been upgrading and downgrading.
+          if (CustomizableUI.isBuiltinToolbar(this.id)) {
+            const kAttributes = new Map([["mode", "icons"], ["iconsize", "small"]]);
+            for (let [attribute, value] of kAttributes) {
+              if (this.getAttribute(attribute) != value) {
+                this.setAttribute(attribute, value);
+                document.persist(this.id, attribute);
+              }
+              if (this.toolbox) {
+                if (this.toolbox.getAttribute(attribute) != value) {
+                  this.toolbox.setAttribute(attribute, value);
+                  document.persist(this.toolbox.id, attribute);
+                }
+              }
+            }
+          }
+
           // Searching for the toolbox palette in the toolbar binding because
           // toolbars are constructed first.
           let toolbox = this.toolbox;
           if (toolbox && !toolbox.palette) {
             for (let node of toolbox.children) {
               if (node.localName == "toolbarpalette") {
                 // Hold on to the palette but remove it from the document.
                 toolbox.palette = node;
--- a/browser/components/customizableui/src/CustomizableUI.jsm
+++ b/browser/components/customizableui/src/CustomizableUI.jsm
@@ -240,16 +240,28 @@ let CustomizableUIInternal = {
     this.registerArea(CustomizableUI.AREA_ADDONBAR, {
       type: CustomizableUI.TYPE_TOOLBAR,
       legacy: true,
       defaultPlacements: ["addonbar-closebutton", "status-bar"],
       defaultCollapsed: false,
     }, true);
   },
 
+  get _builtinToolbars() {
+    return new Set([
+      CustomizableUI.AREA_NAVBAR,
+      CustomizableUI.AREA_BOOKMARKS,
+      CustomizableUI.AREA_TABSTRIP,
+      CustomizableUI.AREA_ADDONBAR,
+#ifndef XP_MACOSX
+      CustomizableUI.AREA_MENUBAR,
+#endif
+    ]);
+  },
+
   _defineBuiltInWidgets: function() {
     //XXXunf Need to figure out how to auto-add new builtin widgets in new
     //       app versions to already customized areas.
     for (let widgetDefinition of CustomizableWidgets) {
       this.createBuiltinWidget(widgetDefinition);
     }
   },
 
@@ -3296,17 +3308,25 @@ this.CustomizableUI = {
       else if (node.id == CustomizableUI.AREA_PANEL)
         place = "panel";
       else if (node.id == "customization-palette")
         place = "palette";
 
       node = node.parentNode;
     }
     return place;
-  }
+  },
+
+  /**
+   * Check if a toolbar is builtin or not.
+   * @param aToolbarId the ID of the toolbar you want to check
+   */
+  isBuiltinToolbar: function(aToolbarId) {
+    return CustomizableUIInternal._builtinToolbars.has(aToolbarId);
+  },
 };
 Object.freeze(this.CustomizableUI);
 Object.freeze(this.CustomizableUI.windows);
 
 /**
  * All external consumers of widgets are really interacting with these wrappers
  * which provide a common interface.
  */