Bug 1454408 - Replace getPref calls needing a default value with standard Services calls. Suite part. r=IanN a=IanN
authorFrank-Rainer Grahl <frgrahl@gmx.net>
Mon, 07 May 2018 12:41:29 +0200
changeset 31469 78712c7817d3
parent 31468 a59b0b5ac649
child 31470 d1f2c2d881cb
push id383
push userclokep@gmail.com
push date2018-05-07 21:52 +0000
reviewersIanN, IanN
bugs1454408
Bug 1454408 - Replace getPref calls needing a default value with standard Services calls. Suite part. r=IanN a=IanN
suite/browser/navigator.js
suite/common/contentAreaClick.js
suite/common/downloads/downloadmanager.js
suite/common/openLocation.js
suite/common/sidebar/sidebarOverlay.js
suite/common/sync/aboutSyncTabs.js
suite/common/utilityOverlay.js
suite/common/viewZoomOverlay.js
suite/mailnews/compose/MsgComposeCommands.js
--- a/suite/browser/navigator.js
+++ b/suite/browser/navigator.js
@@ -607,26 +607,26 @@ function Startup()
   // Check window.arguments[0]. If not null then use it for uriArray
   // otherwise the new window is being called when another browser
   // window already exists so use the New Window pref for uriArray
   if ("arguments" in window && window.arguments.length >= 1) {
     var uriArray;
     if (window.arguments[0]) {
       uriArray = window.arguments[0].toString().split('\n'); // stringify and split
     } else {
-      switch (GetIntPref("browser.windows.loadOnNewWindow", 0))
+      switch (Services.prefs.getIntPref("browser.windows.loadOnNewWindow", 0))
       {
         default:
           uriArray = ["about:blank"];
           break;
         case 1:
           uriArray = getHomePage();
           break;
         case 2:
-          uriArray = [GetStringPref("browser.history.last_page_visited")];
+          uriArray = [Services.prefs.getStringPref("browser.history.last_page_visited", "")];
           break;
       }
     }
     uriToLoad = uriArray.splice(0, 1)[0];
 
     if (uriArray.length > 0)
       window.setTimeout(function(arg) { for (var i in arg) gBrowser.addTab(arg[i]); }, 0, uriArray);
   }
