Bug 723910 - Fix Account Provisioner failure to react once account has been successfully created. (fallout from bug 680456) r+a=Standard8
authorMike Conley <mconley@mozilla.com>
Fri, 03 Feb 2012 22:30:52 -0500
changeset 10610 6b006b33f66195f64dc47b78d767ebd4cd148fde
parent 10609 ad79480a62c3424267d636b68727936d8323778c
child 10611 315ceda5ffe6fff32ae04bd19210dbd2fa67b2e0
push id402
push userbugzilla@standard8.plus.com
push dateTue, 13 Mar 2012 21:17:18 +0000
treeherdercomm-beta@d080a8ebf16a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs723910, 680456
Bug 723910 - Fix Account Provisioner failure to react once account has been successfully created. (fallout from bug 680456) r+a=Standard8
mail/base/content/messenger.xul
mail/base/content/msgMail3PaneWindow.js
mail/components/newmailaccount/content/accountProvisioner.js
mail/components/newmailaccount/content/accountProvisionerTab.js
mail/components/newmailaccount/jar.mn
--- a/mail/base/content/messenger.xul
+++ b/mail/base/content/messenger.xul
@@ -112,16 +112,18 @@
 <script type="application/javascript" src="chrome://messenger/content/widgetglue.js"/>
 <script type="application/javascript" src="chrome://messenger/content/commandglue.js"/>
 <script type="application/javascript" src="chrome://messenger/content/shareglue.js"/>
 <script type="application/javascript" src="chrome://messenger/content/msgViewNavigation.js"/>
 <script type="application/javascript" src="chrome://messenger/content/mailWindow.js"/>
 <script type="application/javascript" src="chrome://messenger/content/selectionsummaries.js"/>
 <script type="application/javascript" src="chrome://messenger/content/msgMail3PaneWindow.js"/>
 <script type="application/javascript" src="chrome://messenger/content/specialTabs.js"/>
+<!-- accountProvisionerTab.js relies on code from specialTabs.js, and so much be loaded after it. -->
+<script type="application/javascript" src="chrome://messenger/content/newmailaccount/accountProvisionerTab.js"/>
 <script type="application/javascript" src="chrome://messenger/content/glodaFacetTab.js"/>
 <script type="application/javascript" src="chrome://messenger/content/searchBar.js"/>
 <script type="application/javascript" src="chrome://messenger/content/mail3PaneWindowCommands.js"/>
 <script type="application/javascript" src="chrome://global/content/contentAreaUtils.js"/>
 <script type="application/javascript" src="chrome://messenger/content/nsContextMenu.js"/>
 <script type="application/javascript" src="chrome://messenger/content/mailContextMenus.js"/>
 <script type="application/javascript" src="chrome://messenger/content/accountUtils.js"/>
 <script type="application/javascript" src="chrome://messenger/content/folderPane.js"/>
--- a/mail/base/content/msgMail3PaneWindow.js
+++ b/mail/base/content/msgMail3PaneWindow.js
@@ -424,16 +424,17 @@ function OnLoadMessenger()
                                     LightWeightThemeWebInstaller, false, true);
   }
 
   Services.obs.addObserver(gPluginHandler.pluginCrashed, "plugin-crashed", false);
 
   // This also registers the contentTabType ("contentTab")
   specialTabs.openSpecialTabsOnStartup();
   tabmail.registerTabType(webSearchTabType);
+  tabmail.registerTabType(accountProvisionerTabType);
 
   // 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);
 }
