Bug 1614469 - fix account settings tab is not necessarily going to the right account (when opened from chat accounts dialog). r=mkmelin
authorKhushil Mistry <khushil324@gmail.com>
Thu, 13 Feb 2020 12:25:18 +0200
changeset 28752 23b8d13cf05890273eb37d63c2f7543416773c94
parent 28751 1ed7ac03ae4415239f012e229b61447134c746f3
child 28753 59a1899adf445ba3990004e9310d4934744324a3
push id17020
push usermkmelin@iki.fi
push dateThu, 13 Feb 2020 10:29:45 +0000
treeherdercomm-central@2e35a75dba0a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin
bugs1614469
Bug 1614469 - fix account settings tab is not necessarily going to the right account (when opened from chat accounts dialog). r=mkmelin
mailnews/base/prefs/content/accountUtils.js
--- a/mailnews/base/prefs/content/accountUtils.js
+++ b/mailnews/base/prefs/content/accountUtils.js
@@ -284,26 +284,43 @@ function MsgAccountManager(selectPage, a
     if (!aServer && typeof window.GetDefaultAccountRootFolder === "function") {
       let folder = window.GetDefaultAccountRootFolder();
       if (folder instanceof Ci.nsIMsgFolder) {
         aServer = folder.server;
       }
     }
   }
   let mailWindow = Services.wm.getMostRecentWindow("mail:3pane");
+  let tabmail = mailWindow.document.getElementById("tabmail");
+
+  mailWindow.focus();
+  // If Account settings tab is already open, change the server
+  // and the selected page, reload the tab and switch to the tab.
+  for (let tabInfo of tabmail.tabInfo) {
+    let tab = tabmail.getTabForBrowser(tabInfo.browser);
+    if (
+      tab &&
+      tab.urlbar &&
+      tab.urlbar.textContent == "about:accountsettings"
+    ) {
+      tab.browser.contentDocument.documentElement.server = aServer;
+      tab.browser.contentDocument.documentElement.selectPage = selectPage;
+      tab.browser.contentWindow.onLoad();
+      tabmail.switchToTab(tabInfo);
+      return;
+    }
+  }
+
   let onLoad = function(event, browser) {
     browser.contentDocument.documentElement.server = aServer;
     browser.contentDocument.documentElement.selectPage = selectPage;
   };
-  mailWindow.focus();
-  mailWindow.document.getElementById("tabmail").openTab("contentTab", {
+  tabmail.openTab("contentTab", {
     contentPage: "about:accountsettings",
     clickHandler: "specialTabs.aboutClickHandler(event);",
-    server: aServer,
-    selectPage,
     onLoad,
   });
 }
 
 function loadInboxForNewAccount() {
   // gNewAccountToLoad is set in the final screen of the Account Wizard if a POP account
   // was created, the download messages box is checked, and the wizard was opened from the 3pane
   if (gNewAccountToLoad) {