214360 - more update notifications work... reorganize some of the apis so they make a bit more sense and are easier to work with

This commit is contained in:
ben%bengoodger.com 2004-04-25 08:52:06 +00:00
parent d7d0a53988
commit e0629f624a
10 changed files with 153 additions and 98 deletions

View File

@ -368,8 +368,10 @@ var gExtensionsViewController = {
{
var id = stripPrefix(gExtensionsView.selected.id);
var items = gExtensionManager.getItemList(id, nsIUpdateItem.TYPE_EXTENSION, { });
gExtensionManager.update(items, items.length,
Components.interfaces.nsIUpdateItem.UPDATE_TYPE_USERINVOKED);
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);
},
cmd_uninstall: function ()

View File

@ -53,16 +53,13 @@ interface nsIExtensionManager : nsISupports
void installTheme(in string aThemeID);
void uninstallTheme(in string aThemeID);
const unsigned short UPDATE_TYPE_MISMATCH = 0x01;
const unsigned short UPDATE_TYPE_USERINVOKED = 0x02;
const unsigned short UPDATE_TYPE_BACKGROUND = 0x04;
const unsigned short SOURCE_EVENT_MISMATCH = 0x01;
const unsigned short UPDATE_RESULT_OK = 0x00;
const unsigned short UPDATE_RESULT_RESTART = 0x01;
unsigned short update([array, size_is(aItemCount)] in nsIUpdateItem aItems,
in unsigned long aItemCount,
in unsigned short aUpdateType);
in unsigned long aItemCount);
void getItemList(in string aItemID,
in unsigned short aType,
@ -77,6 +74,7 @@ interface nsIExtensionItemUpdater : nsISupports
{
void checkForUpdates();
readonly attribute unsigned short updateType;
readonly attribute unsigned short sourceEvent;
readonly attribute unsigned short updateTypes;
};

View File

@ -203,7 +203,7 @@ nsExtensionManager.prototype = {
this._ds.disableExtension(aExtensionID);
},
update: function (aItems, aItemCount, aUpdateType)
update: function (aItems, aItemCount)
{
var pref = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
@ -211,30 +211,11 @@ nsExtensionManager.prototype = {
var appVersion = pref.getCharPref(PREF_EM_APP_VERSION);
if (aItems.length == 0) {
var itemType = Components.interfaces.nsIUpdateItem.TYPE_ANY;
aItems = this.getItemList(null, itemType, { });
}
var updater = new nsExtensionItemUpdater(aUpdateType, aItems, appID, appVersion);
switch (aUpdateType) {
case Components.interfaces.nsIExtensionManager.UPDATE_TYPE_MISMATCH:
case Components.interfaces.nsIExtensionManager.UPDATE_TYPE_USERINVOKED:
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);
ary.AppendElement(updater);
for (var i = 0; i < aItems.length; ++i)
ary.AppendElement(aItems[i]);
ww.openWindow(null, "chrome://mozapps/content/update/update.xul",
"", "chrome,modal,centerscreen", ary);
break;
case Components.interfaces.nsIExtensionManager.UPDATE_TYPE_BACKGROUND:
// The Background Updater Service adds itself as a listener for
// the various kinds of messages that the updater sends out.
updater.checkForUpdates();
break;
var anyType = Components.interfaces.nsIUpdateItem.TYPE_ANY;
aItems = this.getItemList(null, anyType, { });
}
var updater = new nsExtensionItemUpdater(aItems, appID, appVersion);
updater.checkForUpdates();
},
getItemList: function (aItemID, aType, aCountRef)
@ -287,9 +268,8 @@ nsExtensionManager.prototype = {
}
};
function nsExtensionItemUpdater(aUpdateType, aItems, aTargetAppID, aTargetAppVersion)
function nsExtensionItemUpdater(aItems, aTargetAppID, aTargetAppVersion)
{
this._updateType = aUpdateType;
this._items = aItems;
this._count = aItems.length;
this._appID = aTargetAppID;
@ -314,11 +294,6 @@ nsExtensionItemUpdater.prototype = {
"VersionCheck", "", true, this);
},
get updateType()
{
return this._updateType;
},
/////////////////////////////////////////////////////////////////////////////
// nsExtensionItemUpdater
_proxy: null,

