Bug 904521 - Fix the close of chat windows when new windows are opened. r=markh, a=bajaj
authorShane Caraveo <scaraveo@mozilla.com>
Thu, 22 Aug 2013 10:51:30 -0400
changeset 148411 1f447b598a31b723f1e274665bc8aa875403011f
parent 148410 47ae9f576a30aad8b1b7886ca811d684dadba99d
child 148412 e0cc79b0d1e4d0aa24ea4528327d9501f0f531c0
push id2790
push userryanvm@gmail.com
push dateThu, 22 Aug 2013 14:51:41 +0000
treeherdermozilla-beta@e0cc79b0d1e4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmarkh, bajaj
bugs904521
milestone24.0
Bug 904521 - Fix the close of chat windows when new windows are opened. r=markh, a=bajaj
browser/base/content/browser-social.js
browser/modules/Social.jsm
--- a/browser/base/content/browser-social.js
+++ b/browser/base/content/browser-social.js
@@ -83,17 +83,16 @@ SocialUI = {
       switch (topic) {
         case "social:provider-set":
           // Social.provider has changed (possibly to null), update any state
           // which depends on it.
           this._updateActiveUI();
           this._updateMenuItems();
 
           SocialFlyout.unload();
-          SocialChatBar.closeWindows();
           SocialChatBar.update();
           SocialShare.update();
           SocialSidebar.update();
           SocialMark.update();
           SocialToolbar.update();
           SocialMenu.populate();
           break;
         case "social:providers-changed":
@@ -343,24 +342,16 @@ SocialUI = {
     return !!Social.provider;
   },
 
 }
 
 SocialChatBar = {
   init: function() {
   },
-  closeWindows: function() {
-    // close all windows of type Social:Chat
-    let windows = Services.wm.getEnumerator("Social:Chat");
-    while (windows.hasMoreElements()) {
-      let win = windows.getNext();
-      win.close();
-    }
-  },
   get chatbar() {
     return document.getElementById("pinnedchats");
   },
   // Whether the chatbar is available for this window.  Note that in full-screen
   // mode chats are available, but not shown.
   get isAvailable() {
     return SocialUI.enabled && Social.haveLoggedInUser();
   },
--- a/browser/modules/Social.jsm
+++ b/browser/modules/Social.jsm
@@ -112,18 +112,20 @@ this.Social = {
   // Sets the current provider and enables it. Also disables the
   // previously set provider, and notifies observers of the change.
   _setProvider: function (provider) {
     if (this._provider == provider)
       return;
 
     // Disable the previous provider, if any, since we want only one provider to
     // be enabled at once.
-    if (this._provider)
+    if (this._provider) {
       this._provider.enabled = false;
+      this.closeChatWindows();
+    }
 
     this._provider = provider;
 
     if (this._provider) {
       this._provider.enabled = true;
       this._currentProviderPref = this._provider.origin;
     }
     let enabled = !!provider;
@@ -206,16 +208,25 @@ this.Social = {
     } else {
       this.provider = null;
     }
   },
   get enabled() {
     return this.provider != null;
   },
 
+  closeChatWindows: function() {
+    // close all windows of type Social:Chat
+    let windows = Services.wm.getEnumerator("Social:Chat");
+    while (windows.hasMoreElements()) {
+      let win = windows.getNext();
+      win.close();
+    }
+  },
+
   toggle: function Social_toggle() {
     this.enabled = this._disabledForSafeMode ? false : !this.enabled;
     this._disabledForSafeMode = false;
   },
 
   toggleSidebar: function SocialSidebar_toggle() {
     let prefValue = Services.prefs.getBoolPref("social.sidebar.open");
     Services.prefs.setBoolPref("social.sidebar.open", !prefValue);