Bug 782211 - Part 3: Make nsDesktopNotification generate unique name and cookies to prevent collision in the IPC observer and coalescing in the alerts service. r=dougt

This commit is contained in:
William Chen 2013-03-18 06:24:53 -07:00
parent bcf0fa1e8e
commit f95116c1f5
2 changed files with 12 additions and 2 deletions

View File

@ -27,6 +27,8 @@ NS_IMPL_ISUPPORTS1(AlertServiceObserver, nsIObserver)
/* nsDesktopNotification */
/* ------------------------------------------------------------------------ */
uint32_t nsDOMDesktopNotification::sCount = 0;
nsresult
nsDOMDesktopNotification::PostDesktopNotification()
{
@ -56,11 +58,17 @@ nsDOMDesktopNotification::PostDesktopNotification()
if (!alerts)
return NS_ERROR_NOT_IMPLEMENTED;
// Generate a unique name (which will also be used as a cookie) because
// the nsIAlertsService will coalesce notifications with the same name.
// In the case of IPC, the parent process will use the cookie to map
// to nsIObservers, thus cookies must be unique to differentiate observers.
nsString uniqueName = NS_LITERAL_STRING("desktop-notification:");
uniqueName.AppendInt(sCount++);
return alerts->ShowAlertNotification(mIconURL, mTitle, mDescription,
true,
EmptyString(),
uniqueName,
mObserver,
EmptyString(),
uniqueName,
NS_LITERAL_STRING("auto"),
EmptyString());
}

View File

@ -109,6 +109,8 @@ protected:
nsCOMPtr<nsIPrincipal> mPrincipal;
bool mAllow;
bool mShowHasBeenCalled;
static uint32_t sCount;
};
/*