Bug 1265797 - WebExtensions Notification observer should not remove the notificationId on alertshow. r=aswan, a=sylvestre
authorBob Silverberg <bsilverberg@mozilla.com>
Tue, 10 May 2016 12:14:44 -0400
changeset 333290 8e93a77ffdd4f6ce3d43c8ce0d420ea91453590c
parent 333289 c2507c070a5590e16b53cb75d211f06b44acfc54
child 333291 d8adb38dd576398dacbfb96d2c247f8e0158bdf1
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan, sylvestre
bugs1265797
milestone48.0a2
Bug 1265797 - WebExtensions Notification observer should not remove the notificationId on alertshow. r=aswan, a=sylvestre MozReview-Commit-ID: 4RGVdSrF4OU
toolkit/components/extensions/ext-notifications.js
--- a/toolkit/components/extensions/ext-notifications.js
+++ b/toolkit/components/extensions/ext-notifications.js
@@ -49,29 +49,32 @@ Notification.prototype = {
       // This will fail if the OS doesn't support this function.
     }
     notificationsMap.get(this.extension).delete(this.id);
   },
 
   observe(subject, topic, data) {
     let notifications = notificationsMap.get(this.extension);
 
+    function emitAndDelete(event) {
+      notifications.emit(event, data);
+      notifications.delete(this.id);
+    }
+
     // Don't try to emit events if the extension has been unloaded
     if (!notifications) {
       return;
     }
 
     if (topic === "alertclickcallback") {
-      notifications.emit("clicked", data);
+      emitAndDelete("clicked");
     }
     if (topic === "alertfinished") {
-      notifications.emit("closed", data);
+      emitAndDelete("closed");
     }
-
-    notifications.delete(this.id);
   },
 };
 
 /* eslint-disable mozilla/balanced-listeners */
 extensions.on("startup", (type, extension) => {
   let map = new Map();
   EventEmitter.decorate(map);
   notificationsMap.set(extension, map);