From 714e9c9074d9eb2f4063962d07bae6b4f02a1e7a Mon Sep 17 00:00:00 2001 From: Ascrod <32915892+Ascrod@users.noreply.github.com> Date: Sat, 13 Apr 2019 10:53:58 -0400 Subject: Issue #991 Part 7: Toolkit Components --- toolkit/components/asyncshutdown/AsyncShutdown.jsm | 29 +++------------- toolkit/components/blocklist/nsBlocklistService.js | 11 +----- .../jsdownloads/src/DownloadIntegration.jsm | 6 +--- toolkit/components/nsDefaultCLH.js | 8 +---- .../osfile/modules/osfile_async_front.jsm | 40 ++++++---------------- .../components/places/PlacesCategoriesStarter.js | 7 ++-- .../PlacesRemoteTabsAutocompleteProvider.jsm | 6 +--- toolkit/components/places/UnifiedComplete.js | 5 +-- toolkit/components/places/nsPlacesExpiration.js | 14 +++----- .../places/tests/unit/test_000_frecency.js | 10 ++---- .../components/printing/content/printPageSetup.js | 9 +---- toolkit/components/printing/content/printdialog.js | 10 +----- .../components/printing/content/printjoboptions.js | 9 +---- .../components/search/current/nsSearchService.js | 38 ++++++-------------- .../components/search/orginal/nsSearchService.js | 38 ++++++-------------- toolkit/components/telemetry/UITelemetry.jsm | 6 +--- .../url-classifier/nsUrlClassifierHashCompleter.js | 7 +--- .../urlformatter/tests/unit/test_urlformatter.js | 6 ++-- 18 files changed, 55 insertions(+), 204 deletions(-) (limited to 'toolkit') diff --git a/toolkit/components/asyncshutdown/AsyncShutdown.jsm b/toolkit/components/asyncshutdown/AsyncShutdown.jsm index 62ac36f42..9cdf9e126 100644 --- a/toolkit/components/asyncshutdown/AsyncShutdown.jsm +++ b/toolkit/components/asyncshutdown/AsyncShutdown.jsm @@ -79,12 +79,8 @@ const DELAY_WARNING_MS = 10 * 1000; // Crash the process if shutdown is really too long // (allowing for sleep). const PREF_DELAY_CRASH_MS = "toolkit.asyncshutdown.crash_timeout"; -var DELAY_CRASH_MS = 60 * 1000; // One minute -try { - DELAY_CRASH_MS = Services.prefs.getIntPref(PREF_DELAY_CRASH_MS); -} catch (ex) { - // Ignore errors -} +var DELAY_CRASH_MS = Services.prefs.getIntPref(PREF_DELAY_CRASH_MS, + 60 * 1000); // One minute Services.prefs.addObserver(PREF_DELAY_CRASH_MS, function() { DELAY_CRASH_MS = Services.prefs.getIntPref(PREF_DELAY_CRASH_MS); }, false); @@ -207,12 +203,7 @@ function log(msg, prefix = "", error = null) { } } const PREF_DEBUG_LOG = "toolkit.asyncshutdown.log"; -var DEBUG_LOG = false; -try { - DEBUG_LOG = Services.prefs.getBoolPref(PREF_DEBUG_LOG); -} catch (ex) { - // Ignore errors -} +var DEBUG_LOG = Services.prefs.getBoolPref(PREF_DEBUG_LOG, false); Services.prefs.addObserver(PREF_DEBUG_LOG, function() { DEBUG_LOG = Services.prefs.getBoolPref(PREF_DEBUG_LOG); }, false); @@ -360,12 +351,7 @@ this.AsyncShutdown = { * Access function getPhase. For testing purposes only. */ get _getPhase() { - let accepted = false; - try { - accepted = Services.prefs.getBoolPref("toolkit.asyncshutdown.testing"); - } catch (ex) { - // Ignore errors - } + let accepted = Services.prefs.getBoolPref("toolkit.asyncshutdown.testing", false); if (accepted) { return getPhase; } @@ -464,12 +450,7 @@ function getPhase(topic) { * notification. For testing purposes only. */ get _trigger() { - let accepted = false; - try { - accepted = Services.prefs.getBoolPref("toolkit.asyncshutdown.testing"); - } catch (ex) { - // Ignore errors - } + let accepted = Services.prefs.getBoolPref("toolkit.asyncshutdown.testing", false); if (accepted) { return () => spinner.observe(); } diff --git a/toolkit/components/blocklist/nsBlocklistService.js b/toolkit/components/blocklist/nsBlocklistService.js index 49033fc8f..b0115e25d 100644 --- a/toolkit/components/blocklist/nsBlocklistService.js +++ b/toolkit/components/blocklist/nsBlocklistService.js @@ -238,16 +238,7 @@ function getLocale() { /* Get the distribution pref values, from defaults only */ function getDistributionPrefValue(aPrefName) { - var prefValue = "default"; - - var defaults = gPref.getDefaultBranch(null); - try { - prefValue = defaults.getCharPref(aPrefName); - } catch (e) { - // use default when pref not found - } - - return prefValue; + return gPref.getDefaultBranch(null).getCharPref(aPrefName, "default"); } /** diff --git a/toolkit/components/jsdownloads/src/DownloadIntegration.jsm b/toolkit/components/jsdownloads/src/DownloadIntegration.jsm index 305284749..a6875ec48 100644 --- a/toolkit/components/jsdownloads/src/DownloadIntegration.jsm +++ b/toolkit/components/jsdownloads/src/DownloadIntegration.jsm @@ -368,11 +368,7 @@ this.DownloadIntegration = { */ getPreferredDownloadsDirectory: Task.async(function* () { let directoryPath = null; - let prefValue = 1; - - try { - prefValue = Services.prefs.getIntPref("browser.download.folderList"); - } catch(e) {} + let prefValue = Services.prefs.getIntPref("browser.download.folderList", 1); switch(prefValue) { case 0: // Desktop diff --git a/toolkit/components/nsDefaultCLH.js b/toolkit/components/nsDefaultCLH.js index a081bae49..affbf75ee 100644 --- a/toolkit/components/nsDefaultCLH.js +++ b/toolkit/components/nsDefaultCLH.js @@ -104,13 +104,7 @@ nsDefaultCLH.prototype = { // if the pref is missing, ignore the exception try { var chromeURI = prefs.getCharPref("toolkit.defaultChromeURI"); - - var flags = "chrome,dialog=no,all"; - try { - flags = prefs.getCharPref("toolkit.defaultChromeFeatures"); - } - catch (e) { } - + var flags = prefs.getCharPref("toolkit.defaultChromeFeatures", "chrome,dialog=no,all"); var wwatch = Components.classes["@mozilla.org/embedcomp/window-watcher;1"] .getService(nsIWindowWatcher); wwatch.openWindow(null, chromeURI, "_blank", diff --git a/toolkit/components/osfile/modules/osfile_async_front.jsm b/toolkit/components/osfile/modules/osfile_async_front.jsm index 93c7e66d6..1d1d7c73f 100644 --- a/toolkit/components/osfile/modules/osfile_async_front.jsm +++ b/toolkit/components/osfile/modules/osfile_async_front.jsm @@ -239,10 +239,9 @@ var Scheduler = this.Scheduler = { * Prepare to kill the OS.File worker after a few seconds. */ restartTimer: function(arg) { - let delay; - try { - delay = Services.prefs.getIntPref("osfile.reset_worker_delay"); - } catch(e) { + let delay = Services.prefs.getIntPref("osfile.reset_worker_delay", 0); + + if (!delay) { // Don't auto-shutdown if we don't have a delay preference set. return; } @@ -468,43 +467,25 @@ var Scheduler = this.Scheduler = { const PREF_OSFILE_LOG = "toolkit.osfile.log"; const PREF_OSFILE_LOG_REDIRECT = "toolkit.osfile.log.redirect"; -/** - * Safely read a PREF_OSFILE_LOG preference. - * Returns a value read or, in case of an error, oldPref or false. - * - * @param bool oldPref - * An optional value that the DEBUG flag was set to previously. - */ -function readDebugPref(prefName, oldPref = false) { - let pref = oldPref; - try { - pref = Services.prefs.getBoolPref(prefName); - } catch (x) { - // In case of an error when reading a pref keep it as is. - } - // If neither pref nor oldPref were set, default it to false. - return pref; -}; - /** * Listen to PREF_OSFILE_LOG changes and update gShouldLog flag * appropriately. */ Services.prefs.addObserver(PREF_OSFILE_LOG, function prefObserver(aSubject, aTopic, aData) { - SharedAll.Config.DEBUG = readDebugPref(PREF_OSFILE_LOG, SharedAll.Config.DEBUG); + SharedAll.Config.DEBUG = Services.prefs.getBoolPref(PREF_OSFILE_LOG, SharedAll.Config.DEBUG); if (Scheduler.launched) { // Don't start the worker just to set this preference. Scheduler.post("SET_DEBUG", [SharedAll.Config.DEBUG]); } }, false); -SharedAll.Config.DEBUG = readDebugPref(PREF_OSFILE_LOG, false); +SharedAll.Config.DEBUG = Services.prefs.getBoolPref(PREF_OSFILE_LOG, false); Services.prefs.addObserver(PREF_OSFILE_LOG_REDIRECT, function prefObserver(aSubject, aTopic, aData) { - SharedAll.Config.TEST = readDebugPref(PREF_OSFILE_LOG_REDIRECT, OS.Shared.TEST); + SharedAll.Config.TEST = Services.prefs.getBoolPref(PREF_OSFILE_LOG_REDIRECT, OS.Shared.TEST); }, false); -SharedAll.Config.TEST = readDebugPref(PREF_OSFILE_LOG_REDIRECT, false); +SharedAll.Config.TEST = Services.prefs.getBoolPref(PREF_OSFILE_LOG_REDIRECT, false); /** @@ -515,7 +496,7 @@ var nativeWheneverAvailable = true; const PREF_OSFILE_NATIVE = "toolkit.osfile.native"; Services.prefs.addObserver(PREF_OSFILE_NATIVE, function prefObserver(aSubject, aTopic, aData) { - nativeWheneverAvailable = readDebugPref(PREF_OSFILE_NATIVE, nativeWheneverAvailable); + nativeWheneverAvailable = Services.prefs.getBoolPref(PREF_OSFILE_NATIVE, nativeWheneverAvailable); }, false); @@ -557,10 +538,9 @@ Services.prefs.addObserver(PREF_OSFILE_TEST_SHUTDOWN_OBSERVER, function prefObserver() { // The temporary phase topic used to trigger the unclosed // phase warning. - let TOPIC = null; + let TOPIC = Services.prefs.getCharPref(PREF_OSFILE_TEST_SHUTDOWN_OBSERVER, + ""); try { - TOPIC = Services.prefs.getCharPref( - PREF_OSFILE_TEST_SHUTDOWN_OBSERVER); } catch (x) { } if (TOPIC) { diff --git a/toolkit/components/places/PlacesCategoriesStarter.js b/toolkit/components/places/PlacesCategoriesStarter.js index 560bd486a..bab14db52 100644 --- a/toolkit/components/places/PlacesCategoriesStarter.js +++ b/toolkit/components/places/PlacesCategoriesStarter.js @@ -77,11 +77,8 @@ PlacesCategoriesStarter.prototype = { break; case "idle-daily": // Once a week run places.sqlite maintenance tasks. - let lastMaintenance = 0; - try { - lastMaintenance = - Services.prefs.getIntPref("places.database.lastMaintenance"); - } catch (ex) {} + let lastMaintenance = + Services.prefs.getIntPref("places.database.lastMaintenance", 0); let nowSeconds = parseInt(Date.now() / 1000); if (lastMaintenance < nowSeconds - MAINTENANCE_INTERVAL_SECONDS) { PlacesDBUtils.maintenanceOnIdle(); diff --git a/toolkit/components/places/PlacesRemoteTabsAutocompleteProvider.jsm b/toolkit/components/places/PlacesRemoteTabsAutocompleteProvider.jsm index d23d5bc6e..c3bc501eb 100644 --- a/toolkit/components/places/PlacesRemoteTabsAutocompleteProvider.jsm +++ b/toolkit/components/places/PlacesRemoteTabsAutocompleteProvider.jsm @@ -95,11 +95,7 @@ function observe(subject, topic, data) { case "nsPref:changed": if (data == PREF_SHOW_REMOTE_ICONS) { - try { - showRemoteIcons = Services.prefs.getBoolPref(PREF_SHOW_REMOTE_ICONS); - } catch (_) { - showRemoteIcons = true; // no such pref - default is to show the icons. - } + showRemoteIcons = Services.prefs.getBoolPref(PREF_SHOW_REMOTE_ICONS, true); } break; diff --git a/toolkit/components/places/UnifiedComplete.js b/toolkit/components/places/UnifiedComplete.js index ec5f91111..7b63e29bb 100644 --- a/toolkit/components/places/UnifiedComplete.js +++ b/toolkit/components/places/UnifiedComplete.js @@ -437,10 +437,7 @@ XPCOMUtils.defineLazyGetter(this, "Prefs", () => { store.suggestTyped = prefs.get(...PREF_SUGGEST_HISTORY_ONLYTYPED); store.suggestSearches = prefs.get(...PREF_SUGGEST_SEARCHES); store.maxCharsForSearchSuggestions = prefs.get(...PREF_MAX_CHARS_FOR_SUGGEST); - store.keywordEnabled = true; - try { - store.keywordEnabled = Services.prefs.getBoolPref("keyword.enabled"); - } catch (ex) {} + store.keywordEnabled = Services.prefs.getBoolPref("keyword.enabled", true); // If history is not set, onlyTyped value should be ignored. if (!store.suggestHistory) { diff --git a/toolkit/components/places/nsPlacesExpiration.js b/toolkit/components/places/nsPlacesExpiration.js index 499934362..767a4d345 100644 --- a/toolkit/components/places/nsPlacesExpiration.js +++ b/toolkit/components/places/nsPlacesExpiration.js @@ -812,11 +812,8 @@ nsPlacesExpiration.prototype = { _loadPrefs: Task.async(function* () { // Get the user's limit, if it was set. - try { - // We want to silently fail since getIntPref throws if it does not exist, - // and use a default to fallback to. - this._urisLimit = this._prefBranch.getIntPref(PREF_MAX_URIS); - } catch (ex) { /* User limit not set */ } + this._urisLimit = this._prefBranch.getIntPref(PREF_MAX_URIS, + PREF_MAX_URIS_NOTSET); if (this._urisLimit < 0) { // Some testing code expects a pref change to be synchronous, so @@ -874,11 +871,8 @@ nsPlacesExpiration.prototype = { this._urisLimit); // Get the expiration interval value. - try { - // We want to silently fail since getIntPref throws if it does not exist, - // and use a default to fallback to. - this._interval = this._prefBranch.getIntPref(PREF_INTERVAL_SECONDS); - } catch (ex) { /* User interval not set */ } + this._interval = this._prefBranch.getIntPref(PREF_INTERVAL_SECONDS, + PREF_INTERVAL_SECONDS_NOTSET); if (this._interval <= 0) { this._interval = PREF_INTERVAL_SECONDS_NOTSET; } diff --git a/toolkit/components/places/tests/unit/test_000_frecency.js b/toolkit/components/places/tests/unit/test_000_frecency.js index 0a7347a02..64ee86b59 100644 --- a/toolkit/components/places/tests/unit/test_000_frecency.js +++ b/toolkit/components/places/tests/unit/test_000_frecency.js @@ -56,14 +56,8 @@ var prefPrefix = "places.frecency."; function* task_initializeBucket(bucket) { let [cutoffName, weightName] = bucket; // get pref values - var weight = 0, cutoff = 0; - try { - weight = prefs.getIntPref(prefPrefix + weightName); - } catch (ex) {} - try { - cutoff = prefs.getIntPref(prefPrefix + cutoffName); - } catch (ex) {} - + var weight = prefs.getIntPref(prefPrefix + weightName, 0); + var cutoff = prefs.getIntPref(prefPrefix + cutoffName, 0); if (cutoff < 1) return; diff --git a/toolkit/components/printing/content/printPageSetup.js b/toolkit/components/printing/content/printPageSetup.js index 31eb1bdd3..6bcd97207 100644 --- a/toolkit/components/printing/content/printPageSetup.js +++ b/toolkit/components/printing/content/printPageSetup.js @@ -65,14 +65,7 @@ function initDialog() // --------------------------------------------------- function isListOfPrinterFeaturesAvailable() { - var has_printerfeatures = false; - - try { - has_printerfeatures = gPrefs.getBoolPref("print.tmp.printerfeatures." + gPrintSettings.printerName + ".has_special_printerfeatures"); - } catch (ex) { - } - - return has_printerfeatures; + return gPrefs.getBoolPref("print.tmp.printerfeatures." + gPrintSettings.printerName + ".has_special_printerfeatures", false); } // --------------------------------------------------- diff --git a/toolkit/components/printing/content/printdialog.js b/toolkit/components/printing/content/printdialog.js index e5a38ddce..f9ed94bad 100644 --- a/toolkit/components/printing/content/printdialog.js +++ b/toolkit/components/printing/content/printdialog.js @@ -79,15 +79,7 @@ function stripTrailingWhitespace(element) // --------------------------------------------------- function getPrinterDescription(printerName) { - var s = ""; - - try { - /* This may not work with non-ASCII test (see bug 235763 comment #16) */ - s = gPrefs.getCharPref("print.printer_" + printerName + ".printer_description") - } catch (e) { - } - - return s; + return gPrefs.getCharPref("print.printer_" + printerName + ".printer_description", "") } // --------------------------------------------------- diff --git a/toolkit/components/printing/content/printjoboptions.js b/toolkit/components/printing/content/printjoboptions.js index 26f3ffd85..098358940 100644 --- a/toolkit/components/printing/content/printjoboptions.js +++ b/toolkit/components/printing/content/printjoboptions.js @@ -33,14 +33,7 @@ function checkDouble(element, maxVal) // --------------------------------------------------- function isListOfPrinterFeaturesAvailable() { - var has_printerfeatures = false; - - try { - has_printerfeatures = gPrefs.getBoolPref("print.tmp.printerfeatures." + gPrintSettings.printerName + ".has_special_printerfeatures"); - } catch (ex) { - } - - return has_printerfeatures; + return gPrefs.getBoolPref("print.tmp.printerfeatures." + gPrintSettings.printerName + ".has_special_printerfeatures", false); } // --------------------------------------------------- diff --git a/toolkit/components/search/current/nsSearchService.js b/toolkit/components/search/current/nsSearchService.js index 2a8601078..66866540a 100644 --- a/toolkit/components/search/current/nsSearchService.js +++ b/toolkit/components/search/current/nsSearchService.js @@ -390,12 +390,7 @@ function isPartnerBuild() { // Method to determine if we should be using geo-specific defaults function geoSpecificDefaultsEnabled() { - let geoSpecificDefaults = false; - try { - geoSpecificDefaults = Services.prefs.getBoolPref("browser.search.geoSpecificDefaults"); - } catch (e) {} - - return geoSpecificDefaults; + return Services.prefs.getBoolPref("browser.search.geoSpecificDefaults", false); } // Some notes on countryCode and region prefs: @@ -500,11 +495,7 @@ function isUSTimezone() { // If it fails we don't touch that pref so isUS() does its normal thing. var ensureKnownCountryCode = Task.async(function* (ss) { // If we have a country-code already stored in our prefs we trust it. - let countryCode; - try { - countryCode = Services.prefs.getCharPref("browser.search.countryCode"); - } catch (e) {} - + let countryCode = Services.prefs.getCharPref("browser.search.countryCode", ""); if (!countryCode) { // We don't have it cached, so fetch it. fetchCountryCode() will call // storeCountryCode if it gets a result (even if that happens after the @@ -726,10 +717,7 @@ var fetchRegionDefault = (ss) => new Promise(resolve => { // Append the optional cohort value. const cohortPref = "browser.search.cohort"; - let cohort; - try { - cohort = Services.prefs.getCharPref(cohortPref); - } catch (e) {} + let cohort = Services.prefs.getCharPref(cohortPref, ""); if (cohort) endpoint += "/" + cohort; @@ -993,19 +981,13 @@ function QueryParameter(aName, aValue, aPurpose) { function ParamSubstitution(aParamValue, aSearchTerms, aEngine) { var value = aParamValue; - var distributionID = Services.appinfo.distributionID; - try { - distributionID = Services.prefs.getCharPref(BROWSER_SEARCH_PREF + "distributionID"); - } - catch (ex) { } - var official = MOZ_OFFICIAL; - try { - if (Services.prefs.getBoolPref(BROWSER_SEARCH_PREF + "official")) - official = "official"; - else - official = "unofficial"; - } - catch (ex) { } + var distributionID = Services.prefs.getCharPref(BROWSER_SEARCH_PREF + "distributionID", + Services.appinfo.distributionID || ""); + var official; + if (Services.prefs.getBoolPref(BROWSER_SEARCH_PREF + "official", MOZ_OFFICIAL)) + official = "official"; + else + official = "unofficial"; // Custom search parameters. These are only available to default search // engines. diff --git a/toolkit/components/search/orginal/nsSearchService.js b/toolkit/components/search/orginal/nsSearchService.js index 5b5ce7a57..c4481df5f 100644 --- a/toolkit/components/search/orginal/nsSearchService.js +++ b/toolkit/components/search/orginal/nsSearchService.js @@ -418,12 +418,7 @@ function isPartnerBuild() { // Method to determine if we should be using geo-specific defaults function geoSpecificDefaultsEnabled() { - let geoSpecificDefaults = false; - try { - geoSpecificDefaults = Services.prefs.getBoolPref("browser.search.geoSpecificDefaults"); - } catch(e) {} - - return geoSpecificDefaults; + return Services.prefs.getBoolPref("browser.search.geoSpecificDefaults", false); } // Some notes on countryCode and region prefs: @@ -528,11 +523,7 @@ function isUSTimezone() { // If it fails we don't touch that pref so isUS() does its normal thing. var ensureKnownCountryCode = Task.async(function* () { // If we have a country-code already stored in our prefs we trust it. - let countryCode; - try { - countryCode = Services.prefs.getCharPref("browser.search.countryCode"); - } catch(e) {} - + let countryCode = Services.prefs.getCharPref("browser.search.countryCode", ""); if (!countryCode) { // We don't have it cached, so fetch it. fetchCountryCode() will call // storeCountryCode if it gets a result (even if that happens after the @@ -732,10 +723,7 @@ var fetchRegionDefault = () => new Promise(resolve => { // Append the optional cohort value. const cohortPref = "browser.search.cohort"; - let cohort; - try { - cohort = Services.prefs.getCharPref(cohortPref); - } catch(e) {} + let cohort = Services.prefs.getCharPref(cohortPref, ""); if (cohort) endpoint += "/" + cohort; @@ -1034,19 +1022,13 @@ function QueryParameter(aName, aValue, aPurpose) { function ParamSubstitution(aParamValue, aSearchTerms, aEngine) { var value = aParamValue; - var distributionID = MOZ_DISTRIBUTION_ID; - try { - distributionID = Services.prefs.getCharPref(BROWSER_SEARCH_PREF + "distributionID"); - } - catch (ex) { } - var official = MOZ_OFFICIAL; - try { - if (Services.prefs.getBoolPref(BROWSER_SEARCH_PREF + "official")) - official = "official"; - else - official = "unofficial"; - } - catch (ex) { } + var distributionID = Services.prefs.getCharPref(BROWSER_SEARCH_PREF + "distributionID", + MOZ_DISTRIBUTION_ID || ""); + var official; + if (Services.prefs.getBoolPref(BROWSER_SEARCH_PREF + "official", MOZ_OFFICIAL)) + official = "official"; + else + official = "unofficial"; // Custom search parameters. These are only available to default search // engines. diff --git a/toolkit/components/telemetry/UITelemetry.jsm b/toolkit/components/telemetry/UITelemetry.jsm index bd7a34b72..231b52e23 100644 --- a/toolkit/components/telemetry/UITelemetry.jsm +++ b/toolkit/components/telemetry/UITelemetry.jsm @@ -36,11 +36,7 @@ this.UITelemetry = { Services.obs.addObserver(this, "profile-before-change", false); // Pick up the current value. - try { - this._enabled = Services.prefs.getBoolPref(PREF_ENABLED); - } catch (e) { - this._enabled = false; - } + this._enabled = Services.prefs.getBoolPref(PREF_ENABLED, false); return this._enabled; }, diff --git a/toolkit/components/url-classifier/nsUrlClassifierHashCompleter.js b/toolkit/components/url-classifier/nsUrlClassifierHashCompleter.js index ba4bf225a..5d462c90d 100644 --- a/toolkit/components/url-classifier/nsUrlClassifierHashCompleter.js +++ b/toolkit/components/url-classifier/nsUrlClassifierHashCompleter.js @@ -20,12 +20,7 @@ Cu.import("resource://gre/modules/NetUtil.jsm"); // Log only if browser.safebrowsing.debug is true function log(...stuff) { - let logging = null; - try { - logging = Services.prefs.getBoolPref("browser.safebrowsing.debug"); - } catch(e) { - return; - } + let logging = Services.prefs.getBoolPref("browser.safebrowsing.debug", false); if (!logging) { return; } diff --git a/toolkit/components/urlformatter/tests/unit/test_urlformatter.js b/toolkit/components/urlformatter/tests/unit/test_urlformatter.js index 393b0dc33..6f218822a 100644 --- a/toolkit/components/urlformatter/tests/unit/test_urlformatter.js +++ b/toolkit/components/urlformatter/tests/unit/test_urlformatter.js @@ -27,11 +27,9 @@ function run_test() { QueryInterface(Ci.nsIXULRuntime); var abi = macutils && macutils.isUniversalBinary ? "Universal-gcc3" : appInfo.XPCOMABI; - let channel = "default"; let defaults = prefs.QueryInterface(Ci.nsIPrefService).getDefaultBranch(null); - try { - channel = defaults.getCharPref("app.update.channel"); - } catch (e) {} + let channel = defaults.getCharPref("app.update.channel", "default"); + // Set distribution values. defaults.setCharPref("distribution.id", "bacon"); defaults.setCharPref("distribution.version", "1.0"); -- cgit v1.2.3 From 8757548a3e5b5cc4d159d61eb4a12c7af1be548e Mon Sep 17 00:00:00 2001 From: Ascrod <32915892+Ascrod@users.noreply.github.com> Date: Sat, 13 Apr 2019 11:22:15 -0400 Subject: Issue #991 Part 8: Toolkit everything else --- toolkit/content/widgets/browser.xml | 23 +------ toolkit/content/widgets/preferences.xml | 8 +-- toolkit/content/widgets/scrollbox.xml | 27 ++------ toolkit/modules/NewTabUtils.jsm | 20 +++--- toolkit/modules/PermissionsUtils.jsm | 5 +- toolkit/modules/UpdateUtils.jsm | 18 +---- .../secondscreen/SimpleServiceDiscovery.jsm | 5 +- toolkit/mozapps/downloads/nsHelperAppDlg.js | 5 +- toolkit/mozapps/extensions/AddonManager.jsm | 79 ++++++---------------- toolkit/mozapps/extensions/DeferredSave.jsm | 7 +- toolkit/mozapps/extensions/GMPUtils.jsm | 8 +-- .../mozapps/extensions/LightweightThemeManager.jsm | 15 +--- .../mozapps/extensions/internal/AddonLogging.jsm | 7 +- .../extensions/internal/AddonRepository.jsm | 32 ++------- .../extensions/internal/AddonUpdateChecker.jsm | 14 +--- .../extensions/internal/XPIProviderUtils.js | 5 +- 16 files changed, 62 insertions(+), 216 deletions(-) (limited to 'toolkit') diff --git a/toolkit/content/widgets/browser.xml b/toolkit/content/widgets/browser.xml index 9c72e86d8..11ed998cc 100644 --- a/toolkit/content/widgets/browser.xml +++ b/toolkit/content/widgets/browser.xml @@ -19,14 +19,7 @@ if (this.getAttribute("autoscroll") == "false") return false; - var enabled = true; - try { - enabled = this.mPrefs.getBoolPref("general.autoScroll"); - } - catch (ex) { - } - - return enabled; + return this.mPrefs.getBoolPref("general.autoScroll", true); ]]> @@ -1427,18 +1420,8 @@ return; // Toggle browse with caret mode - var browseWithCaretOn = false; - var warn = true; - - try { - warn = this.mPrefs.getBoolPref(kPrefWarnOnEnable); - } catch (ex) { - } - - try { - browseWithCaretOn = this.mPrefs.getBoolPref(kPrefCaretBrowsingOn); - } catch (ex) { - } + var browseWithCaretOn = this.mPrefs.getBoolPref(kPrefCaretBrowsingOn, false); + var warn = this.mPrefs.getBoolPref(kPrefWarnOnEnable, true); if (warn && !browseWithCaretOn) { var checkValue = {value:false}; var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"] diff --git a/toolkit/content/widgets/preferences.xml b/toolkit/content/widgets/preferences.xml index 9fb2ac7ea..11de03246 100644 --- a/toolkit/content/widgets/preferences.xml +++ b/toolkit/content/widgets/preferences.xml @@ -893,12 +893,8 @@ diff --git a/toolkit/content/widgets/scrollbox.xml b/toolkit/content/widgets/scrollbox.xml index ff57a5911..219b7cb5e 100644 --- a/toolkit/content/widgets/scrollbox.xml +++ b/toolkit/content/widgets/scrollbox.xml @@ -80,13 +80,8 @@ @@ -99,13 +94,8 @@ if (this.hasAttribute("smoothscroll")) { this._smoothScroll = (this.getAttribute("smoothscroll") == "true"); } else { - try { - this._smoothScroll = this._prefBranch - .getBoolPref("toolkit.scrollbox.smoothScroll"); - } - catch (ex) { - this._smoothScroll = true; - } + this._smoothScroll = this._prefBranch + .getBoolPref("toolkit.scrollbox.smoothScroll", true); } } return this._smoothScroll; @@ -737,12 +727,9 @@ threshold); }, @@ -1543,10 +1530,8 @@ this.AddonRepository = { // Create url from preference, returning null if preference does not exist _formatURLPref: function AddonRepo_formatURLPref(aPreference, aSubstitutions) { - let url = null; - try { - url = Services.prefs.getCharPref(aPreference); - } catch(e) { + let url = Services.prefs.getCharPref(aPreference, ""); + if (!url) { logger.warn("_formatURLPref: Couldn't get pref: " + aPreference); return null; } @@ -1639,10 +1624,7 @@ var AddonDatabase = { // Create a blank addons.json file this._saveDBToDisk(); - let dbSchema = 0; - try { - dbSchema = Services.prefs.getIntPref(PREF_GETADDONS_DB_SCHEMA); - } catch (e) {} + let dbSchema = Services.prefs.getIntPref(PREF_GETADDONS_DB_SCHEMA, 0); if (dbSchema < DB_MIN_JSON_SCHEMA) { let results = yield new Promise((resolve, reject) => { diff --git a/toolkit/mozapps/extensions/internal/AddonUpdateChecker.jsm b/toolkit/mozapps/extensions/internal/AddonUpdateChecker.jsm index c06dca1d5..a475f7f1f 100644 --- a/toolkit/mozapps/extensions/internal/AddonUpdateChecker.jsm +++ b/toolkit/mozapps/extensions/internal/AddonUpdateChecker.jsm @@ -608,12 +608,7 @@ function UpdateParser(aId, aUpdateKey, aUrl, aObserver) { this.observer = aObserver; this.url = aUrl; - let requireBuiltIn = true; - try { - requireBuiltIn = Services.prefs.getBoolPref(PREF_UPDATE_REQUIREBUILTINCERTS); - } - catch (e) { - } + let requireBuiltIn = Services.prefs.getBoolPref(PREF_UPDATE_REQUIREBUILTINCERTS, true); logger.debug("Requesting " + aUrl); try { @@ -651,12 +646,7 @@ UpdateParser.prototype = { this.request = null; this._doneAt = new Error("place holder"); - let requireBuiltIn = true; - try { - requireBuiltIn = Services.prefs.getBoolPref(PREF_UPDATE_REQUIREBUILTINCERTS); - } - catch (e) { - } + let requireBuiltIn = Services.prefs.getBoolPref(PREF_UPDATE_REQUIREBUILTINCERTS, true); try { CertUtils.checkCert(request.channel, !requireBuiltIn); diff --git a/toolkit/mozapps/extensions/internal/XPIProviderUtils.js b/toolkit/mozapps/extensions/internal/XPIProviderUtils.js index f2420bd1a..69d774e4a 100644 --- a/toolkit/mozapps/extensions/internal/XPIProviderUtils.js +++ b/toolkit/mozapps/extensions/internal/XPIProviderUtils.js @@ -1410,10 +1410,7 @@ this.XPIDatabase = { // when a lightweight theme is applied for example) text += "\r\n[ThemeDirs]\r\n"; - let dssEnabled = false; - try { - dssEnabled = Services.prefs.getBoolPref(PREF_EM_DSS_ENABLED); - } catch (e) {} + let dssEnabled = Services.prefs.getBoolPref(PREF_EM_DSS_ENABLED, false); let themes = []; if (dssEnabled) { -- cgit v1.2.3 From 40fc72376411587e7bf9985fb9545eca1c9aaa8e Mon Sep 17 00:00:00 2001 From: Ascrod <32915892+Ascrod@users.noreply.github.com> Date: Sat, 13 Apr 2019 17:27:59 -0400 Subject: Pref try/catch block fixup. Tag #991. --- toolkit/components/search/current/nsSearchService.js | 13 ++++++++----- toolkit/components/search/orginal/nsSearchService.js | 13 ++++++++----- 2 files changed, 16 insertions(+), 10 deletions(-) (limited to 'toolkit') diff --git a/toolkit/components/search/current/nsSearchService.js b/toolkit/components/search/current/nsSearchService.js index 66866540a..db90e5150 100644 --- a/toolkit/components/search/current/nsSearchService.js +++ b/toolkit/components/search/current/nsSearchService.js @@ -983,11 +983,14 @@ function ParamSubstitution(aParamValue, aSearchTerms, aEngine) { var distributionID = Services.prefs.getCharPref(BROWSER_SEARCH_PREF + "distributionID", Services.appinfo.distributionID || ""); - var official; - if (Services.prefs.getBoolPref(BROWSER_SEARCH_PREF + "official", MOZ_OFFICIAL)) - official = "official"; - else - official = "unofficial"; + var official = MOZ_OFFICIAL; + try { + if (Services.prefs.getBoolPref(BROWSER_SEARCH_PREF + "official")) + official = "official"; + else + official = "unofficial"; + } + catch (ex) { } // Custom search parameters. These are only available to default search // engines. diff --git a/toolkit/components/search/orginal/nsSearchService.js b/toolkit/components/search/orginal/nsSearchService.js index c4481df5f..1cec5f966 100644 --- a/toolkit/components/search/orginal/nsSearchService.js +++ b/toolkit/components/search/orginal/nsSearchService.js @@ -1024,11 +1024,14 @@ function ParamSubstitution(aParamValue, aSearchTerms, aEngine) { var distributionID = Services.prefs.getCharPref(BROWSER_SEARCH_PREF + "distributionID", MOZ_DISTRIBUTION_ID || ""); - var official; - if (Services.prefs.getBoolPref(BROWSER_SEARCH_PREF + "official", MOZ_OFFICIAL)) - official = "official"; - else - official = "unofficial"; + var official = MOZ_OFFICIAL; + try { + if (Services.prefs.getBoolPref(BROWSER_SEARCH_PREF + "official")) + official = "official"; + else + official = "unofficial"; + } + catch (ex) { } // Custom search parameters. These are only available to default search // engines. -- cgit v1.2.3 From 21b4cb27cabecdb5580c01891801c9259689ec87 Mon Sep 17 00:00:00 2001 From: Ascrod <32915892+Ascrod@users.noreply.github.com> Date: Thu, 18 Apr 2019 20:37:23 -0400 Subject: Remove unused try/catch block. Tag #991. --- toolkit/components/osfile/modules/osfile_async_front.jsm | 3 --- 1 file changed, 3 deletions(-) (limited to 'toolkit') diff --git a/toolkit/components/osfile/modules/osfile_async_front.jsm b/toolkit/components/osfile/modules/osfile_async_front.jsm index 1d1d7c73f..9f3b7fb21 100644 --- a/toolkit/components/osfile/modules/osfile_async_front.jsm +++ b/toolkit/components/osfile/modules/osfile_async_front.jsm @@ -540,9 +540,6 @@ Services.prefs.addObserver(PREF_OSFILE_TEST_SHUTDOWN_OBSERVER, // phase warning. let TOPIC = Services.prefs.getCharPref(PREF_OSFILE_TEST_SHUTDOWN_OBSERVER, ""); - try { - } catch (x) { - } if (TOPIC) { // Generate a phase, add a blocker. // Note that this can work only if AsyncShutdown itself has been -- cgit v1.2.3