Bug 1325464 - Use ES6 method syntax for sync.js. r=mattn draft
authorJared Wein <jwein@mozilla.com>
Thu, 22 Dec 2016 15:57:40 -0500
changeset 454592 7585d3ef8773045438813497be74479e0ca0cb61
parent 454591 217439d9312810a398ba11b4a69c8331cdc2fb72
child 454593 5bb3eb92249ed845a03cb95f2af52c9b0bfeafa7
push id39985
push userbmo:jaws@mozilla.com
push dateThu, 29 Dec 2016 19:31:36 +0000
reviewersmattn
bugs1325464
milestone53.0a1
Bug 1325464 - Use ES6 method syntax for sync.js. r=mattn MozReview-Commit-ID: 1Kjus1IWTaW
browser/components/preferences/in-content/sync.js
--- a/browser/components/preferences/in-content/sync.js
+++ b/browser/components/preferences/in-content/sync.js
@@ -37,24 +37,24 @@ var gSyncPane = {
   set page(val) {
     document.getElementById("weavePrefsDeck").selectedIndex = val;
   },
 
   get _usingCustomServer() {
     return Weave.Svc.Prefs.isSet("serverURL");
   },
 
-  needsUpdate: function() {
+  needsUpdate() {
     this.page = PAGE_NEEDS_UPDATE;
     let label = document.getElementById("loginError");
     label.textContent = Weave.Utils.getErrorString(Weave.Status.login);
     label.className = "error";
   },
 
-  init: function() {
+  init() {
     this._setupEventListeners();
 
     // If the Service hasn't finished initializing, wait for it.
     let xps = Components.classes["@mozilla.org/weave/service;1"]
                                 .getService(Components.interfaces.nsISupports)
                                 .wrappedJSObject;
 
     if (xps.ready) {
@@ -80,17 +80,17 @@ var gSyncPane = {
     }.bind(this);
 
     Services.obs.addObserver(onReady, "weave:service:ready", false);
     window.addEventListener("unload", onUnload, false);
 
     xps.ensureLoaded();
   },
 
-  _showLoadPage: function(xps) {
+  _showLoadPage(xps) {
     let username;
     try {
       username = Services.prefs.getCharPref("services.sync.username");
     } catch (e) {}
     if (!username) {
       this.page = FXA_PAGE_LOGGED_OUT;
     } else if (xps.fxAccountsEnabled) {
       // Use cached values while we wait for the up-to-date values
@@ -104,17 +104,17 @@ var gSyncPane = {
       document.getElementById("fxaEmailAddress1").textContent = username;
       this._populateComputerName(cachedComputerName);
       this.page = FXA_PAGE_LOGGED_IN;
     } else { // Old Sync
       this.page = PAGE_HAS_ACCOUNT;
     }
   },
 
-  _init: function() {
+  _init() {
     let topics = ["weave:service:login:error",
                   "weave:service:login:finish",
                   "weave:service:start-over:finish",
                   "weave:service:setup-complete",
                   "weave:service:logout:finish",
                   FxAccountsCommon.ONVERIFIED_NOTIFICATION,
                   FxAccountsCommon.ONLOGIN_NOTIFICATION,
                   FxAccountsCommon.ON_PROFILE_CHANGE_NOTIFICATION,
@@ -156,51 +156,51 @@ var gSyncPane = {
       document.getElementById("verifiedManage").setAttribute("href", accountsManageURI);
     });
 
     this.updateWeavePrefs();
 
     this._initProfileImageUI();
   },
 
-  _toggleComputerNameControls: function(editMode) {
+  _toggleComputerNameControls(editMode) {
     let textbox = document.getElementById("fxaSyncComputerName");
     textbox.disabled = !editMode;
     document.getElementById("fxaChangeDeviceName").hidden = editMode;
     document.getElementById("fxaCancelChangeDeviceName").hidden = !editMode;
     document.getElementById("fxaSaveChangeDeviceName").hidden = !editMode;
   },
 
-  _focusComputerNameTextbox: function() {
+  _focusComputerNameTextbox() {
     let textbox = document.getElementById("fxaSyncComputerName");
     let valLength = textbox.value.length;
     textbox.focus();
     textbox.setSelectionRange(valLength, valLength);
   },
 
-  _blurComputerNameTextbox: function() {
+  _blurComputerNameTextbox() {
     document.getElementById("fxaSyncComputerName").blur();
   },
 
-  _focusAfterComputerNameTextbox: function() {
+  _focusAfterComputerNameTextbox() {
     // Focus the most appropriate element that's *not* the "computer name" box.
     Services.focus.moveFocus(window,
                              document.getElementById("fxaSyncComputerName"),
                              Services.focus.MOVEFOCUS_FORWARD, 0);
   },
 
-  _updateComputerNameValue: function(save) {
+  _updateComputerNameValue(save) {
     if (save) {
       let textbox = document.getElementById("fxaSyncComputerName");
       Weave.Service.clientsEngine.localName = textbox.value;
     }
     this._populateComputerName(Weave.Service.clientsEngine.localName);
   },
 
-  _setupEventListeners: function() {
+  _setupEventListeners() {
     function setEventListener(aId, aEventType, aCallback)
     {
       document.getElementById(aId)
               .addEventListener(aEventType, aCallback.bind(gSyncPane));
     }
 
     setEventListener("noAccountSetup", "click", function(aEvent) {
       aEvent.stopPropagation();
@@ -289,25 +289,25 @@ var gSyncPane = {
       if (e.keyCode == KeyEvent.DOM_VK_RETURN) {
         document.getElementById("fxaSaveChangeDeviceName").click();
       } else if (e.keyCode == KeyEvent.DOM_VK_ESCAPE) {
         document.getElementById("fxaCancelChangeDeviceName").click();
       }
     });
   },
 
-  _initProfileImageUI: function() {
+  _initProfileImageUI() {
     try {
       if (Services.prefs.getBoolPref("identity.fxaccounts.profile_image.enabled")) {
         document.getElementById("fxaProfileImage").hidden = false;
       }
     } catch (e) { }
   },
 
-  updateWeavePrefs: function() {
+  updateWeavePrefs() {
     let service = Components.classes["@mozilla.org/weave/service;1"]
                   .getService(Components.interfaces.nsISupports)
                   .wrappedJSObject;
     // service.fxAccountsEnabled is false iff sync is already configured for
     // the legacy provider.
     if (service.fxAccountsEnabled) {
       let displayNameLabel = document.getElementById("fxaDisplayName");
       let fxaEmailAddress1Label = document.getElementById("fxaEmailAddress1");
@@ -422,17 +422,17 @@ var gSyncPane = {
     } else {
       this.page = PAGE_HAS_ACCOUNT;
       document.getElementById("accountName").textContent = Weave.Service.identity.account;
       document.getElementById("syncComputerName").value = Weave.Service.clientsEngine.localName;
       document.getElementById("tosPP-normal").hidden = this._usingCustomServer;
     }
   },
 
-  startOver: function(showDialog) {
+  startOver(showDialog) {
     if (showDialog) {
       let flags = Services.prompt.BUTTON_POS_0 * Services.prompt.BUTTON_TITLE_IS_STRING +
                   Services.prompt.BUTTON_POS_1 * Services.prompt.BUTTON_TITLE_CANCEL +
                   Services.prompt.BUTTON_POS_1_DEFAULT;
       let buttonChoice =
         Services.prompt.confirmEx(window,
                                   this._stringBundle.GetStringFromName("syncUnlink.title"),
                                   this._stringBundle.GetStringFromName("syncUnlink.label"),
@@ -444,36 +444,36 @@ var gSyncPane = {
       if (buttonChoice == 1)
         return;
     }
 
     Weave.Service.startOver();
     this.updateWeavePrefs();
   },
 
-  updatePass: function() {
+  updatePass() {
     if (Weave.Status.login == Weave.LOGIN_FAILED_LOGIN_REJECTED)
       gSyncUtils.changePassword();
     else
       gSyncUtils.updatePassphrase();
   },
 
-  resetPass: function() {
+  resetPass() {
     if (Weave.Status.login == Weave.LOGIN_FAILED_LOGIN_REJECTED)
       gSyncUtils.resetPassword();
     else
       gSyncUtils.resetPassphrase();
   },
 
-  _getEntryPoint: function() {
+  _getEntryPoint() {
     let params = new URLSearchParams(document.URL.split("#")[0].split("?")[1] || "");
     return params.get("entrypoint") || "preferences";
   },
 
-  _openAboutAccounts: function(action) {
+  _openAboutAccounts(action) {
     let entryPoint = this._getEntryPoint();
     let params = new URLSearchParams();
     if (action) {
       params.set("action", action);
     }
     params.set("entrypoint", entryPoint);
 
     this.replaceTabWithUrl("about:accounts?" + params);
@@ -483,17 +483,17 @@ var gSyncPane = {
    * Invoke the Sync setup wizard.
    *
    * @param wizardType
    *        Indicates type of wizard to launch:
    *          null    -- regular set up wizard
    *          "pair"  -- pair a device first
    *          "reset" -- reset sync
    */
-  openSetup: function(wizardType) {
+  openSetup(wizardType) {
     let service = Components.classes["@mozilla.org/weave/service;1"]
                   .getService(Components.interfaces.nsISupports)
                   .wrappedJSObject;
 
     if (service.fxAccountsEnabled) {
       this._openAboutAccounts();
     } else {
       let win = Services.wm.getMostRecentWindow("Weave:AccountSetup");
@@ -502,17 +502,17 @@ var gSyncPane = {
       else {
         window.openDialog("chrome://browser/content/sync/setup.xul",
                           "weaveSetup", "centerscreen,chrome,resizable=no",
                           wizardType);
       }
     }
   },
 
-  openContentInBrowser: function(url, options) {
+  openContentInBrowser(url, options) {
     let win = Services.wm.getMostRecentWindow("navigator:browser");
     if (!win) {
       // no window to use, so use _openLink to create a new one.  We don't
       // always use that as it prefers to open a new window rather than use
       // an existing one.
       gSyncUtils._openLink(url);
       return;
     }
@@ -525,68 +525,68 @@ var gSyncPane = {
     let browser = window.QueryInterface(Ci.nsIInterfaceRequestor)
                         .getInterface(Ci.nsIWebNavigation)
                         .QueryInterface(Ci.nsIDocShell)
                         .chromeEventHandler;
     // And tell it to load our URL.
     browser.loadURI(url);
   },
 
-  signUp: function() {
+  signUp() {
     this._openAboutAccounts("signup");
   },
 
-  signIn: function() {
+  signIn() {
     this._openAboutAccounts("signin");
   },
 
-  reSignIn: function() {
+  reSignIn() {
     this._openAboutAccounts("reauth");
   },
 
 
-  clickOrSpaceOrEnterPressed: function(event) {
+  clickOrSpaceOrEnterPressed(event) {
     // Note: charCode is deprecated, but 'char' not yet implemented.
     // Replace charCode with char when implemented, see Bug 680830
     return ((event.type == "click" && event.button == 0) ||
             (event.type == "keypress" &&
              (event.charCode == KeyEvent.DOM_VK_SPACE || event.keyCode == KeyEvent.DOM_VK_RETURN)));
   },
 
-  openChangeProfileImage: function(event) {
+  openChangeProfileImage(event) {
     if (this.clickOrSpaceOrEnterPressed(event)) {
       fxAccounts.promiseAccountsChangeProfileURI(this._getEntryPoint(), "avatar")
           .then(url => {
         this.openContentInBrowser(url, {
           replaceQueryString: true
         });
       });
       // Prevent page from scrolling on the space key.
       event.preventDefault();
     }
   },
 
-  openManageFirefoxAccount: function(event) {
+  openManageFirefoxAccount(event) {
     if (this.clickOrSpaceOrEnterPressed(event)) {
       this.manageFirefoxAccount();
       // Prevent page from scrolling on the space key.
       event.preventDefault();
     }
   },
 
-  manageFirefoxAccount: function() {
+  manageFirefoxAccount() {
     fxAccounts.promiseAccountsManageURI(this._getEntryPoint())
       .then(url => {
         this.openContentInBrowser(url, {
           replaceQueryString: true
         });
       });
   },
 
-  verifyFirefoxAccount: function() {
+  verifyFirefoxAccount() {
     let showVerifyNotification = (data) => {
       let isError = !data;
       let maybeNot = isError ? "Not" : "";
       let sb = this._accountsStringBundle;
       let title = sb.GetStringFromName("verification" + maybeNot + "SentTitle");
       let email = !isError && data ? data.email : "";
       let body = sb.formatStringFromName("verification" + maybeNot + "SentBody", [email], 1);
       new Notification(title, { body })
@@ -604,22 +604,22 @@ var gSyncPane = {
       }
     };
 
     fxAccounts.resendVerificationEmail()
       .then(fxAccounts.getSignedInUser, onError)
       .then(onSuccess, onError);
   },
 
-  openOldSyncSupportPage: function() {
+  openOldSyncSupportPage() {
     let url = Services.urlFormatter.formatURLPref("app.support.baseURL") + "old-sync";
     this.openContentInBrowser(url);
   },
 
-  unlinkFirefoxAccount: function(confirm) {
+  unlinkFirefoxAccount(confirm) {
     if (confirm) {
       // We use a string bundle shared with aboutAccounts.
       let sb = Services.strings.createBundle("chrome://browser/locale/syncSetup.properties");
       let disconnectLabel = sb.GetStringFromName("disconnect.label");
       let title = sb.GetStringFromName("disconnect.verify.title");
       let body = sb.GetStringFromName("disconnect.verify.bodyHeading") +
                  "\n\n" +
                  sb.GetStringFromName("disconnect.verify.bodyText");
@@ -641,29 +641,29 @@ var gSyncPane = {
         return;
       }
     }
     fxAccounts.signOut().then(() => {
       this.updateWeavePrefs();
     });
   },
 
-  openAddDevice: function() {
+  openAddDevice() {
     if (!Weave.Utils.ensureMPUnlocked())
       return;
 
     let win = Services.wm.getMostRecentWindow("Sync:AddDevice");
     if (win)
       win.focus();
     else
       window.openDialog("chrome://browser/content/sync/addDevice.xul",
                         "syncAddDevice", "centerscreen,chrome,resizable=no");
   },
 
-  resetSync: function() {
+  resetSync() {
     this.openSetup("reset");
   },
 
   _populateComputerName(value) {
     let textbox = document.getElementById("fxaSyncComputerName");
     if (!textbox.hasAttribute("placeholder")) {
       textbox.setAttribute("placeholder",
                            Weave.Utils.getDefaultDeviceName());