Diff
Modified: trunk/Source/WTF/ChangeLog (284202 => 284203)
--- trunk/Source/WTF/ChangeLog 2021-10-14 22:28:10 UTC (rev 284202)
+++ trunk/Source/WTF/ChangeLog 2021-10-14 22:32:37 UTC (rev 284203)
@@ -1,3 +1,12 @@
+2021-10-14 Alex Christensen <[email protected]>
+
+ Share IPC communication code between webpushd and adattributiond
+ https://bugs.webkit.org/show_bug.cgi?id=231718
+
+ Reviewed by Brady Eidson.
+
+ * wtf/spi/darwin/XPCSPI.h:
+
2021-10-14 Myles C. Maxfield <[email protected]>
All the SDKVariant.xcconfig files should match
Modified: trunk/Source/WTF/wtf/spi/darwin/XPCSPI.h (284202 => 284203)
--- trunk/Source/WTF/wtf/spi/darwin/XPCSPI.h 2021-10-14 22:28:10 UTC (rev 284202)
+++ trunk/Source/WTF/wtf/spi/darwin/XPCSPI.h 2021-10-14 22:32:37 UTC (rev 284203)
@@ -194,6 +194,8 @@
void xpc_dictionary_set_fd(xpc_object_t, const char* key, int fd);
void xpc_dictionary_set_string(xpc_object_t, const char* key, const char* string);
void xpc_dictionary_set_uint64(xpc_object_t, const char* key, uint64_t value);
+void xpc_dictionary_set_data(xpc_object_t, const char *key, const void *bytes,
+ size_t length);
void xpc_dictionary_set_value(xpc_object_t, const char* key, xpc_object_t value);
xpc_type_t xpc_get_type(xpc_object_t);
const char* xpc_type_get_name(xpc_type_t);
Modified: trunk/Source/WebKit/ChangeLog (284202 => 284203)
--- trunk/Source/WebKit/ChangeLog 2021-10-14 22:28:10 UTC (rev 284202)
+++ trunk/Source/WebKit/ChangeLog 2021-10-14 22:32:37 UTC (rev 284203)
@@ -1,3 +1,37 @@
+2021-10-14 Alex Christensen <[email protected]>
+
+ Share IPC communication code between webpushd and adattributiond
+ https://bugs.webkit.org/show_bug.cgi?id=231718
+
+ Reviewed by Brady Eidson.
+
+ This shares enough code from adattributiond to implement a communication protocol for webpushd.
+ Right now the protocol only has one action, EchoTwice, which echos a WTF::String twice as its reply,
+ but that is just a testable behavior that will be soon replaced by more complicated and useful behaviors.
+
+ * Configurations/webpushd.xcconfig:
+ * NetworkProcess/PrivateClickMeasurement/cocoa/PrivateClickMeasurementXPCUtilities.mm:
+ (WebKit::PCM::addVersionAndEncodedMessageToDictionary):
+ * Shared/Daemon/DaemonUtilities.h: Copied from Source/WebKit/Shared/EntryPointUtilities/Cocoa/Daemon/webpushd.c.
+ * Shared/Daemon/DaemonUtilities.mm: Added.
+ (WebKit::startListeningForMachServiceConnections):
+ (WebKit::vectorToXPCData):
+ * Shared/EntryPointUtilities/Cocoa/Daemon/PCMDaemonEntryPoint.mm:
+ (WebKit::connectionAdded):
+ (WebKit::connectionRemoved):
+ (WebKit::PCMDaemonMain):
+ (WebKit::startListeningForMachServiceConnections): Deleted.
+ * SourcesCocoa.txt:
+ * WebKit.xcodeproj/project.pbxproj:
+ * webpushd/WebPushDaemonMain.mm: Added.
+ (WebPushD::CompletionHandler<void):
+ (WebPushD::echoTwice):
+ (WebPushD::decodeMessageAndSendReply):
+ (WebPushD::connectionEventHandler):
+ (WebPushD::connectionAdded):
+ (WebPushD::connectionRemoved):
+ (main):
+
2021-10-14 Wenson Hsieh <[email protected]>
[JS IPC] Make it possible to establish a stream connection using the JS IPC testing API
Modified: trunk/Source/WebKit/Configurations/webpushd.xcconfig (284202 => 284203)
--- trunk/Source/WebKit/Configurations/webpushd.xcconfig 2021-10-14 22:28:10 UTC (rev 284202)
+++ trunk/Source/WebKit/Configurations/webpushd.xcconfig 2021-10-14 22:32:37 UTC (rev 284203)
@@ -25,7 +25,8 @@
PRODUCT_NAME = webpushd;
-FRAMEWORK_SEARCH_PATHS = $(BUILT_PRODUCTS_DIR);
+OTHER_LDFLAGS = -l WTF;
+LIBRARY_SEARCH_PATHS = $(BUILT_PRODUCTS_DIR);
WK_PROCESSED_XCENT_FILE=$(TEMP_FILE_DIR)/$(FULL_PRODUCT_NAME).entitlements
Modified: trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurement/cocoa/PrivateClickMeasurementXPCUtilities.mm (284202 => 284203)
--- trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurement/cocoa/PrivateClickMeasurementXPCUtilities.mm 2021-10-14 22:28:10 UTC (rev 284202)
+++ trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurement/cocoa/PrivateClickMeasurementXPCUtilities.mm 2021-10-14 22:32:37 UTC (rev 284203)
@@ -26,6 +26,7 @@
#import "config.h"
#import "PrivateClickMeasurementXPCUtilities.h"
+#import "DaemonUtilities.h"
#import "PrivateClickMeasurementManagerInterface.h"
#import <wtf/OSObjectPtr.h>
@@ -37,15 +38,7 @@
{
ASSERT(xpc_get_type(dictionary) == XPC_TYPE_DICTIONARY);
xpc_dictionary_set_uint64(dictionary, PCM::protocolVersionKey, PCM::protocolVersionValue);
-
- auto bufferSize = message.size();
- auto rawPointer = message.releaseBuffer().leakPtr();
- auto dispatchData = adoptNS(dispatch_data_create(rawPointer, bufferSize, dispatch_get_main_queue(), ^{
- fastFree(rawPointer);
- }));
- auto xpcData = adoptOSObject(xpc_data_create_with_dispatch_data(dispatchData.get()));
- xpc_dictionary_set_value(dictionary, PCM::protocolEncodedMessageKey, xpcData.get());
-
+ xpc_dictionary_set_value(dictionary, PCM::protocolEncodedMessageKey, vectorToXPCData(WTFMove(message)).get());
}
} // namespace PCM
Copied: trunk/Source/WebKit/Shared/Daemon/DaemonUtilities.h (from rev 284202, trunk/Source/WebKit/Shared/EntryPointUtilities/Cocoa/Daemon/webpushd.c) (0 => 284203)
--- trunk/Source/WebKit/Shared/Daemon/DaemonUtilities.h (rev 0)
+++ trunk/Source/WebKit/Shared/Daemon/DaemonUtilities.h 2021-10-14 22:32:37 UTC (rev 284203)
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2021 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/RetainPtr.h>
+#include <wtf/Vector.h>
+#include <wtf/spi/darwin/XPCSPI.h>
+
+namespace WebKit {
+
+void startListeningForMachServiceConnections(const char* serviceName, const char* entitlement, void(*connectionAdded)(xpc_connection_t), void(*connectionRemoved)(xpc_connection_t), void(*eventHandler)(xpc_object_t));
+RetainPtr<xpc_object_t> vectorToXPCData(Vector<uint8_t>&&);
+
+} // namespace WebKit
Added: trunk/Source/WebKit/Shared/Daemon/DaemonUtilities.mm (0 => 284203)
--- trunk/Source/WebKit/Shared/Daemon/DaemonUtilities.mm (rev 0)
+++ trunk/Source/WebKit/Shared/Daemon/DaemonUtilities.mm 2021-10-14 22:32:37 UTC (rev 284203)
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2021 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 "DaemonUtilities.h"
+
+#import <wtf/RetainPtr.h>
+#import <wtf/cocoa/Entitlements.h>
+
+namespace WebKit {
+
+void startListeningForMachServiceConnections(const char* serviceName, const char* entitlement, void(*connectionAdded)(xpc_connection_t), void(*connectionRemoved)(xpc_connection_t), void(*eventHandler)(xpc_object_t))
+{
+ static NeverDestroyed<RetainPtr<xpc_connection_t>> listener = xpc_connection_create_mach_service(serviceName, dispatch_get_main_queue(), XPC_CONNECTION_MACH_SERVICE_LISTENER);
+ xpc_connection_set_event_handler(listener.get().get(), ^(xpc_object_t peer) {
+ if (xpc_get_type(peer) != XPC_TYPE_CONNECTION)
+ return;
+
+#if USE(APPLE_INTERNAL_SDK)
+ if (entitlement && !WTF::hasEntitlement(peer, entitlement)) {
+ NSLog(@"Connection attempted without required entitlement");
+ xpc_connection_cancel(peer);
+ return;
+ }
+#endif
+
+ xpc_connection_set_event_handler(peer, ^(xpc_object_t event) {
+ if (event == XPC_ERROR_CONNECTION_INVALID)
+ NSLog(@"Failed to start listening for connections to mach service %s, likely because it is not registered with launchd", serviceName);
+ if (event == XPC_ERROR_CONNECTION_INTERRUPTED) {
+ NSLog(@"Removing peer connection %p", peer);
+ connectionRemoved(peer);
+ return;
+ }
+ eventHandler(event);
+ });
+ xpc_connection_set_target_queue(peer, dispatch_get_main_queue());
+ xpc_connection_activate(peer);
+
+ NSLog(@"Adding peer connection %p", peer);
+ connectionAdded(peer);
+ });
+ xpc_connection_activate(listener.get().get());
+}
+
+RetainPtr<xpc_object_t> vectorToXPCData(Vector<uint8_t>&& vector)
+{
+ auto bufferSize = vector.size();
+ auto rawPointer = vector.releaseBuffer().leakPtr();
+ auto dispatchData = adoptNS(dispatch_data_create(rawPointer, bufferSize, dispatch_get_main_queue(), ^{
+ fastFree(rawPointer);
+ }));
+ return adoptNS(xpc_data_create_with_dispatch_data(dispatchData.get()));
+}
+
+} // namespace WebKit
Modified: trunk/Source/WebKit/Shared/EntryPointUtilities/Cocoa/Daemon/PCMDaemonEntryPoint.mm (284202 => 284203)
--- trunk/Source/WebKit/Shared/EntryPointUtilities/Cocoa/Daemon/PCMDaemonEntryPoint.mm 2021-10-14 22:28:10 UTC (rev 284202)
+++ trunk/Source/WebKit/Shared/EntryPointUtilities/Cocoa/Daemon/PCMDaemonEntryPoint.mm 2021-10-14 22:32:37 UTC (rev 284203)
@@ -27,6 +27,7 @@
#import "PCMDaemonEntryPoint.h"
#import "DaemonDecoder.h"
+#import "DaemonUtilities.h"
#import "PCMDaemonConnectionSet.h"
#import "PrivateClickMeasurementConnection.h"
#import "PrivateClickMeasurementManagerInterface.h"
@@ -73,40 +74,6 @@
decodeMessageAndSendToManager(Daemon::Connection(xpc_dictionary_get_remote_connection(request)), messageType, encodedMessage, replySender(messageType, request));
}
-static void startListeningForMachServiceConnections(const char* serviceName)
-{
- static NeverDestroyed<OSObjectPtr<xpc_connection_t>> listener = xpc_connection_create_mach_service(serviceName, dispatch_get_main_queue(), XPC_CONNECTION_MACH_SERVICE_LISTENER);
- xpc_connection_set_event_handler(listener.get().get(), ^(xpc_object_t peer) {
- if (xpc_get_type(peer) != XPC_TYPE_CONNECTION)
- return;
-
-#if USE(APPLE_INTERNAL_SDK)
- if (!WTF::hasEntitlement(peer, "com.apple.private.webkit.adattributiond")) {
- NSLog(@"Connection attempted without required entitlement");
- xpc_connection_cancel(peer);
- return;
- }
-#endif
-
- xpc_connection_set_event_handler(peer, ^(xpc_object_t event) {
- if (event == XPC_ERROR_CONNECTION_INVALID)
- NSLog(@"Failed to start listening for connections to mach service %s, likely because it is not registered with launchd", serviceName);
- if (event == XPC_ERROR_CONNECTION_INTERRUPTED) {
- NSLog(@"Removing peer connection %p", peer);
- PCM::DaemonConnectionSet::singleton().remove(peer);
- return;
- }
- connectionEventHandler(event);
- });
- xpc_connection_set_target_queue(peer, dispatch_get_main_queue());
- xpc_connection_activate(peer);
-
- NSLog(@"Adding peer connection %p", peer);
- PCM::DaemonConnectionSet::singleton().add(peer);
- });
- xpc_connection_activate(listener.get().get());
-}
-
static void registerScheduledActivityHandler()
{
NSLog(@"Registering XPC activity");
@@ -131,6 +98,16 @@
#endif
}
+static void connectionAdded(xpc_connection_t connection)
+{
+ PCM::DaemonConnectionSet::singleton().add(connection);
+}
+
+static void connectionRemoved(xpc_connection_t connection)
+{
+ PCM::DaemonConnectionSet::singleton().remove(connection);
+}
+
int PCMDaemonMain(int argc, const char** argv)
{
if (argc < 5 || strcmp(argv[1], "--machServiceName") || strcmp(argv[3], "--storageLocation")) {
@@ -143,7 +120,7 @@
@autoreleasepool {
enterSandbox();
- startListeningForMachServiceConnections(machServiceName);
+ startListeningForMachServiceConnections(machServiceName, "com.apple.private.webkit.adattributiond", connectionAdded, connectionRemoved, connectionEventHandler);
if (startActivity)
registerScheduledActivityHandler();
WTF::initializeMainThread();
Deleted: trunk/Source/WebKit/Shared/EntryPointUtilities/Cocoa/Daemon/webpushd.c (284202 => 284203)
--- trunk/Source/WebKit/Shared/EntryPointUtilities/Cocoa/Daemon/webpushd.c 2021-10-14 22:28:10 UTC (rev 284202)
+++ trunk/Source/WebKit/Shared/EntryPointUtilities/Cocoa/Daemon/webpushd.c 2021-10-14 22:32:37 UTC (rev 284203)
@@ -1,32 +0,0 @@
-/*
- * Copyright (C) 2021 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.
- */
-
-#include <stdio.h>
-
-int main(int argc, const char** argv)
-{
- // FIXME: Do more things here.
- printf("webpushd is executing\n");
-}
Modified: trunk/Source/WebKit/SourcesCocoa.txt (284202 => 284203)
--- trunk/Source/WebKit/SourcesCocoa.txt 2021-10-14 22:28:10 UTC (rev 284202)
+++ trunk/Source/WebKit/SourcesCocoa.txt 2021-10-14 22:32:37 UTC (rev 284203)
@@ -193,6 +193,8 @@
Shared/Cocoa/WKObject.mm
Shared/Cocoa/WebPreferencesDefaultValuesCocoa.mm
+Shared/Daemon/DaemonUtilities.mm
+
Shared/EntryPointUtilities/Cocoa/Daemon/PCMDaemonConnectionSet.mm
Shared/EntryPointUtilities/Cocoa/Daemon/PCMDaemonEntryPoint.mm
Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (284202 => 284203)
--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj 2021-10-14 22:28:10 UTC (rev 284202)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj 2021-10-14 22:32:37 UTC (rev 284203)
@@ -1255,9 +1255,14 @@
5C1427051C23F84C00D41183 /* DownloadID.h in Headers */ = {isa = PBXBuildFile; fileRef = 5C1426F71C23F84300D41183 /* DownloadID.h */; };
5C1427071C23F84C00D41183 /* DownloadManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 5C1426F91C23F84300D41183 /* DownloadManager.h */; };
5C1427181C23F8B700D41183 /* LegacyCustomProtocolManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 5C1427141C23F8B000D41183 /* LegacyCustomProtocolManager.h */; };
- 5C1579DC27165B8200ED5280 /* webpushd.c in Sources */ = {isa = PBXBuildFile; fileRef = 5C1579DB27165B7500ED5280 /* webpushd.c */; };
5C1579EE27172A8B00ED5280 /* DaemonEncoder.h in Headers */ = {isa = PBXBuildFile; fileRef = 5C1579EA27172A8B00ED5280 /* DaemonEncoder.h */; };
5C1579EF27172A8B00ED5280 /* DaemonDecoder.h in Headers */ = {isa = PBXBuildFile; fileRef = 5C1579EB27172A8B00ED5280 /* DaemonDecoder.h */; };
+ 5C1579FB2717AF5000ED5280 /* DaemonUtilities.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5C1579F92717AF5000ED5280 /* DaemonUtilities.mm */; };
+ 5C1579FC2717AF5000ED5280 /* DaemonUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 5C1579FA2717AF5000ED5280 /* DaemonUtilities.h */; };
+ 5C1579FE2717B6C100ED5280 /* DaemonEncoder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5C1579E827172A8A00ED5280 /* DaemonEncoder.cpp */; };
+ 5C1579FF2717B6D200ED5280 /* DaemonDecoder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5C1579E927172A8B00ED5280 /* DaemonDecoder.cpp */; };
+ 5C157A012717B7FB00ED5280 /* ArgumentCoders.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A3D610413A7F03A00F95D4E /* ArgumentCoders.cpp */; };
+ 5C157A0C2717CA1D00ED5280 /* WebPushDaemonMain.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5C157A0B2717CA1C00ED5280 /* WebPushDaemonMain.mm */; };
5C19A5201FD0B29500EEA323 /* URLSchemeTaskParameters.h in Headers */ = {isa = PBXBuildFile; fileRef = 5C19A51F1FD0B14700EEA323 /* URLSchemeTaskParameters.h */; };
5C20CBA01BB1ECD800895BB1 /* NetworkSession.h in Headers */ = {isa = PBXBuildFile; fileRef = 5C20CB9E1BB0DD1800895BB1 /* NetworkSession.h */; };
5C26958520043212005C439B /* WKOpenPanelParametersPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 5C26958420042F12005C439B /* WKOpenPanelParametersPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -2297,6 +2302,13 @@
remoteGlobalIDString = CD95493426159004008372D9;
remoteInfo = WebKitSwift;
};
+ DFBD8A3B2718B38C00BEC5B0 /* PBXContainerItemProxy */ = {
+ isa = PBXContainerItemProxy;
+ containerPortal = 0867D690FE84028FC02AAC07 /* Project object */;
+ proxyType = 1;
+ remoteGlobalIDString = 8DC2EF4F0486A6940098B216;
+ remoteInfo = WebKit;
+ };
DFEE369926FAD112007C78E0 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 0867D690FE84028FC02AAC07 /* Project object */;
@@ -4535,7 +4547,6 @@
5C14271B1C23F8CC00D41183 /* LegacyCustomProtocolManagerCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = LegacyCustomProtocolManagerCocoa.mm; sourceTree = "<group>"; };
5C1578E5270E0DBC00ED5280 /* com.apple.WebKit.adattributiond.sb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = com.apple.WebKit.adattributiond.sb; sourceTree = "<group>"; };
5C1579DA27165B2F00ED5280 /* webpushd */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = webpushd; sourceTree = BUILT_PRODUCTS_DIR; };
- 5C1579DB27165B7500ED5280 /* webpushd.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = webpushd.c; sourceTree = "<group>"; };
5C1579DD27165BE500ED5280 /* webpushd.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = webpushd.xcconfig; sourceTree = "<group>"; };
5C1579E227172A4900ED5280 /* DaemonConnection.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DaemonConnection.cpp; sourceTree = "<group>"; };
5C1579E327172A4900ED5280 /* DaemonConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DaemonConnection.h; sourceTree = "<group>"; };
@@ -4544,6 +4555,11 @@
5C1579E927172A8B00ED5280 /* DaemonDecoder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DaemonDecoder.cpp; sourceTree = "<group>"; };
5C1579EA27172A8B00ED5280 /* DaemonEncoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DaemonEncoder.h; sourceTree = "<group>"; };
5C1579EB27172A8B00ED5280 /* DaemonDecoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DaemonDecoder.h; sourceTree = "<group>"; };
+ 5C1579F227179FD800ED5280 /* DaemonUtilities.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DaemonUtilities.mm; sourceTree = "<group>"; };
+ 5C1579F327179FD900ED5280 /* DaemonUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DaemonUtilities.h; sourceTree = "<group>"; };
+ 5C1579F92717AF5000ED5280 /* DaemonUtilities.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DaemonUtilities.mm; sourceTree = "<group>"; };
+ 5C1579FA2717AF5000ED5280 /* DaemonUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DaemonUtilities.h; sourceTree = "<group>"; };
+ 5C157A0B2717CA1C00ED5280 /* WebPushDaemonMain.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebPushDaemonMain.mm; sourceTree = "<group>"; };
5C19A51E1FD0B14600EEA323 /* URLSchemeTaskParameters.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = URLSchemeTaskParameters.cpp; sourceTree = "<group>"; };
5C19A51F1FD0B14700EEA323 /* URLSchemeTaskParameters.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = URLSchemeTaskParameters.h; sourceTree = "<group>"; };
5C1B38DF2667140700B1545B /* WebPageNetworkParameters.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebPageNetworkParameters.h; sourceTree = "<group>"; };
@@ -6529,6 +6545,7 @@
0867D691FE84028FC02AAC07 /* WebKit2 */ = {
isa = PBXGroup;
children = (
+ 5C157A0A2717C9F100ED5280 /* webpushd */,
B396EA5512E0ED2D00F4FEB7 /* config.h */,
2D7DEBE021269D5F00B9F73C /* Sources.txt */,
2D7DEBE121269D5F00B9F73C /* SourcesCocoa.txt */,
@@ -6918,6 +6935,7 @@
1AAF0C4712B16328008E49E2 /* cf */,
C01A25FF12662F2100C9ED55 /* cg */,
37C4C0901814B37B003688B9 /* cocoa */,
+ 5C1579F82717AF2200ED5280 /* Daemon */,
51E351C2180F2C8500E53BE9 /* Databases */,
BC82836816B3587900A278FE /* EntryPointUtilities */,
E170877216D6CFEC00F99226 /* FileAPI */,
@@ -9511,6 +9529,23 @@
path = Cocoa;
sourceTree = "<group>";
};
+ 5C1579F82717AF2200ED5280 /* Daemon */ = {
+ isa = PBXGroup;
+ children = (
+ 5C1579FA2717AF5000ED5280 /* DaemonUtilities.h */,
+ 5C1579F92717AF5000ED5280 /* DaemonUtilities.mm */,
+ );
+ path = Daemon;
+ sourceTree = "<group>";
+ };
+ 5C157A0A2717C9F100ED5280 /* webpushd */ = {
+ isa = PBXGroup;
+ children = (
+ 5C157A0B2717CA1C00ED5280 /* WebPushDaemonMain.mm */,
+ );
+ path = webpushd;
+ sourceTree = "<group>";
+ };
5C5CEC372209581B00D6BBB0 /* Daemon */ = {
isa = PBXGroup;
children = (
@@ -9553,11 +9588,12 @@
isa = PBXGroup;
children = (
5CAF7AA526F93A950003F19E /* adattributiond.c */,
+ 5C1579F327179FD900ED5280 /* DaemonUtilities.h */,
+ 5C1579F227179FD800ED5280 /* DaemonUtilities.mm */,
5C6289A827068EC000CF5EC6 /* PCMDaemonConnectionSet.h */,
5C6289A927068EC000CF5EC6 /* PCMDaemonConnectionSet.mm */,
5CB9310426E837FC0032B1C0 /* PCMDaemonEntryPoint.h */,
5CB9310526E837FD0032B1C0 /* PCMDaemonEntryPoint.mm */,
- 5C1579DB27165B7500ED5280 /* webpushd.c */,
);
name = Daemon;
path = Cocoa/Daemon;
@@ -12023,6 +12059,7 @@
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
+ 5C1579FC2717AF5000ED5280 /* DaemonUtilities.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -13598,6 +13635,7 @@
buildRules = (
);
dependencies = (
+ DFBD8A3C2718B38C00BEC5B0 /* PBXTargetDependency */,
5C1579CF27165B2F00ED5280 /* PBXTargetDependency */,
);
name = webpushd;
@@ -14557,7 +14595,11 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
- 5C1579DC27165B8200ED5280 /* webpushd.c in Sources */,
+ 5C157A012717B7FB00ED5280 /* ArgumentCoders.cpp in Sources */,
+ 5C1579FF2717B6D200ED5280 /* DaemonDecoder.cpp in Sources */,
+ 5C1579FE2717B6C100ED5280 /* DaemonEncoder.cpp in Sources */,
+ 5C1579FB2717AF5000ED5280 /* DaemonUtilities.mm in Sources */,
+ 5C157A0C2717CA1D00ED5280 /* WebPushDaemonMain.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -15206,6 +15248,11 @@
target = CD95493426159004008372D9 /* WebKitSwift */;
targetProxy = CD0C36DC2639D3B4004E35D8 /* PBXContainerItemProxy */;
};
+ DFBD8A3C2718B38C00BEC5B0 /* PBXTargetDependency */ = {
+ isa = PBXTargetDependency;
+ target = 8DC2EF4F0486A6940098B216 /* WebKit */;
+ targetProxy = DFBD8A3B2718B38C00BEC5B0 /* PBXContainerItemProxy */;
+ };
DFEE369A26FAD112007C78E0 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = 8DC2EF4F0486A6940098B216 /* WebKit */;
Added: trunk/Source/WebKit/webpushd/WebPushDaemonMain.mm (0 => 284203)
--- trunk/Source/WebKit/webpushd/WebPushDaemonMain.mm (rev 0)
+++ trunk/Source/WebKit/webpushd/WebPushDaemonMain.mm 2021-10-14 22:32:37 UTC (rev 284203)
@@ -0,0 +1,122 @@
+/*
+ * Copyright (C) 2021 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 "DaemonConnection.h"
+#import "DaemonDecoder.h"
+#import "DaemonEncoder.h"
+#import "DaemonUtilities.h"
+#import <Foundation/Foundation.h>
+#import <wtf/MainThread.h>
+#import <wtf/Span.h>
+#import <wtf/spi/darwin/XPCSPI.h>
+
+namespace WebPushD {
+
+constexpr const char* protocolVersionKey = "protocol version";
+constexpr uint64_t protocolVersionValue = 1;
+constexpr const char* protocolMessageTypeKey = "message type";
+constexpr const char* protocolEncodedMessageKey = "encoded message";
+enum class MessageType : uint8_t {
+ EchoTwice = 1
+};
+
+static CompletionHandler<void(Vector<uint8_t>&&)> replySender(RetainPtr<xpc_object_t>&& request)
+{
+ return [request = WTFMove(request)] (Vector<uint8_t>&& message) {
+ auto reply = adoptNS(xpc_dictionary_create_reply(request.get()));
+ ASSERT(xpc_get_type(reply.get()) == XPC_TYPE_DICTIONARY);
+ xpc_dictionary_set_uint64(reply.get(), protocolVersionKey, protocolVersionValue);
+ xpc_dictionary_set_value(reply.get(), protocolEncodedMessageKey, WebKit::vectorToXPCData(WTFMove(message)).get());
+ xpc_connection_send_message(xpc_dictionary_get_remote_connection(request.get()), reply.get());
+ };
+}
+
+static void echoTwice(Span<const uint8_t> encodedMessage, CompletionHandler<void(Vector<uint8_t>&&)>&& replySender)
+{
+ WebKit::Daemon::Decoder decoder(encodedMessage);
+ std::optional<String> string;
+ decoder >> string;
+ if (!string)
+ return;
+
+ auto reply = makeString(*string, *string);
+ WebKit::Daemon::Encoder encoder;
+ encoder << reply;
+ replySender(encoder.takeBuffer());
+}
+
+static void decodeMessageAndSendReply(MessageType messageType, Span<const uint8_t> encodedMessage, CompletionHandler<void(Vector<uint8_t>&&)>&& replySender)
+{
+ switch (messageType) {
+ case MessageType::EchoTwice:
+ echoTwice(encodedMessage, WTFMove(replySender));
+ return;
+ }
+}
+
+static void connectionEventHandler(xpc_object_t request)
+{
+ if (xpc_get_type(request) != XPC_TYPE_DICTIONARY)
+ return;
+ if (xpc_dictionary_get_uint64(request, protocolVersionKey) != protocolVersionValue) {
+ NSLog(@"Received request that was not the current protocol version");
+ return;
+ }
+
+ auto messageType { static_cast<MessageType>(xpc_dictionary_get_uint64(request, protocolMessageTypeKey)) };
+ size_t dataSize { 0 };
+ const void* data = "" protocolEncodedMessageKey, &dataSize);
+ Span<const uint8_t> encodedMessage { static_cast<const uint8_t*>(data), dataSize };
+ decodeMessageAndSendReply(messageType, encodedMessage, replySender(request));
+}
+
+static void connectionAdded(xpc_connection_t)
+{
+}
+
+static void connectionRemoved(xpc_connection_t)
+{
+}
+
+} // namespace WebPushD
+
+int main(int argc, const char** argv)
+{
+ if (argc != 3 || strcmp(argv[1], "--machServiceName")) {
+ NSLog(@"usage: webpushd --machServiceName <name>");
+ return -1;
+ }
+ const char* machServiceName = argv[2];
+
+ @autoreleasepool {
+ // FIXME: Add a sandbox.
+ // FIXME: Add an entitlement check.
+ WebKit::startListeningForMachServiceConnections(machServiceName, nullptr, WebPushD::connectionAdded, WebPushD::connectionRemoved, WebPushD::connectionEventHandler);
+ WTF::initializeMainThread();
+ }
+ CFRunLoopRun();
+ return 0;
+}
Modified: trunk/Tools/ChangeLog (284202 => 284203)
--- trunk/Tools/ChangeLog 2021-10-14 22:28:10 UTC (rev 284202)
+++ trunk/Tools/ChangeLog 2021-10-14 22:32:37 UTC (rev 284203)
@@ -1,3 +1,28 @@
+2021-10-14 Alex Christensen <[email protected]>
+
+ Share IPC communication code between webpushd and adattributiond
+ https://bugs.webkit.org/show_bug.cgi?id=231718
+
+ Reviewed by Brady Eidson.
+
+ * TestWebKitAPI/SourcesCocoa.txt:
+ * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+ * TestWebKitAPI/Tests/WebKitCocoa/EventAttribution.mm:
+ (TestWebKitAPI::testDaemonPList):
+ (TestWebKitAPI::currentExecutableLocation): Deleted.
+ (TestWebKitAPI::currentExecutableDirectory): Deleted.
+ * TestWebKitAPI/Tests/WebKitCocoa/WebPushDaemon.mm: Added.
+ (TestWebKitAPI::testWebPushDaemonLocation):
+ (TestWebKitAPI::testWebPushDaemonPList):
+ (TestWebKitAPI::setUpTestWebPushD):
+ (TestWebKitAPI::cleanUpTestWebPushD):
+ (TestWebKitAPI::TEST):
+ * TestWebKitAPI/cocoa/DaemonTestUtilities.h: Renamed from Source/WebKit/Shared/EntryPointUtilities/Cocoa/Daemon/webpushd.c.
+ * TestWebKitAPI/cocoa/DaemonTestUtilities.mm: Added.
+ (TestWebKitAPI::currentExecutableLocation):
+ (TestWebKitAPI::currentExecutableDirectory):
+ (TestWebKitAPI::registerPlistWithLaunchD):
+
2021-10-14 Wenson Hsieh <[email protected]>
[JS IPC] Make it possible to establish a stream connection using the JS IPC testing API
Modified: trunk/Tools/TestWebKitAPI/SourcesCocoa.txt (284202 => 284203)
--- trunk/Tools/TestWebKitAPI/SourcesCocoa.txt 2021-10-14 22:28:10 UTC (rev 284202)
+++ trunk/Tools/TestWebKitAPI/SourcesCocoa.txt 2021-10-14 22:32:37 UTC (rev 284203)
@@ -24,6 +24,7 @@
EditingTestHarness.mm
WKWebViewConfigurationExtras.mm
+cocoa/DaemonTestUtilities.mm
cocoa/PlatformUtilitiesCocoa.mm
cocoa/TestCocoa.mm
cocoa/TestDownloadDelegate.mm
@@ -40,3 +41,4 @@
Tests/WebKitCocoa/TestAwakener.mm
Tests/WebKitCocoa/TLSDeprecation.mm
Tests/WebKitCocoa/WebSocket.mm
+Tests/WebKitCocoa/WebPushDaemon.mm
Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (284202 => 284203)
--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2021-10-14 22:28:10 UTC (rev 284202)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2021-10-14 22:32:37 UTC (rev 284203)
@@ -2366,6 +2366,9 @@
5C0BF88C1DD5957400B00328 /* MemoryPressureHandler.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MemoryPressureHandler.mm; sourceTree = "<group>"; };
5C0BF88F1DD5999B00B00328 /* WebViewCanPasteZeroPng.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebViewCanPasteZeroPng.mm; sourceTree = "<group>"; };
5C121E8C2410703200486F9B /* ContentWorldPlugIn.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ContentWorldPlugIn.mm; sourceTree = "<group>"; };
+ 5C157A022717C3B100ED5280 /* WebPushDaemon.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebPushDaemon.mm; sourceTree = "<group>"; };
+ 5C157A072717C56600ED5280 /* DaemonTestUtilities.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = DaemonTestUtilities.mm; path = cocoa/DaemonTestUtilities.mm; sourceTree = "<group>"; };
+ 5C157A082717C56600ED5280 /* DaemonTestUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DaemonTestUtilities.h; path = cocoa/DaemonTestUtilities.h; sourceTree = "<group>"; };
5C16F8FB230C942B0074C4A8 /* TextSize.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = TextSize.mm; sourceTree = "<group>"; };
5C19A5231FD0F32600EEA323 /* CookiePrivateBrowsing.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CookiePrivateBrowsing.mm; sourceTree = "<group>"; };
5C23DF0A2245C9D700F454B6 /* Challenge.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = Challenge.mm; sourceTree = "<group>"; };
@@ -3333,6 +3336,8 @@
A13EBB441B87332B00097110 /* WebProcessPlugIn */,
F44A530F21B8976900DBB99C /* ClassMethodSwizzler.h */,
F44A530E21B8976900DBB99C /* ClassMethodSwizzler.mm */,
+ 5C157A082717C56600ED5280 /* DaemonTestUtilities.h */,
+ 5C157A072717C56600ED5280 /* DaemonTestUtilities.mm */,
F47DFB2721A885E700021FB6 /* DataDetectorsCoreSPI.h */,
F46128B4211C861A00D9FADB /* DragAndDropSimulator.h */,
F44D06481F3962E3001A0E29 /* EditingTestHarness.h */,
@@ -3687,6 +3692,7 @@
5C973F5B1F58EF0A00359C27 /* WebGLPolicy.mm */,
51714EB61CF8C7A4004723C4 /* WebProcessKillIDBCleanup.mm */,
C1D8EE212028E8E3008EB141 /* WebProcessTerminate.mm */,
+ 5C157A022717C3B100ED5280 /* WebPushDaemon.mm */,
5120C83C1E6750790025B250 /* WebsiteDataStoreCustomPaths.mm */,
5C9E56841DF9143D00C9EE33 /* WebsitePolicies.mm */,
DF8A2E41267BEFAB00ED59DF /* WebSocket.mm */,
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/EventAttribution.mm (284202 => 284203)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/EventAttribution.mm 2021-10-14 22:28:10 UTC (rev 284202)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/EventAttribution.mm 2021-10-14 22:32:37 UTC (rev 284203)
@@ -25,6 +25,7 @@
#import "config.h"
+#import "DaemonTestUtilities.h"
#import "HTTPServer.h"
#import "PlatformUtilities.h"
#import "Test.h"
@@ -43,8 +44,6 @@
#import <WebKit/WKWebsiteDataStorePrivate.h>
#import <WebKit/_WKInspector.h>
#import <WebKit/_WKWebsiteDataStoreConfiguration.h>
-#import <mach-o/dyld.h>
-#import <wtf/OSObjectPtr.h>
#import <wtf/spi/darwin/XPCSPI.h>
#if HAVE(RSA_BSSA)
@@ -381,23 +380,6 @@
// FIXME: Get this working in the iOS simulator.
#if PLATFORM(MAC)
-static RetainPtr<NSURL> currentExecutableLocation()
-{
- uint32_t size { 0 };
- _NSGetExecutablePath(nullptr, &size);
- Vector<char> buffer;
- buffer.resize(size + 1);
- _NSGetExecutablePath(buffer.data(), &size);
- buffer[size] = '\0';
- auto pathString = adoptNS([[NSString alloc] initWithUTF8String:buffer.data()]);
- return adoptNS([[NSURL alloc] initFileURLWithPath:pathString.get() isDirectory:NO]);
-}
-
-static RetainPtr<NSURL> currentExecutableDirectory()
-{
- return [currentExecutableLocation() URLByDeletingLastPathComponent];
-}
-
static RetainPtr<NSURL> testPCMDaemonLocation()
{
return [currentExecutableDirectory() URLByAppendingPathComponent:@"adattributiond" isDirectory:NO];
@@ -405,9 +387,9 @@
#if HAVE(OS_LAUNCHD_JOB)
-static OSObjectPtr<xpc_object_t> testDaemonPList(NSURL *storageLocation)
+static RetainPtr<xpc_object_t> testDaemonPList(NSURL *storageLocation)
{
- auto plist = adoptOSObject(xpc_dictionary_create(nullptr, nullptr, 0));
+ auto plist = adoptNS(xpc_dictionary_create(nullptr, nullptr, 0));
xpc_dictionary_set_string(plist.get(), "_ManagedBy", "TestWebKitAPI");
xpc_dictionary_set_string(plist.get(), "Label", "org.webkit.pcmtestdaemon");
xpc_dictionary_set_bool(plist.get(), "LaunchOnlyOnce", true);
@@ -414,17 +396,17 @@
xpc_dictionary_set_string(plist.get(), "StandardErrorPath", [storageLocation URLByAppendingPathComponent:@"daemon_stderr"].path.fileSystemRepresentation);
{
- auto environmentVariables = adoptOSObject(xpc_dictionary_create(nullptr, nullptr, 0));
+ auto environmentVariables = adoptNS(xpc_dictionary_create(nullptr, nullptr, 0));
xpc_dictionary_set_string(environmentVariables.get(), "DYLD_FRAMEWORK_PATH", currentExecutableDirectory().get().fileSystemRepresentation);
xpc_dictionary_set_value(plist.get(), "EnvironmentVariables", environmentVariables.get());
}
{
- auto machServices = adoptOSObject(xpc_dictionary_create(nullptr, nullptr, 0));
+ auto machServices = adoptNS(xpc_dictionary_create(nullptr, nullptr, 0));
xpc_dictionary_set_bool(machServices.get(), "org.webkit.pcmtestdaemon.service", true);
xpc_dictionary_set_value(plist.get(), "MachServices", machServices.get());
}
{
- auto programArguments = adoptOSObject(xpc_array_create(nullptr, 0));
+ auto programArguments = adoptNS(xpc_array_create(nullptr, 0));
auto executableLocation = testPCMDaemonLocation();
xpc_array_set_string(programArguments.get(), XPC_ARRAY_APPEND, executableLocation.get().fileSystemRepresentation);
xpc_array_set_string(programArguments.get(), XPC_ARRAY_APPEND, "--machServiceName");
@@ -436,7 +418,7 @@
return plist;
}
-#else
+#else // HAVE(OS_LAUNCHD_JOB)
static RetainPtr<NSDictionary> testDaemonPList(NSURL *storageLocation)
{
@@ -456,7 +438,7 @@
};
}
-#endif
+#endif // HAVE(OS_LAUNCHD_JOB)
static std::pair<NSURL *, WKWebViewConfiguration *> setUpDaemon(WKWebViewConfiguration *viewConfiguration)
{
@@ -471,20 +453,10 @@
auto plist = testDaemonPList(tempDir);
#if HAVE(OS_LAUNCHD_JOB)
- auto launchDJob = adoptNS([[OSLaunchdJob alloc] initWithPlist:plist.get()]);
- [launchDJob submit:&error];
+ registerPlistWithLaunchD(WTFMove(plist));
#else
- NSURL *plistLocation = [tempDir URLByAppendingPathComponent:@"DaemonInfo.plist"];
- BOOL success = [fileManager createDirectoryAtURL:tempDir withIntermediateDirectories:YES attributes:nil error:&error];
- EXPECT_TRUE(success);
- EXPECT_NULL(error);
- success = [plist writeToURL:plistLocation error:&error];
- EXPECT_TRUE(success);
- system([NSString stringWithFormat:@"launchctl unload %@ 2> /dev/null", plistLocation.path].fileSystemRepresentation);
- system([NSString stringWithFormat:@"launchctl load %@", plistLocation.path].fileSystemRepresentation);
+ registerPlistWithLaunchD(WTFMove(plist), tempDir);
#endif
- EXPECT_NULL(error);
-
auto dataStoreConfiguration = adoptNS([_WKWebsiteDataStoreConfiguration new]);
dataStoreConfiguration.get().pcmMachServiceName = @"org.webkit.pcmtestdaemon.service";
viewConfiguration.websiteDataStore = adoptNS([[WKWebsiteDataStore alloc] _initWithConfiguration:dataStoreConfiguration.get()]).get();
Added: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebPushDaemon.mm (0 => 284203)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebPushDaemon.mm (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebPushDaemon.mm 2021-10-14 22:32:37 UTC (rev 284203)
@@ -0,0 +1,152 @@
+/*
+ * Copyright (C) 2021 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 "DaemonTestUtilities.h"
+
+namespace TestWebKitAPI {
+
+// FIXME: Get this working in the iOS simulator.
+#if PLATFORM(MAC)
+
+static RetainPtr<NSURL> testWebPushDaemonLocation()
+{
+ return [currentExecutableDirectory() URLByAppendingPathComponent:@"webpushd" isDirectory:NO];
+}
+
+#if HAVE(OS_LAUNCHD_JOB)
+
+static RetainPtr<xpc_object_t> testWebPushDaemonPList(NSURL *storageLocation)
+{
+ auto plist = adoptNS(xpc_dictionary_create(nullptr, nullptr, 0));
+ xpc_dictionary_set_string(plist.get(), "_ManagedBy", "TestWebKitAPI");
+ xpc_dictionary_set_string(plist.get(), "Label", "org.webkit.webpushtestdaemon");
+ xpc_dictionary_set_bool(plist.get(), "LaunchOnlyOnce", true);
+ xpc_dictionary_set_string(plist.get(), "StandardErrorPath", [storageLocation URLByAppendingPathComponent:@"daemon_stderr"].path.fileSystemRepresentation);
+
+ {
+ auto environmentVariables = adoptNS(xpc_dictionary_create(nullptr, nullptr, 0));
+ xpc_dictionary_set_string(environmentVariables.get(), "DYLD_FRAMEWORK_PATH", currentExecutableDirectory().get().fileSystemRepresentation);
+ xpc_dictionary_set_value(plist.get(), "EnvironmentVariables", environmentVariables.get());
+ }
+ {
+ auto machServices = adoptNS(xpc_dictionary_create(nullptr, nullptr, 0));
+ xpc_dictionary_set_bool(machServices.get(), "org.webkit.webpushtestdaemon.service", true);
+ xpc_dictionary_set_value(plist.get(), "MachServices", machServices.get());
+ }
+ {
+ auto programArguments = adoptNS(xpc_array_create(nullptr, 0));
+ auto executableLocation = testWebPushDaemonLocation();
+ xpc_array_set_string(programArguments.get(), XPC_ARRAY_APPEND, executableLocation.get().fileSystemRepresentation);
+ xpc_array_set_string(programArguments.get(), XPC_ARRAY_APPEND, "--machServiceName");
+ xpc_array_set_string(programArguments.get(), XPC_ARRAY_APPEND, "org.webkit.webpushtestdaemon.service");
+ xpc_dictionary_set_value(plist.get(), "ProgramArguments", programArguments.get());
+ }
+ return plist;
+}
+
+#else // HAVE(OS_LAUNCHD_JOB)
+
+static RetainPtr<NSDictionary> testWebPushDaemonPList(NSURL *storageLocation)
+{
+ return @{
+ @"Label" : @"org.webkit.pcmtestdaemon",
+ @"LaunchOnlyOnce" : @YES,
+ @"StandardErrorPath" : [storageLocation URLByAppendingPathComponent:@"daemon_stderr"].path,
+ @"EnvironmentVariables" : @{ @"DYLD_FRAMEWORK_PATH" : currentExecutableDirectory().get().path },
+ @"MachServices" : @{ @"org.webkit.webpushtestdaemon.service" : @YES },
+ @"ProgramArguments" : @[
+ testWebPushDaemonLocation().get().path,
+ @"--machServiceName",
+ @"org.webkit.webpushtestdaemon.service"
+ ]
+ };
+}
+
+#endif // HAVE(OS_LAUNCHD_JOB)
+
+static NSURL *setUpTestWebPushD()
+{
+ NSFileManager *fileManager = [NSFileManager defaultManager];
+ NSURL *tempDir = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"WebPushDaemonTest"] isDirectory:YES];
+ NSError *error = nil;
+ if ([fileManager fileExistsAtPath:tempDir.path])
+ [fileManager removeItemAtURL:tempDir error:&error];
+ EXPECT_NULL(error);
+
+ system("killall webpushd -9 2> /dev/null");
+
+ auto plist = testWebPushDaemonPList(tempDir);
+#if HAVE(OS_LAUNCHD_JOB)
+ registerPlistWithLaunchD(WTFMove(plist));
+#else
+ registerPlistWithLaunchD(WTFMove(plist), tempDir);
+#endif
+
+ return tempDir;
+}
+
+static void cleanUpTestWebPushD(NSURL *tempDir)
+{
+ system("killall webpushd -9");
+
+ EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:tempDir.path]);
+ NSError *error = nil;
+ [[NSFileManager defaultManager] removeItemAtURL:tempDir error:&error];
+ EXPECT_NULL(error);
+}
+
+TEST(WebPushD, BasicCommunication)
+{
+ NSURL *tempDir = setUpTestWebPushD();
+
+ auto connection = adoptNS(xpc_connection_create_mach_service("org.webkit.webpushtestdaemon.service", dispatch_get_main_queue(), 0));
+ xpc_connection_set_event_handler(connection.get(), ^(xpc_object_t) { });
+ xpc_connection_activate(connection.get());
+ auto dictionary = adoptNS(xpc_dictionary_create(nullptr, nullptr, 0));
+
+ std::array<uint8_t, 10> encodedString { 5, 0, 0, 0, 1, 'h', 'e', 'l', 'l', 'o' };
+ xpc_dictionary_set_uint64(dictionary.get(), "protocol version", 1);
+ xpc_dictionary_set_uint64(dictionary.get(), "message type", 1);
+ xpc_dictionary_set_data(dictionary.get(), "encoded message", encodedString.data(), encodedString.size());
+
+ __block bool done = false;
+ xpc_connection_send_message_with_reply(connection.get(), dictionary.get(), dispatch_get_main_queue(), ^(xpc_object_t reply) {
+ size_t dataSize = 0;
+ const void* data = "" "encoded message", &dataSize);
+ EXPECT_EQ(dataSize, 15u);
+ std::array<uint8_t, 15> expectedReply { 10, 0, 0, 0, 1, 'h', 'e', 'l', 'l', 'o' , 'h', 'e', 'l', 'l', 'o' };
+ EXPECT_FALSE(memcmp(data, expectedReply.data(), expectedReply.size()));
+ done = true;
+ });
+ TestWebKitAPI::Util::run(&done);
+
+ cleanUpTestWebPushD(tempDir);
+}
+
+#endif // PLATFORM(MAC)
+
+} // namespace TestWebKitAPI
Copied: trunk/Tools/TestWebKitAPI/cocoa/DaemonTestUtilities.h (from rev 284202, trunk/Source/WebKit/Shared/EntryPointUtilities/Cocoa/Daemon/webpushd.c) (0 => 284203)
--- trunk/Tools/TestWebKitAPI/cocoa/DaemonTestUtilities.h (rev 0)
+++ trunk/Tools/TestWebKitAPI/cocoa/DaemonTestUtilities.h 2021-10-14 22:32:37 UTC (rev 284203)
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2021 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
+
+#import <wtf/RetainPtr.h>
+#import <wtf/spi/darwin/XPCSPI.h>
+
+@class NSDictionary;
+@class NSURL;
+
+namespace TestWebKitAPI {
+
+RetainPtr<NSURL> currentExecutableDirectory();
+
+#if HAVE(OS_LAUNCHD_JOB)
+void registerPlistWithLaunchD(RetainPtr<xpc_object_t>&&);
+#else
+void registerPlistWithLaunchD(RetainPtr<NSDictionary>&&, NSURL *tempDir);
+#endif
+
+} // namespace TestWebKitAPI
Added: trunk/Tools/TestWebKitAPI/cocoa/DaemonTestUtilities.mm (0 => 284203)
--- trunk/Tools/TestWebKitAPI/cocoa/DaemonTestUtilities.mm (rev 0)
+++ trunk/Tools/TestWebKitAPI/cocoa/DaemonTestUtilities.mm 2021-10-14 22:32:37 UTC (rev 284203)
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2021 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 "DaemonTestUtilities.h"
+
+#import <mach-o/dyld.h>
+#import <wtf/Vector.h>
+
+namespace TestWebKitAPI {
+
+static RetainPtr<NSURL> currentExecutableLocation()
+{
+ uint32_t size { 0 };
+ _NSGetExecutablePath(nullptr, &size);
+ Vector<char> buffer;
+ buffer.resize(size + 1);
+ _NSGetExecutablePath(buffer.data(), &size);
+ buffer[size] = '\0';
+ auto pathString = adoptNS([[NSString alloc] initWithUTF8String:buffer.data()]);
+ return adoptNS([[NSURL alloc] initFileURLWithPath:pathString.get() isDirectory:NO]);
+}
+
+RetainPtr<NSURL> currentExecutableDirectory()
+{
+ return [currentExecutableLocation() URLByDeletingLastPathComponent];
+}
+
+#if HAVE(OS_LAUNCHD_JOB)
+
+void registerPlistWithLaunchD(RetainPtr<xpc_object_t>&& plist)
+{
+ NSError *error = nil;
+ auto launchDJob = adoptNS([[OSLaunchdJob alloc] initWithPlist:plist.get()]);
+ [launchDJob submit:&error];
+ EXPECT_FALSE(error);
+}
+
+#else // HAVE(OS_LAUNCHD_JOB)
+
+void registerPlistWithLaunchD(RetainPtr<NSDictionary>&& plist, NSURL *tempDir)
+{
+ NSError *error = nil;
+ NSURL *plistLocation = [tempDir URLByAppendingPathComponent:@"DaemonInfo.plist"];
+ BOOL success = [[NSFileManager defaultManager] createDirectoryAtURL:tempDir withIntermediateDirectories:YES attributes:nil error:&error];
+ EXPECT_TRUE(success);
+ EXPECT_FALSE(error);
+ success = [plist writeToURL:plistLocation error:&error];
+ EXPECT_TRUE(success);
+ system([NSString stringWithFormat:@"launchctl unload %@ 2> /dev/null", plistLocation.path].fileSystemRepresentation);
+ system([NSString stringWithFormat:@"launchctl load %@", plistLocation.path].fileSystemRepresentation);
+ EXPECT_FALSE(error);
+}
+
+#endif // HAVE(OS_LAUNCHD_JOB)
+
+} // namespace TestWebKitAPI