Title: [289114] trunk/Source/WebKit
Revision
289114
Author
n...@apple.com
Date
2022-02-04 08:06:51 -0800 (Fri, 04 Feb 2022)

Log Message

Import APSConnection-related SPI
https://bugs.webkit.org/show_bug.cgi?id=235856

Reviewed Youenn Fablet.

This imports the SPI declarations necessary to build against ApplePushService in WebKit. It
also includes a PushServiceConnection interface that can sit in front of APSConnection, and
a fake interface that will be fleshed out for testing purposes.


* Platform/spi/Cocoa/ApplePushServiceSPI.h: Added.
* WebKit.xcodeproj/project.pbxproj:
* webpushd/ApplePushServiceConnection.h: Added.
* webpushd/ApplePushServiceConnection.mm: Added.
(-[_WKAPSConnectionDelegate initWithConnection:]):
(-[_WKAPSConnectionDelegate connection:didReceivePublicToken:]):
(-[_WKAPSConnectionDelegate connection:didReceiveIncomingMessage:]):
(WebPushD::ApplePushServiceConnection::ApplePushServiceConnection):
(WebPushD::makeTokenInfo):
(WebPushD::ApplePushServiceConnection::subscribe):
(WebPushD::ApplePushServiceConnection::unsubscribe):
(WebPushD::ApplePushServiceConnection::enabledTopics):
(WebPushD::ApplePushServiceConnection::ignoredTopics):
(WebPushD::ApplePushServiceConnection::opportunisticTopics):
(WebPushD::ApplePushServiceConnection::nonWakingTopics):
(WebPushD::ApplePushServiceConnection::setEnabledTopics):
(WebPushD::ApplePushServiceConnection::setIgnoredTopics):
(WebPushD::ApplePushServiceConnection::setOpportunisticTopics):
(WebPushD::ApplePushServiceConnection::setNonWakingTopics):
(WebPushD::ApplePushServiceConnection::setTopicLists):
* webpushd/MockPushServiceConnection.h: Added.
* webpushd/MockPushServiceConnection.mm: Added.
(WebPushD::MockPushServiceConnection::MockPushServiceConnection):
(WebPushD::MockPushServiceConnection::subscribe):
(WebPushD::MockPushServiceConnection::unsubscribe):
(WebPushD::MockPushServiceConnection::enabledTopics):
(WebPushD::MockPushServiceConnection::ignoredTopics):
(WebPushD::MockPushServiceConnection::opportunisticTopics):
(WebPushD::MockPushServiceConnection::nonWakingTopics):
(WebPushD::MockPushServiceConnection::setEnabledTopics):
(WebPushD::MockPushServiceConnection::setIgnoredTopics):
(WebPushD::MockPushServiceConnection::setOpportunisticTopics):
(WebPushD::MockPushServiceConnection::setNonWakingTopics):
(WebPushD::MockPushServiceConnection::setTopicLists):
* webpushd/PushServiceConnection.h: Added.
* webpushd/PushServiceConnection.mm: Added.
(WebPushD::PushServiceConnection::startListeningForPushMessages):
(WebPushD::PushServiceConnection::didReceivePushMessage):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (289113 => 289114)


--- trunk/Source/WebKit/ChangeLog	2022-02-04 16:05:26 UTC (rev 289113)
+++ trunk/Source/WebKit/ChangeLog	2022-02-04 16:06:51 UTC (rev 289114)
@@ -1,3 +1,53 @@
+2022-02-04  Ben Nham  <n...@apple.com>
+
+        Import APSConnection-related SPI
+        https://bugs.webkit.org/show_bug.cgi?id=235856
+
+        Reviewed Youenn Fablet.
+
+        This imports the SPI declarations necessary to build against ApplePushService in WebKit. It
+        also includes a PushServiceConnection interface that can sit in front of APSConnection, and
+        a fake interface that will be fleshed out for testing purposes.
+
+        * Platform/spi/Cocoa/ApplePushServiceSPI.h: Added.
+        * WebKit.xcodeproj/project.pbxproj:
+        * webpushd/ApplePushServiceConnection.h: Added.
+        * webpushd/ApplePushServiceConnection.mm: Added.
+        (-[_WKAPSConnectionDelegate initWithConnection:]):
+        (-[_WKAPSConnectionDelegate connection:didReceivePublicToken:]):
+        (-[_WKAPSConnectionDelegate connection:didReceiveIncomingMessage:]):
+        (WebPushD::ApplePushServiceConnection::ApplePushServiceConnection):
+        (WebPushD::makeTokenInfo):
+        (WebPushD::ApplePushServiceConnection::subscribe):
+        (WebPushD::ApplePushServiceConnection::unsubscribe):
+        (WebPushD::ApplePushServiceConnection::enabledTopics):
+        (WebPushD::ApplePushServiceConnection::ignoredTopics):
+        (WebPushD::ApplePushServiceConnection::opportunisticTopics):
+        (WebPushD::ApplePushServiceConnection::nonWakingTopics):
+        (WebPushD::ApplePushServiceConnection::setEnabledTopics):
+        (WebPushD::ApplePushServiceConnection::setIgnoredTopics):
+        (WebPushD::ApplePushServiceConnection::setOpportunisticTopics):
+        (WebPushD::ApplePushServiceConnection::setNonWakingTopics):
+        (WebPushD::ApplePushServiceConnection::setTopicLists):
+        * webpushd/MockPushServiceConnection.h: Added.
+        * webpushd/MockPushServiceConnection.mm: Added.
+        (WebPushD::MockPushServiceConnection::MockPushServiceConnection):
+        (WebPushD::MockPushServiceConnection::subscribe):
+        (WebPushD::MockPushServiceConnection::unsubscribe):
+        (WebPushD::MockPushServiceConnection::enabledTopics):
+        (WebPushD::MockPushServiceConnection::ignoredTopics):
+        (WebPushD::MockPushServiceConnection::opportunisticTopics):
+        (WebPushD::MockPushServiceConnection::nonWakingTopics):
+        (WebPushD::MockPushServiceConnection::setEnabledTopics):
+        (WebPushD::MockPushServiceConnection::setIgnoredTopics):
+        (WebPushD::MockPushServiceConnection::setOpportunisticTopics):
+        (WebPushD::MockPushServiceConnection::setNonWakingTopics):
+        (WebPushD::MockPushServiceConnection::setTopicLists):
+        * webpushd/PushServiceConnection.h: Added.
+        * webpushd/PushServiceConnection.mm: Added.
+        (WebPushD::PushServiceConnection::startListeningForPushMessages):
+        (WebPushD::PushServiceConnection::didReceivePushMessage):
+
 2022-02-04  Per Arne Vollan  <pvol...@apple.com>
 
         [iOS][macOS] Adjust sandbox access to system-fcntl

