Bug 1552851 - move shared functions from AccountManager.js to other AM utility files so they can be safely imported without whole of AccountManager.js, to prevent adding unwanted event handlers. r=jorgk default tip
authoraceman <acelists@atlas.sk>
Mon, 20 May 2019 14:07:00 +0200
changeset 26697 db23151240208013bc4bc45357a5915c033a1855
parent 26696 93545cdce0ccb634384e3a889967866e2f2541f1
push id15951
push usermozilla@jorgk.com
push dateTue, 21 May 2019 22:28:02 +0000
treeherdercomm-central@db2315124020 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorgk
bugs1552851
Bug 1552851 - move shared functions from AccountManager.js to other AM utility files so they can be safely imported without whole of AccountManager.js, to prevent adding unwanted event handlers. r=jorgk
mailnews/base/prefs/content/AccountManager.js
mailnews/base/prefs/content/am-copies.js
mailnews/base/prefs/content/am-copies.xul
mailnews/base/prefs/content/am-identity-edit.xul
mailnews/base/prefs/content/am-junk.js
mailnews/base/prefs/content/am-junk.xul
mailnews/base/prefs/content/am-offline.js
mailnews/base/prefs/content/am-offline.xul
mailnews/base/prefs/content/am-prefs.js
mailnews/base/prefs/content/am-server.js
mailnews/base/prefs/content/am-server.xul
--- a/mailnews/base/prefs/content/AccountManager.js
+++ b/mailnews/base/prefs/content/AccountManager.js
@@ -115,39 +115,16 @@ function updateElementWithKeys(account, 
       if (MailServices.smtp.defaultServer)
         element.serverkey = MailServices.smtp.defaultServer.key;
       break;
     default:
 //      dump("unknown element type! "+type+"\n");
   }
 }
 
