Title: [293296] trunk
Revision
293296
Author
beid...@apple.com
Date
2022-04-23 15:26:57 -0700 (Sat, 23 Apr 2022)

Log Message

Add WKNotification and WKWebsiteDataStore SPI for handling click/close of persistent notifications
https://bugs.webkit.org/show_bug.cgi

Reviewed by Chris Dumez.

Source/WebCore:

Covered by existing tests with WKTR changes.

In Cocoa, expose the dictionary representation of a notification as an NSDictionary,
as it is meant to be used as an NSUserNotification userInfo value.

* Modules/notifications/NotificationData.h:
* Modules/notifications/NotificationDataCocoa.mm: Added.
(WebCore::NotificationData::fromDictionary):
(WebCore::NotificationData::dictionaryRepresentation const):

* SourcesCocoa.txt:
* WebCore.xcodeproj/project.pbxproj:

* workers/service/server/SWServer.cpp:
(WebCore::SWServer::processNotificationEvent):
* workers/service/server/SWServer.h:

Source/WebKit:

For notifications that are persistent, add WKWebsiteDataStore SPI to handle click/close operations,
as the WKNotificationManager's runtime record of such notifications might be gone.

WebKitTestRunner exercises this new SPI in existing tests.

* NetworkProcess/NetworkProcess.cpp:
(WebKit::NetworkProcess::processNotificationEvent):
* NetworkProcess/NetworkProcess.h:
* NetworkProcess/NetworkProcess.messages.in:

* SourcesCocoa.txt:

* UIProcess/API/C/WKNotification.cpp:
(WKNotificationGetIsPersistent):
* UIProcess/API/C/WKNotification.h:

* UIProcess/API/C/mac/WKNotificationPrivateMac.h: Copied from Source/WebKit/UIProcess/API/Cocoa/_WKDownloadInternal.h.
* UIProcess/API/C/mac/WKNotificationPrivateMac.mm: Copied from Source/WebKit/UIProcess/API/Cocoa/_WKDownloadInternal.h.
(WKNotificationCopyDictionaryRepresentation):

* UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
(-[WKWebsiteDataStore _processPersistentNotificationClick:completionHandler:]):
(-[WKWebsiteDataStore _processPersistentNotificationClose:completionHandler:]):
* UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h:

* UIProcess/API/Cocoa/_WKDownload.mm:
* UIProcess/API/Cocoa/_WKDownloadInternal.h:

* UIProcess/Network/NetworkProcessProxy.cpp:
(WebKit::NetworkProcessProxy::processNotificationEvent):
* UIProcess/Network/NetworkProcessProxy.h:

* UIProcess/Notifications/WebNotification.cpp:
* UIProcess/Notifications/WebNotification.h:
* UIProcess/Notifications/WebNotificationManagerProxy.cpp:
(WebKit::dispatchDidClickNotification):
(WebKit::WebNotificationManagerProxy::providerDidCloseNotifications):

* WebKit.xcodeproj/project.pbxproj:

Tools:

Teach WKTR to use the new SPI by keeping a set of notifications that are persistent.

* WebKitTestRunner/WebKitTestRunner.xcodeproj/project.pbxproj:

* WebKitTestRunner/WebNotificationProvider.cpp:
(WTR::WebNotificationProvider::showWebNotification):
(WTR::WebNotificationProvider::closeWebNotification):
(WTR::WebNotificationProvider::reset):
* WebKitTestRunner/WebNotificationProvider.h:

* WebKitTestRunner/cocoa/WebNotificationProviderCocoa.mm:
(WTR::WebNotificationProvider::simulateWebNotificationClickForServiceWorkerNotifications):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (293295 => 293296)


--- trunk/Source/WebCore/ChangeLog	2022-04-23 21:47:00 UTC (rev 293295)
+++ trunk/Source/WebCore/ChangeLog	2022-04-23 22:26:57 UTC (rev 293296)
@@ -1,3 +1,27 @@
+2022-04-23  Brady Eidson  <beid...@apple.com>
+
+        Add WKNotification and WKWebsiteDataStore SPI for handling click/close of persistent notifications
+        https://bugs.webkit.org/show_bug.cgi
+
+        Reviewed by Chris Dumez.
+
+        Covered by existing tests with WKTR changes.
+
+        In Cocoa, expose the dictionary representation of a notification as an NSDictionary,
+        as it is meant to be used as an NSUserNotification userInfo value.
+
+        * Modules/notifications/NotificationData.h:
+        * Modules/notifications/NotificationDataCocoa.mm: Added.
+        (WebCore::NotificationData::fromDictionary):
+        (WebCore::NotificationData::dictionaryRepresentation const):
+
+        * SourcesCocoa.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+
+        * workers/service/server/SWServer.cpp:
+        (WebCore::SWServer::processNotificationEvent):
+        * workers/service/server/SWServer.h:
+
 2022-04-23  Justin Michaud  <justin_mich...@apple.com>
 
         Fix build error caused by LTO + Unified Sources

Modified: trunk/Source/WebCore/Modules/notifications/NotificationData.h (293295 => 293296)


--- trunk/Source/WebCore/Modules/notifications/NotificationData.h	2022-04-23 21:47:00 UTC (rev 293295)
+++ trunk/Source/WebCore/Modules/notifications/NotificationData.h	2022-04-23 22:26:57 UTC (rev 293296)
@@ -32,6 +32,8 @@
 #include <wtf/UUID.h>
 #include <wtf/text/WTFString.h>
 
