From 4a4999af78591e2e214bd1302d85ea3a07f3044d Mon Sep 17 00:00:00 2001 From: "ben%bengoodger.com" Date: Fri, 10 Jun 2005 00:07:47 +0000 Subject: [PATCH] Add an 'errors' page to the update wizard to report verification errors. --- browser/app/profile/firefox.js | 26 ++------ .../en-US/chrome/mozapps/update/updates.dtd | 5 ++ .../chrome/mozapps/update/updates.properties | 5 ++ toolkit/mozapps/extensions/content/update.js | 3 +- toolkit/mozapps/update/content/updates.css | 28 +++++++-- toolkit/mozapps/update/content/updates.js | 61 +++++++++++++++++-- toolkit/mozapps/update/content/updates.xml | 5 +- toolkit/mozapps/update/content/updates.xul | 21 ++++++- .../update/public/nsIUpdateService.idl | 2 +- .../mozapps/update/src/nsUpdateService.js.in | 13 ++-- 10 files changed, 127 insertions(+), 42 deletions(-) diff --git a/browser/app/profile/firefox.js b/browser/app/profile/firefox.js index 8b9f747669f..ff0769f37c6 100644 --- a/browser/app/profile/firefox.js +++ b/browser/app/profile/firefox.js @@ -35,6 +35,8 @@ * * ***** END LICENSE BLOCK ***** */ +// XXX Toolkit-specific preferences should be moved into toolkit.js + #filter substitution # SYNTAX HINTS: dashes are delimiters. Use underscores instead. @@ -56,11 +58,6 @@ pref("xpinstall.dialog.progress.type.chrome", "Extension:Manager-extensions"); // compared to this value. A trailing "+" indicates the post-release trunk. pref("app.extensions.version", "1.0+"); -// Whether or not app updates are enabled -pref("update.app.enabled", true); -pref("update.app.url", "chrome://mozapps/locale/update/update.properties"); - -pref("update.extensions.enabled", true); pref("extensions.getMoreExtensionsURL", "chrome://mozapps/locale/extensions/extensions.properties"); pref("extensions.getMoreThemesURL", "chrome://mozapps/locale/extensions/extensions.properties"); // Developers can set this to |true| if they are constantly changing files in their @@ -81,7 +78,10 @@ pref("app.update.autoInstallEnabled", true); // the user to install. pref("app.update.autoInstallMode", 0); -pref("app.update.url", "chrome://mozapps/locale/update/update.properties"); +// XXX these prefs and others like them are distribution specific and should move +// into chrome://browser +pref("app.update.url", "chrome://mozapps/locale/update/updates.properties"); +pref("app.update.manual.url", "chrome://mozapps/locale/update/updates.properties"); pref("app.update.updatesAvailable", false); // Check for updates to Firefox every day pref("app.update.interval", 86400000); @@ -118,20 +118,6 @@ pref("extensions.dss.enabled", false); // Dynamic Skin Switching pref("extensions.dss.switchPending", false); // Non-dynamic switch pending after next // restart. -// General Update preferences -pref("update.interval", 3600000); // Check each of the above intervals - // every 60 mins -pref("update.showSlidingNotification", true); // Windows-only slide-up taskbar - // notification. -// These prefs relate to the number and severity of updates available. This is a -// cache that the browser notification mechanism uses to determine if it should show -// status bar UI if updates are detected and the app is shut down before installing -// them. -// 0 = low (extension/theme updates), -// 1 = medium (numerous extension/theme updates), -// 2 = high (new version of Firefox/Security patch) -pref("update.severity", 0); - pref("xpinstall.whitelist.add", "update.mozilla.org"); pref("xpinstall.whitelist.add.103", "addons.mozilla.org"); diff --git a/toolkit/locales/en-US/chrome/mozapps/update/updates.dtd b/toolkit/locales/en-US/chrome/mozapps/update/updates.dtd index ac6e5201bc5..0639c516a4b 100755 --- a/toolkit/locales/en-US/chrome/mozapps/update/updates.dtd +++ b/toolkit/locales/en-US/chrome/mozapps/update/updates.dtd @@ -36,3 +36,8 @@ + + + diff --git a/toolkit/locales/en-US/chrome/mozapps/update/updates.properties b/toolkit/locales/en-US/chrome/mozapps/update/updates.properties index 91b818fcaf4..95df849444f 100755 --- a/toolkit/locales/en-US/chrome/mozapps/update/updates.properties +++ b/toolkit/locales/en-US/chrome/mozapps/update/updates.properties @@ -3,3 +3,8 @@ updateType_major=New Version updateType_minor=Security Update introType_minor=An important Security Update for %S is available: introType_major=A new version of %S is available: +verificationError=%S could not confirm the integrity of the update package. +app.update.url=http://localhost/updates-test-1.xml +app.update.manual.url=http://localhost/manual.html +errorsPageHeader=Update Failed +downloadingPageTitle=Downloading Updates diff --git a/toolkit/mozapps/extensions/content/update.js b/toolkit/mozapps/extensions/content/update.js index 3da52424928..4cabcba3a43 100644 --- a/toolkit/mozapps/extensions/content/update.js +++ b/toolkit/mozapps/extensions/content/update.js @@ -68,6 +68,7 @@ const nsIUpdateItem = Components.interfaces.nsIUpdateItem; const nsIUpdateService = Components.interfaces.nsIUpdateService; +const PREF_UPDATE_EXTENSIONS_ENABLED = "extensions.update.enabled"; const PREF_UPDATE_EXTENSIONS_AUTOUPDATEENABLED = "extensions.update.autoUpdateEnabled"; const PREF_UPDATE_EXTENSIONS_COUNT = "extensions.update.count"; const PREF_UPDATE_EXTENSIONS_SEVERITY_THRESHOLD = "extensions.update.severity.threshold"; @@ -130,7 +131,7 @@ var gUpdateWizard = { var pref = Components.classes["@mozilla.org/preferences-service;1"] .getService(Components.interfaces.nsIPrefBranch); if (this.shouldSuggestAutoChecking) - pref.setBoolPref("update.extensions.enabled", this.shouldAutoCheck); + pref.setBoolPref(PREF_EXTENSIONS_UPDATE_ENABLED, this.shouldAutoCheck); if (this.succeeded) { // Downloading and Installed Extension diff --git a/toolkit/mozapps/update/content/updates.css b/toolkit/mozapps/update/content/updates.css index 3bdc01f4c25..a8ffb8dd01b 100755 --- a/toolkit/mozapps/update/content/updates.css +++ b/toolkit/mozapps/update/content/updates.css @@ -1,7 +1,13 @@ -.wizard-header { +wizard[label=""][description=""] .wizard-header, +wizard[label=""] .wizard-header-label, +wizard[description=""] .wizard-header-description { display: none; } +wizard[currentpageid="errors"] .wizard-buttons { + display: -moz-box; +} + .wizard-buttons { display: none; } @@ -14,16 +20,30 @@ margin: 10px 44px 10px 44px; } +#errorReason { + margin-top: 1px; + margin-bottom: 2px; + -moz-margin-start: 6px !important; + -moz-margin-end: 5px; +} + link { -moz-binding: url("chrome://mozapps/content/update/updates.xml#link"); -moz-user-focus: normal; color: blue; border: 1px solid transparent; -} - -.linkLabel { cursor: pointer; text-decoration: underline !important; + margin-top: 1px; + margin-bottom: 2px; + -moz-margin-start: 6px; + -moz-margin-end: 5px; +} + +link > label { + margin: 0px; + padding: 1px; + cursor: inherit; } link:hover:active { diff --git a/toolkit/mozapps/update/content/updates.js b/toolkit/mozapps/update/content/updates.js index e069140466f..f64b1a2be1f 100755 --- a/toolkit/mozapps/update/content/updates.js +++ b/toolkit/mozapps/update/content/updates.js @@ -38,6 +38,7 @@ const nsIUpdateItem = Components.interfaces.nsIUpdateItem; const nsIIncrementalDownload = Components.interfaces.nsIIncrementalDownload; const XMLNS_XUL = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; +const PREF_UPDATE_MANUAL_URL = "app.update.manual.url"; /** * Logs a string to the error console. @@ -66,6 +67,28 @@ var gUpdates = { document.documentElement.advance(); } }, + + advanceToErrorPage: function(currentPage, reason) { + currentPage.setAttribute("next", "errors"); + var errorReason = document.getElementById("errorReason"); + errorReason.value = reason; + var errorLink = document.getElementById("errorLink"); + var pref = Components.classes["@mozilla.org/preferences-service;1"] + .getService(Components.interfaces.nsIPrefBranch2); + var manualURL = pref.getComplexValue(PREF_UPDATE_MANUAL_URL, + Components.interfaces.nsIPrefLocalizedString); + errorLink.href = manualURL.data; + var errorLinkLabel = document.getElementById("errorLinkLabel"); + errorLinkLabel.value = manualURL.data; + + var updateStrings = document.getElementById("updateStrings"); + var pageTitle = updateStrings.getString("errorsPageHeader"); + + var errorPage = document.getElementById("errors"); + errorPage.setAttribute("label", pageTitle); + document.documentElement.setAttribute("label", pageTitle); + document.documentElement.advance(); + }, } var gCheckingPage = { @@ -202,12 +225,15 @@ var gDownloadingPage = { var updates = Components.classes["@mozilla.org/updates/update-service;1"]. getService(Components.interfaces.nsIApplicationUpdateService); - LOG("intergoat"); - updates.downloadUpdate(gUpdates.update, false); - updates.addDownloadListener(this); + var state = updates.downloadUpdate(gUpdates.update, false); + if (state == "failed") + this.showVerificationError(); + else + updates.addDownloadListener(this); // Build the UI for previously installed updates // ... + }, _paused: false, @@ -257,6 +283,8 @@ var gDownloadingPage = { onStopRequest: function(request, context, status) { request.QueryInterface(nsIIncrementalDownload); LOG("gDownloadingPage.onStopRequest: " + request.URI.spec + ", status = " + status); + + const NS_BINDING_ABORTED = 0x804b0002; var updates = Components.classes["@mozilla.org/updates/update-service;1"] .getService(Components.interfaces.nsIApplicationUpdateService); @@ -266,11 +294,26 @@ var gDownloadingPage = { // 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; + var state = updates.downloadUpdate(gUpdates.update, false); + if (state == "failed") + this.showVerificationError(); + else + return; + } + else if (status == NS_BINDING_ABORTED) { + LOG("Download PAUSED"); } updates.removeDownloadListener(this); }, + + showVerificationError: function() { + var updateStrings = document.getElementById("updateStrings"); + var brandStrings = document.getElementById("brandStrings"); + var brandName = brandStrings.getString("brandShortName"); + var verificationError = updateStrings.getFormattedString("verificationError", [brandName]); + var downloadingPage = document.getElementById("downloading"); + gUpdates.advanceToErrorPage(downloadingPage, verificationError); + }, /** * See nsISupports.idl @@ -284,3 +327,11 @@ var gDownloadingPage = { } }; +var gErrorsPage = { + onPageShow: function() { + document.documentElement.getButton("back").disabled = true; + document.documentElement.getButton("cancel").disabled = true; + document.documentElement.getButton("finish").focus(); + } +}; + diff --git a/toolkit/mozapps/update/content/updates.xml b/toolkit/mozapps/update/content/updates.xml index e276f6dac34..5005707406d 100644 --- a/toolkit/mozapps/update/content/updates.xml +++ b/toolkit/mozapps/update/content/updates.xml @@ -7,10 +7,7 @@ xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:xbl="http://www.mozilla.org/xbl"> - - - - + - @@ -138,4 +139,22 @@ + + + + + + + + + + + + + + + diff --git a/toolkit/mozapps/update/public/nsIUpdateService.idl b/toolkit/mozapps/update/public/nsIUpdateService.idl index b06e62b8a36..93c67890297 100644 --- a/toolkit/mozapps/update/public/nsIUpdateService.idl +++ b/toolkit/mozapps/update/public/nsIUpdateService.idl @@ -193,7 +193,7 @@ interface nsIApplicationUpdateService : nsISupports /** * */ - void downloadUpdate(in nsIUpdate update, in boolean background); + AString downloadUpdate(in nsIUpdate update, in boolean background); /** * Pauses the active update download process diff --git a/toolkit/mozapps/update/src/nsUpdateService.js.in b/toolkit/mozapps/update/src/nsUpdateService.js.in index 4f7d462616e..93312bc061f 100644 --- a/toolkit/mozapps/update/src/nsUpdateService.js.in +++ b/toolkit/mozapps/update/src/nsUpdateService.js.in @@ -575,7 +575,7 @@ UpdateService.prototype = { this._downloader.cancel(); } this._downloader = new Downloader(background); - this._downloader.downloadUpdate(update); + return this._downloader.downloadUpdate(update); }, /** @@ -719,8 +719,7 @@ Checker.prototype = { get _updateURL() { try { - //return gPref.getComplexValue(PREF_APP_UPDATE_URL, nsIPrefLocalizedString).data; - return gPref.getCharPref(PREF_APP_UPDATE_URL); + return gPref.getComplexValue(PREF_APP_UPDATE_URL, nsIPrefLocalizedString).data; } catch (e) { } @@ -931,7 +930,7 @@ Downloader.prototype = { function getPatchOfType(type) { for (var i = 0; i < update.patchCount; ++i) { var patch = update.getPatchAt(i); - if (patch.type == type) + if (patch && patch.type == type) return patch; } return null; @@ -941,7 +940,7 @@ Downloader.prototype = { function getPatchWithHash(hashvalue) { for (var i = 0; i < update.patchCount; ++i) { var patch = update.getPatchAt(i); - if (patch.hashvalue == hashvalue) + if (patch && patch.hashvalue == hashvalue) return patch; } return null; @@ -1060,9 +1059,10 @@ Downloader.prototype = { // This function may return null, which indicates that there are no patches // to download. this._patch = this._selectPatch(update, updateDir); + LOG("PATCH = " + this._patch); if (!this._patch) { LOG("no patch to download"); - return; + return this._readStatusFile(updateDir); } this.isCompleteUpdate = this._patch.type == "complete"; @@ -1086,6 +1086,7 @@ Downloader.prototype = { this._request.start(this, null); this._writeStatusFile(updateDir, STATE_DOWNLOADING); + return STATE_DOWNLOADING; }, _listeners: [],