Skip to content

Declarative Web Push: Support pushnotification event for declarative messages that are mutable - #18087

Merged
webkit-commit-queue merged 1 commit into
WebKit:mainfrom
beidson:eng/Declarative-Web-Push-Support-pushnotification-event-for-declarative-messages-that-are-mutable
Sep 23, 2023
Merged

webkit-commit-queue merged 1 commit into
WebKit:mainfrom
beidson:eng/Declarative-Web-Push-Support-pushnotification-event-for-declarative-messages-that-are-mutable

Conversation

@beidson

@beidson beidson commented Sep 22, 2023 •

Copy link
Copy Markdown
Contributor

4b36aea

Declarative Web Push: Support `pushnotification` event for declarative messages that are mutable
https://bugs.webkit.org/show_bug.cgi?id=261956
rdar://114886688

Reviewed by Brent Fulgham and Chris Dumez.

When a declarative web push message arrives, and the sender has explicitly marked it "mutable",
we fire a new `pushnotification` event at the Service Worker if there is one.

That event handler is given the proposed Notification described by the declarative message, and
has the opportunity to offer a new one instead.

It is also given the proposed AppBadge count described by the declarative message, and can modify
that as well.

If the event takes too long, or does *not* override the proposed Notification or AppBadge count,
then the originals described by the declarative message are used instead.

Implementation-wise, it's amazing how long of a chain of message handlers and completion handlers
exist to get a push message from the UI process to the point where an event can be dispatched
to the ServiceWorker.

This patch changes every single link in that chain to:
1 - Pass along the proposed NotificationPayload if one exists
2 - Change the CompletionHandlers to return the new NotificationPayload to be used.