+OBJC_CLASS NSDictionary;
+
 namespace WebCore {
 
 enum class NotificationDirection : uint8_t;
@@ -43,6 +45,11 @@
     NotificationData isolatedCopy() const &;
     NotificationData isolatedCopy() &&;
 
+#if PLATFORM(COCOA)
+    WEBCORE_EXPORT static std::optional<NotificationData> fromDictionary(NSDictionary *dictionaryRepresentation);
+    WEBCORE_EXPORT NSDictionary *dictionaryRepresentation() const;
+#endif
+
     String title;
     String body;
     String iconURL;

Added: trunk/Source/WebCore/Modules/notifications/NotificationDataCocoa.mm (0 => 293296)


--- trunk/Source/WebCore/Modules/notifications/NotificationDataCocoa.mm	                        (rev 0)
+++ trunk/Source/WebCore/Modules/notifications/NotificationDataCocoa.mm	2022-04-23 22:26:57 UTC (rev 293296)
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2022 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "NotificationData.h"
+
+#import "NotificationDirection.h"
+
+static NSString * const WebNotificationTitleKey = @"WebNotificationTitleKey";
+static NSString * const WebNotificationBodyKey = @"WebNotificationBodyKey";
+static NSString * const WebNotificationIconURLKey = @"WebNotificationIconURLKey";
+static NSString * const WebNotificationTagKey = @"WebNotificationTagKey";
+static NSString * const WebNotificationLanguageKey = @"WebNotificationLanguageKey";
+static NSString * const WebNotificationDirectionKey = @"WebNotificationDirectionKey";
+static NSString * const WebNotificationOriginKey = @"WebNotificationOriginKey";
+static NSString * const WebNotificationServiceWorkerRegistrationURLKey = @"WebNotificationServiceWorkerRegistrationURLKey";
+static NSString * const WebNotificationUUIDStringKey = @"WebNotificationUUIDStringKey";
+static NSString * const WebNotificationSessionIDKey = @"WebNotificationSessionIDKey";
+
+namespace WebCore {
+
+std::optional<NotificationData> NotificationData::fromDictionary(NSDictionary *dictionary)
+{
+    NSString *title = dictionary[WebNotificationTitleKey];
+    NSString *body = dictionary[WebNotificationBodyKey];
+    NSString *iconURL = dictionary[WebNotificationIconURLKey];
+    NSString *tag = dictionary[WebNotificationTagKey];
+    NSString *language = dictionary[WebNotificationLanguageKey];
+    NSString *originString = dictionary[WebNotificationOriginKey];
+    NSString *serviceWorkerRegistrationURL = dictionary[WebNotificationServiceWorkerRegistrationURLKey];
+    NSNumber *sessionID = dictionary[WebNotificationSessionIDKey];
+
+    NSString *uuidString = dictionary[WebNotificationUUIDStringKey];
+    auto uuid = UUID::parseVersion4(String(uuidString));
+    if (!uuid)
+        return std::nullopt;
+
+    NotificationDirection direction;
+    NSNumber *directionNumber = dictionary[WebNotificationDirectionKey];
+    switch ((NotificationDirection)(directionNumber.unsignedLongValue)) {
+    case NotificationDirection::Auto:
+    case NotificationDirection::Ltr:
+    case NotificationDirection::Rtl:
+        direction = (NotificationDirection)directionNumber.unsignedLongValue;
+        break;
+    default:
+        return std::nullopt;
+    }
+
+    NotificationData data { title, body, iconURL, tag, language, direction, originString, URL { String { serviceWorkerRegistrationURL } }, *uuid, PAL::SessionID { sessionID.unsignedLongLongValue }, { } };
+    return WTFMove(data);
+}
+
+NSDictionary *NotificationData::dictionaryRepresentation() const
+{
+    return @{
+        WebNotificationTitleKey : (NSString *)title,
+        WebNotificationBodyKey : (NSString *)body,
+        WebNotificationIconURLKey : (NSString *)iconURL,
+        WebNotificationTagKey : (NSString *)tag,
+        WebNotificationLanguageKey : (NSString *)language,
+        WebNotificationOriginKey : (NSString *)originString,
+        WebNotificationDirectionKey : @((unsigned long)direction),
+        WebNotificationServiceWorkerRegistrationURLKey : (NSString *)serviceWorkerRegistrationURL.string(),
+        WebNotificationUUIDStringKey : (NSString *)notificationID.toString(),
+        WebNotificationSessionIDKey : @(sourceSession.toUInt64())
+    };
+}
+
+} // namespace WebKit

Modified: trunk/Source/WebCore/SourcesCocoa.txt (293295 => 293296)


--- trunk/Source/WebCore/SourcesCocoa.txt	2022-04-23 21:47:00 UTC (rev 293295)
+++ trunk/Source/WebCore/SourcesCocoa.txt	2022-04-23 22:26:57 UTC (rev 293296)
@@ -114,6 +114,7 @@
 Modules/model-element/scenekit/SceneKitModelLoaderClient.mm
 Modules/model-element/scenekit/SceneKitModelLoaderUSD.mm
 Modules/model-element/scenekit/SceneKitModelPlayer.mm
+Modules/notifications/NotificationDataCocoa.mm
 Modules/push-api/cocoa/PushCryptoCocoa.cpp
 Modules/plugins/YouTubePluginReplacement.cpp
 Modules/speech/cocoa/SpeechRecognizerCocoa.mm

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (293295 => 293296)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2022-04-23 21:47:00 UTC (rev 293295)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2022-04-23 22:26:57 UTC (rev 293296)
@@ -9909,6 +9909,7 @@
 		518F5000194CAC3A0081BAAE /* JSGamepadButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSGamepadButton.h; sourceTree = "<group>"; };
 		518F97001BE94C5B0023187C /* MemoryIndex.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MemoryIndex.cpp; sourceTree = "<group>"; };
 		518F97011BE94C5B0023187C /* MemoryIndex.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MemoryIndex.h; sourceTree = "<group>"; };
+		5194C26827FFD7C200AEF3CF /* NotificationDataCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = NotificationDataCocoa.mm; sourceTree = "<group>"; };
 		519755F71BFD7DBC003DE980 /* MemoryIndexCursor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MemoryIndexCursor.cpp; sourceTree = "<group>"; };
 		519755F81BFD7DBC003DE980 /* MemoryIndexCursor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MemoryIndexCursor.h; sourceTree = "<group>"; };
 		5198F7A21BBDAA2900E2CC5F /* UniqueIDBDatabaseConnection.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UniqueIDBDatabaseConnection.cpp; sourceTree = "<group>"; };
@@ -21002,6 +21003,7 @@
 				3128CA6A147331630074C72A /* NotificationController.h */,
 				51123E2E27693C3300F9D41B /* NotificationData.cpp */,
 				51123E2C27693C3200F9D41B /* NotificationData.h */,
+				5194C26827FFD7C200AEF3CF /* NotificationDataCocoa.mm */,
 				7CC2DE021ECA04A50027B774 /* NotificationDirection.h */,
 				51E3AF0C276B0602009B429D /* NotificationDirection.idl */,
 				510E2F2C276BE0C300809333 /* NotificationEvent.cpp */,

Modified: trunk/Source/WebCore/workers/service/server/SWServer.cpp (293295 => 293296)


--- trunk/Source/WebCore/workers/service/server/SWServer.cpp	2022-04-23 21:47:00 UTC (rev 293295)
+++ trunk/Source/WebCore/workers/service/server/SWServer.cpp	2022-04-23 22:26:57 UTC (rev 293296)
@@ -1365,25 +1365,35 @@
     });
 }
 
