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 192779 bc14179fc49c189cfba7bd62d5da5112927e5ae8
parent 192778 dcd2cadb740abf1ed3470a3226a15547320d502b
child 192780 2e355bd4da64010bf4f74f18ce5297a495e664d0
push id474
push userasasaki@mozilla.com
push dateMon, 02 Jun 2014 21:01:02 +0000
treeherdermozilla-release@967f4cf1b31c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmconley, sylvestre
bugs989289
milestone30.0a2
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
browser/components/customizableui/test/browser.ini
browser/components/customizableui/test/browser_989289_force_icons_mode_attribute.js
--- a/browser/components/customizableui/content/toolbar.xml
+++ b/browser/components/customizableui/content/toolbar.xml
@@ -40,20 +40,34 @@
       ]]></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" attribute, just
-          // in case it gets accidentally restored from persistence from a user
-          // that's been upgrading and downgrading.
-          this.setAttribute("mode", "icons");
+          // 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.
--- 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);
     }
   },
 
@@ -3295,17 +3307,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.
  */
--- a/browser/components/customizableui/test/browser.ini
+++ b/browser/components/customizableui/test/browser.ini
@@ -86,12 +86,10 @@ skip-if = os == "linux"
 [browser_984455_bookmarks_items_reparenting.js]
 skip-if = os == "linux"
 
 [browser_985815_propagate_setToolbarVisibility.js]
 [browser_981305_separator_insertion.js]
 [browser_989609_bootstrapped_custom_toolbar.js]
 [browser_987177_destroyWidget_xul.js]
 [browser_987177_xul_wrapper_updating.js]
-[browser_989289_force_icons_mode_attribute.js]
-skip-if = os == "linux" && debug
 [browser_987492_window_api.js]
 [browser_panel_toggle.js]
deleted file mode 100644
--- a/browser/components/customizableui/test/browser_989289_force_icons_mode_attribute.js
+++ /dev/null
@@ -1,31 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-"use strict";
-
-const kToolbarID = "test-toolbar";
-
-/**
- * Tests that customizable toolbars are forced to have their mode
- * attribute set to "icons".
- */
-add_task(function* testAddingToolbar() {
-  let toolbar = document.createElement("toolbar");
-  toolbar.setAttribute("mode", "full");
-  toolbar.setAttribute("customizable", "true");
-  toolbar.setAttribute("id", kToolbarID);
-
-  CustomizableUI.registerArea(kToolbarID, {
-     type: CustomizableUI.TYPE_TOOLBAR,
-     legacy: false,
-  })
-
-  gNavToolbox.appendChild(toolbar);
-
-  is(toolbar.getAttribute("mode"), "icons",
-     "Toolbar should have its mode attribute set to icons.")
-
-  toolbar.remove();
-  CustomizableUI.unregisterArea(kToolbarID);
-});
\ No newline at end of file