@@ -973,17 +973,17 @@ function CookieImagePopupAction(aElement
 function OpenSessionHistoryIn(aWhere, aDelta, aTab)
 {
   var win = aWhere == "window" ? null : window;
   aTab = aTab || getBrowser().selectedTab;
   var tab = Cc["@mozilla.org/suite/sessionstore;1"]
               .getService(Ci.nsISessionStore)
               .duplicateTab(win, aTab, aDelta, true);
 
-  var loadInBackground = GetBoolPref("browser.tabs.loadInBackground", false);
+  var loadInBackground = Services.prefs.getBoolPref("browser.tabs.loadInBackground");
 
   switch (aWhere) {
   case "tabfocused":
     // forces tab to be focused
     loadInBackground = true;
     // fall through
   case "tabshifted":
     loadInBackground = !loadInBackground;
@@ -1331,17 +1331,17 @@ var BrowserSearch = {
       if (where == "window")
         return;
     } else {
       loadURI(submission.uri.spec, null, submission.postData, false);
       window.content.focus();
     }
 
     // should we try and open up the sidebar to show the "Search Results" panel?
-    if (GetBoolPref("browser.search.opensidebarsearchpanel", false))
+    if (Services.prefs.getBoolPref("browser.search.opensidebarsearchpanel", false))
       this.revealSidebar();
   },
 
   /**
    * Returns the search bar element if it is present in the toolbar, null otherwise.
    */
   get searchBar() {
     return document.getElementById("searchbar");
@@ -1463,27 +1463,27 @@ function BrowserOpenWindow()
     }
   });
 }
 
 function BrowserOpenTab()
 {
   if (!gInPrintPreviewMode) {
     var uriToLoad;
-    var tabPref = GetIntPref("browser.tabs.loadOnNewTab",0);
+    var tabPref = Services.prefs.getIntPref("browser.tabs.loadOnNewTab", 0);
     switch (tabPref)
     {
       default:
         uriToLoad = "about:blank";
         break;
       case 1:
         uriToLoad = GetLocalizedStringPref("browser.startup.homepage");
         break;
       case 2:
-        uriToLoad = GetStringPref("browser.history.last_page_visited");
+        uriToLoad = Services.prefs.getStringPref("browser.history.last_page_visited", "");
         break;
     }
 
     if (!gBrowser) {
       var win = getTopWin();
       if (win) {
         // If there's an open browser window, it should handle this command
         win.focus();
@@ -1839,17 +1839,17 @@ function handleURLBarCommand(aUserAction
     // Check the pressed modifiers: (also see bug 97123)
     // Modifier Mac | Modifier PC | Action
     // -------------+-------------+-----------
     // Command      | Control     | New Window/Tab
     // Shift+Cmd    | Shift+Ctrl  | New Window/Tab behind current one
     // Option       | Shift       | Save URL (show Filepicker)
 
     // If false, the save modifier is Alt, which is Option on Mac.
-    var modifierIsShift = GetBoolPref("ui.key.saveLink.shift", true);
+    var modifierIsShift = Services.prefs.getBoolPref("ui.key.saveLink.shift", true);
 
     var shiftPressed = false;
     var saveModifier = false; // if the save modifier was pressed
     if (aTriggeringEvent && 'shiftKey' in aTriggeringEvent &&
         'altKey' in aTriggeringEvent) {
       saveModifier = modifierIsShift ? aTriggeringEvent.shiftKey
                      : aTriggeringEvent.altKey;
       shiftPressed = aTriggeringEvent.shiftKey;
@@ -1857,17 +1857,17 @@ function handleURLBarCommand(aUserAction
 
     var browser = getBrowser();
     // Accept both Control and Meta (=Command) as New-Window-Modifiers
     if (aTriggeringEvent &&
         (('ctrlKey' in aTriggeringEvent && aTriggeringEvent.ctrlKey) ||
          ('metaKey' in aTriggeringEvent && aTriggeringEvent.metaKey) ||
          ('button'  in aTriggeringEvent && aTriggeringEvent.button == 1))) {
       // Check if user requests Tabs instead of windows
-      if (GetBoolPref("browser.tabs.opentabfor.urlbar", false)) {
+      if (Services.prefs.getBoolPref("browser.tabs.opentabfor.urlbar", false)) {
         // Reset url in the urlbar
         URLBarSetURI();
         // Open link in new tab
         var t = browser.addTab(data.url, {
                   postData: data.postData,
                   allowThirdPartyFixup: true,
                 });
 
@@ -2769,17 +2769,17 @@ function updateFileUploadItem()
     item.removeAttribute('disabled');
   else
     item.setAttribute('disabled', 'true');
 }
 
 function isBidiEnabled()
 {
   // first check the pref.
-  if (GetBoolPref("bidi.browser.ui", false)) {
+  if (Services.prefs.getBoolPref("bidi.browser.ui", false)) {
     return true;
   }
 
   // now see if the app locale is an RTL one.
   const isRTL = Services.locale.isAppLocaleRTL;
 
   if (isRTL) {
     Services.prefs.setBoolPref("bidi.browser.ui", true);
--- a/suite/common/contentAreaClick.js
+++ b/suite/common/contentAreaClick.js
@@ -117,17 +117,17 @@
     // (call to urlSecurityCheck) is now done within openNew... functions
 
     switch (event.button) {
       case 0:                                                         // if left button clicked
         if (event.metaKey || event.ctrlKey) {                         // and meta or ctrl are down
           if (openNewTabOrWindow(event, href, linkNode))
             return true;
         }
-        var saveModifier = GetBoolPref("ui.key.saveLink.shift", true);
+        var saveModifier = Services.prefs.getBoolPref("ui.key.saveLink.shift", true);
         saveModifier = saveModifier ? event.shiftKey : event.altKey;
 
         if (saveModifier) {                                           // if saveModifier is down
           var doc = linkNode.ownerDocument;
           saveURL(href, gatherTextUnder(linkNode), "SaveLinkTitle",
                   false, true, doc.documentURIObject, doc);
           return true;
         }
--- a/suite/common/downloads/downloadmanager.js
+++ b/suite/common/downloads/downloadmanager.js
@@ -148,18 +148,19 @@ function cancelDownload(aDownload)
 }
 
 function openDownload(aDownload)
 {
   var name = aDownload.displayName;
   var file = new nsLocalFile(aDownload.target.path);
 
   if (file.isExecutable()) {
-    var alertOnEXEOpen = GetBoolPref("browser.download.manager.alertOnEXEOpen",
-                                     true);
+    var alertOnEXEOpen = 
+      Services.prefs.getBoolPref("browser.download.manager.alertOnEXEOpen",
+                                 true);
 
     // On Windows 7 and above, we rely on native security prompting for
     // downloaded content unless it's disabled.
     try {
       var sysInfo = Cc["@mozilla.org/system-info;1"]
                       .getService(Ci.nsIPropertyBag2);
       if (/^Windows/.test(sysInfo.getProperty("name")) &&
           Services.prefs.getBoolPref("browser.download.manager.scanWhenDone"))
--- a/suite/common/openLocation.js
+++ b/suite/common/openLocation.js
@@ -49,17 +49,17 @@ function onLoad()
         gAction = "-1";
       }
       break;
 
     default: // open web page
       gOpenAppList.value = Services.prefs.getIntPref("general.open_location.last_window_choice");
   }
 
-  gInput.value = GetStringPref(gLastPref);
+  gInput.value = Services.prefs.getStringPref(gLastPref, "");
   if (gInput.value)
     gInput.select(); // XXX should probably be done automatically
 
   doEnabling();
 }
 
 function doEnabling()
 {
--- a/suite/common/sidebar/sidebarOverlay.js
+++ b/suite/common/sidebar/sidebarOverlay.js
@@ -743,17 +743,17 @@ function sidebar_overlay_init() {
     if (sidebarObj.never_built) {
       sidebarObj.never_built = false;
 
       debug("sidebar = " + sidebarObj);
       debug("sidebarObj.resource = " + sidebarObj.resource);
       debug("sidebarObj.datasource_uri = " + sidebarObj.datasource_uri);
 
       // Obtain the pref for limiting the number of tabs in view, defaults to 8.
-      gNumTabsInViewPref = GetIntPref("sidebar.num_tabs_in_view", 8);
+      gNumTabsInViewPref = Services.prefs.getIntPref("sidebar.num_tabs_in_view", 8);
 
       // Show the header for the panels area. Use a splitter if there
       // is stuff over the panels area.
       var sidebar_panels_splitter = document.getElementById('sidebar-panels-splitter');
       if (sidebar_element.firstChild != sidebar_panels_splitter) {
         debug("Showing the panels splitter");
         sidebar_panels_splitter.removeAttribute('hidden');
       }
--- a/suite/common/sync/aboutSyncTabs.js
+++ b/suite/common/sync/aboutSyncTabs.js
@@ -195,17 +195,17 @@ var RemoteTabViewer = {
         el.hidden = mode == "all";
       el = el.nextSibling;
     }
   },
 
   _refetchTabs: function(force) {
     if (!force) {
       // Don't bother refetching tabs if we already did so recently
-      let lastFetch = GetIntPref("services.sync.lastTabFetch", 0);
+      let lastFetch = Services.prefs.getIntPref("services.sync.lastTabFetch", 0);
       let now = Math.floor(Date.now() / 1000);
       if (now - lastFetch < 30)
         return false;
     }
 
     // if Clients hasn't synced yet this session, need to sync it as well
     if (Weave.Service.clientsEngine.lastSync == 0)
       Weave.Service.clientsEngine.sync();
--- a/suite/common/utilityOverlay.js
+++ b/suite/common/utilityOverlay.js
@@ -89,76 +89,68 @@ function InitProxyMenu()
     networkProxyWpad.removeAttribute("disabled");
     networkProxySystem.removeAttribute("disabled");
   }
 
   // If no proxy is configured, disable the menuitems.
   // Checking for proxy manual settings.
   var proxyManuallyConfigured = false;
   for (var i = 0; i < kProxyManual.length; i++) {
-    if (GetStringPref(kProxyManual[i]) != "") {
+    if (Services.prefs.getStringPref(kProxyManual[i], "") != "") {
       proxyManuallyConfigured = true;
       break;
     }
   }
 
   if (proxyManuallyConfigured && !proxyLocked) {
     networkProxyManual.removeAttribute("disabled");
   }
   else {
     networkProxyManual.setAttribute("disabled", "true");
   }
 
   //Checking for proxy PAC settings.
   var proxyAutoConfigured = false;
-  if (GetStringPref("network.proxy.autoconfig_url") != "")
+  if (Services.prefs.getStringPref("network.proxy.autoconfig_url", "") != "")
     proxyAutoConfigured = true;
 
   if (proxyAutoConfigured && !proxyLocked) {
     networkProxyPac.removeAttribute("disabled");
   }
   else {
     networkProxyPac.setAttribute("disabled", "true");
   }
 
   // The pref value 3 for network.proxy.type is unused to maintain
   // backwards compatibility. Treat 3 equally to 0. See bug 115720.
   var networkProxyStatus = [networkProxyNo, networkProxyManual, networkProxyPac,
                             networkProxyNo, networkProxyWpad,
                             networkProxySystem];
-  var networkProxyType = GetIntPref("network.proxy.type", 0);
+  var networkProxyType = Services.prefs.getIntPref("network.proxy.type", 0);
   networkProxyStatus[networkProxyType].setAttribute("checked", "true");
 }
 
 function setProxyTypeUI()
 {
   var panel = document.getElementById("offline-status");
   if (!panel)
     return;
 
-  var onlineTooltip = "onlineTooltip" + GetIntPref("network.proxy.type", 0);
+  var onlineTooltip = "onlineTooltip" +
+                      Services.prefs.getIntPref("network.proxy.type", 0);
   panel.setAttribute("tooltiptext", gUtilityBundle.getString(onlineTooltip));
 }
 
 function SetStringPref(aPref, aValue)
 {
-  const nsISupportsString = Ci.nsISupportsString;
   try {
     Services.prefs.setStringPref(aPref, aValue);
   } catch (e) {}
 }
 
-function GetStringPref(name)
-{
-  try {
-    return Services.prefs.getStringPref(name);
-  } catch (e) {}
-  return "";
-}
-
 function GetLocalizedStringPref(aPrefName, aDefaultValue)
 {
   try {
     return Services.prefs.getComplexValue(aPrefName,
                Ci.nsIPrefLocalizedString).data;
   } catch (e) {
     Cu.reportError("Couldn't get " + aPrefName + " pref: " + e);
   }
@@ -288,17 +280,18 @@ function goCustomizeToolbar(toolbox)
   /* If the toolbox has a method "customizeInit" then call it first.
      The optional "customizeDone" method will be invoked by the callback
      from the Customize Window so we don't need to take care of that */
   if ("customizeInit" in toolbox)
     toolbox.customizeInit();
 
   var customizeURL = "chrome://communicator/content/customizeToolbar.xul";
 
-  gCustomizeSheet = GetBoolPref("toolbar.customization.usesheet", false);
+  gCustomizeSheet =
+    Services.prefs.getBoolPref("toolbar.customization.usesheet", false);
 
   if (gCustomizeSheet) {
     var sheetFrame = document.getElementById("customizeToolbarSheetIFrame");
     var panel = document.getElementById("customizeToolbarSheetPopup");
     sheetFrame.hidden = false;
     sheetFrame.toolbox = toolbox;
     sheetFrame.panel = panel;
 
@@ -1125,17 +1118,17 @@ function BrowserOnCommand(event)
                              .getInterface(Ci.nsIWebNavigation)
                              .QueryInterface(Ci.nsIDocShell);
       let securityInfo = docshell.failedChannel.securityInfo;
       let sslStatus = securityInfo.QueryInterface(Ci.nsISSLStatusProvider)
                                   .SSLStatus;
 
       let params = { exceptionAdded : false, sslStatus : sslStatus };
 
-      switch (GetIntPref("browser.ssl_override_behavior", 2)) {
+      switch (services.prefs.getIntPref("browser.ssl_override_behavior", 2)) {
         case 2 : // Pre-fetch & pre-populate.
           params.prefetchCert = true;
           // Fall through.
         case 1 : // Pre-populate.
           params.location = ownerDoc.location.href;
       }
 
       window.openDialog('chrome://pippki/content/exceptionDialog.xul',
@@ -1352,34 +1345,16 @@ function closeMenus(node) {
     if (node.namespaceURI == "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
     && (node.tagName == "menupopup" || node.tagName == "popup"))
       node.hidePopup();
 
     closeMenus(node.parentNode);
   }
 }
 
-function GetBoolPref(aPrefName, aDefaultValue)
-{
-  try {
-    return Services.prefs.getBoolPref(aPrefName);
-  } catch (e) {}
-  return aDefaultValue;
-}
-
-function GetIntPref(aPrefName, aDefaultValue)
-{
-  try {
-    return Services.prefs.getIntPref(aPrefName);
-  } catch (e) {
-    Cu.reportError("Couldn't get " + aPrefName + " pref: " + e);
-  }
-  return aDefaultValue;
-}
-
 /**
  * Toggle a splitter to show or hide some piece of UI (e.g. the message preview
  * pane).
  *
  * @param aSplitterId the splitter that should be toggled
  */
 function togglePaneSplitter(aSplitterId)
 {
@@ -1462,25 +1437,25 @@ function whereToOpenLink(e, ignoreButton
   var middle = !ignoreButton && e.button == 1;
 
   // Don't do anything special with right-mouse clicks.  They're probably clicks on context menu items.
 
   // On macOS ctrl is not evaluated.
   var metaKey = AppConstants.platform == "macosx" ? meta : ctrl;
 
   if (metaKey || middle) {
-    if (GetBoolPref("browser.tabs.opentabfor.middleclick", true))
+    if (Services.prefs.getBoolPref("browser.tabs.opentabfor.middleclick", true))
       return ignoreBackground ? "tabfocused" : shift ? "tabshifted" : "tab";
-    if (GetBoolPref("middlemouse.openNewWindow", true))
+    if (Services.prefs.getBoolPref("middlemouse.openNewWindow", true))
       return "window";
     if (middle)
       return null;
   }
   if (!ignoreSave) {
-    if (GetBoolPref("ui.key.saveLink.shift", true) ? shift : alt)
+    if (Services.prefs.getBoolPref("ui.key.saveLink.shift", true) ? shift : alt)
       return "save";
   }
   if (alt || shift || meta || ctrl)
     return null;
 
   return "current";
 }
 
@@ -1619,17 +1594,18 @@ function openLinkIn(url, where, params)
     sa.appendElement(aPrincipal);
     sa.appendElement(aTriggeringPrincipal);
 
     const sourceWindow = (w || window);
     Services.ww.openWindow(sourceWindow, getBrowserURL(), null, features, sa);
     return;
   }
 
-  var loadInBackground = GetBoolPref("browser.tabs.loadInBackground", false);
+  var loadInBackground =
+    Services.prefs.getBoolPref("browser.tabs.loadInBackground");
 
   // reuse the browser if its current tab is empty
   if (isBrowserEmpty(w.getBrowser()))
     where = "current";
 
   switch (where) {
   case "current":
     let flags = Ci.nsIWebNavigation.LOAD_FLAGS_NONE;
@@ -1696,17 +1672,18 @@ function openUILinkArrayIn(urlArray, whe
   var w = getTopWin();
 
   if (!w || where == "window") {
     return window.openDialog(getBrowserURL(), "_blank", "chrome,all,dialog=no",
                              urlArray.join("\n"), // Pretend that we're a home page group
                              null, null, null, allowThirdPartyFixup);
   }
 
-  var loadInBackground = GetBoolPref("browser.tabs.loadInBackground", false);
+  var loadInBackground = 
+    Services.prefs.getBoolPref("browser.tabs.loadInBackground");
 
   var browser = w.getBrowser();
   switch (where) {
   case "current":
     w.loadURI(urlArray[0], null, null, allowThirdPartyFixup);
     w.content.focus();
     break;
   case "tabshifted":
--- a/suite/common/viewZoomOverlay.js
+++ b/suite/common/viewZoomOverlay.js
@@ -101,17 +101,17 @@ var FullZoom = FullZoom || {
       if (event.getModifierState(key))
         pref.push(modifiers[key]);
     if (pref.length == 1)
       pref = pref[0];
     else // Multiple or no modifiers, use default action
       pref = "mousewheel.default.action";
 
     // Don't do anything if this isn't a "zoom" scroll event.
-    if (GetIntPref(pref, 0) != MOUSE_SCROLL_ZOOM)
+    if (Services.prefs.getIntPref(pref, 0) != MOUSE_SCROLL_ZOOM)
       return;
 
     // XXX Lazily cache all the possible action prefs so we don't have to get
     // them anew from the pref service for every scroll event?  We'd have to
     // make sure to observe them so we can update the cache when they change.
 
     // We have to call _applySettingToPref in a timeout because we handle
     // the event before the event state manager has a chance to apply the zoom
--- a/suite/mailnews/compose/MsgComposeCommands.js
+++ b/suite/mailnews/compose/MsgComposeCommands.js
@@ -3247,19 +3247,17 @@ function SwitchElementFocus(event)
 }
 
 function loadHTMLMsgPrefs()
 {
   var fontSize;
   var textColor;
   var bgColor;
 
-  // This version of GetStringPref() comes from editorUtilities.js instead of
-  // utilitiesOverlay.js
-  var fontFace = GetStringPref("msgcompose.font_face");
+  var fontFace = Services.prefs.getStringPref("msgcompose.font_face", "");
   doStatefulCommand("cmd_fontFace", fontFace);
 
   try {
     fontSize = getPref("msgcompose.font_size");
     EditorSetFontSize(fontSize);
   } catch (e) {}
 
   var bodyElement = GetBodyElement();