Bug 896314 - Fix permission icon when swapping social providers. r=felipe, a=bajaj
authorShane Caraveo <scaraveo@mozilla.com>
Mon, 29 Jul 2013 09:35:41 -0700
changeset 148141 7ef5c3efbcab15ac171c9c61ca62f94777fb36d2
parent 148140 30132c3fe38a209a8d46934e0ec043cfb2102e01
child 148142 7844db8f7d37282e09493b3e8deab037231e5129
push id2697
push userbbajaj@mozilla.com
push dateMon, 05 Aug 2013 18:49:53 +0000
treeherdermozilla-beta@dfec938c7b63 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfelipe, bajaj
bugs896314
milestone24.0a2
Bug 896314 - Fix permission icon when swapping social providers. r=felipe, a=bajaj
browser/base/content/browser-social.js
toolkit/modules/PopupNotifications.jsm
--- a/browser/base/content/browser-social.js
+++ b/browser/base/content/browser-social.js
@@ -1362,16 +1362,17 @@ SocialSidebar = {
         SocialSidebar.setSidebarErrorMessage();
         return;
       }
 
       // Make sure the right sidebar URL is loaded
       if (sbrowser.getAttribute("src") != Social.provider.sidebarURL) {
         sbrowser.setAttribute("src", Social.provider.sidebarURL);
         sbrowser.addEventListener("load", SocialSidebar._loadListener, true);
+        PopupNotifications.locationChange(sbrowser);
       } else {
         this.setSidebarVisibilityState(true);
       }
     }
   },
 
   _loadListener: function SocialSidebar_loadListener() {
     let sbrowser = document.getElementById("social-sidebar-browser");
--- a/toolkit/modules/PopupNotifications.jsm
+++ b/toolkit/modules/PopupNotifications.jsm
@@ -16,16 +16,28 @@ const NOTIFICATION_EVENT_SHOWN = "shown"
 const ICON_SELECTOR = ".notification-anchor-icon";
 const ICON_ATTRIBUTE_SHOWING = "showing";
 
 const PREF_SECURITY_DELAY = "security.notification_enable_delay";
 
 let popupNotificationsMap = new WeakMap();
 let gNotificationParents = new WeakMap;
 
+function getAnchorFromBrowser(aBrowser) {
+  let anchor = aBrowser.getAttribute("popupnotificationanchor") ||
+                aBrowser.popupnotificationanchor;
+  if (anchor) {
+    if (anchor instanceof Ci.nsIDOMXULElement) {
+      return anchor;
+    }
+    return aBrowser.ownerDocument.getElementById(anchor);
+  }
+  return null;
+}
+
 /**
  * Notification object describes a single popup notification.
  *
  * @see PopupNotifications.show()
  */
 function Notification(id, message, anchorID, mainAction, secondaryActions,
                       browser, owner, options) {
   this.id = id;
@@ -55,26 +67,17 @@ Notification.prototype = {
    */
   remove: function Notification_remove() {
     this.owner.remove(this);
   },
 
   get anchorElement() {
     let iconBox = this.owner.iconBox;
 
-    let anchorElement = null;
-    let anchor = this.browser.getAttribute("popupnotificationanchor") ||
-                 this.browser.popupnotificationanchor;
-    if (anchor) {
-      if (anchor instanceof Ci.nsIDOMXULElement) {
-        anchorElement = anchor;
-      } else {
-        anchorElement = this.browser.ownerDocument.getElementById(anchor);
-      }
-    }
+    let anchorElement = getAnchorFromBrowser(this.browser);
 
     if (!iconBox)
       return anchorElement;
 
     if (!anchorElement && this.anchorID)
       anchorElement = iconBox.querySelector("#"+this.anchorID);
 
     // Use a default anchor icon if it's available
@@ -339,18 +342,25 @@ PopupNotifications.prototype = {
       }
 
       this._fireCallback(notification, NOTIFICATION_EVENT_REMOVED);
       return false;
     }, this);
 
     this._setNotificationsForBrowser(aBrowser, notifications);
 
-    if (aBrowser.docShell.isActive)
-      this._update(notifications);
+    if (aBrowser.docShell.isActive) {
+      // get the anchor element if the browser has defined one so it will
+      // _update will handle both the tabs iconBox and non-tab permission
+      // anchors.
+      let anchorElement = notifications.length > 0 ? notifications[0].anchorElement : null;
+      if (!anchorElement)
+        anchorElement = getAnchorFromBrowser(aBrowser);
+      this._update(notifications, anchorElement);
+    }
   },
 
   /**
    * Removes a Notification.
    * @param notification
    *        The Notification object to remove.
    */
   remove: function PopupNotifications_remove(notification) {