⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 293296 in webkit


Ignore:
Timestamp:
Apr 23, 2022, 3:26:57 PM (4 years ago)
Author:
beidson@apple.com
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):

Location:
trunk
Files:
1 added
30 edited
3 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r293295 r293296  
     12022-04-23  Brady Eidson  <beidson@apple.com>
     2
     3        Add WKNotification and WKWebsiteDataStore SPI for handling click/close of persistent notifications
     4        https://bugs.webkit.org/show_bug.cgi
     5
     6        Reviewed by Chris Dumez.
     7
     8        Covered by existing tests with WKTR changes.
     9
     10        In Cocoa, expose the dictionary representation of a notification as an NSDictionary,
     11        as it is meant to be used as an NSUserNotification userInfo value.
     12
     13        * Modules/notifications/NotificationData.h:
     14        * Modules/notifications/NotificationDataCocoa.mm: Added.
     15        (WebCore::NotificationData::fromDictionary):
     16        (WebCore::NotificationData::dictionaryRepresentation const):
     17
     18        * SourcesCocoa.txt:
     19        * WebCore.xcodeproj/project.pbxproj:
     20
     21        * workers/service/server/SWServer.cpp:
     22        (WebCore::SWServer::processNotificationEvent):
     23        * workers/service/server/SWServer.h:
     24
    1252022-04-23  Justin Michaud  <justin_michaud@apple.com>
    226
  • trunk/Source/WebCore/Modules/notifications/NotificationData.h

    r292218 r293296  
    3333#include <wtf/text/WTFString.h>
    3434
     35OBJC_CLASS NSDictionary;
     36
    3537namespace WebCore {
    3638
     
    4345    NotificationData isolatedCopy() const &;
    4446    NotificationData isolatedCopy() &&;
     47
     48#if PLATFORM(COCOA)
     49    WEBCORE_EXPORT static std::optional<NotificationData> fromDictionary(NSDictionary *dictionaryRepresentation);
     50    WEBCORE_EXPORT NSDictionary *dictionaryRepresentation() const;
     51#endif
    4552
    4653    String title;
  • trunk/Source/WebCore/SourcesCocoa.txt

    r292914 r293296  
    115115Modules/model-element/scenekit/SceneKitModelLoaderUSD.mm
    116116Modules/model-element/scenekit/SceneKitModelPlayer.mm
     117Modules/notifications/NotificationDataCocoa.mm
    117118Modules/push-api/cocoa/PushCryptoCocoa.cpp
    118119Modules/plugins/YouTubePluginReplacement.cpp
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r293285 r293296  
    99109910                518F97001BE94C5B0023187C /* MemoryIndex.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MemoryIndex.cpp; sourceTree = "<group>"; };
    99119911                518F97011BE94C5B0023187C /* MemoryIndex.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MemoryIndex.h; sourceTree = "<group>"; };
     9912                5194C26827FFD7C200AEF3CF /* NotificationDataCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = NotificationDataCocoa.mm; sourceTree = "<group>"; };
    99129913                519755F71BFD7DBC003DE980 /* MemoryIndexCursor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MemoryIndexCursor.cpp; sourceTree = "<group>"; };
    99139914                519755F81BFD7DBC003DE980 /* MemoryIndexCursor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MemoryIndexCursor.h; sourceTree = "<group>"; };
     
    2100321004                                51123E2E27693C3300F9D41B /* NotificationData.cpp */,
    2100421005                                51123E2C27693C3200F9D41B /* NotificationData.h */,
     21006                                5194C26827FFD7C200AEF3CF /* NotificationDataCocoa.mm */,
    2100521007                                7CC2DE021ECA04A50027B774 /* NotificationDirection.h */,
    2100621008                                51E3AF0C276B0602009B429D /* NotificationDirection.idl */,
  • trunk/Source/WebCore/workers/service/server/SWServer.cpp

    r293195 r293296  
    13661366}
    13671367
    1368 void SWServer::processNotificationEvent(NotificationData&& data, NotificationEventType type)
    1369 {
    1370     whenImportIsCompletedIfNeeded([this, weakThis = WeakPtr { *this }, data = WTFMove(data), type]() mutable {
    1371         if (!weakThis)
    1372             return;
     1368void SWServer::processNotificationEvent(NotificationData&& data, NotificationEventType type, CompletionHandler<void(bool)>&& callback)
     1369{
     1370    whenImportIsCompletedIfNeeded([this, weakThis = WeakPtr { *this }, data = WTFMove(data), type, callback = WTFMove(callback)]() mutable {
     1371        if (!weakThis) {
     1372            callback(false);
     1373            return;
     1374        }
    13731375
    13741376        auto origin = SecurityOriginData::fromURL(data.serviceWorkerRegistrationURL);
    13751377        ServiceWorkerRegistrationKey registrationKey { WTFMove(origin), URL { data.serviceWorkerRegistrationURL } };
    13761378        auto registration = m_scopeToRegistrationMap.get(registrationKey);
    1377         if (!registration)
    1378             return;
     1379        if (!registration) {
     1380            RELEASE_LOG_ERROR(Push, "Cannot process notification event: Failed to find SW registration for scope %" PRIVATE_LOG_STRING, registrationKey.scope().string().utf8().data());
     1381            callback(true);
     1382            return;
     1383        }
    13791384
    13801385        auto* worker = registration->activeWorker();
    1381         if (!worker)
    1382             return;
    1383 
    1384         fireFunctionalEvent(*registration, [worker = Ref { *worker }, weakThis = WTFMove(weakThis), data = WTFMove(data), type](auto&& connectionOrStatus) mutable {
    1385             if (!connectionOrStatus.has_value())
     1386        if (!worker) {
     1387            RELEASE_LOG_ERROR(Push, "Cannot process notification event: No active worker for scope %" PRIVATE_LOG_STRING, registrationKey.scope().string().utf8().data());
     1388            callback(true);
     1389            return;
     1390        }
     1391
     1392        fireFunctionalEvent(*registration, [worker = Ref { *worker }, weakThis = WTFMove(weakThis), data = WTFMove(data), type, callback = WTFMove(callback)](auto&& connectionOrStatus) mutable {
     1393            if (!connectionOrStatus.has_value()) {
     1394                callback(connectionOrStatus.error() == ShouldSkipEvent::Yes);
    13861395                return;
     1396            }
    13871397
    13881398            auto serviceWorkerIdentifier = worker->identifier();
     
    13941404            });
    13951405            terminateWorkerTimer->startOneShot(weakThis && weakThis->m_isProcessTerminationDelayEnabled ? defaultTerminationDelay : defaultFunctionalEventDuration);
    1396             connectionOrStatus.value()->fireNotificationEvent(serviceWorkerIdentifier, data, type, [terminateWorkerTimer = WTFMove(terminateWorkerTimer), worker = WTFMove(worker)](bool succeeded) mutable {
     1406            connectionOrStatus.value()->fireNotificationEvent(serviceWorkerIdentifier, data, type, [callback = WTFMove(callback), terminateWorkerTimer = WTFMove(terminateWorkerTimer), worker = WTFMove(worker)] (bool succeeded) mutable {
    13971407                RELEASE_LOG_ERROR_IF(!succeeded, ServiceWorker, "Service Worker notification event handler did not succeed");
     1408
    13981409                // FIXME: if succeeded is false, should we implement a default action like opening a new page?
    13991410                if (terminateWorkerTimer->isActive()) {
     
    14011412                    terminateWorkerTimer->stop();
    14021413                }
     1414
     1415                callback(succeeded);
    14031416            });
    14041417        });
  • trunk/Source/WebCore/workers/service/server/SWServer.h

    r293195 r293296  
    231231
    232232    WEBCORE_EXPORT void processPushMessage(std::optional<Vector<uint8_t>>&&, URL&&, CompletionHandler<void(bool)>&&);
    233     WEBCORE_EXPORT void processNotificationEvent(NotificationData&&, NotificationEventType);
     233    WEBCORE_EXPORT void processNotificationEvent(NotificationData&&, NotificationEventType, CompletionHandler<void(bool)>&&);
    234234
    235235    enum class ShouldSkipEvent : bool { No, Yes };
  • trunk/Source/WebKit/ChangeLog

    r293285 r293296  
     12022-04-23  Brady Eidson  <beidson@apple.com>
     2
     3        Add WKNotification and WKWebsiteDataStore SPI for handling click/close of persistent notifications
     4        https://bugs.webkit.org/show_bug.cgi
     5
     6        Reviewed by Chris Dumez.
     7
     8        For notifications that are persistent, add WKWebsiteDataStore SPI to handle click/close operations,
     9        as the WKNotificationManager's runtime record of such notifications might be gone.
     10       
     11        WebKitTestRunner exercises this new SPI in existing tests.
     12       
     13        * NetworkProcess/NetworkProcess.cpp:
     14        (WebKit::NetworkProcess::processNotificationEvent):
     15        * NetworkProcess/NetworkProcess.h:
     16        * NetworkProcess/NetworkProcess.messages.in:
     17       
     18        * SourcesCocoa.txt:
     19       
     20        * UIProcess/API/C/WKNotification.cpp:
     21        (WKNotificationGetIsPersistent):
     22        * UIProcess/API/C/WKNotification.h:
     23       
     24        * UIProcess/API/C/mac/WKNotificationPrivateMac.h: Copied from Source/WebKit/UIProcess/API/Cocoa/_WKDownloadInternal.h.
     25        * UIProcess/API/C/mac/WKNotificationPrivateMac.mm: Copied from Source/WebKit/UIProcess/API/Cocoa/_WKDownloadInternal.h.
     26        (WKNotificationCopyDictionaryRepresentation):
     27       
     28        * UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
     29        (-[WKWebsiteDataStore _processPersistentNotificationClick:completionHandler:]):
     30        (-[WKWebsiteDataStore _processPersistentNotificationClose:completionHandler:]):
     31        * UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h:
     32       
     33        * UIProcess/API/Cocoa/_WKDownload.mm:
     34        * UIProcess/API/Cocoa/_WKDownloadInternal.h:
     35       
     36        * UIProcess/Network/NetworkProcessProxy.cpp:
     37        (WebKit::NetworkProcessProxy::processNotificationEvent):
     38        * UIProcess/Network/NetworkProcessProxy.h:
     39       
     40        * UIProcess/Notifications/WebNotification.cpp:
     41        * UIProcess/Notifications/WebNotification.h:
     42        * UIProcess/Notifications/WebNotificationManagerProxy.cpp:
     43        (WebKit::dispatchDidClickNotification):
     44        (WebKit::WebNotificationManagerProxy::providerDidCloseNotifications):
     45       
     46        * WebKit.xcodeproj/project.pbxproj:
     47
    1482022-04-22  Chris Dumez  <cdumez@apple.com>
    249
  • trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp

    r293285 r293296  
    23022302
    23032303#if ENABLE(SERVICE_WORKER)
    2304 void NetworkProcess::processNotificationEvent(NotificationData&& data, NotificationEventType eventType)
     2304void NetworkProcess::processNotificationEvent(NotificationData&& data, NotificationEventType eventType, CompletionHandler<void(bool)>&& callback)
    23052305{
    23062306    if (auto* session = networkSession(data.sourceSession))
    2307         session->ensureSWServer().processNotificationEvent(WTFMove(data), eventType);
     2307        session->ensureSWServer().processNotificationEvent(WTFMove(data), eventType, WTFMove(callback));
    23082308}
    23092309
  • trunk/Source/WebKit/NetworkProcess/NetworkProcess.h

    r292158 r293296  
    378378    void getPendingPushMessages(PAL::SessionID, CompletionHandler<void(const Vector<WebPushMessage>&)>&&);
    379379    void processPushMessage(PAL::SessionID, WebPushMessage&&, WebCore::PushPermissionState, CompletionHandler<void(bool)>&&);
    380     void processNotificationEvent(WebCore::NotificationData&&, WebCore::NotificationEventType);
     380    void processNotificationEvent(WebCore::NotificationData&&, WebCore::NotificationEventType, CompletionHandler<void(bool)>&&);
    381381#endif
    382382
  • trunk/Source/WebKit/NetworkProcess/NetworkProcess.messages.in

    r292624 r293296  
    211211    GetPendingPushMessages(PAL::SessionID sessionID) -> (Vector<WebKit::WebPushMessage> messages)
    212212    ProcessPushMessage(PAL::SessionID sessionID, struct WebKit::WebPushMessage pushMessage, enum:uint8_t WebCore::PushPermissionState pushPermissionState) -> (bool didSucceed)
    213     ProcessNotificationEvent(struct WebCore::NotificationData data, enum:bool WebCore::NotificationEventType eventType)
     213    ProcessNotificationEvent(struct WebCore::NotificationData data, enum:bool WebCore::NotificationEventType eventType) -> (bool didSucceed)
    214214#endif
    215215    DeletePushAndNotificationRegistration(PAL::SessionID sessionID, struct WebCore::SecurityOriginData origin) -> (String errorMessage)
  • trunk/Source/WebKit/Shared/ModelIdentifier.h

    r291019 r293296  
    2828#import <wtf/text/WTFString.h>
    2929
     30#if ENABLE(ARKIT_INLINE_PREVIEW_IOS)
     31#import <WebCore/GraphicsLayer.h>
     32#endif
     33
    3034namespace WebKit {
    3135
    3236#if ENABLE(ARKIT_INLINE_PREVIEW)
    33 
    34 #if ENABLE(ARKIT_INLINE_PREVIEW_IOS)
    35 #import <WebCore/GraphicsLayer.h>
    36 #endif
    3737
    3838struct ModelIdentifier {
  • trunk/Source/WebKit/SourcesCocoa.txt

    r293266 r293296  
    268268
    269269UIProcess/API/C/mac/WKContextPrivateMac.mm
     270UIProcess/API/C/mac/WKNotificationPrivateMac.mm
    270271UIProcess/API/C/mac/WKPagePrivateMac.mm
    271272UIProcess/API/C/mac/WKProtectionSpaceNS.mm
  • trunk/Source/WebKit/UIProcess/API/C/WKNotification.cpp

    r287412 r293296  
    9696    return WKDataCreate(span.data(), span.size());
    9797}
     98
     99bool WKNotificationGetIsPersistent(WKNotificationRef notification)
     100{
     101    return toImpl(notification)->isPersistentNotification();
     102}
  • trunk/Source/WebKit/UIProcess/API/C/WKNotification.h

    r287412 r293296  
    4444WK_EXPORT uint64_t WKNotificationGetID(WKNotificationRef notification);
    4545WK_EXPORT WKDataRef WKNotificationCopyCoreIDForTesting(WKNotificationRef notification);
     46WK_EXPORT bool WKNotificationGetIsPersistent(WKNotificationRef notification);
    4647
    4748#ifdef __cplusplus
  • trunk/Source/WebKit/UIProcess/API/C/mac/WKNotificationPrivateMac.h

    r293295 r293296  
    11/*
    2  * Copyright (C) 2014 Apple Inc. All rights reserved.
     2 * Copyright (C) 2022 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2424 */
    2525
    26 #import "_WKDownload.h"
     26#ifndef WKNotificationPrivateMac_h
     27#define WKNotificationPrivateMac_h
    2728
    28 #import <wtf/RetainPtr.h>
     29#include <WebKit/WKBase.h>
    2930
    30 @class WKDownload;
     31#ifdef __cplusplus
     32extern "C" {
     33#endif
    3134
    32 @interface _WKDownload () <WKObject> {
    33 @package
    34     RetainPtr<WKDownload> _download;
     35#ifdef __OBJC__
     36
     37@class NSDictionary;
     38
     39WK_EXPORT NSDictionary *WKNotificationCopyDictionaryRepresentation(WKNotificationRef notification) NS_RETURNS_RETAINED;
     40
     41#endif // __OBJC__
     42
     43#ifdef __cplusplus
    3544}
    36 @end
     45#endif
     46
     47#endif /* WKNotificationPrivateMac_h */
  • trunk/Source/WebKit/UIProcess/API/C/mac/WKNotificationPrivateMac.mm

    r293295 r293296  
    11/*
    2  * Copyright (C) 2014 Apple Inc. All rights reserved.
     2 * Copyright (C) 2022 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2424 */
    2525
    26 #import "_WKDownload.h"
     26#import "config.h"
     27#import "WKNotificationPrivateMac.h"
    2728
    28 #import <wtf/RetainPtr.h>
     29#import "WebNotification.h"
     30#import <WebCore/NotificationData.h>
    2931
    30 @class WKDownload;
    31 
    32 @interface _WKDownload () <WKObject> {
    33 @package
    34     RetainPtr<WKDownload> _download;
     32NSDictionary *WKNotificationCopyDictionaryRepresentation(WKNotificationRef notification)
     33{
     34    return [WebKit::toImpl(notification)->data().dictionaryRepresentation() retain];
    3535}
    36 @end
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm

    r292793 r293296  
    3939#import "WKWebViewInternal.h"
    4040#import "WKWebsiteDataRecordInternal.h"
     41#import "WebNotification.h"
    4142#import "WebNotificationManagerProxy.h"
    4243#import "WebPageProxy.h"
     
    5859class WebsiteDataStoreClient final : public WebKit::WebsiteDataStoreClient {
    5960public:
    60     explicit WebsiteDataStoreClient(WKWebsiteDataStore *dataStore, id<_WKWebsiteDataStoreDelegate> delegate)
     61    WebsiteDataStoreClient(WKWebsiteDataStore *dataStore, id<_WKWebsiteDataStoreDelegate> delegate)
    6162        : m_dataStore(dataStore)
    6263        , m_delegate(delegate)
     
    832833}
    833834
     835-(void)_processPersistentNotificationClick:(NSDictionary *)notificationDictionaryRepresentation completionHandler:(void(^)(bool))completionHandler
     836{
     837#if ENABLE(SERVICE_WORKER)
     838    auto notificationData = WebCore::NotificationData::fromDictionary(notificationDictionaryRepresentation);
     839    if (!notificationData) {
     840        RELEASE_LOG_ERROR(Push, "Asked to handle a persistent notification click with an invalid notification dictionary representation");
     841        completionHandler(false);
     842        return;
     843    }
     844
     845    RELEASE_LOG(Push, "Sending persistent notification click from origin %" PRIVATE_LOG_STRING " to network process to handle", notificationData->originString.utf8().data());
     846
     847    notificationData->sourceSession = _websiteDataStore->sessionID();
     848    _websiteDataStore->networkProcess().processNotificationEvent(*notificationData, WebCore::NotificationEventType::Click, [completionHandler = makeBlockPtr(completionHandler)] (bool wasProcessed) {
     849        RELEASE_LOG(Push, "Notification click event processing complete. Callback result: %d", wasProcessed);
     850        completionHandler(wasProcessed);
     851    });
     852#endif
     853}
     854
     855-(void)_processPersistentNotificationClose:(NSDictionary *)notificationDictionaryRepresentation completionHandler:(void(^)(bool))completionHandler
     856{
     857#if ENABLE(SERVICE_WORKER)
     858    auto notificationData = WebCore::NotificationData::fromDictionary(notificationDictionaryRepresentation);
     859    if (!notificationData) {
     860        RELEASE_LOG_ERROR(Push, "Asked to handle a persistent notification click with an invalid notification dictionary representation");
     861        completionHandler(false);
     862        return;
     863    }
     864
     865    RELEASE_LOG(Push, "Sending persistent notification close from origin %" PRIVATE_LOG_STRING " to network process to handle", notificationData->originString.utf8().data());
     866
     867    _websiteDataStore->networkProcess().processNotificationEvent(*notificationData, WebCore::NotificationEventType::Close, [completionHandler = makeBlockPtr(completionHandler)] (bool wasProcessed) {
     868        RELEASE_LOG(Push, "Notification close event processing complete. Callback result: %d", wasProcessed);
     869        completionHandler(wasProcessed);
     870    });
     871#endif
     872}
     873
    834874-(void)_deletePushAndNotificationRegistration:(WKSecurityOrigin *)securityOrigin completionHandler:(void(^)(NSError *))completionHandler
    835875{
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h

    r292126 r293296  
    112112-(void)_getPendingPushMessages:(void(^)(NSArray<NSDictionary *> *))completionHandler WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
    113113-(void)_processPushMessage:(NSDictionary *)pushMessage completionHandler:(void(^)(bool))completionHandler WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
     114-(void)_processPersistentNotificationClick:(NSDictionary *)notificationDictionaryRepresentation completionHandler:(void(^)(bool))completionHandler WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
     115-(void)_processPersistentNotificationClose:(NSDictionary *)notificationDictionaryRepresentation completionHandler:(void(^)(bool))completionHandler WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
    114116-(void)_deletePushAndNotificationRegistration:(WKSecurityOrigin *)securityOrigin completionHandler:(void(^)(NSError *))completionHandler WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
    115117-(void)_getOriginsWithPushAndNotificationPermissions:(void(^)(NSSet<WKSecurityOrigin *> *))completionHandler WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
  • trunk/Source/WebKit/UIProcess/API/Cocoa/_WKDownload.mm

    r282882 r293296  
    3434#import "WKWebViewInternal.h"
    3535#import <wtf/WeakObjCPtr.h>
     36#import <wtf/cocoa/VectorCocoa.h>
     37
    3638
    3739ALLOW_DEPRECATED_DECLARATIONS_BEGIN
  • trunk/Source/WebKit/UIProcess/API/Cocoa/_WKDownloadInternal.h

    r270638 r293296  
    2626#import "_WKDownload.h"
    2727
     28#import "WKObject.h"
    2829#import <wtf/RetainPtr.h>
    2930
  • trunk/Source/WebKit/UIProcess/Cocoa/ModelElementControllerCocoa.mm

    r293063 r293296  
    143143}
    144144
    145 #endif
     145#endif // ENABLE(ARKIT_INLINE_PREVIEW_IOS)
    146146
    147147#if ENABLE(ARKIT_INLINE_PREVIEW_MAC)
     
    313313    }));
    314314}
    315 #endif
     315#endif // ENABLE(ARKIT_INLINE_PREVIEW_MAC)
    316316
    317317#if ENABLE(ARKIT_INLINE_PREVIEW)
     
    546546}
    547547
    548 #endif
    549 
    550 }
    551 
    552 #endif
     548#endif // ENABLE(ARKIT_INLINE_PREVIEW)
     549
     550} // namespace WebKit
     551
     552#endif // ENABLE(ARKIT_INLINE_PREVIEW)
  • trunk/Source/WebKit/UIProcess/ModelElementController.h

    r293063 r293296  
    100100};
    101101
    102 }
     102} // namespace WebKit
    103103
    104104#endif
  • trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp

    r293017 r293296  
    17801780}
    17811781
    1782 void NetworkProcessProxy::processNotificationEvent(const NotificationData& data, NotificationEventType eventType)
    1783 {
    1784     send(Messages::NetworkProcess::ProcessNotificationEvent { data, eventType }, 0);
     1782void NetworkProcessProxy::processNotificationEvent(const NotificationData& data, NotificationEventType eventType, CompletionHandler<void(bool wasProcessed)>&& callback)
     1783{
     1784    RELEASE_ASSERT(!!callback);
     1785    sendWithAsyncReply(Messages::NetworkProcess::ProcessNotificationEvent { data, eventType }, WTFMove(callback));
    17851786}
    17861787#endif // ENABLE(SERVICE_WORKER)
  • trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h

    r293017 r293296  
    287287    void getPendingPushMessages(PAL::SessionID, CompletionHandler<void(const Vector<WebPushMessage>&)>&&);
    288288    void processPushMessage(PAL::SessionID, const WebPushMessage&, CompletionHandler<void(bool wasProcessed)>&&);
    289     void processNotificationEvent(const WebCore::NotificationData&, WebCore::NotificationEventType);
     289    void processNotificationEvent(const WebCore::NotificationData&, WebCore::NotificationEventType, CompletionHandler<void(bool wasProcessed)>&&);
    290290#endif
    291291
  • trunk/Source/WebKit/UIProcess/Notifications/WebNotification.cpp

    r292110 r293296  
    2727#include "WebNotification.h"
    2828
     29#include "APIDictionary.h"
    2930#include <WebCore/NotificationData.h>
    3031
  • trunk/Source/WebKit/UIProcess/Notifications/WebNotification.h

    r292110 r293296  
    2626#pragma once
    2727
    28 #include "APIObject.h"
     28#include "APIDictionary.h"
    2929#include "APISecurityOrigin.h"
    3030#include "Connection.h"
  • trunk/Source/WebKit/UIProcess/Notifications/WebNotificationManagerProxy.cpp

    r292771 r293296  
    195195    if (notification->isPersistentNotification()) {
    196196        if (auto* dataStore = WebsiteDataStore::existingDataStoreForSessionID(notification->sessionID()))
    197             dataStore->networkProcess().processNotificationEvent(notification->data(), NotificationEventType::Click);
     197            dataStore->networkProcess().processNotificationEvent(notification->data(), NotificationEventType::Click, [](bool) { });
    198198        else
    199199            RELEASE_LOG_ERROR(Notifications, "WebsiteDataStore not found from sessionID %" PRIu64 ", dropping notification click", notification->sessionID().toUInt64());
     
    258258        if (notification->isPersistentNotification()) {
    259259            if (auto* dataStore = WebsiteDataStore::existingDataStoreForSessionID(notification->sessionID()))
    260                 dataStore->networkProcess().processNotificationEvent(notification->data(), NotificationEventType::Close);
     260                dataStore->networkProcess().processNotificationEvent(notification->data(), NotificationEventType::Close, [](bool) { });
    261261            else
    262262                RELEASE_LOG_ERROR(Notifications, "WebsiteDataStore not found from sessionID %" PRIu64 ", dropping notification close", notification->sessionID().toUInt64());
  • trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj

    r293266 r293296  
    10381038                518E8EF916B2091C00E91429 /* AuthenticationManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 518E8EF416B2091C00E91429 /* AuthenticationManager.h */; };
    10391039                51933DEF1965EB31008AC3EA /* MenuUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 51933DEB1965EB24008AC3EA /* MenuUtilities.h */; };
     1040                519DFBE7281387C1003FF6AD /* WKNotificationPrivateMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 519DFBE528138756003FF6AD /* WKNotificationPrivateMac.h */; settings = {ATTRIBUTES = (Private, ); }; };
    10401041                51A555F6128C6C47009ABCEC /* WKContextMenuItem.h in Headers */ = {isa = PBXBuildFile; fileRef = 51A555F4128C6C47009ABCEC /* WKContextMenuItem.h */; settings = {ATTRIBUTES = (Private, ); }; };
    10411042                51A55601128C6D92009ABCEC /* WKContextMenuItemTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 51A55600128C6D92009ABCEC /* WKContextMenuItemTypes.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    48574858                51933DEC1965EB24008AC3EA /* MenuUtilities.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MenuUtilities.mm; sourceTree = "<group>"; };
    48584859                5194B3861F192FB900FA4708 /* CookieStorageUtilsCF.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CookieStorageUtilsCF.h; sourceTree = "<group>"; };
     4860                519DFBE528138756003FF6AD /* WKNotificationPrivateMac.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = WKNotificationPrivateMac.h; path = mac/WKNotificationPrivateMac.h; sourceTree = "<group>"; };
     4861                519DFBE628138756003FF6AD /* WKNotificationPrivateMac.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = WKNotificationPrivateMac.mm; path = mac/WKNotificationPrivateMac.mm; sourceTree = "<group>"; };
    48594862                51A555F3128C6C47009ABCEC /* WKContextMenuItem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKContextMenuItem.cpp; sourceTree = "<group>"; };
    48604863                51A555F4128C6C47009ABCEC /* WKContextMenuItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKContextMenuItem.h; sourceTree = "<group>"; };
     
    1097810981                                9FB5F392169E6A80002C25BF /* WKContextPrivateMac.mm */,
    1097910982                                6EE849C61368D92D0038D481 /* WKInspectorPrivateMac.h */,
     10983                                519DFBE528138756003FF6AD /* WKNotificationPrivateMac.h */,
     10984                                519DFBE628138756003FF6AD /* WKNotificationPrivateMac.mm */,
    1098010985                                BCE17B7C1381F1170012A641 /* WKPagePrivateMac.h */,
    1098110986                                BCE17B7B1381F1170012A641 /* WKPagePrivateMac.mm */,
     
    1482214827                                DDA0A2B527E55E4E005E086E /* WebFormDelegate.h in Headers */,
    1482314828                                DDA0A30127E55E4E005E086E /* WebFormDelegatePrivate.h in Headers */,
     14829                                519DFBE7281387C1003FF6AD /* WKNotificationPrivateMac.h in Headers */,
    1482414830                                BCE469561214E6CB000B98EB /* WebFormSubmissionListenerProxy.h in Headers */,
    1482514831                                E5227D8427A11261008EAB57 /* WebFoundTextRange.h in Headers */,
  • trunk/Tools/ChangeLog

    r293294 r293296  
     12022-04-23  Brady Eidson  <beidson@apple.com>
     2   
     3        Add WKNotification and WKWebsiteDataStore SPI for handling click/close of persistent notifications
     4        https://bugs.webkit.org/show_bug.cgi
     5
     6        Reviewed by Chris Dumez.
     7
     8        Teach WKTR to use the new SPI by keeping a set of notifications that are persistent.
     9
     10        * WebKitTestRunner/WebKitTestRunner.xcodeproj/project.pbxproj:
     11
     12        * WebKitTestRunner/WebNotificationProvider.cpp:
     13        (WTR::WebNotificationProvider::showWebNotification):
     14        (WTR::WebNotificationProvider::closeWebNotification):
     15        (WTR::WebNotificationProvider::reset):
     16        * WebKitTestRunner/WebNotificationProvider.h:
     17
     18        * WebKitTestRunner/cocoa/WebNotificationProviderCocoa.mm:
     19        (WTR::WebNotificationProvider::simulateWebNotificationClickForServiceWorkerNotifications):
     20
    1212022-04-23  Elliott Williams  <emw@apple.com>
    222
  • trunk/Tools/WebKitTestRunner/WebKitTestRunner.xcodeproj/project.pbxproj

    r292959 r293296  
    106106                51058AD51D678820009A538C /* libWebCoreTestSupport.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 41230E16138C78BF00BCCFCA /* libWebCoreTestSupport.dylib */; };
    107107                51058AD61D678825009A538C /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0F5169CA1445222D00E0A9D7 /* WebKit.framework */; };
     108                51998A082810FBD1009D68EB /* WebNotificationProviderCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51998A072810FBD1009D68EB /* WebNotificationProviderCocoa.mm */; };
    108109                5641E2D014335E95008307E5 /* JSTextInputController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5641E2CE14335E95008307E5 /* JSTextInputController.cpp */; };
    109110                5664A49A14326384008881BE /* TextInputController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5664A49814326384008881BE /* TextInputController.cpp */; };
     
    331332                49AEEF692407278200C87E4C /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
    332333                510E2F3827741F8300809333 /* DataFunctions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DataFunctions.h; sourceTree = "<group>"; };
     334                51998A072810FBD1009D68EB /* WebNotificationProviderCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebNotificationProviderCocoa.mm; sourceTree = "<group>"; };
    333335                5322FB4113FDA0CD0041ABCC /* CyclicRedundancyCheck.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CyclicRedundancyCheck.cpp; sourceTree = "<group>"; };
    334336                5322FB4213FDA0CD0041ABCC /* CyclicRedundancyCheck.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CyclicRedundancyCheck.h; sourceTree = "<group>"; };
     
    646648                                2D058E0822E2EE2200E4C145 /* UIScriptControllerCocoa.h */,
    647649                                F46240AF2170128300917B16 /* UIScriptControllerCocoa.mm */,
     650                                51998A072810FBD1009D68EB /* WebNotificationProviderCocoa.mm */,
    648651                        );
    649652                        path = cocoa;
     
    12821285                                0F18E6E51D6B9B9E0027E547 /* UIScriptContext.cpp in Sources */,
    12831286                                F46240B1217013E500917B16 /* UIScriptControllerCocoa.mm in Sources */,
     1287                                51998A082810FBD1009D68EB /* WebNotificationProviderCocoa.mm in Sources */,
    12841288                                277CCEDD250F300A0050C572 /* UIScriptControllerCommon.cpp in Sources */,
    12851289                                0F73B55C1BA89042004B3EF4 /* UIScriptControllerIOS.mm in Sources */,
  • trunk/Tools/WebKitTestRunner/WebNotificationProvider.cpp

    r289721 r293296  
    9999void WebNotificationProvider::showWebNotification(WKPageRef page, WKNotificationRef notification)
    100100{
     101    if (WKNotificationGetIsPersistent(notification))
     102        m_knownPersistentNotifications.add(notification);
     103
    101104    auto notificationManager = notificationManagerForPage(page);
    102105    ASSERT(m_knownManagers.contains(notificationManager));
     
    113116void WebNotificationProvider::closeWebNotification(WKNotificationRef notification)
    114117{
     118    if (WKNotificationGetIsPersistent(notification))
     119        m_knownPersistentNotifications.remove(notification);
     120
    115121    auto identifier = adoptWK(WKNotificationCopyCoreIDForTesting(notification));
    116122
     
    172178}
    173179
     180#if !PLATFORM(COCOA)
    174181void WebNotificationProvider::simulateWebNotificationClickForServiceWorkerNotifications()
    175182{
     
    181188    }
    182189}
     190#endif
    183191
    184192void WebNotificationProvider::reset()
     
    190198    }
    191199
     200    m_knownPersistentNotifications.clear();
    192201    m_owningManager.clear();
    193202    m_permissions = adoptWK(WKMutableDictionaryCreate());
  • trunk/Tools/WebKitTestRunner/WebNotificationProvider.h

    r289721 r293296  
    6060    HashMap<UUID, WKNotificationManagerRef> m_owningManager;
    6161    WKRetainPtr<WKMutableDictionaryRef> m_permissions;
     62
     63    HashSet<WKRetainPtr<WKNotificationRef>> m_knownPersistentNotifications;
    6264};
    6365
  • trunk/Tools/WebKitTestRunner/cocoa/WebNotificationProviderCocoa.mm

    r293295 r293296  
    11/*
    2  * Copyright (C) 2014 Apple Inc. All rights reserved.
     2 * Copyright (C) 2022 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2424 */
    2525
    26 #import "_WKDownload.h"
     26#import "config.h"
     27#import "WebNotificationProvider.h"
    2728
     29#import "TestController.h"
     30#import <WebKit/WKNotificationPrivateMac.h>
     31#import <WebKit/WKWebsiteDataStorePrivate.h>
    2832#import <wtf/RetainPtr.h>
    2933
    30 @class WKDownload;
     34namespace WTR {
    3135
    32 @interface _WKDownload () <WKObject> {
    33 @package
    34     RetainPtr<WKDownload> _download;
     36void WebNotificationProvider::simulateWebNotificationClickForServiceWorkerNotifications()
     37{
     38    for (auto& notification : m_knownPersistentNotifications) {
     39        auto dictionaryRepresentation = adoptNS(WKNotificationCopyDictionaryRepresentation(notification.get()));
     40        [(__bridge WKWebsiteDataStore *)TestController::defaultWebsiteDataStore() _processPersistentNotificationClick:dictionaryRepresentation.get() completionHandler:^(bool) { }];
     41    }
    3542}
    36 @end
     43
     44} // namespace WTR
Note: See TracChangeset for help on using the changeset viewer.