-void SWServer::processNotificationEvent(NotificationData&& data, NotificationEventType type)
+void SWServer::processNotificationEvent(NotificationData&& data, NotificationEventType type, CompletionHandler<void(bool)>&& callback)
 {
-    whenImportIsCompletedIfNeeded([this, weakThis = WeakPtr { *this }, data = "" type]() mutable {
-        if (!weakThis)
+    whenImportIsCompletedIfNeeded([this, weakThis = WeakPtr { *this }, data = "" type, callback = WTFMove(callback)]() mutable {
+        if (!weakThis) {
+            callback(false);
             return;
+        }
 
         auto origin = SecurityOriginData::fromURL(data.serviceWorkerRegistrationURL);
         ServiceWorkerRegistrationKey registrationKey { WTFMove(origin), URL { data.serviceWorkerRegistrationURL } };
         auto registration = m_scopeToRegistrationMap.get(registrationKey);
-        if (!registration)
+        if (!registration) {
+            RELEASE_LOG_ERROR(Push, "Cannot process notification event: Failed to find SW registration for scope %" PRIVATE_LOG_STRING, registrationKey.scope().string().utf8().data());
+            callback(true);
             return;
+        }
 
         auto* worker = registration->activeWorker();
-        if (!worker)
+        if (!worker) {
+            RELEASE_LOG_ERROR(Push, "Cannot process notification event: No active worker for scope %" PRIVATE_LOG_STRING, registrationKey.scope().string().utf8().data());
+            callback(true);
             return;
+        }
 
-        fireFunctionalEvent(*registration, [worker = Ref { *worker }, weakThis = WTFMove(weakThis), data = "" type](auto&& connectionOrStatus) mutable {
-            if (!connectionOrStatus.has_value())
+        fireFunctionalEvent(*registration, [worker = Ref { *worker }, weakThis = WTFMove(weakThis), data = "" type, callback = WTFMove(callback)](auto&& connectionOrStatus) mutable {
+            if (!connectionOrStatus.has_value()) {
+                callback(connectionOrStatus.error() == ShouldSkipEvent::Yes);
                 return;
+            }
 
             auto serviceWorkerIdentifier = worker->identifier();
 
@@ -1393,13 +1403,16 @@
                 worker->decrementFunctionalEventCounter();
             });
             terminateWorkerTimer->startOneShot(weakThis && weakThis->m_isProcessTerminationDelayEnabled ? defaultTerminationDelay : defaultFunctionalEventDuration);
-            connectionOrStatus.value()->fireNotificationEvent(serviceWorkerIdentifier, data, type, [terminateWorkerTimer = WTFMove(terminateWorkerTimer), worker = WTFMove(worker)](bool succeeded) mutable {
+            connectionOrStatus.value()->fireNotificationEvent(serviceWorkerIdentifier, data, type, [callback = WTFMove(callback), terminateWorkerTimer = WTFMove(terminateWorkerTimer), worker = WTFMove(worker)] (bool succeeded) mutable {
                 RELEASE_LOG_ERROR_IF(!succeeded, ServiceWorker, "Service Worker notification event handler did not succeed");
+
                 // FIXME: if succeeded is false, should we implement a default action like opening a new page?
                 if (terminateWorkerTimer->isActive()) {
                     worker->decrementFunctionalEventCounter();
                     terminateWorkerTimer->stop();
                 }
+
+                callback(succeeded);
             });
         });
     });

Modified: trunk/Source/WebCore/workers/service/server/SWServer.h (293295 => 293296)


--- trunk/Source/WebCore/workers/service/server/SWServer.h	2022-04-23 21:47:00 UTC (rev 293295)
+++ trunk/Source/WebCore/workers/service/server/SWServer.h	2022-04-23 22:26:57 UTC (rev 293296)
@@ -230,7 +230,7 @@
     bool shouldRunServiceWorkersOnMainThreadForTesting() const { return m_shouldRunServiceWorkersOnMainThreadForTesting; }
 
     WEBCORE_EXPORT void processPushMessage(std::optional<Vector<uint8_t>>&&, URL&&, CompletionHandler<void(bool)>&&);
-    WEBCORE_EXPORT void processNotificationEvent(NotificationData&&, NotificationEventType);
+    WEBCORE_EXPORT void processNotificationEvent(NotificationData&&, NotificationEventType, CompletionHandler<void(bool)>&&);
 
     enum class ShouldSkipEvent : bool { No, Yes };
     void fireFunctionalEvent(SWServerRegistration&, CompletionHandler<void(Expected<SWServerToContextConnection*, ShouldSkipEvent>)>&&);

Modified: trunk/Source/WebKit/ChangeLog (293295 => 293296)


--- trunk/Source/WebKit/ChangeLog	2022-04-23 21:47:00 UTC (rev 293295)
+++ trunk/Source/WebKit/ChangeLog	2022-04-23 22:26:57 UTC (rev 293296)
@@ -1,3 +1,50 @@
+2022-04-23  Brady Eidson  <beid...@apple.com>
+
+        Add WKNotification and WKWebsiteDataStore SPI for handling click/close of persistent notifications
+        https://bugs.webkit.org/show_bug.cgi
+
+        Reviewed by Chris Dumez.
+
+        For notifications that are persistent, add WKWebsiteDataStore SPI to handle click/close operations,
+        as the WKNotificationManager's runtime record of such notifications might be gone.
+        
+        WebKitTestRunner exercises this new SPI in existing tests.
+        
+        * NetworkProcess/NetworkProcess.cpp:
+        (WebKit::NetworkProcess::processNotificationEvent):
+        * NetworkProcess/NetworkProcess.h:
+        * NetworkProcess/NetworkProcess.messages.in:
+        
+        * SourcesCocoa.txt:
+        
+        * UIProcess/API/C/WKNotification.cpp:
+        (WKNotificationGetIsPersistent):
+        * UIProcess/API/C/WKNotification.h:
+        
+        * UIProcess/API/C/mac/WKNotificationPrivateMac.h: Copied from Source/WebKit/UIProcess/API/Cocoa/_WKDownloadInternal.h.
+        * UIProcess/API/C/mac/WKNotificationPrivateMac.mm: Copied from Source/WebKit/UIProcess/API/Cocoa/_WKDownloadInternal.h.
+        (WKNotificationCopyDictionaryRepresentation):
+        
+        * UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
+        (-[WKWebsiteDataStore _processPersistentNotificationClick:completionHandler:]):
+        (-[WKWebsiteDataStore _processPersistentNotificationClose:completionHandler:]):
+        * UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h:
+        
+        * UIProcess/API/Cocoa/_WKDownload.mm:
+        * UIProcess/API/Cocoa/_WKDownloadInternal.h:
+        
+        * UIProcess/Network/NetworkProcessProxy.cpp:
+        (WebKit::NetworkProcessProxy::processNotificationEvent):
+        * UIProcess/Network/NetworkProcessProxy.h:
+        
+        * UIProcess/Notifications/WebNotification.cpp:
+        * UIProcess/Notifications/WebNotification.h:
+        * UIProcess/Notifications/WebNotificationManagerProxy.cpp:
+        (WebKit::dispatchDidClickNotification):
+        (WebKit::WebNotificationManagerProxy::providerDidCloseNotifications):
+        
+        * WebKit.xcodeproj/project.pbxproj:
+
 2022-04-22  Chris Dumez  <cdu...@apple.com>
 
         Move global AtomStrings to a common header to promote reuse

Modified: trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp (293295 => 293296)


--- trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp	2022-04-23 21:47:00 UTC (rev 293295)
+++ trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp	2022-04-23 22:26:57 UTC (rev 293296)
@@ -2301,10 +2301,10 @@
 }
 
 #if ENABLE(SERVICE_WORKER)
-void NetworkProcess::processNotificationEvent(NotificationData&& data, NotificationEventType eventType)
+void NetworkProcess::processNotificationEvent(NotificationData&& data, NotificationEventType eventType, CompletionHandler<void(bool)>&& callback)
 {
     if (auto* session = networkSession(data.sourceSession))
-        session->ensureSWServer().processNotificationEvent(WTFMove(data), eventType);
+        session->ensureSWServer().processNotificationEvent(WTFMove(data), eventType, WTFMove(callback));
 }
 
 #if ENABLE(BUILT_IN_NOTIFICATIONS)

Modified: trunk/Source/WebKit/NetworkProcess/NetworkProcess.h (293295 => 293296)


--- trunk/Source/WebKit/NetworkProcess/NetworkProcess.h	2022-04-23 21:47:00 UTC (rev 293295)
+++ trunk/Source/WebKit/NetworkProcess/NetworkProcess.h	2022-04-23 22:26:57 UTC (rev 293296)
@@ -377,7 +377,7 @@
 #if ENABLE(SERVICE_WORKER)
     void getPendingPushMessages(PAL::SessionID, CompletionHandler<void(const Vector<WebPushMessage>&)>&&);
     void processPushMessage(PAL::SessionID, WebPushMessage&&, WebCore::PushPermissionState, CompletionHandler<void(bool)>&&);
-    void processNotificationEvent(WebCore::NotificationData&&, WebCore::NotificationEventType);
+    void processNotificationEvent(WebCore::NotificationData&&, WebCore::NotificationEventType, CompletionHandler<void(bool)>&&);
 #endif
 
     void deletePushAndNotificationRegistration(PAL::SessionID, const WebCore::SecurityOriginData&, CompletionHandler<void(const String&)>&&);

Modified: trunk/Source/WebKit/NetworkProcess/NetworkProcess.messages.in (293295 => 293296)


--- trunk/Source/WebKit/NetworkProcess/NetworkProcess.messages.in	2022-04-23 21:47:00 UTC (rev 293295)
+++ trunk/Source/WebKit/NetworkProcess/NetworkProcess.messages.in	2022-04-23 22:26:57 UTC (rev 293296)
@@ -210,7 +210,7 @@
 #if ENABLE(SERVICE_WORKER)
     GetPendingPushMessages(PAL::SessionID sessionID) -> (Vector<WebKit::WebPushMessage> messages)
     ProcessPushMessage(PAL::SessionID sessionID, struct WebKit::WebPushMessage pushMessage, enum:uint8_t WebCore::PushPermissionState pushPermissionState) -> (bool didSucceed)
-    ProcessNotificationEvent(struct WebCore::NotificationData data, enum:bool WebCore::NotificationEventType eventType)
+    ProcessNotificationEvent(struct WebCore::NotificationData data, enum:bool WebCore::NotificationEventType eventType) -> (bool didSucceed)
 #endif
     DeletePushAndNotificationRegistration(PAL::SessionID sessionID, struct WebCore::SecurityOriginData origin) -> (String errorMessage)
     GetOriginsWithPushAndNotificationPermissions(PAL::SessionID sessionID) -> (Vector<WebCore::SecurityOriginData> origins)

Modified: trunk/Source/WebKit/Shared/ModelIdentifier.h (293295 => 293296)


--- trunk/Source/WebKit/Shared/ModelIdentifier.h	2022-04-23 21:47:00 UTC (rev 293295)
+++ trunk/Source/WebKit/Shared/ModelIdentifier.h	2022-04-23 22:26:57 UTC (rev 293296)
@@ -27,14 +27,14 @@
 
 #import <wtf/text/WTFString.h>
 
+#if ENABLE(ARKIT_INLINE_PREVIEW_IOS)
+#import <WebCore/GraphicsLayer.h>
+#endif
+
 namespace WebKit {
 
 #if ENABLE(ARKIT_INLINE_PREVIEW)
 
-#if ENABLE(ARKIT_INLINE_PREVIEW_IOS)
-#import <WebCore/GraphicsLayer.h>
-#endif
-
 struct ModelIdentifier {
 #if ENABLE(ARKIT_INLINE_PREVIEW_MAC)
     String uuid;

Modified: trunk/Source/WebKit/SourcesCocoa.txt (293295 => 293296)


--- trunk/Source/WebKit/SourcesCocoa.txt	2022-04-23 21:47:00 UTC (rev 293295)
+++ trunk/Source/WebKit/SourcesCocoa.txt	2022-04-23 22:26:57 UTC (rev 293296)
@@ -267,6 +267,7 @@
 UIProcess/API/C/cg/WKIconDatabaseCG.cpp
 
 UIProcess/API/C/mac/WKContextPrivateMac.mm
+UIProcess/API/C/mac/WKNotificationPrivateMac.mm
 UIProcess/API/C/mac/WKPagePrivateMac.mm
 UIProcess/API/C/mac/WKProtectionSpaceNS.mm
 

Modified: trunk/Source/WebKit/UIProcess/API/C/WKNotification.cpp (293295 => 293296)


--- trunk/Source/WebKit/UIProcess/API/C/WKNotification.cpp	2022-04-23 21:47:00 UTC (rev 293295)
+++ trunk/Source/WebKit/UIProcess/API/C/WKNotification.cpp	2022-04-23 22:26:57 UTC (rev 293296)
@@ -95,3 +95,8 @@
     auto span = identifier.toSpan();
     return WKDataCreate(span.data(), span.size());
 }
+
+bool WKNotificationGetIsPersistent(WKNotificationRef notification)
+{
+    return toImpl(notification)->isPersistentNotification();
+}

Modified: trunk/Source/WebKit/UIProcess/API/C/WKNotification.h (293295 => 293296)


--- trunk/Source/WebKit/UIProcess/API/C/WKNotification.h	2022-04-23 21:47:00 UTC (rev 293295)
+++ trunk/Source/WebKit/UIProcess/API/C/WKNotification.h	2022-04-23 22:26:57 UTC (rev 293296)
@@ -43,6 +43,7 @@
 WK_EXPORT WKSecurityOriginRef WKNotificationGetSecurityOrigin(WKNotificationRef notification);
 WK_EXPORT uint64_t WKNotificationGetID(WKNotificationRef notification);
 WK_EXPORT WKDataRef WKNotificationCopyCoreIDForTesting(WKNotificationRef notification);
+WK_EXPORT bool WKNotificationGetIsPersistent(WKNotificationRef notification);
 
 #ifdef __cplusplus
 }

Copied: trunk/Source/WebKit/UIProcess/API/C/mac/WKNotificationPrivateMac.h (from rev 293295, trunk/Source/WebKit/UIProcess/API/Cocoa/_WKDownloadInternal.h) (0 => 293296)


--- trunk/Source/WebKit/UIProcess/API/C/mac/WKNotificationPrivateMac.h	                        (rev 0)
+++ trunk/Source/WebKit/UIProcess/API/C/mac/WKNotificationPrivateMac.h	2022-04-23 22:26:57 UTC (rev 293296)
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2022 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WKNotificationPrivateMac_h
+#define WKNotificationPrivateMac_h
+
+#include <WebKit/WKBase.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef __OBJC__
+
+@class NSDictionary;
+
+WK_EXPORT NSDictionary *WKNotificationCopyDictionaryRepresentation(WKNotificationRef notification) NS_RETURNS_RETAINED;
+
+#endif // __OBJC__
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* WKNotificationPrivateMac_h */

Copied: trunk/Source/WebKit/UIProcess/API/C/mac/WKNotificationPrivateMac.mm (from rev 293295, trunk/Source/WebKit/UIProcess/API/Cocoa/_WKDownloadInternal.h) (0 => 293296)


--- trunk/Source/WebKit/UIProcess/API/C/mac/WKNotificationPrivateMac.mm	                        (rev 0)
+++ trunk/Source/WebKit/UIProcess/API/C/mac/WKNotificationPrivateMac.mm	2022-04-23 22:26:57 UTC (rev 293296)
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2022 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "WKNotificationPrivateMac.h"
+
+#import "WebNotification.h"
+#import <WebCore/NotificationData.h>
+
+NSDictionary *WKNotificationCopyDictionaryRepresentation(WKNotificationRef notification)
+{
+    return [WebKit::toImpl(notification)->data().dictionaryRepresentation() retain];
+}

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm (293295 => 293296)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm	2022-04-23 21:47:00 UTC (rev 293295)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm	2022-04-23 22:26:57 UTC (rev 293296)
@@ -38,6 +38,7 @@
 #import "WKSecurityOriginInternal.h"
 #import "WKWebViewInternal.h"
 #import "WKWebsiteDataRecordInternal.h"
+#import "WebNotification.h"
 #import "WebNotificationManagerProxy.h"
 #import "WebPageProxy.h"
 #import "WebPushMessage.h"
@@ -57,7 +58,7 @@
 
 class WebsiteDataStoreClient final : public WebKit::WebsiteDataStoreClient {
 public:
-    explicit WebsiteDataStoreClient(WKWebsiteDataStore *dataStore, id<_WKWebsiteDataStoreDelegate> delegate)
+    WebsiteDataStoreClient(WKWebsiteDataStore *dataStore, id<_WKWebsiteDataStoreDelegate> delegate)
         : m_dataStore(dataStore)
         , m_delegate(delegate)
         , m_hasRequestStorageSpaceSelector([m_delegate.get() respondsToSelector:@selector(requestStorageSpace: frameOrigin: quota: currentSize: spaceRequired: decisionHandler:)])
@@ -831,6 +832,45 @@
 #endif
 }
 
+-(void)_processPersistentNotificationClick:(NSDictionary *)notificationDictionaryRepresentation completionHandler:(void(^)(bool))completionHandler
+{
+#if ENABLE(SERVICE_WORKER)
+    auto notificationData = WebCore::NotificationData::fromDictionary(notificationDictionaryRepresentation);
+    if (!notificationData) {
+        RELEASE_LOG_ERROR(Push, "Asked to handle a persistent notification click with an invalid notification dictionary representation");
+        completionHandler(false);
+        return;
+    }
+
+    RELEASE_LOG(Push, "Sending persistent notification click from origin %" PRIVATE_LOG_STRING " to network process to handle", notificationData->originString.utf8().data());
+
+    notificationData->sourceSession = _websiteDataStore->sessionID();
+    _websiteDataStore->networkProcess().processNotificationEvent(*notificationData, WebCore::NotificationEventType::Click, [completionHandler = makeBlockPtr(completionHandler)] (bool wasProcessed) {
+        RELEASE_LOG(Push, "Notification click event processing complete. Callback result: %d", wasProcessed);
+        completionHandler(wasProcessed);
+    });
+#endif
+}
+
+-(void)_processPersistentNotificationClose:(NSDictionary *)notificationDictionaryRepresentation completionHandler:(void(^)(bool))completionHandler
+{
+#if ENABLE(SERVICE_WORKER)
+    auto notificationData = WebCore::NotificationData::fromDictionary(notificationDictionaryRepresentation);
+    if (!notificationData) {
+        RELEASE_LOG_ERROR(Push, "Asked to handle a persistent notification click with an invalid notification dictionary representation");
+        completionHandler(false);
+        return;
+    }
+
+    RELEASE_LOG(Push, "Sending persistent notification close from origin %" PRIVATE_LOG_STRING " to network process to handle", notificationData->originString.utf8().data());
+
+    _websiteDataStore->networkProcess().processNotificationEvent(*notificationData, WebCore::NotificationEventType::Close, [completionHandler = makeBlockPtr(completionHandler)] (bool wasProcessed) {
+        RELEASE_LOG(Push, "Notification close event processing complete. Callback result: %d", wasProcessed);
+        completionHandler(wasProcessed);
+    });
+#endif
+}
+
 -(void)_deletePushAndNotificationRegistration:(WKSecurityOrigin *)securityOrigin completionHandler:(void(^)(NSError *))completionHandler
 {
     auto completionHandlerCopy = makeBlockPtr(completionHandler);

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h (293295 => 293296)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h	2022-04-23 21:47:00 UTC (rev 293295)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h	2022-04-23 22:26:57 UTC (rev 293296)
@@ -111,6 +111,8 @@
 -(bool)_hasServiceWorkerBackgroundActivityForTesting WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
 -(void)_getPendingPushMessages:(void(^)(NSArray<NSDictionary *> *))completionHandler WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
 -(void)_processPushMessage:(NSDictionary *)pushMessage completionHandler:(void(^)(bool))completionHandler WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
+-(void)_processPersistentNotificationClick:(NSDictionary *)notificationDictionaryRepresentation completionHandler:(void(^)(bool))completionHandler WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
+-(void)_processPersistentNotificationClose:(NSDictionary *)notificationDictionaryRepresentation completionHandler:(void(^)(bool))completionHandler WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
 -(void)_deletePushAndNotificationRegistration:(WKSecurityOrigin *)securityOrigin completionHandler:(void(^)(NSError *))completionHandler WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
 -(void)_getOriginsWithPushAndNotificationPermissions:(void(^)(NSSet<WKSecurityOrigin *> *))completionHandler WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
 -(void)_scopeURL:(NSURL *)scopeURL hasPushSubscriptionForTesting:(void(^)(BOOL))completionHandler WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKDownload.mm (293295 => 293296)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKDownload.mm	2022-04-23 21:47:00 UTC (rev 293295)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKDownload.mm	2022-04-23 22:26:57 UTC (rev 293296)
@@ -33,7 +33,9 @@
 #import "WKNSData.h"
 #import "WKWebViewInternal.h"
 #import <wtf/WeakObjCPtr.h>
+#import <wtf/cocoa/VectorCocoa.h>
 
+
 ALLOW_DEPRECATED_DECLARATIONS_BEGIN
 static NSMapTable<WKDownload *, _WKDownload *> *downloadWrapperMap()
 {

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKDownloadInternal.h (293295 => 293296)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKDownloadInternal.h	2022-04-23 21:47:00 UTC (rev 293295)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKDownloadInternal.h	2022-04-23 22:26:57 UTC (rev 293296)
@@ -25,6 +25,7 @@
 
 #import "_WKDownload.h"
 
+#import "WKObject.h"
 #import <wtf/RetainPtr.h>
 
 @class WKDownload;

Modified: trunk/Source/WebKit/UIProcess/Cocoa/ModelElementControllerCocoa.mm (293295 => 293296)


--- trunk/Source/WebKit/UIProcess/Cocoa/ModelElementControllerCocoa.mm	2022-04-23 21:47:00 UTC (rev 293295)
+++ trunk/Source/WebKit/UIProcess/Cocoa/ModelElementControllerCocoa.mm	2022-04-23 22:26:57 UTC (rev 293296)
@@ -142,7 +142,7 @@
         modelView.userInteractionEnabled = isInteractionEnabled;
 }
 
-#endif
+#endif // ENABLE(ARKIT_INLINE_PREVIEW_IOS)
 
 #if ENABLE(ARKIT_INLINE_PREVIEW_MAC)
 
@@ -312,7 +312,7 @@
         return entry.key;
     }));
 }
-#endif
+#endif // ENABLE(ARKIT_INLINE_PREVIEW_MAC)
 
 #if ENABLE(ARKIT_INLINE_PREVIEW)
 
@@ -545,8 +545,8 @@
 #endif
 }
 
