diff options
author | Moonchild <mcwerewolf@wolfbeast.com> | 2019-04-20 11:17:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-20 11:17:30 +0200 |
commit | e0116ac2b78eb4e621a4d0769e01f8358a6d661c (patch) | |
tree | fe2898874f0be34a8425281ecba2cb8cb59fb210 /application/basilisk/components | |
parent | 32577bdb3d2471c0e5ce4cfd0501a820157230cb (diff) | |
parent | 21b4cb27cabecdb5580c01891801c9259689ec87 (diff) | |
download | UXP-e0116ac2b78eb4e621a4d0769e01f8358a6d661c.tar UXP-e0116ac2b78eb4e621a4d0769e01f8358a6d661c.tar.gz UXP-e0116ac2b78eb4e621a4d0769e01f8358a6d661c.tar.lz UXP-e0116ac2b78eb4e621a4d0769e01f8358a6d661c.tar.xz UXP-e0116ac2b78eb4e621a4d0769e01f8358a6d661c.zip |
Merge pull request #1041 from Ascrod/default-pref
Clean up try/catch blocks for preferences
Diffstat (limited to 'application/basilisk/components')
9 files changed, 25 insertions, 102 deletions
diff --git a/application/basilisk/components/customizableui/CustomizableUI.jsm b/application/basilisk/components/customizableui/CustomizableUI.jsm index 31126b37c..d56d63d99 100644 --- a/application/basilisk/components/customizableui/CustomizableUI.jsm +++ b/application/basilisk/components/customizableui/CustomizableUI.jsm @@ -158,10 +158,7 @@ var gUIStateBeforeReset = { XPCOMUtils.defineLazyGetter(this, "log", () => { let scope = {}; Cu.import("resource://gre/modules/Console.jsm", scope); - let debug; - try { - debug = Services.prefs.getBoolPref(kPrefCustomizationDebug); - } catch (ex) {} + let debug = Services.prefs.getBoolPref(kPrefCustomizationDebug, false); let consoleOptions = { maxLogLevel: debug ? "all" : "log", prefix: "CustomizableUI", @@ -1914,16 +1911,10 @@ var CustomizableUIInternal = { // state immediately when a browser window opens, which is important for // other consumers of this API. loadSavedState: function() { - let state = null; - try { - state = Services.prefs.getCharPref(kPrefCustomizationState); - } catch (e) { - log.debug("No saved state found"); - // This will fail if nothing has been customized, so silently fall back to - // the defaults. - } - + let state = Services.prefs.getCharPref(kPrefCustomizationState, ""); if (!state) { + log.debug("No saved state found"); + // Nothing has been customized, so silently fall back to the defaults. return; } try { @@ -2208,10 +2199,7 @@ var CustomizableUIInternal = { this.notifyListeners("onWidgetAdded", widget.id, widget.currentArea, widget.currentPosition); } else if (widgetMightNeedAutoAdding) { - let autoAdd = true; - try { - autoAdd = Services.prefs.getBoolPref(kPrefCustomizationAutoAdd); - } catch (e) {} + let autoAdd = Services.prefs.getBoolPref(kPrefCustomizationAutoAdd, true); // If the widget doesn't have an existing placement, and it hasn't been // seen before, then add it to its default area so it can be used. diff --git a/application/basilisk/components/customizableui/CustomizableWidgets.jsm b/application/basilisk/components/customizableui/CustomizableWidgets.jsm index 9e8f0ec78..d4a191a97 100644 --- a/application/basilisk/components/customizableui/CustomizableWidgets.jsm +++ b/application/basilisk/components/customizableui/CustomizableWidgets.jsm @@ -40,10 +40,7 @@ const kWidePanelItemClass = "panel-wide-item"; XPCOMUtils.defineLazyGetter(this, "log", () => { let scope = {}; Cu.import("resource://gre/modules/Console.jsm", scope); - let debug; - try { - debug = Services.prefs.getBoolPref(kPrefCustomizationDebug); - } catch (ex) {} + let debug = Services.prefs.getBoolPref(kPrefCustomizationDebug, false); let consoleOptions = { maxLogLevel: debug ? "all" : "log", prefix: "CustomizableWidgets", diff --git a/application/basilisk/components/customizableui/CustomizeMode.jsm b/application/basilisk/components/customizableui/CustomizeMode.jsm index 4365ddfbc..2958655d2 100644 --- a/application/basilisk/components/customizableui/CustomizeMode.jsm +++ b/application/basilisk/components/customizableui/CustomizeMode.jsm @@ -40,9 +40,7 @@ let gDebug; XPCOMUtils.defineLazyGetter(this, "log", () => { let scope = {}; Cu.import("resource://gre/modules/Console.jsm", scope); - try { - gDebug = Services.prefs.getBoolPref(kPrefCustomizationDebug); - } catch (ex) {} + gDebug = Services.prefs.getBoolPref(kPrefCustomizationDebug, false); let consoleOptions = { maxLogLevel: gDebug ? "all" : "log", prefix: "CustomizeMode", @@ -1503,10 +1501,7 @@ CustomizeMode.prototype = { if (!AppConstants.CAN_DRAW_IN_TITLEBAR) { return; } - let drawInTitlebar = true; - try { - drawInTitlebar = Services.prefs.getBoolPref(kDrawInTitlebarPref); - } catch (ex) { } + let drawInTitlebar = Services.prefs.getBoolPref(kDrawInTitlebarPref, true); let button = this.document.getElementById("customization-titlebar-visibility-button"); // Drawing in the titlebar means 'hiding' the titlebar: if (drawInTitlebar) { diff --git a/application/basilisk/components/distribution.js b/application/basilisk/components/distribution.js index 589129a5a..c30e4dcfe 100644 --- a/application/basilisk/components/distribution.js +++ b/application/basilisk/components/distribution.js @@ -22,10 +22,7 @@ XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils", this.DistributionCustomizer = function DistributionCustomizer() { // For parallel xpcshell testing purposes allow loading the distribution.ini // file from the profile folder through an hidden pref. - let loadFromProfile = false; - try { - loadFromProfile = Services.prefs.getBoolPref("distribution.testing.loadFromProfile"); - } catch (ex) {} + loadFromProfile = Services.prefs.getBoolPref("distribution.testing.loadFromProfile", false); let dirSvc = Cc["@mozilla.org/file/directory_service;1"]. getService(Ci.nsIProperties); try { @@ -60,13 +57,7 @@ DistributionCustomizer.prototype = { }, get _locale() { - let locale; - try { - locale = this._prefs.getCharPref("general.useragent.locale"); - } - catch (e) { - locale = "en-US"; - } + let locale = this._prefs.getCharPref("general.useragent.locale", "en-US"); this.__defineGetter__("_locale", () => locale); return this._locale; }, @@ -291,11 +282,7 @@ DistributionCustomizer.prototype = { this._ini.getString("Global", "id") + ".bookmarksProcessed"; } - let bmProcessed = false; - try { - bmProcessed = this._prefs.getBoolPref(bmProcessedPref); - } - catch (e) {} + let bmProcessed = this._prefs.getBoolPref(bmProcessedPref, false); if (!bmProcessed) { if (sections["BookmarksMenu"]) diff --git a/application/basilisk/components/feeds/FeedWriter.js b/application/basilisk/components/feeds/FeedWriter.js index 20f1399b0..ceb2a7e2f 100644 --- a/application/basilisk/components/feeds/FeedWriter.js +++ b/application/basilisk/components/feeds/FeedWriter.js @@ -19,12 +19,7 @@ function LOG(str) { let prefB = Cc["@mozilla.org/preferences-service;1"]. getService(Ci.nsIPrefBranch); - let shouldLog = false; - try { - shouldLog = prefB.getBoolPref("feeds.log"); - } - catch (ex) { - } + let shouldLog = prefB.getBoolPref("feeds.log", false); if (shouldLog) dump("*** Feeds: " + str + "\n"); diff --git a/application/basilisk/components/feeds/WebContentConverter.js b/application/basilisk/components/feeds/WebContentConverter.js index 2cb5cd145..159eca7c2 100644 --- a/application/basilisk/components/feeds/WebContentConverter.js +++ b/application/basilisk/components/feeds/WebContentConverter.js @@ -187,13 +187,8 @@ const Utils = { // check if it is in the black list let pb = Services.prefs; - let allowed; - try { - allowed = pb.getBoolPref(PREF_HANDLER_EXTERNAL_PREFIX + "." + aProtocol); - } - catch (e) { - allowed = pb.getBoolPref(PREF_HANDLER_EXTERNAL_PREFIX + "-default"); - } + let allowed = pb.getBoolPref(PREF_HANDLER_EXTERNAL_PREFIX + "." + aProtocol, + pb.getBoolPref(PREF_HANDLER_EXTERNAL_PREFIX + "-default")); if (!allowed) { throw this.getSecurityError( `Not allowed to register a protocol handler for ${aProtocol}`, diff --git a/application/basilisk/components/nsBrowserContentHandler.js b/application/basilisk/components/nsBrowserContentHandler.js index 74144fc1b..d65e52594 100644 --- a/application/basilisk/components/nsBrowserContentHandler.js +++ b/application/basilisk/components/nsBrowserContentHandler.js @@ -100,20 +100,14 @@ const OVERRIDE_NEW_BUILD_ID = 3; * OVERRIDE_NONE otherwise. */ function needHomepageOverride(prefb) { - var savedmstone = null; - try { - savedmstone = prefb.getCharPref("browser.startup.homepage_override.mstone"); - } catch (e) {} + var savedmstone = prefb.getCharPref("browser.startup.homepage_override.mstone", ""); if (savedmstone == "ignore") return OVERRIDE_NONE; var mstone = Services.appinfo.platformVersion; - var savedBuildID = null; - try { - savedBuildID = prefb.getCharPref("browser.startup.homepage_override.buildID"); - } catch (e) {} + var savedBuildID = prefb.getCharPref("browser.startup.homepage_override.buildID", ""); var buildID = Services.appinfo.platformBuildID; @@ -489,10 +483,7 @@ nsBrowserContentHandler.prototype = { // URL if we do end up showing an overridePage. This makes it possible // to have the overridePage's content vary depending on the version we're // upgrading from. - let old_mstone = "unknown"; - try { - old_mstone = Services.prefs.getCharPref("browser.startup.homepage_override.mstone"); - } catch (ex) {} + let old_mstone = Services.prefs.getCharPref("browser.startup.homepage_override.mstone", "unknown"); override = needHomepageOverride(prefb); if (override != OVERRIDE_NONE) { switch (override) { diff --git a/application/basilisk/components/nsBrowserGlue.js b/application/basilisk/components/nsBrowserGlue.js index 82de33240..b4256523f 100644 --- a/application/basilisk/components/nsBrowserGlue.js +++ b/application/basilisk/components/nsBrowserGlue.js @@ -961,10 +961,7 @@ BrowserGlue.prototype = { // Offer to reset a user's profile if it hasn't been used for 60 days. const OFFER_PROFILE_RESET_INTERVAL_MS = 60 * 24 * 60 * 60 * 1000; let lastUse = Services.appinfo.replacedLockTime; - let disableResetPrompt = false; - try { - disableResetPrompt = Services.prefs.getBoolPref("browser.disableResetPrompt"); - } catch (e) {} + let disableResetPrompt = Services.prefs.getBoolPref("browser.disableResetPrompt", false); if (!disableResetPrompt && lastUse && Date.now() - lastUse >= OFFER_PROFILE_RESET_INTERVAL_MS) { @@ -1505,10 +1502,7 @@ BrowserGlue.prototype = { } catch (ex) {} // Support legacy bookmarks.html format for apps that depend on that format. - let autoExportHTML = false; - try { - autoExportHTML = Services.prefs.getBoolPref("browser.bookmarks.autoExportHTML"); - } catch (ex) {} // Do not export. + let autoExportHTML = Services.prefs.getBoolPref("browser.bookmarks.autoExportHTML", false); // Do not export. if (autoExportHTML) { // Sqlite.jsm and Places shutdown happen at profile-before-change, thus, // to be on the safe side, this should run earlier. @@ -1578,10 +1572,7 @@ BrowserGlue.prototype = { // An import operation is about to run. // Don't try to recreate smart bookmarks if autoExportHTML is true or // smart bookmarks are disabled. - let smartBookmarksVersion = 0; - try { - smartBookmarksVersion = Services.prefs.getIntPref("browser.places.smartBookmarksVersion"); - } catch (ex) {} + let smartBookmarksVersion = Services.prefs.getIntPref("browser.places.smartBookmarksVersion", 0); if (!autoExportHTML && smartBookmarksVersion != -1) Services.prefs.setIntPref("browser.places.smartBookmarksVersion", 0); @@ -1932,10 +1923,7 @@ BrowserGlue.prototype = { // Refactor urlbar suggestion preferences to make it extendable and // allow new suggestion types (e.g: search suggestions). let types = ["history", "bookmark", "openpage"]; - let defaultBehavior = 0; - try { - defaultBehavior = Services.prefs.getIntPref("browser.urlbar.default.behavior"); - } catch (ex) {} + let defaultBehavior = Services.prefs.getIntPref("browser.urlbar.default.behavior", 0); try { let autocompleteEnabled = Services.prefs.getBoolPref("browser.urlbar.autocomplete.enabled"); if (!autocompleteEnabled) { @@ -1988,12 +1976,8 @@ BrowserGlue.prototype = { if (currentUIVersion < 30) { // Convert old devedition theme pref to lightweight theme storage - let lightweightThemeSelected = false; - let selectedThemeID = null; - try { - lightweightThemeSelected = Services.prefs.prefHasUserValue("lightweightThemes.selectedThemeID"); - selectedThemeID = Services.prefs.getCharPref("lightweightThemes.selectedThemeID"); - } catch (e) {} + let lightweightThemeSelected = Services.prefs.prefHasUserValue("lightweightThemes.selectedThemeID", false); + let selectedThemeID = Services.prefs.getCharPref("lightweightThemes.selectedThemeID", ""); let defaultThemeSelected = false; try { @@ -2143,10 +2127,7 @@ BrowserGlue.prototype = { const MAX_RESULTS = 10; // Get current smart bookmarks version. If not set, create them. - let smartBookmarksCurrentVersion = 0; - try { - smartBookmarksCurrentVersion = Services.prefs.getIntPref(SMART_BOOKMARKS_PREF); - } catch (ex) {} + let smartBookmarksCurrentVersion = Services.prefs.getIntPref(SMART_BOOKMARKS_PREF, 0); // If version is current, or smart bookmarks are disabled, bail out. if (smartBookmarksCurrentVersion == -1 || diff --git a/application/basilisk/components/sync/aboutSyncTabs.js b/application/basilisk/components/sync/aboutSyncTabs.js index 410494b5b..4808c052f 100644 --- a/application/basilisk/components/sync/aboutSyncTabs.js +++ b/application/basilisk/components/sync/aboutSyncTabs.js @@ -254,13 +254,7 @@ var RemoteTabViewer = { _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 */ - } + lastFetch = Services.prefs.getIntPref("services.sync.lastTabFetch", 0); let now = Math.floor(Date.now() / 1000); if (now - lastFetch < 30) { |