Bug 686936 - Switch suite/browser and suite/common to use GetIntPref helper r=neil
authorIan Neal <iann_cvs@blueyonder.co.uk>
Fri, 16 Sep 2011 23:50:58 +0100
changeset 9188 6d68cf105f8d5e702d964676cdebbedfd2d7b3a7
parent 9187 8809beb3c8dd3c2f55acdc16f40248f27c6c5920
child 9189 295d8878ce8a49a2d5104b2372fe16e1a70fba09
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
bugs686936
Bug 686936 - Switch suite/browser and suite/common to use GetIntPref helper r=neil
suite/browser/navigator.js
suite/common/sidebar/sidebarOverlay.js
suite/common/sync/aboutSyncTabs.js
suite/common/utilityOverlay.js
suite/common/viewZoomOverlay.js
--- a/suite/browser/navigator.js
+++ b/suite/browser/navigator.js
@@ -610,33 +610,29 @@ 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 {
-      try {
-        switch (Services.prefs.getIntPref("browser.windows.loadOnNewWindow"))
-        {
-          default:
-            uriArray = ["about:blank"];
-            break;
-          case 1:
-            uriArray = getHomePage();
-            break;
-          case 2:
-            var history = Components.classes["@mozilla.org/browser/global-history;2"]
-                                    .getService(Components.interfaces.nsIBrowserHistory);
-            uriArray = [history.lastPageVisited];
-            break;
-        }
-      } catch(e) {
-        uriArray = ["about:blank"];
+      switch (GetIntPref("browser.windows.loadOnNewWindow", 0))
+      {
+        default:
+          uriArray = ["about:blank"];
+          break;
+        case 1:
+          uriArray = getHomePage();
+          break;
+        case 2:
+          var history = Components.classes["@mozilla.org/browser/global-history;2"]
+                                  .getService(Components.interfaces.nsIBrowserHistory);
+          uriArray = [history.lastPageVisited];
+          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);
   }
     
@@ -1349,34 +1345,30 @@ function BrowserOpenWindow()
       break;
   }
 }
 
 function BrowserOpenTab()
 {
   if (!gInPrintPreviewMode) {
     var uriToLoad;
-    try {
-      switch ( Services.prefs.getIntPref("browser.tabs.loadOnNewTab") )
-      {
-        default:
-          uriToLoad = "about:blank";
-          break;
-        case 1:
-          uriToLoad = GetLocalizedStringPref("browser.startup.homepage");
-          break;
-        case 2:
-          uriToLoad = gBrowser ? getWebNavigation().currentURI.spec
-                               : Components.classes["@mozilla.org/browser/global-history;2"]
-                                           .getService(Components.interfaces.nsIBrowserHistory)
-                                           .lastPageVisited;
-          break;
-      }
-    } catch(e) {
-      uriToLoad = "about:blank";
+    switch (GetIntPref("browser.tabs.loadOnNewTab", 0))
+    {
+      default:
+        uriToLoad = "about:blank";
+        break;
+      case 1:
+        uriToLoad = GetLocalizedStringPref("browser.startup.homepage");
+        break;
+      case 2:
+        uriToLoad = gBrowser ? getWebNavigation().currentURI.spec
+                             : Components.classes["@mozilla.org/browser/global-history;2"]
+                                         .getService(Components.interfaces.nsIBrowserHistory)
+                                         .lastPageVisited;
+        break;
     }
 
     // Open a new window if someone requests a new tab when no browser window is open
     if (!gBrowser) {
       openDialog(getBrowserURL(), "_blank", "chrome,all,dialog=no", uriToLoad);
       return;
     }
 
@@ -1405,22 +1397,17 @@ function selectFileToOpen(label, prefRoo
   fp.init(window, gNavigatorBundle.getString(label), nsIFilePicker.modeOpen);
   fp.appendFilters(nsIFilePicker.filterAll | nsIFilePicker.filterText | nsIFilePicker.filterImages |
                    nsIFilePicker.filterXML | nsIFilePicker.filterHTML);
 
   const filterIndexPref = prefRoot + "filterIndex";
   const lastDirPref = prefRoot + "dir";
 
   // use a pref to remember the filterIndex selected by the user.
-  var index = 0;
-  try {
-    index = Services.prefs.getIntPref(filterIndexPref);
-  } catch (ex) {
-  }
-  fp.filterIndex = index;
+  fp.filterIndex = GetIntPref(filterIndexPref, 0);
 
   // use a pref to remember the displayDirectory selected by the user.
   try {
     fp.displayDirectory = Services.prefs.getComplexValue(lastDirPref,
                               Components.interfaces.nsILocalFile);
   } catch (ex) {
   }
 
--- a/suite/common/sidebar/sidebarOverlay.js
+++ b/suite/common/sidebar/sidebarOverlay.js
@@ -771,25 +771,18 @@ 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
-      try
-      {
-        gNumTabsInViewPref = prefs.getIntPref("sidebar.num_tabs_in_view");
-      }
-      catch (ex)
-      {
-        gNumTabsInViewPref = 8; // failover default
-      }
+      // Obtain the pref for limiting the number of tabs in view, defaults to 8.
+      gNumTabsInViewPref = 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
@@ -213,21 +213,17 @@ let 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 = 0;
-      try {
-        lastFetch = Services.prefs.getIntPref("services.sync.lastTabFetch");
-      }
-      catch (e) { /* Just use the default value of 0 */ }
+      let lastFetch = 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.Clients.lastSync == 0)
       Weave.Clients.sync();
--- a/suite/common/utilityOverlay.js
+++ b/suite/common/utilityOverlay.js
@@ -1110,26 +1110,22 @@ function BrowserOnCommand(event)
 
   // If the event came from an ssl error page, it is probably either the "Add
   // Exception" or "Get Me Out Of Here" button
   if (/^about:neterror\?e=nssBadCert/.test(ownerDoc.documentURI) ||
       /^about:certerror\?/.test(ownerDoc.documentURI)) {
     if (ot.getAttribute('anonid') == 'exceptionDialogButton') {
       var params = { exceptionAdded : false };
 
-      try {
-        switch (Services.prefs.getIntPref("browser.ssl_override_behavior")) {
-          case 2 : // Pre-fetch & pre-populate.
-            params.prefetchCert = true;
-            // Fall through.
-          case 1 : // Pre-populate.
-            params.location = ownerDoc.location.href;
-        }
-      } catch (e) {
-        Components.utils.reportError("Couldn't get ssl_override pref: " + e);
+      switch (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',
                         '', 'chrome,centerscreen,modal', params);
 
       // If the user added the exception cert, attempt to reload the page
       if (params.exceptionAdded)
         ownerDoc.location.reload();
--- a/suite/common/viewZoomOverlay.js
+++ b/suite/common/viewZoomOverlay.js
@@ -138,21 +138,17 @@ var FullZoom = {
     else if (event.metaKey)
       pref += ".withmetakey";
     else
       pref += ".withnokey";
 
     pref += ".action";
 
     // Don't do anything if this isn't a "zoom" scroll event.
-    var isZoomEvent = false;
-    try {
-      isZoomEvent = (Services.prefs.getIntPref(pref) == MOUSE_SCROLL_ZOOM);
-    } catch (e) {}
-    if (!isZoomEvent)
+    if (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