-#endif
+#endif // ENABLE(ARKIT_INLINE_PREVIEW)
 
-}
+} // namespace WebKit
 
-#endif
+#endif // ENABLE(ARKIT_INLINE_PREVIEW)

Modified: trunk/Source/WebKit/UIProcess/ModelElementController.h (293295 => 293296)


--- trunk/Source/WebKit/UIProcess/ModelElementController.h	2022-04-23 21:47:00 UTC (rev 293295)
+++ trunk/Source/WebKit/UIProcess/ModelElementController.h	2022-04-23 22:26:57 UTC (rev 293296)
@@ -99,6 +99,6 @@
 #endif
 };
 
-}
+} // namespace WebKit
 
 #endif

Modified: trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp (293295 => 293296)


--- trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp	2022-04-23 21:47:00 UTC (rev 293295)
+++ trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp	2022-04-23 22:26:57 UTC (rev 293296)
@@ -1779,9 +1779,10 @@
     sendWithAsyncReply(Messages::NetworkProcess::ProcessPushMessage { sessionID, pushMessage, permission }, WTFMove(callback));
 }
 
-void NetworkProcessProxy::processNotificationEvent(const NotificationData& data, NotificationEventType eventType)
+void NetworkProcessProxy::processNotificationEvent(const NotificationData& data, NotificationEventType eventType, CompletionHandler<void(bool wasProcessed)>&& callback)
 {
-    send(Messages::NetworkProcess::ProcessNotificationEvent { data, eventType }, 0);
+    RELEASE_ASSERT(!!callback);
+    sendWithAsyncReply(Messages::NetworkProcess::ProcessNotificationEvent { data, eventType }, WTFMove(callback));
 }
 #endif // ENABLE(SERVICE_WORKER)
 

