Changeset 284887 in webkit
- Timestamp:
- Oct 26, 2021, 12:34:30 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 17 edited
- 5 copied
-
Source/WebKit/ChangeLog (modified) (1 diff)
-
Source/WebKit/NetworkProcess/Notifications/Cocoa (added)
-
Source/WebKit/NetworkProcess/Notifications/Cocoa/WebPushDaemonConnectionCocoa.mm (added)
-
Source/WebKit/NetworkProcess/Notifications/NetworkNotificationManager.cpp (modified) (1 diff)
-
Source/WebKit/NetworkProcess/Notifications/NetworkNotificationManager.h (modified) (3 diffs)
-
Source/WebKit/NetworkProcess/Notifications/WebPushDaemonConnection.cpp (copied) (copied from trunk/Source/WebKit/NetworkProcess/Notifications/NetworkNotificationManager.cpp ) (1 diff)
-
Source/WebKit/NetworkProcess/Notifications/WebPushDaemonConnection.h (copied) (copied from trunk/Source/WebKit/NetworkProcess/Notifications/NetworkNotificationManager.h ) (1 diff)
-
Source/WebKit/NetworkProcess/WebSocketTask.h (modified) (1 diff)
-
Source/WebKit/NetworkProcess/mac/com.apple.WebKit.NetworkProcess.sb.in (modified) (1 diff)
-
Source/WebKit/Platform/IPC/DaemonConnection.cpp (modified) (2 diffs)
-
Source/WebKit/Platform/IPC/DaemonConnection.h (modified) (1 diff)
-
Source/WebKit/Platform/IPC/cocoa/DaemonConnectionCocoa.mm (modified) (2 diffs)
-
Source/WebKit/Platform/Logging.h (modified) (1 diff)
-
Source/WebKit/Shared/WebPushDaemonConstants.h (copied) (copied from trunk/Source/WebKit/Platform/IPC/DaemonConnection.cpp ) (1 diff)
-
Source/WebKit/Sources.txt (modified) (1 diff)
-
Source/WebKit/SourcesCocoa.txt (modified) (1 diff)
-
Source/WebKit/UIProcess/WebsiteData/WebsiteDataStoreConfiguration.cpp (modified) (1 diff)
-
Source/WebKit/WebKit.xcodeproj/project.pbxproj (modified) (14 diffs)
-
Source/WebKit/webpushd/WebPushDaemon.h (copied) (copied from trunk/Source/WebKit/Platform/IPC/DaemonConnection.cpp ) (1 diff)
-
Source/WebKit/webpushd/WebPushDaemon.mm (copied) (copied from trunk/Source/WebKit/webpushd/WebPushDaemonMain.mm ) (2 diffs)
-
Source/WebKit/webpushd/WebPushDaemonMain.mm (modified) (1 diff)
-
Tools/ChangeLog (modified) (1 diff)
-
Tools/MiniBrowser/mac/AppDelegate.m (modified) (1 diff)
-
Tools/MiniBrowser/mac/WK2BrowserWindowController.m (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r284875 r284887 1 2021-10-26 Brady Eidson <beidson@apple.com> 2 3 Add helper classes and messaging infrastructure to launch webpushd and round trip a message to it 4 https://bugs.webkit.org/show_bug.cgi?id=232262 5 6 Reviewed by Alex Christensen. 7 8 No new tests (No behavior change yet) 9 10 This patch: 11 - Adds classes representing the WebPushDaemon and connections to it 12 - Adds classes/constants/macros related to messaging that daemon 13 - Adds SPI for configuring a connect to that daemon 14 - Gets MiniBrowser closer to supporting built-in notifications 15 - Has way more commented out code than usual for a patch, but that enables a great stopping-point milestone 16 17 * NetworkProcess/Notifications/Cocoa/WebPushDaemonConnectionCocoa.mm: Added. 18 (WebKit::WebPushD::addVersionAndEncodedMessageToDictionary): 19 (WebKit::WebPushD::Connection::newConnectionWasInitialized const): 20 (WebKit::WebPushD::Connection::connectionReceivedEvent const): 21 (WebKit::WebPushD::Connection::dictionaryFromMessage const): 22 23 * NetworkProcess/Notifications/NetworkNotificationManager.cpp: 24 (WebKit::NetworkNotificationManager::NetworkNotificationManager): 25 (WebKit::NetworkNotificationManager::showNotification): 26 (WebKit::NetworkNotificationManager::cancelNotification): 27 (WebKit::NetworkNotificationManager::clearNotifications): 28 (WebKit::NetworkNotificationManager::didDestroyNotification): 29 (WebKit::NetworkNotificationManager::sendMessage const): 30 (WebKit::ReplyCaller<>::callReply): 31 (WebKit::ReplyCaller<String>::callReply): 32 (WebKit::NetworkNotificationManager::sendMessageWithReply const): 33 * NetworkProcess/Notifications/NetworkNotificationManager.h: 34 (WebKit::NetworkNotificationManager::networkSession const): 35 36 * NetworkProcess/Notifications/WebPushDaemonConnection.cpp: Copied from Source/WebKit/Platform/IPC/DaemonConnection.cpp. 37 (WebKit::WebPushD::Connection::Connection): 38 (WebKit::WebPushD::Connection::networkSession const): 39 * NetworkProcess/Notifications/WebPushDaemonConnection.h: Copied from Source/WebKit/NetworkProcess/Notifications/NetworkNotificationManager.h. 40 41 * NetworkProcess/mac/com.apple.WebKit.NetworkProcess.sb.in: 42 43 * Platform/IPC/DaemonConnection.cpp: 44 * Platform/IPC/DaemonConnection.h: 45 (WebKit::Daemon::ConnectionToMachService::machServiceName const): 46 * Platform/IPC/cocoa/DaemonConnectionCocoa.mm: 47 48 * Platform/Logging.h: 49 50 * Shared/WebPushDaemonConstants.h: Copied from Source/WebKit/Platform/IPC/DaemonConnection.cpp. 51 (WebKit::WebPushD::messageTypeSendsReply): 52 53 * UIProcess/WebsiteData/WebsiteDataStoreConfiguration.cpp: 54 (WebKit::WebsiteDataStoreConfiguration::copy const): 55 56 * webpushd/WebPushDaemon.h: Copied from Source/WebKit/NetworkProcess/Notifications/NetworkNotificationManager.h. 57 * webpushd/WebPushDaemon.mm: Copied from Source/WebKit/webpushd/WebPushDaemonMain.mm. 58 (WebPushD::MessageInfo::echoTwice::encodeReply): 59 (WebPushD::handleWebPushDMessageWithReply): 60 (WebPushD::Daemon::singleton): 61 (WebPushD::Daemon::connectionEventHandler): 62 (WebPushD::Daemon::connectionAdded): 63 (WebPushD::Daemon::connectionRemoved): 64 (WebPushD::CompletionHandler<void): 65 (WebPushD::Daemon::decodeAndHandleMessage): 66 (WebPushD::Daemon::echoTwice): 67 68 * webpushd/WebPushDaemonMain.mm: 69 (WebPushD::connectionEventHandler): 70 (WebPushD::connectionAdded): 71 (WebPushD::connectionRemoved): 72 (WebPushD::CompletionHandler<void): Deleted. 73 (WebPushD::echoTwice): Deleted. 74 (WebPushD::decodeMessageAndSendReply): Deleted. 75 76 * Sources.txt: 77 * SourcesCocoa.txt: 78 * WebKit.xcodeproj/project.pbxproj: 79 1 80 2021-10-26 Kate Cheney <katherine_cheney@apple.com> 2 81 -
trunk/Source/WebKit/NetworkProcess/Notifications/NetworkNotificationManager.cpp
r284591 r284887 29 29 #if ENABLE(BUILT_IN_NOTIFICATIONS) 30 30 31 #include "DaemonDecoder.h" 32 #include "DaemonEncoder.h" 33 #include "NetworkSession.h" 34 31 35 namespace WebKit { 32 36 using namespace WebCore; 33 37 34 NetworkNotificationManager::NetworkNotificationManager(NetworkSession& networkSession, const String& )38 NetworkNotificationManager::NetworkNotificationManager(NetworkSession& networkSession, const String& webPushMachServiceName) 35 39 : m_networkSession(networkSession) 36 40 { 41 if (!m_networkSession.sessionID().isEphemeral() && !webPushMachServiceName.isEmpty()) 42 m_connection = makeUnique<WebPushD::Connection>(webPushMachServiceName.utf8(), *this); 37 43 } 38 44 39 45 void NetworkNotificationManager::showNotification(const String&, const String&, const String&, const String&, const String&, WebCore::NotificationDirection, const String&, uint64_t) 40 46 { 47 if (!m_connection) 48 return; 49 50 // FIXME: While we don't normally land commented-out code in the tree, 51 // this is a nice bookmark for a development milestone; Roundtrip communication with webpushd 52 // Will make next development steps obvious. 53 // 54 // CompletionHandler<void(String)>&& completionHandler = [] (String reply) { 55 // printf("Got reply: %s\n", reply.utf8().data()); 56 // }; 57 // 58 // sendMessageWithReply<WebPushD::MessageType::EchoTwice>(WTFMove(completionHandler), String("FIXME: Do useful work here")); 41 59 } 42 60 43 61 void NetworkNotificationManager::cancelNotification(uint64_t) 44 62 { 63 if (!m_connection) 64 return; 45 65 } 46 66 47 67 void NetworkNotificationManager::clearNotifications(const Vector<uint64_t>&) 48 68 { 69 if (!m_connection) 70 return; 49 71 } 50 72 51 73 void NetworkNotificationManager::didDestroyNotification(uint64_t) 52 74 { 75 if (!m_connection) 76 return; 77 } 78 79 80 template<WebPushD::MessageType messageType, typename... Args> 81 void NetworkNotificationManager::sendMessage(Args&&... args) const 82 { 83 RELEASE_ASSERT(m_connection); 84 Daemon::Encoder encoder; 85 encoder.encode(std::forward<Args>(args)...); 86 m_connection->send(messageType, encoder.takeBuffer()); 87 } 88 89 template<typename... Args> struct ReplyCaller; 90 template<> struct ReplyCaller<> { 91 static void callReply(Daemon::Decoder&& decoder, CompletionHandler<void()>&& completionHandler) 92 { 93 completionHandler(); 94 } 95 }; 96 template<> struct ReplyCaller<String> { 97 static void callReply(Daemon::Decoder&& decoder, CompletionHandler<void(String&&)>&& completionHandler) 98 { 99 std::optional<String> string; 100 decoder >> string; 101 if (!string) 102 return completionHandler({ }); 103 completionHandler(WTFMove(*string)); 104 } 105 }; 106 107 template<WebPushD::MessageType messageType, typename... Args, typename... ReplyArgs> 108 void NetworkNotificationManager::sendMessageWithReply(CompletionHandler<void(ReplyArgs...)>&& completionHandler, Args&&... args) const 109 { 110 RELEASE_ASSERT(m_connection); 111 112 Daemon::Encoder encoder; 113 encoder.encode(std::forward<Args>(args)...); 114 m_connection->sendWithReply(messageType, encoder.takeBuffer(), [completionHandler = WTFMove(completionHandler)] (auto replyBuffer) mutable { 115 Daemon::Decoder decoder(WTFMove(replyBuffer)); 116 ReplyCaller<ReplyArgs...>::callReply(WTFMove(decoder), WTFMove(completionHandler)); 117 }); 53 118 } 54 119 -
trunk/Source/WebKit/NetworkProcess/Notifications/NetworkNotificationManager.h
r284591 r284887 29 29 30 30 #include "NotificationManagerMessageHandler.h" 31 #include "WebPushDaemonConnection.h" 31 32 #include <WebCore/NotificationDirection.h> 32 33 #include <wtf/text/WTFString.h> 33 34 34 35 namespace WebKit { 36 37 namespace WebPushD { 38 enum class MessageType : uint8_t; 39 } 35 40 36 41 class NetworkSession; … … 39 44 WTF_MAKE_FAST_ALLOCATED; 40 45 friend class NetworkSession; 46 public: 47 NetworkSession& networkSession() const { return m_networkSession; } 48 41 49 private: 42 50 NetworkNotificationManager(NetworkSession&, const String& webPushMachServiceName); … … 48 56 49 57 NetworkSession& m_networkSession; 58 std::unique_ptr<WebPushD::Connection> m_connection; 59 60 template<WebPushD::MessageType messageType, typename... Args> 61 void sendMessage(Args&&...) const; 62 template<WebPushD::MessageType messageType, typename... Args, typename... ReplyArgs> 63 void sendMessageWithReply(CompletionHandler<void(ReplyArgs...)>&&, Args&&...) const; 50 64 }; 51 65 -
trunk/Source/WebKit/NetworkProcess/Notifications/WebPushDaemonConnection.cpp
r284886 r284887 25 25 26 26 #include "config.h" 27 #include " NetworkNotificationManager.h"27 #include "WebPushDaemonConnection.h" 28 28 29 29 #if ENABLE(BUILT_IN_NOTIFICATIONS) 30 30 31 namespace WebKit { 32 using namespace WebCore; 31 #include "DaemonDecoder.h" 32 #include "DaemonEncoder.h" 33 #include "NetworkSession.h" 33 34 34 NetworkNotificationManager::NetworkNotificationManager(NetworkSession& networkSession, const String&) 35 : m_networkSession(networkSession) 35 namespace WebKit::WebPushD { 36 37 Connection::Connection(CString&& machServiceName, NetworkNotificationManager& manager) 38 : Daemon::ConnectionToMachService<ConnectionTraits>(WTFMove(machServiceName)) 39 , m_notificationManager(manager) 36 40 { 41 LOG(Push, "Creating WebPushD connection to mach service: %s", this->machServiceName().data()); 37 42 } 38 43 39 void NetworkNotificationManager::showNotification(const String&, const String&, const String&, const String&, const String&, WebCore::NotificationDirection, const String&, uint64_t) 44 NetworkSession& Connection::networkSession() const 40 45 { 46 return m_notificationManager.networkSession(); 41 47 } 42 48 43 void NetworkNotificationManager::cancelNotification(uint64_t) 44 { 45 } 49 } // namespace WebKit::WebPushD 46 50 47 void NetworkNotificationManager::clearNotifications(const Vector<uint64_t>&)48 {49 }50 51 void NetworkNotificationManager::didDestroyNotification(uint64_t)52 {53 }54 55 } // namespace WebKit56 51 #endif // ENABLE(BUILT_IN_NOTIFICATIONS) -
trunk/Source/WebKit/NetworkProcess/Notifications/WebPushDaemonConnection.h
r284886 r284887 28 28 #if ENABLE(BUILT_IN_NOTIFICATIONS) 29 29 30 #include "NotificationManagerMessageHandler.h" 31 #include <WebCore/NotificationDirection.h> 32 #include <wtf/text/WTFString.h> 30 #include "DaemonConnection.h" 31 #include "WebPushDaemonConstants.h" 33 32 34 33 namespace WebKit { 35 34 35 class NetworkNotificationManager; 36 36 class NetworkSession; 37 37 38 class NetworkNotificationManager : public NotificationManagerMessageHandler { 39 WTF_MAKE_FAST_ALLOCATED; 40 friend class NetworkSession; 41 private: 42 NetworkNotificationManager(NetworkSession&, const String& webPushMachServiceName); 38 namespace WebPushD { 43 39 44 void showNotification(const String& title, const String& body, const String& iconURL, const String& tag, const String& lang, WebCore::NotificationDirection, const String& originString, uint64_t notificationID) final; 45 void cancelNotification(uint64_t notificationID) final; 46 void clearNotifications(const Vector<uint64_t>& notificationIDs) final; 47 void didDestroyNotification(uint64_t notificationID) final; 48 49 NetworkSession& m_networkSession; 40 struct ConnectionTraits { 41 using MessageType = WebPushD::MessageType; 42 static constexpr const char* protocolVersionKey { WebPushD::protocolVersionKey }; 43 static constexpr uint64_t protocolVersionValue { WebPushD::protocolVersionValue }; 44 static constexpr const char* protocolEncodedMessageKey { WebPushD::protocolEncodedMessageKey }; 50 45 }; 51 46 47 class Connection : public Daemon::ConnectionToMachService<ConnectionTraits> { 48 WTF_MAKE_FAST_ALLOCATED; 49 public: 50 Connection(CString&& machServiceName, NetworkNotificationManager&); 51 52 private: 53 void newConnectionWasInitialized() const final; 54 #if PLATFORM(COCOA) 55 RetainPtr<xpc_object_t> dictionaryFromMessage(MessageType, Daemon::EncodedMessage&&) const final; 56 void connectionReceivedEvent(xpc_object_t) const final; 57 #endif 58 void sendDebugModeIsEnabledMessageIfNecessary() const; 59 60 NetworkSession& networkSession() const; 61 62 NetworkNotificationManager& m_notificationManager; 63 64 template<MessageType messageType, typename... Args> 65 void sendMessage(Args&&...) const; 66 template<MessageType messageType, typename... Args, typename... ReplyArgs> 67 void sendMessageWithReply(CompletionHandler<void(ReplyArgs...)>&&, Args&&...) const; 68 }; 69 70 } // namespace WebPushD 52 71 } // namespace WebKit 53 72 54 73 #endif // ENABLE(BUILT_IN_NOTIFICATIONS) 74 -
trunk/Source/WebKit/NetworkProcess/WebSocketTask.h
r279340 r284887 32 32 #else 33 33 34 #include "DataReference.h" 35 34 36 namespace WebKit { 35 37 -
trunk/Source/WebKit/NetworkProcess/mac/com.apple.WebKit.NetworkProcess.sb.in
r284277 r284887 369 369 (allow mach-lookup (with telemetry) (global-name "com.apple.webkit.adattributiond.service")) 370 370 (allow mach-lookup (with telemetry) (global-name "org.webkit.pcmtestdaemon.service")) 371 372 (allow mach-lookup (with telemetry) (global-name "com.apple.webkit.webpushd.service")) 373 (allow mach-lookup (with telemetry) (global-name "org.webkit.webpushtestdaemon.service")) 371 374 372 375 (with-filter (uid 0) -
trunk/Source/WebKit/Platform/IPC/DaemonConnection.cpp
r284129 r284887 28 28 29 29 #include "PrivateClickMeasurementConnection.h" 30 #include "WebPushDaemonConnection.h" 30 31 31 32 namespace WebKit { … … 48 49 template class ConnectionToMachService<PCM::ConnectionTraits>; 49 50 51 #if ENABLE(BUILT_IN_NOTIFICATIONS) 52 template class ConnectionToMachService<WebPushD::ConnectionTraits>; 50 53 #endif 54 55 #endif // !PLATFORM(COCOA) 51 56 52 57 } // namespace Daemon -
trunk/Source/WebKit/Platform/IPC/DaemonConnection.h
r284129 r284887 72 72 #endif 73 73 74 const CString& machServiceName() const { return m_machServiceName; } 75 74 76 private: 75 77 void initializeConnectionIfNeeded() const; -
trunk/Source/WebKit/Platform/IPC/cocoa/DaemonConnectionCocoa.mm
r284823 r284887 29 29 #import "DaemonEncoder.h" 30 30 #import "PrivateClickMeasurementConnection.h" 31 #import "WebPushDaemonConnection.h" 31 32 #import <wtf/BlockPtr.h> 32 33 #import <wtf/RunLoop.h> … … 113 114 template class ConnectionToMachService<PCM::ConnectionTraits>; 114 115 116 #if ENABLE(BUILT_IN_NOTIFICATIONS) 117 template class ConnectionToMachService<WebPushD::ConnectionTraits>; 118 #endif 119 115 120 } // namespace Daemon 116 121 -
trunk/Source/WebKit/Platform/Logging.h
r282115 r284887 88 88 M(ProcessSwapping) \ 89 89 M(ProximityNetworking) \ 90 M(Push) \ 90 91 M(RemoteLayerTree) \ 91 92 M(Resize) \ -
trunk/Source/WebKit/Shared/WebPushDaemonConstants.h
r284886 r284887 24 24 */ 25 25 26 #include "config.h" 27 #include "DaemonConnection.h" 26 #pragma once 28 27 29 #include "PrivateClickMeasurementConnection.h" 28 namespace WebKit::WebPushD { 30 29 31 namespace WebKit { 30 constexpr const char* protocolVersionKey = "protocol version"; 31 constexpr uint64_t protocolVersionValue = 1; 32 constexpr const char* protocolEncodedMessageKey = "encoded message"; 32 33 33 namespace Daemon { 34 constexpr const char* protocolDebugMessageKey { "debug message" }; 35 constexpr const char* protocolDebugMessageLevelKey { "debug message level" }; 34 36 35 #if !PLATFORM(COCOA) 37 constexpr const char* protocolMessageTypeKey { "message type" }; 38 enum class MessageType : uint8_t { 39 EchoTwice = 1, 40 }; 36 41 37 template<typename Traits> 38 void ConnectionToMachService<Traits>::send(typename Traits::MessageType, EncodedMessage&&) const 42 inline bool messageTypeSendsReply(MessageType messageType) 39 43 { 44 switch (messageType) { 45 case MessageType::EchoTwice: 46 return true; 47 } 48 ASSERT_NOT_REACHED(); 49 return false; 40 50 } 41 51 42 template<typename Traits> 43 void ConnectionToMachService<Traits>::sendWithReply(typename Traits::MessageType, EncodedMessage&&, CompletionHandler<void(EncodedMessage&&)>&& completionHandler) const 44 { 45 completionHandler({ }); 46 } 47 48 template class ConnectionToMachService<PCM::ConnectionTraits>; 49 50 #endif 51 52 } // namespace Daemon 53 54 } // namespace WebKit 52 } // namespace WebKit::WebPushD -
trunk/Source/WebKit/Sources.txt
r284591 r284887 99 99 100 100 NetworkProcess/Notifications/NetworkNotificationManager.cpp 101 NetworkProcess/Notifications/WebPushDaemonConnection.cpp 101 102 102 103 NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementClientImpl.cpp -
trunk/Source/WebKit/SourcesCocoa.txt
r284444 r284887 41 41 NetworkProcess/EntryPoint/Cocoa/Daemon/DaemonEntryPoint.mm 42 42 NetworkProcess/EntryPoint/Cocoa/XPCService/NetworkServiceEntryPoint.mm 43 44 NetworkProcess/Notifications/Cocoa/WebPushDaemonConnectionCocoa.mm 43 45 44 46 NetworkProcess/PrivateClickMeasurement/cocoa/PrivateClickMeasurementConnectionCocoa.mm -
trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStoreConfiguration.cpp
r284661 r284887 106 106 copy->m_allowsHSTSWithUntrustedRootCertificate = this->m_allowsHSTSWithUntrustedRootCertificate; 107 107 copy->m_pcmMachServiceName = this->m_pcmMachServiceName; 108 copy->m_webPushMachServiceName = this->m_webPushMachServiceName; 108 109 #if PLATFORM(COCOA) 109 110 if (m_proxyConfiguration) -
trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj
r284662 r284887 1036 1036 512935E41288D97800A4B695 /* InjectedBundlePageContextMenuClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 512935E21288D97800A4B695 /* InjectedBundlePageContextMenuClient.h */; }; 1037 1037 5129EB1223D0DE7B00AF1CD7 /* ContentWorldShared.h in Headers */ = {isa = PBXBuildFile; fileRef = 5129EB1123D0DE7800AF1CD7 /* ContentWorldShared.h */; }; 1038 512CD6982721EFC800F7F8EC /* WebPushDaemonConnection.h in Headers */ = {isa = PBXBuildFile; fileRef = 512CD6972721EFC300F7F8EC /* WebPushDaemonConnection.h */; }; 1039 512CD69A2721F0A900F7F8EC /* WebPushDaemonConstants.h in Headers */ = {isa = PBXBuildFile; fileRef = 512CD6992721F04900F7F8EC /* WebPushDaemonConstants.h */; }; 1040 512CD69F2723393A00F7F8EC /* WebPushDaemon.h in Headers */ = {isa = PBXBuildFile; fileRef = 512CD69D2723393A00F7F8EC /* WebPushDaemon.h */; }; 1041 512CD6A02723393A00F7F8EC /* WebPushDaemon.mm in Sources */ = {isa = PBXBuildFile; fileRef = 512CD69E2723393A00F7F8EC /* WebPushDaemon.mm */; }; 1038 1042 512E34E5130B4D0500ABD19A /* WKApplicationCacheManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 517A33B4130B308C00F80CB5 /* WKApplicationCacheManager.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1039 1043 512ECC3527196ADB00089B66 /* PrivateClickMeasurementConnection.h in Headers */ = {isa = PBXBuildFile; fileRef = 5CB930FE26E802160032B1C0 /* PrivateClickMeasurementConnection.h */; }; … … 1056 1060 513FFB91201459C6002596EA /* WebMessagePortChannelProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 513FFB8F201459C2002596EA /* WebMessagePortChannelProvider.h */; }; 1057 1061 514129941C6428BB0059E714 /* WebIDBConnectionToServer.h in Headers */ = {isa = PBXBuildFile; fileRef = 514129921C6428100059E714 /* WebIDBConnectionToServer.h */; }; 1062 514526ED271E1647000467B6 /* NetworkNotificationManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 514526EB271E1626000467B6 /* NetworkNotificationManager.h */; }; 1058 1063 514526FF271FB7EC000467B6 /* NotificationManagerMessageHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 514526FE271FB7E8000467B6 /* NotificationManagerMessageHandler.h */; }; 1059 1064 51452703271FBA3A000467B6 /* NotificationManagerMessageHandlerMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51452702271FBA36000467B6 /* NotificationManagerMessageHandlerMessageReceiver.cpp */; }; … … 1061 1066 51452705271FBA40000467B6 /* NotificationManagerMessageHandlerMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = 51452701271FBA35000467B6 /* NotificationManagerMessageHandlerMessages.h */; }; 1062 1067 51452708271FBEC6000467B6 /* WebNotificationManagerMessageHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 51452707271FBEC1000467B6 /* WebNotificationManagerMessageHandler.h */; }; 1063 514526ED271E1647000467B6 /* NetworkNotificationManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 514526EB271E1626000467B6 /* NetworkNotificationManager.h */; };1064 1068 51489CC32370DBFA0044E68A /* WKFindResult.h in Headers */ = {isa = PBXBuildFile; fileRef = 51489CC12370DACC0044E68A /* WKFindResult.h */; settings = {ATTRIBUTES = (Public, ); }; }; 1065 1069 51489CC7237237800044E68A /* WKFindResultInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 51489CC6237237780044E68A /* WKFindResultInternal.h */; }; … … 4134 4138 512935E21288D97800A4B695 /* InjectedBundlePageContextMenuClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InjectedBundlePageContextMenuClient.h; sourceTree = "<group>"; }; 4135 4139 5129EB1123D0DE7800AF1CD7 /* ContentWorldShared.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ContentWorldShared.h; sourceTree = "<group>"; }; 4140 512CD6962721EFC200F7F8EC /* WebPushDaemonConnection.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebPushDaemonConnection.cpp; sourceTree = "<group>"; }; 4141 512CD6972721EFC300F7F8EC /* WebPushDaemonConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebPushDaemonConnection.h; sourceTree = "<group>"; }; 4142 512CD6992721F04900F7F8EC /* WebPushDaemonConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebPushDaemonConstants.h; sourceTree = "<group>"; }; 4143 512CD69C27223A0800F7F8EC /* WebPushDaemonConnectionCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebPushDaemonConnectionCocoa.mm; sourceTree = "<group>"; }; 4144 512CD69D2723393A00F7F8EC /* WebPushDaemon.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebPushDaemon.h; sourceTree = "<group>"; }; 4145 512CD69E2723393A00F7F8EC /* WebPushDaemon.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebPushDaemon.mm; sourceTree = "<group>"; }; 4136 4146 512F588E12A8838800629530 /* AuthenticationChallengeProxy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AuthenticationChallengeProxy.cpp; sourceTree = "<group>"; }; 4137 4147 512F588F12A8838800629530 /* AuthenticationChallengeProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AuthenticationChallengeProxy.h; sourceTree = "<group>"; }; … … 4168 4178 5143B25E1DDCDFD10014FAC6 /* _WKIconLoadingDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKIconLoadingDelegate.h; sourceTree = "<group>"; }; 4169 4179 5143B2611DDD0DA00014FAC6 /* APIIconLoadingClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APIIconLoadingClient.h; sourceTree = "<group>"; }; 4180 514526EB271E1626000467B6 /* NetworkNotificationManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkNotificationManager.h; sourceTree = "<group>"; }; 4181 514526EC271E1627000467B6 /* NetworkNotificationManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetworkNotificationManager.cpp; sourceTree = "<group>"; }; 4170 4182 514526FC271FB7E8000467B6 /* NotificationManagerMessageHandler.messages.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = NotificationManagerMessageHandler.messages.in; sourceTree = "<group>"; }; 4171 4183 514526FE271FB7E8000467B6 /* NotificationManagerMessageHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NotificationManagerMessageHandler.h; sourceTree = "<group>"; }; … … 4175 4187 51452706271FBEC1000467B6 /* WebNotificationManagerMessageHandler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebNotificationManagerMessageHandler.cpp; sourceTree = "<group>"; }; 4176 4188 51452707271FBEC1000467B6 /* WebNotificationManagerMessageHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebNotificationManagerMessageHandler.h; sourceTree = "<group>"; }; 4177 514526EB271E1626000467B6 /* NetworkNotificationManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkNotificationManager.h; sourceTree = "<group>"; };4178 514526EC271E1627000467B6 /* NetworkNotificationManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetworkNotificationManager.cpp; sourceTree = "<group>"; };4179 4189 51489CC12370DACC0044E68A /* WKFindResult.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKFindResult.h; sourceTree = "<group>"; }; 4180 4190 51489CC22370DACC0044E68A /* WKFindResult.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKFindResult.mm; sourceTree = "<group>"; }; … … 7139 7149 BC306822125A6B9400E71278 /* WebProcessCreationParameters.h */, 7140 7150 467E43E72243FF6D00B13924 /* WebProcessDataStoreParameters.h */, 7151 512CD6992721F04900F7F8EC /* WebPushDaemonConstants.h */, 7141 7152 5C8DD37F1FE4519200F2A556 /* WebsiteAutoplayPolicy.h */, 7142 7153 5C8DD3811FE455CA00F2A556 /* WebsiteAutoplayQuirk.h */, … … 9036 9047 sourceTree = "<group>"; 9037 9048 }; 9049 512CD69B272239E400F7F8EC /* Cocoa */ = { 9050 isa = PBXGroup; 9051 children = ( 9052 512CD69C27223A0800F7F8EC /* WebPushDaemonConnectionCocoa.mm */, 9053 ); 9054 path = Cocoa; 9055 sourceTree = "<group>"; 9056 }; 9038 9057 512F588D12A8836F00629530 /* Authentication */ = { 9039 9058 isa = PBXGroup; … … 9056 9075 isa = PBXGroup; 9057 9076 children = ( 9077 512CD69B272239E400F7F8EC /* Cocoa */, 9058 9078 514526EC271E1627000467B6 /* NetworkNotificationManager.cpp */, 9059 9079 514526EB271E1626000467B6 /* NetworkNotificationManager.h */, 9080 512CD6962721EFC200F7F8EC /* WebPushDaemonConnection.cpp */, 9081 512CD6972721EFC300F7F8EC /* WebPushDaemonConnection.h */, 9060 9082 ); 9061 9083 path = Notifications; … … 9579 9601 5CBB6D4D271F67CC00FD1A5D /* com.apple.webkit.webpushd.plist */, 9580 9602 5C157A0B2717CA1C00ED5280 /* WebPushDaemonMain.mm */, 9603 512CD69D2723393A00F7F8EC /* WebPushDaemon.h */, 9604 512CD69E2723393A00F7F8EC /* WebPushDaemon.mm */, 9581 9605 ); 9582 9606 path = webpushd; … … 12101 12125 files = ( 12102 12126 5C1579FC2717AF5000ED5280 /* DaemonUtilities.h in Headers */, 12127 512CD69F2723393A00F7F8EC /* WebPushDaemon.h in Headers */, 12103 12128 ); 12104 12129 runOnlyForDeploymentPostprocessing = 0; … … 12819 12844 93AB9B4D257567DC0098B10E /* SpeechRecognitionRemoteRealtimeMediaSourceManager.h in Headers */, 12820 12845 93D6B772254BB5190058DD3A /* SpeechRecognitionServer.h in Headers */, 12846 512CD69A2721F0A900F7F8EC /* WebPushDaemonConstants.h in Headers */, 12821 12847 93D6B784254CCD0E0058DD3A /* SpeechRecognitionServerMessages.h in Headers */, 12822 12848 93D6B785254CCD430058DD3A /* SpeechRecognitionServerMessagesReplies.h in Headers */, … … 12906 12932 9955A6EC1C7980C200EB6A93 /* WebAutomationSession.h in Headers */, 12907 12933 99C3AE2D1DADA6AD00AF5C16 /* WebAutomationSessionMacros.h in Headers */, 12934 512CD6982721EFC800F7F8EC /* WebPushDaemonConnection.h in Headers */, 12908 12935 1C0A19581C90068F00FE0EBB /* WebAutomationSessionMessages.h in Headers */, 12909 12936 1C0A19471C8FF1A800FE0EBB /* WebAutomationSessionProxy.h in Headers */, … … 14661 14688 buildActionMask = 2147483647; 14662 14689 files = ( 14690 512CD6A02723393A00F7F8EC /* WebPushDaemon.mm in Sources */, 14663 14691 5C157A012717B7FB00ED5280 /* ArgumentCoders.cpp in Sources */, 14664 14692 5C1579FF2717B6D200ED5280 /* DaemonDecoder.cpp in Sources */, -
trunk/Source/WebKit/webpushd/WebPushDaemon.h
r284886 r284887 24 24 */ 25 25 26 #include "config.h" 27 #include "DaemonConnection.h" 26 #pragma once 28 27 29 #include "PrivateClickMeasurementConnection.h" 28 #include "WebPushDaemonConstants.h" 29 #include <wtf/Forward.h> 30 #include <wtf/OSObjectPtr.h> 31 #include <wtf/Span.h> 32 #include <wtf/spi/darwin/XPCSPI.h> 30 33 31 namespace WebKit { 34 using WebKit::WebPushD::MessageType; 32 35 33 namespace Daemon{36 namespace WebPushD { 34 37 35 #if !PLATFORM(COCOA) 38 using EncodedMessage = Vector<uint8_t>; 36 39 37 template<typename Traits> 38 void ConnectionToMachService<Traits>::send(typename Traits::MessageType, EncodedMessage&&) const 39 { 40 } 40 class Daemon { 41 friend class WTF::NeverDestroyed<Daemon>; 42 public: 43 static Daemon& singleton(); 41 44 42 template<typename Traits> 43 void ConnectionToMachService<Traits>::sendWithReply(typename Traits::MessageType, EncodedMessage&&, CompletionHandler<void(EncodedMessage&&)>&& completionHandler) const 44 { 45 completionHandler({ }); 46 } 45 void connectionEventHandler(xpc_object_t); 46 void connectionAdded(xpc_connection_t); 47 void connectionRemoved(xpc_connection_t); 47 48 48 template class ConnectionToMachService<PCM::ConnectionTraits>; 49 // Message handlers 50 void echoTwice(const String&, CompletionHandler<void(const String&)>&& replySender); 49 51 50 #endif 52 private: 53 Daemon() = default; 51 54 52 } // namespace Daemon 55 CompletionHandler<void(EncodedMessage&&)> createReplySender(MessageType, OSObjectPtr<xpc_object_t>&& request); 56 void decodeAndHandleMessage(MessageType, Span<const uint8_t> encodedMessage, CompletionHandler<void(EncodedMessage&&)>&&); 57 }; 53 58 54 } // namespace Web Kit59 } // namespace WebPushD -
trunk/Source/WebKit/webpushd/WebPushDaemon.mm
r284886 r284887 25 25 26 26 #import "config.h" 27 #import "DaemonConnection.h" 27 #import "WebPushDaemon.h" 28 28 29 #import "DaemonDecoder.h" 29 30 #import "DaemonEncoder.h" 30 31 #import "DaemonUtilities.h" 31 #import <Foundation/Foundation.h> 32 #import <wtf/MainThread.h> 32 #import "HandleMessage.h" 33 #import "WebPushDaemonConstants.h" 34 35 #import <wtf/CompletionHandler.h> 36 #import <wtf/NeverDestroyed.h> 33 37 #import <wtf/Span.h> 34 #import <wtf/spi/darwin/XPCSPI.h> 38 39 using namespace WebKit::WebPushD; 35 40 36 41 namespace WebPushD { 37 42 38 constexpr const char* protocolVersionKey = "protocol version"; 39 constexpr uint64_t protocolVersionValue = 1; 40 constexpr const char* protocolMessageTypeKey = "message type"; 41 constexpr const char* protocolEncodedMessageKey = "encoded message"; 42 enum class MessageType : uint8_t { 43 EchoTwice = 1 44 }; 43 namespace MessageInfo { 45 44 46 static CompletionHandler<void(Vector<uint8_t>&&)> replySender(RetainPtr<xpc_object_t>&& request) 45 #define FUNCTION(mf) struct mf { static constexpr auto MemberFunction = &WebPushD::Daemon::mf; 46 #define ARGUMENTS(...) using ArgsTuple = std::tuple<__VA_ARGS__>; 47 #define REPLY(...) using Reply = CompletionHandler<void(__VA_ARGS__)>; \ 48 static WebPushD::EncodedMessage encodeReply(__VA_ARGS__); 49 #define END }; 50 51 FUNCTION(echoTwice) 52 ARGUMENTS(String) 53 REPLY(String) 54 END 55 56 #undef FUNCTION 57 #undef ARGUMENTS 58 #undef REPLY 59 #undef END 60 61 WebPushD::EncodedMessage echoTwice::encodeReply(String reply) 47 62 { 48 return [request = WTFMove(request)] (Vector<uint8_t>&& message) { 63 WebKit::Daemon::Encoder encoder; 64 encoder << reply; 65 return encoder.takeBuffer(); 66 } 67 68 } // namespace MessageInfo 69 70 template<typename Info> 71 void handleWebPushDMessageWithReply(Span<const uint8_t> encodedMessage, CompletionHandler<void(WebPushD::EncodedMessage&&)>&& replySender) 72 { 73 WebKit::Daemon::Decoder decoder(encodedMessage); 74 75 std::optional<typename Info::ArgsTuple> arguments; 76 decoder >> arguments; 77 if (UNLIKELY(!arguments)) 78 return; 79 80 typename Info::Reply completionHandler { [replySender = WTFMove(replySender)] (auto&&... args) mutable { 81 replySender(Info::encodeReply(args...)); 82 } }; 83 84 IPC::callMemberFunction(WTFMove(*arguments), WTFMove(completionHandler), &WebPushD::Daemon::singleton(), Info::MemberFunction); 85 } 86 87 Daemon& Daemon::singleton() 88 { 89 static NeverDestroyed<Daemon> daemon; 90 return daemon; 91 } 92 93 void Daemon::connectionEventHandler(xpc_object_t request) 94 { 95 if (xpc_get_type(request) != XPC_TYPE_DICTIONARY) 96 return; 97 98 if (xpc_dictionary_get_uint64(request, protocolVersionKey) != protocolVersionValue) { 99 NSLog(@"Received request that was not the current protocol version"); 100 // FIXME: Cut off this connection 101 return; 102 } 103 104 auto messageType { static_cast<MessageType>(xpc_dictionary_get_uint64(request, protocolMessageTypeKey)) }; 105 size_t dataSize { 0 }; 106 const void* data = xpc_dictionary_get_data(request, protocolEncodedMessageKey, &dataSize); 107 Span<const uint8_t> encodedMessage { static_cast<const uint8_t*>(data), dataSize }; 108 109 decodeAndHandleMessage(messageType, encodedMessage, createReplySender(messageType, request)); 110 } 111 112 void Daemon::connectionAdded(xpc_connection_t) 113 { 114 // FIXME: Track connections 115 } 116 117 void Daemon::connectionRemoved(xpc_connection_t) 118 { 119 // FIXME: Track connections 120 } 121 122 CompletionHandler<void(EncodedMessage&&)> Daemon::createReplySender(MessageType messageType, OSObjectPtr<xpc_object_t>&& request) 123 { 124 if (!messageTypeSendsReply(messageType)) 125 return nullptr; 126 127 return [request = WTFMove(request)] (EncodedMessage&& message) { 49 128 auto reply = adoptNS(xpc_dictionary_create_reply(request.get())); 50 129 ASSERT(xpc_get_type(reply.get()) == XPC_TYPE_DICTIONARY); … … 55 134 } 56 135 57 static void echoTwice(Span<const uint8_t> encodedMessage, CompletionHandler<void(Vector<uint8_t>&&)>&& replySender)136 void Daemon::decodeAndHandleMessage(MessageType messageType, Span<const uint8_t> encodedMessage, CompletionHandler<void(EncodedMessage&&)>&& replySender) 58 137 { 59 WebKit::Daemon::Decoder decoder(encodedMessage); 60 std::optional<String> string; 61 decoder >> string; 62 if (!string) 63 return; 138 ASSERT(messageTypeSendsReply(messageType) == !!replySender); 64 139 65 auto reply = makeString(*string, *string);66 WebKit::Daemon::Encoder encoder;67 encoder << reply;68 replySender(encoder.takeBuffer());69 }70 71 static void decodeMessageAndSendReply(MessageType messageType, Span<const uint8_t> encodedMessage, CompletionHandler<void(Vector<uint8_t>&&)>&& replySender)72 {73 140 switch (messageType) { 74 141 case MessageType::EchoTwice: 75 echoTwice(encodedMessage, WTFMove(replySender));76 return;142 handleWebPushDMessageWithReply<MessageInfo::echoTwice>(encodedMessage, WTFMove(replySender)); 143 break; 77 144 } 78 145 } 79 146 80 static void connectionEventHandler(xpc_object_t request)147 void Daemon::echoTwice(const String& message, CompletionHandler<void(const String&)>&& replySender) 81 148 { 82 if (xpc_get_type(request) != XPC_TYPE_DICTIONARY) 83 return; 84 if (xpc_dictionary_get_uint64(request, protocolVersionKey) != protocolVersionValue) { 85 NSLog(@"Received request that was not the current protocol version"); 86 return; 87 } 88 89 auto messageType { static_cast<MessageType>(xpc_dictionary_get_uint64(request, protocolMessageTypeKey)) }; 90 size_t dataSize { 0 }; 91 const void* data = xpc_dictionary_get_data(request, protocolEncodedMessageKey, &dataSize); 92 Span<const uint8_t> encodedMessage { static_cast<const uint8_t*>(data), dataSize }; 93 decodeMessageAndSendReply(messageType, encodedMessage, replySender(request)); 94 } 95 96 static void connectionAdded(xpc_connection_t) 97 { 98 } 99 100 static void connectionRemoved(xpc_connection_t) 101 { 149 replySender(makeString(message, message)); 102 150 } 103 151 104 152 } // namespace WebPushD 105 106 int main(int argc, const char** argv)107 {108 if (argc != 3 || strcmp(argv[1], "--machServiceName")) {109 NSLog(@"usage: webpushd --machServiceName <name>");110 return -1;111 }112 const char* machServiceName = argv[2];113 114 @autoreleasepool {115 // FIXME: Add a sandbox.116 // FIXME: Add an entitlement check.117 WebKit::startListeningForMachServiceConnections(machServiceName, nullptr, WebPushD::connectionAdded, WebPushD::connectionRemoved, WebPushD::connectionEventHandler);118 WTF::initializeMainThread();119 }120 CFRunLoopRun();121 return 0;122 } -
trunk/Source/WebKit/webpushd/WebPushDaemonMain.mm
r284203 r284887 29 29 #import "DaemonEncoder.h" 30 30 #import "DaemonUtilities.h" 31 #import "WebPushDaemon.h" 31 32 #import <Foundation/Foundation.h> 32 33 #import <wtf/MainThread.h> 33 #import <wtf/Span.h>34 34 #import <wtf/spi/darwin/XPCSPI.h> 35 36 using WebKit::Daemon::EncodedMessage; 37 using WebPushD::Daemon; 35 38 36 39 namespace WebPushD { 37 40 38 constexpr const char* protocolVersionKey = "protocol version"; 39 constexpr uint64_t protocolVersionValue = 1; 40 constexpr const char* protocolMessageTypeKey = "message type"; 41 constexpr const char* protocolEncodedMessageKey = "encoded message"; 42 enum class MessageType : uint8_t { 43 EchoTwice = 1 44 }; 45 46 static CompletionHandler<void(Vector<uint8_t>&&)> replySender(RetainPtr<xpc_object_t>&& request) 41 static void connectionEventHandler(xpc_object_t request) 47 42 { 48 return [request = WTFMove(request)] (Vector<uint8_t>&& message) { 49 auto reply = adoptNS(xpc_dictionary_create_reply(request.get())); 50 ASSERT(xpc_get_type(reply.get()) == XPC_TYPE_DICTIONARY); 51 xpc_dictionary_set_uint64(reply.get(), protocolVersionKey, protocolVersionValue); 52 xpc_dictionary_set_value(reply.get(), protocolEncodedMessageKey, WebKit::vectorToXPCData(WTFMove(message)).get()); 53 xpc_connection_send_message(xpc_dictionary_get_remote_connection(request.get()), reply.get()); 54 }; 43 Daemon::singleton().connectionEventHandler(request); 55 44 } 56 45 57 static void echoTwice(Span<const uint8_t> encodedMessage, CompletionHandler<void(Vector<uint8_t>&&)>&& replySender)46 static void connectionAdded(xpc_connection_t connection) 58 47 { 59 WebKit::Daemon::Decoder decoder(encodedMessage); 60 std::optional<String> string; 61 decoder >> string; 62 if (!string) 63 return; 64 65 auto reply = makeString(*string, *string); 66 WebKit::Daemon::Encoder encoder; 67 encoder << reply; 68 replySender(encoder.takeBuffer()); 48 Daemon::singleton().connectionAdded(connection); 69 49 } 70 50 71 static void decodeMessageAndSendReply(MessageType messageType, Span<const uint8_t> encodedMessage, CompletionHandler<void(Vector<uint8_t>&&)>&& replySender)51 static void connectionRemoved(xpc_connection_t connection) 72 52 { 73 switch (messageType) { 74 case MessageType::EchoTwice: 75 echoTwice(encodedMessage, WTFMove(replySender)); 76 return; 77 } 78 } 79 80 static void connectionEventHandler(xpc_object_t request) 81 { 82 if (xpc_get_type(request) != XPC_TYPE_DICTIONARY) 83 return; 84 if (xpc_dictionary_get_uint64(request, protocolVersionKey) != protocolVersionValue) { 85 NSLog(@"Received request that was not the current protocol version"); 86 return; 87 } 88 89 auto messageType { static_cast<MessageType>(xpc_dictionary_get_uint64(request, protocolMessageTypeKey)) }; 90 size_t dataSize { 0 }; 91 const void* data = xpc_dictionary_get_data(request, protocolEncodedMessageKey, &dataSize); 92 Span<const uint8_t> encodedMessage { static_cast<const uint8_t*>(data), dataSize }; 93 decodeMessageAndSendReply(messageType, encodedMessage, replySender(request)); 94 } 95 96 static void connectionAdded(xpc_connection_t) 97 { 98 } 99 100 static void connectionRemoved(xpc_connection_t) 101 { 53 Daemon::singleton().connectionRemoved(connection); 102 54 } 103 55 -
trunk/Tools/ChangeLog
r284878 r284887 1 2021-10-26 Brady Eidson <beidson@apple.com> 2 3 Add helper classes and messaging infrastructure to launch webpushd and round trip a message to it 4 https://bugs.webkit.org/show_bug.cgi?id=232262 5 6 Reviewed by Alex Christensen. 7 8 * MiniBrowser/mac/AppDelegate.m: 9 (persistentDataStore): 10 * MiniBrowser/mac/WK2BrowserWindowController.m: 11 (-[WK2BrowserWindowController _webView:requestNotificationPermissionForSecurityOrigin:decisionHandler:]): 12 1 13 2021-10-26 Simon Fraser <simon.fraser@apple.com> 2 14 -
trunk/Tools/MiniBrowser/mac/AppDelegate.m
r277627 r284887 99 99 _WKWebsiteDataStoreConfiguration *configuration = [[[_WKWebsiteDataStoreConfiguration alloc] init] autorelease]; 100 100 configuration.networkCacheSpeculativeValidationEnabled = YES; 101 102 // FIXME: When built-in notifications are enabled, WebKit doesn't yet gracefully handle a missing webpushd service 103 // Until it does, uncomment this line when the service is known to be installed. 104 // [configuration setWebPushMachServiceName:@"org.webkit.webpushtestdaemon.service"]; 105 101 106 dataStore = [[WKWebsiteDataStore alloc] _initWithConfiguration:configuration]; 102 107 } -
trunk/Tools/MiniBrowser/mac/WK2BrowserWindowController.m
r275110 r284887 211 211 212 212 return 1; 213 } 214 215 - (void)_webView:(WKWebView *)webView requestNotificationPermissionForSecurityOrigin:(WKSecurityOrigin *)securityOrigin decisionHandler:(void (^)(BOOL))decisionHandler 216 { 217 // For testing, grant notification permission to all origins. 218 // FIXME: Consider adding a dialog and in-memory permissions manager 219 NSLog(@"Granting notifications permission to origin %@", securityOrigin); 220 decisionHandler(YES); 213 221 } 214 222
Note:
See TracChangeset
for help on using the changeset viewer.