Add-on Manager

  • Raccourci de la révision : Mozilla/Add-ons/Add-on_Manager
  • Titre de la révision : Add-on Manager
  • ID de la révision : 470351
  • Créé :
  • Créateur : Goofy
  • Version actuelle ? Non
  • Commentaire

Contenu de la révision

{{ gecko_minversion_header("2.0") }}

Le gestionnaire de modules prend en charge l'ensemble des modules complémentaires installés dans l'application. Grâce à ses API on peut retrouver des informations sur les modules installés et on peut en installer de nouveaux. les API sont conçues pour être génériques et prendre en charge différents types de modules.

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.

Accéder aux modules déjà installés

Information about installed add-ons can be retrieved through the main {{ AMInterface("AddonManager") }} API. All of its functions are asynchronous meaning that a callback function must be passed to receive the {{ AMInterface("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 {{AMInterface("Addon")}} objects
});
// This code will execute before the code inside the callback

Notifications about changes to installed add-ons are dispatched to any registered {{ AMInterface("AddonListener") }}s. They must be registered through the {{ AMInterface("AddonManager","addAddonListener") }} method.

Installer de nouveaux modules

New add-ons can be installed by using the {{ AMInterface("AddonManager","getInstallForFile") }} or {{ AMInterface("AddonManager","getInstallForURL") }} methods on the {{ AMInterface("AddonManager") }} object. These will pass an {{ AMInterface("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("http://www.foo.com/test.xpi", function(aInstall) {
  // aInstall is an instance of {{AMInterface("AddonInstall")}}
  aInstall.install();
}, "application/x-xpinstall");

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

Trouver des mises à jour

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

{{ h1_gecko_minversion("Detecting add-on changes", "7.0") }}

You can also get lists of add-ons that, at startup, were changed in various ways. The {{ AMInterface("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.");
} 

Voir aussi

{{ ListSubpages() }}

Source de la révision

<p>{{ gecko_minversion_header("2.0") }}</p>
<p>Le gestionnaire de modules prend en charge l'ensemble des modules complémentaires installés dans l'application. Grâce à ses API on peut retrouver des informations sur les modules installés et on peut en installer de nouveaux. les API sont conçues pour être génériques et prendre en charge différents types de modules.</p>
<p>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.</p>
<h2 id="Acc.C3.A9der_aux_modules_d.C3.A9j.C3.A0_install.C3.A9s">Accéder aux modules déjà installés</h2>
<p>Information about installed add-ons can be retrieved through the main {{ AMInterface("AddonManager") }} API. All of its functions are asynchronous meaning that a callback function must be passed to receive the {{ AMInterface("Addon") }} instances. The callback may well only be called after the API function returns. For example:</p>
<pre class="brush: js">
Components.utils.import("resource://gre/modules/AddonManager.jsm");

AddonManager.getAllAddons(function(aAddons) {
  // Here aAddons is an array of {{AMInterface("Addon")}} objects
});
// This code will execute before the code inside the callback
</pre>
<p>Notifications about changes to installed add-ons are dispatched to any registered {{ AMInterface("AddonListener") }}s. They must be registered through the {{ AMInterface("AddonManager","addAddonListener") }} method.</p>
<h2 id="Installer_de_nouveaux_modules">Installer de nouveaux modules</h2>
<p>New add-ons can be installed by using the {{ AMInterface("AddonManager","getInstallForFile") }} or {{ AMInterface("AddonManager","getInstallForURL") }} methods on the {{ AMInterface("AddonManager") }} object. These will pass an {{ AMInterface("AddonInstall") }} instance to the callback which can then be used to install the add-on:</p>
<pre class="brush: js">
Components.utils.import("resource://gre/modules/AddonManager.jsm");

AddonManager.getInstallForURL("http://www.foo.com/test.xpi", function(aInstall) {
  // aInstall is an instance of {{AMInterface("AddonInstall")}}
  aInstall.install();
}, "application/x-xpinstall");
</pre>
<p>The progress of {{ AMInterface("AddonInstall") }}s can be monitored using an {{ AMInterface("InstallListener") }}. A listener can be registered either for a specific install using the {{ AMInterface("AddonInstall","addListener") }} method or for all installs using the {{ AMInterface("AddonManager","addInstallListener") }} method.</p>
<h2 id="Trouver_des_mises_.C3.A0_jour">Trouver des mises à jour</h2>
<p>Add-ons can be checked for updates using the {{ AMInterface("Addon","findUpdates") }} method. It must be passed an {{ AMInterface("UpdateListener") }} to receive information about compatibility information and new update information. Any available update is returned as an {{ AMInterface("AddonInstall") }} which is ready to be downloaded and installed.</p>
<p>{{ h1_gecko_minversion("Detecting add-on changes", "7.0") }}</p>
<p>You can also get lists of add-ons that, at startup, were changed in various ways. The {{ AMInterface("AddonManager", "getStartupChanges") }} method lets you find out which add-ons were installed, removed, updated, enabled, or disabled at application startup.</p>
<p>For example, to take a look at the add-ons that were disabled at startup:</p>
<pre class="brush: js">
Components.utils.import("resource://gre/modules/AddonManager.jsm");

let addonIDs = AddonManager.getStartupChanges(AddonManager.STARTUP_CHANGE_DISABLED);
if (addonIDs.length &gt; 0)&nbsp;{
&nbsp; // addonIDs is now an array of the add-on IDs that have been disabled
alert("Note:&nbsp;" + addonIDs.length +&nbsp;" add-ons have been disabled.");
} 
</pre>
<h2 id="Voir_aussi">Voir aussi</h2>
<p>{{ ListSubpages() }}</p>
Revenir à cette révision