Bug 944740: Don't show Metro button in palette on non-win8. r=Gijs
authorMarina Samuel <msamuel@mozilla.com>
Tue, 03 Dec 2013 15:41:56 -0500
changeset 158506 03a55dd19083434bd16583b5770b5a0bff769f55
parent 158505 2b85377ba0c42e1a791902507c8a5d774fbe3846
child 158576 85694fd9b17cf468f11350af85f82f79d16e2e39
push id25748
push userryanvm@gmail.com
push dateTue, 03 Dec 2013 21:42:03 +0000
treeherdermozilla-central@03a55dd19083 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs
bugs944740
milestone28.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 944740: Don't show Metro button in palette on non-win8. r=Gijs
browser/components/customizableui/src/CustomizableUI.jsm
browser/components/customizableui/src/CustomizableWidgets.jsm
--- a/browser/components/customizableui/src/CustomizableUI.jsm
+++ b/browser/components/customizableui/src/CustomizableUI.jsm
@@ -146,33 +146,19 @@ let CustomizableUIInternal = {
       "print-button",
       "history-panelmenu",
       "fullscreen-button",
       "find-button",
       "preferences-button",
       "add-ons-button"
     ];
 
-#ifdef XP_WIN
-#ifdef MOZ_METRO
-    // Show switch-to-metro-button if in Windows 8.
-    let isMetroCapable = false;
-    try {
-      // Windows 8 is version 6.2.
-      let version = Cc["@mozilla.org/system-info;1"]
-                      .getService(Ci.nsIPropertyBag2)
-                      .getProperty("version");
-      isMetroCapable = (parseFloat(version) >= 6.2);
-    } catch (ex) { }
-
-    if (isMetroCapable) {
+    if (gPalette.has("switch-to-metro-button")) {
       panelPlacements.push("switch-to-metro-button");
     }
-#endif
-#endif
 
     let showCharacterEncoding = Services.prefs.getComplexValue(
       "browser.menu.showCharacterEncoding",
       Ci.nsIPrefLocalizedString
     ).data;
     if (showCharacterEncoding == "true") {
       panelPlacements.push("characterencoding-button");
     }
--- a/browser/components/customizableui/src/CustomizableWidgets.jsm
+++ b/browser/components/customizableui/src/CustomizableWidgets.jsm
@@ -20,16 +20,24 @@ XPCOMUtils.defineLazyServiceGetter(this,
 
 const kNSXUL = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
 const kPrefCustomizationDebug = "browser.uiCustomization.debug";
 const kWidePanelItemClass = "panel-wide-item";
 
 let gModuleName = "[CustomizableWidgets]";
 #include logging.js
 
+function isWin8OrHigher() {
+  let osName = Services.sysinfo.getProperty("name");
+  let version = Services.sysinfo.getProperty("version");
+
+  // Windows 8 is version >= 6.2
+  return osName == "Windows_NT" && Services.vc.compare(version, "6.2") >= 0;
+}
+
 function setAttributes(aNode, aAttrs) {
   for (let [name, value] of Iterator(aAttrs)) {
     if (!value) {
       if (aNode.hasAttribute(name))
         aNode.removeAttribute(name);
     } else {
       if (name == "label" || name == "tooltiptext")
         value = CustomizableUI.getLocalizedProperty({id: aAttrs.id}, name);
@@ -255,28 +263,16 @@ const CustomizableWidgets = [{
         items.firstChild.remove();
       }
 
       parent.appendChild(items);
       aEvent.target.removeEventListener("command",
                                         win.PanelUI.onCommandHandler);
     }
   }, {
-    id: "switch-to-metro-button",
-    removable: true,
-    defaultArea: CustomizableUI.AREA_PANEL,
-    onCommand: function(aEvent) {
-      let win = aEvent.target &&
-                aEvent.target.ownerDocument &&
-                aEvent.target.ownerDocument.defaultView;
-      if (win && typeof win.SwitchToMetro == "function") {
-        win.SwitchToMetro();
-      }
-    }
-  }, {
     id: "add-ons-button",
     removable: true,
     shortcutId: "key_openAddons",
     defaultArea: CustomizableUI.AREA_PANEL,
     onCommand: function(aEvent) {
       let win = aEvent.target &&
                 aEvent.target.ownerDocument &&
                 aEvent.target.ownerDocument.defaultView;
@@ -792,8 +788,28 @@ const CustomizableWidgets = [{
   }, {
     id: "email-link-button",
     removable: true,
     onCommand: function(aEvent) {
       let win = aEvent.view;
       win.MailIntegration.sendLinkForWindow(win.content);
     }
   }];
+
+#ifdef XP_WIN
+#ifdef MOZ_METRO
+if (isWin8OrHigher()) {
+  CustomizableWidgets.push({
+    id: "switch-to-metro-button",
+    removable: true,
+    defaultArea: CustomizableUI.AREA_PANEL,
+    onCommand: function(aEvent) {
+      let win = aEvent.target &&
+        aEvent.target.ownerDocument &&
+        aEvent.target.ownerDocument.defaultView;
+      if (win && typeof win.SwitchToMetro == "function") {
+        win.SwitchToMetro();
+      }
+    }
+  });
+}
+#endif
+#endif
\ No newline at end of file