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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
var EXPORTED_SYMBOLS = ["BlocklistTestProxyChild"];
var Cm = Components.manager;
const kBlocklistServiceUUID = "{66354bc9-7ed1-4692-ae1d-8da97d6b205e}";
const kBlocklistServiceContractID = "@mozilla.org/extensions/blocklist;1";
let existingBlocklistFactory = null;
try {
existingBlocklistFactory = Cm.getClassObject(
Cc[kBlocklistServiceContractID],
Ci.nsIFactory
);
} catch (ex) {}
const { setTimeout } = ChromeUtils.importESModule(
"resource://gre/modules/Timer.sys.mjs"
);
/*
* A lightweight blocklist proxy for testing purposes.
*/
var BlocklistProxy = {
_uuid: null,
QueryInterface: ChromeUtils.generateQI([
"nsIObserver",
"nsIBlocklistService",
"nsITimerCallback",
]),
init() {
if (!this._uuid) {
this._uuid = Services.uuid.generateUUID();
Cm.nsIComponentRegistrar.registerFactory(
this._uuid,
"",
"@mozilla.org/extensions/blocklist;1",
this
);
}
},
uninit() {
if (this._uuid) {
Cm.nsIComponentRegistrar.unregisterFactory(this._uuid, this);
if (existingBlocklistFactory) {
Cm.nsIComponentRegistrar.registerFactory(
Components.ID(kBlocklistServiceUUID),
"Blocklist Service",
"@mozilla.org/extensions/blocklist;1",
existingBlocklistFactory
);
}
this._uuid = null;
}
},
notify(aTimer) {},
async getAddonBlocklistState(aAddon, aAppVersion, aToolkitVersion) {
await new Promise(r => setTimeout(r, 150));
return 0; // STATE_NOT_BLOCKED
},
};
class BlocklistTestProxyChild extends JSProcessActorChild {
constructor() {
super();
BlocklistProxy.init();
}
receiveMessage(message) {
if (message.name == "unload") {
BlocklistProxy.uninit();
}
}
}
|