Bug 759163 - If Account Provisioner tab is restorable on startup, the Account Provisioner dialog should not open. r=bwinton, a=Standard8.
authorMike Conley <mconley@mozilla.com>
Tue, 29 May 2012 14:31:44 -0400
changeset 11361 dfee2c01d8d98070b5ba6f450c1caa0b29a10ae8
parent 11360 5869020d2976e06b3e48b515235eb69fcc882dd6
child 11362 0276e70d4f88f7facbb84f5b354d71004bb84060
push id520
push usermconley@mozilla.com
push dateTue, 29 May 2012 18:33:27 +0000
treeherdercomm-beta@dfee2c01d8d9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbwinton, Standard8
bugs759163
Bug 759163 - If Account Provisioner tab is restorable on startup, the Account Provisioner dialog should not open. r=bwinton, a=Standard8.
mail/base/content/msgMail3PaneWindow.js
mail/components/newmailaccount/content/accountProvisionerTab.js
--- a/mail/base/content/msgMail3PaneWindow.js
+++ b/mail/base/content/msgMail3PaneWindow.js
@@ -326,24 +326,40 @@ const MailPrefObserver = {
   }
 };
 
 /**
  * Called on startup if there are no accounts.
  */
 function AutoConfigWizard(okCallback)
 {
+  let suppressDialogs = false;
+
+  // Try to get the suppression pref that we stashed away in accountProvisionerTab.js.
+  // If it doesn't exist, nsIPrefBranch throws, so we eat it silently and move along.
+  try {
+    suppressDialogs = Services.prefs.getBoolPref("mail.provider.suppress_dialog_on_startup");
+  } catch(e) {};
+
+  if (suppressDialogs) {
+    // 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 100ms is a bit arbitrary, but seems
+    // 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 });
-    }, 100);
+    }, 200);
   }
   else
     NewMailAccount(msgWindow, okCallback);
 }
 
 /**
  * Called on startup to initialize various parts of the main window
  */
@@ -607,16 +623,17 @@ function FindOther3PaneWindow()
 }
 
 /**
  * Called by messenger.xul:onunload, the 3-pane window inside of tabs window.
  *  It's being unloaded!  Right now!
  */
 function OnUnloadMessenger()
 {
+  Services.obs.notifyObservers(window, "mail-unloading-messenger", null);
   accountManager.removeIncomingServerListener(gThreePaneIncomingServerListener);
   gPrefBranch.removeObserver("mail.pane_config.dynamic", MailPrefObserver);
   gPrefBranch.removeObserver("mail.showCondensedAddresses", MailPrefObserver);
 
   sessionStoreManager.unloadingWindow(window);
 
   let tabmail = document.getElementById("tabmail");
   tabmail._teardown();
--- a/mail/components/newmailaccount/content/accountProvisionerTab.js
+++ b/mail/components/newmailaccount/content/accountProvisionerTab.js
@@ -52,16 +52,17 @@ accountProvisionerTabType.openTab = func
  * (for the context of this accountProvisionerTab "aTab"), and then we
  * unregister our observer that was registered in _setMonitoring.
  */
 accountProvisionerTabType.closeTab = function(aTab) {
   specialTabs.contentTabType.closeTab.call(this, aTab);
   this._log.info("Performing account provisioner cleanup");
   this._log.info("Removing httpRequestObserver");
   Services.obs.removeObserver(this._observer, "http-on-examine-response");
+  Services.obs.removeObserver(this.quitObserver, "mail-unloading-messenger", false);
   delete this._observer;
   this._log.info("Account provisioner cleanup is done.");
 }
 
 /**
  * Serialize our tab into something we can restore later.
  */
 accountProvisionerTabType.persistTab = function(aTab) {
@@ -103,16 +104,17 @@ accountProvisionerTabType._setMonitoring
     realName: aRealName,
     email: aEmail,
     searchEngine: aSearchEngine,
   });
 
   // Register our observer
   Services.obs.addObserver(this._observer, "http-on-examine-response",
                            false);
+  Services.obs.addObserver(this.quitObserver, "mail-unloading-messenger", false);
 
   this._log.info("httpRequestObserver wired up.");
 }
 
 /**
  * Click handler for the Account Provisioner tab that allows all links
  * to open within the current content tab, except for those which have
  * their targets set to _blank - these links open in the default browser.
@@ -130,8 +132,28 @@ accountProvisionerTabType.clickHandler =
     if (aEvent.target.target == "_blank") {
       aEvent.preventDefault();
       openLinkExternally(href);
     }
   }
 
   return false;
 }
+
+/**
+ * This observer listens for the mail-unloading-messenger event fired by each
+ * mail window before they unload. If the mail window is the same window that
+ * this accountProvisionerTab belongs to, then we stash a pref so that when
+ * the session restarts, we go straight to the tab, as opposed to showing the
+ * dialog again.
+ */
+accountProvisionerTabType.quitObserver = {
+  observe: function(aSubject, aTopic, aData) {
+    // Make sure we saw the right topic, and that the window that is closing
+    // is the 3pane window that the accountProvisionerTab belongs to.
+    if (aTopic == "mail-unloading-messenger" && (aSubject === window)) {
+      // We quit while the accountProvisionerTab was opened. Set our sneaky
+      // pref so that we suppress the dialog on startup.
+      Services.prefs.setBoolPref("mail.provider.suppress_dialog_on_startup",
+                                 true);
+    }
+  }
+}