Bug 940494 - When a Social provider has a status button, the provider's icon should go to the status button rather than the social api toolbar button. r=markh, a=bajaj
authorFlorian Quèze <florian@queze.net>
Mon, 25 Nov 2013 13:39:12 +0100
changeset 166630 8dcdb738ddbc1e8fcd63015ebeb26c84d72d0b23
parent 166629 39c91b039dcdae6fd47d53ae6e0c4a83a7386451
child 166631 56f4f6a8d4d97ab81465bbb96aaf7b8f81e5e1d9
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmarkh, bajaj
bugs940494
milestone27.0a2
Bug 940494 - When a Social provider has a status button, the provider's icon should go to the status button rather than the social api toolbar button. r=markh, a=bajaj
browser/base/content/browser-social.js
browser/base/content/test/social/browser_social_status.js
browser/base/content/test/social/head.js
--- a/browser/base/content/browser-social.js
+++ b/browser/base/content/browser-social.js
@@ -147,29 +147,32 @@ SocialUI = {
           SocialToolbar.populateProviderMenus();
           SocialShare.populateProviderMenu();
           SocialStatus.populateToolbarPalette();
           SocialMarks.populateToolbarPalette();
           break;
 
         // Provider-specific notifications
         case "social:ambient-notification-changed":
-          SocialStatus.updateNotification(data);
+          SocialStatus.updateButton(data);
           if (this._matchesCurrentProvider(data)) {
             SocialToolbar.updateButton();
             SocialMenu.populate();
           }
           break;
         case "social:profile-changed":
           // make sure anything that happens here only affects the provider for
           // which the profile is changing, and that anything we call actually
           // needs to change based on profile data.
+          SocialStatus.updateButton(data);
           if (this._matchesCurrentProvider(data)) {
             SocialToolbar.updateProvider();
           }
+          // Refresh the provider menus, as the icons may have changed.
+          SocialToolbar.populateProviderMenus();
           break;
         case "social:frameworker-error":
           if (this.enabled && Social.provider.origin == data) {
             SocialSidebar.setSidebarErrorMessage();
           }
           break;
 
         case "nsPref:changed":
@@ -841,27 +844,32 @@ SocialToolbar = {
     this._updateButtonHiddenState();
     this.updateProvider();
     this.populateProviderMenus();
   },
 
   // Called when the Social.provider changes
   updateProvider: function () {
     let provider = Social.provider;
-    if (provider) {
+    // If the provider uses the new SocialStatus button, then they do
+    // not get to customize the old toolbar button.  Since the status
+    // button depends on multiple workers, if not enabled we will
+    // ignore this limitation.  That allows a provider to migrate to
+    // the new functionality once we enable multiple workers.
+    if (provider && (!provider.statusURL || !Social.allowMultipleWorkers)) {
       this.button.setAttribute("label", provider.name);
       this.button.setAttribute("tooltiptext", provider.name);
       this.button.style.listStyleImage = "url(" + provider.iconURL + ")";
-
-      this.updateProfile();
     } else {
       this.button.setAttribute("label", gNavigatorBundle.getString("service.toolbarbutton.label"));
       this.button.setAttribute("tooltiptext", gNavigatorBundle.getString("service.toolbarbutton.tooltiptext"));
       this.button.style.removeProperty("list-style-image");
     }
+    if (provider)
+      this.updateProfile();
     this.updateButton();
   },
 
   get button() {
     return document.getElementById("social-provider-button");
   },
 
   // Note: this doesn't actually handle hiding the toolbar button,
@@ -1526,36 +1534,43 @@ SocialStatus = {
       }
     } else {
       frame.setAttribute("origin", provider.origin);
       SharedFrame.updateURL(notificationFrameId, provider.statusURL);
     }
     aButton.setAttribute("notificationFrameId", notificationFrameId);
   },
 
