Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Add-on Manager

The Add-on Manager is responsible for managing all of the add-ons installed in the application. Through its APIs information about all installed add-ons can be retrieved and new add-ons can be installed. The APIs are designed to be generic and support many different types of add-ons.

Many functions in the Add-on Manager interface operate asynchronously returning results through callbacks passed to the functions. The callbacks may be called immediately while the initial function is still executing or shortly after depending on when the requested data becomes available.

Accessing installed add-ons

Information about installed add-ons can be retrieved through the main AddonManager API. All of its functions are asynchronous meaning that a callback function must be passed to receive the Addon instances. The callback may well only be called after the API function returns. For example:

Components.utils.import("resource://gre/modules/AddonManager.jsm");

AddonManager.getAllAddons(function(aAddons) {
  // Here aAddons is an array of Addon objects
});
// This code will execute before the code inside the callback

Notifications about changes to installed add-ons are dispatched to any registered AddonListeners. They must be registered through the AddonManager.addAddonListener() method.

Installing new add-ons

New add-ons can be installed by using the AddonManager.getInstallForFile() or AddonManager.getInstallForURL() methods on the AddonManager object. These will pass an AddonInstall instance to the callback which can then be used to install the add-on:

Components.utils.import("resource://gre/modules/AddonManager.jsm");

AddonManager.getInstallForURL("https://www.foo.com/test.xpi", function(aInstall) {
  // aInstall is an instance of AddonInstall
  aInstall.install();
}, "application/x-xpinstall");

The progress of AddonInstalls can be monitored using an InstallListener. A listener can be registered either for a specific install using the AddonInstall.addListener() method or for all installs using the AddonManager.addInstallListener() method.

Finding updates

Add-ons can be checked for updates using the Addon.findUpdates() method. It must be passed an UpdateListener to receive information about compatibility information and new update information. Any available update is returned as an AddonInstall which is ready to be downloaded and installed.

Gecko 7.0 が必要(Firefox 7.0 / Thunderbird 7.0 / SeaMonkey 2.4)

Detecting add-on changes

You can also get lists of add-ons that, at startup, were changed in various ways. The AddonManager.getStartupChanges() method lets you find out which add-ons were installed, removed, updated, enabled, or disabled at application startup.

For example, to take a look at the add-ons that were disabled at startup:

Components.utils.import("resource://gre/modules/AddonManager.jsm");

let addonIDs = AddonManager.getStartupChanges(AddonManager.STARTUP_CHANGE_DISABLED);
if (addonIDs.length > 0) {
  // addonIDs is now an array of the add-on IDs that have been disabled
alert("Note: " + addonIDs.length + " add-ons have been disabled.");
} 

See also

ドキュメントのタグと貢献者

 このページの貢献者: ethertank, trevorh
 最終更新者: ethertank,