* Source/WebCore/CMakeLists.txt:
* Source/WebCore/DerivedSources-input.xcfilelist:
* Source/WebCore/DerivedSources-output.xcfilelist:
* Source/WebCore/DerivedSources.make:
* Source/WebCore/Headers.cmake:
* Source/WebCore/Modules/notifications/Notification.cpp:
(WebCore::Notification::create):
(WebCore::Notification::Notification):
* Source/WebCore/Modules/notifications/Notification.h:
* Source/WebCore/Modules/notifications/NotificationOptionsPayload.h:
(WebCore::NotificationOptionsPayload::isolatedCopy):
* Source/WebCore/Modules/notifications/NotificationPayload.cpp:
(WebCore::NotificationPayload::fromNotificationData):
* Source/WebCore/Modules/notifications/NotificationPayload.h:
(WebCore::NotificationPayload::isolatedCopy):
* Source/WebCore/Modules/push-api/PushNotificationEvent.cpp: Copied from Source/WebCore/Modules/notifications/NotificationPayload.cpp.
(WebCore::PushNotificationEvent::PushNotificationEvent):
(WebCore::PushNotificationEvent::~PushNotificationEvent):
(WebCore::PushNotificationEvent::create):
* Source/WebCore/Modules/push-api/PushNotificationEvent.h: Added.
* Source/WebCore/Modules/push-api/PushNotificationEvent.idl: Copied from Source/WebCore/Modules/notifications/NotificationOptionsPayload.h.
* Source/WebCore/Modules/push-api/PushNotificationEventInit.h: Copied from Source/WebCore/Modules/notifications/NotificationOptionsPayload.h.
* Source/WebCore/Modules/push-api/PushNotificationEventInit.idl: Copied from Source/WebCore/Modules/notifications/NotificationOptionsPayload.h.
* Source/WebCore/Modules/webcodecs/WebCodecsAudioEncoder.cpp:
* Source/WebCore/Sources.txt:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/bindings/js/WebCoreBuiltinNames.h:
* Source/WebCore/dom/EventNames.h:
* Source/WebCore/dom/EventNames.in:
* Source/WebCore/page/WorkerNavigator.cpp:
(WebCore::WorkerNavigator::setAppBadge):
* Source/WebCore/testing/ServiceWorkerInternals.cpp:
(WebCore::ServiceWorkerInternals::schedulePushEvent):
* Source/WebCore/workers/service/ServiceWorkerGlobalScope.cpp:
(WebCore::ServiceWorkerGlobalScope::dispatchPushEvent):
(WebCore::ServiceWorkerGlobalScope::dispatchPushNotificationEvent):
(WebCore::ServiceWorkerGlobalScope::clearPushNotificationEvent):
* Source/WebCore/workers/service/ServiceWorkerGlobalScope.h:
* Source/WebCore/workers/service/ServiceWorkerRegistration.cpp:
(WebCore::ServiceWorkerRegistration::showNotification):
* Source/WebCore/workers/service/context/SWContextManager.cpp:
(WebCore::SWContextManager::firePushEvent):
* Source/WebCore/workers/service/context/SWContextManager.h:
* Source/WebCore/workers/service/context/ServiceWorkerThread.cpp:
(WebCore::ServiceWorkerThread::queueTaskToFirePushEvent):
(WebCore::ServiceWorkerThread::queueTaskToFirePushNotificationEvent):
(WebCore::ServiceWorkerThread::startNotificationPayloadFunctionalEventMonitoring):
(WebCore::ServiceWorkerThread::heartBeatTimerFired):
* Source/WebCore/workers/service/context/ServiceWorkerThread.h:
(WebCore::ServiceWorkerThread::stopNotificationPayloadFunctionalEventMonitoring):
* Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.cpp:
(WebCore::ServiceWorkerThreadProxy::firePushEvent):
* Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.h:
* Source/WebCore/workers/service/server/SWServer.cpp:
(WebCore::SWServer::processPushMessage):
* Source/WebCore/workers/service/server/SWServer.h:
* Source/WebCore/workers/service/server/SWServerToContextConnection.h:
* Source/WebKit/NetworkProcess/NetworkProcess.cpp:
(WebKit::NetworkProcess::processPushMessage):
* Source/WebKit/NetworkProcess/NetworkProcess.h:
* Source/WebKit/NetworkProcess/NetworkProcess.messages.in:
* Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.cpp:
(WebKit::WebSWServerToContextConnection::firePushEvent):
* Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.h:
* Source/WebKit/Scripts/webkit/messages.py:
(types_that_cannot_be_forward_declared):
* Source/WebKit/Shared/Cocoa/WebPushMessageCocoa.mm:
(WebKit::WebPushMessage::fromDictionary):
* Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in:
* Source/WebKit/Shared/WebPushMessage.h:
* Source/WebKit/Shared/WebPushMessage.serialization.in:
* Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp:
(WebKit::NetworkProcessProxy::processPushMessage):
* Source/WebKit/UIProcess/Network/NetworkProcessProxy.h:
* Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp:
(WebKit::WebsiteDataStore::processPushMessage):
* Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp:
(WebKit::WebSWContextManagerConnection::firePushEvent):
* Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h:
* Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in:
* Source/WebKit/webpushd/PushService.mm:
(WebPushD::PushService::didReceivePushMessage):
* Source/WebKit/webpushd/WebPushDaemon.mm:
(WebPushD::WebPushDaemon::injectPushMessageForTesting):
(WebPushD::WebPushDaemon::getPendingPushMessages):
* Tools/TestWebKitAPI/Tests/WebKitCocoa/WebPushDaemon.mm:
(-[PushNotificationDelegate clearMostRecents]):

Canonical link: https://commits.webkit.org/268358@main

de03b84

Misc iOS, tvOS & watchOS macOS Linux Windows
❌ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 wincairo
✅ 🧪 bindings ✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug ✅ 🧪 wpe-wk2
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🛠 gtk
✅ 🧪 webkitpy ✅ 🧪 ios-wk2-wpt ✅ 🧪 mac-wk1 ✅ 🧪 gtk-wk2
✅ 🧪 api-ios ✅ 🧪 mac-wk2 ✅ 🧪 api-gtk
✅ 🛠 tv ✅ 🧪 mac-AS-debug-wk2
✅ 🛠 tv-sim
✅ 🛠 🧪 merge ✅ 🛠 watch
✅ 🛠 watch-sim

