Bug 511593: Need to check for add-on updates, r=gavin

This commit is contained in:
Mark Finkle 2009-09-06 21:08:06 -04:00
Родитель 116f0d8c94
Коммит c19ec6b0ab
7 изменённых файлов: 156 добавлений и 6 удалений

Просмотреть файл

@ -23,10 +23,11 @@
<xul:spacer flex="1"/>
<xul:label class="normal" crop="end" xbl:inherits="value=typeLabel"/>
</xul:hbox>
<xul:hbox align="center">
<xul:vbox>
<xul:label class="normal hide-on-select" xbl:inherits="value=description" crop="end" flex="1"/>
<xul:description class="normal show-on-select" xbl:inherits="xbl:text=description" flex="1"/>
</xul:hbox>
<xul:label class="normal-bold" xbl:inherits="value=updateStatus"/>
</xul:vbox>
</xul:vbox>
</xul:hbox>
<xul:hbox class="show-on-select buttons-box">
@ -118,10 +119,10 @@
<xul:spacer flex="1"/>
<xul:hbox class="addon-type-or-rating" align="center" xbl:inherits="rating"/>
</xul:hbox>
<xul:hbox align="center">
<xul:vbox>
<xul:label class="normal hide-on-select" xbl:inherits="value=description" crop="end" flex="1"/>
<xul:description class="normal show-on-select" xbl:inherits="xbl:text=description" flex="1"/>
</xul:hbox>
</xul:vbox>
</xul:vbox>
</xul:hbox>
<xul:vbox flex="1">

Просмотреть файл

@ -326,6 +326,8 @@
<richlistbox id="addons-list" flex="1" onselect="ExtensionsView.hideOptions()">
<richlistitem id="addons-local" class="section-header" align="center">
<label value="&addonsLocal.label;" flex="1"/>
<spacer flex="1"/>
<button class="button-dark" label="&addonsUpdate.label;" oncommand="ExtensionsView.updateAll();"/>
</richlistitem>
<richlistitem id="addons-repo" class="section-header">
<label value="&addonsRepo.label;" flex="1"/>

Просмотреть файл

