зеркало из https://github.com/mozilla/pjs.git
fall back to downloading a complete download package if the verification of the patch fails
This commit is contained in:
Родитель
7cacacf414
Коммит
0a47eab877
|
@ -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 <ben@mozilla.org> (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 nsIUpdateItem = Components.interfaces.nsIUpdateItem;
|
||||||
const nsIIncrementalDownload = Components.interfaces.nsIIncrementalDownload;
|
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.
|
* Logs a string to the error console.
|
||||||
|
@ -149,8 +187,7 @@ var gUpdatesAvailablePage = {
|
||||||
var gDownloadingPage = {
|
var gDownloadingPage = {
|
||||||
onPageShow: function() {
|
onPageShow: function() {
|
||||||
// Build the UI for the active download
|
// Build the UI for the active download
|
||||||
var update = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
|
var update = document.createElementNS(XMLNS_XUL, "update");
|
||||||
"update");
|
|
||||||
update.setAttribute("state", "downloading");
|
update.setAttribute("state", "downloading");
|
||||||
update.setAttribute("name", "Firefox 1.0.4");
|
update.setAttribute("name", "Firefox 1.0.4");
|
||||||
update.setAttribute("status", "Blah");
|
update.setAttribute("status", "Blah");
|
||||||
|
@ -159,11 +196,13 @@ var gDownloadingPage = {
|
||||||
var updatesView = document.getElementById("updatesView");
|
var updatesView = document.getElementById("updatesView");
|
||||||
updatesView.appendChild(update);
|
updatesView.appendChild(update);
|
||||||
|
|
||||||
|
updatesView.addEventListener("update-pause", this.onPause, false);
|
||||||
|
|
||||||
// Add this UI as a listener for active downloads
|
// Add this UI as a listener for active downloads
|
||||||
var updates =
|
var updates =
|
||||||
Components.classes["@mozilla.org/updates/update-service;1"]
|
Components.classes["@mozilla.org/updates/update-service;1"].
|
||||||
.getService(Components.interfaces.nsIApplicationUpdateService);
|
getService(Components.interfaces.nsIApplicationUpdateService);
|
||||||
LOG("goats");
|
LOG("intergoat");
|
||||||
updates.downloadUpdate(gUpdates.update, false);
|
updates.downloadUpdate(gUpdates.update, false);
|
||||||
updates.addDownloadListener(this);
|
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() {
|
onClose: function() {
|
||||||
// Remove ourself as a download listener so that we don't continue to be
|
// 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
|
// fed progress and state notifications after the UI we're updating has
|
||||||
|
@ -193,7 +243,7 @@ var gDownloadingPage = {
|
||||||
|
|
||||||
onProgress: function(request, context, progress, maxProgress) {
|
onProgress: function(request, context, progress, maxProgress) {
|
||||||
request.QueryInterface(nsIIncrementalDownload);
|
request.QueryInterface(nsIIncrementalDownload);
|
||||||
LOG("gDownloadingPage.onProgress: " + request.URI.spec + ", " + progress + "/" + maxProgress);
|
//LOG("gDownloadingPage.onProgress: " + request.URI.spec + ", " + progress + "/" + maxProgress);
|
||||||
|
|
||||||
var active = document.getElementById("activeDownloadItem");
|
var active = document.getElementById("activeDownloadItem");
|
||||||
active.setAttribute("progress", Math.floor(100 * (progress/maxProgress)));
|
active.setAttribute("progress", Math.floor(100 * (progress/maxProgress)));
|
||||||
|
@ -207,6 +257,19 @@ var gDownloadingPage = {
|
||||||
onStopRequest: function(request, context, status) {
|
onStopRequest: function(request, context, status) {
|
||||||
request.QueryInterface(nsIIncrementalDownload);
|
request.QueryInterface(nsIIncrementalDownload);
|
||||||
LOG("gDownloadingPage.onStopRequest: " + request.URI.spec + ", status = " + status);
|
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);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -78,7 +78,9 @@
|
||||||
<xul:progressmeter class="update-item-progress" xbl:inherits="value=progress"/>
|
<xul:progressmeter class="update-item-progress" xbl:inherits="value=progress"/>
|
||||||
<xul:hbox align="center">
|
<xul:hbox align="center">
|
||||||
<xul:label class="update-item-status" xbl:inherits="value=status" flex="1" crop="right"/>
|
<xul:label class="update-item-status" xbl:inherits="value=status" flex="1" crop="right"/>
|
||||||
<xul:button class="update-item-pause" label="&pause.label;" accesskey="&pause.accesskey;"/>
|
<xul:button class="update-item-pause"
|
||||||
|
label="&pause.label;" accesskey="&pause.accesskey;"
|
||||||
|
oncommand="this.parentNode.parentNode.fireEvent('pause');"/>
|
||||||
</xul:hbox>
|
</xul:hbox>
|
||||||
</content>
|
</content>
|
||||||
<implementation>
|
<implementation>
|
||||||
|
|
|
@ -87,6 +87,13 @@ interface nsIUpdate : nsISupports
|
||||||
*/
|
*/
|
||||||
attribute AString detailsurl;
|
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);
|
void downloadUpdate(in nsIUpdate update, in boolean background);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pauses the active update download process
|
||||||
|
*/
|
||||||
|
void pauseDownload();
|
||||||
};
|
};
|
||||||
|
|
||||||
[scriptable, uuid(0765c92c-6145-4253-9db4-594d8023087e)]
|
[scriptable, uuid(0765c92c-6145-4253-9db4-594d8023087e)]
|
||||||
|
|
|
@ -533,7 +533,7 @@ UpdateService.prototype = {
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* See nsIUpdateService.idl
|
||||||
*/
|
*/
|
||||||
addDownloadListener: function(listener) {
|
addDownloadListener: function(listener) {
|
||||||
if (!this._downloader) {
|
if (!this._downloader) {
|
||||||
|
@ -544,7 +544,7 @@ UpdateService.prototype = {
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* See nsIUpdateService.idl
|
||||||
*/
|
*/
|
||||||
removeDownloadListener: function(listener) {
|
removeDownloadListener: function(listener) {
|
||||||
if (!this._downloader) {
|
if (!this._downloader) {
|
||||||
|
@ -555,13 +555,11 @@ UpdateService.prototype = {
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* See nsIUpdateService.idl
|
||||||
*/
|
*/
|
||||||
downloadUpdate: function(update, background) {
|
downloadUpdate: function(update, background) {
|
||||||
LOG("downloadUpdate");
|
|
||||||
|
|
||||||
if (this._downloader && this._downloader.isBusy) {
|
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");
|
LOG("no support for downloading more than one update at a time");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -571,6 +569,14 @@ UpdateService.prototype = {
|
||||||
this._downloader.downloadUpdate(update);
|
this._downloader.downloadUpdate(update);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* See nsIUpdateService.idl
|
||||||
|
*/
|
||||||
|
pauseDownload: function() {
|
||||||
|
if (this._downloader && this._downloader.isBusy)
|
||||||
|
this._downloader.cancel();
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See nsISupports.idl
|
* See nsISupports.idl
|
||||||
*/
|
*/
|
||||||
|
@ -634,6 +640,7 @@ function Update(type, version, extensionversion, detailsurl, patches) {
|
||||||
this.version = version;
|
this.version = version;
|
||||||
this.extensionversion = extensionversion;
|
this.extensionversion = extensionversion;
|
||||||
this.detailsurl = detailsurl;
|
this.detailsurl = detailsurl;
|
||||||
|
this.isCompleteUpdate = false;
|
||||||
this._patches = patches;
|
this._patches = patches;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -810,6 +817,13 @@ Downloader.prototype = {
|
||||||
_patch: null, // UpdatePatch
|
_patch: null, // UpdatePatch
|
||||||
_request: null, // nsIIncrementalDownload
|
_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,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@ -1018,6 +1032,8 @@ Downloader.prototype = {
|
||||||
if (!patch)
|
if (!patch)
|
||||||
patch = getPatchOfType("complete");
|
patch = getPatchOfType("complete");
|
||||||
|
|
||||||
|
update.isCompleteUpdate = useComplete;
|
||||||
|
|
||||||
writeUpdateInfo(patch);
|
writeUpdateInfo(patch);
|
||||||
return patch;
|
return patch;
|
||||||
},
|
},
|
||||||
|
@ -1034,7 +1050,6 @@ Downloader.prototype = {
|
||||||
* attempt to resume downloading what it was previously downloading.
|
* attempt to resume downloading what it was previously downloading.
|
||||||
*/
|
*/
|
||||||
downloadUpdate: function(update) {
|
downloadUpdate: function(update) {
|
||||||
LOG("downloadUpdate");
|
|
||||||
var updateDir = this._getUpdatesDir();
|
var updateDir = this._getUpdatesDir();
|
||||||
|
|
||||||
// This function may return null, which indicates that there are no patches
|
// This function may return null, which indicates that there are no patches
|
||||||
|
@ -1044,6 +1059,7 @@ Downloader.prototype = {
|
||||||
LOG("no patch to download");
|
LOG("no patch to download");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
this.isCompleteUpdate = this._patch.type == "complete";
|
||||||
|
|
||||||
var patchFile = updateDir.clone();
|
var patchFile = updateDir.clone();
|
||||||
patchFile.append(FILE_UPDATE_ARCHIVE);
|
patchFile.append(FILE_UPDATE_ARCHIVE);
|
||||||
|
@ -1101,9 +1117,8 @@ Downloader.prototype = {
|
||||||
},
|
},
|
||||||
|
|
||||||
onProgress: function(request, context, progress, maxProgress) {
|
onProgress: function(request, context, progress, maxProgress) {
|
||||||
LOG("MODE: " + (this.background ? "BACKGROUND" : "FOREGROUND"));
|
|
||||||
request.QueryInterface(nsIIncrementalDownload);
|
request.QueryInterface(nsIIncrementalDownload);
|
||||||
LOG("Downloader.onProgress: " + request.URI.spec + ", " + progress + "/" + maxProgress);
|
// LOG("Downloader.onProgress: " + request.URI.spec + ", " + progress + "/" + maxProgress);
|
||||||
var listenerCount = this._listeners.length;
|
var listenerCount = this._listeners.length;
|
||||||
for (var i = 0; i < listenerCount; ++i) {
|
for (var i = 0; i < listenerCount; ++i) {
|
||||||
var listener = this._listeners[i];
|
var listener = this._listeners[i];
|
||||||
|
|
Загрузка…
Ссылка в новой задаче