Bug 599231 - Display Fennec update download progress

Bug 599231 - Display Fennec update download progress [r=mfinkle]
This commit is contained in:
Alex Pakhotin 2010-09-30 23:22:31 -07:00
parent c2dec83501
commit e4507cc5d7

View File

@ -39,6 +39,8 @@ const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
const UPDATE_NOTIFICATION_NAME = "update-app";
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
@ -51,6 +53,10 @@ XPCOMUtils.defineLazyGetter(this, "gBrandBundle", function aus_gBrandBundle() {
return Services.strings.createBundle("chrome://branding/locale/brand.properties");
});
XPCOMUtils.defineLazyGetter(this, "gBrowserBundle", function aus_gBrowserBundle() {
return Services.strings.createBundle("chrome://browser/locale/browser.properties");
});
function getPref(func, preference, defaultValue) {
try {
return Services.prefs[func](preference);
@ -66,7 +72,7 @@ function UpdatePrompt() { }
UpdatePrompt.prototype = {
classID: Components.ID("{88b3eb21-d072-4e3b-886d-f89d8c49fe59}"),
QueryInterface: XPCOMUtils.generateQI([Ci.nsIUpdatePrompt]),
QueryInterface: XPCOMUtils.generateQI([Ci.nsIUpdatePrompt, Ci.nsIRequestObserver, Ci.nsIProgressEventSink]),
get _enabled() {
return !getPref("getBoolPref", "app.update.silent", false);
@ -85,7 +91,7 @@ UpdatePrompt.prototype = {
};
let notifier = Cc["@mozilla.org/alerts-service;1"].getService(Ci.nsIAlertsService);
notifier.showAlertNotification(aImageUrl, aTitle, aText, true, "", observer, "update-app");
notifier.showAlertNotification(aImageUrl, aTitle, aText, true, "", observer, UPDATE_NOTIFICATION_NAME);
},
_handleUpdate: function UP__handleUpdate(aUpdate, aMode) {
@ -106,7 +112,14 @@ UpdatePrompt.prototype = {
if (download) {
// Start downloading the update in the background
let aus = Cc["@mozilla.org/updates/update-service;1"].getService(Ci.nsIApplicationUpdateService);
aus.downloadUpdate(aUpdate, true);
if (aus.downloadUpdate(aUpdate, true) != "failed") {
let title = gBrowserBundle.formatStringFromName("alertDownloadsStart", [aUpdate.name], 1);
let imageUrl = "drawable://alert_download_progress";
this._showNotification(aUpdate, title, "", imageUrl, "download");
// Add this UI as a listener for active downloads
aus.addDownloadListener(this);
}
}
} else if(aMode == "downloaded") {
// Notify all windows that an application quit has been requested
@ -121,6 +134,16 @@ UpdatePrompt.prototype = {
}
},
_updateDownloadProgress: function UP__updateDownloadProgress(aProgress, aTotal) {
let alertsService = Cc["@mozilla.org/alerts-service;1"].getService(Ci.nsIAlertsService);
let progressListener = alertsService.QueryInterface(Ci.nsIAlertsProgressListener);
progressListener.onProgress(UPDATE_NOTIFICATION_NAME, aProgress, aTotal);
},
// -------------------------
// nsIUpdatePrompt interface
// -------------------------
checkForUpdates: function UP_checkForUpdates() {
// NOT IMPL
},
@ -171,7 +194,37 @@ UpdatePrompt.prototype = {
showUpdateHistory: function UP_showUpdateHistory(aParent) {
// NOT IMPL
},
// ----------------------------
// nsIRequestObserver interface
// ----------------------------
// When the data transfer begins
onStartRequest: function(request, context) {
// NOT IMPL
},
// When the data transfer ends
onStopRequest: function(request, context, status) {
let aus = Cc["@mozilla.org/updates/update-service;1"].getService(Ci.nsIApplicationUpdateService);
aus.removeDownloadListener(this);
},
// ------------------------------
// nsIProgressEventSink interface
// ------------------------------
// When new data has been downloaded
onProgress: function(request, context, progress, maxProgress) {
this._updateDownloadProgress(progress, maxProgress);
},
// When we have new status text
onStatus: function(request, context, status, statusText) {
// NOT IMPL
}
};
const NSGetFactory = XPCOMUtils.generateNSGetFactory([UpdatePrompt]);