-function hideShowControls(serverType) {
-  let controls = document.querySelectorAll("[hidefor]");
-  for (let controlNo = 0; controlNo < controls.length; controlNo++) {
-    let control = controls[controlNo];
-    let hideFor = control.getAttribute("hidefor");
-
-    // Hide unsupported server types using hideFor="servertype1,servertype2".
-    let hide = false;
-    let hideForTokens = hideFor.split(",");
-    for (let tokenNo = 0; tokenNo < hideForTokens.length; tokenNo++) {
-      if (hideForTokens[tokenNo] == serverType) {
-        hide = true;
-        break;
-      }
-    }
-
-    if (hide)
-      control.setAttribute("hidden", "true");
-    else
-      control.removeAttribute("hidden");
-  }
-}
-
 // called when the whole document loads
 // perform initialization here
 function onLoad() {
   var selectedServer;
   var selectPage = null;
 
   // Arguments can have two properties: (1) "server," the nsIMsgIncomingServer
   // to select initially and (2) "selectPage," the page for that server to that
--- a/mailnews/base/prefs/content/am-copies.js
+++ b/mailnews/base/prefs/content/am-copies.js
@@ -1,14 +1,15 @@
 /* -*- Mode: Java; tab-width: 2; 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/. */
 
-/* import-globals-from AccountManager.js */
+/* import-globals-from am-prefs.js */
+/* import-globals-from amUtils.js */
 
 var {MailUtils} = ChromeUtils.import("resource:///modules/MailUtils.jsm");
 
 var gFccRadioElemChoice, gDraftsRadioElemChoice, gArchivesRadioElemChoice, gTmplRadioElemChoice;
 var gFccRadioElemChoiceLocked, gDraftsRadioElemChoiceLocked, gArchivesRadioElemChoiceLocked, gTmplRadioElemChoiceLocked;
 var gDefaultPickerMode = "1";
 
 var gFccFolderWithDelim, gDraftsFolderWithDelim, gArchivesFolderWithDelim, gTemplatesFolderWithDelim;
--- a/mailnews/base/prefs/content/am-copies.xul
+++ b/mailnews/base/prefs/content/am-copies.xul
@@ -9,18 +9,18 @@
 
 <!DOCTYPE page SYSTEM "chrome://messenger/locale/am-copies.dtd">
 
 <page xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
       title="&copyAndFolderTitle.label;"
       onload="parent.onPanelLoaded('am-copies.xul');">
 
   <vbox flex="1" style="overflow: auto;">
-    <script src="chrome://messenger/content/AccountManager.js"/>
     <script src="chrome://messenger/content/am-copies.js"/>
+    <script src="chrome://messenger/content/am-prefs.js"/>
     <script src="chrome://messenger/content/amUtils.js"/>
 
     <hbox class="dialogheader">
       <label class="dialogheader-title" value="&copyAndFolderTitle.label;"/>
     </hbox>
 #include am-copies.inc.xul
   </vbox>
 </page>
--- a/mailnews/base/prefs/content/am-identity-edit.xul
+++ b/mailnews/base/prefs/content/am-identity-edit.xul
@@ -29,17 +29,16 @@
   <stringbundle id="bundle_prefs"
                 src="chrome://messenger/locale/prefs.properties"/>
   <stringbundle id="bundle_messenger"
                 src="chrome://messenger/locale/messenger.properties"/>
 
   <script src="chrome://messenger/content/am-prefs.js"/>
   <script src="chrome://messenger/content/am-identity-edit.js"/>
   <script src="chrome://messenger/content/amUtils.js"/>
-  <script src="chrome://messenger/content/AccountManager.js"/>
   <script src="chrome://messenger/content/am-copies.js"/>
   <script src="chrome://messenger/content/am-addressing.js"/>
   <script src="chrome://messenger/content/am-smime.js"/>
   <script>
   <![CDATA[
     window.addEventListener("load", smimeOnLoadEditor, false);
   ]]>
   </script>
--- a/mailnews/base/prefs/content/am-junk.js
+++ b/mailnews/base/prefs/content/am-junk.js
@@ -1,14 +1,15 @@
 /* -*- Mode: Java; tab-width: 2; 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/. */
 
-/* import-globals-from AccountManager.js */
+/* import-globals-from am-prefs.js */
+/* import-globals-from amUtils.js */
 
 var {MailServices} = ChromeUtils.import("resource:///modules/MailServices.jsm");
 var {fixIterator} = ChromeUtils.import("resource:///modules/iteratorUtils.jsm");
 var {MailUtils} = ChromeUtils.import("resource:///modules/MailUtils.jsm");
 
 var gDeferredToAccount = "";
 
 function onInit(aPageId, aServerId) {
@@ -104,20 +105,20 @@ function onInit(aPageId, aServerId) {
 
   // enable or disable the useServerFilter checkbox
   onCheckItem("useServerFilterList", ["server.useServerFilter"]);
 
   updateJunkTargetsAndRetention();
 }
 
 function onPreInit(account, accountValues) {
-  if (getAccountValue(account, accountValues, "server", "type", null, false) == "pop3")
-    gDeferredToAccount = getAccountValue(account, accountValues,
-                                         "pop3", "deferredToAccount",
-                                         null, false);
+  if (top.getAccountValue(account, accountValues, "server", "type", null, false) == "pop3")
+    gDeferredToAccount = top.getAccountValue(account, accountValues,
+                                             "pop3", "deferredToAccount",
+                                             null, false);
 
   buildServerFilterMenuList();
 }
 
 /**
  * Called when someone checks or unchecks the adaptive junk mail checkbox.
  * set the value of the hidden element accordingly
  *
--- a/mailnews/base/prefs/content/am-junk.xul
+++ b/mailnews/base/prefs/content/am-junk.xul
@@ -16,17 +16,16 @@
 %junkMailDTD;
 ]>
 
 <page xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
       title="&junkSettings.label;"
       onload="parent.onPanelLoaded('am-junk.xul');">
 
   <vbox flex="1" style="overflow: auto;">
-    <script src="chrome://messenger/content/AccountManager.js"/>
     <script src="chrome://messenger/content/am-junk.js"/>
     <script src="chrome://messenger/content/am-prefs.js"/>
     <script src="chrome://messenger/content/amUtils.js"/>
     <stringbundle id="bundle_messenger" src="chrome://messenger/locale/messenger.properties"/>
 
     <hbox class="dialogheader">
       <label class="dialogheader-title" value="&junkSettings.label;"/>
     </hbox>
--- a/mailnews/base/prefs/content/am-offline.js
+++ b/mailnews/base/prefs/content/am-offline.js
@@ -1,14 +1,14 @@
 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  * 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/. */
 
-/* import-globals-from AccountManager.js */
+/* import-globals-from am-prefs.js */
 /* import-globals-from ../../content/retention.js */
 
 var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
 var {fixIterator} = ChromeUtils.import("resource:///modules/iteratorUtils.jsm");
 
 var gIncomingServer;
 var gServerType;
 var gImapIncomingServer;
@@ -22,19 +22,19 @@ function onInit(aPageId, aServerId) {
   onLockPreference();
 
   // init values here
   initServerSettings();
   initRetentionSettings();
   initDownloadSettings();
   initOfflineSettings();
 
-  onCheckItem("offline.notDownloadMin", "offline.notDownload");
-  onCheckItem("nntp.downloadMsgMin", "nntp.downloadMsg");
-  onCheckItem("nntp.removeBodyMin", "nntp.removeBody");
+  onCheckItem1("offline.notDownloadMin", "offline.notDownload");
+  onCheckItem1("nntp.downloadMsgMin", "nntp.downloadMsg");
+  onCheckItem1("nntp.removeBodyMin", "nntp.removeBody");
   onCheckKeepMsg();
 }
 
 /**
  * Store initial offline flag for each folder and the allFoldersOffline
  * checkbox. Use to restore the flags and checkbox if edits are canceled.
  */
 function initOfflineSettings() {
@@ -113,17 +113,17 @@ function initDownloadSettings() {
     autosyncInterval.disabled = false;
     autosyncValue.disabled = false;
   }
   autosyncPref.value = autosyncPrefValue;
 }
 
 
 function onPreInit(account, accountValues) {
-  gServerType = getAccountValue(account, accountValues, "server", "type", null, false);
+  gServerType = top.getAccountValue(account, accountValues, "server", "type", null, false);
   hideShowControls(gServerType);
   gIncomingServer = account.incomingServer;
   gIncomingServer.type = gServerType;
 
   // 10 is OFFLINE_SUPPORT_LEVEL_REGULAR, see nsIMsgIncomingServer.idl
   // currently, there is no offline without diskspace
   var titleStringID = (gIncomingServer.offlineSupportLevel >= 10) ?
    "prefPanel-synchronization" : "prefPanel-diskspace";
@@ -187,17 +187,17 @@ function onAutosyncChange() {
 }
 
 function onAutosyncNotDownload() {
   // This function is called when the autosync version of offline.notDownload
   // is changed it simply copies the new checkbox value over to the element
   // driving the preference.
   document.getElementById("offline.notDownload").checked =
     document.getElementById("autosync.notDownload").checked;
-  onCheckItem("offline.notDownloadMin", "offline.notDownload");
+  onCheckItem1("offline.notDownloadMin", "offline.notDownload");
 }
 
 function onCancel() {
   // restore the offline flags for all folders
   restoreOfflineFolders(gOfflineMap);
   document.getElementById("offline.folders").checked = gOfflineFolders;
 }
 
@@ -315,17 +315,18 @@ function onLockPreference() {
   ];
 
   finalPrefString = initPrefString + "." + gIncomingServer.key + ".";
   gPref = Services.prefs.getBranch(finalPrefString);
 
   disableIfLocked(allPrefElements);
 }
 
-function onCheckItem(changeElementId, checkElementId) {
+// XXX TODO: Function should be merged with onCheckItem in bug 755885.
+function onCheckItem1(changeElementId, checkElementId) {
   var element = document.getElementById(changeElementId);
   var checked = document.getElementById(checkElementId).checked;
   if (checked && !gLockedPref[checkElementId]) {
     element.removeAttribute("disabled");
   } else {
     element.setAttribute("disabled", "true");
   }
 }
--- a/mailnews/base/prefs/content/am-offline.xul
+++ b/mailnews/base/prefs/content/am-offline.xul
@@ -8,19 +8,19 @@
 <!DOCTYPE page SYSTEM "chrome://messenger/locale/am-offline.dtd">
 
 <page xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
       onload="parent.onPanelLoaded('am-offline.xul');">
 
   <vbox flex="1" style="overflow: auto;">
     <stringbundle id="bundle_prefs" src="chrome://messenger/locale/prefs.properties"/>
 
-    <script src="chrome://messenger/content/AccountManager.js"/>
     <script src="chrome://messenger/content/retention.js"/>
     <script src="chrome://messenger/content/am-offline.js"/>
+    <script src="chrome://messenger/content/am-prefs.js"/>
 
     <label hidden="true" wsm_persist="true" id="server.type"/>
     <label id="imap.autoSyncMaxAgeDays" hidden="true"
            wsm_persist="true" preftype="int"
            prefstring="mail.server.%serverkey%.autosync_max_age_days"/>
 
     <hbox id="headertitle" class="dialogheader">
       <label class="dialogheader-title"/>
--- a/mailnews/base/prefs/content/am-prefs.js
+++ b/mailnews/base/prefs/content/am-prefs.js
@@ -104,8 +104,36 @@ function onCheckItem(aChangeElementId, a
     }
   }
 
   if (!disabled && getAccountValueIsLocked(elementToControl))
     disabled = true;
 
   elementToControl.disabled = disabled;
 }
+
+/**
+ * Hides and shows elements relevant for the given server type.
+ *
+ * @param aServerType  Name of the server type for which to show/hide elements
+ */
+function hideShowControls(serverType) {
+  let controls = document.querySelectorAll("[hidefor]");
+  for (let controlNo = 0; controlNo < controls.length; controlNo++) {
+    let control = controls[controlNo];
+    let hideFor = control.getAttribute("hidefor");
+
+    // Hide unsupported server types using hideFor="servertype1,servertype2".
+    let hide = false;
+    let hideForTokens = hideFor.split(",");
+    for (let tokenNo = 0; tokenNo < hideForTokens.length; tokenNo++) {
+      if (hideForTokens[tokenNo] == serverType) {
+        hide = true;
+        break;
+      }
+    }
+
+    if (hide)
+      control.setAttribute("hidden", "true");
+    else
+      control.removeAttribute("hidden");
+  }
+}
--- a/mailnews/base/prefs/content/am-server.js
+++ b/mailnews/base/prefs/content/am-server.js
@@ -1,14 +1,15 @@
 /* -*- Mode: Java; tab-width: 2; 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/. */
 
-/* import-globals-from AccountManager.js */
+/* import-globals-from am-prefs.js */
+/* import-globals-from amUtils.js */
 
 var {fixIterator} = ChromeUtils.import("resource:///modules/iteratorUtils.jsm");
 var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
 var {MailUtils} = ChromeUtils.import("resource:///modules/MailUtils.jsm");
 var {BrowserUtils} = ChromeUtils.import("resource://gre/modules/BrowserUtils.jsm");
 
 var gServer;
 var gOriginalStoreType;
--- a/mailnews/base/prefs/content/am-server.xul
+++ b/mailnews/base/prefs/content/am-server.xul
@@ -14,17 +14,16 @@
 ]>
 
 <page xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"
       xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
       title="&serverSettings.label;"
       onload="parent.onPanelLoaded('am-server.xul');">
 
   <vbox flex="1" style="overflow: auto;">
-    <script src="chrome://messenger/content/AccountManager.js"/>
     <script src="chrome://messenger/content/am-server.js"/>
     <script src="chrome://messenger/content/am-prefs.js"/>
     <script src="chrome://messenger/content/amUtils.js"/>
     <script src="chrome://messenger/content/menulist-charsetpicker.js"/>
     <stringbundle id="bundle_messenger" src="chrome://messenger/locale/messenger.properties"/>
 
     <label hidden="true" wsm_persist="true" id="server.type"/>
     <label hidden="true"