Bug 738810 - convert mailnews/base/prefs/content/AccountManager.js to Services.jsm and MailServices.js. r=IanN, r=mconley
authoraceman <acelists@atlas.sk>
Sat, 02 Jun 2012 14:41:56 -0400
changeset 10340 3468a34b21bdb1090ad66c4e42193ec5cb1ad4b4
parent 10339 62b83330b36cae3a2a1efca94b42500f652e90de
child 10341 88ce9f09dda7bac079409728b7d23e373486dad9
push id7829
push usermconley@mozilla.com
push dateSat, 02 Jun 2012 18:48:00 +0000
treeherdercomm-central@7ee39bdf99ae [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersIanN, mconley
bugs738810
Bug 738810 - convert mailnews/base/prefs/content/AccountManager.js to Services.jsm and MailServices.js. r=IanN, r=mconley
mail/test/mozmill/account/test-mail-account-setup-wizard.js
mailnews/base/prefs/content/AccountManager.js
mailnews/base/prefs/content/am-prefs.js
--- a/mail/test/mozmill/account/test-mail-account-setup-wizard.js
+++ b/mail/test/mozmill/account/test-mail-account-setup-wizard.js
@@ -3,16 +3,19 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 var MODULE_NAME = "test-mail-account-setup-wizard";
 
 var RELATIVE_ROOT = "../shared-modules";
 var MODULE_REQUIRES = ["folder-display-helpers", "window-helpers",
                        "account-manager-helpers", "keyboard-helpers" ];
 
+Components.utils.import("resource://gre/modules/Services.jsm");
+Components.utils.import("resource:///modules/mailServices.js");
+
 var mozmill = {};
 Components.utils.import("resource://mozmill/modules/mozmill.js", mozmill);
 var controller = {};
 Components.utils.import("resource://mozmill/modules/controller.js", controller);
 var elib = {};
 Components.utils.import("resource://mozmill/modules/elementslib.js", elib);
 
 var wh, account, incoming, outgoing;
@@ -45,36 +48,34 @@ function open_mail_account_setup_wizard(
 
 // Remove an account on the Account Manager
 function remove_account(amc) {
   let win = amc.window;
 
   try {
     // Remove the account and incoming server
     let serverId = incoming.serverURI;
-    Cc["@mozilla.org/messenger/account-manager;1"]
-      .getService(Ci.nsIMsgAccountManager).removeAccount(account);
+    MailServices.accounts.removeAccount(account);
     if (serverId in win.accountArray)
       delete win.accountArray[serverId];
     win.selectServer(null, null);
 
     // Remove the outgoing server
-    win.smtpService.deleteSmtpServer(outgoing);
+    MailServices.smtp.deleteSmtpServer(outgoing);
     win.replaceWithDefaultSmtpServer(outgoing.key);
   } catch (ex) {
     throw new Error("failure to remove account: " + ex + "\n");
   }
 }
 
 function test_mail_account_setup() {
   // Set the pref to load a local autoconfig file.
-  let pref = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
   let pref_name = "mailnews.auto_config_url";
   let url = collector.addHttpResource("../account/xml", "autoconfig");
-  pref.setCharPref(pref_name, url);
+  Services.prefs.setCharPref(pref_name, url);
 
   // Force .com MIME-Type to text/xml
   collector.httpd.registerContentType("com", "text/xml");
 
   open_mail_account_setup_wizard(function (awc) {
     // Input user's account information
     awc.e("realname").focus();
     input_value(awc, user.name);
@@ -95,27 +96,27 @@ function test_mail_account_setup() {
     config = awc.window.gEmailConfigWizard.getConcreteConfig();
 
     // Open the advanced settings (Account Manager) to create the account
     // immediately.  We use an invalid email/password so the setup will fail
     // anyway.
     open_advanced_settings_from_account_wizard(subtest_verify_account, awc);
 
     // Clean up
-    pref.clearUserPref(pref_name);
+    Services.prefs.clearUserPref(pref_name);
   });
 }
 
 function subtest_verify_account(amc) {
   amc.waitFor(function () (amc.window.currentAccount != null),
               "Timeout waiting for currentAccount to become non-null");
   account = amc.window.currentAccount;
   let identity = account.defaultIdentity;
   incoming = account.incomingServer;
-  outgoing = amc.window.smtpService.getServerByKey(identity.smtpServerKey);
+  outgoing = MailServices.smtp.getServerByKey(identity.smtpServerKey);
 
   let config = {
     "incoming server username": {
       actual: incoming.username, expected: user.email.split("@")[0]
     },
     "outgoing server username": {
       actual: outgoing.username, expected: user.email.split("@")[0]
     },
@@ -148,20 +149,19 @@ function subtest_verify_account(amc) {
 }
 
 /**
  * Make sure that we don't re-set the information we get from the config
  * file if the password is incorrect.
  **/
 function test_bad_password_uses_old_settings() {
   // Set the pref to load a local autoconfig file.
-  let pref = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
   let pref_name = "mailnews.auto_config_url";
   let url = collector.addHttpResource("../account/xml", "autoconfig");
-  pref.setCharPref(pref_name, url);
+  Services.prefs.setCharPref(pref_name, url);
 
   // Force .com MIME-Type to text/xml
   collector.httpd.registerContentType("com", "text/xml");
 
   mc.sleep(0);
   open_mail_account_setup_wizard(function (awc) {
     try {
       // Input user's account information
@@ -191,39 +191,36 @@ function test_bad_password_uses_old_sett
       // Make sure all the values are the same as in the user object.
       awc.sleep(1000);
       assert_equals(awc.e("outgoing_hostname").value, user.outgoingHost,
                     "Outgoing server changed!");
       assert_equals(awc.e("incoming_hostname").value, user.incomingHost,
                     "incoming server changed!");
     } finally {
       // Clean up
-      pref.clearUserPref(pref_name);
+      Services.prefs.clearUserPref(pref_name);
       awc.e("cancel_button").click();
     }
   });
 }
 
 function test_remember_password() {
   remember_password_test(true);
   remember_password_test(false);
 }
 
 /* Test remember_password checkbox behavior with
  * signon.rememberSignons set to "aPrefValue"
  */
 function remember_password_test(aPrefValue) {
-  let pref = Cc["@mozilla.org/preferences-service;1"]
-      .getService(Ci.nsIPrefBranch);
-
   // save the pref for backup purpose
   let rememberSignons_pref_save =
-      pref.getBoolPref("signon.rememberSignons", true);
+      Services.prefs.getBoolPref("signon.rememberSignons", true);
 
-  pref.setBoolPref("signon.rememberSignons", aPrefValue);
+  Services.prefs.setBoolPref("signon.rememberSignons", aPrefValue);
 
   // without this, it breaks the test, don't know why
   mc.sleep(0);
   open_mail_account_setup_wizard(function (awc) {
     try {
       let password = new elementslib.ID(awc.window.document, "password");
       let rememberPassword =
           new elementslib.ID(awc.window.document, "remember_password");
@@ -240,15 +237,15 @@ function remember_password_test(aPrefVal
         awc.assertNotChecked(rememberPassword);
       }
 
       // empty the password field
       awc.keypress(password, 'a', {accelKey: true});
       awc.keypress(password, 'VK_DELETE', {});
 
       // restore the saved signon.rememberSignons value
-      pref.setBoolPref("signon.rememberSignons", rememberSignons_pref_save);
+      Services.prefs.setBoolPref("signon.rememberSignons", rememberSignons_pref_save);
     } finally {
       // close the wizard
       awc.e("cancel_button").click();
     }
   });
 }
--- a/mailnews/base/prefs/content/AccountManager.js
+++ b/mailnews/base/prefs/content/AccountManager.js
@@ -41,20 +41,16 @@ var accountArray;
 var gGenericAttributeTypes;
 
 var currentAccount;
 var currentPageId;
 
 var pendingAccount;
 var pendingPageId;
 
-// services used
-var smtpService;
-var nsPrefBranch;
-
 // This sets an attribute in a xul element so that we can later
 // know what value to substitute in a prefstring.  Different
 // preference types set different attributes.  We get the value
 // in the same way as the function getAccountValue() determines it.
 function updateElementWithKeys(account, element, type) {
   switch (type)
   {
     case "identity":
@@ -62,18 +58,18 @@ function updateElementWithKeys(account, 
       break;
     case "pop3":
     case "imap":
     case "nntp":
     case "server":
       element["serverkey"] = account.incomingServer.key;
       break;
     case "smtp":
-      if (smtpService.defaultServer)
-        element["serverkey"] = smtpService.defaultServer.key;
+      if (MailServices.smtp.defaultServer)
+        element["serverkey"] = MailServices.smtp.defaultServer.key;
       break;
     default:
 //      dump("unknown element type! "+type+"\n");
   }
 }
 
 function hideShowControls(serverType) {
   var controls = document.getElementsByAttribute("hidefor", "*");
@@ -110,19 +106,16 @@ function onLoad() {
   if ("arguments" in window && window.arguments[0]) {
     selectedServer = window.arguments[0].server;
     selectPage = window.arguments[0].selectPage;
   }
 
   accountArray = new Object();
   gGenericAttributeTypes = new Object();
 
-  smtpService =
-    Components.classes["@mozilla.org/messengercompose/smtp;1"].getService(Components.interfaces.nsISmtpService);
-
   gAccountTree.load();
 
   setTimeout(selectServer, 0, selectedServer, selectPage);
 }
 
 function onUnload() {
   gAccountTree.unload();
 }
@@ -161,36 +154,35 @@ function selectServer(server, selectPage
   if (lastItem.localName == "treeitem")
     index = accountTree.contentView.getIndexOfItem(lastItem);
 
   accountTree.treeBoxObject.ensureRowIsVisible(index);
 }
 
 function replaceWithDefaultSmtpServer(deletedSmtpServerKey)
 {
-  //First we replace the smtpserverkey in every identity
-  const Ci = Components.interfaces;
-  var am = Components.classes["@mozilla.org/messenger/account-manager;1"]
-                     .getService(Ci.nsIMsgAccountManager);
-  for each (var identity in fixIterator(am.allIdentities, Ci.nsIMsgIdentity)) {
+  // First we replace the smtpserverkey in every identity.
+  let am = MailServices.accounts;
+  for each (let identity in fixIterator(am.allIdentities,
+                                        Components.interfaces.nsIMsgIdentity)) {
     if (identity.smtpServerKey == deletedSmtpServerKey)
       identity.smtpServerKey = "";
   }
 
   // When accounts have already been loaded in the panel then the first
   // replacement will be overwritten when the accountvalues are written out
   // from the pagedata.  We get the loaded accounts and check to make sure
   // that the account exists for the accountid and that it has a default
   // identity associated with it (to exclude smtpservers and local folders)
   // Then we check only for the identity[type] and smtpServerKey[slot] and
   // replace that with the default smtpserverkey if necessary.
 
   for (var accountid in accountArray) {
     var account = accountArray[accountid]._account;
-    if(account && account.defaultIdentity) {
+    if (account && account.defaultIdentity) {
       var accountValues = accountArray[accountid];
       var smtpServerKey = getAccountValue(account, accountValues, "identity",
                                           "smtpServerKey", null, false);
       if (smtpServerKey == deletedSmtpServerKey)
         setAccountValue(accountValues, "identity", "smtpServerKey", "");
     }
   }
 }
@@ -226,17 +218,17 @@ function onAccept() {
  * Also check if the Local Directory path was changed.
  *
  * @param showAlert  show and alert if a problem with the host / user name is found
  */
 function checkUserServerChanges(showAlert) {
   const prefBundle = document.getElementById("bundle_prefs");
   const alertTitle = prefBundle.getString("prefPanel-server");
   var alertText = null;
-  if (smtpService.defaultServer) {
+  if (MailServices.smtp.defaultServer) {
     try {
       var smtpHostName = top.frames["contentFrame"]
                             .document.getElementById("smtp.hostname");
       if (smtpHostName && hostnameIsIllegal(smtpHostName.value)) {
         alertText = prefBundle.getString("enterValidHostname");
         Services.prompt.alert(window, alertTitle, alertText);
         gSmtpHostNameIsIllegal = true;
       }
@@ -244,17 +236,17 @@ function checkUserServerChanges(showAler
     catch (ex) {}
   }
 
   var accountValues = getValueArrayFor(currentAccount);
   if (!accountValues)
     return true;
 
   var pageElements = getPageFormElements();
-  if (pageElements == null)
+  if (!pageElements)
     return true;
 
   // Get the new username, hostname and type from the page
   var newUser, newHost, newType, oldUser, oldHost;
   var uIndx, hIndx;
   for (var i = 0; i < pageElements.length; i++) {
     if (pageElements[i].id) {
       var vals = pageElements[i].id.split(".");
@@ -383,20 +375,17 @@ function onSave() {
 }
 
 function onAddAccount() {
   MsgAccountWizard();
 }
 
 function AddMailAccount()
 {
-  let msgWindow = Components.classes["@mozilla.org/messenger/services/session;1"]
-                            .getService(Components.interfaces.nsIMsgMailSession)
-                            .topmostMsgWindow;
-  NewMailAccount(msgWindow);
+  NewMailAccount(MailServices.mailSession.topmostMsgWindow);
 }
 
 function AddIMAccount()
 {
   window.openDialog("chrome://messenger/content/chat/imAccountWizard.xul",
                     "", "chrome,modal,titlebar,centerscreen");
 }
 
@@ -533,17 +522,17 @@ function saveAccount(accountValues, acco
         dest = server.QueryInterface(Components.interfaces.nsIPop3IncomingServer);
       else if (type == "imap")
         dest = server.QueryInterface(Components.interfaces.nsIImapIncomingServer);
       else if (type == "none")
         dest = server.QueryInterface(Components.interfaces.nsINoIncomingServer);
       else if (type == "nntp")
         dest = server.QueryInterface(Components.interfaces.nsINntpIncomingServer);
       else if (type == "smtp")
-        dest = smtpService.defaultServer;
+        dest = MailServices.smtp.defaultServer;
 
       } catch (ex) {
         // don't do anything, just means we don't support that
       }
       if (dest == undefined) continue;
 
       if ((type in gGenericAttributeTypes) && (slot in gGenericAttributeTypes[type])) {
         var methodName = "get";
@@ -720,33 +709,34 @@ function setEnabled(control, enabled)
 // nothing is selected.
 function onAccountTreeSelect(pageId, account)
 {
   let tree = document.getElementById("accounttree");
 
   let changeView = pageId && account;
   if (!changeView) {
     if (tree.view.selection.count < 1)
-      return null;
+      return false;
 
     let node = tree.contentView.getItemAtIndex(tree.currentIndex);
-    account = node._account;
+    account = ("_account" in node) ? node._account : null;
+
     pageId = node.getAttribute("PageTag")
   }
 
   if (pageId == currentPageId && account == currentAccount)
-    return;
+    return true;
 
   // check if user/host names have been changed
   checkUserServerChanges(false);
 
   if (gSmtpHostNameIsIllegal) {
     gSmtpHostNameIsIllegal = false;
     selectServer(currentAccount.incomingServer, currentPageId);
-    return;
+    return true;
   }
 
   // save the previous page
   savePage(currentAccount);
 
   let changeAccount = (account != currentAccount);
 
   if (changeView)
@@ -763,16 +753,18 @@ function onAccountTreeSelect(pageId, acc
     loadPage(pageId);
   } else if (changeAccount) {
     // same page, different server
     restorePage(pageId, account);
   }
 
   if (changeAccount)
     updateButtons(tree, account);
+
+  return true;
 }
 
 // page has loaded
 function onPanelLoaded(pageId) {
   if (pageId != pendingPageId) {
 
     // if we're reloading the current page, we'll assume the
     // page has asked itself to be completely reloaded from
@@ -791,29 +783,25 @@ function onPanelLoaded(pageId) {
 
   // probably unnecessary, but useful for debugging
   pendingAccount = null;
   pendingPageId = null;
 }
 
 function loadPage(pageId)
 {
-  var chromePackageName;
-  try 
-  {
+  let chromePackageName;
+  try {
     // we could compare against "main","server","copies","offline","addressing",
     // "smtp" and "advanced" first to save the work, but don't,
     // as some of these might be turned into extensions (for thunderbird)
-    var am = Components.classes["@mozilla.org/messenger/account-manager;1"]
-                       .getService(Components.interfaces.nsIMsgAccountManager);
-    var package = pageId.split("am-")[1].split(".xul")[0];
-    chromePackageName = am.getChromePackageName(package);
+    let packageName = pageId.split("am-")[1].split(".xul")[0];
+    chromePackageName = MailServices.accounts.getChromePackageName(packageName);
   }
-  catch (ex) 
-  {
+  catch (ex) {
     chromePackageName = "messenger";
   }
   const LOAD_FLAGS_NONE = Components.interfaces.nsIWebNavigation.LOAD_FLAGS_NONE;
   document.getElementById("contentFrame").webNavigation.loadURI("chrome://" + chromePackageName + "/content/" + pageId, LOAD_FLAGS_NONE, null, null, null);
 }
 
 // save the values of the widgets to the given server
 function savePage(account)
@@ -821,25 +809,25 @@ function savePage(account)
   if (!account)
     return;
 
   // tell the page that it's about to save
   if ("onSave" in top.frames["contentFrame"])
     top.frames["contentFrame"].onSave();
 
   var accountValues = getValueArrayFor(account);
-  if (!accountValues) 
+  if (!accountValues)
     return;
 
   var pageElements = getPageFormElements();
-  if (!pageElements) 
+  if (!pageElements)
     return;
 
   // store the value in the account
-  for (var i=0; i<pageElements.length; i++) {
+  for (var i = 0; i < pageElements.length; i++) {
     if (pageElements[i].id) {
       var vals = pageElements[i].id.split(".");
       if (vals.length >= 2) {
         var type = vals[0];
         var slot = vals[1];
 
         setAccountValue(accountValues,
                         type, slot,
@@ -875,17 +863,17 @@ function getAccountValue(account, accoun
       source = server.QueryInterface(Components.interfaces.nsIPop3IncomingServer);
     else if (type == "imap")
       source = server.QueryInterface(Components.interfaces.nsIImapIncomingServer);
     else if (type == "none")
       source = server.QueryInterface(Components.interfaces.nsINoIncomingServer);
     else if (type == "nntp")
       source = server.QueryInterface(Components.interfaces.nsINntpIncomingServer);
     else if (type == "smtp")
-      source = smtpService.defaultServer;
+      source = MailServices.smtp.defaultServer;
     } catch (ex) {
     }
 
     if (source) {
       if (isGeneric) {
         if (!(type in gGenericAttributeTypes))
           gGenericAttributeTypes[type] = new Object();
 
@@ -927,28 +915,28 @@ function getAccountValue(account, accoun
 
 // restore the values of the widgets from the given server
 function restorePage(pageId, account)
 {
   if (!account)
     return;
 
   var accountValues = getValueArrayFor(account);
-  if (!accountValues) 
+  if (!accountValues)
     return;
 
   if ("onPreInit" in top.frames["contentFrame"])
     top.frames["contentFrame"].onPreInit(account, accountValues);
 
   var pageElements = getPageFormElements();
-  if (!pageElements) 
+  if (!pageElements)
     return;
 
   // restore the value from the account
-  for (var i=0; i<pageElements.length; i++) {
+  for (var i = 0; i < pageElements.length; i++) {
     if (pageElements[i].id) {
       var vals = pageElements[i].id.split(".");
       if (vals.length >= 2) {
         var type = vals[0];
         var slot = vals[1];
         // buttons are lockable, but don't have any data so we skip that part.
         // elements that do have data, we get the values at poke them in.
         if (pageElements[i].localName != "button") {
@@ -962,22 +950,22 @@ function restorePage(pageId, account)
             break;
           case "pop3":
           case "imap":
           case "nntp":
           case "server":
             element["serverkey"] = account.incomingServer.key;
             break;
           case "smtp":
-            if (smtpService.defaultServer)
-              element["serverkey"] = smtpService.defaultServer.key;
+            if (MailServices.smtp.defaultServer)
+              element["serverkey"] = MailServices.smtp.defaultServer.key;
             break;
         }
         var isLocked = getAccountValueIsLocked(pageElements[i]);
-        setEnabled(pageElements[i],!isLocked);
+        setEnabled(pageElements[i], !isLocked);
       }
     }
   }
 
   // tell the page that new values have been loaded
   if ("onInit" in top.frames["contentFrame"])
     top.frames["contentFrame"].onInit(pageId, account.incomingServer.serverURI);
 
@@ -1095,19 +1083,21 @@ function setFormElementValue(formElement
 // helper routine for account manager panels to get the current account for the selected server
 function getCurrentAccount()
 {
   return currentAccount;
 }
 
 // get the array of form elements for the given page
 function getPageFormElements() {
-  if("getElementsByAttribute" in top.frames["contentFrame"].document)
+  if ("getElementsByAttribute" in top.frames["contentFrame"].document)
     return top.frames["contentFrame"].document
               .getElementsByAttribute("wsm_persist", "true");
+
+  return null;
 }
 
 // get the value array for the given account
 function getValueArrayFor(account) {
   var serverId = account ? account.incomingServer.serverURI : "global";
 
   if (!(serverId in accountArray)) {
     accountArray[serverId] = new Object();
@@ -1198,18 +1188,19 @@ var gAccountTree = {
       var panelsToKeep = [];
       var idents = mgr.GetIdentitiesForServer(server);
       if (idents.Count()) {
         panelsToKeep.push(panels[0]); // The server panel is valid
         panelsToKeep.push(panels[1]); // also the copies panel
         panelsToKeep.push(panels[4]); // and addresssing
       }
 
-      // Everyone except news and RSS has a junk panel
+      // Everyone except News, RSS and IM has a junk panel
       // XXX: unextensible!
+      // The existence of server.spamSettings can't currently be used for this.
       if (server.type != "nntp" && server.type != "rss" && server.type != "im")
         panelsToKeep.push(panels[5]);
 
       // Check offline/diskspace support level
       var offline = server.offlineSupportLevel;
       var diskspace = server.supportsDiskSpace;
       if (offline >= 10 && diskspace)
         panelsToKeep.push(panels[2]);
--- a/mailnews/base/prefs/content/am-prefs.js
+++ b/mailnews/base/prefs/content/am-prefs.js
@@ -1,91 +1,82 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  * 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/. */
 
-
 /* functions for disabling front end elements when the appropriate
    back-end preference is locked. */
 
-
-var nsPrefBranch = null;
+Components.utils.import("resource://gre/modules/Services.jsm");
 
-// Prefs in mailnews require dynamic portions to indicate 
-// which of multiple servers or identies.  This function
-// takes a string and a xul element.
-//  The string is a prefstring with a token %tokenname%.
-//  The xul element has an attribute of name |tokenname|
-//  whose value is substituted into the string and returned
-//  by the function.
-//  Any tokens which do not have associated attribute value
-//  are not substituted, and left in the string as-is.
-function substPrefTokens(aStr, element)
+/**
+ * Prefs in MailNews require dynamic portions to indicate
+ * which of multiple servers or identities. This function
+ * takes a string and a xul element.
+ *
+ * @param aStr  The string is a prefstring with a token %tokenname%.
+ * @param aElement  The xul element has an attribute of name |tokenname|
+ *                  whose value is substituted into the string and returned
+ *                  by the function.
+ *
+ * Any tokens which do not have associated attribute value
+ * are not substituted, and left in the string as-is.
+ */
+function substPrefTokens(aStr, aElement)
 {
-  var tokenpat = /%(\w+)%/;
-  var token;
-  var newprefstr = "";
+  let tokenpat = /%(\w+)%/;
+  let token;
+  let newprefstr = "";
 
-  var prefPartsArray = aStr.split(".");
+  let prefPartsArray = aStr.split(".");
   /* here's a little loop that goes through
      each part of the string separated by a dot, and
      if any parts are of the form %string%, it will replace
      them with the value of the attribute of that name from
      the xul object */
-  for (var i=0; i< prefPartsArray.length; i++) {
+  for (let i = 0; i < prefPartsArray.length; i++) {
     token = prefPartsArray[i].match(tokenpat);
     if (token) { /* we've got a %% match */
       if (token[1]) {
-        if (element[token[1]]) {
-          newprefstr += element[token[1]] + "."; // here's where we get the info
+        if (aElement[token[1]]) {
+          newprefstr += aElement[token[1]] + "."; // here's where we get the info
         } else { /* all we got was this stinkin % */
           newprefstr += prefPartsArray[i] + ".";
         }
       }
     } else /* if (token) */ {
       newprefstr += prefPartsArray[i] + ".";
     }
   }
-  newprefstr = newprefstr.slice(0,-1); // remove the last char, a dot
-  if (newprefstr.length <=0 )
+  newprefstr = newprefstr.slice(0, -1); // remove the last char, a dot
+  if (newprefstr.length <= 0)
     newprefstr = null;
 
   return newprefstr;
 }
 
-// A simple function which given a xul element with
-// the pref related attributes (pref, preftype, prefstring)
-// return if the prefstring specified in that element is
-// locked (true/false).
-// If it does not have a valid prefstring, a false is returned.
-function getAccountValueIsLocked(element)
+/**
+ * A simple function to check if a pref in an element is locked.
+ *
+ * @param aElement  a xul element with the pref related attributes
+ *                 (pref, preftype, prefstring)
+ * @return  whether the prefstring specified in that element is
+ *          locked (true/false).
+ *          If it does not have a valid prefstring, a false is returned.
+ */
+function getAccountValueIsLocked(aElement)
 {
-  var prefstr = "";
-  var preftype;
-  var prefval;
-  var prefstring;
-
-  if (!nsPrefBranch) {
-    var prefService = Components.classes["@mozilla.org/preferences-service;1"];
-    prefService = prefService.getService();
-    prefService = prefService.QueryInterface(Components.interfaces.nsIPrefService);
-
-    nsPrefBranch = prefService.getBranch(null);
-  }
-
-  prefstring = element.getAttribute("prefstring");
+  let prefstring = aElement.getAttribute("prefstring");
   if (prefstring) {
-    preftype    = element.getAttribute("preftype");
-    prefstr = substPrefTokens(prefstring, element);
+    let preftype = aElement.getAttribute("preftype");
+    let prefstr = substPrefTokens(prefstring, aElement);
     // see if the prefstring is locked
-    if (prefstr) {
-      var bLocked=nsPrefBranch.prefIsLocked(prefstr);
-      return bLocked;
-    }
+    if (prefstr)
+      return Services.prefs.prefIsLocked(prefstr);
   }
   return false;
 }
 
 /**
  * Enables/disables element (slave) according to the checked state
  * of another element (master).
  *