Modified: trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h (293295 => 293296)


--- trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h	2022-04-23 21:47:00 UTC (rev 293295)
+++ trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h	2022-04-23 22:26:57 UTC (rev 293296)
@@ -286,7 +286,7 @@
 #if ENABLE(SERVICE_WORKER)
     void getPendingPushMessages(PAL::SessionID, CompletionHandler<void(const Vector<WebPushMessage>&)>&&);
     void processPushMessage(PAL::SessionID, const WebPushMessage&, CompletionHandler<void(bool wasProcessed)>&&);
-    void processNotificationEvent(const WebCore::NotificationData&, WebCore::NotificationEventType);
+    void processNotificationEvent(const WebCore::NotificationData&, WebCore::NotificationEventType, CompletionHandler<void(bool wasProcessed)>&&);
 #endif
 
     void deletePushAndNotificationRegistration(PAL::SessionID, const WebCore::SecurityOriginData&, CompletionHandler<void(const String&)>&&);

Modified: trunk/Source/WebKit/UIProcess/Notifications/WebNotification.cpp (293295 => 293296)


--- trunk/Source/WebKit/UIProcess/Notifications/WebNotification.cpp	2022-04-23 21:47:00 UTC (rev 293295)
+++ trunk/Source/WebKit/UIProcess/Notifications/WebNotification.cpp	2022-04-23 22:26:57 UTC (rev 293296)
@@ -26,6 +26,7 @@
 #include "config.h"
 #include "WebNotification.h"
 
