Bug 1081192: move the Loop button to the palette by default. r=jaws,abr a=lmandel
authorMike de Boer <mdeboer@mozilla.com>
Mon, 13 Oct 2014 17:02:59 +0200
changeset 225692 9e9e53d15011
parent 225691 35b93d3f5d65
child 225693 00cf6dd17a10
push id3982
push userrjesup@wgate.com
push dateTue, 14 Oct 2014 02:10:17 +0000
treeherdermozilla-beta@9e9e53d15011 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws, abr, lmandel
bugs1081192
milestone34.0
Bug 1081192: move the Loop button to the palette by default. r=jaws,abr a=lmandel
browser/app/profile/firefox.js
browser/base/content/browser-loop.js
browser/base/content/browser.xul
browser/components/customizableui/CustomizableUI.jsm
browser/components/customizableui/CustomizableWidgets.jsm
browser/components/loop/MozLoopService.jsm
browser/components/loop/test/mochitest/head.js
browser/modules/test/browser_UITour_availableTargets.js
--- a/browser/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -1573,25 +1573,20 @@ pref("shumway.disabled", true);
 #endif
 
 // The maximum amount of decoded image data we'll willingly keep around (we
 // might keep around more than this, but we'll try to get down to this value).
 // (This is intentionally on the high side; see bug 746055.)
 pref("image.mem.max_decoded_image_kb", 256000);
 
 // Enable by default development builds up until early beta
-#ifdef EARLY_BETA_OR_EARLIER
-pref("loop.enabled", true);
-pref("loop.throttled", false);
-#else
 pref("loop.enabled", true);
 pref("loop.throttled", true);
 pref("loop.soft_start_ticket_number", -1);
 pref("loop.soft_start_hostname", "soft-start.loop.services.mozilla.com");
-#endif
 
 pref("loop.server", "https://loop.services.mozilla.com");
 pref("loop.seenToS", "unseen");
 pref("loop.legal.ToS_url", "https://accounts.firefox.com/legal/terms");
 pref("loop.legal.privacy_url", "https://www.mozilla.org/privacy/");
 pref("loop.do_not_disturb", false);
 pref("loop.ringtone", "chrome://browser/content/loop/shared/sounds/Firefox-Long.ogg");
 pref("loop.retry_delay.start", 60000);
--- a/browser/base/content/browser-loop.js
+++ b/browser/base/content/browser-loop.js
@@ -39,28 +39,33 @@ XPCOMUtils.defineLazyModuleGetter(this, 
                            "about:looppanel", null, callback);
     },
 
     /**
      * Triggers the initialization of the loop service.  Called by
      * delayedStartup.
      */
     init: function() {
+      let toolbarButton = this.toolbarButton;
       if (!Services.prefs.getBoolPref("loop.enabled")) {
-        this.toolbarButton.node.hidden = true;
+        if (toolbarButton && toolbarButton.node) {
+          toolbarButton.node.hidden = true;
+        }
         return;
       }
 
       // Add observer notifications before the service is initialized
       Services.obs.addObserver(this, "loop-status-changed", false);
 
       // If we're throttled, check to see if it's our turn to be unthrottled
       if (Services.prefs.getBoolPref("loop.throttled")) {
-        this.toolbarButton.node.hidden = true;
-        MozLoopService.checkSoftStart(this.toolbarButton.node);
+        if (toolbarButton && toolbarButton.node) {
+          toolbarButton.node.hidden = true;
+        }
+        MozLoopService.checkSoftStart(toolbarButton && toolbarButton.node);
         return;
       }
 
       MozLoopService.initialize();
       this.updateToolbarState();
     },
 
     uninit: function() {
@@ -81,20 +86,25 @@ XPCOMUtils.defineLazyModuleGetter(this, 
      * @param {string} [aReason] Some states are only shown if
      *                           a related reason is provided.
      *
      *                 aReason="login": Used after a login is completed
      *                   successfully. This is used so the state can be
      *                   temporarily shown until the next state change.
      */
     updateToolbarState: function(aReason = null) {
+      let toolbarButton = this.toolbarButton;
+      if (!toolbarButton || !toolbarButton.node) {
+        return;
+      }
+
       let state = "";
       if (MozLoopService.errors.size) {
         state = "error";
       } else if (aReason == "login" && MozLoopService.userProfile) {
         state = "active";
       } else if (MozLoopService.doNotDisturb) {
         state = "disabled";
       }
-      this.toolbarButton.node.setAttribute("state", state);
+      toolbarButton.node.setAttribute("state", state);
     },
   };
 })();
--- a/browser/base/content/browser.xul
+++ b/browser/base/content/browser.xul
@@ -664,17 +664,17 @@
            Should you need to add items to the toolbar here, make sure to also add them
            to the default placements of buttons in CustomizableUI.jsm, so the
            customization code doesn't get confused.
       -->
     <toolbar id="nav-bar" class="toolbar-primary chromeclass-toolbar"
              aria-label="&navbarCmd.label;"
              fullscreentoolbar="true" mode="icons" customizable="true"
              iconsize="small"
-             defaultset="urlbar-container,search-container,bookmarks-menu-button,downloads-button,home-button,loop-call-button,social-share-button,social-toolbar-item"
+             defaultset="urlbar-container,search-container,bookmarks-menu-button,downloads-button,home-button,social-share-button,social-toolbar-item"
              customizationtarget="nav-bar-customization-target"
              overflowable="true"
              overflowbutton="nav-bar-overflow-button"
              overflowtarget="widget-overflow-list"
              overflowpanel="widget-overflow"
              context="toolbar-context-menu">
 
       <hbox id="nav-bar-customization-target" flex="1">
