Bug 734547 - Use Services.prefs instead of getPref() in TB MsgComposeCommands.js. r=jorgk
authoraceman <acelists@atlas.sk>
Wed, 21 Nov 2018 15:26:00 +0100
changeset 33774 dfe843fc864c5d24b51e071b8ecedb6f24b68c76
parent 33773 34934d017e6068cd99126d83363c4559d72f1233
child 33775 57b3ea524f1df2ba4ed65b55a17413fbec194d07
push id388
push userclokep@gmail.com
push dateMon, 28 Jan 2019 20:54:56 +0000
reviewersjorgk
bugs734547
Bug 734547 - Use Services.prefs instead of getPref() in TB MsgComposeCommands.js. r=jorgk
mail/components/compose/content/MsgComposeCommands.js
--- a/mail/components/compose/content/MsgComposeCommands.js
+++ b/mail/components/compose/content/MsgComposeCommands.js
@@ -2886,18 +2886,18 @@ function ComposeStartup(aParams) {
 
   // finally, see if we need to auto open the address sidebar.
   var sideBarBox = document.getElementById("sidebar-box");
   if (sideBarBox.getAttribute("sidebarVisible") == "true") {
     // if we aren't supposed to have the side bar hidden, make sure it is visible
     if (document.getElementById("sidebar").getAttribute("src") == "")
       setTimeout(toggleAddressPicker, 0);   // do this on a delay so we don't hurt perf. on bringing up a new compose window
   }
-  gAutoSaveInterval = getPref("mail.compose.autosave") ?
-    getPref("mail.compose.autosaveinterval") * 60000 : 0;
+  gAutoSaveInterval = Services.prefs.getBoolPref("mail.compose.autosave") ?
+    Services.prefs.getIntPref("mail.compose.autosaveinterval") * 60000 : 0;
 
   if (gAutoSaveInterval)
     gAutoSaveTimeout = setTimeout(AutoSave, gAutoSaveInterval);
 
   gAutoSaveKickedIn = false;
 }
 /* eslint-enable complexity */
 