-  updateNotification: function(origin) {
+  updateButton: function(origin) {
     if (!Social.allowMultipleWorkers)
       return;
     let provider = Social._getProviderFromOrigin(origin);
     let button = document.getElementById(this._toolbarHelper.idFromOrgin(provider.origin));
     if (button) {
       // we only grab the first notification, ignore all others
       let icons = provider.ambientNotificationIcons;
       let iconNames = Object.keys(icons);
       let notif = icons[iconNames[0]];
+
+      // The image and tooltip need to be updated for both
+      // ambient notification and profile changes.
+      let iconURL, tooltiptext;
+      if (notif) {
+        iconURL = notif.iconURL;
+        tooltiptext = notif.label;
+      }
+      button.setAttribute("image", iconURL || provider.iconURL);
+      button.setAttribute("tooltiptext", tooltiptext || provider.name);
+
       if (!notif) {
         button.setAttribute("badge", "");
         button.setAttribute("aria-label", "");
-        button.setAttribute("tooltiptext", "");
         return;
       }
 
-      button.style.listStyleImage = "url(" + notif.iconURL || provider.iconURL + ")";
-      button.setAttribute("tooltiptext", notif.label);
-
       let badge = notif.counter || "";
       button.setAttribute("badge", badge);
       let ariaLabel = notif.label;
       // if there is a badge value, we must use a localizable string to insert it.
       if (badge)
         ariaLabel = gNavigatorBundle.getFormattedString("social.aria.toolbarButtonBadgeText",
                                                         [ariaLabel, badge]);
       button.setAttribute("aria-label", ariaLabel);
--- a/browser/base/content/test/social/browser_social_status.js
+++ b/browser/base/content/test/social/browser_social_status.js
@@ -183,17 +183,17 @@ var tests = {
           if (e.data.result == "shown") {
             let panel = document.getElementById("social-notification-panel");
             panel.hidePopup();
           } else {
             port.postMessage({topic: "test-ambient-notification", data: icon});
             port.close();
             waitForCondition(function() { return btn.getAttribute("badge"); },
                        function() {
-                         is(btn.style.listStyleImage, "url(\"" + icon.iconURL + "\")", "notification icon updated");
+                         is(btn.getAttribute("image"), icon.iconURL, "notification icon updated");
                          next();
                        }, "button updated by notification");
           }
           break;
       }
     };
     port.postMessage({topic: "test-init"});
   },
--- a/browser/base/content/test/social/head.js
+++ b/browser/base/content/test/social/head.js
@@ -239,17 +239,17 @@ function checkSocialUI(win) {
   isbool(win.SocialSidebar.canShow, enabled, "social sidebar active?");
   if (enabled)
     isbool(win.SocialSidebar.opened, enabled, "social sidebar open?");
   isbool(win.SocialChatBar.isAvailable, enabled, "chatbar available?");
   isbool(!win.SocialChatBar.chatbar.hidden, enabled, "chatbar visible?");
 
   isbool(!doc.getElementById("social-toolbar-item").hidden, active, "toolbar items visible?");
   if (active) {
-    if (!enabled) {
+    if (!enabled || (Social.defaultProvider.statusURL && Social.allowMultipleWorkers)) {
       _ok(!win.SocialToolbar.button.style.listStyleImage, "toolbar button is default icon");
     } else {
       _is(win.SocialToolbar.button.style.listStyleImage, 'url("' + Social.defaultProvider.iconURL + '")', "toolbar button has provider icon");
     }
   }
   // the menus should always have the provider name
   if (provider) {
     for (let id of ["menu_socialSidebar", "menu_socialAmbientMenu"])
@@ -571,9 +571,8 @@ function getPopupWidth() {
   let margins = parseInt(cs.marginLeft) + parseInt(cs.marginRight);
   return popup.parentNode.getBoundingClientRect().width + margins;
 }
 
 function closeAllChats() {
   let chatbar = window.SocialChatBar.chatbar;
   chatbar.removeAll();
 }
-