Bug 551709 - Auto-update add-ons [r=vingtetun]

This commit is contained in:
Mark Finkle 2010-03-16 23:42:01 -04:00
parent 4b3406874e
commit 22868d3696
6 changed files with 219 additions and 113 deletions

View File

@ -149,6 +149,9 @@ pref("xpinstall.dialog.progress.chrome", "chrome://browser/content/browser.xul")
pref("xpinstall.dialog.progress.type.skin", "navigator:browser");
pref("xpinstall.dialog.progress.type.chrome", "navigator:browser");
pref("xpinstall.whitelist.add", "addons.mozilla.org");
pref("extensions.autoupdate.enabled", true);
pref("extensions.autoupdate.interval", 86400);
pref("extensions.update.enabled", false);
pref("extensions.update.interval", 86400);
pref("extensions.dss.enabled", false);
@ -407,10 +410,11 @@ pref("browser.search.param.yahoo-fr-ja", "mozff");
#endif
/* app update prefs */
pref("app.update.timer", 60000); // milliseconds (1 min)
#ifdef MOZ_UPDATER
pref("app.update.auto", true);
pref("app.update.channel", "@MOZ_UPDATE_CHANNEL@");
pref("app.update.timer", 600000);
pref("app.update.mode", 1);
pref("app.update.silent", false);
pref("app.update.url", "https://aus2.mozilla.org/update/4/%PRODUCT%/%VERSION%/%BUILD_ID%/%BUILD_TARGET%/%LOCALE%/%CHANNEL%/%OS_VERSION%/%DISTRIBUTION%/%DISTRIBUTION_VERSION%/%PLATFORM_VERSION%/update.xml");

View File

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

View File

