From 1b88aad30a5b1f681c8b70a9b8243a477dcccc9f Mon Sep 17 00:00:00 2001 From: "ben%bengoodger.com" Date: Wed, 28 Apr 2004 07:30:08 +0000 Subject: [PATCH] Make the update wizard actually invoke XPInstall APIs to install the updates --- .../extensions/src/nsExtensionManager.js.in | 105 +++++++++++++++--- toolkit/mozapps/jar.mn | 2 + toolkit/mozapps/update/content/errors.xul | 81 ++++++++++++++ toolkit/mozapps/update/content/update.js | 69 ++++++++++-- toolkit/mozapps/update/content/update.xul | 14 ++- toolkit/mozapps/update/content/updates.xml | 17 ++- toolkit/mozapps/update/locale/errors.dtd | 5 + toolkit/mozapps/update/locale/update.dtd | 18 ++- .../mozapps/update/locale/update.properties | 4 + .../update/src/nsBackgroundUpdateService.js | 3 - 10 files changed, 279 insertions(+), 39 deletions(-) create mode 100644 toolkit/mozapps/update/content/errors.xul create mode 100644 toolkit/mozapps/update/locale/errors.dtd diff --git a/toolkit/mozapps/extensions/src/nsExtensionManager.js.in b/toolkit/mozapps/extensions/src/nsExtensionManager.js.in index ff010c03c9f7..4f81b0104903 100644 --- a/toolkit/mozapps/extensions/src/nsExtensionManager.js.in +++ b/toolkit/mozapps/extensions/src/nsExtensionManager.js.in @@ -164,6 +164,36 @@ nsExtensionManager.prototype = { // we don't do this every time we start. autoregFile.remove(false); } + + // Load default preferences files for all extensions + + var defaultsManifest = fileLocator.get("ProfD", Components.interfaces.nsIFile); + defaultsManifest.append("extensions"); + defaultsManifest.append("Defaults"); + if (defaultsManifest.exists()) { + var pref = Components.classes["@mozilla.org/preferences-service;1"] + .getService(Components.interfaces.nsIPrefService); + var fis = Components.classes["@mozilla.org/network/file-input-stream;1"] + .createInstance(Components.interfaces.nsIFileInputStream); + fis.init(defaultsManifest, -1, -1, false); + var lis = fis.QueryInterface(Components.interfaces.nsILineInputStream); + var line = { value: "" }; + var more = false; + do { + more = lis.readLine(line); + var lf = Components.classes["@mozilla.org/file/local;1"] + .createInstance(Components.interfaces.nsILocalFile); + var path = line.value; + if (path.charAt(path.length-1) == "\n") + path = path.substr(0, path.length - 1); + lf.initWithPath(path); + + if (lf.exists()) + pref.readUserPrefs(lf); + } + while (more); + fis.close(); + } break; } }, @@ -175,7 +205,7 @@ nsExtensionManager.prototype = { // Check to see if the version of the application that is being started // now is the same one that was started last time. var pref = Components.classes["@mozilla.org/preferences-service;1"] - .getService(Components.interfaces.nsIPrefBranch); + .getService(Components.interfaces.nsIPrefBranch); var currAppVersion = pref.getCharPref(PREF_EM_APP_VERSION); try { var lastAppVersion = pref.getCharPref(PREF_EM_LAST_APP_VERSION); @@ -211,7 +241,7 @@ nsExtensionManager.prototype = { return rv; }, - _writeAutoReg: function () + _writeProfileFile: function (aSubfolder, aFileName, aGetDirFunc, aWriteLineFunc) { // When an operation is performed that requires a component re-registration // (extension enabled/disabled, installed, uninstalled), we must write the @@ -230,14 +260,16 @@ nsExtensionManager.prototype = { // Open the .autoreg file for writing. - var autoregFile = profileDir.clone(); - autoregFile.append(".autoreg"); + var dataFile = profileDir.clone(); + if (aSubfolder) + dataFile.append(aSubfolder); + dataFile.append(aFileName); var fos = Components.classes["@mozilla.org/network/file-output-stream;1"] .createInstance(Components.interfaces.nsIFileOutputStream); const MODE_WRONLY = 0x02; const MODE_CREATE = 0x08; const MODE_TRUNCATE = 0x20; - fos.init(autoregFile, MODE_WRONLY | MODE_CREATE | MODE_TRUNCATE, 0664, 0); + fos.init(dataFile, MODE_WRONLY | MODE_CREATE | MODE_TRUNCATE, 0664, 0); var extensions = this.getItemList(null, Components.interfaces.nsIUpdateItem.TYPE_EXTENSION, { }); for (var i = 0; i < extensions.length; ++i) { @@ -254,19 +286,60 @@ nsExtensionManager.prototype = { var dir = location == "profile" ? profileDir : globalDir; // Now synthesize the components dir for the extension - var componentsDir = dir.clone(); - componentsDir.append("extensions"); - componentsDir.append(extension.id); - componentsDir.append("components"); - if (componentsDir.exists()) { + var sourceDir = aGetDirFunc(dir, extension.id); + if (sourceDir.exists()) { // write the relative path of the components dir - var line = "reg:extensions/" + extension.id + "/components/\n"; - fos.write(line, line.length); + aWriteLineFunc(fos, sourceDir, extension.id); } } fos.close(); }, + + _getComponentsDir: function (aSourceDir, aExtensionID) + { + var sourceDir = aSourceDir.clone(); + sourceDir.append("extensions"); + sourceDir.append(aExtensionID); + sourceDir.append("components"); + return sourceDir; + }, + + _getPreferencesDir: function (aSourceDir, aExtensionID) + { + var sourceDir = aSourceDir.clone(); + sourceDir.append("extensions"); + sourceDir.append(aExtensionID); + sourceDir.append("defaults"); + sourceDir.append("preferences"); + return sourceDir; + }, + + _writeAutoregLines: function (aStream, aSourceDir, aExtensionID) + { + var line = "reg:extensions/" + aExtensionID + "/components/\n"; + aStream.write(line, line.length); + }, + + _writePreferencesLines: function (aStream, aSourceDir, aExtensionID) + { + var files = aSourceDir.directoryEntries; + while (files.hasMoreElements()) { + var file = files.getNext().QueryInterface(Components.interfaces.nsILocalFile); + var line = file.path + "\n"; + aStream.write(line, line.length); + } + }, + _writeProfileData: function () + { + this._writeProfileFile(null, ".autoreg", + this._getComponentsDir, + this._writeAutoregLines); + this._writeProfileFile("extensions", "Defaults", + this._getPreferencesDir, + this._writePreferencesLines); + }, + ///////////////////////////////////////////////////////////////////////////// // nsIExtensionManager installExtensionFromStream: function (aStream, aUseProfile) @@ -290,25 +363,25 @@ nsExtensionManager.prototype = { this._ensureDS(); this._ds.installExtension(ds, aUseProfile); - this._writeAutoReg(); + this._writeProfileData(); }, uninstallExtension: function (aExtensionID) { this._ds.uninstallExtension(aExtensionID); - this._writeAutoReg(); + this._writeProfileData(); }, enableExtension: function (aExtensionID) { this._ds.enableExtension(aExtensionID); - this._writeAutoReg(); + this._writeProfileData(); }, disableExtension: function (aExtensionID) { this._ds.disableExtension(aExtensionID); - this._writeAutoReg(); + this._writeProfileData(); }, // XXXben - handle the case where the item provides its own update url. diff --git a/toolkit/mozapps/jar.mn b/toolkit/mozapps/jar.mn index 0579648ffc0e..2f4b24f1206c 100755 --- a/toolkit/mozapps/jar.mn +++ b/toolkit/mozapps/jar.mn @@ -23,6 +23,7 @@ toolkit.jar: * content/mozapps/update/update.js (update/content/update.js) * content/mozapps/update/updates.xml (update/content/updates.xml) * content/mozapps/update/update.css (update/content/update.css) +* content/mozapps/update/errors.xul (update/content/errors.xul) * content/mozapps/shared/richview.xml (shared/content/richview.xml) content/mozapps/contents.rdf (contents-content.rdf) @@ -39,6 +40,7 @@ en-US.jar: locale/en-US/mozapps/extensions/about.dtd (extensions/locale/about.dtd) locale/en-US/mozapps/update/update.dtd (update/locale/update.dtd) locale/en-US/mozapps/update/update.properties (update/locale/update.properties) + locale/en-US/mozapps/update/errors.dtd (update/locale/errors.dtd) locale/en-US/mozapps/contents.rdf (contents-locale.rdf) classic.jar: diff --git a/toolkit/mozapps/update/content/errors.xul b/toolkit/mozapps/update/content/errors.xul new file mode 100644 index 000000000000..f36389cf66d6 --- /dev/null +++ b/toolkit/mozapps/update/content/errors.xul @@ -0,0 +1,81 @@ + + +# -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- +# 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 Ben Goodger. +# Portions created by the Initial Developer are Copyright (C) 2004 +# the Initial Developer. All Rights Reserved. +# +# Contributor(s): +# Ben Goodger +# +# 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 ***** + + + + + + + + + + + + + + + + + + + + diff --git a/toolkit/mozapps/update/content/update.js b/toolkit/mozapps/update/content/update.js index 8a339310e24b..eb9bb6718eb7 100644 --- a/toolkit/mozapps/update/content/update.js +++ b/toolkit/mozapps/update/content/update.js @@ -368,17 +368,72 @@ var gInstallingPage = { // Get XPInstallManager and kick off download/install // process, registering us as an observer. - - //XXXben - window.advance = function() - { - document.getElementById("installing").setAttribute("next", "finished"); - document.documentElement.advance(); + var items = []; + + var foundList = document.getElementById("foundList"); + for (var i = 0; i < foundList.childNodes.length; ++i) { + var item = foundList.childNodes[i]; + if (item.type != nsIUpdateItem.TYPE_APP) { + items.push(item.url); + this._objs.push({ name: item.name }); + } } - setTimeout("advance()", 2000); + + var xpimgr = Components.classes["@mozilla.org/xpinstall/install-manager;1"] + .createInstance(Components.interfaces.nsIXPInstallManager); + xpimgr.initManagerFromChrome(items, items.length, this); + }, + + ///////////////////////////////////////////////////////////////////////////// + // nsIXPIProgressDialog + onStateChange: function (aIndex, aState, aValue) + { + var strings = document.getElementById("updateStrings"); + + const nsIXPIProgressDialog = Components.interfaces.nsIXPIProgressDialog; + switch (aState) { + case nsIXPIProgressDialog.DOWNLOAD_START: + var label = strings.getFormattedString("downloadingPrefix", [this._objs[aIndex].name]); + var actionItem = document.getElementById("actionItem"); + actionItem.value = label; + break; + case nsIXPIProgressDialog.DOWNLOAD_DONE: + case nsIXPIProgressDialog.INSTALL_START: + var label = strings.getFormattedString("installingPrefix", [this._objs[aIndex].name]); + var actionItem = document.getElementById("actionItem"); + actionItem.value = label; + break; + case nsIXPIProgressDialog.INSTALL_DONE: + if (aValue) { + this._objs[aIndex].error = aValue; + this._errors = true; + } + break; + case nsIXPIProgressDialog.DIALOG_CLOSE: + document.getElementById("installing").setAttribute("next", this._errors ? "errors" : "finished"); + document.documentElement.advance(); + break; + } + }, + + _objs: [], + _errors: false, + + onProgress: function (aIndex, aValue, aMaxValue) + { + var downloadProgress = document.getElementById("downloadProgress"); + downloadProgress.value = Math.ceil((aValue/aMaxValue) * 100); } }; +var gErrorsPage = { + onShowErrors: function () + { + openDialog("chrome://mozapps/content/update/errors.xul", "", + "modal", gInstallingPage._objs); + } +}; + var gFinishedPage = { onPageShow: function () diff --git a/toolkit/mozapps/update/content/update.xul b/toolkit/mozapps/update/content/update.xul index 90acafda0b7a..92584994f3d6 100644 --- a/toolkit/mozapps/update/content/update.xul +++ b/toolkit/mozapps/update/content/update.xul @@ -131,10 +131,20 @@ label="&installing.title;" onpageshow="gInstallingPage.onPageShow();"> - +