--- a/mail/components/newmailaccount/content/accountProvisioner.js
+++ b/mail/components/newmailaccount/content/accountProvisioner.js
@@ -454,84 +454,26 @@ var EmailAccountProvisioner = {
 
     gLog.info("Opening up a contentTab with the order form.");
     // Then open a content tab.
     let mail3Pane = Cc["@mozilla.org/appshell/window-mediator;1"]
           .getService(Ci.nsIWindowMediator)
           .getMostRecentWindow("mail:3pane");
 
     let tabmail = mail3Pane.document.getElementById("tabmail");
-    tabmail.openTab("contentTab", {
+    tabmail.openTab("accountProvisionerTab", {
       contentPage: url,
+      realName: firstName + " " + lastName,
+      email: email,
+      searchEngine: provider.search_engine,
       onLoad: function (aEvent, aBrowser) {
-        // There are a few things we want to do once the tab content loads:
-        // 1.  We want to register an observer to watch for HTTP requests
-        //     where the contentType contains text/xml
-        // 2.  We want to register a tab monitor to watch for when the
-        //     tab we're opening closes, so that it can clean up the
-        //     observer.
-
-        // At this point, when onLoad is called, we run into some scoping
-        // issues.  Services and gLog are no longer in scope, so we have to
-        // redefine them.
-        Components.utils.import("resource://gre/modules/Services.jsm");
-        Components.utils.import("resource:///modules/gloda/log4moz.js");
-        let gLog = Log4Moz.getConfiguredLogger("mail.provider");
-
-        // We'll construct our special observer (defined in urlListener.js)
-        // that will watch for requests where the contentType contains
-        // text/xml.
-        let observer = new mail3Pane.httpRequestObserver(aBrowser, {
-          realName: firstName + " " + lastName,
-          email: email,
-          searchEngine: provider.search_engine,
-        });
-
-        // Register our observer
-        Services.obs.addObserver(observer, "http-on-examine-response",
-                                 false);
-        gLog.info("httpRequestObserver wired up.");
-
-        // The provisionerTabMonitor lets us clean up when the tab closes.
-        // This tab closure can occur from a variety of events (successful
-        // account transaction, user closes the tab, user quits Thunderbird,
-        // etc), and so the tab monitor allows us to catch all of those
-        // cases.
-        let provisionerTabMonitor = {
-          monitorName: "accountProvisionerMonitor",
-          onTabTitleChanged: function() {},
-          onTabSwitched: function(aTab, aOldTab) {},
-          onTabOpened: function(aTab, aIsFirstTab, aWasCurrentTab) {},
-          onTabClosing: function(aTab) {
-            if (aTab.browser === aBrowser) {
-              // Once again, due to scoping issues, we have to re-import
-              // Services.
-              Components.utils.import("resource://gre/modules/Services.jsm");
-              gLog.info("Performing account provisioner cleanup");
-              gLog.info("Unregistering tab monitor");
-              tabmail.unregisterTabMonitor(provisionerTabMonitor);
-              gLog.info("Removing httpRequestObserver");
-              Services.obs.removeObserver(observer, "http-on-examine-response");
-              gLog.info("Account provisioner cleanup is done.");
-            }
-          },
-          onTabPersist: function(aTab) {},
-          onTabRestored: function(aTab, aState, aIsFirstTab) {},
-        }
-
-        // Register the monitor.
-        tabmail.registerTabMonitor(provisionerTabMonitor);
-
-        // Close the Account Provisioner window once the page
-        // has loaded.
-        gLog.info("Handing off to the contentTab, and closing Email "
-                  + "Account Provisioner.")
         window.close();
       },
     });
+
     // Wait for the handler to close us.
     EmailAccountProvisioner.spinning(true);
     EmailAccountProvisioner.searchEnabled(false);
     $("#notifications").children().not(".spinner").hide();
   },
 
   /**
    * Attempt to fetch the provider list from the server.  If it fails,
new file mode 100644
--- /dev/null
+++ b/mail/components/newmailaccount/content/accountProvisionerTab.js
@@ -0,0 +1,78 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+let Cc = Components.classes;
+let Ci = Components.interfaces;
+let Cu = Components.utils;
+
+Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource:///modules/gloda/log4moz.js");
+
+/**
+ * A content tab for the account provisioner.  We use Javascript-y magic to
+ * "subclass" specialTabs.contentTabType, and then override the appropriate
+ * members.
+ */
+let accountProvisionerTabType = Object.create(specialTabs.contentTabType, {
+  name: {value: "accountProvisionerTab"},
+  modes: {value: {
+    accountProvisionerTab: {
+      type: "accountProvisionerTab",
+      maxTabs: 1,
+    }
+  }},
+  _log: {value: Log4Moz.getConfiguredLogger("mail.provider")},
+});
+
+/**
+ * Here, we're overriding openTab - first we call the openTab of contentTab
+ * (for the context of this accountProvisionerTab "aTab") and then passing
+ * special arguments "realName", "email" and "searchEngine" from the caller
+ * of openTab, and passing those to our _setMonitoring function.
+ */
+accountProvisionerTabType.openTab = function(aTab, aArgs) {
+  specialTabs.contentTabType.openTab.call(this, aTab, aArgs);
+
+  this._setMonitoring(aTab.browser, aArgs.realName, aArgs.email,
+                      aArgs.searchEngine);
+}
+
+/**
+ * We're overriding closeTab - first, we call the closeTab of contentTab,
+ * (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");
+  this._log.info("Account provisioner cleanup is done.");
+}
+
+/**
+ * This function registers an observer to watch for HTTP requests where the
+ * contentType contains text/xml.
+ */
+accountProvisionerTabType._setMonitoring = function(aBrowser, aRealName,
+                                                    aEmail, aSearchEngine) {
+  let mail3Pane = Cc["@mozilla.org/appshell/window-mediator;1"]
+        .getService(Ci.nsIWindowMediator)
+        .getMostRecentWindow("mail:3pane");
+
+  // We'll construct our special observer (defined in urlListener.js)
+  // that will watch for requests where the contentType contains
+  // text/xml.
+  this._observer = new mail3Pane.httpRequestObserver(aBrowser, {
+    realName: aRealName,
+    email: aEmail,
+    searchEngine: aSearchEngine,
+  });
+
+  // Register our observer
+  Services.obs.addObserver(this._observer, "http-on-examine-response",
+                           false);
+
+  this._log.info("httpRequestObserver wired up.");
+}
--- a/mail/components/newmailaccount/jar.mn
+++ b/mail/components/newmailaccount/jar.mn
@@ -1,6 +1,7 @@
 messenger.jar:
+    content/messenger/newmailaccount/accountProvisionerTab.js   (content/accountProvisionerTab.js)
     content/messenger/newmailaccount/accountProvisioner.xhtml   (content/accountProvisioner.xhtml)
     content/messenger/newmailaccount/accountProvisioner.js      (content/accountProvisioner.js)
     content/messenger/newmailaccount/uriListener.js             (content/uriListener.js)
     content/messenger/newmailaccount/jquery.scrollTo.js         (content/jquery.scrollTo.js)
     content/messenger/newmailaccount/jquery.tmpl.js             (content/jquery.tmpl.js)