@ -60,7 +60,7 @@ var ExtensionsView = {
_restartCount: 0,
_observerIndex: -1,
_isXPInstallEnabled: function isXPInstallEnabled() {
_isXPInstallEnabled: function ev__isXPInstallEnabled() {
let enabled = false;
let locked = false;
try {
@ -307,6 +307,7 @@ var ExtensionsView = {
let desc = this._getRDFProperty(addon.id, "description");
let optionsURL = this._getRDFProperty(addon.id, "optionsURL");
let opType = this._getRDFProperty(addon.id, "opType");
let updateable = this._getRDFProperty(addon.id, "updateable");
let listitem = this._createItem(addon, "local");
listitem.setAttribute("isDisabled", isDisabled);
@ -314,6 +315,7 @@ var ExtensionsView = {
listitem.setAttribute("description", desc);
listitem.setAttribute("optionsURL", optionsURL);
listitem.setAttribute("opType", opType);
listitem.setAttribute("updateable", updateable);
this._list.insertBefore(listitem, this._repoItem);
}
},
@ -510,6 +512,32 @@ var ExtensionsView = {
resetSearch: function ev_resetSearch() {
document.getElementById("addons-search-text").value = "";
this.getAddonsFromRepo("");
},
updateAll: function ev_updateAll() {
if (!this._isXPInstallEnabled())
return;
// To support custom views we check the add-ons displayed in the list
let items = [];
let start = this._localItem.nextSibling;
let end = this._repoItem;
while (start != end) {
if (start.getAttribute("updateable") != "false")
items.push(this._extmgr.getItemForID(start.getAttribute("addonID")));
start = start.nextSibling;
}
if (items.length > 0) {
let listener = new UpdateCheckListener();
this._extmgr.update(items, items.length, Ci.nsIExtensionManager.UPDATE_CHECK_NEWVERSION, listener);
}
if (this._list.selectedItem)
this._list.selectedItem.focus();
this._pref.setBoolPref("extensions.update.notifyUser", false);
}
};
@ -631,6 +659,13 @@ XPInstallDownloadManager.prototype = {
return;
element.setAttribute("status", (Components.isSuccessCode(aStatus) ? "success" : "fail"));
// If we are updating an add-on, change the status
if (element.hasAttribute("updating")) {
let strings = document.getElementById("bundle_browser");
element.setAttribute("updateStatus", strings.getFormattedString("addonUpdate.updated", [aAddon.version]));
element.removeAttribute("updating");
}
},
onInstallsCompleted: function() {
@ -674,3 +709,91 @@ XPInstallDownloadManager.prototype = {
return this;
}
};
///////////////////////////////////////////////////////////////////////////////
// Add-on update listener. Starts a download for any add-on with a viable
// update waiting
function UpdateCheckListener() {
this._addons = [];
}
UpdateCheckListener.prototype = {
/////////////////////////////////////////////////////////////////////////////
// nsIAddonUpdateCheckListener
onUpdateStarted: function ucl_onUpdateStarted() {
},
onUpdateEnded: function ucl_onUpdateEnded() {
if (!this._addons.length)
return;
// If we have some updateable add-ons, let's download them
let items = [];
for (let i = 0; i < this._addons.length; i++)
items.push(ExtensionsView._extmgr.getItemForID(this._addons[i]));
// Start the actual downloads
ExtensionsView._extmgr.addDownloads(items, items.length, null);
},
onAddonUpdateStarted: function ucl_onAddonUpdateStarted(aAddon) {
if (!document)
return;
let strings = document.getElementById("bundle_browser");
let element = document.getElementById(PREFIX_ITEM_URI + aAddon.id);
element.setAttribute("updateStatus", strings.getString("addonUpdate.checking"));
},
onAddonUpdateEnded: function ucl_onAddonUpdateEnded(aAddon, aStatus) {
if (!document)
return;
let strings = document.getElementById("bundle_browser");
let element = document.getElementById(PREFIX_ITEM_URI + aAddon.id);
let updateable = false;
const nsIAUCL = Ci.nsIAddonUpdateCheckListener;
switch (aStatus) {
case nsIAUCL.STATUS_UPDATE:
var statusMsg = strings.getFormattedString("addonUpdate.updating", [aAddon.version]);
updateable = true;
break;
case nsIAUCL.STATUS_VERSIONINFO:
statusMsg = strings.getString("addonUpdate.compatibility");
break;
case nsIAUCL.STATUS_FAILURE:
statusMsg = strings.getString("addonUpdate.error");
break;
case nsIAUCL.STATUS_DISABLED:
statusMsg = strings.getString("addonUpdate.disabled");
break;
case nsIAUCL.STATUS_APP_MANAGED:
case nsIAUCL.STATUS_NO_UPDATE:
statusMsg = strings.getString("addonUpdate.noupdate");
break;
case nsIAUCL.STATUS_NOT_MANAGED:
statusMsg = strings.getString("addonUpdate.notsupported");
break;
case nsIAUCL.STATUS_READ_ONLY:
statusMsg = strings.getString("addonUpdate.notsupported");
break;
default:
statusMsg = strings.getString("addonUpdate.noupdate");
}
element.setAttribute("updateStatus", statusMsg);
// Save the add-on id if we can download an update
if (updateable) {
this._addons.push(aAddon.id);
element.setAttribute("updating", "true");
}
},
QueryInterface: function ucl_QueryInterface(aIID) {
if (!aIID.equals(Ci.nsIAddonUpdateCheckListener) &&
!aIID.equals(Ci.nsISupports))
throw Components.results.NS_ERROR_NO_INTERFACE;
return this;
}
};

Просмотреть файл

@ -43,6 +43,7 @@
<!ENTITY addonsHeader.label "Add-ons">
<!ENTITY addonsLocal.label "Your Add-ons">
<!ENTITY addonsUpdate.label "Update">
<!ENTITY addonsRepo.label "Get Add-ons">
<!ENTITY addonsRecommended.label "Recommended">
<!ENTITY addonsSearch.label "Search">

Просмотреть файл

@ -20,6 +20,15 @@ addonType.2=Extension
addonType.4=Theme
addonType.8=Locale
addonUpdate.checking=Checking for updates…
addonUpdate.updating=Updating to %S
addonUpdate.updated=Updated to %S
addonUpdate.compatibility=A compatibility update has been applied
addonUpdate.noupdate=No updates were found
addonUpdate.notsupported=Updates not supported
addonUpdate.disabled=Updates are disabled
addonUpdate.error=An error occurred
# Download Manager
# LOCALIZATION NOTE (Status): — is the "em dash" (long dash)
# #1 download size for FINISHED or download state; #2 host (e.g., eTLD + 1, IP)

Просмотреть файл

@ -304,6 +304,13 @@ richlistitem description.normal {
white-space: pre-wrap;
}
richlistitem label.normal-bold,
richlistitem description.normal-bold {
font-weight: bold;
font-size: 60% !important;
white-space: pre-wrap;
}
richlistitem[selected="true"] {
color: black;
background-color: white;

Просмотреть файл

@ -452,6 +452,13 @@ richlistitem description.normal {
white-space: pre-wrap;
}
richlistitem label.normal-bold,
richlistitem description.normal-bold {
font-weight: bold;
font-size: 60% !important;
white-space: pre-wrap;
}
richlistitem[selected="true"] {
color: black;
background-color: white;