インストール済みのアドオンを調べる
firefoxの拡張機能開発メモ. 現在のプロファイルにインストール済みのアドオンを調べたい. nsIExtensionManagerというインタフェースを使うと実現できるようです.
コード
var extensionsManager = Components.classes["@mozilla.org/extensions/manager;1"] .getService(Components.interfaces.nsIExtensionManager); var itemsList = extensionsManager.getItemList(2, {}); for (var i=0; i{ Application.console.log(itemsList[i].name); // 拡張の名前を表示 }
nsIExtensionManager で提供されている getItemList() というメソッドで一覧が取得できます.
nsIExtensionManager
nsIExtensionManagerはアドオンのインストールや管理の機能を提供してくれるものです.
Interface representing a system for the installation and management of Extensions, Themes etc.
getItemList()というメソッドでアドオンの一覧を取得できます.
/**
* Retrieves a list of visible nsIUpdateItems of items matching the
* specified type.
* @param type
* The type of item to return.
* @param countRef
* The XPCJS reference to the number of items returned.
* @returns An array of nsIUpdateItems matching the id/type filter.
*
* XXXben - it would be good if this function took an optional
* install location.
*/
void getItemList(in unsigned long type,
[optional] out unsigned long itemCount,
[retval, array, size_is(itemCount)] out nsIUpdateItem items);
typeにはアドオンのタイプ(install.rdfに書くやつと同じです)を指定します. 拡張機能なので2にします. countRefという引数はXPCJSリファレンスというものらしいのですが, よくわかりません. すべての拡張の情報を取得するだけならば, とりあえず空のオブジェクトを渡せば大丈夫です. 返り値はnsIUpdateItemsです.
nsIUpdateItems
nsIUpdateItem は拡張の名前やバージョンなどの情報を持っています. 詳しくはリファレンスをどうぞ.
参考
- MXR is retired
- nsIUpdateItem Interface
- Extension List Dumper というインストール済み機能拡張の情報を一覧で表示してくれる拡張があったので, そのコードも参考にしました.