diff --git a/dom/notification/Notification.cpp b/dom/notification/Notification.cpp index c77e3ba7eb84..65530a38bb35 100644 --- a/dom/notification/Notification.cpp +++ b/dom/notification/Notification.cpp @@ -1317,6 +1317,8 @@ bool Notification::IsInPrivateBrowsing() { return false; } +// Step 4 of +// https://notifications.spec.whatwg.org/#dom-notification-notification void Notification::ShowInternal() { AssertIsOnMainThread(); MOZ_ASSERT(mTempRef, @@ -1331,13 +1333,15 @@ void Notification::ShowInternal() { std::swap(ownership, mTempRef); MOZ_ASSERT(ownership->GetNotification() == this); - nsresult rv = PersistNotification(); - if (NS_FAILED(rv)) { - NS_WARNING("Could not persist Notification"); - } - nsCOMPtr alertService = components::Alerts::Service(); + // Step 4.1: If the result of getting the notifications permission state is + // not "granted", then queue a task to fire an event named error on this, and + // abort these steps. + // + // XXX(krosylight): But this function is also triggered by + // Notification::ShowPersistentNotification which already does its own + // permission check. Can we split this? ErrorResult result; NotificationPermission permission = NotificationPermission::Denied; if (mWorkerPrivate) { @@ -1358,13 +1362,28 @@ void Notification::ShowInternal() { } else { DispatchTrustedEvent(u"error"_ns); } + mIsClosed = true; return; } + // Preparing for Step 4.2 the fetch steps. The actual work happens in + // nsIAlertNotification::LoadImage nsAutoString iconUrl; nsAutoString soundUrl; ResolveIconAndSoundURL(iconUrl, soundUrl); + // Step 4.3 the show steps, which are almost all about processing `tag` and + // then displaying the notification. Both are handled by + // nsIAlertsService::ShowAlert/PersistentNotification. The below is all about + // constructing the observer (for show and close events) right and ultimately + // call the alerts service function. + + // XXX(krosylight): Non-persistent notifications probably don't need this + nsresult rv = PersistNotification(); + if (NS_FAILED(rv)) { + NS_WARNING("Could not persist Notification"); + } + bool isPersistent = false; nsCOMPtr observer; if (mScope.IsEmpty()) { diff --git a/widget/windows/ToastNotification.cpp b/widget/windows/ToastNotification.cpp index afdffc19acbe..83692b26a18f 100644 --- a/widget/windows/ToastNotification.cpp +++ b/widget/windows/ToastNotification.cpp @@ -776,6 +776,9 @@ ToastNotification::CloseAlert(const nsAString& aAlertName, bool aContextClosed) { RefPtr handler; if (NS_WARN_IF(!mActiveHandlers.Get(aAlertName, getter_AddRefs(handler)))) { + // This can happen when the handler is gone but the closure signal is not + // yet reached to the content process, and then the process tries closing + // the same signal. return NS_OK; }