Bug 759758 - Thunderbird sometimes switches back to inbox tab after opening the Account Provisioner tab. f=bwinton,squib,bienvenu, r=bienvenu.
authorMike Conley <mconley@mozilla.com>
Mon, 18 Jun 2012 10:37:31 -0400
changeset 10459 cff415a502cb6bdea2eb994d00741ea9426a1665
parent 10458 d4e85c946f4c1a427e8f9fcd1365e2b66213fd8f
child 10460 307193116eff79f395125562f6a6404898b12b2c
push id7911
push usermconley@mozilla.com
push dateMon, 18 Jun 2012 14:37:53 +0000
treeherdercomm-central@cff415a502cb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbienvenu
bugs759758
Bug 759758 - Thunderbird sometimes switches back to inbox tab after opening the Account Provisioner tab. f=bwinton,squib,bienvenu, r=bienvenu.
mail/base/content/msgMail3PaneWindow.js
mail/components/newmailaccount/content/accountProvisioner.js
mailnews/base/prefs/content/accountUtils.js
--- a/mail/base/content/msgMail3PaneWindow.js
+++ b/mail/base/content/msgMail3PaneWindow.js
@@ -304,23 +304,26 @@ function AutoConfigWizard(okCallback)
     // Looks like we were in the middle of filling out an account form. We
     // won't display the dialogs in that case.
     Services.prefs.clearUserPref("mail.provider.suppress_dialog_on_startup");
     okCallback();
     return;
   }
 
   if (gPrefBranch.getBoolPref("mail.provider.enabled")) {
-    // We need to let the event loop pump a little so that the 3pane finishes
-    // opening - so we use setTimeout. The 200ms is a bit arbitrary, but seems
-    // to be enough time to let the 3pane do it's thing, and not pull focus
-    // when the Account Provisioner modal window closes.
-    setTimeout(function() {
-      NewMailAccountProvisioner(msgWindow, { okCallback: okCallback });
-    }, 200);
+    Services.obs.addObserver({
+      observe: function(aSubject, aTopic, aData) {
+        if (aTopic == "mail-tabs-session-restored" && aSubject === window) {
+          // We're done here, unregister this observer.
+          Services.obs.removeObserver(this, "mail-tabs-session-restored");
+          NewMailAccountProvisioner(msgWindow, { okCallback: null });
+        }
+      }
+    }, "mail-tabs-session-restored", false);
+    okCallback();
   }
   else
     NewMailAccount(msgWindow, okCallback);
 }
 
 /**
  * Called on startup to initialize various parts of the main window
  */
@@ -380,21 +383,16 @@ function OnLoadMessenger()
     // glodaFacetTab* in glodaFacetTab.js
     tabmail.registerTabType(glodaFacetTabType);
     QuickFilterBarMuxer._init();
     tabmail.registerTabMonitor(GlodaSearchBoxTabMonitor);
     tabmail.registerTabMonitor(statusMessageCountsMonitor);
     tabmail.openFirstTab();
   }
 
