2012-05-21 04:12:37 -07:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# 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/.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-09-14 16:17:59 -07:00
|
|
|
// Services = object with smart getters for common XPCOM services
|
|
|
|
Components.utils.import("resource://gre/modules/Services.jsm");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-12-16 12:04:40 -08:00
|
|
|
const PREF_EM_HOTFIX_ID = "extensions.hotfix.id";
|
|
|
|
|
2010-05-09 10:47:12 -07:00
|
|
|
function init(aEvent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (aEvent.target != document)
|
|
|
|
return;
|
2007-09-11 08:52:04 -07:00
|
|
|
|
2007-09-12 07:16:32 -07:00
|
|
|
try {
|
2010-09-14 16:17:59 -07:00
|
|
|
var distroId = Services.prefs.getCharPref("distribution.id");
|
2007-09-12 07:16:32 -07:00
|
|
|
if (distroId) {
|
2010-09-14 16:17:59 -07:00
|
|
|
var distroVersion = Services.prefs.getCharPref("distribution.version");
|
2013-07-19 13:17:29 -07:00
|
|
|
|
|
|
|
var distroIdField = document.getElementById("distributionId");
|
|
|
|
distroIdField.value = distroId + " - " + distroVersion;
|
|
|
|
distroIdField.style.display = "block";
|
|
|
|
|
2013-11-20 16:22:44 -08:00
|
|
|
try {
|
|
|
|
// This is in its own try catch due to bug 895473 and bug 900925.
|
|
|
|
var distroAbout = Services.prefs.getComplexValue("distribution.about",
|
|
|
|
Components.interfaces.nsISupportsString);
|
|
|
|
var distroField = document.getElementById("distribution");
|
|
|
|
distroField.value = distroAbout;
|
|
|
|
distroField.style.display = "block";
|
|
|
|
}
|
|
|
|
catch (ex) {
|
|
|
|
// Pref is unset
|
|
|
|
Components.utils.reportError(ex);
|
|
|
|
}
|
2007-09-12 07:16:32 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
// Pref is unset
|
2007-09-11 08:52:04 -07:00
|
|
|
}
|
|
|
|
|
2011-12-19 16:43:12 -08:00
|
|
|
// Include the build ID and display warning if this is an "a#" (nightly or aurora) build
|
2010-10-23 19:57:45 -07:00
|
|
|
let version = Services.appinfo.version;
|
2011-04-13 13:25:58 -07:00
|
|
|
if (/a\d+$/.test(version)) {
|
2010-10-23 19:57:45 -07:00
|
|
|
let buildID = Services.appinfo.appBuildID;
|
|
|
|
let buildDate = buildID.slice(0,4) + "-" + buildID.slice(4,6) + "-" + buildID.slice(6,8);
|
2011-06-17 18:01:36 -07:00
|
|
|
document.getElementById("version").textContent += " (" + buildDate + ")";
|
2011-12-19 16:43:12 -08:00
|
|
|
document.getElementById("experimental").hidden = false;
|
|
|
|
document.getElementById("communityDesc").hidden = true;
|
2010-10-23 19:57:45 -07:00
|
|
|
}
|
|
|
|
|
2010-09-14 16:17:59 -07:00
|
|
|
#ifdef MOZ_UPDATER
|
2010-09-23 21:02:08 -07:00
|
|
|
gAppUpdater = new appUpdater();
|
2008-09-08 03:12:48 -07:00
|
|
|
|
2013-03-06 10:42:36 -08:00
|
|
|
#if MOZ_UPDATE_CHANNEL != release
|
2011-05-30 09:18:08 -07:00
|
|
|
let defaults = Services.prefs.getDefaultBranch("");
|
|
|
|
let channelLabel = document.getElementById("currentChannel");
|
|
|
|
channelLabel.value = defaults.getCharPref("app.update.channel");
|
2011-08-24 07:48:02 -07:00
|
|
|
#endif
|
2013-03-06 10:42:36 -08:00
|
|
|
#endif
|
2011-04-08 10:26:51 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
// it may not be sized at this point, and we need its width to calculate its position
|
|
|
|
window.sizeToContent();
|
|
|
|
window.moveTo((screen.availWidth / 2) - (window.outerWidth / 2), screen.availHeight / 5);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-09-14 16:17:59 -07:00
|
|
|
#ifdef MOZ_UPDATER
|
2010-09-23 21:02:08 -07:00
|
|
|
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
Components.utils.import("resource://gre/modules/DownloadUtils.jsm");
|
|
|
|
Components.utils.import("resource://gre/modules/AddonManager.jsm");
|
|
|
|
|
|
|
|
var gAppUpdater;
|
|
|
|
|
|
|
|
function onUnload(aEvent) {
|
|
|
|
if (gAppUpdater.isChecking)
|
|
|
|
gAppUpdater.checker.stopChecking(Components.interfaces.nsIUpdateChecker.CURRENT_CHECK);
|
|
|
|
// Safe to call even when there isn't a download in progress.
|
|
|
|
gAppUpdater.removeDownloadListener();
|
|
|
|
gAppUpdater = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function appUpdater()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-09-23 21:02:08 -07:00
|
|
|
this.updateDeck = document.getElementById("updateDeck");
|
|
|
|
|
|
|
|
// Hide the update deck when there is already an update window open to avoid
|
|
|
|
// syncing issues between them.
|
|
|
|
if (Services.wm.getMostRecentWindow("Update:Wizard")) {
|
|
|
|
this.updateDeck.hidden = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "aus",
|
|
|
|
"@mozilla.org/updates/update-service;1",
|
|
|
|
"nsIApplicationUpdateService");
|
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "checker",
|
|
|
|
"@mozilla.org/updates/update-checker;1",
|
|
|
|
"nsIUpdateChecker");
|
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "um",
|
|
|
|
"@mozilla.org/updates/update-manager;1",
|
|
|
|
"nsIUpdateManager");
|
|
|
|
|
|
|
|
this.bundle = Services.strings.
|
|
|
|
createBundle("chrome://browser/locale/browser.properties");
|
|
|
|
|
|
|
|
let manualURL = Services.urlFormatter.formatURLPref("app.update.url.manual");
|
|
|
|
let manualLink = document.getElementById("manualLink");
|
|
|
|
manualLink.value = manualURL;
|
|
|
|
manualLink.href = manualURL;
|
|
|
|
document.getElementById("failedLink").href = manualURL;
|
|
|
|
|
|
|
|
if (this.updateDisabledAndLocked) {
|
|
|
|
this.selectPanel("adminDisabled");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-05-22 08:35:59 -07:00
|
|
|
if (this.isPending || this.isApplied) {
|
2013-12-11 15:14:58 -08:00
|
|
|
this.selectPanel("apply");
|
2010-09-23 21:02:08 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-22 07:16:53 -07:00
|
|
|
if (this.aus.isOtherInstanceHandlingUpdates) {
|
|
|
|
this.selectPanel("otherInstanceHandlingUpdates");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-09-23 21:02:08 -07:00
|
|
|
if (this.isDownloading) {
|
|
|
|
this.startDownload();
|
2013-12-11 15:14:58 -08:00
|
|
|
// selectPanel("downloading") is called from setupDownloadingUI().
|
2010-09-23 21:02:08 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-12-16 13:55:44 -08:00
|
|
|
// Honor the "Never check for updates" option by not only disabling background
|
|
|
|
// update checks, but also in the About dialog, by presenting a
|
|
|
|
// "Check for updates" button.
|
|
|
|
// If updates are found, the user is then asked if he wants to "Update to <version>".
|
|
|
|
if (!this.updateEnabled) {
|
|
|
|
this.selectPanel("checkForUpdates");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// That leaves the options
|
|
|
|
// "Check for updates, but let me choose whether to install them", and
|
|
|
|
// "Automatically install updates".
|
|
|
|
// In both cases, we check for updates without asking.
|
|
|
|
// In the "let me choose" case, we ask before downloading though, in onCheckComplete.
|
|
|
|
this.checkForUpdates();
|
2010-09-14 16:17:59 -07:00
|
|
|
}
|
2010-09-23 21:02:08 -07:00
|
|
|
|
|
|
|
appUpdater.prototype =
|
|
|
|
{
|
|
|
|
// true when there is an update check in progress.
|
|
|
|
isChecking: false,
|
|
|
|
|
|
|
|
// true when there is an update already staged / ready to be applied.
|
|
|
|
get isPending() {
|
2012-01-04 20:19:14 -08:00
|
|
|
if (this.update) {
|
2013-05-15 11:45:35 -07:00
|
|
|
return this.update.state == "pending" ||
|
2012-01-04 20:19:14 -08:00
|
|
|
this.update.state == "pending-service";
|
|
|
|
}
|
|
|
|
return this.um.activeUpdate &&
|
|
|
|
(this.um.activeUpdate.state == "pending" ||
|
|
|
|
this.um.activeUpdate.state == "pending-service");
|
2010-09-23 21:02:08 -07:00
|
|
|
},
|
|
|
|
|
2012-05-22 07:50:04 -07:00
|
|
|
// true when there is an update already installed in the background.
|
|
|
|
get isApplied() {
|
|
|
|
if (this.update)
|
|
|
|
return this.update.state == "applied" ||
|
|
|
|
this.update.state == "applied-service";
|
|
|
|
return this.um.activeUpdate &&
|
|
|
|
(this.um.activeUpdate.state == "applied" ||
|
|
|
|
this.um.activeUpdate.state == "applied-service");
|
|
|
|
},
|
|
|
|
|
2010-09-23 21:02:08 -07:00
|
|
|
// true when there is an update download in progress.
|
|
|
|
get isDownloading() {
|
|
|
|
if (this.update)
|
|
|
|
return this.update.state == "downloading";
|
|
|
|
return this.um.activeUpdate &&
|
|
|
|
this.um.activeUpdate.state == "downloading";
|
|
|
|
},
|
|
|
|
|
|
|
|
// true when updating is disabled by an administrator.
|
|
|
|
get updateDisabledAndLocked() {
|
|
|
|
return !this.updateEnabled &&
|
|
|
|
Services.prefs.prefIsLocked("app.update.enabled");
|
|
|
|
},
|
|
|
|
|
|
|
|
// true when updating is enabled.
|
|
|
|
get updateEnabled() {
|
|
|
|
try {
|
|
|
|
return Services.prefs.getBoolPref("app.update.enabled");
|
|
|
|
}
|
|
|
|
catch (e) { }
|
|
|
|
return true; // Firefox default is true
|
|
|
|
},
|
|
|
|
|
2012-05-22 07:50:04 -07:00
|
|
|
// true when updating in background is enabled.
|
|
|
|
get backgroundUpdateEnabled() {
|
|
|
|
return this.updateEnabled &&
|
2012-05-31 17:28:32 -07:00
|
|
|
gAppUpdater.aus.canStageUpdates;
|
2012-05-22 07:50:04 -07:00
|
|
|
},
|
|
|
|
|
2010-09-23 21:02:08 -07:00
|
|
|
// true when updating is automatic.
|
|
|
|
get updateAuto() {
|
|
|
|
try {
|
|
|
|
return Services.prefs.getBoolPref("app.update.auto");
|
|
|
|
}
|
|
|
|
catch (e) { }
|
|
|
|
return true; // Firefox default is true
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-12-11 15:14:58 -08:00
|
|
|
* Sets the panel of the updateDeck.
|
2010-09-23 21:02:08 -07:00
|
|
|
*
|
|
|
|
* @param aChildID
|
2013-12-11 15:14:58 -08:00
|
|
|
* The id of the deck's child to select, e.g. "apply".
|
2010-09-23 21:02:08 -07:00
|
|
|
*/
|
|
|
|
selectPanel: function(aChildID) {
|
2013-12-11 15:14:58 -08:00
|
|
|
let panel = document.getElementById(aChildID);
|
|
|
|
|
|
|
|
let button = panel.querySelector("button");
|
|
|
|
if (button) {
|
|
|
|
if (aChildID == "downloadAndInstall") {
|
|
|
|
let updateVersion = gAppUpdater.update.displayVersion;
|
|
|
|
button.label = this.bundle.formatStringFromName("update.downloadAndInstallButton.label", [updateVersion], 1);
|
|
|
|
button.accessKey = this.bundle.GetStringFromName("update.downloadAndInstallButton.accesskey");
|
|
|
|
}
|
|
|
|
this.updateDeck.selectedPanel = panel;
|
|
|
|
if (!document.commandDispatcher.focusedElement || // don't steal the focus
|
|
|
|
document.commandDispatcher.focusedElement.localName == "button") // except from the other buttons
|
|
|
|
button.focus();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
this.updateDeck.selectedPanel = panel;
|
|
|
|
}
|
2010-09-23 21:02:08 -07:00
|
|
|
},
|
|
|
|
|
2013-12-16 13:55:44 -08:00
|
|
|
/**
|
|
|
|
* Check for updates
|
|
|
|
*/
|
|
|
|
checkForUpdates: function() {
|
|
|
|
this.selectPanel("checkingForUpdates");
|
|
|
|
this.isChecking = true;
|
|
|
|
this.checker.checkForUpdates(this.updateCheckListener, true);
|
|
|
|
// after checking, onCheckComplete() is called
|
|
|
|
},
|
|
|
|
|
2010-09-23 21:02:08 -07:00
|
|
|
/**
|
2013-12-11 15:14:58 -08:00
|
|
|
* Check for addon compat, or start the download right away
|
2010-09-23 21:02:08 -07:00
|
|
|
*/
|
2013-12-11 15:14:58 -08:00
|
|
|
doUpdate: function() {
|
|
|
|
// skip the compatibility check if the update doesn't provide appVersion,
|
|
|
|
// or the appVersion is unchanged, e.g. nightly update
|
|
|
|
if (!this.update.appVersion ||
|
|
|
|
Services.vc.compare(gAppUpdater.update.appVersion,
|
|
|
|
Services.appinfo.version) == 0) {
|
|
|
|
this.startDownload();
|
|
|
|
} else {
|
|
|
|
this.checkAddonCompatibility();
|
|
|
|
}
|
2010-09-23 21:02:08 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-12-11 15:14:58 -08:00
|
|
|
* Handles oncommand for the "Restart to Update" button
|
|
|
|
* which is presented after the download has been downloaded.
|
2010-09-23 21:02:08 -07:00
|
|
|
*/
|
2013-12-11 15:14:58 -08:00
|
|
|
buttonRestartAfterDownload: function() {
|
|
|
|
if (!this.isPending && !this.isApplied)
|
|
|
|
return;
|
|
|
|
|
2010-09-23 21:02:08 -07:00
|
|
|
// Notify all windows that an application quit has been requested.
|
|
|
|
let cancelQuit = Components.classes["@mozilla.org/supports-PRBool;1"].
|
|
|
|
createInstance(Components.interfaces.nsISupportsPRBool);
|
|
|
|
Services.obs.notifyObservers(cancelQuit, "quit-application-requested", "restart");
|
|
|
|
|
|
|
|
// Something aborted the quit process.
|
|
|
|
if (cancelQuit.data)
|
|
|
|
return;
|
|
|
|
|
2011-11-07 21:20:42 -08:00
|
|
|
let appStartup = Components.classes["@mozilla.org/toolkit/app-startup;1"].
|
|
|
|
getService(Components.interfaces.nsIAppStartup);
|
|
|
|
|
2010-09-23 21:02:08 -07:00
|
|
|
// If already in safe mode restart in safe mode (bug 327119)
|
|
|
|
if (Services.appinfo.inSafeMode) {
|
2011-11-07 21:20:42 -08:00
|
|
|
appStartup.restartInSafeMode(Components.interfaces.nsIAppStartup.eAttemptQuit);
|
|
|
|
return;
|
2010-09-23 21:02:08 -07:00
|
|
|
}
|
|
|
|
|
2011-11-07 21:20:42 -08:00
|
|
|
appStartup.quit(Components.interfaces.nsIAppStartup.eAttemptQuit |
|
|
|
|
Components.interfaces.nsIAppStartup.eRestart);
|
2013-12-11 15:14:58 -08:00
|
|
|
},
|
2010-09-23 21:02:08 -07:00
|
|
|
|
2013-12-11 15:14:58 -08:00
|
|
|
/**
|
|
|
|
* Handles oncommand for the "Apply Update…" button
|
|
|
|
* which is presented if we need to show the billboard or license.
|
|
|
|
*/
|
|
|
|
buttonApplyBillboard: function() {
|
2010-09-23 21:02:08 -07:00
|
|
|
const URI_UPDATE_PROMPT_DIALOG = "chrome://mozapps/content/update/updates.xul";
|
2013-12-11 15:14:58 -08:00
|
|
|
var ary = null;
|
|
|
|
ary = Components.classes["@mozilla.org/supports-array;1"].
|
|
|
|
createInstance(Components.interfaces.nsISupportsArray);
|
|
|
|
ary.AppendElement(this.update);
|
|
|
|
var openFeatures = "chrome,centerscreen,dialog=no,resizable=no,titlebar,toolbar=no";
|
|
|
|
Services.ww.openWindow(null, URI_UPDATE_PROMPT_DIALOG, "", openFeatures, ary);
|
|
|
|
window.close(); // close the "About" window; updates.xul takes over.
|
2010-09-23 21:02:08 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements nsIUpdateCheckListener. The methods implemented by
|
2013-02-01 18:58:48 -08:00
|
|
|
* nsIUpdateCheckListener are in a different scope from nsIIncrementalDownload
|
|
|
|
* to make it clear which are used by each interface.
|
2010-09-23 21:02:08 -07:00
|
|
|
*/
|
|
|
|
updateCheckListener: {
|
|
|
|
/**
|
|
|
|
* See nsIUpdateService.idl
|
|
|
|
*/
|
|
|
|
onCheckComplete: function(aRequest, aUpdates, aUpdateCount) {
|
|
|
|
gAppUpdater.isChecking = false;
|
|
|
|
gAppUpdater.update = gAppUpdater.aus.
|
|
|
|
selectUpdate(aUpdates, aUpdates.length);
|
|
|
|
if (!gAppUpdater.update) {
|
|
|
|
gAppUpdater.selectPanel("noUpdatesFound");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-22 13:37:12 -07:00
|
|
|
if (gAppUpdater.update.unsupported) {
|
|
|
|
if (gAppUpdater.update.detailsURL) {
|
|
|
|
let unsupportedLink = document.getElementById("unsupportedLink");
|
|
|
|
unsupportedLink.href = gAppUpdater.update.detailsURL;
|
|
|
|
}
|
|
|
|
gAppUpdater.selectPanel("unsupportedSystem");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-09-23 21:02:08 -07:00
|
|
|
if (!gAppUpdater.aus.canApplyUpdates) {
|
|
|
|
gAppUpdater.selectPanel("manualUpdate");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Firefox no longer displays a license for updates and the licenseURL
|
|
|
|
// check is just in case a distibution does.
|
|
|
|
if (gAppUpdater.update.billboardURL || gAppUpdater.update.licenseURL) {
|
2013-12-11 15:14:58 -08:00
|
|
|
gAppUpdater.selectPanel("applyBillboard");
|
2010-09-23 21:02:08 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-12-11 15:14:58 -08:00
|
|
|
if (gAppUpdater.updateAuto) // automatically download and install
|
|
|
|
gAppUpdater.doUpdate();
|
|
|
|
else // ask
|
|
|
|
gAppUpdater.selectPanel("downloadAndInstall");
|
2010-09-23 21:02:08 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* See nsIUpdateService.idl
|
|
|
|
*/
|
|
|
|
onError: function(aRequest, aUpdate) {
|
|
|
|
// Errors in the update check are treated as no updates found. If the
|
|
|
|
// update check fails repeatedly without a success the user will be
|
|
|
|
// notified with the normal app update user interface so this is safe.
|
|
|
|
gAppUpdater.isChecking = false;
|
|
|
|
gAppUpdater.selectPanel("noUpdatesFound");
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* See nsISupports.idl
|
|
|
|
*/
|
|
|
|
QueryInterface: function(aIID) {
|
|
|
|
if (!aIID.equals(Components.interfaces.nsIUpdateCheckListener) &&
|
|
|
|
!aIID.equals(Components.interfaces.nsISupports))
|
|
|
|
throw Components.results.NS_ERROR_NO_INTERFACE;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks the compatibility of add-ons for the application update.
|
|
|
|
*/
|
|
|
|
checkAddonCompatibility: function() {
|
2011-12-16 12:04:40 -08:00
|
|
|
try {
|
|
|
|
var hotfixID = Services.prefs.getCharPref(PREF_EM_HOTFIX_ID);
|
|
|
|
}
|
|
|
|
catch (e) { }
|
|
|
|
|
2010-09-23 21:02:08 -07:00
|
|
|
var self = this;
|
|
|
|
AddonManager.getAllAddons(function(aAddons) {
|
|
|
|
self.addons = [];
|
|
|
|
self.addonsCheckedCount = 0;
|
|
|
|
aAddons.forEach(function(aAddon) {
|
2011-01-13 11:36:36 -08:00
|
|
|
// Protect against code that overrides the add-ons manager and doesn't
|
|
|
|
// implement the isCompatibleWith or the findUpdates method.
|
|
|
|
if (!("isCompatibleWith" in aAddon) || !("findUpdates" in aAddon)) {
|
|
|
|
let errMsg = "Add-on doesn't implement either the isCompatibleWith " +
|
|
|
|
"or the findUpdates method!";
|
|
|
|
if (aAddon.id)
|
|
|
|
errMsg += " Add-on ID: " + aAddon.id;
|
|
|
|
Components.utils.reportError(errMsg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-09-23 21:02:08 -07:00
|
|
|
// If an add-on isn't appDisabled and isn't userDisabled then it is
|
|
|
|
// either active now or the user expects it to be active after the
|
|
|
|
// restart. If that is the case and the add-on is not installed by the
|
|
|
|
// application and is not compatible with the new application version
|
|
|
|
// then the user should be warned that the add-on will become
|
|
|
|
// incompatible. If an addon's type equals plugin it is skipped since
|
|
|
|
// checking plugins compatibility information isn't supported and
|
|
|
|
// getting the scope property of a plugin breaks in some environments
|
2011-12-16 12:04:40 -08:00
|
|
|
// (see bug 566787). The hotfix add-on is also ignored as it shouldn't
|
|
|
|
// block the user from upgrading.
|
2011-01-13 11:36:36 -08:00
|
|
|
try {
|
2011-12-16 12:04:40 -08:00
|
|
|
if (aAddon.type != "plugin" && aAddon.id != hotfixID &&
|
2011-01-13 11:36:36 -08:00
|
|
|
!aAddon.appDisabled && !aAddon.userDisabled &&
|
|
|
|
aAddon.scope != AddonManager.SCOPE_APPLICATION &&
|
|
|
|
aAddon.isCompatible &&
|
|
|
|
!aAddon.isCompatibleWith(self.update.appVersion,
|
|
|
|
self.update.platformVersion))
|
|
|
|
self.addons.push(aAddon);
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
Components.utils.reportError(e);
|
|
|
|
}
|
2010-09-23 21:02:08 -07:00
|
|
|
});
|
|
|
|
self.addonsTotalCount = self.addons.length;
|
|
|
|
if (self.addonsTotalCount == 0) {
|
|
|
|
self.startDownload();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
self.checkAddonsForUpdates();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if there are updates for add-ons that are incompatible with the
|
|
|
|
* application update.
|
|
|
|
*/
|
|
|
|
checkAddonsForUpdates: function() {
|
|
|
|
this.addons.forEach(function(aAddon) {
|
|
|
|
aAddon.findUpdates(this, AddonManager.UPDATE_WHEN_NEW_APP_DETECTED,
|
|
|
|
this.update.appVersion,
|
|
|
|
this.update.platformVersion);
|
|
|
|
}, this);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* See XPIProvider.jsm
|
|
|
|
*/
|
|
|
|
onCompatibilityUpdateAvailable: function(aAddon) {
|
|
|
|
for (var i = 0; i < this.addons.length; ++i) {
|
|
|
|
if (this.addons[i].id == aAddon.id) {
|
|
|
|
this.addons.splice(i, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* See XPIProvider.jsm
|
|
|
|
*/
|
|
|
|
onUpdateAvailable: function(aAddon, aInstall) {
|
2014-01-06 00:46:32 -08:00
|
|
|
if (!Services.blocklist.isAddonBlocklisted(aAddon,
|
2013-03-29 13:10:47 -07:00
|
|
|
this.update.appVersion,
|
|
|
|
this.update.platformVersion)) {
|
2010-09-23 21:02:08 -07:00
|
|
|
// Compatibility or new version updates mean the same thing here.
|
|
|
|
this.onCompatibilityUpdateAvailable(aAddon);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* See XPIProvider.jsm
|
|
|
|
*/
|
|
|
|
onUpdateFinished: function(aAddon) {
|
|
|
|
++this.addonsCheckedCount;
|
|
|
|
|
|
|
|
if (this.addonsCheckedCount < this.addonsTotalCount)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (this.addons.length == 0) {
|
|
|
|
// Compatibility updates or new version updates were found for all add-ons
|
|
|
|
this.startDownload();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-12-11 15:14:58 -08:00
|
|
|
this.selectPanel("apply");
|
2010-09-23 21:02:08 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Starts the download of an update mar.
|
|
|
|
*/
|
|
|
|
startDownload: function() {
|
|
|
|
if (!this.update)
|
|
|
|
this.update = this.um.activeUpdate;
|
|
|
|
this.update.QueryInterface(Components.interfaces.nsIWritablePropertyBag);
|
|
|
|
this.update.setProperty("foregroundDownload", "true");
|
|
|
|
|
|
|
|
this.aus.pauseDownload();
|
|
|
|
let state = this.aus.downloadUpdate(this.update, false);
|
|
|
|
if (state == "failed") {
|
2013-05-15 11:45:35 -07:00
|
|
|
this.selectPanel("downloadFailed");
|
2010-09-23 21:02:08 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-05-29 13:20:12 -07:00
|
|
|
this.setupDownloadingUI();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Switches to the UI responsible for tracking the download.
|
|
|
|
*/
|
|
|
|
setupDownloadingUI: function() {
|
2010-09-23 21:02:08 -07:00
|
|
|
this.downloadStatus = document.getElementById("downloadStatus");
|
|
|
|
this.downloadStatus.value =
|
|
|
|
DownloadUtils.getTransferTotal(0, this.update.selectedPatch.size);
|
|
|
|
this.selectPanel("downloading");
|
|
|
|
this.aus.addDownloadListener(this);
|
|
|
|
},
|
|
|
|
|
|
|
|
removeDownloadListener: function() {
|
2012-10-24 11:39:51 -07:00
|
|
|
if (this.aus) {
|
|
|
|
this.aus.removeDownloadListener(this);
|
|
|
|
}
|
2010-09-23 21:02:08 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* See nsIRequestObserver.idl
|
|
|
|
*/
|
|
|
|
onStartRequest: function(aRequest, aContext) {
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* See nsIRequestObserver.idl
|
|
|
|
*/
|
|
|
|
onStopRequest: function(aRequest, aContext, aStatusCode) {
|
|
|
|
switch (aStatusCode) {
|
|
|
|
case Components.results.NS_ERROR_UNEXPECTED:
|
|
|
|
if (this.update.selectedPatch.state == "download-failed" &&
|
|
|
|
(this.update.isCompleteUpdate || this.update.patchCount != 2)) {
|
|
|
|
// Verification error of complete patch, informational text is held in
|
|
|
|
// the update object.
|
|
|
|
this.removeDownloadListener();
|
|
|
|
this.selectPanel("downloadFailed");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Verification failed for a partial patch, complete patch is now
|
|
|
|
// downloading so return early and do NOT remove the download listener!
|
|
|
|
break;
|
|
|
|
case Components.results.NS_BINDING_ABORTED:
|
|
|
|
// Do not remove UI listener since the user may resume downloading again.
|
|
|
|
break;
|
|
|
|
case Components.results.NS_OK:
|
|
|
|
this.removeDownloadListener();
|
2012-05-22 07:50:04 -07:00
|
|
|
if (this.backgroundUpdateEnabled) {
|
|
|
|
this.selectPanel("applying");
|
|
|
|
let update = this.um.activeUpdate;
|
|
|
|
let self = this;
|
2012-05-23 14:51:50 -07:00
|
|
|
Services.obs.addObserver(function (aSubject, aTopic, aData) {
|
2012-05-22 07:50:04 -07:00
|
|
|
// Update the UI when the background updater is finished
|
2012-05-29 13:20:12 -07:00
|
|
|
let status = aData;
|
2012-05-23 14:51:50 -07:00
|
|
|
if (status == "applied" || status == "applied-service" ||
|
|
|
|
status == "pending" || status == "pending-service") {
|
|
|
|
// If the update is successfully applied, or if the updater has
|
2013-12-11 15:14:58 -08:00
|
|
|
// fallen back to non-staged updates, show the "Restart to Update"
|
2012-05-23 14:51:50 -07:00
|
|
|
// button.
|
2013-12-11 15:14:58 -08:00
|
|
|
self.selectPanel("apply");
|
2012-05-22 07:50:04 -07:00
|
|
|
} else if (status == "failed") {
|
|
|
|
// Background update has failed, let's show the UI responsible for
|
|
|
|
// prompting the user to update manually.
|
|
|
|
self.selectPanel("downloadFailed");
|
2012-05-29 13:20:12 -07:00
|
|
|
} else if (status == "downloading") {
|
|
|
|
// We've fallen back to downloading the full update because the
|
|
|
|
// partial update failed to get staged in the background.
|
|
|
|
// Therefore we need to keep our observer.
|
|
|
|
self.setupDownloadingUI();
|
|
|
|
return;
|
2012-05-22 07:50:04 -07:00
|
|
|
}
|
2012-05-23 14:51:50 -07:00
|
|
|
Services.obs.removeObserver(arguments.callee, "update-staged");
|
|
|
|
}, "update-staged", false);
|
2012-05-22 07:50:04 -07:00
|
|
|
} else {
|
2013-12-11 15:14:58 -08:00
|
|
|
this.selectPanel("apply");
|
2012-05-22 07:50:04 -07:00
|
|
|
}
|
2010-09-23 21:02:08 -07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
this.removeDownloadListener();
|
|
|
|
this.selectPanel("downloadFailed");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* See nsIProgressEventSink.idl
|
|
|
|
*/
|
|
|
|
onStatus: function(aRequest, aContext, aStatus, aStatusArg) {
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* See nsIProgressEventSink.idl
|
|
|
|
*/
|
|
|
|
onProgress: function(aRequest, aContext, aProgress, aProgressMax) {
|
|
|
|
this.downloadStatus.value =
|
|
|
|
DownloadUtils.getTransferTotal(aProgress, aProgressMax);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* See nsISupports.idl
|
|
|
|
*/
|
|
|
|
QueryInterface: function(aIID) {
|
|
|
|
if (!aIID.equals(Components.interfaces.nsIProgressEventSink) &&
|
|
|
|
!aIID.equals(Components.interfaces.nsIRequestObserver) &&
|
|
|
|
!aIID.equals(Components.interfaces.nsISupports))
|
|
|
|
throw Components.results.NS_ERROR_NO_INTERFACE;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
};
|
2010-09-14 16:17:59 -07:00
|
|
|
#endif
|