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

Changeset 284887 in webkit


Ignore:
Timestamp:
Oct 26, 2021, 12:34:30 PM (5 years ago)
Author:
beidson@apple.com
Message:

Add helper classes and messaging infrastructure to launch webpushd and round trip a message to it
https://bugs.webkit.org/show_bug.cgi?id=232262

Reviewed by Alex Christensen.

Source/WebKit:

No new tests (No behavior change yet)

This patch:

  • Adds classes representing the WebPushDaemon and connections to it
  • Adds classes/constants/macros related to messaging that daemon
  • Adds SPI for configuring a connect to that daemon
  • Gets MiniBrowser closer to supporting built-in notifications
  • Has way more commented out code than usual for a patch, but that enables a great stopping-point milestone
  • NetworkProcess/Notifications/Cocoa/WebPushDaemonConnectionCocoa.mm: Added.

(WebKit::WebPushD::addVersionAndEncodedMessageToDictionary):
(WebKit::WebPushD::Connection::newConnectionWasInitialized const):
(WebKit::WebPushD::Connection::connectionReceivedEvent const):
(WebKit::WebPushD::Connection::dictionaryFromMessage const):

  • NetworkProcess/Notifications/NetworkNotificationManager.cpp:

(WebKit::NetworkNotificationManager::NetworkNotificationManager):
(WebKit::NetworkNotificationManager::showNotification):
(WebKit::NetworkNotificationManager::cancelNotification):
(WebKit::NetworkNotificationManager::clearNotifications):
(WebKit::NetworkNotificationManager::didDestroyNotification):
(WebKit::NetworkNotificationManager::sendMessage const):
(WebKit::ReplyCaller<>::callReply):
(WebKit::ReplyCaller<String>::callReply):
(WebKit::NetworkNotificationManager::sendMessageWithReply const):

  • NetworkProcess/Notifications/NetworkNotificationManager.h:

(WebKit::NetworkNotificationManager::networkSession const):

  • NetworkProcess/Notifications/WebPushDaemonConnection.cpp: Copied from Source/WebKit/Platform/IPC/DaemonConnection.cpp.

(WebKit::WebPushD::Connection::Connection):
(WebKit::WebPushD::Connection::networkSession const):

  • NetworkProcess/Notifications/WebPushDaemonConnection.h: Copied from Source/WebKit/NetworkProcess/Notifications/NetworkNotificationManager.h.
  • NetworkProcess/mac/com.apple.WebKit.NetworkProcess.sb.in:
  • Platform/IPC/DaemonConnection.cpp:
  • Platform/IPC/DaemonConnection.h:

(WebKit::Daemon::ConnectionToMachService::machServiceName const):

  • Platform/IPC/cocoa/DaemonConnectionCocoa.mm:
  • Platform/Logging.h:
  • Shared/WebPushDaemonConstants.h: Copied from Source/WebKit/Platform/IPC/DaemonConnection.cpp.

(WebKit::WebPushD::messageTypeSendsReply):

  • UIProcess/WebsiteData/WebsiteDataStoreConfiguration.cpp:

(WebKit::WebsiteDataStoreConfiguration::copy const):

  • webpushd/WebPushDaemon.h: Copied from Source/WebKit/NetworkProcess/Notifications/NetworkNotificationManager.h.
  • webpushd/WebPushDaemon.mm: Copied from Source/WebKit/webpushd/WebPushDaemonMain.mm.

(WebPushD::MessageInfo::echoTwice::encodeReply):
(WebPushD::handleWebPushDMessageWithReply):
(WebPushD::Daemon::singleton):
(WebPushD::Daemon::connectionEventHandler):
(WebPushD::Daemon::connectionAdded):
(WebPushD::Daemon::connectionRemoved):
(WebPushD::CompletionHandler<void):
(WebPushD::Daemon::decodeAndHandleMessage):
(WebPushD::Daemon::echoTwice):

  • webpushd/WebPushDaemonMain.mm:

(WebPushD::connectionEventHandler):
(WebPushD::connectionAdded):
(WebPushD::connectionRemoved):
(WebPushD::CompletionHandler<void): Deleted.
(WebPushD::echoTwice): Deleted.
(WebPushD::decodeMessageAndSendReply): Deleted.

  • Sources.txt:
  • SourcesCocoa.txt:
  • WebKit.xcodeproj/project.pbxproj:

Tools:

  • MiniBrowser/mac/AppDelegate.m:

(persistentDataStore):

  • MiniBrowser/mac/WK2BrowserWindowController.m:

(-[WK2BrowserWindowController _webView:requestNotificationPermissionForSecurityOrigin:decisionHandler:]):

Location:
trunk
Files:
2 added
17 edited
5 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r284875 r284887  
     12021-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       
    1802021-10-26  Kate Cheney  <katherine_cheney@apple.com>
    281
  • trunk/Source/WebKit/NetworkProcess/Notifications/NetworkNotificationManager.cpp

    r284591 r284887  
    2929#if ENABLE(BUILT_IN_NOTIFICATIONS)
    3030
     31#include "DaemonDecoder.h"
     32#include "DaemonEncoder.h"
     33#include "NetworkSession.h"
     34
    3135namespace WebKit {
    3236using namespace WebCore;
    3337
    34 NetworkNotificationManager::NetworkNotificationManager(NetworkSession& networkSession, const String&)
     38NetworkNotificationManager::NetworkNotificationManager(NetworkSession& networkSession, const String& webPushMachServiceName)
    3539    : m_networkSession(networkSession)
    3640{
     41    if (!m_networkSession.sessionID().isEphemeral() && !webPushMachServiceName.isEmpty())
     42        m_connection = makeUnique<WebPushD::Connection>(webPushMachServiceName.utf8(), *this);
    3743}
    3844
    3945void NetworkNotificationManager::showNotification(const String&, const String&, const String&, const String&, const String&, WebCore::NotificationDirection, const String&, uint64_t)
    4046{
     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"));
    4159}
    4260
    4361void NetworkNotificationManager::cancelNotification(uint64_t)
    4462{
     63    if (!m_connection)
     64        return;
    4565}
    4666
    4767void NetworkNotificationManager::clearNotifications(const Vector<uint64_t>&)
    4868{
     69    if (!m_connection)
     70        return;
    4971}
    5072
    5173void NetworkNotificationManager::didDestroyNotification(uint64_t)
    5274{
     75    if (!m_connection)
     76        return;
     77}
     78
     79
     80template<WebPushD::MessageType messageType, typename... Args>
     81void 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
     89template<typename... Args> struct ReplyCaller;
     90template<> struct ReplyCaller<> {
     91    static void callReply(Daemon::Decoder&& decoder, CompletionHandler<void()>&& completionHandler)
     92    {
     93        completionHandler();
     94    }
     95};
     96template<> 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
     107template<WebPushD::MessageType messageType, typename... Args, typename... ReplyArgs>
     108void 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    });
    53118}
    54119
  • trunk/Source/WebKit/NetworkProcess/Notifications/NetworkNotificationManager.h

    r284591 r284887  
    2929
    3030#include "NotificationManagerMessageHandler.h"
     31#include "WebPushDaemonConnection.h"
    3132#include <WebCore/NotificationDirection.h>
    3233#include <wtf/text/WTFString.h>
    3334
    3435namespace WebKit {
     36
     37namespace WebPushD {
     38enum class MessageType : uint8_t;
     39}
    3540
    3641class NetworkSession;
     
    3944    WTF_MAKE_FAST_ALLOCATED;
    4045    friend class NetworkSession;
     46public:
     47    NetworkSession& networkSession() const { return m_networkSession; }
     48
    4149private:
    4250    NetworkNotificationManager(NetworkSession&, const String& webPushMachServiceName);
     
    4856
    4957    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;
    5064};
    5165
  • trunk/Source/WebKit/NetworkProcess/Notifications/WebPushDaemonConnection.cpp

    r284886 r284887  
    2525
    2626#include "config.h"
    27 #include "NetworkNotificationManager.h"
     27#include "WebPushDaemonConnection.h"
    2828
    2929#if ENABLE(BUILT_IN_NOTIFICATIONS)
    3030
    31 namespace WebKit {
    32 using namespace WebCore;
     31#include "DaemonDecoder.h"
     32#include "DaemonEncoder.h"
     33#include "NetworkSession.h"
    3334
    34 NetworkNotificationManager::NetworkNotificationManager(NetworkSession& networkSession, const String&)
    35     : m_networkSession(networkSession)
     35namespace WebKit::WebPushD {
     36
     37Connection::Connection(CString&& machServiceName, NetworkNotificationManager& manager)
     38    : Daemon::ConnectionToMachService<ConnectionTraits>(WTFMove(machServiceName))
     39    , m_notificationManager(manager)
    3640{
     41    LOG(Push, "Creating WebPushD connection to mach service: %s", this->machServiceName().data());
    3742}
    3843
    39 void NetworkNotificationManager::showNotification(const String&, const String&, const String&, const String&, const String&, WebCore::NotificationDirection, const String&, uint64_t)
     44NetworkSession& Connection::networkSession() const
    4045{
     46    return m_notificationManager.networkSession();
    4147}
    4248
    43 void NetworkNotificationManager::cancelNotification(uint64_t)
    44 {
    45 }
     49} // namespace WebKit::WebPushD
    4650
    47 void NetworkNotificationManager::clearNotifications(const Vector<uint64_t>&)
    48 {
    49 }
    50 
    51 void NetworkNotificationManager::didDestroyNotification(uint64_t)
    52 {
    53 }
    54 
    55 } // namespace WebKit
    5651#endif // ENABLE(BUILT_IN_NOTIFICATIONS)
  • trunk/Source/WebKit/NetworkProcess/Notifications/WebPushDaemonConnection.h

    r284886 r284887  
    2828#if ENABLE(BUILT_IN_NOTIFICATIONS)
    2929
    30 #include "NotificationManagerMessageHandler.h"
    31 #include <WebCore/NotificationDirection.h>
    32 #include <wtf/text/WTFString.h>
     30#include "DaemonConnection.h"
     31#include "WebPushDaemonConstants.h"
    3332
    3433namespace WebKit {
    3534
     35class NetworkNotificationManager;
    3636class NetworkSession;
    3737
    38 class NetworkNotificationManager : public NotificationManagerMessageHandler {
    39     WTF_MAKE_FAST_ALLOCATED;
    40     friend class NetworkSession;
    41 private:
    42     NetworkNotificationManager(NetworkSession&, const String& webPushMachServiceName);
     38namespace WebPushD {
    4339
    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;
     40struct 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 };
    5045};
    5146
     47class Connection : public Daemon::ConnectionToMachService<ConnectionTraits> {
     48    WTF_MAKE_FAST_ALLOCATED;
     49public:
     50    Connection(CString&& machServiceName, NetworkNotificationManager&);
     51
     52private:
     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
    5271} // namespace WebKit
    5372
    5473#endif // ENABLE(BUILT_IN_NOTIFICATIONS)
     74
  • trunk/Source/WebKit/NetworkProcess/WebSocketTask.h

    r279340 r284887  
    3232#else
    3333
     34#include "DataReference.h"
     35
    3436namespace WebKit {
    3537
  • trunk/Source/WebKit/NetworkProcess/mac/com.apple.WebKit.NetworkProcess.sb.in

    r284277 r284887  
    369369(allow mach-lookup (with telemetry) (global-name "com.apple.webkit.adattributiond.service"))
    370370(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"))
    371374
    372375(with-filter (uid 0)
  • trunk/Source/WebKit/Platform/IPC/DaemonConnection.cpp

    r284129 r284887  
    2828
    2929#include "PrivateClickMeasurementConnection.h"
     30#include "WebPushDaemonConnection.h"
    3031
    3132namespace WebKit {
     
    4849template class ConnectionToMachService<PCM::ConnectionTraits>;
    4950
     51#if ENABLE(BUILT_IN_NOTIFICATIONS)
     52template class ConnectionToMachService<WebPushD::ConnectionTraits>;
    5053#endif
     54
     55#endif // !PLATFORM(COCOA)
    5156
    5257} // namespace Daemon
  • trunk/Source/WebKit/Platform/IPC/DaemonConnection.h

    r284129 r284887  
    7272#endif
    7373
     74    const CString& machServiceName() const { return m_machServiceName; }
     75
    7476private:
    7577    void initializeConnectionIfNeeded() const;
  • trunk/Source/WebKit/Platform/IPC/cocoa/DaemonConnectionCocoa.mm

    r284823 r284887  
    2929#import "DaemonEncoder.h"
    3030#import "PrivateClickMeasurementConnection.h"
     31#import "WebPushDaemonConnection.h"
    3132#import <wtf/BlockPtr.h>
    3233#import <wtf/RunLoop.h>
     
    113114template class ConnectionToMachService<PCM::ConnectionTraits>;
    114115
     116#if ENABLE(BUILT_IN_NOTIFICATIONS)
     117template class ConnectionToMachService<WebPushD::ConnectionTraits>;
     118#endif
     119
    115120} // namespace Daemon
    116121
  • trunk/Source/WebKit/Platform/Logging.h

    r282115 r284887  
    8888    M(ProcessSwapping) \
    8989    M(ProximityNetworking) \
     90    M(Push) \
    9091    M(RemoteLayerTree) \
    9192    M(Resize) \
  • trunk/Source/WebKit/Shared/WebPushDaemonConstants.h

    r284886 r284887  
    2424 */
    2525
    26 #include "config.h"
    27 #include "DaemonConnection.h"
     26#pragma once
    2827
    29 #include "PrivateClickMeasurementConnection.h"
     28namespace WebKit::WebPushD {
    3029
    31 namespace WebKit {
     30constexpr const char* protocolVersionKey = "protocol version";
     31constexpr uint64_t protocolVersionValue = 1;
     32constexpr const char* protocolEncodedMessageKey = "encoded message";
    3233
    33 namespace Daemon {
     34constexpr const char* protocolDebugMessageKey { "debug message" };
     35constexpr const char* protocolDebugMessageLevelKey { "debug message level" };
    3436
    35 #if !PLATFORM(COCOA)
     37constexpr const char* protocolMessageTypeKey { "message type" };
     38enum class MessageType : uint8_t {
     39    EchoTwice = 1,
     40};
    3641
    37 template<typename Traits>
    38 void ConnectionToMachService<Traits>::send(typename Traits::MessageType, EncodedMessage&&) const
     42inline bool messageTypeSendsReply(MessageType messageType)
    3943{
     44    switch (messageType) {
     45    case MessageType::EchoTwice:
     46        return true;
     47    }
     48    ASSERT_NOT_REACHED();
     49    return false;
    4050}
    4151
    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  
    9999
    100100NetworkProcess/Notifications/NetworkNotificationManager.cpp
     101NetworkProcess/Notifications/WebPushDaemonConnection.cpp
    101102
    102103NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementClientImpl.cpp
  • trunk/Source/WebKit/SourcesCocoa.txt

    r284444 r284887  
    4141NetworkProcess/EntryPoint/Cocoa/Daemon/DaemonEntryPoint.mm
    4242NetworkProcess/EntryPoint/Cocoa/XPCService/NetworkServiceEntryPoint.mm
     43
     44NetworkProcess/Notifications/Cocoa/WebPushDaemonConnectionCocoa.mm
    4345
    4446NetworkProcess/PrivateClickMeasurement/cocoa/PrivateClickMeasurementConnectionCocoa.mm
  • trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStoreConfiguration.cpp

    r284661 r284887  
    106106    copy->m_allowsHSTSWithUntrustedRootCertificate = this->m_allowsHSTSWithUntrustedRootCertificate;
    107107    copy->m_pcmMachServiceName = this->m_pcmMachServiceName;
     108    copy->m_webPushMachServiceName = this->m_webPushMachServiceName;
    108109#if PLATFORM(COCOA)
    109110    if (m_proxyConfiguration)
  • trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj

    r284662 r284887  
    10361036                512935E41288D97800A4B695 /* InjectedBundlePageContextMenuClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 512935E21288D97800A4B695 /* InjectedBundlePageContextMenuClient.h */; };
    10371037                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 */; };
    10381042                512E34E5130B4D0500ABD19A /* WKApplicationCacheManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 517A33B4130B308C00F80CB5 /* WKApplicationCacheManager.h */; settings = {ATTRIBUTES = (Private, ); }; };
    10391043                512ECC3527196ADB00089B66 /* PrivateClickMeasurementConnection.h in Headers */ = {isa = PBXBuildFile; fileRef = 5CB930FE26E802160032B1C0 /* PrivateClickMeasurementConnection.h */; };
     
    10561060                513FFB91201459C6002596EA /* WebMessagePortChannelProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 513FFB8F201459C2002596EA /* WebMessagePortChannelProvider.h */; };
    10571061                514129941C6428BB0059E714 /* WebIDBConnectionToServer.h in Headers */ = {isa = PBXBuildFile; fileRef = 514129921C6428100059E714 /* WebIDBConnectionToServer.h */; };
     1062                514526ED271E1647000467B6 /* NetworkNotificationManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 514526EB271E1626000467B6 /* NetworkNotificationManager.h */; };
    10581063                514526FF271FB7EC000467B6 /* NotificationManagerMessageHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 514526FE271FB7E8000467B6 /* NotificationManagerMessageHandler.h */; };
    10591064                51452703271FBA3A000467B6 /* NotificationManagerMessageHandlerMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51452702271FBA36000467B6 /* NotificationManagerMessageHandlerMessageReceiver.cpp */; };
     
    10611066                51452705271FBA40000467B6 /* NotificationManagerMessageHandlerMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = 51452701271FBA35000467B6 /* NotificationManagerMessageHandlerMessages.h */; };
    10621067                51452708271FBEC6000467B6 /* WebNotificationManagerMessageHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 51452707271FBEC1000467B6 /* WebNotificationManagerMessageHandler.h */; };
    1063                 514526ED271E1647000467B6 /* NetworkNotificationManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 514526EB271E1626000467B6 /* NetworkNotificationManager.h */; };
    10641068                51489CC32370DBFA0044E68A /* WKFindResult.h in Headers */ = {isa = PBXBuildFile; fileRef = 51489CC12370DACC0044E68A /* WKFindResult.h */; settings = {ATTRIBUTES = (Public, ); }; };
    10651069                51489CC7237237800044E68A /* WKFindResultInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 51489CC6237237780044E68A /* WKFindResultInternal.h */; };
     
    41344138                512935E21288D97800A4B695 /* InjectedBundlePageContextMenuClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InjectedBundlePageContextMenuClient.h; sourceTree = "<group>"; };
    41354139                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>"; };
    41364146                512F588E12A8838800629530 /* AuthenticationChallengeProxy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AuthenticationChallengeProxy.cpp; sourceTree = "<group>"; };
    41374147                512F588F12A8838800629530 /* AuthenticationChallengeProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AuthenticationChallengeProxy.h; sourceTree = "<group>"; };
     
    41684178                5143B25E1DDCDFD10014FAC6 /* _WKIconLoadingDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKIconLoadingDelegate.h; sourceTree = "<group>"; };
    41694179                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>"; };
    41704182                514526FC271FB7E8000467B6 /* NotificationManagerMessageHandler.messages.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = NotificationManagerMessageHandler.messages.in; sourceTree = "<group>"; };
    41714183                514526FE271FB7E8000467B6 /* NotificationManagerMessageHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NotificationManagerMessageHandler.h; sourceTree = "<group>"; };
     
    41754187                51452706271FBEC1000467B6 /* WebNotificationManagerMessageHandler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebNotificationManagerMessageHandler.cpp; sourceTree = "<group>"; };
    41764188                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>"; };
    41794189                51489CC12370DACC0044E68A /* WKFindResult.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKFindResult.h; sourceTree = "<group>"; };
    41804190                51489CC22370DACC0044E68A /* WKFindResult.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKFindResult.mm; sourceTree = "<group>"; };
     
    71397149                                BC306822125A6B9400E71278 /* WebProcessCreationParameters.h */,
    71407150                                467E43E72243FF6D00B13924 /* WebProcessDataStoreParameters.h */,
     7151                                512CD6992721F04900F7F8EC /* WebPushDaemonConstants.h */,
    71417152                                5C8DD37F1FE4519200F2A556 /* WebsiteAutoplayPolicy.h */,
    71427153                                5C8DD3811FE455CA00F2A556 /* WebsiteAutoplayQuirk.h */,
     
    90369047                        sourceTree = "<group>";
    90379048                };
     9049                512CD69B272239E400F7F8EC /* Cocoa */ = {
     9050                        isa = PBXGroup;
     9051                        children = (
     9052                                512CD69C27223A0800F7F8EC /* WebPushDaemonConnectionCocoa.mm */,
     9053                        );
     9054                        path = Cocoa;
     9055                        sourceTree = "<group>";
     9056                };
    90389057                512F588D12A8836F00629530 /* Authentication */ = {
    90399058                        isa = PBXGroup;
     
    90569075                        isa = PBXGroup;
    90579076                        children = (
     9077                                512CD69B272239E400F7F8EC /* Cocoa */,
    90589078                                514526EC271E1627000467B6 /* NetworkNotificationManager.cpp */,
    90599079                                514526EB271E1626000467B6 /* NetworkNotificationManager.h */,
     9080                                512CD6962721EFC200F7F8EC /* WebPushDaemonConnection.cpp */,
     9081                                512CD6972721EFC300F7F8EC /* WebPushDaemonConnection.h */,
    90609082                        );
    90619083                        path = Notifications;
     
    95799601                                5CBB6D4D271F67CC00FD1A5D /* com.apple.webkit.webpushd.plist */,
    95809602                                5C157A0B2717CA1C00ED5280 /* WebPushDaemonMain.mm */,
     9603                                512CD69D2723393A00F7F8EC /* WebPushDaemon.h */,
     9604                                512CD69E2723393A00F7F8EC /* WebPushDaemon.mm */,
    95819605                        );
    95829606                        path = webpushd;
     
    1210112125                        files = (
    1210212126                                5C1579FC2717AF5000ED5280 /* DaemonUtilities.h in Headers */,
     12127                                512CD69F2723393A00F7F8EC /* WebPushDaemon.h in Headers */,
    1210312128                        );
    1210412129                        runOnlyForDeploymentPostprocessing = 0;
     
    1281912844                                93AB9B4D257567DC0098B10E /* SpeechRecognitionRemoteRealtimeMediaSourceManager.h in Headers */,
    1282012845                                93D6B772254BB5190058DD3A /* SpeechRecognitionServer.h in Headers */,
     12846                                512CD69A2721F0A900F7F8EC /* WebPushDaemonConstants.h in Headers */,
    1282112847                                93D6B784254CCD0E0058DD3A /* SpeechRecognitionServerMessages.h in Headers */,
    1282212848                                93D6B785254CCD430058DD3A /* SpeechRecognitionServerMessagesReplies.h in Headers */,
     
    1290612932                                9955A6EC1C7980C200EB6A93 /* WebAutomationSession.h in Headers */,
    1290712933                                99C3AE2D1DADA6AD00AF5C16 /* WebAutomationSessionMacros.h in Headers */,
     12934                                512CD6982721EFC800F7F8EC /* WebPushDaemonConnection.h in Headers */,
    1290812935                                1C0A19581C90068F00FE0EBB /* WebAutomationSessionMessages.h in Headers */,
    1290912936                                1C0A19471C8FF1A800FE0EBB /* WebAutomationSessionProxy.h in Headers */,
     
    1466114688                        buildActionMask = 2147483647;
    1466214689                        files = (
     14690                                512CD6A02723393A00F7F8EC /* WebPushDaemon.mm in Sources */,
    1466314691                                5C157A012717B7FB00ED5280 /* ArgumentCoders.cpp in Sources */,
    1466414692                                5C1579FF2717B6D200ED5280 /* DaemonDecoder.cpp in Sources */,
  • trunk/Source/WebKit/webpushd/WebPushDaemon.h

    r284886 r284887  
    2424 */
    2525
    26 #include "config.h"
    27 #include "DaemonConnection.h"
     26#pragma once
    2827
    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>
    3033
    31 namespace WebKit {
     34using WebKit::WebPushD::MessageType;
    3235
    33 namespace Daemon {
     36namespace WebPushD {
    3437
    35 #if !PLATFORM(COCOA)
     38using EncodedMessage = Vector<uint8_t>;
    3639
    37 template<typename Traits>
    38 void ConnectionToMachService<Traits>::send(typename Traits::MessageType, EncodedMessage&&) const
    39 {
    40 }
     40class Daemon {
     41    friend class WTF::NeverDestroyed<Daemon>;
     42public:
     43    static Daemon& singleton();
    4144
    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);
    4748
    48 template class ConnectionToMachService<PCM::ConnectionTraits>;
     49    // Message handlers
     50    void echoTwice(const String&, CompletionHandler<void(const String&)>&& replySender);
    4951
    50 #endif
     52private:
     53    Daemon() = default;
    5154
    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};
    5358
    54 } // namespace WebKit
     59} // namespace WebPushD
  • trunk/Source/WebKit/webpushd/WebPushDaemon.mm

    r284886 r284887  
    2525
    2626#import "config.h"
    27 #import "DaemonConnection.h"
     27#import "WebPushDaemon.h"
     28
    2829#import "DaemonDecoder.h"
    2930#import "DaemonEncoder.h"
    3031#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>
    3337#import <wtf/Span.h>
    34 #import <wtf/spi/darwin/XPCSPI.h>
     38
     39using namespace WebKit::WebPushD;
    3540
    3641namespace WebPushD {
    3742
    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 };
     43namespace MessageInfo {
    4544
    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
     51FUNCTION(echoTwice)
     52ARGUMENTS(String)
     53REPLY(String)
     54END
     55
     56#undef FUNCTION
     57#undef ARGUMENTS
     58#undef REPLY
     59#undef END
     60
     61WebPushD::EncodedMessage echoTwice::encodeReply(String reply)
    4762{
    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
     70template<typename Info>
     71void 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
     87Daemon& Daemon::singleton()
     88{
     89    static NeverDestroyed<Daemon> daemon;
     90    return daemon;
     91}
     92
     93void 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
     112void Daemon::connectionAdded(xpc_connection_t)
     113{
     114    // FIXME: Track connections
     115}
     116
     117void Daemon::connectionRemoved(xpc_connection_t)
     118{
     119    // FIXME: Track connections
     120}
     121
     122CompletionHandler<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) {
    49128        auto reply = adoptNS(xpc_dictionary_create_reply(request.get()));
    50129        ASSERT(xpc_get_type(reply.get()) == XPC_TYPE_DICTIONARY);
     
    55134}
    56135
    57 static void echoTwice(Span<const uint8_t> encodedMessage, CompletionHandler<void(Vector<uint8_t>&&)>&& replySender)
     136void Daemon::decodeAndHandleMessage(MessageType messageType, Span<const uint8_t> encodedMessage, CompletionHandler<void(EncodedMessage&&)>&& replySender)
    58137{
    59     WebKit::Daemon::Decoder decoder(encodedMessage);
    60     std::optional<String> string;
    61     decoder >> string;
    62     if (!string)
    63         return;
     138    ASSERT(messageTypeSendsReply(messageType) == !!replySender);
    64139
    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 {
    73140    switch (messageType) {
    74141    case MessageType::EchoTwice:
    75         echoTwice(encodedMessage, WTFMove(replySender));
    76         return;
     142        handleWebPushDMessageWithReply<MessageInfo::echoTwice>(encodedMessage, WTFMove(replySender));
     143        break;
    77144    }
    78145}
    79146
    80 static void connectionEventHandler(xpc_object_t request)
     147void Daemon::echoTwice(const String& message, CompletionHandler<void(const String&)>&& replySender)
    81148{
    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));
    102150}
    103151
    104152} // 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  
    2929#import "DaemonEncoder.h"
    3030#import "DaemonUtilities.h"
     31#import "WebPushDaemon.h"
    3132#import <Foundation/Foundation.h>
    3233#import <wtf/MainThread.h>
    33 #import <wtf/Span.h>
    3434#import <wtf/spi/darwin/XPCSPI.h>
     35
     36using WebKit::Daemon::EncodedMessage;
     37using WebPushD::Daemon;
    3538
    3639namespace WebPushD {
    3740
    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)
     41static void connectionEventHandler(xpc_object_t request)
    4742{
    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);
    5544}
    5645
    57 static void echoTwice(Span<const uint8_t> encodedMessage, CompletionHandler<void(Vector<uint8_t>&&)>&& replySender)
     46static void connectionAdded(xpc_connection_t connection)
    5847{
    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);
    6949}
    7050
    71 static void decodeMessageAndSendReply(MessageType messageType, Span<const uint8_t> encodedMessage, CompletionHandler<void(Vector<uint8_t>&&)>&& replySender)
     51static void connectionRemoved(xpc_connection_t connection)
    7252{
    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);
    10254}
    10355
  • trunk/Tools/ChangeLog

    r284878 r284887  
     12021-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
    1132021-10-26  Simon Fraser  <simon.fraser@apple.com>
    214
  • trunk/Tools/MiniBrowser/mac/AppDelegate.m

    r277627 r284887  
    9999        _WKWebsiteDataStoreConfiguration *configuration = [[[_WKWebsiteDataStoreConfiguration alloc] init] autorelease];
    100100        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
    101106        dataStore = [[WKWebsiteDataStore alloc] _initWithConfiguration:configuration];
    102107    }
  • trunk/Tools/MiniBrowser/mac/WK2BrowserWindowController.m

    r275110 r284887  
    211211
    212212    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);
    213221}
    214222
Note: See TracChangeset for help on using the changeset viewer.