View File

@ -48,6 +48,7 @@ classic.jar:
skin/classic/mozapps/extensions/viewWatermark.png (extensions/skin/viewWatermark.png)
skin/classic/mozapps/update/update.css (update/skin/update.css)
skin/classic/mozapps/update/warning.gif (update/skin/warning.gif)
+ skin/classic/mozapps/update/icon32.png (update/skin/icon32.png)
skin/classic/mozapps/shared/richview.xml (shared/skin/richview.xml)
skin/classic/mozapps/shared/richview.css (shared/skin/richview.css)
skin/classic/mozapps/shared/viewFader.png (shared/skin/viewFader.png)

View File

@ -1,6 +1,4 @@
//
// window.arguments[0] is the nsIExtensionItemUpdater object
//
// window.arguments[1...] is an array of nsIUpdateItem implementing objects
// that are to be updated.
// * if the array is empty, all items are updated (like a background update
@ -41,11 +39,14 @@
// performed again.
//
const nsIUpdateItem = Components.interfaces.nsIUpdateItem;
const MISMATCH = Components.interfaces.nsIExtensionManager.UPDATE_TYPE_MISMATCH;
const USERINVOKED = Components.interfaces.nsIExtensionManager.UPDATE_TYPE_USERINVOKED;
const nsIUpdateItem = Components.interfaces.nsIUpdateItem;
const nsIUpdateService = Components.interfaces.nsIUpdateService;
var gUpdater = null;
const PREF_APP_ID = "app.id";
const PREF_UPDATE_APP_UPDATESAVAILABLE = "update.app.updatesAvailable";
var gSourceEvent = null;
var gUpdateTypes = null;
var gUpdateWizard = {
// The items to check for updates for (e.g. an extension, some subset of extensions,
@ -62,16 +63,17 @@ var gUpdateWizard = {
init: function ()
{
gUpdater = window.arguments[0].QueryInterface(Components.interfaces.nsIExtensionItemUpdater);
for (var i = 1; i < window.arguments.length; ++i)
gUpdateTypes = window.arguments[0];
gSourceEvent = window.arguments[1];
for (var i = 2; i < window.arguments.length; ++i)
this.items.push(window.arguments[i].QueryInterface(nsIUpdateItem));
var pref = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
this.shouldSuggestAutoChecking = (gUpdater.updateType == MISMATCH) &&
!pref.getBoolPref("update.extensions.enabled");
this.shouldSuggestAutoChecking = (gSourceEvent == nsIUpdateService.SOURCE_EVENT_MISMATCH) &&
!pref.getBoolPref("update.extensions.enabled");
if (gUpdater.updateType == USERINVOKED) {
if (gSourceEvent == nsIUpdateService.SOURCE_EVENT_USER) {
document.getElementById("mismatch").setAttribute("next", "checking");
document.documentElement.advance();
}
@ -138,7 +140,6 @@ var gMismatchPage = {
}
};
const nsIBUS = Components.interfaces.nsIBackgroundUpdateService;
var gUpdatePage = {
_completeCount: 0,
_updateState: 0,
@ -146,7 +147,9 @@ var gUpdatePage = {
"Update:Extension:Ended",
"Update:Extension:Item-Started",
"Update:Extension:Item-Ended",
"Update:Extension:Item-Error"],
"Update:Extension:Item-Error",
"Update:App:Ended",
"Update:Ended"],
onPageShow: function ()
{
@ -160,9 +163,11 @@ var gUpdatePage = {
for (var i = 0; i < this._messages.length; ++i)
os.addObserver(this, this._messages[i], false);
gUpdater.checkForUpdates();
this._updateState = nsIBUS.UPDATED_NONE;
var updates = Components.classes["@mozilla.org/updates/update-service;1"]
.getService(Components.interfaces.nsIUpdateService);
updates.checkForUpdatesInternal(gUpdateWizard.items, gUpdateWizard.items.length, gUpdateTypes);
this._updateState = nsIUpdateService.UPDATED_NONE;
},
uninit: function ()
@ -194,7 +199,8 @@ var gUpdatePage = {
// If we were passed a set of extensions/themes/other to update, this
// means we're not checking for app updates, so don't wait for the app
// update to complete before advancing (because there is none).
canFinish = gUpdateWizard.items.length > 0;
// canFinish = gUpdateWizard.items.length > 0;
// XXXben
break;
case "Update:Ended":
// If we're doing a general update check, (that is, no specific extensions/themes
@ -207,7 +213,23 @@ var gUpdatePage = {
// updates so it can list them first.
var pref = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
gUpdateWizard.appUpdatesAvailable = pref.getBoolPref(PREF_UPDATE_APPUPDATESAVAILABLE);
gUpdateWizard.appUpdatesAvailable = pref.getBoolPref(PREF_UPDATE_APP_UPDATESAVAILABLE);
if (gUpdateWizard.appUpdatesAvailable) {
var appID = pref.getCharPref(PREF_APP_ID);
var updates = Components.classes["@mozilla.org/updates/update-service;1"]
.getService(Components.interfaces.nsIUpdateService);
var brandShortName = document.getElementById("brandStrings").getString("brandShortName");
var item = Components.classes["@mozilla.org/updates/item;1"]
.createInstance(Components.interfaces.nsIUpdateItem);
item.init(appID, updates.appUpdateVersion,
brandShortName, -1, updates.appUpdateURL,
"chrome://mozapps/skin/update/icon32.png",
Components.interfaces.nsIUpdateItem.TYPE_APP);
gUpdateWizard.itemsToUpdate.splice(0, 0, item);
}
break;
}
@ -285,7 +307,7 @@ var gFinishedPage = {
fEC.hidden = true;
}
if (gUpdater.updateType == MISMATCH) {
if (gUpdater.updateType == nsIUpdateService.SOURCE_EVENT_MISMATCH) {
document.getElementById("finishedMismatch").hidden = false;
document.getElementById("incompatibleAlert").hidden = false;
}

View File

@ -51,8 +51,8 @@
<body>
<![CDATA[
if (aTopic == "Update:Ended") {
var updates = Components.classes["@mozilla.org/updates/background-update-service;1"]
.getService(Components.interfaces.nsIBackgroundUpdateService);
var updates = Components.classes["@mozilla.org/updates/update-service;1"]
.getService(Components.interfaces.nsIUpdateService);
this.severity = updates.updateSeverity;
this.updateCount = updates.updateCount;
@ -105,9 +105,10 @@
<method name="showUpdates">
<body>
<![CDATA[
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);
]]>
</body>
</method>

View File

@ -44,7 +44,7 @@ include $(DEPTH)/config/autoconf.mk
MODULE = update
XPIDL_MODULE = update
XPIDLSRCS = nsIBackgroundUpdateService.idl
XPIDLSRCS = nsIUpdateService.idl
include $(topsrcdir)/config/rules.mk

View File

@ -38,20 +38,6 @@
#include "nsISupports.idl"
[scriptable, uuid(c8a2339e-770a-417d-ab9c-efde1f23ba24)]
interface nsIBackgroundUpdateService : nsISupports
{
void checkForUpdates();
void checkForUpdatesNow();
readonly attribute long updateCount;
readonly attribute unsigned short updateSeverity;
readonly attribute wstring appUpdateDescription;
readonly attribute wstring appUpdateURL;
};
[scriptable, uuid(37648f86-0f77-4007-929e-673a75d5438f)]
interface nsIUpdateItem : nsISupports
{
@ -62,11 +48,11 @@ interface nsIUpdateItem : nsISupports
readonly attribute wstring updateURL;
readonly attribute wstring iconURL;
const unsigned short TYPE_ANY = 0x00;
const unsigned short TYPE_APP = 0x01;
const unsigned short TYPE_EXTENSION = 0x02;
const unsigned short TYPE_THEME = 0x04;
const unsigned short TYPE_LOCALE = 0x08;
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;
readonly attribute long type;
@ -77,3 +63,27 @@ interface nsIUpdateItem : nsISupports
readonly attribute wstring objectSource;
};
[scriptable, uuid(c8a2339e-770a-417d-ab9c-efde1f23ba24)]
interface nsIUpdateService : nsISupports
{
void watchForUpdates();
const unsigned short SOURCE_EVENT_USER = 0x01;
const unsigned short SOURCE_EVENT_BACKGROUND = 0x02;
void checkForUpdates([array, size_is(aItemCount)] in nsIUpdateItem aItems,
in unsigned long aItemCount,
in unsigned short aUpdateTypes,
in unsigned short aSourceEvent);
void checkForUpdatesInternal([array, size_is(aItemCount)] in nsIUpdateItem aItems,
in unsigned long aItemCount,
in unsigned short aUpdateTypes);
readonly attribute long updateCount;
readonly attribute unsigned short updateSeverity;
readonly attribute string appUpdateVersion;
readonly attribute wstring appUpdateDescription;
readonly attribute wstring appUpdateURL;
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

View File

@ -40,6 +40,7 @@ const PREF_APP_VERSION = "app.version";
const PREF_UPDATE_APP_ENABLED = "update.app.enabled";
const PREF_UPDATE_APP_URI = "update.app.url";
const PREF_UPDATE_APP_UPDATESAVAILABLE = "update.app.updatesAvailable";
const PREF_UPDATE_APP_UPDATEVERSION = "update.app.updateVersion";
const PREF_UPDATE_APP_UPDATEDESCRIPTION = "update.app.updateDescription";
const PREF_UPDATE_APP_UPDATEURL = "update.app.updateURL";
@ -51,7 +52,8 @@ const PREF_UPDATE_INTERVAL = "update.interval";
const PREF_UPDATE_LASTUPDATEDATE = "update.lastUpdateDate";
const PREF_UPDATE_SEVERITY = "update.severity";
const nsIBUS = Components.interfaces.nsIBackgroundUpdateService;
const nsIUpdateService = Components.interfaces.nsIUpdateService;
const nsIUpdateItem = Components.interfaces.nsIUpdateItem;
const UPDATED_EXTENSIONS = 0x01;
const UPDATED_APP = 0x02;
@ -67,8 +69,8 @@ nsBackgroundUpdateService.prototype = {
_pref: null,
/////////////////////////////////////////////////////////////////////////////
// nsIBackgroundUpdateService
checkForUpdates: function ()
// nsIUpdateService
watchForUpdates: function ()
{
// This is called when the app starts, so check to see if the time interval
// expired between now and the last time an automated update was performed.
@ -81,28 +83,67 @@ nsBackgroundUpdateService.prototype = {
var interval = this._pref.getIntPref(PREF_UPDATE_INTERVAL);
var lastUpdateTime = this._pref.getIntPref(PREF_UPDATE_LASTUPDATEDATE);
var timeSinceLastCheck = Date.UTC() - lastUpdateTime;
this.checkForUpdatesNow(); /// XXXben
this.checkForUpdatesInternal([], 0, nsIUpdateItem.TYPE_ANY); /// XXXben
if (timeSinceLastCheck > interval)
this.checkForUpdatesNow();
this.checkForUpdatesInternal([], 0, nsIUpdateItem.TYPE_ANY);
else
this._makeTimer(interval - timeSinceLastCheck);
},
checkForUpdatesNow: function ()
checkForUpdates: function (aItems, aItemCount, aUpdateTypes, aSourceEvent)
{
switch (aSourceEvent) {
case Components.interfaces.nsIExtensionManager.SOURCE_EVENT_MISMATCH:
case nsIUpdateService.SOURCE_EVENT_USER:
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 updateTypes = Components.classes["@mozilla.org/supports-PRUint8;1"]
.createInstance(Components.interfaces.nsISupportsPRUint8);
updateTypes.data = aUpdateTypes;
ary.AppendElement(updateTypes);
var sourceEvent = Components.classes["@mozilla.org/supports-PRUint8;1"]
.createInstance(Components.interfaces.nsISupportsPRUint8);
sourceEvent.data = aSourceEvent;
ary.AppendElement(sourceEvent);
for (var i = 0; i < aItems.length; ++i)
ary.AppendElement(aItems[i]);
ww.openWindow(null, "chrome://mozapps/content/update/update.xul",
"", "chrome,modal,centerscreen", ary);
break;
case nsIUpdateService.SOURCE_EVENT_BACKGROUND:
// Rather than show a UI, call the checkForUpdates function directly here.
// The Browser's inline front end update notification system listens for the
// updates that this function broadcasts.
this.checkForUpdatesInternal([], 0, aUpdateTypes, aSourceEvent);
// If this was a background update, reset timer.
this._makeTimer(this._pref.getIntPref(PREF_UPDATE_INTERVAL));
this._pref.setIntPref(PREF_UPDATE_LASTUPDATEDATE, Date.UTC());
break;
}
},
checkForUpdatesInternal: function (aItems, aItemCount, aUpdateTypes)
{
// Listen for notifications sent out by the app updater (implemented here) and the
// extension updater (implemented in nsExtensionItemUpdater)
var os = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
.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);
this._updateState = 0;
var appUpdatesEnabled = this._pref.getBoolPref(PREF_UPDATE_APP_ENABLED);
var extUpdatesEnabled = this._pref.getBoolPref(PREF_UPDATE_EXTENSIONS_ENABLED);
if (appUpdatesEnabled) {
if (appUpdatesEnabled && ((aUpdateTypes == nsIUpdateItem.TYPE_ANY) ||
(aUpdateTypes == nsIUpdateItem.TYPE_APP))) {
var dsURI = this._pref.getComplexValue(PREF_UPDATE_APP_URI,
Components.interfaces.nsIPrefLocalizedString).data;
var rdf = Components.classes["@mozilla.org/rdf/rdf-service;1"]
@ -111,13 +152,11 @@ nsBackgroundUpdateService.prototype = {
ds = ds.QueryInterface(Components.interfaces.nsIRDFXMLSink);
ds.addXMLSinkObserver(new nsAppUpdateXMLRDFDSObserver(this));
}
if (extUpdatesEnabled) {
if (extUpdatesEnabled && (aUpdateTypes != nsIUpdateItem.TYPE_APP)) {
var em = Components.classes["@mozilla.org/extensions/manager;1"]
.getService(Components.interfaces.nsIExtensionManager);
em.update([], 0, Components.interfaces.nsIExtensionManager.UPDATE_TYPE_BACKGROUND);
em.update(aItems, aItems.length);
}
this._makeTimer(this._pref.getIntPref(PREF_UPDATE_INTERVAL));
},
get updateCount()
@ -135,6 +174,11 @@ nsBackgroundUpdateService.prototype = {
return this._pref.getIntPref(PREF_UPDATE_SEVERITY);
},
get appUpdateVersion()
{
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;
@ -210,7 +254,7 @@ nsBackgroundUpdateService.prototype = {
// nsISupports
QueryInterface: function (aIID)
{
if (!aIID.equals(Components.interfaces.nsIBackgroundUpdateService) &&
if (!aIID.equals(Components.interfaces.nsIUpdateService) &&
!aIID.equals(Components.interfaces.nsISupports))
throw Components.results.NS_ERROR_NO_INTERFACE;
return this;
@ -281,6 +325,8 @@ nsAppUpdateXMLRDFDSObserver.prototype =
var version = this._getProperty(ds, appID, "version");
var checker = new VersionChecker(appVersion, version);
if (checker.isNewer) {
pref.setCharPref(PREF_UPDATE_APP_UPDATEVERSION, version);
var severity = this._getProperty(ds, appID, "severity");
// Synthesize the real severity value using the hint from the web site
// and the version.
@ -452,7 +498,7 @@ var gModule = {
_objects: {
manager: { CID: Components.ID("{B3C290A6-3943-4B89-8BBE-C01EB7B3B311}"),
contractID: "@mozilla.org/updates/background-update-service;1",
contractID: "@mozilla.org/updates/update-service;1",
className: "Background Update Service",
factory: {
createInstance: function (aOuter, aIID)