Bug 231786 - WebKit Managed Notifications: Skeleton NotificationProvider
Summary: WebKit Managed Notifications: Skeleton NotificationProvider
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit Misc. (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Brady Eidson
URL:
Keywords: InRadar
Depends on: 231926 231931
Blocks: 199105
  Show dependency treegraph
 
Reported: 2021-10-14 16:58 PDT by Brady Eidson
Modified: 2021-10-20 23:52 PDT (History)
14 users (show)

See Also:


Attachments
Patch v1 (31.32 KB, patch)
2021-10-14 20:24 PDT, Brady Eidson
achristensen: review+
Details | Formatted Diff | Diff
PFL v1 (31.57 KB, patch)
2021-10-14 21:03 PDT, Brady Eidson
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
PFL v2 (31.52 KB, patch)
2021-10-14 23:40 PDT, Brady Eidson
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
PFL v3 (31.50 KB, patch)
2021-10-15 01:20 PDT, Brady Eidson
no flags Details | Formatted Diff | Diff
New approach v1 (35.92 KB, patch)
2021-10-19 09:14 PDT, Brady Eidson
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
New approach v2 (35.89 KB, patch)
2021-10-19 09:17 PDT, Brady Eidson
no flags Details | Formatted Diff | Diff
New approach v3 (36.82 KB, patch)
2021-10-19 10:02 PDT, Brady Eidson
no flags Details | Formatted Diff | Diff
Patch with better messaging v1 (33.41 KB, patch)
2021-10-20 16:54 PDT, Brady Eidson
achristensen: review+
Details | Formatted Diff | Diff
PFL v1 (33.38 KB, patch)
2021-10-20 17:06 PDT, Brady Eidson
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
PFL v2 (34.12 KB, patch)
2021-10-20 17:57 PDT, Brady Eidson
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Another try PFL (33.95 KB, patch)
2021-10-20 18:48 PDT, Brady Eidson
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
PFL again (34.00 KB, patch)
2021-10-20 19:28 PDT, Brady Eidson
no flags Details | Formatted Diff | Diff
PFL maybe the last one? (40.09 KB, patch)
2021-10-20 21:22 PDT, Brady Eidson
no flags Details | Formatted Diff | Diff
PFL with better way to disable these tests (35.29 KB, patch)
2021-10-20 21:51 PDT, Brady Eidson
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Brady Eidson 2021-10-14 16:58:22 PDT
To change how Notifications work to be WebKit managed (instead of client managed) we'll add a different API::NotificationProvider to perform all the logic.

Let's land a skeleton first.

<rdar://84275562>
Comment 1 Brady Eidson 2021-10-14 20:24:27 PDT
Created attachment 441326 [details]
Patch v1
Comment 2 Alex Christensen 2021-10-14 20:33:38 PDT
Comment on attachment 441326 [details]
Patch v1

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

> Source/WebKit/UIProcess/Notifications/Cocoa/WebNotificationProviderCocoa.h:53
> +    bool isClientReplaceable() const final { return false; }

I don't think I understand why this is needed.  Can we go without?

> Source/WebKit/UIProcess/Notifications/Cocoa/WebNotificationProviderCocoa.mm:39
> +        return std::make_unique<WebNotificationProviderCocoa>();

makeUnique which also does a fastMalloc check.

> Source/WebKit/UIProcess/Notifications/Cocoa/WebNotificationProviderCocoa.mm:40
> +    return nullptr;

It would be nice if this returned makeUniqueRef<API::NotificationProvider>(); if it's not enabled.  Then we would never need to null check m_provider in WebNotificationManagerProxy, which can also be changed from a std::unique_ptr to a UniqueRef.  Right now it can never be null, and I think we should keep that.
Comment 3 Brady Eidson 2021-10-14 20:37:35 PDT
(In reply to Alex Christensen from comment #2)
> Comment on attachment 441326 [details]
> Patch v1
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=441326&action=review
> 
> > Source/WebKit/UIProcess/Notifications/Cocoa/WebNotificationProviderCocoa.h:53
> > +    bool isClientReplaceable() const final { return false; }
> 
> I don't think I understand why this is needed.  Can we go without?

I will explain in the ChangeLog as well, but for the record:

Without this (temporary) mechanism, you'd be unable to run existing Safari against new WebKit to get the new feature, because Safari would override the NotificationProvider through an SPI call.

> 
> > Source/WebKit/UIProcess/Notifications/Cocoa/WebNotificationProviderCocoa.mm:39
> > +        return std::make_unique<WebNotificationProviderCocoa>();
> 
> makeUnique which also does a fastMalloc check.

Yessssss

> 
> > Source/WebKit/UIProcess/Notifications/Cocoa/WebNotificationProviderCocoa.mm:40
> > +    return nullptr;
> 
> It would be nice if this returned
> makeUniqueRef<API::NotificationProvider>(); if it's not enabled.  Then we
> would never need to null check m_provider in WebNotificationManagerProxy,
> which can also be changed from a std::unique_ptr to a UniqueRef.  Right now
> it can never be null, and I think we should keep that.

This is to support the above - Note that *if* this returns null, then the WebNotificationManagerProxy will create the default API::NotificationProvider.

This is necessary for the weird branch of having this feature enabled at runtime or not.
Comment 4 Alex Christensen 2021-10-14 20:59:49 PDT
Comment on attachment 441326 [details]
Patch v1

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

>>> Source/WebKit/UIProcess/Notifications/Cocoa/WebNotificationProviderCocoa.mm:40
>>> +    return nullptr;
>> 
>> It would be nice if this returned makeUniqueRef<API::NotificationProvider>(); if it's not enabled.  Then we would never need to null check m_provider in WebNotificationManagerProxy, which can also be changed from a std::unique_ptr to a UniqueRef.  Right now it can never be null, and I think we should keep that.
> 
> This is to support the above - Note that *if* this returns null, then the WebNotificationManagerProxy will create the default API::NotificationProvider.
> 
> This is necessary for the weird branch of having this feature enabled at runtime or not.

This has one call site.  Immediately after it you have this:
if (!m_provider)
    m_provider = makeUnique<API::NotificationProvider>();
I don't understand how returning null here and returning makeUnique<API::NotificationProvider>(); are different
Comment 5 Alex Christensen 2021-10-14 21:00:24 PDT
Comment on attachment 441326 [details]
Patch v1

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

>>> Source/WebKit/UIProcess/Notifications/Cocoa/WebNotificationProviderCocoa.mm:40
>>> +    return nullptr;
>> 
>> It would be nice if this returned makeUniqueRef<API::NotificationProvider>(); if it's not enabled.  Then we would never need to null check m_provider in WebNotificationManagerProxy, which can also be changed from a std::unique_ptr to a UniqueRef.  Right now it can never be null, and I think we should keep that.
> 
> This is to support the above - Note that *if* this returns null, then the WebNotificationManagerProxy will create the default API::NotificationProvider.
> 
> This is necessary for the weird branch of having this feature enabled at runtime or not.

This has one call site.  Immediately after it you have this:
if (!m_provider)
    m_provider = makeUnique<API::NotificationProvider>();
I don't understand how returning null here and returning makeUnique<API::NotificationProvider>(); are different
Comment 6 Brady Eidson 2021-10-14 21:03:42 PDT
Created attachment 441328 [details]
PFL v1
Comment 7 Brady Eidson 2021-10-14 23:40:18 PDT
Created attachment 441339 [details]
PFL v2
Comment 8 Brady Eidson 2021-10-15 01:20:54 PDT
Created attachment 441345 [details]
PFL v3
Comment 9 EWS 2021-10-15 02:26:15 PDT
Committed r284240 (243049@main): <https://commits.webkit.org/243049@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 441345 [details].
Comment 10 WebKit Commit Bot 2021-10-18 17:20:10 PDT
Re-opened since this is blocked by bug 231926
Comment 11 Brady Eidson 2021-10-19 09:14:29 PDT
Created attachment 441736 [details]
New approach v1
Comment 12 Brady Eidson 2021-10-19 09:17:15 PDT
Created attachment 441738 [details]
New approach v2
Comment 13 Alex Christensen 2021-10-19 09:25:02 PDT
Comment on attachment 441736 [details]
New approach v1

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

> Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp:295
> +    if (decoder.messageName() == Messages::WebPageProxy::ShowNotification::name())

This is usually in generated code, and WebPageProxies aren't in the network process.  I would add this:
// FIXME: move these to a new message receiver type.
That way we can make the NetworkSession own one of the new type and the WebPageProxy also own one of the new type, and both would forward messages to that new type and this would be auto-generated.

> Source/WebKit/WebProcess/Notifications/WebNotificationManager.cpp:141
> +template<typename U> bool sendNotificationMessage(WebProcess& process, U&& message, WebPage* page)

Can this be a WebPage& ?

> Source/WebKit/WebProcess/Notifications/WebNotificationManager.cpp:148
> +    {

unnecessary
Comment 14 Brady Eidson 2021-10-19 09:58:47 PDT
(In reply to Alex Christensen from comment #13)
> Comment on attachment 441736 [details]
> New approach v1
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=441736&action=review
> 
> > Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp:295
> > +    if (decoder.messageName() == Messages::WebPageProxy::ShowNotification::name())
> 
> This is usually in generated code, and WebPageProxies aren't in the network
> process.  I would add this:
> // FIXME: move these to a new message receiver type.
> That way we can make the NetworkSession own one of the new type and the
> WebPageProxy also own one of the new type, and both would forward messages
> to that new type and this would be auto-generated.

Yes, we can autogenerate that type of thing in the future, but manual code will still have to be written for both on both sides of the wire.

There's no example of this yet. Yay for new ground.

> 
> > Source/WebKit/WebProcess/Notifications/WebNotificationManager.cpp:141
> > +template<typename U> bool sendNotificationMessage(WebProcess& process, U&& message, WebPage* page)
> 
> Can this be a WebPage& ?
> 
> > Source/WebKit/WebProcess/Notifications/WebNotificationManager.cpp:148
> > +    {
> 
> unnecessary

Fixing these.
Comment 15 Brady Eidson 2021-10-19 10:02:10 PDT
Created attachment 441746 [details]
New approach v3
Comment 16 Chris Dumez 2021-10-19 10:04:35 PDT
Comment on attachment 441736 [details]
New approach v1

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

> Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp:274
> +    if (decoder.messageReceiverName() == Messages::WebPageProxy::messageReceiverName()) {

This looks wrong. I don't think NetworkConnectionToWebProcess should be dealing with WebPageProxy messages. Why can't the call site choose an appropriate message name based on which connection it is sending the IPC on?

If this isn't possible, an alternative would be to introduce a new MessageReceiver type (e.g. WebNotificationProxy) in Shared/ that could be reused from both the network process and the UIProcess. It would look a lot nicer than having the network process handle WebPageProxy messages (which is super confusing).
Comment 17 Chris Dumez 2021-10-19 10:05:33 PDT
Comment on attachment 441746 [details]
New approach v3

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

> Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp:274
> +    if (decoder.messageReceiverName() == Messages::WebPageProxy::messageReceiverName()) {

Looks like this new approach has the same issue.
Comment 18 Alex Christensen 2021-10-19 10:09:35 PDT
Comment on attachment 441746 [details]
New approach v3

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

> Source/WebKit/NetworkProcess/Notifications/NetworkNotificationManager.h:41
> +    void cancelNotification(uint64_t notificationID);

This should be a strongly typed identifier.
Comment 19 Brady Eidson 2021-10-19 10:33:26 PDT
(In reply to Chris Dumez from comment #16)
> Comment on attachment 441736 [details]
> New approach v1
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=441736&action=review
> 
> > Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp:274
> > +    if (decoder.messageReceiverName() == Messages::WebPageProxy::messageReceiverName()) {
> 
> This looks wrong. I don't think NetworkConnectionToWebProcess should be
> dealing with WebPageProxy messages. Why can't the call site choose an
> appropriate message name based on which connection it is sending the IPC on?

I *literally asked you about this yesterday on Slack* and you said "No reason why not"


Why should we duplicate message types for the exact identically same message (we shouldn't)

> If this isn't possible, an alternative would be to introduce a new
> MessageReceiver type (e.g. WebNotificationProxy) in Shared/ that could be
> reused from both the network process and the UIProcess. It would look a lot
> nicer than having the network process handle WebPageProxy messages (which is
> super confusing).

That's exactly what the FIXME says.
Comment 20 Brady Eidson 2021-10-19 10:34:28 PDT
(In reply to Alex Christensen from comment #18)
> Comment on attachment 441746 [details]
> New approach v3
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=441746&action=review
> 
> > Source/WebKit/NetworkProcess/Notifications/NetworkNotificationManager.h:41
> > +    void cancelNotification(uint64_t notificationID);
> 
> This should be a strongly typed identifier.

Seems like relevant cleanup for later (definitely not relevant to this patch)
Comment 21 Brady Eidson 2021-10-19 10:35:19 PDT
I'll work on the message receiver bit.

Sad about the misunderstanding yesterday that led me to skip bothering with it.
Comment 22 Brady Eidson 2021-10-20 14:52:30 PDT
That was done in https://trac.webkit.org/changeset/284564/webkit

Rebasing this patch on that work now.
Comment 23 Brady Eidson 2021-10-20 16:54:26 PDT
Created attachment 441955 [details]
Patch with better messaging v1
Comment 24 Alex Christensen 2021-10-20 16:58:42 PDT
Comment on attachment 441955 [details]
Patch with better messaging v1

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

> Source/WebCore/ChangeLog:8
> +        No new tests (OOPS!).

remove
Comment 25 Alex Christensen 2021-10-20 17:01:26 PDT
Comment on attachment 441955 [details]
Patch with better messaging v1

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

> Source/WebKit/NetworkProcess/Notifications/NetworkNotificationManager.h:2
> + * Copyright (C) 2020 Apple Inc. All rights reserved.

2021
Comment 26 Brady Eidson 2021-10-20 17:06:17 PDT
Created attachment 441959 [details]
PFL v1
Comment 27 Brady Eidson 2021-10-20 17:57:11 PDT
Created attachment 441969 [details]
PFL v2
Comment 28 Brady Eidson 2021-10-20 18:48:46 PDT
Created attachment 441971 [details]
Another try PFL
Comment 29 Brady Eidson 2021-10-20 19:28:20 PDT
Created attachment 441973 [details]
PFL again
Comment 30 Brady Eidson 2021-10-20 21:21:58 PDT
Have to disable BuiltInNotificationsEnabled on some layouttests for now.

Re-enabling is covered by <rdar://84492078>
Comment 31 Brady Eidson 2021-10-20 21:22:32 PDT
Created attachment 441982 [details]
PFL maybe the last one?
Comment 32 EWS Watchlist 2021-10-20 21:23:17 PDT
This patch modifies the imported WPT tests. Please ensure that any changes on the tests (not coming from a WPT import) are exported to WPT. Please see https://trac.webkit.org/wiki/WPTExportProcess
Comment 33 Brady Eidson 2021-10-20 21:51:01 PDT
Created attachment 441984 [details]
PFL with better way to disable these tests
Comment 34 EWS 2021-10-20 23:51:58 PDT
Committed r284591 (243324@main): <https://commits.webkit.org/243324@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 441984 [details].