--- a/browser/components/customizableui/CustomizableUI.jsm
+++ b/browser/components/customizableui/CustomizableUI.jsm
@@ -201,17 +201,16 @@ let CustomizableUIInternal = {
       type: CustomizableUI.TYPE_TOOLBAR,
       overflowable: true,
       defaultPlacements: [
         "urlbar-container",
         "search-container",
         "bookmarks-menu-button",
         "downloads-button",
         "home-button",
-        "loop-call-button",
         "social-share-button",
       ],
       defaultCollapsed: false,
     }, true);
 #ifndef XP_MACOSX
     this.registerArea(CustomizableUI.AREA_MENUBAR, {
       legacy: true,
       type: CustomizableUI.TYPE_TOOLBAR,
--- a/browser/components/customizableui/CustomizableWidgets.jsm
+++ b/browser/components/customizableui/CustomizableWidgets.jsm
@@ -896,39 +896,41 @@ const CustomizableWidgets = [{
     }
   }, {
     id: "email-link-button",
     tooltiptext: "email-link-button.tooltiptext3",
     onCommand: function(aEvent) {
       let win = aEvent.view;
       win.MailIntegration.sendLinkForWindow(win.content);
     }
-  }, {
+  }];
+
+if (Services.prefs.getBoolPref("loop.enabled") && !Services.prefs.getBoolPref("loop.throttled")) {
+  CustomizableWidgets.push({
     id: "loop-call-button",
     type: "custom",
     // XXX Bug 1013989 will provide a label for the button
     label: "loop-call-button.label",
     tooltiptext: "loop-call-button.tooltiptext",
-    defaultArea: CustomizableUI.AREA_NAVBAR,
-    introducedInVersion: 1,
     onBuild: function(aDocument) {
       let node = aDocument.createElementNS(kNSXUL, "toolbarbutton");
       node.setAttribute("id", this.id);
       node.classList.add("toolbarbutton-1");
       node.classList.add("chromeclass-toolbar-additional");
       node.setAttribute("type", "badged");
       node.setAttribute("label", CustomizableUI.getLocalizedProperty(this, "label"));
       node.setAttribute("tooltiptext", CustomizableUI.getLocalizedProperty(this, "tooltiptext"));
       node.setAttribute("removable", "true");
       node.addEventListener("command", function(event) {
         aDocument.defaultView.LoopUI.openCallPanel(event);
       });
       return node;
     }
-  }];
+  });
+}
 
 #ifdef XP_WIN
 #ifdef MOZ_METRO
 if (Services.metro && Services.metro.supported) {
   let widgetArgs = {tooltiptext: "switch-to-metro-button2.tooltiptext"};
   let brandShortName = BrandBundle.GetStringFromName("brandShortName");
   let metroTooltip = CustomizableUI.getLocalizedProperty(widgetArgs, "tooltiptext",
                                                          [brandShortName]);
--- a/browser/components/loop/MozLoopService.jsm
+++ b/browser/components/loop/MozLoopService.jsm
@@ -1275,17 +1275,19 @@ this.MozLoopService = {
       let now_serving = ((parseInt(address[1]) * 0x10000) +
                          (parseInt(address[2]) * 0x100) +
                          parseInt(address[3]));
 
       if (now_serving > ticket) {
         // Hot diggity! It's our turn! Activate the service.
         log.info("MozLoopService: Activating Loop via soft-start");
         Services.prefs.setBoolPref("loop.throttled", false);
-        buttonNode.hidden = false;
+        if (buttonNode) {
+          buttonNode.hidden = false;
+        }
         this.initialize();
       }
       if (typeof(doneCb) == "function") {
         doneCb(null);
       }
     };
 
     // We use DNS to propagate the slow-start value, since it has well-known
--- a/browser/components/loop/test/mochitest/head.js
+++ b/browser/components/loop/test/mochitest/head.js
@@ -209,16 +209,23 @@ let mockPushHandler = {
   /**
    * Test-only API to simplify notifying a push notification result.
    */
   notify: function(version) {
     this._notificationCallback(version);
   }
 };
 
+// Add the Loop button to the navbar.
+CustomizableUI.addWidgetToArea("loop-call-button", CustomizableUI.AREA_NAVBAR);
+
+registerCleanupFunction(function() {
+  CustomizableUI.reset();
+});
+
 const mockDb = {
   _store: { },
   _next_guid: 1,
 
   add: function(details, callback) {
     if (!("id" in details)) {
       callback(new Error("No 'id' field present"));
       return;
--- a/browser/modules/test/browser_UITour_availableTargets.js
+++ b/browser/modules/test/browser_UITour_availableTargets.js
@@ -21,17 +21,16 @@ let tests = [
         "accountStatus",
         "addons",
         "appMenu",
         "backForward",
         "bookmarks",
         "customize",
         "help",
         "home",
-        "loop",
         "pinnedTab",
         "quit",
         "search",
         "searchProvider",
         "urlbar",
       ]);
       ok(UITour.availableTargetsCache.has(window),
          "Targets should now be cached");
@@ -46,17 +45,16 @@ let tests = [
     gContentAPI.getConfiguration("availableTargets", (data) => {
       ok_targets(data, [
         "accountStatus",
         "addons",
         "appMenu",
         "backForward",
         "customize",
         "help",
-        "loop",
         "home",
         "pinnedTab",
         "quit",
         "search",
         "searchProvider",
         "urlbar",
       ]);
       ok(UITour.availableTargetsCache.has(window),
@@ -78,17 +76,16 @@ let tests = [
         "accountStatus",
         "addons",
         "appMenu",
         "backForward",
         "bookmarks",
         "customize",
         "help",
         "home",
-        "loop",
         "pinnedTab",
         "quit",
         "urlbar",
       ]);
       CustomizableUI.reset();
       done();
     });
   },