-  // verifyAccounts returns true if the callback won't be called
-  // We also don't want the account wizard to open if any sort of account exists
-  if (verifyAccounts(LoadPostAccountWizard, false, AutoConfigWizard))
-    LoadPostAccountWizard();
-
   // Install the light-weight theme handlers
   let panelcontainer = document.getElementById("tabpanelcontainer");
   if (panelcontainer) {
     panelcontainer.addEventListener("InstallBrowserTheme",
                                     LightWeightThemeWebInstaller, false, true);
     panelcontainer.addEventListener("PreviewBrowserTheme",
                                     LightWeightThemeWebInstaller, false, true);
     panelcontainer.addEventListener("ResetBrowserThemePreview",
@@ -403,16 +401,21 @@ function OnLoadMessenger()
 
   Services.obs.addObserver(gPluginHandler.pluginCrashed, "plugin-crashed", false);
 
   // This also registers the contentTabType ("contentTab")
   specialTabs.openSpecialTabsOnStartup();
   webSearchTabType.initialize();
   tabmail.registerTabType(accountProvisionerTabType);
 
+  // verifyAccounts returns true if the callback won't be called
+  // We also don't want the account wizard to open if any sort of account exists
+  if (verifyAccounts(LoadPostAccountWizard, false, AutoConfigWizard))
+    LoadPostAccountWizard();
+
   // Set up the summary frame manager to handle loading pages in the
   // multi-message pane
   gSummaryFrameManager = new SummaryFrameManager(
                          document.getElementById("multimessage"));
 
   window.addEventListener("AppCommand", HandleAppCommandEvent, true);
 }
 
@@ -425,16 +428,17 @@ function LoadPostAccountWizard()
   MigrateAttachmentDownloadStore();
   MigrateJunkMailSettings();
   MigrateFolderViews();
   MigrateOpenMessageBehavior();
   Components.utils.import("resource:///modules/mailMigrator.js");
   MailMigrator.migratePostAccountWizard();
 
   accountManager.setSpecialFolders();
+
   try {
     accountManager.loadVirtualFolders();
   } catch (e) {Components.utils.reportError(e);}
   accountManager.addIncomingServerListener(gThreePaneIncomingServerListener);
 
   gPhishingDetector.init();
 
   AddToSession();
@@ -650,17 +654,17 @@ function atStartupRestoreTabs(aDontResto
   if (state) {
     let tabsState = state.tabs;
     let tabmail = document.getElementById("tabmail");
     tabmail.restoreTabs(tabsState, aDontRestoreFirstTab);
   }
 
   // it's now safe to load extra Tabs.
   setTimeout(loadExtraTabs, 0);
-
+  Services.obs.notifyObservers(window, "mail-tabs-session-restored", null);
   return state ? true : false;
 }
 
 /**
  * Loads and restores tabs upon opening a window by evaluating window.arguments[1].
  *
  * The type of the object is specified by it's action property. It can be
  * either "restore" or "open". "restore" invokes tabmail.restoreTab() for each
@@ -741,22 +745,24 @@ function loadStartMsgHdr(aStartMsgHdr)
 function loadStartFolder(initialUri)
 {
     var defaultServer = null;
     var startFolder;
     var isLoginAtStartUpEnabled = false;
 
     // If a URI was explicitly specified, we'll just clobber the default tab
     let loadFolder = !atStartupRestoreTabs(!!initialUri);
+
     if (initialUri)
       loadFolder = true;
 
     //First get default account
     try
     {
+
         if(initialUri)
             startFolder = GetMsgFolderFromUri(initialUri);
         else
         {
             try {
                 var defaultAccount = accountManager.defaultAccount;
             } catch (x) {
                 return; // exception caused by no default account, ignore it.
--- a/mail/components/newmailaccount/content/accountProvisioner.js
+++ b/mail/components/newmailaccount/content/accountProvisioner.js
@@ -73,17 +73,16 @@ var EmailAccountProvisioner = {
   _storage: null,
   providers: {},
   _someProvidersChecked: false,
   // These get passed in when creating the Account Provisioner window.
   NewMailAccount: window.arguments[0].NewMailAccount,
   NewComposeMessage: window.arguments[0].NewComposeMessage,
   openAddonsMgr: window.arguments[0].openAddonsMgr,
   msgWindow: window.arguments[0].msgWindow,
-  okCallback: window.arguments[0].okCallback,
 
   get someProvidersChecked() {
     return this._someProvidersChecked;
   },
 
   set someProvidersChecked(aVal) {
     this._someProvidersChecked = aVal;
     EmailAccountProvisioner.onSearchInputOrProvidersChanged();
@@ -262,28 +261,21 @@ var EmailAccountProvisioner = {
     // initial enabled/disabled state of the search button.
     EmailAccountProvisioner.onSearchInputOrProvidersChanged();
 
     $("#window").css("height", window.innerHeight - 1);
 
     $("button.existing").click(function() {
       EmailAccountProvisioner.saveName();
       EmailAccountProvisioner.NewMailAccount(EmailAccountProvisioner.msgWindow,
-                                             EmailAccountProvisioner.okCallback,
+                                             null,
                                              window.arguments[0]);
-      // Set the callback to null, so that we don't call it.
-      EmailAccountProvisioner.okCallback = null;
       window.close();
     });
 
-    $(window).unload(function() {
-      if (EmailAccountProvisioner.okCallback)
-        EmailAccountProvisioner.okCallback();
-    });
-
     // Handle Ctrl-W and Esc
     $(window).keypress(function(event) {
       if ((event.which == "119" && isAccel(event))
           || event.keyCode == 27) {
         window.close();
       }
     });
 
--- a/mailnews/base/prefs/content/accountUtils.js
+++ b/mailnews/base/prefs/content/accountUtils.js
@@ -96,17 +96,16 @@ function verifyAccounts(wizardCallback, 
 
         var accounts = am.accounts;
 
         // as long as we have some accounts, we're fine.
         var accountCount = accounts.Count();
         var invalidAccounts = getInvalidAccounts(accounts);
         if (invalidAccounts.length > 0 && invalidAccounts.length == accountCount) {
             prefillAccount = invalidAccounts[0];
-        } else {
         }
 
         // if there are no accounts, or all accounts are "invalid"
         // then kick off the account migration. Or if this is a new (to Mozilla) profile.
         // MCD can set up accounts without the profile being used yet
         if (newProfile) {
           // check if MCD is configured. If not, say this is not a new profile
           // so that we don't accidentally remigrate non MCD profiles.