@beidson beidson self-assigned this Sep 22, 2023
@beidson beidson added the WebKit Misc. For miscellaneous bugs in the WebKit framework (and not JavaScriptCore or WebCore). label Sep 22, 2023
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Sep 22, 2023
@beidson beidson removed the merging-blocked Applied to prevent a change from being merged label Sep 22, 2023
@beidson
beidson force-pushed the eng/Declarative-Web-Push-Support-pushnotification-event-for-declarative-messages-that-are-mutable branch from 9436650 to 8b9ac17 Compare September 22, 2023 17:30
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Sep 22, 2023
@beidson beidson removed the merging-blocked Applied to prevent a change from being merged label Sep 22, 2023
@beidson
beidson force-pushed the eng/Declarative-Web-Push-Support-pushnotification-event-for-declarative-messages-that-are-mutable branch from 8b9ac17 to db7d27d Compare September 22, 2023 17:55
@beidson
beidson force-pushed the eng/Declarative-Web-Push-Support-pushnotification-event-for-declarative-messages-that-are-mutable branch from db7d27d to b7dced9 Compare September 22, 2023 18:29
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Sep 22, 2023
@beidson beidson removed the merging-blocked Applied to prevent a change from being merged label Sep 22, 2023
@beidson
beidson force-pushed the eng/Declarative-Web-Push-Support-pushnotification-event-for-declarative-messages-that-are-mutable branch from b7dced9 to 07dcef8 Compare September 22, 2023 19:54
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Sep 22, 2023
@beidson beidson removed the merging-blocked Applied to prevent a change from being merged label Sep 22, 2023
@beidson
beidson force-pushed the eng/Declarative-Web-Push-Support-pushnotification-event-for-declarative-messages-that-are-mutable branch from 07dcef8 to 51fa4c7 Compare September 22, 2023 20:32
@beidson
beidson force-pushed the eng/Declarative-Web-Push-Support-pushnotification-event-for-declarative-messages-that-are-mutable branch from 51fa4c7 to 381ddb1 Compare September 22, 2023 21:21

@brentfulgham brentfulgham left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, I had a few small questions and suggestions but no need for another review from me. r=me!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could just be forward declared, since it's passed as a reference and not a member of this class.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is how it originally was. In one of the EWS runs it broke various different builds in fun and creative ways.
Because it was building locally, and shrouded in UnifiedSource mystery on the bots... I decided to take the shortcut option. =/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be ~PushNotificationEvent() = default;?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup. Needed to set a breakpoint at some point, didn't revert back 👍

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you missed this change.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these last three includes could be forward-declared.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could probably move the #if ENABLE(DECLARATIVE_WEB_PUSH) inside the if(serviceWorkerGlobalScope), then you could delete line 328.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe:

