1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
'use strict';
const unload = require("sdk/system/unload").when;
const {AddonManager, AddonManagerPrivate, AddonType} = require("../utils/addonmanager");
var defaultUIPriority = 6001; // this increases when it is used
exports.AddonProvider = function(options) {
var types = null;
// AddonManagerPrivate.AddonType DNE in Gecko (FF) < 6
if (AddonType) {
types = [new AddonType(
options.type, // TODO: RANDOMIZE?
null,
options.localeKey,
AddonManager.VIEW_TYPE_LIST,
options.uiPriority || defaultUIPriority++)];
}
var provider = {
getAddonByID: function(aId, aCallback) {
aCallback(options.getAddonByID(aId));
},
getAddonsByTypes: function(aTypes, aCallback) {
if (aTypes && aTypes.indexOf(options.type) < 0) {
// not the right type, return nothing
aCallback([]);
}
else {
// the right type, return all addons
aCallback(options.getAddons());
}
},
getInstallsByTypes: function(aTypes, aCallback) {
aCallback([]);
}
};
AddonManagerPrivate.registerProvider(provider, types);
unload(function() {
AddonManagerPrivate.unregisterProvider(provider);
});
return this;
};
|