From 66adfcdd1569a382a1920b8a2bb15458e093c3f4 Mon Sep 17 00:00:00 2001 From: "ben%bengoodger.com" Date: Mon, 26 Apr 2004 04:58:59 +0000 Subject: [PATCH] more smartupdate work. git-svn-id: svn://10.0.0.236/trunk@155517 18797224-902f-48f8-a5cc-f745e15eee43 --- .../prefwindow/content/pref-advanced.js | 9 +- .../mozapps/extensions/content/extensions.js | 3 +- .../extensions/src/nsExtensionManager.js.in | 9 +- .../toolkit/mozapps/update/content/update.js | 51 ++++++- .../toolkit/mozapps/update/content/update.xul | 14 ++ .../mozapps/update/content/updates.xml | 6 +- .../toolkit/mozapps/update/locale/update.dtd | 8 ++ .../update/public/nsIUpdateService.idl | 16 ++- .../update/src/nsBackgroundUpdateService.js | 136 ++++++++++-------- mozilla/toolkit/mozapps/update/src/update.rdf | 2 +- 10 files changed, 181 insertions(+), 73 deletions(-) diff --git a/mozilla/browser/components/prefwindow/content/pref-advanced.js b/mozilla/browser/components/prefwindow/content/pref-advanced.js index c3210b464b0..ae258e9fee7 100644 --- a/mozilla/browser/components/prefwindow/content/pref-advanced.js +++ b/mozilla/browser/components/prefwindow/content/pref-advanced.js @@ -166,9 +166,10 @@ function openDeviceManager() function checkForUpdates() { - // XXXben - check for "all types" and the app itself here. - var em = Components.classes["@mozilla.org/extensions/manager;1"] - .getService(Components.interfaces.nsIExtensionManager); - em.update([], 0, Components.interfaces.nsIExtensionManager.UPDATE_TYPE_USERINVOKED); + var updates = Components.classes["@mozilla.org/updates/update-service;1"] + .getService(Components.interfaces.nsIUpdateService); + updates.checkForUpdates([], 0, Components.interfaces.nsIUpdateItem.TYPE_ANY, + Components.interfaces.nsIUpdateService.SOURCE_EVENT_USER, + window); } diff --git a/mozilla/toolkit/mozapps/extensions/content/extensions.js b/mozilla/toolkit/mozapps/extensions/content/extensions.js index 3d35aa9059e..1a70745284a 100644 --- a/mozilla/toolkit/mozapps/extensions/content/extensions.js +++ b/mozilla/toolkit/mozapps/extensions/content/extensions.js @@ -371,7 +371,8 @@ var gExtensionsViewController = { var updates = Components.classes["@mozilla.org/updates/update-service;1"] .getService(Components.interfaces.nsIUpdateService); updates.checkForUpdates(items, items.length, nsIUpdateItem.TYPE_EXTENSION, - Components.interfaces.nsIUpdateService.SOURCE_EVENT_USER); + Components.interfaces.nsIUpdateService.SOURCE_EVENT_USER, + window); }, cmd_uninstall: function () diff --git a/mozilla/toolkit/mozapps/extensions/src/nsExtensionManager.js.in b/mozilla/toolkit/mozapps/extensions/src/nsExtensionManager.js.in index 3b497fba479..cfba2d1c584 100644 --- a/mozilla/toolkit/mozapps/extensions/src/nsExtensionManager.js.in +++ b/mozilla/toolkit/mozapps/extensions/src/nsExtensionManager.js.in @@ -123,6 +123,8 @@ function nsExtensionManager() nsExtensionManager.prototype = { + + ///////////////////////////////////////////////////////////////////////////// // nsIObserver observe: function (aSubject, aTopic, aData) { @@ -153,8 +155,11 @@ nsExtensionManager.prototype = { // Now disable the extension so it won't hurt anything. this.disableExtension(items[i].id); } - this.update(items, items.length, - Components.interfaces.nsIExtensionManager.UPDATE_TYPE_MISMATCH); + var updates = Components.classes["@mozilla.org/updates/update-service;1"] + .getService(Components.interfaces.nsIUpdateService); + updates.checkForUpdates(items, items.length, Components.interfaces.nsIUpdateItem.TYPE_ADDON, + Components.interfaces.nsIExtensionManager.SOURCE_EVENT_MISMATCH, + null); } } diff --git a/mozilla/toolkit/mozapps/update/content/update.js b/mozilla/toolkit/mozapps/update/content/update.js index f851e050f47..64ac3e1df99 100644 --- a/mozilla/toolkit/mozapps/update/content/update.js +++ b/mozilla/toolkit/mozapps/update/content/update.js @@ -41,6 +41,7 @@ const nsIUpdateItem = Components.interfaces.nsIUpdateItem; const nsIUpdateService = Components.interfaces.nsIUpdateService; +const nsIExtensionManager = Components.interfaces.nsIExtensionManager; const PREF_APP_ID = "app.id"; const PREF_UPDATE_APP_UPDATESAVAILABLE = "update.app.updatesAvailable"; @@ -61,6 +62,8 @@ var gUpdateWizard = { shouldSuggestAutoChecking: false, shouldAutoCheck: false, + updatingApp: false, + init: function () { gUpdateTypes = window.arguments[0]; @@ -93,6 +96,34 @@ var gUpdateWizard = { .getService(Components.interfaces.nsIPrefBranch); pref.setBoolPref("update.extensions.enabled", this.shouldAutoCheck); } + + if (this.updatingApp) { + var updates = Components.classes["@mozilla.org/updates/update-service;1"] + .getService(Components.interfaces.nsIUpdateService); +# If we're not a browser, use the external protocol service to load the URI. +#ifndef MOZ_PHOENIX + var uri = Components.classes["@mozilla.org/network/standard-url;1"] + .createInstance(Components.interfaces.nsIURI); + uri.spec = updates.appUpdateURL; + + var protocolSvc = Components.classes["@mozilla.org/uriloader/external-protocol-service;1"] + .getService(Components.interfaces.nsIExternalProtocolService); + if (protocolSvc.isExposedProtocol(uri.scheme)) + protocolSvc.loadUrl(uri); +# If we're a browser, open a new browser window instead. +#else + var ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"] + .getService(Components.interfaces.nsIWindowWatcher); + var ary = Components.classes["@mozilla.org/supports-array;1"] + .createInstance(Components.interfaces.nsISupportsArray); + var url = Components.classes["@mozilla.org/supports-string;1"] + .createInstance(Components.interfaces.nsISupportsString); + url.data = updates.appUpdateURL; + ary.AppendElement(url); + ww.openWindow(null, "chrome://browser/content/browser.xul", + "_blank", "chrome,all,dialog=no", ary); +#endif + } }, _setUpButton: function (aButtonID, aButtonKey, aDisabled) @@ -168,7 +199,8 @@ var gUpdatePage = { var updates = Components.classes["@mozilla.org/updates/update-service;1"] .getService(Components.interfaces.nsIUpdateService); - updates.checkForUpdatesInternal(gUpdateWizard.items, gUpdateWizard.items.length, gUpdateTypes); + updates.checkForUpdatesInternal(gUpdateWizard.items, gUpdateWizard.items.length, + gUpdateTypes, gSourceEvent); this._updateState = nsIUpdateService.UPDATED_NONE; }, @@ -273,6 +305,7 @@ var gFoundPage = { this._appUpdateExists = true; this._appSelected = true; this._appItem = updateitem; + document.getElementById("found").setAttribute("next", "appupdate"); } else { updateitem.checked = !this._appUpdateExists; @@ -293,9 +326,11 @@ var gFoundPage = { var nonAppItem = this._nonAppItems[i]; nonAppItem.checked = !aEvent.target.checked; } + document.getElementById("found").setAttribute("next", "appupdate"); } else { this._appItem.checked = false; + document.getElementById("found").setAttribute("next", "installing"); } } @@ -312,6 +347,18 @@ var gFoundPage = { } }; +var gAppUpdatePage = { + onPageShow: function () + { + gUpdateWizard.setButtonLabels(null, true, + null, true, + null, true); + gUpdateWizard.updatingApp = true; + + document.documentElement.getButton("finish").focus(); + } +}; + var gInstallingPage = { onPageShow: function () { @@ -355,7 +402,7 @@ var gFinishedPage = { fEC.hidden = true; } - if (gSourceEvent == nsIUpdateService.SOURCE_EVENT_MISMATCH) { + if (gSourceEvent == nsIExtensionManager.SOURCE_EVENT_MISMATCH) { document.getElementById("finishedMismatch").hidden = false; document.getElementById("incompatibleAlert").hidden = false; } diff --git a/mozilla/toolkit/mozapps/update/content/update.xul b/mozilla/toolkit/mozapps/update/content/update.xul index 2cab56f80eb..90acafda0b7 100644 --- a/mozilla/toolkit/mozapps/update/content/update.xul +++ b/mozilla/toolkit/mozapps/update/content/update.xul @@ -113,6 +113,20 @@ + + + + + + + + + + + + diff --git a/mozilla/toolkit/mozapps/update/content/updates.xml b/mozilla/toolkit/mozapps/update/content/updates.xml index 9e063bd5c2b..cd32bd11008 100644 --- a/mozilla/toolkit/mozapps/update/content/updates.xml +++ b/mozilla/toolkit/mozapps/update/content/updates.xml @@ -48,7 +48,8 @@ this.updateCount = updates.updateCount; #ifdef XP_WIN - this._showUpdateInfo(); + if (parseInt(aData) == Components.interfaces.nsIUpdateService.SOURCE_EVENT_BACKGROUND) + this._showUpdateInfo(); #endif } ]]> @@ -99,7 +100,8 @@ var updates = Components.classes["@mozilla.org/updates/update-service;1"] .getService(Components.interfaces.nsIUpdateService); updates.checkForUpdates([], 0, Components.interfaces.nsIUpdateItem.TYPE_ANY, - Components.interfaces.nsIUpdateService.SOURCE_EVENT_USER); + Components.interfaces.nsIUpdateService.SOURCE_EVENT_USER, + window); ]]> diff --git a/mozilla/toolkit/mozapps/update/locale/update.dtd b/mozilla/toolkit/mozapps/update/locale/update.dtd index be32c32111d..f5230c2f5dc 100644 --- a/mozilla/toolkit/mozapps/update/locale/update.dtd +++ b/mozilla/toolkit/mozapps/update/locale/update.dtd @@ -49,3 +49,11 @@ + + + + + + diff --git a/mozilla/toolkit/mozapps/update/public/nsIUpdateService.idl b/mozilla/toolkit/mozapps/update/public/nsIUpdateService.idl index 8dc30e90222..f91f89754e5 100644 --- a/mozilla/toolkit/mozapps/update/public/nsIUpdateService.idl +++ b/mozilla/toolkit/mozapps/update/public/nsIUpdateService.idl @@ -38,6 +38,8 @@ #include "nsISupports.idl" +interface nsIDOMWindowInternal; + [scriptable, uuid(37648f86-0f77-4007-929e-673a75d5438f)] interface nsIUpdateItem : nsISupports { @@ -50,9 +52,11 @@ interface nsIUpdateItem : nsISupports const unsigned short TYPE_ANY = 0x01; const unsigned short TYPE_APP = 0x02; - const unsigned short TYPE_EXTENSION = 0x04; - const unsigned short TYPE_THEME = 0x08; - const unsigned short TYPE_LOCALE = 0x10; + const unsigned short TYPE_ADDON = 0x04; + + const unsigned short TYPE_EXTENSION = 0x08; + const unsigned short TYPE_THEME = 0x10; + const unsigned short TYPE_LOCALE = 0x20; readonly attribute long type; @@ -74,10 +78,12 @@ interface nsIUpdateService : nsISupports void checkForUpdates([array, size_is(aItemCount)] in nsIUpdateItem aItems, in unsigned long aItemCount, in unsigned short aUpdateTypes, - in unsigned short aSourceEvent); + in unsigned short aSourceEvent, + in nsIDOMWindowInternal aParentWindow); void checkForUpdatesInternal([array, size_is(aItemCount)] in nsIUpdateItem aItems, in unsigned long aItemCount, - in unsigned short aUpdateTypes); + in unsigned short aUpdateTypes, + in unsigned short aSourceEvent); readonly attribute long updateCount; readonly attribute unsigned short updateSeverity; diff --git a/mozilla/toolkit/mozapps/update/src/nsBackgroundUpdateService.js b/mozilla/toolkit/mozapps/update/src/nsBackgroundUpdateService.js index 82384c64140..2ab20b89991 100644 --- a/mozilla/toolkit/mozapps/update/src/nsBackgroundUpdateService.js +++ b/mozilla/toolkit/mozapps/update/src/nsBackgroundUpdateService.js @@ -67,7 +67,7 @@ function nsBackgroundUpdateService() nsBackgroundUpdateService.prototype = { _timer: null, _pref: null, - + ///////////////////////////////////////////////////////////////////////////// // nsIUpdateService watchForUpdates: function () @@ -83,15 +83,17 @@ nsBackgroundUpdateService.prototype = { var interval = this._pref.getIntPref(PREF_UPDATE_INTERVAL); var lastUpdateTime = this._pref.getIntPref(PREF_UPDATE_LASTUPDATEDATE); var timeSinceLastCheck = Date.UTC() - lastUpdateTime; - this.checkForUpdatesInternal([], 0, nsIUpdateItem.TYPE_ANY); /// XXXben + this.checkForUpdatesInternal([], 0, nsIUpdateItem.TYPE_ANY, + nsIUpdateService.SOURCE_EVENT_BACKGROUND); /// XXXben if (timeSinceLastCheck > interval) - this.checkForUpdatesInternal([], 0, nsIUpdateItem.TYPE_ANY); + this.checkForUpdatesInternal([], 0, nsIUpdateItem.TYPE_ANY, + nsIUpdateService.SOURCE_EVENT_BACKGROUND); else this._makeTimer(interval - timeSinceLastCheck); }, - checkForUpdates: function (aItems, aItemCount, aUpdateTypes, aSourceEvent) + checkForUpdates: function (aItems, aItemCount, aUpdateTypes, aSourceEvent, aParentWindow) { switch (aSourceEvent) { case Components.interfaces.nsIExtensionManager.SOURCE_EVENT_MISMATCH: @@ -110,7 +112,7 @@ nsBackgroundUpdateService.prototype = { ary.AppendElement(sourceEvent); for (var i = 0; i < aItems.length; ++i) ary.AppendElement(aItems[i]); - ww.openWindow(null, "chrome://mozapps/content/update/update.xul", + ww.openWindow(aParentWindow, "chrome://mozapps/content/update/update.xul", "", "chrome,modal,centerscreen", ary); break; case nsIUpdateService.SOURCE_EVENT_BACKGROUND: @@ -127,18 +129,17 @@ nsBackgroundUpdateService.prototype = { } }, - checkForUpdatesInternal: function (aItems, aItemCount, aUpdateTypes) + checkForUpdatesInternal: function (aItems, aItemCount, aUpdateTypes, aSourceEvent) { // Listen for notifications sent out by the app updater (implemented here) and the // extension updater (implemented in nsExtensionItemUpdater) + var updateObserver = new nsUpdateObserver(aUpdateTypes, aSourceEvent); var os = Components.classes["@mozilla.org/observer-service;1"] .getService(Components.interfaces.nsIObserverService); - os.addObserver(this, "Update:Extension:Item-Ended", false); - os.addObserver(this, "Update:Extension:Ended", false); - os.addObserver(this, "Update:App:Ended", false); + os.addObserver(updateObserver, "Update:Extension:Item-Ended", false); + os.addObserver(updateObserver, "Update:Extension:Ended", false); + os.addObserver(updateObserver, "Update:App:Ended", false); - this._updateState = 0; - var appUpdatesEnabled = this._pref.getBoolPref(PREF_UPDATE_APP_ENABLED); var extUpdatesEnabled = this._pref.getBoolPref(PREF_UPDATE_EXTENSIONS_ENABLED); @@ -176,65 +177,28 @@ nsBackgroundUpdateService.prototype = { get appUpdateVersion() { - return this._pref.getComplexValue(PREF_UPDATE_APP_UPDATEVERSION, Components.interfaces.nsISupportsString).data; + return this._pref.getComplexValue(PREF_UPDATE_APP_UPDATEVERSION, + Components.interfaces.nsISupportsString).data; }, get appUpdateDescription() { - return this._pref.getComplexValue(PREF_UPDATE_APP_UPDATEDESCRIPTION, Components.interfaces.nsISupportsString).data; + return this._pref.getComplexValue(PREF_UPDATE_APP_UPDATEDESCRIPTION, + Components.interfaces.nsISupportsString).data; }, get appUpdateURL() { - return this._pref.getComplexValue(PREF_UPDATE_APP_UPDATEURL, Components.interfaces.nsISupportsString).data; - }, - - ///////////////////////////////////////////////////////////////////////////// - // nsIObserver - _updateState: 0, - get _doneUpdating() - { - var test = 0; - if (this._pref.getBoolPref(PREF_UPDATE_APP_ENABLED)) - test |= UPDATED_APP; - if (this._pref.getBoolPref(PREF_UPDATE_EXTENSIONS_ENABLED)) - test |= UPDATED_EXTENSIONS; - return (this._updateState & test) == test; - }, - - observe: function (aSubject, aTopic, aData) - { - switch (aTopic) { - case "Update:Extension:Item-Ended": - this._pref.setIntPref(PREF_UPDATE_EXTENSIONS_COUNT, - this._pref.getIntPref(PREF_UPDATE_EXTENSIONS_COUNT) + 1); - break; - case "Update:Extension:Ended": - this._updateState |= UPDATED_EXTENSIONS; - break; - case "Update:App:Ended": - this._updateState |= UPDATED_APP; - break; - } - - if (this._doneUpdating) { - // The Inline Browser Update UI uses this notification to refresh its update - // UI if necessary. - var os = Components.classes["@mozilla.org/observer-service;1"] - .getService(Components.interfaces.nsIObserverService); - os.notifyObservers(null, "Update:Ended", ""); - - os.removeObserver(this, "Update:Extension:Item-Ended"); - os.removeObserver(this, "Update:Extension:Ended"); - os.removeObserver(this, "Update:App:Ended"); - } + return this._pref.getComplexValue(PREF_UPDATE_APP_UPDATEURL, + Components.interfaces.nsISupportsString).data; }, ///////////////////////////////////////////////////////////////////////////// // nsITimerCallback notify: function (aTimer) { - this.checkForUpdatesNow(); + this.checkForUpdatesInternal([], 0, nsIUpdateItem.TYPE_ANY, + nsIUpdateService.SOURCE_EVENT_BACKGROUND); }, ///////////////////////////////////////////////////////////////////////////// @@ -261,6 +225,66 @@ nsBackgroundUpdateService.prototype = { } }; +function nsUpdateObserver(aUpdateTypes, aSourceEvent) +{ + this._pref = Components.classes["@mozilla.org/preferences-service;1"] + .getService(Components.interfaces.nsIPrefBranch); + this._updateTypes = aUpdateTypes; + this._sourceEvent = aSourceEvent; +} + +nsUpdateObserver.prototype = { + _updateTypes: 0, + _sourceEvent: 0, + _updateState: 0, + get _doneUpdating() + { + var test = 0; + var updatingApp = this._updateTypes == nsIUpdateItem.TYPE_ANY || + this._updateTypes == nsIUpdateItem.TYPE_APP; + var updatingExt = this._updateTypes != nsIUpdateItem.TYPE_APP; + + if (this._pref.getBoolPref(PREF_UPDATE_APP_ENABLED) && + updatingApp) + test |= UPDATED_APP; + if (this._pref.getBoolPref(PREF_UPDATE_EXTENSIONS_ENABLED) && + updatingExt) + test |= UPDATED_EXTENSIONS; + + return (this._updateState & test) == test; + }, + + ///////////////////////////////////////////////////////////////////////////// + // nsIObserver + observe: function (aSubject, aTopic, aData) + { + switch (aTopic) { + case "Update:Extension:Item-Ended": + this._pref.setIntPref(PREF_UPDATE_EXTENSIONS_COUNT, + this._pref.getIntPref(PREF_UPDATE_EXTENSIONS_COUNT) + 1); + break; + case "Update:Extension:Ended": + this._updateState |= UPDATED_EXTENSIONS; + break; + case "Update:App:Ended": + this._updateState |= UPDATED_APP; + break; + } + + if (this._doneUpdating) { + // The Inline Browser Update UI uses this notification to refresh its update + // UI if necessary. + var os = Components.classes["@mozilla.org/observer-service;1"] + .getService(Components.interfaces.nsIObserverService); + os.notifyObservers(null, "Update:Ended", this._sourceEvent.toString()); + + os.removeObserver(this, "Update:Extension:Item-Ended"); + os.removeObserver(this, "Update:Extension:Ended"); + os.removeObserver(this, "Update:App:Ended"); + } + } +}; + function nsAppUpdateXMLRDFDSObserver(aUpdateService) { this._updateService = aUpdateService; diff --git a/mozilla/toolkit/mozapps/update/src/update.rdf b/mozilla/toolkit/mozapps/update/src/update.rdf index 6b25d9bab01..0c56c875df7 100644 --- a/mozilla/toolkit/mozapps/update/src/update.rdf +++ b/mozilla/toolkit/mozapps/update/src/update.rdf @@ -10,7 +10,7 @@ - 0 + 2 http://www.mozilla.org/products/firefox/