+#include "APIDictionary.h"
 #include <WebCore/NotificationData.h>
 
 namespace WebKit {

Modified: trunk/Source/WebKit/UIProcess/Notifications/WebNotification.h (293295 => 293296)


--- trunk/Source/WebKit/UIProcess/Notifications/WebNotification.h	2022-04-23 21:47:00 UTC (rev 293295)
+++ trunk/Source/WebKit/UIProcess/Notifications/WebNotification.h	2022-04-23 22:26:57 UTC (rev 293296)
@@ -25,7 +25,7 @@
 
 #pragma once
 
-#include "APIObject.h"
+#include "APIDictionary.h"
 #include "APISecurityOrigin.h"
 #include "Connection.h"
 #include "WebPageProxyIdentifier.h"

Modified: trunk/Source/WebKit/UIProcess/Notifications/WebNotificationManagerProxy.cpp (293295 => 293296)


--- trunk/Source/WebKit/UIProcess/Notifications/WebNotificationManagerProxy.cpp	2022-04-23 21:47:00 UTC (rev 293295)
+++ trunk/Source/WebKit/UIProcess/Notifications/WebNotificationManagerProxy.cpp	2022-04-23 22:26:57 UTC (rev 293296)
@@ -194,7 +194,7 @@
 #if ENABLE(SERVICE_WORKER)
     if (notification->isPersistentNotification()) {
         if (auto* dataStore = WebsiteDataStore::existingDataStoreForSessionID(notification->sessionID()))
-            dataStore->networkProcess().processNotificationEvent(notification->data(), NotificationEventType::Click);
+            dataStore->networkProcess().processNotificationEvent(notification->data(), NotificationEventType::Click, [](bool) { });
         else
             RELEASE_LOG_ERROR(Notifications, "WebsiteDataStore not found from sessionID %" PRIu64 ", dropping notification click", notification->sessionID().toUInt64());
         return;
@@ -257,7 +257,7 @@
 #if ENABLE(SERVICE_WORKER)
         if (notification->isPersistentNotification()) {
             if (auto* dataStore = WebsiteDataStore::existingDataStoreForSessionID(notification->sessionID()))
-                dataStore->networkProcess().processNotificationEvent(notification->data(), NotificationEventType::Close);
+                dataStore->networkProcess().processNotificationEvent(notification->data(), NotificationEventType::Close, [](bool) { });
             else
                 RELEASE_LOG_ERROR(Notifications, "WebsiteDataStore not found from sessionID %" PRIu64 ", dropping notification close", notification->sessionID().toUInt64());
             return;

Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (293295 => 293296)


--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2022-04-23 21:47:00 UTC (rev 293295)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2022-04-23 22:26:57 UTC (rev 293296)
@@ -1037,6 +1037,7 @@
 		518D2CAE12D5153B003BB93B /* WebBackForwardListItem.h in Headers */ = {isa = PBXBuildFile; fileRef = 518D2CAC12D5153B003BB93B /* WebBackForwardListItem.h */; };
 		518E8EF916B2091C00E91429 /* AuthenticationManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 518E8EF416B2091C00E91429 /* AuthenticationManager.h */; };
 		51933DEF1965EB31008AC3EA /* MenuUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 51933DEB1965EB24008AC3EA /* MenuUtilities.h */; };
+		519DFBE7281387C1003FF6AD /* WKNotificationPrivateMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 519DFBE528138756003FF6AD /* WKNotificationPrivateMac.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		51A555F6128C6C47009ABCEC /* WKContextMenuItem.h in Headers */ = {isa = PBXBuildFile; fileRef = 51A555F4128C6C47009ABCEC /* WKContextMenuItem.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		51A55601128C6D92009ABCEC /* WKContextMenuItemTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 51A55600128C6D92009ABCEC /* WKContextMenuItemTypes.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		51A728DE1B1BAD3800102EEE /* WKBundleNavigationActionPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 51A728DC1B1BAD2D00102EEE /* WKBundleNavigationActionPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -4856,6 +4857,8 @@
 		51933DEB1965EB24008AC3EA /* MenuUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MenuUtilities.h; sourceTree = "<group>"; };
 		51933DEC1965EB24008AC3EA /* MenuUtilities.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MenuUtilities.mm; sourceTree = "<group>"; };
 		5194B3861F192FB900FA4708 /* CookieStorageUtilsCF.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CookieStorageUtilsCF.h; sourceTree = "<group>"; };
+		519DFBE528138756003FF6AD /* WKNotificationPrivateMac.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = WKNotificationPrivateMac.h; path = mac/WKNotificationPrivateMac.h; sourceTree = "<group>"; };
+		519DFBE628138756003FF6AD /* WKNotificationPrivateMac.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = WKNotificationPrivateMac.mm; path = mac/WKNotificationPrivateMac.mm; sourceTree = "<group>"; };
 		51A555F3128C6C47009ABCEC /* WKContextMenuItem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKContextMenuItem.cpp; sourceTree = "<group>"; };
 		51A555F4128C6C47009ABCEC /* WKContextMenuItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKContextMenuItem.h; sourceTree = "<group>"; };
 		51A55600128C6D92009ABCEC /* WKContextMenuItemTypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKContextMenuItemTypes.h; sourceTree = "<group>"; };
@@ -10977,6 +10980,8 @@
 				9FB5F393169E6A80002C25BF /* WKContextPrivateMac.h */,
 				9FB5F392169E6A80002C25BF /* WKContextPrivateMac.mm */,
 				6EE849C61368D92D0038D481 /* WKInspectorPrivateMac.h */,
+				519DFBE528138756003FF6AD /* WKNotificationPrivateMac.h */,
+				519DFBE628138756003FF6AD /* WKNotificationPrivateMac.mm */,
 				BCE17B7C1381F1170012A641 /* WKPagePrivateMac.h */,
 				BCE17B7B1381F1170012A641 /* WKPagePrivateMac.mm */,
 				5272D4C71E735F0900EB4290 /* WKProtectionSpaceNS.h */,
@@ -14821,6 +14826,7 @@
 				BCE469541214E6CB000B98EB /* WebFormClient.h in Headers */,
 				DDA0A2B527E55E4E005E086E /* WebFormDelegate.h in Headers */,
 				DDA0A30127E55E4E005E086E /* WebFormDelegatePrivate.h in Headers */,
+				519DFBE7281387C1003FF6AD /* WKNotificationPrivateMac.h in Headers */,
 				BCE469561214E6CB000B98EB /* WebFormSubmissionListenerProxy.h in Headers */,
 				E5227D8427A11261008EAB57 /* WebFoundTextRange.h in Headers */,
 				E55CFD4E279D31E5002F1020 /* WebFoundTextRangeController.h in Headers */,

Modified: trunk/Tools/ChangeLog (293295 => 293296)


--- trunk/Tools/ChangeLog	2022-04-23 21:47:00 UTC (rev 293295)
+++ trunk/Tools/ChangeLog	2022-04-23 22:26:57 UTC (rev 293296)
@@ -1,3 +1,23 @@
+2022-04-23  Brady Eidson  <beid...@apple.com>
+    
+        Add WKNotification and WKWebsiteDataStore SPI for handling click/close of persistent notifications
+        https://bugs.webkit.org/show_bug.cgi
+
+        Reviewed by Chris Dumez.
+
+        Teach WKTR to use the new SPI by keeping a set of notifications that are persistent.
+
+        * WebKitTestRunner/WebKitTestRunner.xcodeproj/project.pbxproj:
+
+        * WebKitTestRunner/WebNotificationProvider.cpp:
+        (WTR::WebNotificationProvider::showWebNotification):
+        (WTR::WebNotificationProvider::closeWebNotification):
+        (WTR::WebNotificationProvider::reset):
+        * WebKitTestRunner/WebNotificationProvider.h:
+
+        * WebKitTestRunner/cocoa/WebNotificationProviderCocoa.mm:
+        (WTR::WebNotificationProvider::simulateWebNotificationClickForServiceWorkerNotifications):
+
 2022-04-23  Elliott Williams  <e...@apple.com>
 
         [buildbot] Increase the EWS compile timeout to account for delayed output from clang/XCBuild

Modified: trunk/Tools/WebKitTestRunner/WebKitTestRunner.xcodeproj/project.pbxproj (293295 => 293296)


--- trunk/Tools/WebKitTestRunner/WebKitTestRunner.xcodeproj/project.pbxproj	2022-04-23 21:47:00 UTC (rev 293295)
+++ trunk/Tools/WebKitTestRunner/WebKitTestRunner.xcodeproj/project.pbxproj	2022-04-23 22:26:57 UTC (rev 293296)
@@ -105,6 +105,7 @@
 		4430AE191F82C4FD0099915A /* GeneratedTouchesDebugWindow.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4430AE171F82C4EE0099915A /* GeneratedTouchesDebugWindow.mm */; };
 		51058AD51D678820009A538C /* libWebCoreTestSupport.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 41230E16138C78BF00BCCFCA /* libWebCoreTestSupport.dylib */; };
 		51058AD61D678825009A538C /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0F5169CA1445222D00E0A9D7 /* WebKit.framework */; };
