Make sure we only emit 'destroy' for a notification once

There are multiple code passes that can result in Notification::destroy()
being called, such as a notification being closed by the application
when it exits and the associated source being removed at the same time.
However, we should only emit 'destroy' for the notification and
do the associated work once.
This commit is contained in:
Marina Zhurakhinskaya 2011-01-30 18:33:49 -05:00
parent 20b7d34577
commit 7369ea6125

View File

@ -254,6 +254,7 @@ Notification.prototype = {
// 'transient' is a reserved keyword in JS, so we have to use an alternate variable name // 'transient' is a reserved keyword in JS, so we have to use an alternate variable name
this.isTransient = false; this.isTransient = false;
this.expanded = false; this.expanded = false;
this._destroyed = false;
this._useActionIcons = false; this._useActionIcons = false;
this._customContent = false; this._customContent = false;
this._bannerBodyText = null; this._bannerBodyText = null;
@ -771,6 +772,9 @@ Notification.prototype = {
}, },
destroy: function(reason) { destroy: function(reason) {
if (this._destroyed)
return;
this._destroyed = true;
if (!reason) if (!reason)
reason = NotificationDestroyedReason.DISMISSED; reason = NotificationDestroyedReason.DISMISSED;
this.emit('destroy', reason); this.emit('destroy', reason);