From 7ae6b830df2e6a732536174da4e21a536c73b4cd Mon Sep 17 00:00:00 2001 From: "Brian R. Bondy" Date: Wed, 12 Jun 2013 10:31:09 -0400 Subject: [PATCH] Bug 866229 - Use metro enabled pref. r=rstrong --- browser/metro/base/content/aboutPanel.js | 17 ++++++++-- toolkit/mozapps/update/nsUpdateService.js | 32 +++++++++++++++++++ toolkit/mozapps/update/test/chrome/utils.js | 21 +++++++++--- toolkit/mozapps/update/test/shared.js | 1 + .../update/test/unit/head_update.js.in | 1 + 5 files changed, 66 insertions(+), 6 deletions(-) diff --git a/browser/metro/base/content/aboutPanel.js b/browser/metro/base/content/aboutPanel.js index 0f287e1dc807..ff62ad4dc5ee 100644 --- a/browser/metro/base/content/aboutPanel.js +++ b/browser/metro/base/content/aboutPanel.js @@ -2,6 +2,9 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. +// Services = object with smart getters for common XPCOM services +Components.utils.import("resource://gre/modules/Services.jsm"); + var gAppUpdater; var AboutPanelUI = { get _aboutVersionLabel() { @@ -162,11 +165,21 @@ appUpdater.prototype = // true when updating is enabled. get updateEnabled() { + let updatesEnabled = true; try { - return Services.prefs.getBoolPref("app.update.enabled"); + updatesEnabled = Services.prefs.getBoolPref("app.update.metro.enabled"); } catch (e) { } - return true; // Firefox default is true + if (!updatesEnabled) { + return false; + } + + try { + updatesEnabled = Services.prefs.getBoolPref("app.update.enabled") + } + catch (e) { } + + return updatesEnabled; }, // true when updating in background is enabled. diff --git a/toolkit/mozapps/update/nsUpdateService.js b/toolkit/mozapps/update/nsUpdateService.js index 5cee849a6008..700b8e6b6464 100644 --- a/toolkit/mozapps/update/nsUpdateService.js +++ b/toolkit/mozapps/update/nsUpdateService.js @@ -32,6 +32,7 @@ const PREF_APP_UPDATE_CERT_ERRORS = "app.update.cert.errors"; const PREF_APP_UPDATE_CERT_MAXERRORS = "app.update.cert.maxErrors"; const PREF_APP_UPDATE_CERT_REQUIREBUILTIN = "app.update.cert.requireBuiltIn"; const PREF_APP_UPDATE_ENABLED = "app.update.enabled"; +const PREF_APP_UPDATE_METRO_ENABLED = "app.update.metro.enabled"; const PREF_APP_UPDATE_IDLETIME = "app.update.idletime"; const PREF_APP_UPDATE_INCOMPATIBLE_MODE = "app.update.incompatible.mode"; const PREF_APP_UPDATE_INTERVAL = "app.update.interval"; @@ -642,6 +643,25 @@ XPCOMUtils.defineLazyGetter(this, "gCanStageUpdates", function aus_gCanStageUpda return true; }); +XPCOMUtils.defineLazyGetter(this, "gMetroUpdatesEnabled", function aus_gMetroUpdatesEnabled() { +#ifdef XP_WIN +#ifdef MOZ_METRO + let metroUtils = Cc["@mozilla.org/windows-metroutils;1"]. + createInstance(Ci.nsIWinMetroUtils); + if (metroUtils && metroUtils.immersive) { + let metroUpdate = getPref("getBoolPref", PREF_APP_UPDATE_METRO_ENABLED, true); + if (!metroUpdate) { + LOG("gMetroUpdatesEnabled - unable to automatically check for metro" + + " updates, disabled by pref"); + return false; + } + } +#endif +#endif + + return true; +}); + XPCOMUtils.defineLazyGetter(this, "gCanCheckForUpdates", function aus_gCanCheckForUpdates() { // If the administrator has locked the app update functionality // OFF - this is not just a user setting, so disable the manual @@ -653,6 +673,10 @@ XPCOMUtils.defineLazyGetter(this, "gCanCheckForUpdates", function aus_gCanCheckF return false; } + if (!gMetroUpdatesEnabled) { + return false; + } + // If we don't know the binary platform we're updating, we can't update. if (!gABI) { LOG("gCanCheckForUpdates - unable to check for updates, unknown ABI"); @@ -2395,6 +2419,10 @@ UpdateService.prototype = { return; } + if (!gMetroUpdatesEnabled) { + return; + } + if (!gCanApplyUpdates) { LOG("UpdateService:_selectAndInstallUpdate - the user is unable to " + "apply updates... prompting"); @@ -3364,6 +3392,10 @@ Checker.prototype = { */ _enabled: true, get enabled() { + if (!gMetroUpdatesEnabled) { + return false; + } + return getPref("getBoolPref", PREF_APP_UPDATE_ENABLED, true) && gCanCheckForUpdates && this._enabled; }, diff --git a/toolkit/mozapps/update/test/chrome/utils.js b/toolkit/mozapps/update/test/chrome/utils.js index 16a80d67afc4..3567f21daa2d 100644 --- a/toolkit/mozapps/update/test/chrome/utils.js +++ b/toolkit/mozapps/update/test/chrome/utils.js @@ -167,10 +167,11 @@ var gCloseWindowTimeoutCounter = 0; // The following vars are for restoring previous preference values (if present) // when the test finishes. -var gAppUpdateEnabled; // app.update.enabled -var gAppUpdateURLDefault; // app.update.url (default prefbranch) -var gAppUpdateURL; // app.update.url.override -var gExtUpdateURL; // extensions.update.url +var gAppUpdateEnabled; // app.update.enabled +var gAppUpdateMetroEnabled; // app.update.metro.enabled +var gAppUpdateURLDefault; // app.update.url (default prefbranch) +var gAppUpdateURL; // app.update.url.override +var gExtUpdateURL; // extensions.update.url var gTestCounter = -1; var gWin; @@ -809,6 +810,11 @@ function setupPrefs() { } Services.prefs.setBoolPref(PREF_APP_UPDATE_ENABLED, true) + if (Services.prefs.prefHasUserValue(PREF_APP_UPDATE_METRO_ENABLED)) { + gAppUpdateMetroEnabled = Services.prefs.getBoolPref(PREF_APP_UPDATE_METRO_ENABLED); + } + Services.prefs.setBoolPref(PREF_APP_UPDATE_METRO_ENABLED, true) + if (Services.prefs.prefHasUserValue(PREF_EXTENSIONS_UPDATE_URL)) { gExtUpdateURL = Services.prefs.getCharPref(PREF_EXTENSIONS_UPDATE_URL); } @@ -845,6 +851,13 @@ function resetPrefs() { Services.prefs.clearUserPref(PREF_APP_UPDATE_ENABLED); } + if (gAppUpdateMetroEnabled !== undefined) { + Services.prefs.setBoolPref(PREF_APP_UPDATE_METRO_ENABLED, gAppUpdateMetroEnabled); + } + else if (Services.prefs.prefHasUserValue(PREF_APP_UPDATE_METRO_ENABLED)) { + Services.prefs.clearUserPref(PREF_APP_UPDATE_METRO_ENABLED); + } + if (gExtUpdateURL !== undefined) { Services.prefs.setCharPref(PREF_EXTENSIONS_UPDATE_URL, gExtUpdateURL); } diff --git a/toolkit/mozapps/update/test/shared.js b/toolkit/mozapps/update/test/shared.js index 5171257569f8..c8a2e7123b6f 100644 --- a/toolkit/mozapps/update/test/shared.js +++ b/toolkit/mozapps/update/test/shared.js @@ -23,6 +23,7 @@ const PREF_APP_UPDATE_CERT_MAXERRORS = "app.update.cert.maxErrors"; const PREF_APP_UPDATE_CERT_REQUIREBUILTIN = "app.update.cert.requireBuiltIn"; const PREF_APP_UPDATE_CHANNEL = "app.update.channel"; const PREF_APP_UPDATE_ENABLED = "app.update.enabled"; +const PREF_APP_UPDATE_METRO_ENABLED = "app.update.metro.enabled"; const PREF_APP_UPDATE_IDLETIME = "app.update.idletime"; const PREF_APP_UPDATE_LOG = "app.update.log"; const PREF_APP_UPDATE_NEVER_BRANCH = "app.update.never."; diff --git a/toolkit/mozapps/update/test/unit/head_update.js.in b/toolkit/mozapps/update/test/unit/head_update.js.in index 247f3830b6ba..35dc1d7dac57 100644 --- a/toolkit/mozapps/update/test/unit/head_update.js.in +++ b/toolkit/mozapps/update/test/unit/head_update.js.in @@ -358,6 +358,7 @@ function cleanUp() { */ function setDefaultPrefs() { Services.prefs.setBoolPref(PREF_APP_UPDATE_ENABLED, true); + Services.prefs.setBoolPref(PREF_APP_UPDATE_METRO_ENABLED, true); // Don't display UI for a successful installation. Some apps may not set this // pref to false like Firefox does. Services.prefs.setBoolPref(PREF_APP_UPDATE_SHOW_INSTALLED_UI, false);