+		51998A082810FBD1009D68EB /* WebNotificationProviderCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51998A072810FBD1009D68EB /* WebNotificationProviderCocoa.mm */; };
 		5641E2D014335E95008307E5 /* JSTextInputController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5641E2CE14335E95008307E5 /* JSTextInputController.cpp */; };
 		5664A49A14326384008881BE /* TextInputController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5664A49814326384008881BE /* TextInputController.cpp */; };
 		5670B8281386FCA5002EB355 /* EventSenderProxy.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5670B8271386FCA5002EB355 /* EventSenderProxy.mm */; };
@@ -330,6 +331,7 @@
 		4430AE181F82C4EF0099915A /* GeneratedTouchesDebugWindow.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedTouchesDebugWindow.h; sourceTree = "<group>"; };
 		49AEEF692407278200C87E4C /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
 		510E2F3827741F8300809333 /* DataFunctions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DataFunctions.h; sourceTree = "<group>"; };
+		51998A072810FBD1009D68EB /* WebNotificationProviderCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebNotificationProviderCocoa.mm; sourceTree = "<group>"; };
 		5322FB4113FDA0CD0041ABCC /* CyclicRedundancyCheck.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CyclicRedundancyCheck.cpp; sourceTree = "<group>"; };
 		5322FB4213FDA0CD0041ABCC /* CyclicRedundancyCheck.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CyclicRedundancyCheck.h; sourceTree = "<group>"; };
 		5322FB4413FDA0EA0041ABCC /* PixelDumpSupport.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PixelDumpSupport.cpp; sourceTree = "<group>"; };
@@ -645,6 +647,7 @@
 				41C5378D21F1333C008B1FAD /* TestWebsiteDataStoreDelegate.mm */,
 				2D058E0822E2EE2200E4C145 /* UIScriptControllerCocoa.h */,
 				F46240AF2170128300917B16 /* UIScriptControllerCocoa.mm */,
