Bug 238544 - ServiceWorkerRegistration.getNotifications should list all persistent notifications
Summary: ServiceWorkerRegistration.getNotifications should list all persistent notific...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Service Workers (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: youenn fablet
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-03-30 03:08 PDT by youenn fablet
Modified: 2022-04-01 06:14 PDT (History)
7 users (show)

See Also:


Attachments
Patch (32.49 KB, patch)
2022-03-30 03:29 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (32.63 KB, patch)
2022-03-31 01:57 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Patch for landing (33.08 KB, patch)
2022-04-01 02:12 PDT, youenn fablet
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description youenn fablet 2022-03-30 03:08:20 PDT
ServiceWorkerRegistration.getNotifications should list all persistent notifications
Comment 1 youenn fablet 2022-03-30 03:29:18 PDT
Created attachment 456109 [details]
Patch
Comment 2 youenn fablet 2022-03-31 01:57:07 PDT
Created attachment 456220 [details]
Patch
Comment 3 Darin Adler 2022-03-31 09:37:59 PDT
Comment on attachment 456220 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=456220&action=review

Not confident that all this code

> Source/WebCore/workers/service/ServiceWorkerContainer.cpp:627
> +        std::sort(data.begin(), data.end(), [](auto& a, auto& b) { return a.creationTime < b.creationTime; });

Is it safe to use an unstable sort here? If there are any two notifications with the same creationTime, then they could end up shuffled randomly by the sort algorithm. If we used a stable sort, then they would stay in the order they are already in, even if the times happened to be identical.

> Source/WebCore/workers/service/WorkerSWClientConnection.cpp:84
> +    for (auto& callback : navigationPreloadStateCallbacks.values())
> +        callback(Exception { AbortError, "context stopped"_s });

This is in hash table (pseudo-random) order. Is that OK?

> Source/WebCore/workers/service/WorkerSWClientConnection.cpp:88
> +    for (auto& callback : getNotificationsCallbacks.values())
>          callback(Exception { AbortError, "context stopped"_s });

Ditto.

> Source/WebKit/UIProcess/Notifications/WebNotificationManagerProxy.cpp:306
> +    Vector<NotificationData> result;

Should we be reserving initial capacity? Does this typically get sized the same as m_notifications or is it usually a much smaller subset?

> Source/WebKit/UIProcess/Notifications/WebNotificationManagerProxy.cpp:315
> +    callback(WTFMove(result));

Can this vector be long-lived? If so, maybe we should do shrinkToFit after building it and before transferring ownership?
Comment 4 youenn fablet 2022-04-01 02:04:32 PDT
(In reply to Darin Adler from comment #3)
> Comment on attachment 456220 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=456220&action=review
> 
> Not confident that all this code
> 
> > Source/WebCore/workers/service/ServiceWorkerContainer.cpp:627
> > +        std::sort(data.begin(), data.end(), [](auto& a, auto& b) { return a.creationTime < b.creationTime; });
> 
> Is it safe to use an unstable sort here? If there are any two notifications
> with the same creationTime, then they could end up shuffled randomly by the
> sort algorithm. If we used a stable sort, then they would stay in the order
> they are already in, even if the times happened to be identical.

We get the vector from a UIProcess HashMap, there is no guarantee the order of the pre-sorted Vector will be stable.
To be bullet proof, we would need to do the sorting in UIProcess and rely on both creationTime and UIProcess incrementing counter.
I'll change this.

> > Source/WebCore/workers/service/WorkerSWClientConnection.cpp:84
> > +    for (auto& callback : navigationPreloadStateCallbacks.values())
> > +        callback(Exception { AbortError, "context stopped"_s });
> 
> This is in hash table (pseudo-random) order. Is that OK?

I think this is ok. These completion handlers can complete in no particular order.

> > Source/WebKit/UIProcess/Notifications/WebNotificationManagerProxy.cpp:306
> > +    Vector<NotificationData> result;
> 
> Should we be reserving initial capacity? Does this typically get sized the
> same as m_notifications or is it usually a much smaller subset?

Difficult to say.
I would expect most web sites to have a single registration doing notifications but that is not guaranteed. If tag is empty, my guess is that it should be roughly the same as m_notifications. If tag is used, it probably means it is only a small subset.

> > Source/WebKit/UIProcess/Notifications/WebNotificationManagerProxy.cpp:315
> > +    callback(WTFMove(result));
> 
> Can this vector be long-lived? If so, maybe we should do shrinkToFit after
> building it and before transferring ownership?

Vector is short lived, it is sent directly to WebProcess through IPC.
Comment 5 youenn fablet 2022-04-01 02:12:52 PDT
Created attachment 456338 [details]
Patch for landing
Comment 6 EWS 2022-04-01 06:13:14 PDT
Committed r292218 (249121@main): <https://commits.webkit.org/249121@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 456338 [details].
Comment 7 Radar WebKit Bug Importer 2022-04-01 06:14:17 PDT
<rdar://problem/91158736>