Bug 1203331 - [webext] Use SingletonEventManager in a few places (r=gabor)

This commit is contained in:
Bill McCloskey
2015-09-06 17:53:09 -07:00
parent 53ba768590
commit 1c889843fc
3 changed files with 30 additions and 15 deletions

View File

@@ -9,7 +9,7 @@ var {
// WeakMap[Extension -> Set[Notification]]
var notificationsMap = new WeakMap();
// WeakMap[Extension -> callback]
// WeakMap[Extension -> Set[callback]]
var notificationCallbacksMap = new WeakMap();
// Manages a notification popup (notifications API) created by the extension.
@@ -54,8 +54,8 @@ Notification.prototype = {
return;
}
if (notificationCallbacksMap.has(this.extension)) {
notificationCallbackMap.get(this.extension)(this);
for (let callback in notificationCallbacksMap.get(this.extension)) {
callback(this);
}
notificationsMap.get(this.extension).delete(this);
@@ -64,6 +64,7 @@ Notification.prototype = {
extensions.on("startup", (type, extension) => {
notificationsMap.set(extension, new Set());
notificationCallbacksMap.set(extension, new Set());
});
extensions.on("shutdown", (type, extension) => {
@@ -71,6 +72,7 @@ extensions.on("shutdown", (type, extension) => {
notification.clear();
}
notificationsMap.delete(extension);
notificationCallbacksMap.delete(extension);
});
var nextId = 0;
@@ -128,9 +130,9 @@ extensions.registerPrivilegedAPI("notifications", (extension, context) => {
fire(notification.id, true);
};
notificationCallbackMap.set(extension, listener);
notificationCallbacksMap.get(extension).add(listener);
return () => {
notificationCallbackMap.delete(extension);
notificationCallbacksMap.get(extension).delete(listener);
};
}).api(),