Added: trunk/Source/WebKit/Platform/spi/Cocoa/ApplePushServiceSPI.h (0 => 289114)


--- trunk/Source/WebKit/Platform/spi/Cocoa/ApplePushServiceSPI.h	                        (rev 0)
+++ trunk/Source/WebKit/Platform/spi/Cocoa/ApplePushServiceSPI.h	2022-02-04 16:06:51 UTC (rev 289114)
@@ -0,0 +1,102 @@
+/*
+ * 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.
+ */
+
+#if USE(APPLE_INTERNAL_SDK)
+
+#import <ApplePushService/ApplePushService.h>
+
+#else // if !USE(APPLE_INTERNAL_SDK)
+
+#import <Foundation/Foundation.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+WTF_EXTERN_C_BEGIN
+extern NSString *const APSEnvironmentProduction;
+
+typedef NS_ENUM(NSInteger, APSURLTokenErrorCode) {
+    APSURLTokenErrorCodeInvalidArguments = 100,
+    APSURLTokenErrorCodeXPCError = 101,
+    APSURLTokenErrorCodeTopicSaltingFailed = 102,
+    APSURLTokenErrorCodeTopicAlreadyInFilter = 103,
+};
+WTF_EXTERN_C_END
+
+@class APSConnection;
+@protocol APSConnectionDelegate;
+
+@interface APSMessage : NSObject<NSCoding>
+@property (nonatomic, retain) NSString *topic;
+@property (nonatomic, retain) NSDictionary *userInfo;
+@property (nonatomic, assign) NSUInteger identifier;
+@end
+
+@interface APSIncomingMessage : APSMessage
+@end
+
+#if HAVE(APPLE_PUSH_SERVICE_URL_TOKEN_SUPPORT)
+
+@interface APSURLToken : NSObject<NSSecureCoding, NSCopying>
+@property (nonatomic, strong) NSString *tokenURL;
+@end
+
+@interface APSURLTokenInfo : NSObject<NSSecureCoding, NSCopying>
+- (instancetype)initWithTopic:(NSString *)topic vapidPublicKey:(nullable NSData *)vapidPublicKey;
+@end
+
+typedef void(^APSConnectionRequestURLTokenCompletion)(APSURLToken * __nullable token, NSError * __nullable error);
+typedef void(^APSConnectionInvalidateURLTokenCompletion)(BOOL success, NSError * __nullable error);
+
+#endif // HAVE(APPLE_PUSH_SERVICE_URL_TOKEN_SUPPORT)
+
+@interface APSConnection : NSObject
+
+- (instancetype)initWithEnvironmentName:(NSString *)environmentName namedDelegatePort:(nullable NSString *)namedDelegatePort queue:(dispatch_queue_t)queue;
+
+#if HAVE(APPLE_PUSH_SERVICE_URL_TOKEN_SUPPORT)
+- (void)requestURLTokenForInfo:(APSURLTokenInfo *)info completion:(APSConnectionRequestURLTokenCompletion)completion;
+- (void)invalidateURLTokenForInfo:(APSURLTokenInfo *)info completion:(APSConnectionInvalidateURLTokenCompletion)completion;
+#endif // HAVE(APPLE_PUSH_SERVICE_URL_TOKEN_SUPPORT)
+
+@property (nonatomic, readwrite, assign, nullable) id<APSConnectionDelegate> delegate;
+
+@property (nonatomic, readwrite, strong, setter=_setEnabledTopics:, nullable) NSArray<NSString *> *enabledTopics;
+@property (nonatomic, readwrite, strong, setter=_setIgnoredTopics:, nullable) NSArray<NSString *> *ignoredTopics;
+@property (nonatomic, readwrite, strong, setter=_setOpportunisticTopics:, nullable) NSArray<NSString *> *opportunisticTopics;
+@property (nonatomic, readwrite, strong, setter=_setNonWakingTopics:, nullable) NSArray<NSString *> *nonWakingTopics;
+
+- (void)setEnabledTopics:(NSArray<NSString *> *)enabledTopics ignoredTopics:(NSArray<NSString *> *)ignoredTopics opportunisticTopics:(NSArray<NSString *> *)opportunisticTopics nonWakingTopics:(NSArray<NSString *> *)nonWakingTopics;
+
+@end
+
+@protocol APSConnectionDelegate<NSObject>
+- (void)connection:(APSConnection *)connection didReceivePublicToken:(NSData *)publicToken;
+@optional
+- (void)connection:(APSConnection *)connection didReceiveIncomingMessage:(APSIncomingMessage *)message;
+@end
+
+NS_ASSUME_NONNULL_END
+
+#endif // !USE(APPLE_INTERNAL_SDK)

Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (289113 => 289114)