+				51998A072810FBD1009D68EB /* WebNotificationProviderCocoa.mm */,
 			);
 			path = cocoa;
 			sourceTree = "<group>";
@@ -1281,6 +1284,7 @@
 				41C5378E21F13414008B1FAD /* TestWebsiteDataStoreDelegate.mm in Sources */,
 				0F18E6E51D6B9B9E0027E547 /* UIScriptContext.cpp in Sources */,
 				F46240B1217013E500917B16 /* UIScriptControllerCocoa.mm in Sources */,
+				51998A082810FBD1009D68EB /* WebNotificationProviderCocoa.mm in Sources */,
 				277CCEDD250F300A0050C572 /* UIScriptControllerCommon.cpp in Sources */,
 				0F73B55C1BA89042004B3EF4 /* UIScriptControllerIOS.mm in Sources */,
 				0F18E6E61D6B9BA20027E547 /* UIScriptControllerShared.cpp in Sources */,

Modified: trunk/Tools/WebKitTestRunner/WebNotificationProvider.cpp (293295 => 293296)


--- trunk/Tools/WebKitTestRunner/WebNotificationProvider.cpp	2022-04-23 21:47:00 UTC (rev 293295)
+++ trunk/Tools/WebKitTestRunner/WebNotificationProvider.cpp	2022-04-23 22:26:57 UTC (rev 293296)
@@ -98,6 +98,9 @@
 
 void WebNotificationProvider::showWebNotification(WKPageRef page, WKNotificationRef notification)
 {
+    if (WKNotificationGetIsPersistent(notification))
+        m_knownPersistentNotifications.add(notification);
+
     auto notificationManager = notificationManagerForPage(page);
     ASSERT(m_knownManagers.contains(notificationManager));
 
@@ -112,6 +115,9 @@
 
 void WebNotificationProvider::closeWebNotification(WKNotificationRef notification)
 {
+    if (WKNotificationGetIsPersistent(notification))
+        m_knownPersistentNotifications.remove(notification);
+
     auto identifier = adoptWK(WKNotificationCopyCoreIDForTesting(notification));
 
     auto notificationManager = m_owningManager.take(dataToUUID(identifier.get()));
@@ -171,6 +177,7 @@
     WKNotificationManagerProviderDidClickNotification_b(m_owningManager.get(identifier), notificationID);
 }
 
+#if !PLATFORM(COCOA)
 void WebNotificationProvider::simulateWebNotificationClickForServiceWorkerNotifications()
 {
     auto sharedManager = WKNotificationManagerGetSharedServiceWorkerNotificationManager();
@@ -180,6 +187,7 @@
         WKNotificationManagerProviderDidClickNotification_b(sharedManager, uuidToData(iterator.key).get());
     }
 }
+#endif
 
 void WebNotificationProvider::reset()
 {
@@ -189,6 +197,7 @@
         WKNotificationManagerProviderDidCloseNotifications(iterator.value, array.get());
     }
 
+    m_knownPersistentNotifications.clear();
     m_owningManager.clear();
     m_permissions = adoptWK(WKMutableDictionaryCreate());
 }

Modified: trunk/Tools/WebKitTestRunner/WebNotificationProvider.h (293295 => 293296)


--- trunk/Tools/WebKitTestRunner/WebNotificationProvider.h	2022-04-23 21:47:00 UTC (rev 293295)
+++ trunk/Tools/WebKitTestRunner/WebNotificationProvider.h	2022-04-23 22:26:57 UTC (rev 293296)
@@ -59,6 +59,8 @@
     HashSet<WKRetainPtr<WKNotificationManagerRef>> m_knownManagers;
     HashMap<UUID, WKNotificationManagerRef> m_owningManager;
     WKRetainPtr<WKMutableDictionaryRef> m_permissions;
+
+    HashSet<WKRetainPtr<WKNotificationRef>> m_knownPersistentNotifications;
 };
 
 }

Copied: trunk/Tools/WebKitTestRunner/cocoa/WebNotificationProviderCocoa.mm (from rev 293295, trunk/Source/WebKit/UIProcess/API/Cocoa/_WKDownloadInternal.h) (0 => 293296)


--- trunk/Tools/WebKitTestRunner/cocoa/WebNotificationProviderCocoa.mm	                        (rev 0)
+++ trunk/Tools/WebKitTestRunner/cocoa/WebNotificationProviderCocoa.mm	2022-04-23 22:26:57 UTC (rev 293296)
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2022 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "WebNotificationProvider.h"
+
+#import "TestController.h"
+#import <WebKit/WKNotificationPrivateMac.h>
+#import <WebKit/WKWebsiteDataStorePrivate.h>
+#import <wtf/RetainPtr.h>
+
+namespace WTR {
+
+void WebNotificationProvider::simulateWebNotificationClickForServiceWorkerNotifications()
+{
+    for (auto& notification : m_knownPersistentNotifications) {
+        auto dictionaryRepresentation = adoptNS(WKNotificationCopyDictionaryRepresentation(notification.get()));
+        [(__bridge WKWebsiteDataStore *)TestController::defaultWebsiteDataStore() _processPersistentNotificationClick:dictionaryRepresentation.get() completionHandler:^(bool) { }];
+    }
+}
+
+} // namespace WTR
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to