@ -231,6 +231,10 @@ var ExtensionsView = {
var os = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
os.addObserver(this._dloadmgr, "xpinstall-download-started", false);
// Watch for add-on update notifications
os.addObserver(this, "addon-update-started", false);
os.addObserver(this, "addon-update-ended", false);
let self = this;
let panels = document.getElementById("panel-items");
panels.addEventListener("select",
@ -286,6 +290,8 @@ var ExtensionsView = {
uninit: function ev_uninit() {
var os = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
os.removeObserver(this._dloadmgr, "xpinstall-download-started");
os.removeObserver(this, "addon-update-started");
os.removeObserver(this, "addon-update-ended");
this._extmgr.removeInstallListenerAt(this._observerIndex);
},
@ -617,33 +623,58 @@ var ExtensionsView = {
this.getAddonsFromRepo("");
},
updateAll: function ev_updateAll() {
if (!this._isXPInstallEnabled())
observe: function ev_observe(aSubject, aTopic, aData) {
if (!document)
return;
// Make sure we're online before attempting to load
Util.forceOnline();
let addon = aSubject.QueryInterface(Ci.nsIUpdateItem);
let strings = Elements.browserBundle;
let element = document.getElementById(PREFIX_ITEM_URI + addon.id);
if (!element)
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;
switch (aTopic) {
case "addon-update-started":
element.setAttribute("updateStatus", strings.getString("addonUpdate.checking"));
break;
case "addon-update-ended":
let status = parseInt(aData);
let updateable = false;
const nsIAUCL = Ci.nsIAddonUpdateCheckListener;
switch (status) {
case nsIAUCL.STATUS_UPDATE:
var statusMsg = strings.getFormattedString("addonUpdate.updating", [addon.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);
while (start != end) {
if (start.getAttribute("updateable") == "true")
items.push(this._extmgr.getItemForID(start.getAttribute("addonID")));
start = start.nextSibling;
// Tag the add-on so the XPInstallDownloadManager knows it's an update
if (updateable)
element.setAttribute("updating", "true");
break;
}
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);
}
};
@ -825,90 +856,3 @@ 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 = Elements.browserBundle;
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 = Elements.browserBundle;
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;
}
};

View File

@ -0,0 +1,160 @@
/* ***** BEGIN LICENSE BLOCK *****
* 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 Add-on Update Service.
*
* The Initial Developer of the Original Code is Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Mark Finkle <mfinkle@mozilla.com>
*
* 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 ***** */
const Cc = Components.classes;
const Ci = Components.interfaces;
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyServiceGetter(this, "gObs",
"@mozilla.org/observer-service;1",
"nsIObserverService");
XPCOMUtils.defineLazyServiceGetter(this, "gExtMgr",
"@mozilla.org/extensions/manager;1",
"nsIExtensionManager");
XPCOMUtils.defineLazyServiceGetter(this, "gIO",
"@mozilla.org/network/io-service;1",
"nsIIOService");
XPCOMUtils.defineLazyServiceGetter(this, "gPref",
"@mozilla.org/preferences-service;1",
"nsIPrefBranch2");
function getPref(func, preference, defaultValue) {
try {
return gPref[func](preference);
}
catch (e) {}
return defaultValue;
}
// -----------------------------------------------------------------------
// Add-on auto-update management service
// -----------------------------------------------------------------------
const PREF_ADDON_UPDATE_ENABLED = "extensions.autoupdate.enabled";
const PREF_ADDON_UPDATE_INTERVAL = "extensions.autoupdate.interval";
var gNeedsRestart = false;
function AddonUpdateService() {}
AddonUpdateService.prototype = {
classDescription: "Add-on auto-update management",
contractID: "@mozilla.org/browser/addon-update-service;1",
classID: Components.ID("{93c8824c-9b87-45ae-bc90-5b82a1e4d877}"),
QueryInterface: XPCOMUtils.generateQI([Ci.nsITimerCallback]),
_xpcom_categories: [{ category: "update-timer",
value: "@mozilla.org/browser/addon-update-service;1," +
"getService,auto-addon-background-update-timer," +
PREF_ADDON_UPDATE_INTERVAL + ",86400" }],
notify: function aus_notify(aTimer) {
if (aTimer && !getPref("getBoolPref", PREF_ADDON_UPDATE_ENABLED, true))
return;
// If we already auto-upgraded and installed new versions, ignore this check
if (gNeedsRestart)
return;
gIO.offline = false;
// Extension Manager will check for empty list and auto-check all add-ons
let items = [];
let listener = new UpdateCheckListener();
gExtMgr.update(items, items.length, Ci.nsIExtensionManager.UPDATE_CHECK_NEWVERSION, listener);
}
};
// -----------------------------------------------------------------------
// 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(gExtMgr.getItemForID(this._addons[i]));
// Start the actual downloads
gExtMgr.addDownloads(items, items.length, null);
// Remember that we downloaded new updates so we don't check again
gNeedsRestart = true;
},
onAddonUpdateStarted: function ucl_onAddonUpdateStarted(aAddon) {
gObs.notifyObservers(aAddon, "addon-update-started", null);
},
onAddonUpdateEnded: function ucl_onAddonUpdateEnded(aAddon, aStatus) {
gObs.notifyObservers(aAddon, "addon-update-ended", aStatus);
// Save the add-on id if we can download an update
if (aStatus == Ci.nsIAddonUpdateCheckListener.STATUS_UPDATE)
this._addons.push(aAddon.id);
},
QueryInterface: function ucl_QueryInterface(aIID) {
if (!aIID.equals(Ci.nsIAddonUpdateCheckListener) &&
!aIID.equals(Ci.nsISupports))
throw Components.results.NS_ERROR_NO_INTERFACE;
return this;
}
};
function NSGetModule(aCompMgr, aFileSpec) {
return XPCOMUtils.generateModule([AddonUpdateService]);
}

View File

@ -63,6 +63,7 @@ EXTRA_COMPONENTS = \
BrowserCLH.js \
ContentDispatchChooser.js \
AutoCompleteCache.js \
AddonUpdateService.js \
$(NULL)
DIRS = protocols \

View File

@ -36,7 +36,6 @@
<!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">