Bug 686999 - Rename getBoolPref helper to GetBoolPref and make more use of it r=neil
authorIan Neal <iann_cvs@blueyonder.co.uk>
Fri, 16 Sep 2011 16:17:39 +0100
changeset 9185 68c36509612b40ec67c81291bf81ab6bc9aebe77
parent 9184 5394a4d394e418c6d502812745fb319dd2f36bcb
child 9186 3450e93def8c8c9632387baae7c0d91802924ae1
push id230
push userbugzilla@standard8.plus.com
push dateTue, 08 Nov 2011 22:55:24 +0000
treeherdercomm-beta@63dad5648415 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersneil
bugs686999
Bug 686999 - Rename getBoolPref helper to GetBoolPref and make more use of it r=neil
suite/browser/navigator.js
suite/common/contentAreaClick.js
suite/common/downloads/downloadmanager.js
suite/common/utilityOverlay.js
--- a/suite/browser/navigator.js
+++ b/suite/browser/navigator.js
@@ -905,17 +905,17 @@ function popupHost()
 function OpenSessionHistoryIn(aWhere, aDelta, aTab)
 {
   var win = aWhere == "window" ? null : window;
   aTab = aTab || getBrowser().selectedTab;
   var tab = Components.classes["@mozilla.org/suite/sessionstore;1"]
                       .getService(Components.interfaces.nsISessionStore)
                       .duplicateTab(win, aTab, aDelta, true);
 
-  var loadInBackground = getBoolPref("browser.tabs.loadInBackground", false);
+  var loadInBackground = GetBoolPref("browser.tabs.loadInBackground", false);
 
   switch (aWhere) {
   case "tabfocused":
     // forces tab to be focused
     loadInBackground = true;
     // fall through
   case "tabshifted":
     loadInBackground = !loadInBackground;
@@ -1226,21 +1226,17 @@ const 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?
-    var autoOpenSidebar = false;
-    try {
-      autoOpenSidebar = Services.prefs.getBoolPref("browser.search.opensidebarsearchpanel");
-    } catch (e) {}
-    if (autoOpenSidebar)
+    if (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");
@@ -1631,21 +1627,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 = true;
-    try {
-      modifierIsShift = Services.prefs.getBoolPref("ui.key.saveLink.shift");
-    }
-    catch (ex) {}
+    var modifierIsShift = 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;
@@ -1654,23 +1646,17 @@ function handleURLBarCommand(aUserAction
     var browser = getBrowser();
     var postData = {};
     url = getShortcutOrURI(url, postData);
     // Accept both Control and Meta (=Command) as New-Window-Modifiers
     if (aTriggeringEvent &&
         (('ctrlKey' in aTriggeringEvent && aTriggeringEvent.ctrlKey) ||
          ('metaKey' in aTriggeringEvent && aTriggeringEvent.metaKey))) {
       // Check if user requests Tabs instead of windows
-      var openTab = false;
-      try {
-        openTab = Services.prefs.getBoolPref("browser.tabs.opentabfor.urlbar");
-      }
-      catch (ex) {}
-
-      if (openTab) {
+      if (GetBoolPref("browser.tabs.opentabfor.urlbar", false)) {
         // Open link in new tab
         var t = browser.addTab(url, {allowThirdPartyFixup: true, postData: postData.value});
 
         // Focus new tab unless shift is pressed
         if (!shiftPressed) {
           browser.userTypedValue = null;
           browser.selectedTab = t;
         }
--- a/suite/common/contentAreaClick.js
+++ b/suite/common/contentAreaClick.js
@@ -163,24 +163,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.ownerDocument))
             return true;
         } 
-        var saveModifier = true;
-        if (pref) {
-          try {
-            saveModifier = pref.getBoolPref("ui.key.saveLink.shift");
-          }
-          catch(ex) {            
-          }
-        }
+        var saveModifier = GetBoolPref("ui.key.saveLink.shift", true);
         saveModifier = saveModifier ? event.shiftKey : event.altKey;
           
         if (saveModifier) {                                           // if saveModifier is down
           saveURL(href, gatherTextUnder(linkNode), "SaveLinkTitle",
                   false, true, linkNode.ownerDocument.documentURIObject);
           return true;
         }
         if (event.altKey)                                             // if alt is down
--- a/suite/common/downloads/downloadmanager.js
+++ b/suite/common/downloads/downloadmanager.js
@@ -194,20 +194,18 @@ function removeDownload(aDownloadID)
 }
 
 function openDownload(aDownload)
 {
   var name = aDownload.displayName;
   var file = aDownload.targetFile;
 
   if (file.isExecutable()) {
-    var alertOnEXEOpen = true;
-    try {
-      alertOnEXEOpen = gPrefService.getBoolPref("browser.download.manager.alertOnEXEOpen");
-    } catch (e) { }
+    var alertOnEXEOpen = GetBoolPref("browser.download.manager.alertOnEXEOpen",
+                                     true);
 
     // On Vista and above, we rely on native security prompting for
     // downloaded content unless it's disabled.
     try {
       var sysInfo = Components.classes["@mozilla.org/system-info;1"]
                               .getService(Components.interfaces.nsIPropertyBag2);
       if (/^Windows/.test(sysInfo.getProperty("name")) &&
           (parseFloat(sysInfo.getProperty("version")) >= 6 &&
--- a/suite/common/utilityOverlay.js
+++ b/suite/common/utilityOverlay.js
@@ -316,17 +316,17 @@ 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://global/content/customizeToolbar.xul";
 
-  gCustomizeSheet = getBoolPref("toolbar.customization.usesheet", false);
+  gCustomizeSheet = 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;
 
@@ -1268,24 +1268,22 @@ function checkForMiddleClick(node, event
 function closeMenus(node)
 {
   for (; node; node = node.parentNode) {
     if (node instanceof Components.interfaces.nsIDOMXULPopupElement)
       node.hidePopup();
   }
 }
 
-function getBoolPref(prefname, def)
+function GetBoolPref(aPrefName, aDefaultValue)
 {
   try {
-    return Services.prefs.getBoolPref(prefname);
-  }
-  catch (er) {
-    return def;
-  }
+    return Services.prefs.getBoolPref(aPrefName);
+  } catch (e) {}
+  return aDefaultValue;
 }
 
 function GetIntPref(aPrefName, aDefaultValue)
 {
   try {
     return Services.prefs.getIntPref(aPrefName);
   } catch (e) {
     Components.utils.reportError("Couldn't get " + aPrefName + " pref: " + e);
@@ -1324,26 +1322,25 @@ function whereToOpenLink(e, ignoreButton
   var ctrl = e.ctrlKey;
   var meta = e.metaKey;
   var alt = e.altKey;
 
   // ignoreButton allows "middle-click paste" to use function without always opening in a new window.
   var middle = !ignoreButton && e.button == 1;
 
   if (meta || ctrl || middle) {
-    if (getBoolPref("browser.tabs.opentabfor.middleclick", true))
+    if (GetBoolPref("browser.tabs.opentabfor.middleclick", true))
       return ignoreBackground ? "tabfocused" : shift ? "tabshifted" : "tab";
-    if (getBoolPref("middlemouse.openNewWindow", true))
+    if (GetBoolPref("middlemouse.openNewWindow", true))
       return "window";
     if (middle)
       return null;
   }
   if (!ignoreSave) {
-    var saveKey = getBoolPref("ui.key.saveLink.shift", true) ? shift : alt;
-    if (saveKey)
+    if (GetBoolPref("ui.key.saveLink.shift", true) ? shift : alt)
       return "save";
   }
   if (alt || shift || meta || ctrl)
     return null;
   return "current";
 }
 
 /* openUILinkIn opens a URL in a place specified by the parameter |where|.
@@ -1390,17 +1387,17 @@ function openUILinkIn(url, where, aAllow
 
   var w = getTopWin();
 
   if (!w || where == "window") {
     return window.openDialog(getBrowserURL(), "_blank", "chrome,all,dialog=no", url,
                              null, null, aPostData, aAllowThirdPartyFixup);
   }
 
-  var loadInBackground = getBoolPref("browser.tabs.loadInBackground", false);
+  var loadInBackground = GetBoolPref("browser.tabs.loadInBackground", false);
 
   // reuse the browser if its current tab is empty
   if (isBrowserEmpty(w.getBrowser()))
     where = "current";
 
   switch (where) {
   case "current":
     w.loadURI(url, aReferrerURI, aPostData, aAllowThirdPartyFixup);
@@ -1447,17 +1444,17 @@ 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 = GetBoolPref("browser.tabs.loadInBackground", false);
 
   var browser = w.getBrowser();
   switch (where) {
   case "current":
     w.loadURI(urlArray[0], null, null, allowThirdPartyFixup);
     w.content.focus();
     break;
   case "tabshifted":