From 77c25513a89334609a6774834b8a3c6384da243a Mon Sep 17 00:00:00 2001 From: Robert Strong Date: Wed, 17 Mar 2010 16:12:30 -0700 Subject: [PATCH] Bug 549969 - Add ability to save xml attributes from update xml that app update doesn't care about. r=dolske --- toolkit/mozapps/update/nsIUpdateService.idl | 13 +-- toolkit/mozapps/update/nsUpdateService.js | 96 +++++++++++-------- toolkit/mozapps/update/test/shared.js | 37 ++++--- .../update/test/unit/test_0020_general.js | 16 ++-- .../update/test/unit/test_0060_manager.js | 26 +++-- 5 files changed, 107 insertions(+), 81 deletions(-) diff --git a/toolkit/mozapps/update/nsIUpdateService.idl b/toolkit/mozapps/update/nsIUpdateService.idl index 696307fa5bbf..2fc211bc19e9 100644 --- a/toolkit/mozapps/update/nsIUpdateService.idl +++ b/toolkit/mozapps/update/nsIUpdateService.idl @@ -113,7 +113,7 @@ interface nsIUpdatePatch : nsISupports * that the front end and other application services can use to learn more * about what is going on. */ -[scriptable, uuid(31eced2b-8adb-46f9-992b-26858ab3d558)] +[scriptable, uuid(2379e2e1-8eab-4084-8d8c-94ffeee56804)] interface nsIUpdate : nsISupports { /** @@ -189,17 +189,6 @@ interface nsIUpdate : nsISupports */ attribute AString channel; - /** - * Stores custom string data provided by the update xml for use by the - * application. - * - * Implementation Note: After an update has been successfully applied this - * value will be added to the app.update.extra preference and if an - * application uses this preference to determine that an update has been - * applied it should also delete the preference. - */ - attribute AString extra1; - /** * Whether to show the update prompt which requires user confirmation when an * update is found during a background update check. This overrides the diff --git a/toolkit/mozapps/update/nsUpdateService.js b/toolkit/mozapps/update/nsUpdateService.js index 08f30ad0a3d5..0caafbefe7cb 100644 --- a/toolkit/mozapps/update/nsUpdateService.js +++ b/toolkit/mozapps/update/nsUpdateService.js @@ -53,13 +53,13 @@ const PREF_APP_UPDATE_AUTO = "app.update.auto"; const PREF_APP_UPDATE_BACKGROUND_INTERVAL = "app.update.download.backgroundInterval"; const PREF_APP_UPDATE_CHANNEL = "app.update.channel"; const PREF_APP_UPDATE_ENABLED = "app.update.enabled"; -const PREF_APP_UPDATE_EXTRA1 = "app.update.extra1"; 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"; const PREF_APP_UPDATE_LOG = "app.update.log"; const PREF_APP_UPDATE_MODE = "app.update.mode"; const PREF_APP_UPDATE_NEVER_BRANCH = "app.update.never."; +const PREF_APP_UPDATE_POSTUPDATE = "app.update.postupdate"; const PREF_APP_UPDATE_PROMPTWAITTIME = "app.update.promptWaitTime"; const PREF_APP_UPDATE_SHOW_INSTALLED_UI = "app.update.showInstalledUI"; const PREF_APP_UPDATE_SILENT = "app.update.silent"; @@ -860,36 +860,57 @@ function Update(update) { attr.QueryInterface(Ci.nsIDOMAttr); if (attr.value == "undefined") continue; - else if (attr.name == "installDate" && attr.value) - this.installDate = parseInt(attr.value); - else if (attr.name == "isCompleteUpdate") - this.isCompleteUpdate = attr.value == "true"; - else if (attr.name == "isSecurityUpdate") - this.isSecurityUpdate = attr.value == "true"; - else if (attr.name == "showPrompt") - this.showPrompt = attr.value == "true"; - else if (attr.name == "showNeverForVersion") - this.showNeverForVersion = attr.value == "true"; - else if (attr.name == "showSurvey") - this.showSurvey = attr.value == "true"; else if (attr.name == "detailsURL") this._detailsURL = attr.value; - else if (attr.name == "channel") - this.channel = attr.value; else if (attr.name == "extensionVersion") { // Prevent extensionVersion from replacing appVersion if appVersion is // present in the update xml. if (!this.appVersion) this.appVersion = attr.value; } + else if (attr.name == "installDate" && attr.value) + this.installDate = parseInt(attr.value); + else if (attr.name == "isCompleteUpdate") + this.isCompleteUpdate = attr.value == "true"; + else if (attr.name == "isSecurityUpdate") + this.isSecurityUpdate = attr.value == "true"; + else if (attr.name == "showNeverForVersion") + this.showNeverForVersion = attr.value == "true"; + else if (attr.name == "showPrompt") + this.showPrompt = attr.value == "true"; + else if (attr.name == "showSurvey") + this.showSurvey = attr.value == "true"; else if (attr.name == "version") { // Prevent version from replacing displayVersion if displayVersion is // present in the update xml. if (!this.displayVersion) this.displayVersion = attr.value; } - else + else { this[attr.name] = attr.value; + + switch (attr.name) { + case "appVersion": + case "billboardURL": + case "buildID": + case "channel": + case "displayVersion": + case "licenseURL": + case "name": + case "platformVersion": + case "previousAppVersion": + case "serviceURL": + case "statusText": + case "type": + break; + default: + // Save custom attributes when serializing to the local xml file but + // don't use this method for the expected attributes which are already + // handled in serialize. + this.setProperty(attr.name, attr.value); + break; + }; + } } // Set the initial value with the current time when it doesn't already have a @@ -987,36 +1008,36 @@ Update.prototype = { */ serialize: function Update_serialize(updates) { var update = updates.createElementNS(URI_UPDATE_NS, "update"); - update.setAttribute("type", this.type); - update.setAttribute("name", this.name); - update.setAttribute("displayVersion", this.displayVersion); - // for backwards compatibility in case the user downgrades - update.setAttribute("version", this.displayVersion); update.setAttribute("appVersion", this.appVersion); update.setAttribute("buildID", this.buildID); + update.setAttribute("channel", this.channel); + update.setAttribute("displayVersion", this.displayVersion); // for backwards compatibility in case the user downgrades update.setAttribute("extensionVersion", this.appVersion); + update.setAttribute("installDate", this.installDate); + update.setAttribute("isCompleteUpdate", this.isCompleteUpdate); + update.setAttribute("name", this.name); + update.setAttribute("serviceURL", this.serviceURL); + update.setAttribute("showNeverForVersion", this.showNeverForVersion); + update.setAttribute("showPrompt", this.showPrompt); + update.setAttribute("showSurvey", this.showSurvey); + update.setAttribute("type", this.type); + // for backwards compatibility in case the user downgrades + + // Optional attributes + update.setAttribute("version", this.displayVersion); + if (this.billboardURL) + update.setAttribute("billboardURL", this.billboardURL); + if (this.detailsURL) + update.setAttribute("detailsURL", this.detailsURL); + if (this.licenseURL) + update.setAttribute("licenseURL", this.licenseURL); if (this.platformVersion) update.setAttribute("platformVersion", this.platformVersion); if (this.previousAppVersion) update.setAttribute("previousAppVersion", this.previousAppVersion); - if (this.detailsURL) - update.setAttribute("detailsURL", this.detailsURL); - if (this.billboardURL) - update.setAttribute("billboardURL", this.billboardURL); - if (this.licenseURL) - update.setAttribute("licenseURL", this.licenseURL); - update.setAttribute("serviceURL", this.serviceURL); - update.setAttribute("installDate", this.installDate); if (this.statusText) update.setAttribute("statusText", this.statusText); - update.setAttribute("isCompleteUpdate", this.isCompleteUpdate); - update.setAttribute("channel", this.channel); - update.setAttribute("showPrompt", this.showPrompt); - update.setAttribute("showSurvey", this.showSurvey); - update.setAttribute("showNeverForVersion", this.showNeverForVersion); - if (this.extra1) - update.setAttribute("extra1", this.extra1); updates.documentElement.appendChild(update); for (var p in this._properties) { @@ -1197,8 +1218,7 @@ UpdateService.prototype = { // Update the patch's metadata. um.activeUpdate = update; - gPref.setCharPref(PREF_APP_UPDATE_EXTRA1, - update.extra1 ? update.extra1 : "undefined"); + gPref.setBoolPref(PREF_APP_UPDATE_POSTUPDATE, true); prompter.showUpdateInstalled(); // Done with this update. Clean it up. diff --git a/toolkit/mozapps/update/test/shared.js b/toolkit/mozapps/update/test/shared.js index f39dcd0bd879..3d40d51b22aa 100644 --- a/toolkit/mozapps/update/test/shared.js +++ b/toolkit/mozapps/update/test/shared.js @@ -190,12 +190,13 @@ function getRemoteUpdateString(aPatches, aType, aName, aDisplayVersion, aAppVersion, aPlatformVersion, aBuildID, aDetailsURL, aBillboardURL, aLicenseURL, aShowPrompt, aShowNeverForVersion, aShowSurvey, - aExtra1, aVersion, aExtensionVersion) { + aVersion, aExtensionVersion, aCustom1, + aCustom2) { return getUpdateString(aType, aName, aDisplayVersion, aAppVersion, aPlatformVersion, aBuildID, aDetailsURL, aBillboardURL, aLicenseURL, aShowPrompt, - aShowNeverForVersion, aShowSurvey, aExtra1, aVersion, - aExtensionVersion) + ">\n" + + aShowNeverForVersion, aShowSurvey, aVersion, + aExtensionVersion, aCustom1, aCustom2) + ">\n" + aPatches + " \n"; } @@ -255,8 +256,8 @@ function getLocalUpdateString(aPatches, aType, aName, aDisplayVersion, aServiceURL, aInstallDate, aStatusText, aIsCompleteUpdate, aChannel, aForegroundDownload, aShowPrompt, aShowNeverForVersion, aShowSurvey, - aExtra1, aVersion, aExtensionVersion, - aPreviousAppVersion) { + aVersion, aExtensionVersion, aPreviousAppVersion, + aCustom1, aCustom2) { var serviceURL = aServiceURL ? aServiceURL : "http://test_service/"; var installDate = aInstallDate ? aInstallDate : "1238441400314"; var statusText = aStatusText ? aStatusText : "Install Pending"; @@ -268,7 +269,8 @@ function getLocalUpdateString(aPatches, aType, aName, aDisplayVersion, return getUpdateString(aType, aName, aDisplayVersion, aAppVersion, aPlatformVersion, aBuildID, aDetailsURL, aBillboardURL, aLicenseURL, aShowPrompt, aShowNeverForVersion, - aShowSurvey, aExtra1, aVersion, aExtensionVersion) + + aShowSurvey, aVersion, aExtensionVersion, aCustom1, + aCustom2) + " " + previousAppVersion + "serviceURL=\"" + serviceURL + "\" " + @@ -343,22 +345,27 @@ function getLocalPatchString(aType, aURL, aHashFunction, aHashValue, aSize, * @param aShowSurvey * Whether to show the 'No Thanks' button in the update prompt. * If null will not be added and the backend will default to false. - * @param aExtra1 - * A custom string provided by the update xml for use by the - * application. - * If null will not be added. * @param aVersion * The update's application version from 1.9.2. * If null will not be present. * @param aExtensionVersion * The update's application version from 1.9.2. * If null will not be present. + * @param aCustom1 + * A custom attribute name AND attribute value to add to the xml. + * Example: custom1_attribute="custom1 value" + * If null will not be present. + * @param aCustom2 + * A custom attribute name AND attribute value to add to the xml. + * Example: custom2_attribute="custom2 value" + * If null will not be present. * @returns The string representing an update element for an update xml file. */ function getUpdateString(aType, aName, aDisplayVersion, aAppVersion, aPlatformVersion, aBuildID, aDetailsURL, aBillboardURL, aLicenseURL, aShowPrompt, aShowNeverForVersion, - aShowSurvey, aExtra1, aVersion, aExtensionVersion) { + aShowSurvey, aVersion, aExtensionVersion, aCustom1, + aCustom2) { var type = aType ? aType : "major"; var name = aName ? aName : "App Update Test"; var displayVersion = ""; @@ -390,7 +397,8 @@ function getUpdateString(aType, aName, aDisplayVersion, aAppVersion, var showPrompt = aShowPrompt ? "showPrompt=\"" + aShowPrompt + "\" " : ""; var showNeverForVersion = aShowNeverForVersion ? "showNeverForVersion=\"" + aShowNeverForVersion + "\" " : ""; var showSurvey = aShowSurvey ? "showSurvey=\"" + aShowSurvey + "\" " : ""; - var extra1 = aExtra1 ? "extra1=\"" + aExtra1 + "\" " : ""; + var custom1 = aCustom1 ? aCustom1 + " " : ""; + var custom2 = aCustom2 ? aCustom2 + " " : ""; return "