if (!isDeclarative && !result) {
    if (auto session = networkSession(sessionID)) {
        session->notificationmanager()....

Comment thread Source/WebKit/Shared/WebPushMessage.h Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could WebCore::NotificationPayload be forward declared?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of all the "This could be forward declared?" comments this one hurts the most in the number of files I'd have to go touch.

The frustration here is that I can get it building locally, but then the wildly different configs on the bots (iOS, tv, older Mac, linuxes) all have different notions of unified sources.

I tried to resolve these forward declare vs includes multiple times today, but can't afford to spend any more time back-and-forthing with EWS on this =(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's a huge issue, don't bother. I've just trained myself to watch for these includes since it's a lot of work to remove them later (as you know!) :-)

@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Sep 22, 2023

@cdumez cdumez left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still reviewing but putting a few comments out there since this was already r+

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean to return a const std::optional<NotificationData>& ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, that's what I meant.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can probably be private.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be a std::optional<unsigned long long> since the member is optional.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this isn't supported? I thought this worked, as long as the implementation returned a std::optional<unsigned long>.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just checked and this is totally supported. We have plenty of examples in the existing code base where this is working. We don't need custom bindings.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I figured tried, it absolutely failed compiling miserably.

I do see other users of it, so I'm trying again.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ping me on Slack if you get into trouble with the generated bindings. Hopefully I can help. We should definitely be able to make this work without custom bindings.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WTFMove(resultPayload).isolatedCopy() no? since we're passing to another thread.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why we have code that does WTFMove(resultPayload).isolatedCopy(), if moving the object to another thread is bad.

Shouldn't such cases always just be resultPayload = resultPayload.isolatedCopy() (assuming the return of isolatedCopy is automatically moved to the new lambda value?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many of our objects (like String) have a more optimized isolatedCopy() version when called on a r-value reference (which avoids isolated copying in cases where it is safe). Therefore, if our can WTFMove(), you should WTFMove().isolatedCopy().

Also, you should always isolatedCopy() when passing non-trivial types to another thread.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yah, if we deem somewhere needs an isolatedCopy(), then the WTFMove(...) part is unnecessary.

I'll check more closely on this, but I'm not convinced we need them:
It came directly off IPC and been WTFMove()'d around.

After addressing all other feedback, will look closely.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yah, if we deem somewhere needs an isolatedCopy(), then the WTFMove(...) part is unnecessary.

I explained that this isn't true. WTFMove(foo).isolatedCopy() is more efficient with MANY of our types. See for example String:

    WTF_EXPORT_PRIVATE String WARN_UNUSED_RETURN isolatedCopy() const &;
    WTF_EXPORT_PRIVATE String WARN_UNUSED_RETURN isolatedCopy() &&;

It came directly off IPC and been WTFMove()'d around.

We use WTFMove().isolatedCopy() these days to do this safely. It is as efficient and you can't get it wrong. It is bad practice to make assumption and just WTFMove() to another thread. We stopped doing this a while back.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we need to isolatedCopy() data and proposedPayload?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked at those types. We don't need to isolatedCopy() data but I believe we need it for proposedPayload.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so - Each of them has directly come in off IPC and been WTFMove()'d around.

Certainly data never has been before this patch.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what WTFMove(proposedPayload).isolatedCopy() is for and you need to make sure proposedPayload has a && isolatedCopy().

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RefPtr

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed? It's not stored for later use and cannot possibly be cleared here before this use is done.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ryosuke and I are fixing them after you land code like this because the static analyzer complains. You're calling a function on it on the next line so you need to hold a strong ref to it. Recent policy change for safety.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RefPtr

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely less sure about lifecycle for this one - Added.

Comment thread Source/WebCore/page/WorkerNavigator.cpp Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RefPtr

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the same reason as the last one about the current notification even, not needed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, no raw pointer variable in new code, even if you think it is safe.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing ? since you say in the comment below that this attribute is nullable.

@beidson beidson removed the merging-blocked Applied to prevent a change from being merged label Sep 22, 2023
@beidson
beidson force-pushed the eng/Declarative-Web-Push-Support-pushnotification-event-for-declarative-messages-that-are-mutable branch from 381ddb1 to 58bb336 Compare September 22, 2023 22:58
@beidson
beidson force-pushed the eng/Declarative-Web-Push-Support-pushnotification-event-for-declarative-messages-that-are-mutable branch from 58bb336 to 8df4f26 Compare September 23, 2023 01:04
@webkit-early-warning-system

Copy link
Copy Markdown
Collaborator

Starting EWS tests for 8df4f26. Live statuses available at the PR page, #18087

@cdumez cdumez left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with nits.

Nice that you were able to make unsigned long long? work in the IDL.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you missed this change.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2023?

Comment thread Source/WebCore/page/WorkerNavigator.cpp Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: little bit of a weird pattern. This would be more concise and achieve the same:

if (RefPtr event = downcast<ServiceWorkerGlobalScope>(*scope).pushNotificationEvent()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same weird pattern. Not much use in saying both auto and RefPtr.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ref

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing crossThreadCopy() for resultPayload.

@beidson
beidson force-pushed the eng/Declarative-Web-Push-Support-pushnotification-event-for-declarative-messages-that-are-mutable branch from 8df4f26 to 46eeaab Compare September 23, 2023 03:28
@beidson
beidson force-pushed the eng/Declarative-Web-Push-Support-pushnotification-event-for-declarative-messages-that-are-mutable branch from 46eeaab to de03b84 Compare September 23, 2023 06:40
@beidson beidson added the merge-queue Applied to send a pull request to merge-queue label Sep 23, 2023
…e messages that are mutable

https://bugs.webkit.org/show_bug.cgi?id=261956
rdar://114886688

Reviewed by Brent Fulgham and Chris Dumez.

When a declarative web push message arrives, and the sender has explicitly marked it "mutable",
we fire a new `pushnotification` event at the Service Worker if there is one.

That event handler is given the proposed Notification described by the declarative message, and
has the opportunity to offer a new one instead.

It is also given the proposed AppBadge count described by the declarative message, and can modify
that as well.

If the event takes too long, or does *not* override the proposed Notification or AppBadge count,
then the originals described by the declarative message are used instead.

Implementation-wise, it's amazing how long of a chain of message handlers and completion handlers
exist to get a push message from the UI process to the point where an event can be dispatched
to the ServiceWorker.

This patch changes every single link in that chain to:
1 - Pass along the proposed NotificationPayload if one exists
2 - Change the CompletionHandlers to return the new NotificationPayload to be used.

* Source/WebCore/CMakeLists.txt:
* Source/WebCore/DerivedSources-input.xcfilelist:
* Source/WebCore/DerivedSources-output.xcfilelist:
* Source/WebCore/DerivedSources.make:
* Source/WebCore/Headers.cmake:
* Source/WebCore/Modules/notifications/Notification.cpp:
(WebCore::Notification::create):
(WebCore::Notification::Notification):
* Source/WebCore/Modules/notifications/Notification.h:
* Source/WebCore/Modules/notifications/NotificationOptionsPayload.h:
(WebCore::NotificationOptionsPayload::isolatedCopy):
* Source/WebCore/Modules/notifications/NotificationPayload.cpp:
(WebCore::NotificationPayload::fromNotificationData):
* Source/WebCore/Modules/notifications/NotificationPayload.h:
(WebCore::NotificationPayload::isolatedCopy):
* Source/WebCore/Modules/push-api/PushNotificationEvent.cpp: Copied from Source/WebCore/Modules/notifications/NotificationPayload.cpp.
(WebCore::PushNotificationEvent::PushNotificationEvent):
(WebCore::PushNotificationEvent::~PushNotificationEvent):
(WebCore::PushNotificationEvent::create):
* Source/WebCore/Modules/push-api/PushNotificationEvent.h: Added.
* Source/WebCore/Modules/push-api/PushNotificationEvent.idl: Copied from Source/WebCore/Modules/notifications/NotificationOptionsPayload.h.
* Source/WebCore/Modules/push-api/PushNotificationEventInit.h: Copied from Source/WebCore/Modules/notifications/NotificationOptionsPayload.h.
* Source/WebCore/Modules/push-api/PushNotificationEventInit.idl: Copied from Source/WebCore/Modules/notifications/NotificationOptionsPayload.h.
* Source/WebCore/Modules/webcodecs/WebCodecsAudioEncoder.cpp:
* Source/WebCore/Sources.txt:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/bindings/js/WebCoreBuiltinNames.h:
* Source/WebCore/dom/EventNames.h:
* Source/WebCore/dom/EventNames.in:
* Source/WebCore/page/WorkerNavigator.cpp:
(WebCore::WorkerNavigator::setAppBadge):
* Source/WebCore/testing/ServiceWorkerInternals.cpp:
(WebCore::ServiceWorkerInternals::schedulePushEvent):
* Source/WebCore/workers/service/ServiceWorkerGlobalScope.cpp:
(WebCore::ServiceWorkerGlobalScope::dispatchPushEvent):
(WebCore::ServiceWorkerGlobalScope::dispatchPushNotificationEvent):
(WebCore::ServiceWorkerGlobalScope::clearPushNotificationEvent):
* Source/WebCore/workers/service/ServiceWorkerGlobalScope.h:
* Source/WebCore/workers/service/ServiceWorkerRegistration.cpp:
(WebCore::ServiceWorkerRegistration::showNotification):
* Source/WebCore/workers/service/context/SWContextManager.cpp:
(WebCore::SWContextManager::firePushEvent):
* Source/WebCore/workers/service/context/SWContextManager.h:
* Source/WebCore/workers/service/context/ServiceWorkerThread.cpp:
(WebCore::ServiceWorkerThread::queueTaskToFirePushEvent):
(WebCore::ServiceWorkerThread::queueTaskToFirePushNotificationEvent):
(WebCore::ServiceWorkerThread::startNotificationPayloadFunctionalEventMonitoring):
(WebCore::ServiceWorkerThread::heartBeatTimerFired):
* Source/WebCore/workers/service/context/ServiceWorkerThread.h:
(WebCore::ServiceWorkerThread::stopNotificationPayloadFunctionalEventMonitoring):
* Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.cpp:
(WebCore::ServiceWorkerThreadProxy::firePushEvent):
* Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.h:
* Source/WebCore/workers/service/server/SWServer.cpp:
(WebCore::SWServer::processPushMessage):
* Source/WebCore/workers/service/server/SWServer.h:
* Source/WebCore/workers/service/server/SWServerToContextConnection.h:
* Source/WebKit/NetworkProcess/NetworkProcess.cpp:
(WebKit::NetworkProcess::processPushMessage):
* Source/WebKit/NetworkProcess/NetworkProcess.h:
* Source/WebKit/NetworkProcess/NetworkProcess.messages.in:
* Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.cpp:
(WebKit::WebSWServerToContextConnection::firePushEvent):
* Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.h:
* Source/WebKit/Scripts/webkit/messages.py:
(types_that_cannot_be_forward_declared):
* Source/WebKit/Shared/Cocoa/WebPushMessageCocoa.mm:
(WebKit::WebPushMessage::fromDictionary):
* Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in:
* Source/WebKit/Shared/WebPushMessage.h:
* Source/WebKit/Shared/WebPushMessage.serialization.in:
* Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp:
(WebKit::NetworkProcessProxy::processPushMessage):
* Source/WebKit/UIProcess/Network/NetworkProcessProxy.h:
* Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp:
(WebKit::WebsiteDataStore::processPushMessage):
* Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp:
(WebKit::WebSWContextManagerConnection::firePushEvent):
* Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h:
* Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in:
* Source/WebKit/webpushd/PushService.mm:
(WebPushD::PushService::didReceivePushMessage):
* Source/WebKit/webpushd/WebPushDaemon.mm:
(WebPushD::WebPushDaemon::injectPushMessageForTesting):
(WebPushD::WebPushDaemon::getPendingPushMessages):
* Tools/TestWebKitAPI/Tests/WebKitCocoa/WebPushDaemon.mm:
(-[PushNotificationDelegate clearMostRecents]):

Canonical link: https://commits.webkit.org/268358@main
@webkit-commit-queue
webkit-commit-queue force-pushed the eng/Declarative-Web-Push-Support-pushnotification-event-for-declarative-messages-that-are-mutable branch from de03b84 to 4b36aea Compare September 23, 2023 08:54
@webkit-commit-queue

Copy link
Copy Markdown
Collaborator

Committed 268358@main (4b36aea): https://commits.webkit.org/268358@main

Reviewed commits have been landed. Closing PR #18087 and removing active labels.

@webkit-commit-queue
webkit-commit-queue merged commit 4b36aea into WebKit:main Sep 23, 2023
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Sep 23, 2023
@saschanaz saschanaz mentioned this pull request Jul 31, 2025
3 of 4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

WebKit Misc. For miscellaneous bugs in the WebKit framework (and not JavaScriptCore or WebCore).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants