diff --git a/mozilla/toolkit/mozapps/update/content/updates.js b/mozilla/toolkit/mozapps/update/content/updates.js index 2ebd0a049d8..e069140466f 100755 --- a/mozilla/toolkit/mozapps/update/content/updates.js +++ b/mozilla/toolkit/mozapps/update/content/updates.js @@ -1,5 +1,43 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Update Service. + * + * The Initial Developer of the Original Code is Google Inc. + * Portions created by the Initial Developer are Copyright (C) 2005 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Ben Goodger (Original Author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + const nsIUpdateItem = Components.interfaces.nsIUpdateItem; const nsIIncrementalDownload = Components.interfaces.nsIIncrementalDownload; +const XMLNS_XUL = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; /** * Logs a string to the error console. @@ -149,8 +187,7 @@ var gUpdatesAvailablePage = { var gDownloadingPage = { onPageShow: function() { // Build the UI for the active download - var update = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", - "update"); + var update = document.createElementNS(XMLNS_XUL, "update"); update.setAttribute("state", "downloading"); update.setAttribute("name", "Firefox 1.0.4"); update.setAttribute("status", "Blah"); @@ -159,11 +196,13 @@ var gDownloadingPage = { var updatesView = document.getElementById("updatesView"); updatesView.appendChild(update); + updatesView.addEventListener("update-pause", this.onPause, false); + // Add this UI as a listener for active downloads var updates = - Components.classes["@mozilla.org/updates/update-service;1"] - .getService(Components.interfaces.nsIApplicationUpdateService); - LOG("goats"); + Components.classes["@mozilla.org/updates/update-service;1"]. + getService(Components.interfaces.nsIApplicationUpdateService); + LOG("intergoat"); updates.downloadUpdate(gUpdates.update, false); updates.addDownloadListener(this); @@ -171,6 +210,17 @@ var gDownloadingPage = { // ... }, + _paused: false, + onPause: function() { + var updates = + Components.classes["@mozilla.org/updates/update-service;1"]. + getService(Components.interfaces.nsIApplicationUpdateService); + if (this._paused) + updates.downloadUpdate(gUpdates.update, false); + else + updates.pauseDownload(); + }, + onClose: function() { // Remove ourself as a download listener so that we don't continue to be // fed progress and state notifications after the UI we're updating has @@ -193,7 +243,7 @@ var gDownloadingPage = { onProgress: function(request, context, progress, maxProgress) { request.QueryInterface(nsIIncrementalDownload); - LOG("gDownloadingPage.onProgress: " + request.URI.spec + ", " + progress + "/" + maxProgress); + //LOG("gDownloadingPage.onProgress: " + request.URI.spec + ", " + progress + "/" + maxProgress); var active = document.getElementById("activeDownloadItem"); active.setAttribute("progress", Math.floor(100 * (progress/maxProgress))); @@ -207,6 +257,19 @@ var gDownloadingPage = { onStopRequest: function(request, context, status) { request.QueryInterface(nsIIncrementalDownload); LOG("gDownloadingPage.onStopRequest: " + request.URI.spec + ", status = " + status); + var updates = + Components.classes["@mozilla.org/updates/update-service;1"] + .getService(Components.interfaces.nsIApplicationUpdateService); + if (status == Components.results.NS_ERROR_UNEXPECTED && + !gUpdates.update.isCompleteUpdate) { + // If we were downloading a patch and the patch verification phase + // failed, log this and then commence downloading the complete update. + LOG("Verification of patch failed, downloading complete update"); + gUpdates.update.isCompleteUpdate = true; + updates.downloadUpdate(gUpdates.update, false); + return; + } + updates.removeDownloadListener(this); }, /** diff --git a/mozilla/toolkit/mozapps/update/content/updates.xml b/mozilla/toolkit/mozapps/update/content/updates.xml index 39d361ff5cc..e276f6dac34 100644 --- a/mozilla/toolkit/mozapps/update/content/updates.xml +++ b/mozilla/toolkit/mozapps/update/content/updates.xml @@ -78,7 +78,9 @@ - + diff --git a/mozilla/toolkit/mozapps/update/public/nsIUpdateService.idl b/mozilla/toolkit/mozapps/update/public/nsIUpdateService.idl index 3aa68c950e9..b06e62b8a36 100644 --- a/mozilla/toolkit/mozapps/update/public/nsIUpdateService.idl +++ b/mozilla/toolkit/mozapps/update/public/nsIUpdateService.idl @@ -87,6 +87,13 @@ interface nsIUpdate : nsISupports */ attribute AString detailsurl; + /** + * Whether or not the update being downloaded is a complete replacement of + * the user's existing installation or a patch representing the difference + * between the new version and the previous version. + */ + attribute boolean isCompleteUpdate; + /** * */ @@ -187,6 +194,11 @@ interface nsIApplicationUpdateService : nsISupports * */ void downloadUpdate(in nsIUpdate update, in boolean background); + + /** + * Pauses the active update download process + */ + void pauseDownload(); }; [scriptable, uuid(0765c92c-6145-4253-9db4-594d8023087e)] diff --git a/mozilla/toolkit/mozapps/update/src/nsUpdateService.js.in b/mozilla/toolkit/mozapps/update/src/nsUpdateService.js.in index 0c03d54d1f5..1abfec9ac35 100644 --- a/mozilla/toolkit/mozapps/update/src/nsUpdateService.js.in +++ b/mozilla/toolkit/mozapps/update/src/nsUpdateService.js.in @@ -533,7 +533,7 @@ UpdateService.prototype = { }, /** - * + * See nsIUpdateService.idl */ addDownloadListener: function(listener) { if (!this._downloader) { @@ -544,7 +544,7 @@ UpdateService.prototype = { }, /** - * + * See nsIUpdateService.idl */ removeDownloadListener: function(listener) { if (!this._downloader) { @@ -555,13 +555,11 @@ UpdateService.prototype = { }, /** - * + * See nsIUpdateService.idl */ downloadUpdate: function(update, background) { - LOG("downloadUpdate"); - if (this._downloader && this._downloader.isBusy) { - if (background == this._downloader.background) { + if (update.isCompleteUpdate == this._downloader.isCompleteUpdate) { LOG("no support for downloading more than one update at a time"); return; } @@ -571,6 +569,14 @@ UpdateService.prototype = { this._downloader.downloadUpdate(update); }, + /** + * See nsIUpdateService.idl + */ + pauseDownload: function() { + if (this._downloader && this._downloader.isBusy) + this._downloader.cancel(); + }, + /** * See nsISupports.idl */ @@ -634,6 +640,7 @@ function Update(type, version, extensionversion, detailsurl, patches) { this.version = version; this.extensionversion = extensionversion; this.detailsurl = detailsurl; + this.isCompleteUpdate = false; this._patches = patches; } @@ -810,6 +817,13 @@ Downloader.prototype = { _patch: null, // UpdatePatch _request: null, // nsIIncrementalDownload + /** + * Whether or not the update being downloaded is a complete replacement of + * the user's existing installation or a patch representing the difference + * between the new version and the previous version. + */ + isCompleteUpdate: null, + /** * */ @@ -1017,6 +1031,8 @@ Downloader.prototype = { patch = getPatchOfType("partial"); if (!patch) patch = getPatchOfType("complete"); + + update.isCompleteUpdate = useComplete; writeUpdateInfo(patch); return patch; @@ -1034,7 +1050,6 @@ Downloader.prototype = { * attempt to resume downloading what it was previously downloading. */ downloadUpdate: function(update) { - LOG("downloadUpdate"); var updateDir = this._getUpdatesDir(); // This function may return null, which indicates that there are no patches @@ -1044,6 +1059,7 @@ Downloader.prototype = { LOG("no patch to download"); return; } + this.isCompleteUpdate = this._patch.type == "complete"; var patchFile = updateDir.clone(); patchFile.append(FILE_UPDATE_ARCHIVE); @@ -1101,9 +1117,8 @@ Downloader.prototype = { }, onProgress: function(request, context, progress, maxProgress) { - LOG("MODE: " + (this.background ? "BACKGROUND" : "FOREGROUND")); request.QueryInterface(nsIIncrementalDownload); - LOG("Downloader.onProgress: " + request.URI.spec + ", " + progress + "/" + maxProgress); + // LOG("Downloader.onProgress: " + request.URI.spec + ", " + progress + "/" + maxProgress); var listenerCount = this._listeners.length; for (var i = 0; i < listenerCount; ++i) { var listener = this._listeners[i];