Closed Bug 1265841 Opened 4 years ago Closed 4 years ago

Implement the `notificationclose` service worker event

Categories

(Core :: DOM: Push Notifications, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla49
Tracking Status
firefox49 --- fixed

People

(Reporter: lina, Assigned: lina)

References

Details

(Whiteboard: btpp-active)

Attachments

(1 file, 1 obsolete file)

We don't implement `notificationclose` (https://notifications.spec.whatwg.org/#closing-a-notification) yet, so a service worker can't know when a persistent notification is closed.
Assignee: nobody → kcambridge
Status: NEW → ASSIGNED
Whiteboard: btpp-active
https://reviewboard.mozilla.org/r/47715/#review44507

::: dom/notification/Notification.cpp:1730
(Diff revision 1)
>      // The observer is wholly owned by the NotificationObserver passed to the alert service.
> -    observer = new ServiceWorkerNotificationObserver(mScope, GetPrincipal(), mID);
> +    nsAutoString behavior;
> +    if (NS_WARN_IF(!mBehavior.ToJSON(behavior))) {
> +      behavior.Truncate();
> +    }
> +    observer = new ServiceWorkerNotificationObserver(mScope,

It might make sense for `ServiceWorkerNotificationObserver` to just take ownership of the notification, as `{MainThread, Worker}NotificationObserver` already do.

But I'm not sure if that means we need to register a feature to keep the notification alive. It also seems like persistent notifications can be accessed from either thread; I'm assuming that's one of the reasons we release the notification and call `ConstructFromFields` when we need it again.
Comment on attachment 8743321 [details]
MozReview Request: Bug 1265841 - Implement the `notificationclose` service worker event. r=wchen,baku

Review request updated; see interdiff: https://reviewboard.mozilla.org/r/47715/diff/1-2/
Comment on attachment 8743321 [details]
MozReview Request: Bug 1265841 - Implement the `notificationclose` service worker event. r=wchen,baku

Review request updated; see interdiff: https://reviewboard.mozilla.org/r/47715/diff/2-3/
No longer blocks: 1265828
Depends on: 1265828
Comment on attachment 8743321 [details]
MozReview Request: Bug 1265841 - Implement the `notificationclose` service worker event. r=wchen,baku

Review request updated; see interdiff: https://reviewboard.mozilla.org/r/47715/diff/3-4/
Attachment #8743622 - Attachment is obsolete: true
Attachment #8743622 - Flags: review?(wchen)
I haven't been keeping up with the changes to https://notifications.spec.whatwg.org/, but it looks like notifications created via the `Notification` constructor no longer have `onshow` or `onclose` events. I guess that's because they're meant to be temporary (https://github.com/whatwg/notifications/issues/31#issuecomment-75955968), as opposed to persistent service worker notifications.
Comment on attachment 8743321 [details]
MozReview Request: Bug 1265841 - Implement the `notificationclose` service worker event. r=wchen,baku

https://reviewboard.mozilla.org/r/47715/#review45969

::: dom/notification/Notification.cpp:1590
(Diff revision 4)
> -      return rv;
> +    return rv;
> -    }
> +  }
>  
> -    nsCOMPtr<nsIServiceWorkerManager> swm =
> +  nsCOMPtr<nsIServiceWorkerManager> swm =
> -      mozilla::services::GetServiceWorkerManager();
> +    mozilla::services::GetServiceWorkerManager();
> +  if (NS_WARN_IF(!swm)) {

If swm is not available we should still remove the notification from notification storage since it's no longer around.

::: dom/workers/ServiceWorkerPrivate.cpp:1093
(Diff revision 4)
> +
> +  return NS_OK;
> +}
> +
> +nsresult
> +ServiceWorkerPrivate::SendNotificationCloseEvent(const nsAString& aID,

There is a lot of duplicated code for ServiceWorkePrivate and ServiceWorkerManager. Can you refactor the function to take the event as a parameter, similar to what you did for SendNotificationEventRunnable?
Attachment #8743321 - Flags: review?(wchen)
Comment on attachment 8743321 [details]
MozReview Request: Bug 1265841 - Implement the `notificationclose` service worker event. r=wchen,baku

Review request updated; see interdiff: https://reviewboard.mozilla.org/r/47715/diff/4-5/
Attachment #8743321 - Flags: review?(wchen)
Comment on attachment 8743321 [details]
MozReview Request: Bug 1265841 - Implement the `notificationclose` service worker event. r=wchen,baku

https://reviewboard.mozilla.org/r/47715/#review46395

::: dom/notification/Notification.cpp:1630
(Diff revision 5)
>      if (notificationStorage) {
>        notificationStorage->Delete(origin, mID);
>      }
> +
> +    if (!NS_WARN_IF(!swm)) {
> +      swm->SendNotificationCloseEvent(originSuffix,

Let's handle the nsresult from SendNotificationCloseEvent and SendNotificationClickEvent.
Attachment #8743321 - Flags: review?(wchen) → review+
Haitao, CCing you on this bug, since it might affect bug 1264815. If you're refactoring `ServiceWorkerNotificationObserver`, it probably makes sense to have this bug depend on yours, but it's up to you.
Comment on attachment 8743321 [details]
MozReview Request: Bug 1265841 - Implement the `notificationclose` service worker event. r=wchen,baku

https://reviewboard.mozilla.org/r/47715/#review53080

::: dom/notification/Notification.cpp:1600
(Diff revision 5)
> -    }
> +  }
>  
> -    nsCOMPtr<nsIServiceWorkerManager> swm =
> +  nsCOMPtr<nsIServiceWorkerManager> swm =
> -      mozilla::services::GetServiceWorkerManager();
> +    mozilla::services::GetServiceWorkerManager();
>  
> -    if (swm) {
> +  if (!strcmp("alertclickcallback", aTopic) && !NS_WARN_IF(!swm)) {

I prefer to have:

if (NS_WARN_IF(!swm)) {
  return NS_ERROR_FAILURE;
}

::: dom/notification/Notification.cpp:1629
(Diff revision 5)
>        do_GetService(NS_NOTIFICATION_STORAGE_CONTRACTID);
>      if (notificationStorage) {
>        notificationStorage->Delete(origin, mID);
>      }
> +
> +    if (!NS_WARN_IF(!swm)) {

if (NS_WARN_IF(!swm)) {
  return NS_ERROR_FAILURE;
}

this if (!NS_WARN_IF(!swm)) is confusing
Attachment #8743321 - Flags: review?(amarchesini) → review+
Comment on attachment 8743321 [details]
MozReview Request: Bug 1265841 - Implement the `notificationclose` service worker event. r=wchen,baku

Review request updated; see interdiff: https://reviewboard.mozilla.org/r/47715/diff/5-6/
Attachment #8743321 - Attachment description: MozReview Request: Bug 1265841 - Implement the `notificationclose` service worker event. r?wchen,baku → MozReview Request: Bug 1265841 - Implement the `notificationclose` service worker event. r=wchen,baku
Pushed by kcambridge@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/253aa0a9809b
Implement the `notificationclose` service worker event. r=wchen,baku
https://hg.mozilla.org/mozilla-central/rev/253aa0a9809b
Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla49
Blocks: 1282222
You need to log in before you can comment on or make changes to this bug.