@@ -2946,21 +2946,17 @@ function WizCallback(state) {
     ComposeStartup(null);
   } else {
     // The account wizard is still closing so we can't close just yet
     setTimeout(MsgComposeCloseWindow, 0);
   }
 }
 
 function ComposeLoad() {
-  try {
-    var other_headers = getPref("mail.compose.other.header");
-  } catch (ex) {
-    dump("failed to get the mail.compose.other.header pref\n");
-  }
+  var other_headers = Services.prefs.getCharPref("mail.compose.other.header", "");
 
   AddMessageComposeOfflineQuitObserver();
 
   setupAutocomplete();
 
   try {
     SetupCommandUpdateHandlers();
     // This will do migration, or create a new account if we need to.
@@ -3069,17 +3065,17 @@ function GetCharsetUIString() {
       return charset;
     }
   }
   return "";
 }
 
 // Add-ons can override this to customize the behavior.
 function DoSpellCheckBeforeSend() {
-  return getPref("mail.SpellCheckBeforeSend");
+  return Services.prefs.getBoolPref("mail.SpellCheckBeforeSend");
 }
 
 /**
  * Handles message sending operations.
  * @param msgType nsIMsgCompDeliverMode of the operation.
  */
 /* eslint-disable complexity */
 function GenericSendMessage(msgType) {
@@ -3147,17 +3143,18 @@ function GenericSendMessage(msgType) {
 
     // Attachment Reminder: Alert the user if
     //  - the user requested "Remind me later" from either the notification bar or the menu
     //    (alert regardless of the number of files already attached: we can't guess for how many
     //    or which files users want the reminder, and guessing wrong will annoy them a lot), OR
     //  - the aggressive pref is set and the latest notification is still showing (implying
     //    that the message has no attachment(s) yet, message still contains some attachment
     //    keywords, and notification was not dismissed).
-    if (gManualAttachmentReminder || (getPref("mail.compose.attachment_reminder_aggressive") &&
+    if (gManualAttachmentReminder ||
+        (Services.prefs.getBoolPref("mail.compose.attachment_reminder_aggressive") &&
          document.getElementById("attachmentNotificationBox")
                  .getNotificationWithValue("attachmentReminder"))) {
       let flags = Services.prompt.BUTTON_POS_0 * Services.prompt.BUTTON_TITLE_IS_STRING +
                   Services.prompt.BUTTON_POS_1 * Services.prompt.BUTTON_TITLE_IS_STRING;
       let hadForgotten = Services.prompt.confirmEx(window,
                          getComposeBundle().getString("attachmentReminderTitle"),
                          getComposeBundle().getString("attachmentReminderMsg"),
                          flags,
@@ -3179,17 +3176,17 @@ function GenericSendMessage(msgType) {
     let account = MailServices.accounts.getAccount(currentAccountKey);
     if (!account) {
       throw new Error("currentAccountKey '" + currentAccountKey +
                       "' has no matching account!");
     }
     if (account.incomingServer.type != "nntp" && msgCompFields.newsgroups != "") {
       const kDontAskAgainPref = "mail.compose.dontWarnMail2Newsgroup";
       // default to ask user if the pref is not set
-      let dontAskAgain = getPref(kDontAskAgainPref);
+      let dontAskAgain = Services.prefs.getBoolPref(kDontAskAgainPref);
       if (!dontAskAgain) {
         let checkbox = {value: false};
         let okToProceed = Services.prompt.confirmCheck(
                               window,
                               getComposeBundle().getString("noNewsgroupSupportTitle"),
                               getComposeBundle().getString("recipientDlogMessage"),
                               getComposeBundle().getString("CheckMsg"),
                               checkbox);
@@ -3258,20 +3255,18 @@ function GenericSendMessage(msgType) {
       msgType == Ci.nsIMsgCompDeliverMode.Save ||
       msgType == Ci.nsIMsgCompDeliverMode.SaveAsDraft ||
       msgType == Ci.nsIMsgCompDeliverMode.AutoSaveAsDraft ||
       msgType == Ci.nsIMsgCompDeliverMode.SaveAsTemplate) {
     var fallbackCharset = {};
     // Check encoding, switch to UTF-8 if the default encoding doesn't fit
     // and disable_fallback_to_utf8 isn't set for this encoding.
     if (!gMsgCompose.checkCharsetConversion(getCurrentIdentity(), fallbackCharset)) {
-      var disableFallback = false;
-      try {
-        disableFallback = getPref("mailnews.disable_fallback_to_utf8." + originalCharset);
-      } catch (e) {}
+      let disableFallback = Services.prefs
+        .getBoolPref("mailnews.disable_fallback_to_utf8." + originalCharset, false);
       if (disableFallback)
         msgCompFields.needToCheckCharset = false;
       else
         fallbackCharset.value = "UTF-8";
     }
 
     if (fallbackCharset &&
         fallbackCharset.value && fallbackCharset.value != "")
@@ -3424,17 +3419,17 @@ function SendMessage() {
 
   GenericSendMessage(sendInBackground ?
                      Ci.nsIMsgCompDeliverMode.Background :
                      Ci.nsIMsgCompDeliverMode.Now);
   ExitFullscreenMode();
 }
 
 function SendMessageWithCheck() {
-  var warn = getPref("mail.warn_on_send_accel_key");
+  var warn = Services.prefs.getBoolPref("mail.warn_on_send_accel_key");
 
   if (warn) {
     let bundle = getComposeBundle();
     let checkValue = {value: false};
     let buttonPressed = Services.prompt.confirmEx(window,
       bundle.getString("sendMessageCheckWindowTitle"),
       bundle.getString("sendMessageCheckLabel"),
       (Services.prompt.BUTTON_TITLE_IS_STRING * Services.prompt.BUTTON_POS_0) +
@@ -5562,17 +5557,17 @@ function LoadIdentity(startup) {
       var event = document.createEvent("Events");
       event.initEvent("compose-from-changed", false, true);
       document.getElementById("msgcomposeWindow").dispatchEvent(event);
 
       gComposeNotificationBar.clearIdentityWarning();
     }
 
     if (!startup) {
-      if (getPref("mail.autoComplete.highlightNonMatches"))
+      if (Services.prefs.getBoolPref("mail.autoComplete.highlightNonMatches"))
         document.getElementById("addressCol2#1").highlightNonMatches = true;
 
       // Only do this if we aren't starting up...
       // It gets done as part of startup already.
       addRecipientsToIgnoreList(gCurrentIdentity.fullAddress);
 
       // If the From field is editable, reset the address from the identity.
       if (identityElement.editable) {
@@ -5582,17 +5577,18 @@ function LoadIdentity(startup) {
         );
       }
     }
   }
 }
 
 function MakeFromFieldEditable(ignoreWarning) {
   let bundle = getComposeBundle();
-  if (!ignoreWarning && !getPref("mail.compose.warned_about_customize_from")) {
+  if (!ignoreWarning &&
+      !Services.prefs.getBoolPref("mail.compose.warned_about_customize_from")) {
     var check = { value: false };
     if (Services.prompt.confirmEx(window,
           bundle.getString("customizeFromAddressTitle"),
           bundle.getString("customizeFromAddressWarning"),
           Services.prompt.BUTTON_POS_0 * Services.prompt.BUTTON_TITLE_OK +
           Services.prompt.BUTTON_POS_1 * Services.prompt.BUTTON_TITLE_CANCEL +
           Services.prompt.BUTTON_POS_1_DEFAULT,
           null, null, null,
@@ -5614,17 +5610,17 @@ function MakeFromFieldEditable(ignoreWar
 }
 
 function setupAutocomplete() {
   var autoCompleteWidget = document.getElementById("addressCol2#1");
   try {
     // Request that input that isn't matched be highlighted.
     // This element then gets cloned for subsequent rows, so they should
     // honor it as well.
-    if (getPref("mail.autoComplete.highlightNonMatches"))
+    if (Services.prefs.getBoolPref("mail.autoComplete.highlightNonMatches"))
       autoCompleteWidget.highlightNonMatches = true;
   } catch (ex) {}
 }
 
 function fromKeyPress(event) {
   if (event.keyCode == KeyEvent.DOM_VK_RETURN)
     awSetFocus(1, awGetInputElement(1));
 }
@@ -6282,49 +6278,43 @@ function AddRecipient(aRecipientType, aA
 }
 
 // Public method called by the contants sidebar.
 function AddRecipientsArray(aRecipientType, aAddressArray) {
   awAddRecipientsArray(aRecipientType, aAddressArray);
 }
 
 function loadHTMLMsgPrefs() {
-  try {
-    let fontFace = getPref("msgcompose.font_face", true);
+  let fontFace = Services.prefs.getStringPref("msgcompose.font_face", "");
+  if (fontFace)
     doStatefulCommand("cmd_fontFace", fontFace);
-  } catch (e) {}
-
-  try {
-    let fontSize = getPref("msgcompose.font_size");
+
+  let fontSize = Services.prefs.getCharPref("msgcompose.font_size", "");
+  if (fontSize)
     EditorSetFontSize(fontSize);
-  } catch (e) {}
 
   let bodyElement = GetBodyElement();
 
-  let useDefault = getPref("msgcompose.default_colors");
-
-  try {
-    let textColor = (useDefault ? "" : getPref("msgcompose.text_color"));
-    if ((!bodyElement.getAttribute("text")) && textColor) {
-      bodyElement.setAttribute("text", textColor);
-      gDefaultTextColor = textColor;
-      document.getElementById("cmd_fontColor").setAttribute("state", textColor);
-      onFontColorChange();
-    }
-  } catch (e) {}
-
-  try {
-    let bgColor = (useDefault ? "" : getPref("msgcompose.background_color"));
-    if ((!bodyElement.getAttribute("bgcolor")) && bgColor) {
-      bodyElement.setAttribute("bgcolor", bgColor);
-      gDefaultBackgroundColor = bgColor;
-      document.getElementById("cmd_backgroundColor").setAttribute("state", bgColor);
-      onBackgroundColorChange();
-    }
-  } catch (e) {}
+  let useDefault = Services.prefs.getBoolPref("msgcompose.default_colors");
+
+  let textColor = (useDefault ? "" : Services.prefs.getCharPref("msgcompose.text_color", ""));
+  if ((!bodyElement.getAttribute("text")) && textColor) {
+    bodyElement.setAttribute("text", textColor);
+    gDefaultTextColor = textColor;
+    document.getElementById("cmd_fontColor").setAttribute("state", textColor);
+    onFontColorChange();
+  }
+
+  let bgColor = (useDefault ? "" : Services.prefs.getCharPref("msgcompose.background_color", ""));
+  if ((!bodyElement.getAttribute("bgcolor")) && bgColor) {
+    bodyElement.setAttribute("bgcolor", bgColor);
+    gDefaultBackgroundColor = bgColor;
+    document.getElementById("cmd_backgroundColor").setAttribute("state", bgColor);
+    onBackgroundColorChange();
+  }
 }
 
 function AutoSave() {
   if (gMsgCompose.editor && (gContentChanged || gMsgCompose.bodyModified) &&
       !gSendOperationInProgress && !gSaveOperationInProgress) {
     GenericSendMessage(Ci.nsIMsgCompDeliverMode.AutoSaveAsDraft);
     gAutoSaveKickedIn = true;
   }
@@ -6339,17 +6329,17 @@ var gAttachmentNotifier = {
   _obs: null,
 
   enabled: false,
 
   init: function gAN_init(aDocument) {
     if (this._obs)
       this.shutdown();
 
-    this.enabled = getPref("mail.compose.attachment_reminder");
+    this.enabled = Services.prefs.getBoolPref("mail.compose.attachment_reminder");
     if (!this.enabled)
       return;
 
     this._obs = new MutationObserver(function gAN_handleMutations(aMutations) {
       gAttachmentNotifier.timer.cancel();
       gAttachmentNotifier.timer.initWithCallback(gAttachmentNotifier.event, 500,
                                                  Ci.nsITimer.TYPE_ONE_SHOT);
     });
@@ -6576,17 +6566,17 @@ function InitEditor() {
           .setAttribute("disabled", !gSpellChecker.canSpellCheck);
   document.getElementById("spellCheckEnable")
           .setAttribute("disabled", !gSpellChecker.canSpellCheck);
   // If canSpellCheck = false, then hidden = false, i.e. show it so that we can
   // still add dictionaries. Else, hide that.
   document.getElementById("spellCheckAddDictionariesMain")
           .setAttribute("hidden", gSpellChecker.canSpellCheck);
   // Then, we enable related UI entries.
-  enableInlineSpellCheck(getPref("mail.spellcheck.inline"));
+  enableInlineSpellCheck(Services.prefs.getBoolPref("mail.spellcheck.inline"));
   gAttachmentNotifier.init(editor.document);
 
   // Listen for spellchecker changes, set document language to
   // dictionary picked by the user via the right-click menu in the editor.
   document.addEventListener("spellcheck-changed", updateDocumentLanguage);
 
   // XXX: the error event fires twice for each load. Why??
   editor.document.body.addEventListener("error", function(event) {
@@ -6691,32 +6681,16 @@ function enableInlineSpellCheck(aEnableI
   document.getElementById("spellCheckDictionaries")
           .setAttribute("hidden", !aEnableInlineSpellCheck);
 }
 
 function getMailToolbox() {
   return document.getElementById("compose-toolbox");
 }
 
-function getPref(aPrefName, aIsComplex) {
-  if (aIsComplex) {
-    return Services.prefs.getStringPref(aPrefName);
-  }
-  switch (Services.prefs.getPrefType(aPrefName)) {
-    case Ci.nsIPrefBranch.PREF_BOOL:
-      return Services.prefs.getBoolPref(aPrefName);
-    case Ci.nsIPrefBranch.PREF_INT:
-      return Services.prefs.getIntPref(aPrefName);
-    case Ci.nsIPrefBranch.PREF_STRING:
-      return Services.prefs.getCharPref(aPrefName);
-    default: // includes nsIPrefBranch.PREF_INVALID
-      return null;
-  }
-}
-
 /**
  * Helper function to dispatch a CustomEvent to the attachmentbucket.
  *
  * @param aEventType the name of the event to fire.
  * @param aData any detail data to pass to the CustomEvent.
  */
 function dispatchAttachmentBucketEvent(aEventType, aData) {
   let bucket = document.getElementById("attachmentBucket");