diff options
Diffstat (limited to 'toolkit/mozapps/update')
-rw-r--r-- | toolkit/mozapps/update/content/updates.js | 28 | ||||
-rw-r--r-- | toolkit/mozapps/update/nsUpdateService.js | 89 |
2 files changed, 35 insertions, 82 deletions
diff --git a/toolkit/mozapps/update/content/updates.js b/toolkit/mozapps/update/content/updates.js index 6e8de7275..9996014b5 100644 --- a/toolkit/mozapps/update/content/updates.js +++ b/toolkit/mozapps/update/content/updates.js @@ -85,28 +85,6 @@ function openUpdateURL(event) { } /** - * Gets a preference value, handling the case where there is no default. - * @param func - * The name of the preference function to call, on nsIPrefBranch - * @param preference - * The name of the preference - * @param defaultValue - * The default value to return in the event the preference has - * no setting - * @returns The value of the preference, or undefined if there was no - * user or default value. - */ -function getPref(func, preference, defaultValue) { - try { - return Services.prefs[func](preference); - } - catch (e) { - LOG("General", "getPref - failed to get preference: " + preference); - } - return defaultValue; -} - -/** * A set of shared data and control functions for the wizard as a whole. */ var gUpdates = { @@ -320,7 +298,7 @@ var gUpdates = { onLoad: function() { this.wiz = document.documentElement; - gLogEnabled = getPref("getBoolPref", PREF_APP_UPDATE_LOG, false); + gLogEnabled = Services.prefs.getBoolPref(PREF_APP_UPDATE_LOG, false); this.strings = document.getElementById("updateStrings"); var brandStrings = document.getElementById("brandStrings"); @@ -601,7 +579,7 @@ var gNoUpdatesPage = { LOG("gNoUpdatesPage", "onPageShow - could not select an appropriate " + "update. Either there were no updates or |selectUpdate| failed"); - if (getPref("getBoolPref", PREF_APP_UPDATE_ENABLED, true)) + if (Services.prefs.getBoolPref(PREF_APP_UPDATE_ENABLED, true)) document.getElementById("noUpdatesAutoEnabled").hidden = false; else document.getElementById("noUpdatesAutoDisabled").hidden = false; @@ -1309,7 +1287,7 @@ var gFinishedPage = { moreElevatedLinkLabel.setAttribute("hidden", "false"); } - if (getPref("getBoolPref", PREF_APP_UPDATE_TEST_LOOP, false)) { + if (Services.prefs.getBoolPref(PREF_APP_UPDATE_TEST_LOOP, false)) { setTimeout(function () { gUpdates.wiz.getButton("finish").click(); }, UPDATE_TEST_LOOP_INTERVAL); } diff --git a/toolkit/mozapps/update/nsUpdateService.js b/toolkit/mozapps/update/nsUpdateService.js index 4e2d66a5c..8b0167de6 100644 --- a/toolkit/mozapps/update/nsUpdateService.js +++ b/toolkit/mozapps/update/nsUpdateService.js @@ -164,7 +164,7 @@ XPCOMUtils.defineLazyModuleGetter(this, "UpdateUtils", "resource://gre/modules/UpdateUtils.jsm"); XPCOMUtils.defineLazyGetter(this, "gLogEnabled", function aus_gLogEnabled() { - return getPref("getBoolPref", PREF_APP_UPDATE_LOG, false); + return Services.prefs.getBoolPref(PREF_APP_UPDATE_LOG, false); }); XPCOMUtils.defineLazyGetter(this, "gUpdateBundle", function aus_gUpdateBundle() { @@ -494,7 +494,7 @@ XPCOMUtils.defineLazyGetter(this, "gCanStageUpdatesSession", function aus_gCSUS( */ function getCanStageUpdates() { // If staging updates are disabled, then just bail out! - if (!getPref("getBoolPref", PREF_APP_UPDATE_STAGING_ENABLED, false)) { + if (!Services.prefs.getBoolPref(PREF_APP_UPDATE_STAGING_ENABLED, false)) { LOG("getCanStageUpdates - staging updates is disabled by preference " + PREF_APP_UPDATE_STAGING_ENABLED); return false; @@ -514,7 +514,7 @@ XPCOMUtils.defineLazyGetter(this, "gCanCheckForUpdates", function aus_gCanCheckF // If the administrator has disabled app update and locked the preference so // users can't check for updates. This preference check is ok in this lazy // getter since locked prefs don't change until the application is restarted. - var enabled = getPref("getBoolPref", PREF_APP_UPDATE_ENABLED, true); + var enabled = Services.prefs.getBoolPref(PREF_APP_UPDATE_ENABLED, true); if (!enabled && Services.prefs.prefIsLocked(PREF_APP_UPDATE_ENABLED)) { LOG("gCanCheckForUpdates - unable to automatically check for updates, " + "the preference is disabled and admistratively locked."); @@ -551,27 +551,6 @@ function LOG(string) { } /** - * Gets a preference value, handling the case where there is no default. - * @param func - * The name of the preference function to call, on nsIPrefBranch - * @param preference - * The name of the preference - * @param defaultValue - * The default value to return in the event the preference has - * no setting - * @return The value of the preference, or undefined if there was no - * user or default value. - */ -function getPref(func, preference, defaultValue) { - try { - return Services.prefs[func](preference); - } - catch (e) { - } - return defaultValue; -} - -/** * Convert a string containing binary values to hex. */ function binaryToHex(input) { @@ -898,16 +877,15 @@ function handleUpdateFailure(update, errorCode) { } if (update.errorCode == ELEVATION_CANCELED) { - let cancelations = getPref("getIntPref", PREF_APP_UPDATE_CANCELATIONS, 0); + let cancelations = Services.prefs.getIntPref(PREF_APP_UPDATE_CANCELATIONS, 0); cancelations++; Services.prefs.setIntPref(PREF_APP_UPDATE_CANCELATIONS, cancelations); if (AppConstants.platform == "macosx") { - let osxCancelations = getPref("getIntPref", - PREF_APP_UPDATE_CANCELATIONS_OSX, 0); + let osxCancelations = Services.prefs.getIntPref(PREF_APP_UPDATE_CANCELATIONS_OSX, 0); osxCancelations++; Services.prefs.setIntPref(PREF_APP_UPDATE_CANCELATIONS_OSX, osxCancelations); - let maxCancels = getPref("getIntPref", + let maxCancels = Services.prefs.getIntPref( PREF_APP_UPDATE_CANCELATIONS_OSX_MAX, DEFAULT_CANCELATIONS_OSX_MAX); // Prevent the preference from setting a value greater than 5. @@ -1177,8 +1155,8 @@ function Update(update) { this.showNeverForVersion = false; this.unsupported = false; this.channel = "default"; - this.promptWaitTime = getPref("getIntPref", PREF_APP_UPDATE_PROMPTWAITTIME, 43200); - this.backgroundInterval = getPref("getIntPref", PREF_APP_UPDATE_BACKGROUNDINTERVAL, + this.promptWaitTime = Services.prefs.getIntPref(PREF_APP_UPDATE_PROMPTWAITTIME, 43200); + this.backgroundInterval = Services.prefs.getIntPref(PREF_APP_UPDATE_BACKGROUNDINTERVAL, DOWNLOAD_BACKGROUND_INTERVAL); // Null <update>, assume this is a message container and do no @@ -1558,7 +1536,7 @@ UpdateService.prototype = { break; case "nsPref:changed": if (data == PREF_APP_UPDATE_LOG) { - gLogEnabled = getPref("getBoolPref", PREF_APP_UPDATE_LOG, false); + gLogEnabled = Services.prefs.getBoolPref(PREF_APP_UPDATE_LOG, false); } break; case "profile-change-net-teardown": // fall thru @@ -1795,11 +1773,11 @@ UpdateService.prototype = { // Send the error code to telemetry AUSTLMY.pingCheckExError(this._pingSuffix, update.errorCode); update.errorCode = BACKGROUNDCHECK_MULTIPLE_FAILURES; - let errCount = getPref("getIntPref", PREF_APP_UPDATE_BACKGROUNDERRORS, 0); + let errCount = Services.prefs.getIntPref(PREF_APP_UPDATE_BACKGROUNDERRORS, 0); errCount++; Services.prefs.setIntPref(PREF_APP_UPDATE_BACKGROUNDERRORS, errCount); // Don't allow the preference to set a value greater than 20 for max errors. - let maxErrors = Math.min(getPref("getIntPref", PREF_APP_UPDATE_BACKGROUNDMAXERRORS, 10), 20); + let maxErrors = Math.min(Services.prefs.getIntPref(PREF_APP_UPDATE_BACKGROUNDMAXERRORS, 10), 20); if (errCount >= maxErrors) { let prompter = Cc["@mozilla.org/updates/update-prompt;1"]. @@ -1969,7 +1947,7 @@ UpdateService.prototype = { AUSTLMY.pingCheckCode(this._pingSuffix, AUSTLMY.CHK_INVALID_DEFAULT_URL); } - } else if (!getPref("getBoolPref", PREF_APP_UPDATE_ENABLED, true)) { + } else if (!Services.prefs.getBoolPref(PREF_APP_UPDATE_ENABLED, true)) { AUSTLMY.pingCheckCode(this._pingSuffix, AUSTLMY.CHK_PREF_DISABLED); } else if (!hasUpdateMutex()) { AUSTLMY.pingCheckCode(this._pingSuffix, AUSTLMY.CHK_NO_MUTEX); @@ -2027,7 +2005,7 @@ UpdateService.prototype = { // (see bug 350636). let neverPrefName = PREFBRANCH_APP_UPDATE_NEVER + aUpdate.appVersion; if (aUpdate.showNeverForVersion && - getPref("getBoolPref", neverPrefName, false)) { + Services.prefs.getBoolPref(neverPrefName, false)) { LOG("UpdateService:selectUpdate - skipping update because the " + "preference " + neverPrefName + " is true"); lastCheckCode = AUSTLMY.CHK_UPDATE_NEVER_PREF; @@ -2058,7 +2036,7 @@ UpdateService.prototype = { let update = minorUpdate || majorUpdate; if (AppConstants.platform == "macosx" && update) { if (getElevationRequired()) { - let installAttemptVersion = getPref("getCharPref", + let installAttemptVersion = Services.prefs.getCharPref( PREF_APP_UPDATE_ELEVATE_VERSION, null); if (vc.compare(installAttemptVersion, update.appVersion) != 0) { @@ -2072,12 +2050,9 @@ UpdateService.prototype = { Services.prefs.clearUserPref(PREF_APP_UPDATE_ELEVATE_NEVER); } } else { - let numCancels = getPref("getIntPref", - PREF_APP_UPDATE_CANCELATIONS_OSX, 0); - let rejectedVersion = getPref("getCharPref", - PREF_APP_UPDATE_ELEVATE_NEVER, ""); - let maxCancels = getPref("getIntPref", - PREF_APP_UPDATE_CANCELATIONS_OSX_MAX, + let numCancels = Services.prefs.getIntPref(PREF_APP_UPDATE_CANCELATIONS_OSX, 0); + let rejectedVersion = Services.prefs.getCharPref(PREF_APP_UPDATE_ELEVATE_NEVER, ""); + let maxCancels = Services.prefs.getIntPref(PREF_APP_UPDATE_CANCELATIONS_OSX_MAX, DEFAULT_CANCELATIONS_OSX_MAX); if (numCancels >= maxCancels) { LOG("UpdateService:selectUpdate - the user requires elevation to " + @@ -2136,7 +2111,7 @@ UpdateService.prototype = { return; } - var updateEnabled = getPref("getBoolPref", PREF_APP_UPDATE_ENABLED, true); + var updateEnabled = Services.prefs.getBoolPref(PREF_APP_UPDATE_ENABLED, true); if (!updateEnabled) { AUSTLMY.pingCheckCode(this._pingSuffix, AUSTLMY.CHK_PREF_DISABLED); LOG("UpdateService:_selectAndInstallUpdate - not prompting because " + @@ -2152,7 +2127,7 @@ UpdateService.prototype = { if (update.unsupported) { LOG("UpdateService:_selectAndInstallUpdate - update not supported for " + "this system"); - if (!getPref("getBoolPref", PREF_APP_UPDATE_NOTIFIEDUNSUPPORTED, false)) { + if (!Services.prefs.getBoolPref(PREF_APP_UPDATE_NOTIFIEDUNSUPPORTED, false)) { LOG("UpdateService:_selectAndInstallUpdate - notifying that the " + "update is not supported for this system"); this._showPrompt(update); @@ -2193,7 +2168,7 @@ UpdateService.prototype = { return; } - if (!getPref("getBoolPref", PREF_APP_UPDATE_AUTO, true)) { + if (!Services.prefs.getBoolPref(PREF_APP_UPDATE_AUTO, true)) { LOG("UpdateService:_selectAndInstallUpdate - prompting because silent " + "install is disabled"); AUSTLMY.pingCheckCode(this._pingSuffix, AUSTLMY.CHK_SHOWPROMPT_PREF); @@ -2733,7 +2708,7 @@ UpdateManager.prototype = { Services.obs.notifyObservers(null, "update-staged", update.state); // Only prompt when the UI isn't already open. - let windowType = getPref("getCharPref", PREF_APP_UPDATE_ALTWINDOWTYPE, null); + let windowType = Services.prefs.getCharPref(PREF_APP_UPDATE_ALTWINDOWTYPE, null); if (Services.wm.getMostRecentWindow(UPDATE_WINDOW_NAME) || windowType && Services.wm.getMostRecentWindow(windowType)) { return; @@ -2813,7 +2788,7 @@ Checker.prototype = { this._forced = force; // Use the override URL if specified. - let url = getPref("getCharPref", PREF_APP_UPDATE_URL_OVERRIDE, null); + let url = Services.prefs.getCharPref(PREF_APP_UPDATE_URL_OVERRIDE, null); // Otherwise, construct the update URL from component parts. if (!url) { @@ -3016,7 +2991,7 @@ Checker.prototype = { */ _enabled: true, get enabled() { - return getPref("getBoolPref", PREF_APP_UPDATE_ENABLED, true) && + return Services.prefs.getBoolPref(PREF_APP_UPDATE_ENABLED, true) && gCanCheckForUpdates && hasUpdateMutex() && this._enabled; }, @@ -3502,11 +3477,11 @@ Downloader.prototype = { var shouldRegisterOnlineObserver = false; var shouldRetrySoon = false; var deleteActiveUpdate = false; - var retryTimeout = getPref("getIntPref", PREF_APP_UPDATE_SOCKET_RETRYTIMEOUT, + var retryTimeout = Services.prefs.getIntPref(PREF_APP_UPDATE_SOCKET_RETRYTIMEOUT, DEFAULT_SOCKET_RETRYTIMEOUT); // Prevent the preference from setting a value greater than 10000. retryTimeout = Math.min(retryTimeout, 10000); - var maxFail = getPref("getIntPref", PREF_APP_UPDATE_SOCKET_MAXERRORS, + var maxFail = Services.prefs.getIntPref(PREF_APP_UPDATE_SOCKET_MAXERRORS, DEFAULT_SOCKET_MAX_ERRORS); // Prevent the preference from setting a value greater than 20. maxFail = Math.min(maxFail, 20); @@ -3762,7 +3737,7 @@ UpdatePrompt.prototype = { * See nsIUpdateService.idl */ showUpdateAvailable: function UP_showUpdateAvailable(update) { - if (getPref("getBoolPref", PREF_APP_UPDATE_SILENT, false) || + if (Services.prefs.getBoolPref(PREF_APP_UPDATE_SILENT, false) || this._getUpdateWindow() || this._getAltUpdateWindow()) { return; } @@ -3775,7 +3750,7 @@ UpdatePrompt.prototype = { * See nsIUpdateService.idl */ showUpdateDownloaded: function UP_showUpdateDownloaded(update, background) { - if (background && getPref("getBoolPref", PREF_APP_UPDATE_SILENT, false)) { + if (background && Services.prefs.getBoolPref(PREF_APP_UPDATE_SILENT, false)) { return; } // Trigger the display of the hamburger menu badge. @@ -3797,7 +3772,7 @@ UpdatePrompt.prototype = { * See nsIUpdateService.idl */ showUpdateError: function UP_showUpdateError(update) { - if (getPref("getBoolPref", PREF_APP_UPDATE_SILENT, false) || + if (Services.prefs.getBoolPref(PREF_APP_UPDATE_SILENT, false) || this._getAltUpdateWindow()) return; @@ -3840,7 +3815,7 @@ UpdatePrompt.prototype = { * See nsIUpdateService.idl */ showUpdateElevationRequired: function UP_showUpdateElevationRequired() { - if (getPref("getBoolPref", PREF_APP_UPDATE_SILENT, false) || + if (Services.prefs.getBoolPref(PREF_APP_UPDATE_SILENT, false) || this._getAltUpdateWindow()) { return; } @@ -3864,7 +3839,7 @@ UpdatePrompt.prototype = { * application update user interface window. */ _getAltUpdateWindow: function UP__getAltUpdateWindow() { - let windowType = getPref("getCharPref", PREF_APP_UPDATE_ALTWINDOWTYPE, null); + let windowType = Services.prefs.getCharPref(PREF_APP_UPDATE_ALTWINDOWTYPE, null); if (!windowType) return null; return Services.wm.getMostRecentWindow(windowType); @@ -3916,7 +3891,7 @@ UpdatePrompt.prototype = { var idleService = Cc["@mozilla.org/widget/idleservice;1"]. getService(Ci.nsIIdleService); // Don't allow the preference to set a value greater than 600 seconds for the idle time. - const IDLE_TIME = Math.min(getPref("getIntPref", PREF_APP_UPDATE_IDLETIME, 60), 600); + const IDLE_TIME = Math.min(Services.prefs.getIntPref(PREF_APP_UPDATE_IDLETIME, 60), 600); if (idleService.idleTime / 1000 >= IDLE_TIME) { this._showUI(parent, uri, features, name, page, update); return; @@ -3961,7 +3936,7 @@ UpdatePrompt.prototype = { getService(Ci.nsIIdleService); // Don't allow the preference to set a value greater than 600 seconds for the idle time. - const IDLE_TIME = Math.min(getPref("getIntPref", PREF_APP_UPDATE_IDLETIME, 60), 600); + const IDLE_TIME = Math.min(Services.prefs.getIntPref(PREF_APP_UPDATE_IDLETIME, 60), 600); if (idleService.idleTime / 1000 >= IDLE_TIME) { this._showUI(parent, uri, features, name, page, update); } else { |