Changeset 283559 in webkit
- Timestamp:
- Oct 5, 2021, 11:12:24 AM (4 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 1 deleted
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r283522 r283559 1 2021-10-05 Alex Christensen <achristensen@webkit.org> 2 3 Implement missing functions in PrivateClickMeasurementDaemonClient 4 https://bugs.webkit.org/show_bug.cgi?id=231060 5 6 Reviewed by Chris Dumez. 7 8 Enable debug mode in the daemon if any connected clients have debug mode enabled. 9 Broadcast debug messages to all clients, which will then broadcast them to all web processes. 10 Add an API test that turns it on then off and checks that the debug messages make it all the way to the inspector. 11 12 * NetworkProcess/NetworkSession.cpp: 13 (WebKit::managerOrProxy): 14 (WebKit::NetworkSession::setPrivateClickMeasurementDebugMode): 15 * NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementConnection.cpp: 16 (WebKit::PCM::ConnectionToMachService::ConnectionToMachService): 17 (WebKit::PCM::ConnectionToMachService::send const): 18 (WebKit::PCM::ConnectionToMachService::sendWithReply const): 19 (WebKit::PCM::Connection::Connection): Deleted. 20 (WebKit::PCM::Connection::send const): Deleted. 21 (WebKit::PCM::Connection::sendWithReply const): Deleted. 22 * NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementConnection.h: 23 (WebKit::PCM::Connection::Connection): 24 (WebKit::PCM::Connection::get const): 25 * NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementDaemonClient.cpp: 26 (WebKit::PCM::DaemonClient::broadcastConsoleMessage): 27 (WebKit::PCM::DaemonClient::debugModeEnabled const): 28 * NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementManager.cpp: 29 (WebKit::PrivateClickMeasurementManager::setDebugModeIsEnabled): 30 * NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementManager.h: 31 * NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementManagerInterface.cpp: 32 (WebKit::PCM::messageTypeSendsReply): 33 (WebKit::PCM::handlePCMMessageSetDebugModeIsEnabled): 34 (WebKit::PCM::decodeMessageAndSendToManager): 35 * NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementManagerInterface.h: 36 * NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementManagerProxy.cpp: 37 (WebKit::PCM::ManagerProxy::ManagerProxy): 38 (WebKit::PCM::ManagerProxy::setDebugModeIsEnabled): 39 * NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementManagerProxy.h: 40 * NetworkProcess/PrivateClickMeasurement/cocoa/PrivateClickMeasurementConnectionCocoa.mm: Renamed from Source/WebKit/NetworkProcess/PrivateClickMeasurement/cocoa/PrivateClickMeasurementDaemonConnectionCocoa.mm. 41 (WebKit::PCM::ConnectionToMachService::initializeConnectionIfNeeded const): 42 (WebKit::PCM::ConnectionToMachService::sendDebugModeIsEnabledMessageIfNecessary const): 43 (WebKit::PCM::ConnectionToMachService::checkForDebugMessageBroadcast const): 44 (WebKit::PCM::Connection::send const): 45 (WebKit::PCM::Connection::sendWithReply const): 46 (WebKit::PCM::ConnectionToMachService::send const): 47 (WebKit::PCM::ConnectionToMachService::sendWithReply const): 48 * Shared/EntryPointUtilities/Cocoa/Daemon/PCMDaemonConnectionSet.h: Copied from Source/WebKit/NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementConnection.h. 49 * Shared/EntryPointUtilities/Cocoa/Daemon/PCMDaemonConnectionSet.mm: Added. 50 (WebKit::PCM::DaemonConnectionSet::singleton): 51 (WebKit::PCM::DaemonConnectionSet::add): 52 (WebKit::PCM::DaemonConnectionSet::remove): 53 (WebKit::PCM::DaemonConnectionSet::setConnectedNetworkProcessHasDebugModeEnabled): 54 (WebKit::PCM::DaemonConnectionSet::debugModeEnabled const): 55 (WebKit::PCM::DaemonConnectionSet::broadcastConsoleMessage): 56 * Shared/EntryPointUtilities/Cocoa/Daemon/PCMDaemonEntryPoint.mm: 57 (WebKit::connectionEventHandler): 58 (WebKit::startListeningForMachServiceConnections): 59 (WebKit::peers): Deleted. 60 * SourcesCocoa.txt: 61 * UIProcess/API/Cocoa/WKWebsiteDataStore.mm: 62 (-[WKWebsiteDataStore _setPrivateClickMeasurementDebugModeEnabledForTesting:]): 63 * UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h: 64 * WebKit.xcodeproj/project.pbxproj: 65 1 66 2021-10-04 Chris Dumez <cdumez@apple.com> 2 67 -
trunk/Source/WebKit/NetworkProcess/NetworkSession.cpp
r283504 r283559 99 99 { 100 100 if (!parameters.pcmMachServiceName.isEmpty()) 101 return makeUniqueRef<PCM::ManagerProxy>(parameters.pcmMachServiceName );101 return makeUniqueRef<PCM::ManagerProxy>(parameters.pcmMachServiceName, networkSession); 102 102 return makeUniqueRef<PrivateClickMeasurementManager>(makeUniqueRef<PCM::ClientImpl>(networkSession, networkProcess), pcmStoreDirectory(networkSession, parameters.resourceLoadStatisticsParameters.directory, parameters.resourceLoadStatisticsParameters.privateClickMeasurementStorageDirectory)); 103 103 } … … 428 428 429 429 m_privateClickMeasurementDebugModeEnabled = enabled; 430 431 auto message = enabled ? "[Private Click Measurement] Turned Debug Mode on."_s : "[Private Click Measurement] Turned Debug Mode off."_s; 432 m_networkProcess->broadcastConsoleMessage(sessionID(), MessageSource::PrivateClickMeasurement, MessageLevel::Info, message); 430 m_privateClickMeasurement->setDebugModeIsEnabled(enabled); 433 431 } 434 432 -
trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementConnection.cpp
r282368 r283559 33 33 namespace PCM { 34 34 35 ConnectionToMachService::ConnectionToMachService(CString&& machServiceName, NetworkSession& networkSession) 36 : m_machServiceName(WTFMove(machServiceName)) 37 , m_networkSession(makeWeakPtr(networkSession)) { } 38 35 39 #if !PLATFORM(COCOA) 36 40 37 Connection::Connection(CString&&) 41 void ConnectionToMachService::send(MessageType, EncodedMessage&&) const 38 42 { 39 43 notImplemented(); 40 44 } 41 45 42 void Connection::send(MessageType, EncodedMessage&&) const 43 { 44 notImplemented(); 45 } 46 47 void Connection::sendWithReply(MessageType, EncodedMessage&&, CompletionHandler<void(EncodedMessage&&)>&& completionHandler) const 46 void ConnectionToMachService::sendWithReply(MessageType, EncodedMessage&&, CompletionHandler<void(EncodedMessage&&)>&& completionHandler) const 48 47 { 49 48 notImplemented(); -
trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementConnection.h
r282430 r283559 29 29 #include <wtf/Vector.h> 30 30 #include <wtf/WeakPtr.h> 31 #include <wtf/text/CString.h> 31 32 32 33 #if PLATFORM(COCOA) 33 #include <wtf/ OSObjectPtr.h>34 #include <wtf/RetainPtr.h> 34 35 #include <wtf/spi/darwin/XPCSPI.h> 35 36 #endif 36 37 37 38 namespace WebKit { 39 40 class NetworkSession; 38 41 39 42 namespace PCM { … … 44 47 class Connection : public CanMakeWeakPtr<Connection> { 45 48 public: 46 explicit Connection(CString&& machServiceName); 49 Connection() = default; 50 #if PLATFORM(COCOA) 51 explicit Connection(RetainPtr<xpc_connection_t>&& connection) 52 : m_connection(WTFMove(connection)) { } 53 xpc_connection_t get() const { return m_connection.get(); } 54 void send(xpc_object_t) const; 55 void sendWithReply(xpc_object_t, CompletionHandler<void(xpc_object_t)>&&) const; 56 protected: 57 mutable RetainPtr<xpc_connection_t> m_connection; 58 #endif 59 }; 60 61 class ConnectionToMachService : public Connection { 62 public: 63 ConnectionToMachService(CString&& machServiceName, NetworkSession&); 47 64 48 65 void send(MessageType, EncodedMessage&&) const; … … 50 67 51 68 private: 69 void initializeConnectionIfNeeded() const; 52 70 #if PLATFORM(COCOA) 53 void initializeConnectionIfNeeded() const; 71 void checkForDebugMessageBroadcast(xpc_object_t) const; 72 #endif 73 void sendDebugModeIsEnabledMessageIfNecessary() const; 54 74 55 75 const CString m_machServiceName; 56 mutable OSObjectPtr<xpc_connection_t> m_connection; 57 #endif 76 WeakPtr<NetworkSession> m_networkSession; 58 77 }; 59 78 -
trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementDaemonClient.cpp
r282230 r283559 27 27 #include "PrivateClickMeasurementDaemonClient.h" 28 28 29 #include <WebCore/NotImplemented.h> 29 #if PLATFORM(COCOA) 30 #include "PCMDaemonConnectionSet.h" 31 #endif 30 32 31 33 namespace WebKit { … … 33 35 namespace PCM { 34 36 35 void DaemonClient::broadcastConsoleMessage(JSC::MessageLevel , const String&)37 void DaemonClient::broadcastConsoleMessage(JSC::MessageLevel level, const String& message) 36 38 { 37 notImplemented(); 39 #if PLATFORM(COCOA) 40 DaemonConnectionSet::singleton().broadcastConsoleMessage(level, message); 41 #else 42 UNUSED_PARAM(level); 43 UNUSED_PARAM(message); 44 #endif 38 45 } 39 46 … … 45 52 bool DaemonClient::debugModeEnabled() const 46 53 { 47 notImplemented(); 54 #if PLATFORM(COCOA) 55 return DaemonConnectionSet::singleton().debugModeEnabled(); 56 #else 48 57 return false; 58 #endif 49 59 } 50 60 -
trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementManager.cpp
r283383 r283559 228 228 } 229 229 230 void PrivateClickMeasurementManager::setDebugModeIsEnabled(bool enabled) 231 { 232 // This doesn't maintain global state, it just broadcasts a message when debug mode enabled changes. 233 // The state is either stored in NetworkSession when not using the daemon 234 // or in DaemonConnectionSet per-connection when using the daemon. 235 236 auto message = enabled ? "[Private Click Measurement] Turned Debug Mode on."_s : "[Private Click Measurement] Turned Debug Mode off."_s; 237 m_client->broadcastConsoleMessage(MessageLevel::Info, message); 238 } 239 230 240 void PrivateClickMeasurementManager::handleAttribution(AttributionTriggerData&& attributionTriggerData, const URL& requestURL, WebCore::RegistrableDomain&& redirectDomain, const URL& firstPartyURL, const ApplicationBundleIdentifier& applicationBundleIdentifier) 231 241 { -
trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementManager.h
r283383 r283559 53 53 void clearForRegistrableDomain(const RegistrableDomain&, CompletionHandler<void()>&&) final; 54 54 void migratePrivateClickMeasurementFromLegacyStorage(PrivateClickMeasurement&&, PrivateClickMeasurementAttributionType) final; 55 void setDebugModeIsEnabled(bool) final; 55 56 56 57 void toStringForTesting(CompletionHandler<void(String)>&&) const final; -
trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementManagerInterface.cpp
r283383 r283559 35 35 #include "WebCoreArgumentCoders.h" 36 36 37 #if PLATFORM(COCOA) 38 #include "PCMDaemonConnectionSet.h" 39 #endif 40 37 41 namespace WebKit { 38 42 … … 68 72 FUNCTION(migratePrivateClickMeasurementFromLegacyStorage) 69 73 ARGUMENTS(WebCore::PrivateClickMeasurement, PrivateClickMeasurementAttributionType) 74 END 75 76 FUNCTION(setDebugModeIsEnabled) 77 ARGUMENTS(bool) 70 78 END 71 79 … … 148 156 case MessageType::HandleAttribution: 149 157 case MessageType::MigratePrivateClickMeasurementFromLegacyStorage: 158 case MessageType::SetDebugModeIsEnabled: 150 159 case MessageType::SetOverrideTimerForTesting: 151 160 case MessageType::SetTokenPublicKeyURLForTesting: … … 201 210 } 202 211 212 static void handlePCMMessageSetDebugModeIsEnabled(const Connection& connection, PCM::EncodedMessage&& encodedMessage) 213 { 214 #if PLATFORM(COCOA) 215 PCM::Decoder decoder(WTFMove(encodedMessage)); 216 std::optional<bool> enabled; 217 decoder >> enabled; 218 if (UNLIKELY(!enabled)) 219 return; 220 221 auto& connectionSet = DaemonConnectionSet::singleton(); 222 bool debugModeWasEnabled = connectionSet.debugModeEnabled(); 223 connectionSet.setConnectedNetworkProcessHasDebugModeEnabled(connection, *enabled); 224 if (debugModeWasEnabled != connectionSet.debugModeEnabled()) 225 daemonManager().setDebugModeIsEnabled(*enabled); 226 #else 227 UNUSED_PARAM(connection); 228 UNUSED_PARAM(encodedMessage); 229 #endif 230 } 231 203 232 template<typename Info> 204 233 void handlePCMMessageWithReply(PCM::EncodedMessage&& encodedMessage, CompletionHandler<void(PCM::EncodedMessage&&)>&& replySender) … … 218 247 } 219 248 220 void decodeMessageAndSendToManager( MessageType messageType, Vector<uint8_t>&& encodedMessage, CompletionHandler<void(Vector<uint8_t>&&)>&& replySender)249 void decodeMessageAndSendToManager(const Connection& connection, MessageType messageType, Vector<uint8_t>&& encodedMessage, CompletionHandler<void(Vector<uint8_t>&&)>&& replySender) 221 250 { 222 251 ASSERT(messageTypeSendsReply(messageType) == !!replySender); … … 234 263 handlePCMMessageWithReply<MessageInfo::clearForRegistrableDomain>(WTFMove(encodedMessage), WTFMove(replySender)); 235 264 break; 265 case PCM::MessageType::SetDebugModeIsEnabled: 266 handlePCMMessageSetDebugModeIsEnabled(connection, WTFMove(encodedMessage)); 267 break; 236 268 case PCM::MessageType::MigratePrivateClickMeasurementFromLegacyStorage: 237 269 handlePCMMessage<MessageInfo::migratePrivateClickMeasurementFromLegacyStorage>(WTFMove(encodedMessage)); -
trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementManagerInterface.h
r283383 r283559 42 42 namespace PCM { 43 43 44 class Connection; 45 44 46 class ManagerInterface { 45 47 public: … … 58 60 virtual void clearForRegistrableDomain(const RegistrableDomain&, CompletionHandler<void()>&&) = 0; 59 61 virtual void migratePrivateClickMeasurementFromLegacyStorage(PrivateClickMeasurement&&, PrivateClickMeasurementAttributionType) = 0; 62 virtual void setDebugModeIsEnabled(bool) = 0; 60 63 61 64 virtual void toStringForTesting(CompletionHandler<void(String)>&&) const = 0; … … 76 79 constexpr uint64_t protocolVersionValue { 1 }; 77 80 81 constexpr const char* protocolDebugMessageLevelKey { "debug message level" }; 82 constexpr const char* protocolDebugMessageKey { "debug message" }; 83 78 84 constexpr const char* protocolMessageTypeKey { "message type" }; 79 85 enum class MessageType : uint8_t { … … 83 89 ClearForRegistrableDomain, 84 90 MigratePrivateClickMeasurementFromLegacyStorage, 91 SetDebugModeIsEnabled, 85 92 ToStringForTesting, 86 93 SetOverrideTimerForTesting, … … 100 107 using EncodedMessage = Vector<uint8_t>; 101 108 102 void decodeMessageAndSendToManager( MessageType, Vector<uint8_t>&& message, CompletionHandler<void(Vector<uint8_t>&&)>&&);109 void decodeMessageAndSendToManager(const Connection&, MessageType, Vector<uint8_t>&& message, CompletionHandler<void(Vector<uint8_t>&&)>&&); 103 110 bool messageTypeSendsReply(MessageType); 104 111 … … 119 126 WebKit::PCM::MessageType::ClearForRegistrableDomain, 120 127 WebKit::PCM::MessageType::MigratePrivateClickMeasurementFromLegacyStorage, 128 WebKit::PCM::MessageType::SetDebugModeIsEnabled, 121 129 WebKit::PCM::MessageType::ToStringForTesting, 122 130 WebKit::PCM::MessageType::SetOverrideTimerForTesting, -
trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementManagerProxy.cpp
r283383 r283559 73 73 } 74 74 75 ManagerProxy::ManagerProxy(const String& machServiceName )76 : m_connection(machServiceName.utf8() ) { }75 ManagerProxy::ManagerProxy(const String& machServiceName, NetworkSession& networkSession) 76 : m_connection(machServiceName.utf8(), networkSession) { } 77 77 78 78 void ManagerProxy::storeUnattributed(WebCore::PrivateClickMeasurement&& pcm, CompletionHandler<void()>&& completionHandler) … … 94 94 { 95 95 sendMessageWithReply<MessageType::ClearForRegistrableDomain>(WTFMove(completionHandler), domain); 96 } 97 98 void ManagerProxy::setDebugModeIsEnabled(bool enabled) 99 { 100 sendMessage<MessageType::SetDebugModeIsEnabled>(enabled); 96 101 } 97 102 -
trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementManagerProxy.h
r283383 r283559 33 33 namespace WebKit { 34 34 35 class NetworkSession; 36 35 37 namespace PCM { 36 38 … … 38 40 WTF_MAKE_FAST_ALLOCATED; 39 41 public: 40 ManagerProxy(const String& machServiceName );42 ManagerProxy(const String& machServiceName, NetworkSession&); 41 43 42 44 using ApplicationBundleIdentifier = String; … … 47 49 void clearForRegistrableDomain(const WebCore::RegistrableDomain&, CompletionHandler<void()>&&) final; 48 50 void migratePrivateClickMeasurementFromLegacyStorage(WebCore::PrivateClickMeasurement&&, PrivateClickMeasurementAttributionType) final; 51 void setDebugModeIsEnabled(bool) final; 49 52 50 53 void toStringForTesting(CompletionHandler<void(String)>&&) const final; … … 67 70 void sendMessageWithReply(CompletionHandler<void(ReplyArgs...)>&&, Args&&...) const; 68 71 69 Connection m_connection;72 ConnectionToMachService m_connection; 70 73 }; 71 74 -
trunk/Source/WebKit/Shared/EntryPointUtilities/Cocoa/Daemon/PCMDaemonEntryPoint.mm
r282368 r283559 27 27 #import "PCMDaemonEntryPoint.h" 28 28 29 #import "PCMDaemonConnectionSet.h" 29 30 #import "PrivateClickMeasurementConnection.h" 31 #import "PrivateClickMeasurementDecoder.h" 30 32 #import "PrivateClickMeasurementManagerInterface.h" 31 33 #import "PrivateClickMeasurementXPCUtilities.h" … … 43 45 44 46 namespace WebKit { 45 46 static HashSet<RetainPtr<xpc_connection_t>>& peers()47 {48 ASSERT(RunLoop::isMain());49 static NeverDestroyed<HashSet<RetainPtr<xpc_connection_t>>> set;50 return set.get();51 }52 47 53 48 static CompletionHandler<void(PCM::EncodedMessage&&)> replySender(PCM::MessageType messageType, OSObjectPtr<xpc_object_t>&& request) … … 75 70 const void* data = xpc_dictionary_get_data(request, PCM::protocolEncodedMessageKey, &dataSize); 76 71 PCM::EncodedMessage encodedMessage { static_cast<const uint8_t*>(data), dataSize }; 77 decodeMessageAndSendToManager( messageType, WTFMove(encodedMessage), replySender(messageType, request));72 decodeMessageAndSendToManager(PCM::Connection(xpc_dictionary_get_remote_connection(request)), messageType, WTFMove(encodedMessage), replySender(messageType, request)); 78 73 } 79 74 … … 92 87 if (event == XPC_ERROR_CONNECTION_INTERRUPTED) { 93 88 NSLog(@"removing peer connection %p", peer); 94 peers().remove(peer);89 PCM::DaemonConnectionSet::singleton().remove(peer); 95 90 return; 96 91 } … … 101 96 102 97 NSLog(@"adding peer connection %p", peer); 103 peers().add(peer);98 PCM::DaemonConnectionSet::singleton().add(peer); 104 99 }); 105 100 xpc_connection_activate(listener.get().get()); -
trunk/Source/WebKit/SourcesCocoa.txt
r283276 r283559 42 42 NetworkProcess/EntryPoint/Cocoa/XPCService/NetworkServiceEntryPoint.mm 43 43 44 NetworkProcess/PrivateClickMeasurement/cocoa/PrivateClickMeasurement DaemonConnectionCocoa.mm44 NetworkProcess/PrivateClickMeasurement/cocoa/PrivateClickMeasurementConnectionCocoa.mm 45 45 NetworkProcess/PrivateClickMeasurement/cocoa/PrivateClickMeasurementNetworkLoaderCocoa.mm 46 46 NetworkProcess/PrivateClickMeasurement/cocoa/PrivateClickMeasurementXPCUtilities.mm … … 194 194 Shared/Cocoa/WebPreferencesDefaultValuesCocoa.mm 195 195 196 Shared/EntryPointUtilities/Cocoa/Daemon/PCMDaemonConnectionSet.mm 196 197 Shared/EntryPointUtilities/Cocoa/Daemon/PCMDaemonEntryPoint.mm 197 198 -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm
r282429 r283559 659 659 } 660 660 661 - (void)_setPrivateClickMeasurementDebugModeEnabledForTesting:(BOOL)enabled 662 { 663 _websiteDataStore->setPrivateClickMeasurementDebugMode(enabled); 664 } 665 661 666 - (void)_appBoundDomains:(void (^)(NSArray<NSString *> *))completionHandler 662 667 { -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h
r282269 r283559 86 86 - (void)_allowTLSCertificateChain:(NSArray *)certificateChain forHost:(NSString *)host WK_API_AVAILABLE(macos(12.0), ios(15.0)); 87 87 - (void)_trustServerForLocalPCMTesting:(SecTrustRef)serverTrust WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA)); 88 - (void)_setPrivateClickMeasurementDebugModeEnabledForTesting:(BOOL)enabled WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA)); 88 89 89 90 - (void)_renameOrigin:(NSURL *)oldName to:(NSURL *)newName forDataOfTypes:(NSSet<NSString *> *)dataTypes completionHandler:(void (^)(void))completionHandler; -
trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj
r283276 r283559 4538 4538 5C5D2389227A1892000B9BDA /* _WKCustomHeaderFields.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKCustomHeaderFields.h; sourceTree = "<group>"; }; 4539 4539 5C5D238A227A1D9B000B9BDA /* APICustomHeaderFields.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APICustomHeaderFields.h; sourceTree = "<group>"; }; 4540 5C6289A827068EC000CF5EC6 /* PCMDaemonConnectionSet.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PCMDaemonConnectionSet.h; sourceTree = "<group>"; }; 4541 5C6289A927068EC000CF5EC6 /* PCMDaemonConnectionSet.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = PCMDaemonConnectionSet.mm; sourceTree = "<group>"; }; 4540 4542 5C62FDF81EFC263C00CE072E /* WKURLSchemeTaskPrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WKURLSchemeTaskPrivate.h; sourceTree = "<group>"; }; 4541 4543 5C66A4B32320961300EA4D44 /* WKHTTPCookieStoreRef.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKHTTPCookieStoreRef.cpp; sourceTree = "<group>"; }; … … 4601 4603 5CB930C126E054B80032B1C0 /* PrivateClickMeasurementClientImpl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PrivateClickMeasurementClientImpl.h; sourceTree = "<group>"; }; 4602 4604 5CB930F226E7EEE00032B1C0 /* PrivateClickMeasurementNetworkLoaderCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PrivateClickMeasurementNetworkLoaderCocoa.mm; sourceTree = "<group>"; }; 4603 5CB930F426E801E80032B1C0 /* PrivateClickMeasurement DaemonConnectionCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = PrivateClickMeasurementDaemonConnectionCocoa.mm; sourceTree = "<group>"; };4605 5CB930F426E801E80032B1C0 /* PrivateClickMeasurementConnectionCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = PrivateClickMeasurementConnectionCocoa.mm; sourceTree = "<group>"; }; 4604 4606 5CB930F526E802150032B1C0 /* PrivateClickMeasurementManagerProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PrivateClickMeasurementManagerProxy.h; sourceTree = "<group>"; }; 4605 4607 5CB930F626E802150032B1C0 /* PrivateClickMeasurementDaemonClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PrivateClickMeasurementDaemonClient.h; sourceTree = "<group>"; }; … … 9469 9471 isa = PBXGroup; 9470 9472 children = ( 9471 5CB930F426E801E80032B1C0 /* PrivateClickMeasurement DaemonConnectionCocoa.mm */,9473 5CB930F426E801E80032B1C0 /* PrivateClickMeasurementConnectionCocoa.mm */, 9472 9474 5CB930F226E7EEE00032B1C0 /* PrivateClickMeasurementNetworkLoaderCocoa.mm */, 9473 9475 5CB9310726E841CB0032B1C0 /* PrivateClickMeasurementXPCUtilities.h */, … … 9481 9483 children = ( 9482 9484 5CAF7AA526F93A950003F19E /* AdAttributionDaemon.c */, 9485 5C6289A827068EC000CF5EC6 /* PCMDaemonConnectionSet.h */, 9486 5C6289A927068EC000CF5EC6 /* PCMDaemonConnectionSet.mm */, 9483 9487 5CB9310426E837FC0032B1C0 /* PCMDaemonEntryPoint.h */, 9484 9488 5CB9310526E837FD0032B1C0 /* PCMDaemonEntryPoint.mm */, -
trunk/Tools/ChangeLog
r283553 r283559 1 2021-10-05 Alex Christensen <achristensen@webkit.org> 2 3 Implement missing functions in PrivateClickMeasurementDaemonClient 4 https://bugs.webkit.org/show_bug.cgi?id=231060 5 6 Reviewed by Chris Dumez. 7 8 * TestWebKitAPI/Tests/WebKitCocoa/EventAttribution.mm: 9 (TestWebKitAPI::testDaemonPList): 10 (TestWebKitAPI::cleanUpDaemon): 11 (TestWebKitAPI::TEST): 12 * TestWebKitAPI/cocoa/TestUIDelegate.h: 13 * TestWebKitAPI/cocoa/TestUIDelegate.mm: 14 (-[TestUIDelegate _webView:didAttachLocalInspector:]): 15 (-[TestUIDelegate waitForInspectorToShow]): 16 (-[WKWebView _test_waitForInspectorToShow]): 17 1 18 2021-10-05 David Kilzer <ddkilzer@apple.com> 2 19 -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/EventAttribution.mm
r283357 r283559 30 30 #import "Test.h" 31 31 #import "TestNavigationDelegate.h" 32 #import "TestUIDelegate.h" 32 33 #import "TestWKWebView.h" 33 34 #import "Utilities.h" 35 #import "WKWebViewConfigurationExtras.h" 34 36 #import <WebKit/WKMain.h> 37 #import <WebKit/WKPage.h> 38 #import <WebKit/WKPageInjectedBundleClient.h> 39 #import <WebKit/WKPreferencesPrivate.h> 40 #import <WebKit/WKString.h> 35 41 #import <WebKit/WKWebViewPrivate.h> 36 42 #import <WebKit/WKWebViewPrivateForTesting.h> 37 43 #import <WebKit/WKWebsiteDataStorePrivate.h> 44 #import <WebKit/_WKInspector.h> 38 45 #import <WebKit/_WKWebsiteDataStoreConfiguration.h> 39 46 #import <mach-o/dyld.h> … … 49 56 50 57 #endif // HAVE(RSA_BSSA) 58 59 @interface WKWebView () 60 - (WKPageRef)_pageForTesting; 61 @end 51 62 52 63 @interface MockEventAttribution : NSObject … … 111 122 } 112 123 113 void runBasic EventAttributionTest(WKWebViewConfiguration *configuration, Function<void(WKWebView *, const HTTPServer&)>&& addAttributionToWebView)124 void runBasicPCMTest(WKWebViewConfiguration *configuration, Function<void(WKWebView *, const HTTPServer&)>&& addAttributionToWebView) 114 125 { 115 126 clearState(); … … 164 175 165 176 #if HAVE(RSA_BSSA) 166 TEST( EventAttribution, FraudPrevention)177 TEST(PrivateClickMeasurement, FraudPrevention) 167 178 { 168 179 [WKWebsiteDataStore _setNetworkProcessSuspensionAllowedForTesting:NO]; … … 318 329 #endif 319 330 320 TEST( EventAttribution, Basic)321 { 322 runBasic EventAttributionTest(nil, [](WKWebView *webView, const HTTPServer& server) {331 TEST(PrivateClickMeasurement, Basic) 332 { 333 runBasicPCMTest(nil, [](WKWebView *webView, const HTTPServer& server) { 323 334 [webView _addEventAttributionWithSourceID:42 destinationURL:exampleURL() sourceDescription:@"test source description" purchaser:@"test purchaser" reportEndpoint:server.request().URL optionalNonce:nil applicationBundleID:@"test.bundle.id"]; 324 335 }); 325 336 } 326 337 327 TEST( EventAttribution, DatabaseLocation)338 TEST(PrivateClickMeasurement, DatabaseLocation) 328 339 { 329 340 NSFileManager *fileManager = [NSFileManager defaultManager]; … … 342 353 auto dataStore = adoptNS([[WKWebsiteDataStore alloc] _initWithConfiguration:dataStoreConfiguration.get()]); 343 354 viewConfiguration.get().websiteDataStore = dataStore.get(); 344 runBasic EventAttributionTest(viewConfiguration.get(), [](WKWebView *webView, const HTTPServer& server) {355 runBasicPCMTest(viewConfiguration.get(), [](WKWebView *webView, const HTTPServer& server) { 345 356 [webView _addEventAttributionWithSourceID:42 destinationURL:exampleURL() sourceDescription:@"test source description" purchaser:@"test purchaser" reportEndpoint:server.request().URL optionalNonce:nil applicationBundleID:@"test.bundle.id"]; 346 357 }); … … 401 412 xpc_dictionary_set_string(plist.get(), "Label", "org.webkit.pcmtestdaemon"); 402 413 xpc_dictionary_set_bool(plist.get(), "LaunchOnlyOnce", true); 414 xpc_dictionary_set_string(plist.get(), "StandardErrorPath", [storageLocation URLByAppendingPathComponent:@"daemon_stderr"].path.fileSystemRepresentation); 403 415 404 416 { … … 432 444 @"Label" : @"org.webkit.pcmtestdaemon", 433 445 @"LaunchOnlyOnce" : @YES, 446 @"StandardErrorPath" : [storageLocation URLByAppendingPathComponent:@"daemon_stderr"].path, 434 447 @"EnvironmentVariables" : @{ @"DYLD_FRAMEWORK_PATH" : currentExecutableDirectory().get().path }, 435 448 @"MachServices" : @{ @"org.webkit.pcmtestdaemon.service" : @YES }, … … 446 459 #endif 447 460 448 TEST(EventAttribution, Daemon)461 static std::pair<NSURL *, WKWebViewConfiguration *> setUpDaemon(WKWebViewConfiguration *viewConfiguration) 449 462 { 450 463 NSFileManager *fileManager = [NSFileManager defaultManager]; … … 468 481 success = [plist writeToURL:plistLocation error:&error]; 469 482 EXPECT_TRUE(success); 470 system([NSString stringWithFormat:@"launchctl load %@", plistLocation.path]. UTF8String);483 system([NSString stringWithFormat:@"launchctl load %@", plistLocation.path].fileSystemRepresentation); 471 484 #endif 472 485 EXPECT_NULL(error); … … 474 487 auto dataStoreConfiguration = adoptNS([_WKWebsiteDataStoreConfiguration new]); 475 488 dataStoreConfiguration.get().pcmMachServiceName = @"org.webkit.pcmtestdaemon.service"; 476 auto viewConfiguration = adoptNS([WKWebViewConfiguration new]); 477 viewConfiguration.get().websiteDataStore = adoptNS([[WKWebsiteDataStore alloc] _initWithConfiguration:dataStoreConfiguration.get()]).get(); 478 runBasicEventAttributionTest(viewConfiguration.get(), [](WKWebView *webView, const HTTPServer& server) { 489 viewConfiguration.websiteDataStore = adoptNS([[WKWebsiteDataStore alloc] _initWithConfiguration:dataStoreConfiguration.get()]).get(); 490 491 return std::make_pair(tempDir, viewConfiguration); 492 } 493 494 static void cleanUpDaemon(NSURL *tempDir) 495 { 496 system("killall AdAttributionDaemon -9"); 497 498 EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:tempDir.path]); 499 NSError *error = nil; 500 [[NSFileManager defaultManager] removeItemAtURL:tempDir error:&error]; 501 EXPECT_NULL(error); 502 } 503 504 TEST(PrivateClickMeasurement, DaemonBasicFunctionality) 505 { 506 auto [tempDir, configuration] = setUpDaemon(adoptNS([WKWebViewConfiguration new]).autorelease()); 507 runBasicPCMTest(configuration, [](WKWebView *webView, const HTTPServer& server) { 479 508 [webView _addEventAttributionWithSourceID:42 destinationURL:exampleURL() sourceDescription:@"test source description" purchaser:@"test purchaser" reportEndpoint:server.request().URL optionalNonce:nil applicationBundleID:@"test.bundle.id"]; 480 509 }); 481 482 system("killall AdAttributionDaemon -9"); 483 484 EXPECT_TRUE([fileManager fileExistsAtPath:tempDir.path]); 485 [fileManager removeItemAtURL:tempDir error:&error]; 486 EXPECT_NULL(error); 510 cleanUpDaemon(tempDir); 511 } 512 513 static void setInjectedBundleClient(WKWebView *webView, Vector<String>& consoleMessages) 514 { 515 WKPageInjectedBundleClientV0 injectedBundleClient = { 516 { 0, &consoleMessages }, 517 [] (WKPageRef, WKStringRef messageName, WKTypeRef message, const void* clientInfo) { 518 auto& consoleMessages = *reinterpret_cast<Vector<String>*>(const_cast<void*>(clientInfo)); 519 if (WKStringIsEqualToUTF8CString(messageName, "ConsoleMessage")) 520 consoleMessages.append(Util::toNS((WKStringRef)message)); 521 }, 522 nullptr, 523 }; 524 WKPageSetPageInjectedBundleClient(webView._pageForTesting, &injectedBundleClient.base); 525 }; 526 527 static RetainPtr<TestWKWebView> webViewWithOpenInspector(WKWebViewConfiguration *configuration) 528 { 529 configuration.preferences._developerExtrasEnabled = YES; 530 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSZeroRect configuration:configuration]); 531 [webView synchronouslyLoadHTMLString:@"start processes"]; 532 [[webView _inspector] show]; 533 [webView _test_waitForInspectorToShow]; 534 return webView; 535 } 536 537 TEST(PrivateClickMeasurement, DaemonDebugMode) 538 { 539 auto [tempDir, configuration] = setUpDaemon([WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"BundlePageConsoleMessage"]); 540 Vector<String> consoleMessages; 541 auto webView = webViewWithOpenInspector(configuration); 542 setInjectedBundleClient(webView.get(), consoleMessages); 543 [configuration.websiteDataStore _setPrivateClickMeasurementDebugModeEnabledForTesting:YES]; 544 while (consoleMessages.isEmpty()) 545 Util::spinRunLoop(); 546 EXPECT_WK_STREQ(consoleMessages[0], "[Private Click Measurement] Turned Debug Mode on."); 547 [configuration.websiteDataStore _setPrivateClickMeasurementDebugModeEnabledForTesting:NO]; 548 while (consoleMessages.size() < 2) 549 Util::spinRunLoop(); 550 EXPECT_WK_STREQ(consoleMessages[1], "[Private Click Measurement] Turned Debug Mode off."); 551 } 552 553 TEST(PrivateClickMeasurement, NetworkProcessDebugMode) 554 { 555 auto configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"BundlePageConsoleMessage"]; 556 Vector<String> consoleMessages; 557 auto webView = webViewWithOpenInspector(configuration); 558 setInjectedBundleClient(webView.get(), consoleMessages); 559 [configuration.websiteDataStore _setPrivateClickMeasurementDebugModeEnabledForTesting:YES]; 560 while (consoleMessages.isEmpty()) 561 Util::spinRunLoop(); 562 EXPECT_WK_STREQ(consoleMessages[0], "[Private Click Measurement] Turned Debug Mode on."); 563 [configuration.websiteDataStore _setPrivateClickMeasurementDebugModeEnabledForTesting:NO]; 564 while (consoleMessages.size() < 2) 565 Util::spinRunLoop(); 566 EXPECT_WK_STREQ(consoleMessages[1], "[Private Click Measurement] Turned Debug Mode off."); 487 567 } 488 568 … … 491 571 #if HAVE(UI_EVENT_ATTRIBUTION) 492 572 493 TEST( EventAttribution, BasicWithIOSSPI)494 { 495 runBasic EventAttributionTest(nil, [](WKWebView *webView, const HTTPServer& server) {573 TEST(PrivateClickMeasurement, BasicWithIOSSPI) 574 { 575 runBasicPCMTest(nil, [](WKWebView *webView, const HTTPServer& server) { 496 576 auto attribution = adoptNS([[MockEventAttribution alloc] initWithReportEndpoint:server.request().URL destinationURL:exampleURL()]); 497 577 webView._uiEventAttribution = (UIEventAttribution *)attribution.get(); … … 501 581 } 502 582 503 TEST( EventAttribution, BasicWithEphemeralIOSSPI)504 { 505 runBasic EventAttributionTest(nil, [](WKWebView *webView, const HTTPServer& server) {583 TEST(PrivateClickMeasurement, BasicWithEphemeralIOSSPI) 584 { 585 runBasicPCMTest(nil, [](WKWebView *webView, const HTTPServer& server) { 506 586 auto attribution = adoptNS([[MockEventAttribution alloc] initWithReportEndpoint:server.request().URL destinationURL:exampleURL()]); 507 587 webView._ephemeralUIEventAttribution = (UIEventAttribution *)attribution.get(); -
trunk/Tools/TestWebKitAPI/cocoa/TestUIDelegate.h
r270273 r283559 41 41 @interface WKWebView (TestUIDelegateExtras) 42 42 - (NSString *)_test_waitForAlert; 43 - (void)_test_waitForInspectorToShow; 43 44 @end -
trunk/Tools/TestWebKitAPI/cocoa/TestUIDelegate.mm
r270273 r283559 31 31 #import <wtf/RetainPtr.h> 32 32 33 @implementation TestUIDelegate 33 @implementation TestUIDelegate { 34 BOOL _showedInspector; 35 } 34 36 35 37 - (WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures … … 82 84 } 83 85 86 - (void)_webView:(WKWebView *)webView didAttachLocalInspector:(_WKInspector *)inspector 87 { 88 _showedInspector = YES; 89 } 90 91 - (void)waitForInspectorToShow 92 { 93 while (!_showedInspector) 94 TestWebKitAPI::Util::spinRunLoop(); 95 } 96 84 97 @end 85 98 … … 96 109 } 97 110 111 - (void)_test_waitForInspectorToShow 112 { 113 EXPECT_FALSE(self.UIDelegate); 114 auto uiDelegate = adoptNS([TestUIDelegate new]); 115 self.UIDelegate = uiDelegate.get(); 116 [uiDelegate waitForInspectorToShow]; 117 self.UIDelegate = nil; 118 } 119 98 120 @end
Note:
See TracChangeset
for help on using the changeset viewer.