--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2022-02-04 16:05:26 UTC (rev 289113)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2022-02-04 16:06:51 UTC (rev 289114)
@@ -1998,6 +1998,13 @@
 		E5CBA76727A318E100DF7858 /* UnifiedSource119.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E5CBA76027A3187900DF7858 /* UnifiedSource119.cpp */; };
 		E5CBA76827A318E100DF7858 /* UnifiedSource117.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E5CBA76227A3187900DF7858 /* UnifiedSource117.cpp */; };
 		E5DEFA6826F8F42600AB68DB /* PhotosUISPI.h in Headers */ = {isa = PBXBuildFile; fileRef = E5DEFA6726F8F42600AB68DB /* PhotosUISPI.h */; };
+		EBA8D3AB27A5E31300CB7900 /* ApplePushServiceSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = EBA8D3AA27A5E31300CB7900 /* ApplePushServiceSPI.h */; };
+		EBA8D3B227A5E33F00CB7900 /* ApplePushServiceConnection.mm in Sources */ = {isa = PBXBuildFile; fileRef = EBA8D3AC27A5E33E00CB7900 /* ApplePushServiceConnection.mm */; };
+		EBA8D3B327A5E33F00CB7900 /* MockPushServiceConnection.h in Headers */ = {isa = PBXBuildFile; fileRef = EBA8D3AD27A5E33E00CB7900 /* MockPushServiceConnection.h */; };
+		EBA8D3B427A5E33F00CB7900 /* ApplePushServiceConnection.h in Headers */ = {isa = PBXBuildFile; fileRef = EBA8D3AE27A5E33F00CB7900 /* ApplePushServiceConnection.h */; };
+		EBA8D3B527A5E33F00CB7900 /* PushServiceConnection.h in Headers */ = {isa = PBXBuildFile; fileRef = EBA8D3AF27A5E33F00CB7900 /* PushServiceConnection.h */; };
+		EBA8D3B627A5E33F00CB7900 /* MockPushServiceConnection.mm in Sources */ = {isa = PBXBuildFile; fileRef = EBA8D3B027A5E33F00CB7900 /* MockPushServiceConnection.mm */; };
+		EBA8D3B727A5E33F00CB7900 /* PushServiceConnection.mm in Sources */ = {isa = PBXBuildFile; fileRef = EBA8D3B127A5E33F00CB7900 /* PushServiceConnection.mm */; };
 		ED82A7F2128C6FAF004477B3 /* WKBundlePageOverlay.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A22F0FF1289FCD90085E74F /* WKBundlePageOverlay.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		F409BA181E6E64BC009DA28E /* WKDragDestinationAction.h in Headers */ = {isa = PBXBuildFile; fileRef = F409BA171E6E64B3009DA28E /* WKDragDestinationAction.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		F4299507270E234D0032298B /* StreamMessageReceiver.h in Headers */ = {isa = PBXBuildFile; fileRef = F4299506270E234C0032298B /* StreamMessageReceiver.h */; };
@@ -6452,6 +6459,13 @@
 		E5DEFA6726F8F42600AB68DB /* PhotosUISPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PhotosUISPI.h; sourceTree = "<group>"; };
 		EB0D312D275AE13300863D8F /* com.apple.webkit.webpushd.mac.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = com.apple.webkit.webpushd.mac.plist; sourceTree = "<group>"; };
 		EB0D312E275AE13300863D8F /* com.apple.webkit.webpushd.ios.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = com.apple.webkit.webpushd.ios.plist; sourceTree = "<group>"; };
+		EBA8D3AA27A5E31300CB7900 /* ApplePushServiceSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ApplePushServiceSPI.h; sourceTree = "<group>"; };
+		EBA8D3AC27A5E33E00CB7900 /* ApplePushServiceConnection.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ApplePushServiceConnection.mm; sourceTree = "<group>"; };
+		EBA8D3AD27A5E33E00CB7900 /* MockPushServiceConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MockPushServiceConnection.h; sourceTree = "<group>"; };
+		EBA8D3AE27A5E33F00CB7900 /* ApplePushServiceConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ApplePushServiceConnection.h; sourceTree = "<group>"; };
+		EBA8D3AF27A5E33F00CB7900 /* PushServiceConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PushServiceConnection.h; sourceTree = "<group>"; };
+		EBA8D3B027A5E33F00CB7900 /* MockPushServiceConnection.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MockPushServiceConnection.mm; sourceTree = "<group>"; };
+		EBA8D3B127A5E33F00CB7900 /* PushServiceConnection.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PushServiceConnection.mm; sourceTree = "<group>"; };
 		ECA680D31E6904B500731D20 /* ExtraPrivateSymbolsForTAPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExtraPrivateSymbolsForTAPI.h; sourceTree = "<group>"; };
 		ECBFC1DB1E6A4D66000300C7 /* ExtraPublicSymbolsForTAPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ExtraPublicSymbolsForTAPI.h; sourceTree = "<group>"; };
 		F036978715F4BF0500C3A80E /* WebColorPicker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebColorPicker.cpp; sourceTree = "<group>"; };
@@ -8649,6 +8663,7 @@
 				572EBBDC25392181000552B3 /* AppAttestSPI.h */,
 				9565083726D87A2B00E15CB7 /* AppleMediaServicesSPI.h */,
 				9565083826D87A2B00E15CB7 /* AppleMediaServicesUISPI.h */,
+				EBA8D3AA27A5E31300CB7900 /* ApplePushServiceSPI.h */,
 				57FABB0E25817CF00059DC95 /* AuthenticationServicesCoreSPI.h */,
 				1A5705101BE410E500874AF1 /* BlockSPI.h */,
 				E50620912542102000C43091 /* ContactsUISPI.h */,
@@ -10069,6 +10084,8 @@
 				517B5F63275A8D5C002DC22D /* webpushtool */,
 				5160E954274B887100567388 /* AppBundleRequest.h */,
 				5160E953274B887100567388 /* AppBundleRequest.mm */,
+				EBA8D3AE27A5E33F00CB7900 /* ApplePushServiceConnection.h */,
+				EBA8D3AC27A5E33E00CB7900 /* ApplePushServiceConnection.mm */,
 				EB0D312E275AE13300863D8F /* com.apple.webkit.webpushd.ios.plist */,
 				EB0D312D275AE13300863D8F /* com.apple.webkit.webpushd.mac.plist */,
 				51F7BB75274498BB00C45A72 /* MockAppBundleForTesting.h */,
@@ -10075,10 +10092,14 @@
 				51F7BB74274498BA00C45A72 /* MockAppBundleForTesting.mm */,
 				5160E95C274C2A0300567388 /* MockAppBundleRegistry.h */,
 				5160E95F274C2A3F00567388 /* MockAppBundleRegistry.mm */,
+				EBA8D3AD27A5E33E00CB7900 /* MockPushServiceConnection.h */,
+				EBA8D3B027A5E33F00CB7900 /* MockPushServiceConnection.mm */,
 				5160E957274C0D8800567388 /* PushAppBundle.h */,
 				5160E958274C0D8800567388 /* PushAppBundle.mm */,
 				51F7BB792744C50700C45A72 /* PushClientConnection.h */,
 				51F7BB7A2744C50700C45A72 /* PushClientConnection.mm */,
+				EBA8D3AF27A5E33F00CB7900 /* PushServiceConnection.h */,
+				EBA8D3B127A5E33F00CB7900 /* PushServiceConnection.mm */,
 				517B5F77275E9795002DC22D /* webpushd.cpp */,
 				512CD69D2723393A00F7F8EC /* WebPushDaemon.h */,
 				512CD69E2723393A00F7F8EC /* WebPushDaemon.mm */,
@@ -12889,6 +12910,8 @@
 				F48D2A8521583A7E00C6752B /* AppKitSPI.h in Headers */,
 				9565083926D87A2B00E15CB7 /* AppleMediaServicesSPI.h in Headers */,
 				9565083A26D87A2B00E15CB7 /* AppleMediaServicesUISPI.h in Headers */,
+				EBA8D3B427A5E33F00CB7900 /* ApplePushServiceConnection.h in Headers */,
+				EBA8D3AB27A5E31300CB7900 /* ApplePushServiceSPI.h in Headers */,
 				F4EC94E32356CC57000BB614 /* ApplicationServicesSPI.h in Headers */,
 				1AD4C1931B39F33200ABC28E /* ApplicationStateTracker.h in Headers */,
 				493102BD2683F3D0002BB885 /* AppPrivacyReport.h in Headers */,
@@ -13106,6 +13129,7 @@
 				57DCEDC7214F18300016B847 /* MockLocalConnection.h in Headers */,
 				57DCEDC3214F114C0016B847 /* MockLocalService.h in Headers */,
 				57B8264C230603C100B72EB0 /* MockNfcService.h in Headers */,
+				EBA8D3B327A5E33F00CB7900 /* MockPushServiceConnection.h in Headers */,
 				7137BA8025F1542000914EE3 /* ModelElementController.h in Headers */,
 				C0E3AA7C1209E83C00A49D01 /* Module.h in Headers */,
 				2D50366B1BCDE17900E20BB3 /* NativeWebGestureEvent.h in Headers */,
@@ -13226,6 +13250,7 @@
 				517B5F81275E97B6002DC22D /* PushAppBundle.h in Headers */,
 				517B5F7D275E97B6002DC22D /* PushClientConnection.h in Headers */,
 				517B5F95275EBA63002DC22D /* PushMessageForTesting.h in Headers */,
+				EBA8D3B527A5E33F00CB7900 /* PushServiceConnection.h in Headers */,
 				A1E688701F6E2BAB007006A6 /* QuarantineSPI.h in Headers */,
 				1A0C227E2451130A00ED614D /* QuickLookThumbnailingSoftLink.h in Headers */,
 				1AEE57252409F142002005D6 /* QuickLookThumbnailLoader.h in Headers */,
@@ -15424,6 +15449,7 @@
 				99E7189A21F79D9E0055E975 /* _WKTouchEventGenerator.mm in Sources */,
 				572EBBDA2538F6B4000552B3 /* AppAttestInternalSoftLink.mm in Sources */,
 				517B5F7E275E97B6002DC22D /* AppBundleRequest.mm in Sources */,
+				EBA8D3B227A5E33F00CB7900 /* ApplePushServiceConnection.mm in Sources */,
 				2DEB1D2E2127473600933906 /* ArgumentCodersCF.cpp in Sources */,
 				CD4570D424411D0F00A3DCEB /* AudioSessionRoutingArbitrator.cpp in Sources */,
 				CD4570D3244113B500A3DCEB /* AudioSessionRoutingArbitratorProxyMessageReceiver.cpp in Sources */,
@@ -15457,6 +15483,7 @@
 				9B4790912531563200EC11AB /* MessageArgumentDescriptions.cpp in Sources */,
 				517B5F84275E97B6002DC22D /* MockAppBundleForTesting.mm in Sources */,
 				517B5F86275E97B6002DC22D /* MockAppBundleRegistry.mm in Sources */,
+				EBA8D3B627A5E33F00CB7900 /* MockPushServiceConnection.mm in Sources */,
 				57B826452304F14000B72EB0 /* NearFieldSoftLink.mm in Sources */,
 				C1C1B30F2540F50D00D9100B /* NetworkConnectionToWebProcessMac.mm in Sources */,
 				51DD9F2816367DA2001578E9 /* NetworkConnectionToWebProcessMessageReceiver.cpp in Sources */,
@@ -15482,6 +15509,7 @@
 				2D54C31B212F4DA60049C174 /* ProcessLauncher.cpp in Sources */,
 				517B5F82275E97B6002DC22D /* PushAppBundle.mm in Sources */,
 				517B5F7B275E97A9002DC22D /* PushClientConnection.mm in Sources */,
+				EBA8D3B727A5E33F00CB7900 /* PushServiceConnection.mm in Sources */,
 				1A0C227F2451130A00ED614D /* QuickLookThumbnailingSoftLink.mm in Sources */,
 				1A0C225E243575CD00ED614D /* QuickLookThumbnailLoader.mm in Sources */,
 				9B1229CE23FF25F2008CA751 /* RemoteAudioDestinationManager.cpp in Sources */,

Added: trunk/Source/WebKit/webpushd/ApplePushServiceConnection.h (0 => 289114)


--- trunk/Source/WebKit/webpushd/ApplePushServiceConnection.h	                        (rev 0)
+++ trunk/Source/WebKit/webpushd/ApplePushServiceConnection.h	2022-02-04 16:06:51 UTC (rev 289114)
@@ -0,0 +1,67 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#if HAVE(APPLE_PUSH_SERVICE_URL_TOKEN_SUPPORT)
+
+#include "ApplePushServiceSPI.h"
+#include "PushServiceConnection.h"
+#include <wtf/HashMap.h>
+
+namespace WebPushD {
+
+class ApplePushServiceConnection final : public PushServiceConnection {
+public:
+    ApplePushServiceConnection(const String& incomingPushServiceName);
+    ~ApplePushServiceConnection();
+
+    void subscribe(const String& topic, const Vector<uint8_t>& vapidPublicKey, SubscribeHandler&&) final;
+    void unsubscribe(const String& topic, const Vector<uint8_t>& vapidPublicKey, UnsubscribeHandler&&) final;
+
+    Vector<String> enabledTopics() override;
+    Vector<String> ignoredTopics() override;
+    Vector<String> opportunisticTopics() override;
+    Vector<String> nonWakingTopics() override;
+
+    void setEnabledTopics(Vector<String>&&) override;
+    void setIgnoredTopics(Vector<String>&&) override;
+    void setOpportunisticTopics(Vector<String>&&) override;
+    void setNonWakingTopics(Vector<String>&&) override;
+
+    void setTopicLists(TopicLists&&) override;
+
+private:
+    RetainPtr<APSConnection> m_connection;
+    RetainPtr<id<APSConnectionDelegate>> m_delegate;
+    unsigned m_handlerIdentifier { 0 };
+    HashMap<unsigned, SubscribeHandler> m_subscribeHandlers;
+    HashMap<unsigned, UnsubscribeHandler> m_unsubscribeHandlers;
+};
+
+} // namespace WebPushD
+
+#endif // HAVE(APPLE_PUSH_SERVICE_URL_TOKEN_SUPPORT)
+

Added: trunk/Source/WebKit/webpushd/ApplePushServiceConnection.mm (0 => 289114)


--- trunk/Source/WebKit/webpushd/ApplePushServiceConnection.mm	                        (rev 0)
+++ trunk/Source/WebKit/webpushd/ApplePushServiceConnection.mm	2022-02-04 16:06:51 UTC (rev 289114)
@@ -0,0 +1,170 @@
+/*
+ * 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 "ApplePushServiceConnection.h"
+
+#if HAVE(APPLE_PUSH_SERVICE_URL_TOKEN_SUPPORT)
+
+#import <wtf/BlockPtr.h>
+#import <wtf/cocoa/VectorCocoa.h>
+
+@interface _WKAPSConnectionDelegate : NSObject<APSConnectionDelegate> {
+    WeakPtr<WebPushD::ApplePushServiceConnection> _connection;
+}
+@end
+
+@implementation _WKAPSConnectionDelegate
+
+- (instancetype)initWithConnection:(WebPushD::ApplePushServiceConnection *)connection
+{
+    if ((self = [super init]))
+        _connection = connection;
+    return self;
+}
+
+- (void)connection:(APSConnection *)connection didReceivePublicToken:(NSData *)publicToken
+{
+    UNUSED_PARAM(connection);
+    UNUSED_PARAM(publicToken);
+}
+
+- (void)connection:(APSConnection *)connection didReceiveIncomingMessage:(APSIncomingMessage *)message
+{
+    UNUSED_PARAM(connection);
+
+    ASSERT(isMainRunLoop());
+
+    if (_connection)
+        _connection->didReceivePushMessage(message.topic, message.userInfo);
+}
+
+@end
+
+namespace WebPushD {
+
+ApplePushServiceConnection::ApplePushServiceConnection(const String& incomingPushServiceName)
+{
+    m_connection = adoptNS([[APSConnection alloc] initWithEnvironmentName:APSEnvironmentProduction namedDelegatePort:incomingPushServiceName queue:dispatch_get_main_queue()]);
+    m_delegate = adoptNS([[_WKAPSConnectionDelegate alloc] initWithConnection:this]);
+    [m_connection setDelegate:m_delegate.get()];
+}
+
+ApplePushServiceConnection::~ApplePushServiceConnection()
+{
+    [m_connection setDelegate:nil];
+}
+
+static RetainPtr<APSURLTokenInfo> makeTokenInfo(const String& topic, const Vector<uint8_t>& vapidPublicKey)
+{
+    auto serverPublicKey = adoptNS([[NSData alloc] initWithBytes:vapidPublicKey.data() length:vapidPublicKey.size()]);
+    return adoptNS([[APSURLTokenInfo alloc] initWithTopic:topic vapidPublicKey:serverPublicKey.get()]);
+}
+
+void ApplePushServiceConnection::subscribe(const String& topic, const Vector<uint8_t>& vapidPublicKey, SubscribeHandler&& subscribeHandler)
+{
+    ASSERT(isMainRunLoop());
+
+    // Stash the completion handler away and look it up by id so that we can ensure it gets destructed on the main thread. If we move the handler and capture it in the Obj-C block, it might get destructed on a secondary thread since this completion block moves between different dispatch queues in the APS implementation.
+    auto identifier = ++m_handlerIdentifier;
+    m_subscribeHandlers.add(identifier, WTFMove(subscribeHandler));
+
+    [m_connection requestURLTokenForInfo:makeTokenInfo(topic, vapidPublicKey).get() completion:makeBlockPtr([this, weakThis = WeakPtr { *this }, identifier] (APSURLToken *token, NSError *error) {
+        if (!weakThis)
+            return;
+
+        auto handler = m_subscribeHandlers.take(identifier);
+        handler(token.tokenURL, error);
+    }).get()];
+}
+
+void ApplePushServiceConnection::unsubscribe(const String& topic, const Vector<uint8_t>& vapidPublicKey, UnsubscribeHandler&& unsubscribeHandler)
+{
+    ASSERT(isMainRunLoop());
+
+    // See subscribe for why we stash the handler into a map.
+    auto identifier = ++m_handlerIdentifier;
+    m_unsubscribeHandlers.add(identifier, WTFMove(unsubscribeHandler));
+
+    [m_connection invalidateURLTokenForInfo:makeTokenInfo(topic, vapidPublicKey).get() completion:makeBlockPtr([this, weakThis = WeakPtr { *this }, identifier] (BOOL success, NSError *error) {
+        if (!weakThis)
+            return;
+
+        // FIXME: remove this once APS stops calling back on the wrong queue (rdar://88100275).
+        dispatch_async(dispatch_get_main_queue(), ^{
+            auto handler = m_unsubscribeHandlers.take(identifier);
+            handler(success, error);
+        });
+    }).get()];
+}
+
+Vector<String> ApplePushServiceConnection::enabledTopics()
+{
+    return makeVector<String>([m_connection enabledTopics]);
+}
+
+Vector<String> ApplePushServiceConnection::ignoredTopics()
+{
+    return makeVector<String>([m_connection ignoredTopics]);
+}
+
+Vector<String> ApplePushServiceConnection::opportunisticTopics()
+{
+    return makeVector<String>([m_connection opportunisticTopics]);
+}
+
+Vector<String> ApplePushServiceConnection::nonWakingTopics()
+{
+    return makeVector<String>([m_connection nonWakingTopics]);
+}
+
+void ApplePushServiceConnection::setEnabledTopics(Vector<String>&& topics)
+{
+    [m_connection _setEnabledTopics:createNSArray(WTFMove(topics)).get()];
+}
+
+void ApplePushServiceConnection::setIgnoredTopics(Vector<String>&& topics)
+{
+    [m_connection _setIgnoredTopics:createNSArray(WTFMove(topics)).get()];
+}
+
+void ApplePushServiceConnection::setOpportunisticTopics(Vector<String>&& topics)
+{
+    [m_connection _setOpportunisticTopics:createNSArray(WTFMove(topics)).get()];
+}
+
+void ApplePushServiceConnection::setNonWakingTopics(Vector<String>&& topics)
+{
+    [m_connection _setNonWakingTopics:createNSArray(WTFMove(topics)).get()];
+}
+
+void ApplePushServiceConnection::setTopicLists(TopicLists&& topicLists)
+{
+    [m_connection setEnabledTopics:createNSArray(WTFMove(topicLists.enabledTopics)).get() ignoredTopics:createNSArray(WTFMove(topicLists.ignoredTopics)).get() opportunisticTopics:createNSArray(WTFMove(topicLists.opportunisticTopics)).get() nonWakingTopics:createNSArray(WTFMove(topicLists.nonWakingTopics)).get()];
+}
+
+} // namespace WebPushD
+
+#endif // HAVE(APPLE_PUSH_SERVICE_URL_TOKEN_SUPPORT)

Added: trunk/Source/WebKit/webpushd/MockPushServiceConnection.h (0 => 289114)


--- trunk/Source/WebKit/webpushd/MockPushServiceConnection.h	                        (rev 0)
+++ trunk/Source/WebKit/webpushd/MockPushServiceConnection.h	2022-02-04 16:06:51 UTC (rev 289114)
@@ -0,0 +1,53 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include "PushServiceConnection.h"
+
+namespace WebPushD {
+
+class MockPushServiceConnection final : public PushServiceConnection {
+public:
+    MockPushServiceConnection();
+    ~MockPushServiceConnection();
+
+    void subscribe(const String& topic, const Vector<uint8_t>& vapidPublicKey, SubscribeHandler&&) override;
+    void unsubscribe(const String& topic, const Vector<uint8_t>& vapidPublicKey, UnsubscribeHandler&&) override;
+
+    Vector<String> enabledTopics() override;
+    Vector<String> ignoredTopics() override;
+    Vector<String> opportunisticTopics() override;
+    Vector<String> nonWakingTopics() override;
+
+    void setEnabledTopics(Vector<String>&&) override;
+    void setIgnoredTopics(Vector<String>&&) override;
+    void setOpportunisticTopics(Vector<String>&&) override;
+    void setNonWakingTopics(Vector<String>&&) override;
+
+    void setTopicLists(TopicLists&&) override;
+};
+
+} // namespace WebPushD

Added: trunk/Source/WebKit/webpushd/MockPushServiceConnection.mm (0 => 289114)


--- trunk/Source/WebKit/webpushd/MockPushServiceConnection.mm	                        (rev 0)
+++ trunk/Source/WebKit/webpushd/MockPushServiceConnection.mm	2022-02-04 16:06:51 UTC (rev 289114)
@@ -0,0 +1,87 @@
+/*
+ * 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 "MockPushServiceConnection.h"
+
+namespace WebPushD {
+
+MockPushServiceConnection::MockPushServiceConnection()
+{
+}
+
+MockPushServiceConnection::~MockPushServiceConnection() = default;
+
+void MockPushServiceConnection::subscribe(const String&, const Vector<uint8_t>&, SubscribeHandler&& handler)
+{
+    handler({ }, [NSError errorWithDomain:NSCocoaErrorDomain code:NSFeatureUnsupportedError userInfo:nil]);
+}
+
+void MockPushServiceConnection::unsubscribe(const String&, const Vector<uint8_t>&, UnsubscribeHandler&& handler)
+{
+    handler({ }, [NSError errorWithDomain:NSCocoaErrorDomain code:NSFeatureUnsupportedError userInfo:nil]);
+}
+
+Vector<String> MockPushServiceConnection::enabledTopics()
+{
+    return { };
+}
+
+Vector<String> MockPushServiceConnection::ignoredTopics()
+{
+    return { };
+}
+
+Vector<String> MockPushServiceConnection::opportunisticTopics()
+{
+    return { };
+}
+
+Vector<String> MockPushServiceConnection::nonWakingTopics()
+{
+    return { };
+}
+
+void MockPushServiceConnection::setEnabledTopics(Vector<String>&& topics)
+{
+}
+
+void MockPushServiceConnection::setIgnoredTopics(Vector<String>&& topics)
+{
+}
+
+void MockPushServiceConnection::setOpportunisticTopics(Vector<String>&& topics)
+{
+}
+
+void MockPushServiceConnection::setNonWakingTopics(Vector<String>&& topics)
+{
+}
+
+void MockPushServiceConnection::setTopicLists(TopicLists&& topicLists)
+{
+}
+
+} // namespace WebPushD

Added: trunk/Source/WebKit/webpushd/PushServiceConnection.h (0 => 289114)


--- trunk/Source/WebKit/webpushd/PushServiceConnection.h	                        (rev 0)
+++ trunk/Source/WebKit/webpushd/PushServiceConnection.h	2022-02-04 16:06:51 UTC (rev 289114)
@@ -0,0 +1,82 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include <wtf/CompletionHandler.h>
+#include <wtf/Deque.h>
+#include <wtf/Function.h>
+#include <wtf/RetainPtr.h>
+#include <wtf/Vector.h>
+#include <wtf/WeakPtr.h>
+#include <wtf/text/WTFString.h>
+
+OBJC_CLASS NSError;
+OBJC_CLASS NSString;
+OBJC_CLASS NSDictionary;
+
+namespace WebPushD {
+
+class PushServiceConnection : public CanMakeWeakPtr<PushServiceConnection> {
+    WTF_MAKE_FAST_ALLOCATED;
+public:
+    using IncomingPushMessageHandler = Function<void(NSString *, NSDictionary *)>;
+
+    PushServiceConnection() = default;
+    virtual ~PushServiceConnection() = default;
+
+    using SubscribeHandler = CompletionHandler<void(NSString *, NSError *)>;
+    virtual void subscribe(const String& topic, const Vector<uint8_t>& vapidPublicKey, SubscribeHandler&&) = 0;
+
+    using UnsubscribeHandler = CompletionHandler<void(bool, NSError *)>;
+    virtual void unsubscribe(const String& topic, const Vector<uint8_t>& vapidPublicKey, UnsubscribeHandler&&) = 0;
+
+    virtual Vector<String> enabledTopics() = 0;
+    virtual Vector<String> ignoredTopics() = 0;
+    virtual Vector<String> opportunisticTopics() = 0;
+    virtual Vector<String> nonWakingTopics() = 0;
+
+    virtual void setEnabledTopics(Vector<String>&&) = 0;
+    virtual void setIgnoredTopics(Vector<String>&&) = 0;
+    virtual void setOpportunisticTopics(Vector<String>&&) = 0;
+    virtual void setNonWakingTopics(Vector<String>&&) = 0;
+
+    struct TopicLists {
+        Vector<String> enabledTopics;
+        Vector<String> ignoredTopics;
+        Vector<String> opportunisticTopics;
+        Vector<String> nonWakingTopics;
+    };
+    virtual void setTopicLists(TopicLists&&) = 0;
+
+    void startListeningForPushMessages(IncomingPushMessageHandler&&);
+    void didReceivePushMessage(NSString *topic, NSDictionary *userInfo);
+
+private:
+    IncomingPushMessageHandler m_incomingPushMessageHandler;
+    Deque<std::pair<RetainPtr<NSString>, RetainPtr<NSDictionary>>> m_pendingPushes;
+};
+
+} // namespace WebPushD

Added: trunk/Source/WebKit/webpushd/PushServiceConnection.mm (0 => 289114)


--- trunk/Source/WebKit/webpushd/PushServiceConnection.mm	                        (rev 0)
+++ trunk/Source/WebKit/webpushd/PushServiceConnection.mm	2022-02-04 16:06:51 UTC (rev 289114)
@@ -0,0 +1,60 @@
+/*
+ * 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 "PushServiceConnection.h"
+
+#import <wtf/WorkQueue.h>
+
+namespace WebPushD {
+
+void PushServiceConnection::startListeningForPushMessages(IncomingPushMessageHandler&& handler)
+{
+    m_incomingPushMessageHandler = WTFMove(handler);
+
+    if (!m_pendingPushes.size())
+        return;
+
+    WorkQueue::main().dispatch([this]() mutable {
+        while (m_pendingPushes.size()) {
+            @autoreleasepool {
+                auto message = m_pendingPushes.takeFirst();
+                m_incomingPushMessageHandler(message.first.get(), message.second.get());
+            }
+        }
+    });
+}
+
+void PushServiceConnection::didReceivePushMessage(NSString *topic, NSDictionary *userInfo)
+{
+    if (!m_incomingPushMessageHandler) {
+        m_pendingPushes.append({ topic, userInfo });
+        return;
+    }
+
+    m_incomingPushMessageHandler(topic, userInfo);
+}
+
+} // namespace WebPushD
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to