Bug 1112552 - Clean up global-scope pollution from browser-fxaccounts.js. r=dao
☠☠ backed out by 0aa625346f89 ☠ ☠
authorabdelrhman <codo.abdo@gmail.com>
Mon, 22 Dec 2014 13:28:29 +0100
changeset 220900 1dd103323b7c5aa74170aafb9bba902ef42a7e2c
parent 220854 93b79187eeaf13cba9eb52368da92f8624b4b4bf
child 220901 b0940fe618e405629c5ffdee047ee95bc296d545
push id28003
push userryanvm@gmail.com
push dateMon, 22 Dec 2014 22:44:16 +0000
treeherdermozilla-central@d5167dc0ded3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdao
bugs1112552
milestone37.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1112552 - Clean up global-scope pollution from browser-fxaccounts.js. r=dao
browser/base/content/browser-fxaccounts.js
--- a/browser/base/content/browser-fxaccounts.js
+++ b/browser/base/content/browser-fxaccounts.js
@@ -1,24 +1,17 @@
 # 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/.
 
-XPCOMUtils.defineLazyGetter(this, "FxAccountsCommon", function () {
-  return Cu.import("resource://gre/modules/FxAccountsCommon.js", {});
-});
+let gFxAccounts = {
 
-XPCOMUtils.defineLazyModuleGetter(this, "fxaMigrator",
-  "resource://services-sync/FxaMigrator.jsm");
-
-const PREF_SYNC_START_DOORHANGER = "services.sync.ui.showSyncStartDoorhanger";
-const DOORHANGER_ACTIVATE_DELAY_MS = 5000;
-const SYNC_MIGRATION_NOTIFICATION_TITLE = "fxa-migration";
-
-let gFxAccounts = {
+  PREF_SYNC_START_DOORHANGER: "services.sync.ui.showSyncStartDoorhanger",
+  DOORHANGER_ACTIVATE_DELAY_MS: 5000,
+  SYNC_MIGRATION_NOTIFICATION_TITLE: "fxa-migration",
 
   _initialized: false,
   _inCustomizationMode: false,
 
   get weave() {
     delete this.weave;
     return this.weave = Cc["@mozilla.org/weave/service;1"]
                           .getService(Ci.nsISupports)
@@ -29,18 +22,18 @@ let gFxAccounts = {
     // Do all this dance to lazy-load FxAccountsCommon.
     delete this.topics;
     return this.topics = [
       "weave:service:ready",
       "weave:service:sync:start",
       "weave:service:login:error",
       "weave:service:setup-complete",
       "fxa-migration:state-changed",
-      FxAccountsCommon.ONVERIFIED_NOTIFICATION,
-      FxAccountsCommon.ONLOGOUT_NOTIFICATION
+      this.FxAccountsCommon.ONVERIFIED_NOTIFICATION,
+      this.FxAccountsCommon.ONLOGOUT_NOTIFICATION
     ];
   },
 
   get button() {
     delete this.button;
     return this.button = document.getElementById("PanelUI-fxa-status");
   },
 
@@ -103,18 +96,18 @@ let gFxAccounts = {
       Services.obs.removeObserver(this, topic);
     }
 
     this._initialized = false;
   },
 
   observe: function (subject, topic, data) {
     switch (topic) {
-      case FxAccountsCommon.ONVERIFIED_NOTIFICATION:
-        Services.prefs.setBoolPref(PREF_SYNC_START_DOORHANGER, true);
+      case this.FxAccountsCommon.ONVERIFIED_NOTIFICATION:
+        Services.prefs.setBoolPref(this.PREF_SYNC_START_DOORHANGER, true);
         break;
       case "weave:service:sync:start":
         this.onSyncStart();
         break;
       case "fxa-migration:state-changed":
         this.onMigrationStateChanged(data, subject);
         break;
       default:
@@ -126,21 +119,21 @@ let gFxAccounts = {
   onSyncStart: function () {
     if (!this.isActiveWindow) {
       return;
     }
 
     let showDoorhanger = false;
 
     try {
-      showDoorhanger = Services.prefs.getBoolPref(PREF_SYNC_START_DOORHANGER);
+      showDoorhanger = Services.prefs.getBoolPref(this.PREF_SYNC_START_DOORHANGER);
     } catch (e) { /* The pref might not exist. */ }
 
     if (showDoorhanger) {
-      Services.prefs.clearUserPref(PREF_SYNC_START_DOORHANGER);
+      Services.prefs.clearUserPref(this.PREF_SYNC_START_DOORHANGER);
       this.showSyncStartedDoorhanger();
     }
   },
 
   onMigrationStateChanged: function (newState, email) {
     this._migrationInfo = !newState ? null : {
       state: newState,
       email: email ? email.QueryInterface(Ci.nsISupportsString).data : null,
@@ -150,17 +143,17 @@ let gFxAccounts = {
 
   handleEvent: function (event) {
     if (event.type == "activate") {
       // Our window might have been in the background while we received the
       // sync:start notification. If still needed, show the doorhanger after
       // a short delay. Without this delay the doorhanger would not show up
       // or with a too small delay show up while we're still animating the
       // window.
-      setTimeout(() => this.onSyncStart(), DOORHANGER_ACTIVATE_DELAY_MS);
+      setTimeout(() => this.onSyncStart(), this.DOORHANGER_ACTIVATE_DELAY_MS);
     } else {
       this._inCustomizationMode = event.type == "customizationstarting";
       this.updateAppMenuItem();
     }
   },
 
   showDoorhanger: function (id) {
     let panel = document.getElementById(id);
@@ -246,94 +239,94 @@ let gFxAccounts = {
       doUpdate(null);
     });
   },
 
   updateAppMenuItemForMigration: Task.async(function* () {
     let status = null;
     let label = null;
     switch (this._migrationInfo.state) {
-      case fxaMigrator.STATE_USER_FXA:
+      case this.fxaMigrator.STATE_USER_FXA:
         status = "migrate-signup";
         label = this.strings.formatStringFromName("needUserShort",
           [this.button.getAttribute("fxabrandname")], 1);
         break;
-      case fxaMigrator.STATE_USER_FXA_VERIFIED:
+      case this.fxaMigrator.STATE_USER_FXA_VERIFIED:
         status = "migrate-verify";
         label = this.strings.formatStringFromName("needVerifiedUserShort",
                                                   [this._migrationInfo.email],
                                                   1);
         break;
     }
     this.button.label = label;
     this.button.hidden = false;
     this.button.setAttribute("fxastatus", status);
   }),
 
   updateMigrationNotification: Task.async(function* () {
     if (!this._migrationInfo) {
-      Weave.Notifications.removeAll(SYNC_MIGRATION_NOTIFICATION_TITLE);
+      Weave.Notifications.removeAll(this.SYNC_MIGRATION_NOTIFICATION_TITLE);
       return;
     }
     if (gBrowser.currentURI.spec.split("?")[0] == "about:accounts") {
       // If the current tab is about:accounts, assume the user just completed a
       // migration step and don't bother them with a redundant notification.
       return;
     }
     let note = null;
     switch (this._migrationInfo.state) {
-      case fxaMigrator.STATE_USER_FXA: {
+      case this.fxaMigrator.STATE_USER_FXA: {
         let msg = this.strings.GetStringFromName("needUserLong");
         let upgradeLabel =
           this.strings.GetStringFromName("upgradeToFxA.label");
         let upgradeAccessKey =
           this.strings.GetStringFromName("upgradeToFxA.accessKey");
         note = new Weave.Notification(
           undefined, msg, undefined, Weave.Notifications.PRIORITY_WARNING, [
             new Weave.NotificationButton(upgradeLabel, upgradeAccessKey, () => {
-              fxaMigrator.createFxAccount(window);
+              this.fxaMigrator.createFxAccount(window);
             }),
           ]
         );
         break;
       }
-      case fxaMigrator.STATE_USER_FXA_VERIFIED: {
+      case this.fxaMigrator.STATE_USER_FXA_VERIFIED: {
         let msg =
           this.strings.formatStringFromName("needVerifiedUserLong",
                                             [this._migrationInfo.email], 1);
         let resendLabel =
           this.strings.GetStringFromName("resendVerificationEmail.label");
         let resendAccessKey =
           this.strings.GetStringFromName("resendVerificationEmail.accessKey");
         note = new Weave.Notification(
           undefined, msg, undefined, Weave.Notifications.PRIORITY_INFO, [
             new Weave.NotificationButton(resendLabel, resendAccessKey, () => {
-              fxaMigrator.resendVerificationMail();
+              this.fxaMigrator.resendVerificationMail();
             }),
           ]
         );
         break;
       }
     }
-    note.title = SYNC_MIGRATION_NOTIFICATION_TITLE;
+    note.title = this.SYNC_MIGRATION_NOTIFICATION_TITLE;
     Weave.Notifications.replaceTitle(note);
   }),
 
   onMenuPanelCommand: function (event) {
     let button = event.originalTarget;
 
     switch (button.getAttribute("fxastatus")) {
     case "signedin":
       this.openPreferences();
       break;
     case "error":
       this.openSignInAgainPage("menupanel");
       break;
     case "migrate-signup":
-      fxaMigrator.createFxAccount(window);
+      this.fxaMigrator.createFxAccount(window);
       break;
     case "migrate-verify":
       // Instead of using the migrator module directly here the UX calls for
       // us to open prefs which has a "resend" button.
       this.openPreferences();
       break;
     default:
       this.openAccountsPage(null, { entryPoint: "menupanel" });
@@ -369,8 +362,15 @@ let gFxAccounts = {
       replaceQueryString: true
     });
   },
 
   openSignInAgainPage: function (entryPoint) {
     this.openAccountsPage("reauth", { entryPoint: entryPoint });
   },
 };
+
+XPCOMUtils.defineLazyGetter(gFxAccounts, "FxAccountsCommon", function () {
+  return Cu.import("resource://gre/modules/FxAccountsCommon.js", {});
+});
+
+XPCOMUtils.defineLazyModuleGetter(gFxAccounts, "fxaMigrator",
+  "resource://services-sync/FxaMigrator.jsm");