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

Changeset 286273 in webkit


Ignore:
Timestamp:
Nov 29, 2021, 4:20:57 PM (5 years ago)
Author:
beidson@apple.com
Message:

Make webpushd "fake registration for testing" much more complicated by adding a "mock app bundle" install
https://bugs.webkit.org/show_bug.cgi?id=233454

Reviewed by Alex Christensen.

Covered by API tests.

Before this patch, webpushd remembered "registrations" using a simple in-memory HashMap.

In the near future, registrations will actually be represented with a placeholder app bundle on disk.

The process of installing placeholders (and checking for existing ones) is complicated and asynchronous.

This patch shifts the in-memory testing implementation from a simple HashMap to a "complicated and asynchronous"
registration mechanism that simulates how app-bundle installs will work.

Once the "real" mechanisms are in place there will be much more in-depth testing that we can do.
For now, this is a "no behavior change" patch.

  • NetworkProcess/Notifications/Cocoa/WebPushDaemonConnectionCocoa.mm:

(WebKit::WebPushD::Connection::connectionReceivedEvent const):

  • UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
  • WebKit.xcodeproj/project.pbxproj:

"PushAppBundle" is an abstract base class for representing a placeholder application bundle for a registration.
Eventually there will be a native one for each platform that actually does system operations.
For now, the concrete implementation is the in-memory "Mock" app bundle.

  • webpushd/PushAppBundle.h: Copied from Source/WebKit/webpushd/PushClientConnection.h.
  • webpushd/PushAppBundle.mm: Copied from Source/WebKit/webpushd/PushClientConnection.h.

(WebPushD::PushAppBundleClient::~PushAppBundleClient):
(WebPushD::PushAppBundle::PushAppBundle):
(WebPushD::PushAppBundle::~PushAppBundle):
(WebPushD::PushAppBundle::detachFromClient):

An "AppBundleRequest" is a queable operation meant to do something with an "App bundle".
For now the operations are "create" and "delete"

  • webpushd/AppBundleRequest.h: Added.

(WebPushD::AppBundleRequestImpl::AppBundleRequestImpl):
(WebPushD::AppBundleRequestImpl::~AppBundleRequestImpl):
(WebPushD::AppBundleRequestImpl::callCompletionHandlerAndCleanup):
(WebPushD::AppBundlePermissionsRequest::AppBundlePermissionsRequest):
(WebPushD::AppBundleDeletionRequest::AppBundleDeletionRequest):

  • webpushd/AppBundleRequest.mm: Added.

(WebPushD::AppBundleRequest::AppBundleRequest):
(WebPushD::AppBundleRequest::~AppBundleRequest):
(WebPushD::AppBundleRequest::start):
(WebPushD::AppBundleRequest::cancel):
(WebPushD::AppBundleRequest::cleanupAfterCompletionHandler):
(WebPushD::AppBundlePermissionsRequest::startInternal):
(WebPushD::AppBundlePermissionsRequest::didCheckForExistingBundle):
(WebPushD::AppBundlePermissionsRequest::didCreateAppBundle):
(WebPushD::AppBundleDeletionRequest::startInternal):
(WebPushD::AppBundleDeletionRequest::didDeleteExistingBundleWithError):

  • webpushd/MockAppBundleForTesting.h: Copied from Source/WebKit/webpushd/PushClientConnection.h.

(WebPushD::MockAppBundleForTesting::create):

  • webpushd/MockAppBundleForTesting.mm: Added.

(WebPushD::MockAppBundleForTesting::MockAppBundleForTesting):
(WebPushD::MockAppBundleForTesting::~MockAppBundleForTesting):
(WebPushD::MockAppBundleForTesting::checkForExistingBundle):
(WebPushD::MockAppBundleForTesting::deleteExistingBundle):
(WebPushD::MockAppBundleForTesting::createBundle):
(WebPushD::MockAppBundleForTesting::stop):

  • webpushd/MockAppBundleRegistry.h: Copied from Source/WebKit/webpushd/PushClientConnection.h.
  • webpushd/MockAppBundleRegistry.mm: Added.

(WebPushD::MockAppBundleRegistry::singleton):
(WebPushD::MockAppBundleRegistry::getOriginsWithRegistrations):
(WebPushD::MockAppBundleRegistry::doesBundleExist):
(WebPushD::MockAppBundleRegistry::createBundle):
(WebPushD::MockAppBundleRegistry::deleteBundle):

  • webpushd/PushClientConnection.h:
  • webpushd/PushClientConnection.mm:

(WebPushD::ClientConnection::create):
(WebPushD::ClientConnection::enqueueAppBundleRequest):
(WebPushD::ClientConnection::maybeStartNextAppBundleRequest):
(WebPushD::ClientConnection::didCompleteAppBundleRequest):
(WebPushD::ClientConnection::connectionClosed):

  • webpushd/WebPushDaemon.h:
  • webpushd/WebPushDaemon.mm:

(WebPushD::Daemon::connectionAdded):
(WebPushD::Daemon::connectionRemoved):
(WebPushD::Daemon::requestSystemNotificationPermission):
(WebPushD::Daemon::getOriginsWithPushAndNotificationPermissions):
(WebPushD::Daemon::deletePushAndNotificationRegistration):

Location:
trunk
Files:
4 added
9 edited
4 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r286272 r286273  
     12021-11-29  Brady Eidson  <beidson@apple.com>
     2
     3        Make webpushd "fake registration for testing" much more complicated by adding a "mock app bundle" install
     4        https://bugs.webkit.org/show_bug.cgi?id=233454
     5
     6        Reviewed by Alex Christensen.
     7
     8        Covered by API tests.
     9       
     10        Before this patch, webpushd remembered "registrations" using a simple in-memory HashMap.
     11       
     12        In the near future, registrations will actually be represented with a placeholder app bundle on disk.
     13       
     14        The process of installing placeholders (and checking for existing ones) is complicated and asynchronous.
     15       
     16        This patch shifts the in-memory testing implementation from a simple HashMap to a "complicated and asynchronous"
     17        registration mechanism that simulates how app-bundle installs will work.
     18       
     19        Once the "real" mechanisms are in place there will be much more in-depth testing that we can do.
     20        For now, this is a "no behavior change" patch.
     21
     22        * NetworkProcess/Notifications/Cocoa/WebPushDaemonConnectionCocoa.mm:
     23        (WebKit::WebPushD::Connection::connectionReceivedEvent const):
     24        * UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
     25
     26        * WebKit.xcodeproj/project.pbxproj:
     27
     28        "PushAppBundle" is an abstract base class for representing a placeholder application bundle for a registration.
     29        Eventually there will be a native one for each platform that actually does system operations.
     30        For now, the concrete implementation is the in-memory "Mock" app bundle.
     31
     32        * webpushd/PushAppBundle.h: Copied from Source/WebKit/webpushd/PushClientConnection.h.
     33        * webpushd/PushAppBundle.mm: Copied from Source/WebKit/webpushd/PushClientConnection.h.
     34        (WebPushD::PushAppBundleClient::~PushAppBundleClient):
     35        (WebPushD::PushAppBundle::PushAppBundle):
     36        (WebPushD::PushAppBundle::~PushAppBundle):
     37        (WebPushD::PushAppBundle::detachFromClient):
     38       
     39        An "AppBundleRequest" is a queable operation meant to do something with an "App bundle".
     40        For now the operations are "create" and "delete"
     41       
     42        * webpushd/AppBundleRequest.h: Added.
     43        (WebPushD::AppBundleRequestImpl::AppBundleRequestImpl):
     44        (WebPushD::AppBundleRequestImpl::~AppBundleRequestImpl):
     45        (WebPushD::AppBundleRequestImpl::callCompletionHandlerAndCleanup):
     46        (WebPushD::AppBundlePermissionsRequest::AppBundlePermissionsRequest):
     47        (WebPushD::AppBundleDeletionRequest::AppBundleDeletionRequest):
     48        * webpushd/AppBundleRequest.mm: Added.
     49        (WebPushD::AppBundleRequest::AppBundleRequest):
     50        (WebPushD::AppBundleRequest::~AppBundleRequest):
     51        (WebPushD::AppBundleRequest::start):
     52        (WebPushD::AppBundleRequest::cancel):
     53        (WebPushD::AppBundleRequest::cleanupAfterCompletionHandler):
     54        (WebPushD::AppBundlePermissionsRequest::startInternal):
     55        (WebPushD::AppBundlePermissionsRequest::didCheckForExistingBundle):
     56        (WebPushD::AppBundlePermissionsRequest::didCreateAppBundle):
     57        (WebPushD::AppBundleDeletionRequest::startInternal):
     58        (WebPushD::AppBundleDeletionRequest::didDeleteExistingBundleWithError):
     59
     60        * webpushd/MockAppBundleForTesting.h: Copied from Source/WebKit/webpushd/PushClientConnection.h.
     61        (WebPushD::MockAppBundleForTesting::create):
     62        * webpushd/MockAppBundleForTesting.mm: Added.
     63        (WebPushD::MockAppBundleForTesting::MockAppBundleForTesting):
     64        (WebPushD::MockAppBundleForTesting::~MockAppBundleForTesting):
     65        (WebPushD::MockAppBundleForTesting::checkForExistingBundle):
     66        (WebPushD::MockAppBundleForTesting::deleteExistingBundle):
     67        (WebPushD::MockAppBundleForTesting::createBundle):
     68        (WebPushD::MockAppBundleForTesting::stop):
     69
     70        * webpushd/MockAppBundleRegistry.h: Copied from Source/WebKit/webpushd/PushClientConnection.h.
     71        * webpushd/MockAppBundleRegistry.mm: Added.
     72        (WebPushD::MockAppBundleRegistry::singleton):
     73        (WebPushD::MockAppBundleRegistry::getOriginsWithRegistrations):
     74        (WebPushD::MockAppBundleRegistry::doesBundleExist):
     75        (WebPushD::MockAppBundleRegistry::createBundle):
     76        (WebPushD::MockAppBundleRegistry::deleteBundle):
     77
     78        * webpushd/PushClientConnection.h:
     79        * webpushd/PushClientConnection.mm:
     80        (WebPushD::ClientConnection::create):
     81        (WebPushD::ClientConnection::enqueueAppBundleRequest):
     82        (WebPushD::ClientConnection::maybeStartNextAppBundleRequest):
     83        (WebPushD::ClientConnection::didCompleteAppBundleRequest):
     84        (WebPushD::ClientConnection::connectionClosed):
     85
     86        * webpushd/WebPushDaemon.h:
     87        * webpushd/WebPushDaemon.mm:
     88        (WebPushD::Daemon::connectionAdded):
     89        (WebPushD::Daemon::connectionRemoved):
     90        (WebPushD::Daemon::requestSystemNotificationPermission):
     91        (WebPushD::Daemon::getOriginsWithPushAndNotificationPermissions):
     92        (WebPushD::Daemon::deletePushAndNotificationRegistration):
     93
    1942021-11-29  David Kilzer  <ddkilzer@apple.com>
    295
  • trunk/Source/WebKit/NetworkProcess/Notifications/Cocoa/WebPushDaemonConnectionCocoa.mm

    r284887 r286273  
    6262        return;
    6363    auto messageLevel = static_cast<JSC::MessageLevel>(xpc_dictionary_get_uint64(request, protocolDebugMessageLevelKey));
    64     networkSession().networkProcess().broadcastConsoleMessage(networkSession().sessionID(), MessageSource::PrivateClickMeasurement, messageLevel, String::fromUTF8(debugMessage));
     64    networkSession().networkProcess().broadcastConsoleMessage(networkSession().sessionID(), MessageSource::Other, messageLevel, String::fromUTF8(debugMessage));
    6565}
    6666
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h

    r285799 r286273  
    160160
    161161- (void)_webView:(WKWebView *)webView startXRSessionWithCompletionHandler:(void (^)(id))completionHandler WK_API_AVAILABLE(macos(12.0), ios(15.0));
    162 - (void)_webView:(WKWebView *)webView requestNotificationPermissionForSecurityOrigin:(WKSecurityOrigin *)securityOrigin decisionHandler:(void (^)(BOOL))decisionHandler WK_API_AVAILABLE(macos(10.13.4));
     162- (void)_webView:(WKWebView *)webView requestNotificationPermissionForSecurityOrigin:(WKSecurityOrigin *)securityOrigin decisionHandler:(void (^)(BOOL))decisionHandler WK_API_AVAILABLE(macos(10.13.4), ios(WK_IOS_TBA));
    163163
    164164#if TARGET_OS_IPHONE
  • trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj

    r286258 r286273  
    10061006                515BE1B31D5902DD00DD7C68 /* GamepadData.h in Headers */ = {isa = PBXBuildFile; fileRef = 515BE1B01D59006900DD7C68 /* GamepadData.h */; };
    10071007                515BE1B51D5917FF00DD7C68 /* UIGamepad.h in Headers */ = {isa = PBXBuildFile; fileRef = 515BE1AD1D555C5100DD7C68 /* UIGamepad.h */; };
     1008                5160E955274B887200567388 /* AppBundleRequest.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5160E953274B887100567388 /* AppBundleRequest.mm */; };
     1009                5160E956274B887200567388 /* AppBundleRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = 5160E954274B887100567388 /* AppBundleRequest.h */; };
     1010                5160E959274C0D8900567388 /* PushAppBundle.h in Headers */ = {isa = PBXBuildFile; fileRef = 5160E957274C0D8800567388 /* PushAppBundle.h */; };
     1011                5160E95A274C0D8900567388 /* PushAppBundle.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5160E958274C0D8800567388 /* PushAppBundle.mm */; };
     1012                5160E95E274C2A0300567388 /* MockAppBundleRegistry.h in Headers */ = {isa = PBXBuildFile; fileRef = 5160E95C274C2A0300567388 /* MockAppBundleRegistry.h */; };
     1013                5160E960274C2A4000567388 /* MockAppBundleRegistry.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5160E95F274C2A3F00567388 /* MockAppBundleRegistry.mm */; };
    10081014                5163199416289A6000E22F00 /* NetworkProcessMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51ACC9341628064800342550 /* NetworkProcessMessageReceiver.cpp */; };
    10091015                5163199516289A6300E22F00 /* NetworkProcessMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = 51ACC9351628064800342550 /* NetworkProcessMessages.h */; };
     
    10571063                51F060E11654318500F3282F /* WebMDNSRegisterMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51F060DD1654317500F3282F /* WebMDNSRegisterMessageReceiver.cpp */; };
    10581064                51F060E11654318500F3283F /* NetworkMDNSRegisterMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51F060DD1654317500F3283F /* NetworkMDNSRegisterMessageReceiver.cpp */; };
     1065                51F7BB76274498BB00C45A72 /* MockAppBundleForTesting.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51F7BB74274498BA00C45A72 /* MockAppBundleForTesting.mm */; };
     1066                51F7BB77274498BB00C45A72 /* MockAppBundleForTesting.h in Headers */ = {isa = PBXBuildFile; fileRef = 51F7BB75274498BB00C45A72 /* MockAppBundleForTesting.h */; };
    10591067                51F7BB7B2744C50700C45A72 /* PushClientConnection.h in Headers */ = {isa = PBXBuildFile; fileRef = 51F7BB792744C50700C45A72 /* PushClientConnection.h */; };
    10601068                51F7BB7C2744C50700C45A72 /* PushClientConnection.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51F7BB7A2744C50700C45A72 /* PushClientConnection.mm */; };
     
    43394347                515C415B207D74E100726E02 /* SuspendedPageProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SuspendedPageProxy.h; sourceTree = "<group>"; };
    43404348                5160BFE013381DF900918999 /* LoggingFoundation.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = LoggingFoundation.mm; sourceTree = "<group>"; };
     4349                5160E953274B887100567388 /* AppBundleRequest.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AppBundleRequest.mm; sourceTree = "<group>"; };
     4350                5160E954274B887100567388 /* AppBundleRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppBundleRequest.h; sourceTree = "<group>"; };
     4351                5160E957274C0D8800567388 /* PushAppBundle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PushAppBundle.h; sourceTree = "<group>"; };
     4352                5160E958274C0D8800567388 /* PushAppBundle.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PushAppBundle.mm; sourceTree = "<group>"; };
     4353                5160E95C274C2A0300567388 /* MockAppBundleRegistry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MockAppBundleRegistry.h; sourceTree = "<group>"; };
     4354                5160E95F274C2A3F00567388 /* MockAppBundleRegistry.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MockAppBundleRegistry.mm; sourceTree = "<group>"; };
    43414355                5164C0941B05B757004F102A /* AuxiliaryProcess.messages.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = AuxiliaryProcess.messages.in; sourceTree = "<group>"; };
    43424356                516A4A5B120A2CCD00C05B7F /* APIError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APIError.h; sourceTree = "<group>"; };
     
    44464460                51F060DD1654317500F3283F /* NetworkMDNSRegisterMessageReceiver.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = NetworkMDNSRegisterMessageReceiver.cpp; path = DerivedSources/WebKit2/NetworkMDNSRegisterMessageReceiver.cpp; sourceTree = BUILT_PRODUCTS_DIR; };
    44474461                51F060DE1654317500F3281B /* WebResourceLoaderMessages.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = WebResourceLoaderMessages.h; path = DerivedSources/WebKit2/WebResourceLoaderMessages.h; sourceTree = BUILT_PRODUCTS_DIR; };
     4462                51F7BB74274498BA00C45A72 /* MockAppBundleForTesting.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MockAppBundleForTesting.mm; sourceTree = "<group>"; };
     4463                51F7BB75274498BB00C45A72 /* MockAppBundleForTesting.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MockAppBundleForTesting.h; sourceTree = "<group>"; };
    44484464                51F7BB792744C50700C45A72 /* PushClientConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PushClientConnection.h; sourceTree = "<group>"; };
    44494465                51F7BB7A2744C50700C45A72 /* PushClientConnection.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PushClientConnection.mm; sourceTree = "<group>"; };
     
    98599875                        children = (
    98609876                                5CBB6D4D271F67CC00FD1A5D /* com.apple.webkit.webpushd.plist */,
     9877                                5160E954274B887100567388 /* AppBundleRequest.h */,
     9878                                5160E953274B887100567388 /* AppBundleRequest.mm */,
     9879                                51F7BB75274498BB00C45A72 /* MockAppBundleForTesting.h */,
     9880                                51F7BB74274498BA00C45A72 /* MockAppBundleForTesting.mm */,
     9881                                5160E95C274C2A0300567388 /* MockAppBundleRegistry.h */,
     9882                                5160E95F274C2A3F00567388 /* MockAppBundleRegistry.mm */,
     9883                                5160E957274C0D8800567388 /* PushAppBundle.h */,
     9884                                5160E958274C0D8800567388 /* PushAppBundle.mm */,
    98619885                                51F7BB792744C50700C45A72 /* PushClientConnection.h */,
    98629886                                51F7BB7A2744C50700C45A72 /* PushClientConnection.mm */,
     
    1240012424                        buildActionMask = 2147483647;
    1240112425                        files = (
     12426                                5160E959274C0D8900567388 /* PushAppBundle.h in Headers */,
     12427                                51F7BB7B2744C50700C45A72 /* PushClientConnection.h in Headers */,
     12428                                5160E95E274C2A0300567388 /* MockAppBundleRegistry.h in Headers */,
    1240212429                                5C1579FC2717AF5000ED5280 /* DaemonUtilities.h in Headers */,
    12403                                 51F7BB7B2744C50700C45A72 /* PushClientConnection.h in Headers */,
     12430                                5160E956274B887200567388 /* AppBundleRequest.h in Headers */,
    1240412431                                512CD69F2723393A00F7F8EC /* WebPushDaemon.h in Headers */,
     12432                                51F7BB77274498BB00C45A72 /* MockAppBundleForTesting.h in Headers */,
    1240512433                        );
    1240612434                        runOnlyForDeploymentPostprocessing = 0;
     
    1493914967                                51F7BB7D2745640400C45A72 /* CodeSigning.mm in Sources */,
    1494014968                                5C1579FF2717B6D200ED5280 /* DaemonDecoder.cpp in Sources */,
     14969                                51F7BB76274498BB00C45A72 /* MockAppBundleForTesting.mm in Sources */,
     14970                                5160E955274B887200567388 /* AppBundleRequest.mm in Sources */,
     14971                                5160E95A274C0D8900567388 /* PushAppBundle.mm in Sources */,
     14972                                5160E960274C2A4000567388 /* MockAppBundleRegistry.mm in Sources */,
     14973                                51F7BB7C2744C50700C45A72 /* PushClientConnection.mm in Sources */,
    1494114974                                5C1579FE2717B6C100ED5280 /* DaemonEncoder.cpp in Sources */,
    1494214975                                5C1579FB2717AF5000ED5280 /* DaemonUtilities.mm in Sources */,
    14943                                 51F7BB7C2744C50700C45A72 /* PushClientConnection.mm in Sources */,
    1494414976                                512CD6A02723393A00F7F8EC /* WebPushDaemon.mm in Sources */,
    1494514977                                5C157A0C2717CA1D00ED5280 /* WebPushDaemonMain.mm in Sources */,
  • trunk/Source/WebKit/webpushd/MockAppBundleForTesting.h

    r286272 r286273  
    2626#pragma once
    2727
    28 #include <optional>
    29 #include <wtf/Forward.h>
    30 #include <wtf/OSObjectPtr.h>
    31 #include <wtf/spi/darwin/XPCSPI.h>
     28#include "PushAppBundle.h"
     29#include <wtf/Vector.h>
    3230#include <wtf/text/WTFString.h>
    3331
    3432namespace WebPushD {
    3533
    36 class ClientConnection {
     34class MockAppBundleForTesting : public PushAppBundle {
    3735    WTF_MAKE_FAST_ALLOCATED;
    3836public:
    39     ClientConnection(xpc_connection_t);
     37    static Ref<MockAppBundleForTesting> create(const String& originString, const String& hostAppBundleIdentifier, PushAppBundleClient& client)
     38    {
     39        return adoptRef(*new MockAppBundleForTesting(originString, hostAppBundleIdentifier, client));
     40    }
    4041
    41     bool hasHostAppAuditToken() const { return !!m_hostAppAuditToken; }
    42     void setHostAppAuditTokenData(const Vector<uint8_t>&);
    43 
    44     const String& hostAppCodeSigningIdentifier();
    45     bool hostAppHasPushEntitlement();
    46 
    47     bool debugModeIsEnabled() const { return m_debugModeEnabled; }
    48     void setDebugModeIsEnabled(bool);
     42    ~MockAppBundleForTesting() final = default;
    4943
    5044private:
    51     OSObjectPtr<xpc_connection_t> m_xpcConnection;
     45    MockAppBundleForTesting(const String& originString, const String& hostAppBundleIdentifier, PushAppBundleClient&);
    5246
    53     std::optional<audit_token_t> m_hostAppAuditToken;
    54     std::optional<String> m_hostAppCodeSigningIdentifier;
    55     std::optional<bool> m_hostAppHasPushEntitlement;
     47    void checkForExistingBundle() final;
     48    void deleteExistingBundle() final;
     49    void createBundle() final;
     50    void stop() final;
    5651
    57     bool m_debugModeEnabled { false };
     52    String m_originString;
     53    String m_hostAppBundleIdentifier;
    5854};
    5955
     56
    6057} // namespace WebPushD
  • trunk/Source/WebKit/webpushd/MockAppBundleRegistry.h

    r286272 r286273  
    2626#pragma once
    2727
    28 #include <optional>
    29 #include <wtf/Forward.h>
    30 #include <wtf/OSObjectPtr.h>
    31 #include <wtf/spi/darwin/XPCSPI.h>
     28#include <wtf/HashMap.h>
     29#include <wtf/HashSet.h>
     30#include <wtf/text/StringHash.h>
    3231#include <wtf/text/WTFString.h>
    3332
    3433namespace WebPushD {
    3534
    36 class ClientConnection {
    37     WTF_MAKE_FAST_ALLOCATED;
     35class MockAppBundleForTesting;
     36
     37class MockAppBundleRegistry {
     38    friend class MockAppBundleForTesting;
    3839public:
    39     ClientConnection(xpc_connection_t);
     40    static MockAppBundleRegistry& singleton();
    4041
    41     bool hasHostAppAuditToken() const { return !!m_hostAppAuditToken; }
    42     void setHostAppAuditTokenData(const Vector<uint8_t>&);
    43 
    44     const String& hostAppCodeSigningIdentifier();
    45     bool hostAppHasPushEntitlement();
    46 
    47     bool debugModeIsEnabled() const { return m_debugModeEnabled; }
    48     void setDebugModeIsEnabled(bool);
     42    Vector<String> getOriginsWithRegistrations(const String& hostAppBundleIdentifier);
    4943
    5044private:
    51     OSObjectPtr<xpc_connection_t> m_xpcConnection;
     45    bool doesBundleExist(const String& hostAppBundleIdentifier, const String& originString);
     46    void createBundle(const String& hostAppBundleIdentifier, const String& originString);
     47    void deleteBundle(const String& hostAppBundleIdentifier, const String& originString);
    5248
    53     std::optional<audit_token_t> m_hostAppAuditToken;
    54     std::optional<String> m_hostAppCodeSigningIdentifier;
    55     std::optional<bool> m_hostAppHasPushEntitlement;
    56 
    57     bool m_debugModeEnabled { false };
     49    HashMap<String, HashSet<String>> m_registeredBundleMap;
    5850};
    5951
  • trunk/Source/WebKit/webpushd/PushAppBundle.h

    r286272 r286273  
    2626#pragma once
    2727
    28 #include <optional>
    29 #include <wtf/Forward.h>
    30 #include <wtf/OSObjectPtr.h>
    31 #include <wtf/spi/darwin/XPCSPI.h>
    32 #include <wtf/text/WTFString.h>
     28#include <wtf/RefCounted.h>
     29
     30@class NSError;
    3331
    3432namespace WebPushD {
    3533
    36 class ClientConnection {
    37     WTF_MAKE_FAST_ALLOCATED;
    38 public:
    39     ClientConnection(xpc_connection_t);
    40 
    41     bool hasHostAppAuditToken() const { return !!m_hostAppAuditToken; }
    42     void setHostAppAuditTokenData(const Vector<uint8_t>&);
    43 
    44     const String& hostAppCodeSigningIdentifier();
    45     bool hostAppHasPushEntitlement();
    46 
    47     bool debugModeIsEnabled() const { return m_debugModeEnabled; }
    48     void setDebugModeIsEnabled(bool);
    49 
    50 private:
    51     OSObjectPtr<xpc_connection_t> m_xpcConnection;
    52 
    53     std::optional<audit_token_t> m_hostAppAuditToken;
    54     std::optional<String> m_hostAppCodeSigningIdentifier;
    55     std::optional<bool> m_hostAppHasPushEntitlement;
    56 
    57     bool m_debugModeEnabled { false };
     34enum class PushAppBundleExists : bool {
     35    No,
     36    Yes,
    5837};
    5938
     39enum class PushAppBundleCreationResult : bool {
     40    Failure,
     41    Success,
     42};
     43
     44class PushAppBundle;
     45
     46class PushAppBundleClient {
     47public:
     48    virtual ~PushAppBundleClient();
     49
     50    virtual void didCheckForExistingBundle(PushAppBundle&, PushAppBundleExists) = 0;
     51    virtual void didDeleteExistingBundleWithError(PushAppBundle&, NSError *) = 0;
     52    virtual void didCreateAppBundle(PushAppBundle&, PushAppBundleCreationResult) = 0;
     53};
     54
     55class PushAppBundle : public RefCounted<PushAppBundle> {
     56public:
     57    virtual ~PushAppBundle();
     58    void detachFromClient();
     59
     60    virtual void checkForExistingBundle() = 0;
     61    virtual void deleteExistingBundle() = 0;
     62    virtual void createBundle() = 0;
     63    virtual void stop() = 0;
     64
     65protected:
     66    PushAppBundle(PushAppBundleClient&);
     67
     68    PushAppBundleClient* m_client;
     69};
     70
     71
    6072} // namespace WebPushD
  • trunk/Source/WebKit/webpushd/PushAppBundle.mm

    r286272 r286273  
    2424 */
    2525
    26 #pragma once
    27 
    28 #include <optional>
    29 #include <wtf/Forward.h>
    30 #include <wtf/OSObjectPtr.h>
    31 #include <wtf/spi/darwin/XPCSPI.h>
    32 #include <wtf/text/WTFString.h>
     26#import "config.h"
     27#import "PushAppBundle.h"
    3328
    3429namespace WebPushD {
    3530
    36 class ClientConnection {
    37     WTF_MAKE_FAST_ALLOCATED;
    38 public:
    39     ClientConnection(xpc_connection_t);
     31PushAppBundleClient::~PushAppBundleClient()
     32{
     33}
    4034
    41     bool hasHostAppAuditToken() const { return !!m_hostAppAuditToken; }
    42     void setHostAppAuditTokenData(const Vector<uint8_t>&);
     35PushAppBundle::PushAppBundle(PushAppBundleClient& client)
     36    : m_client(&client)
     37{
     38}
    4339
    44     const String& hostAppCodeSigningIdentifier();
    45     bool hostAppHasPushEntitlement();
     40PushAppBundle::~PushAppBundle()
     41{
     42    ASSERT(!m_client);
     43}
    4644
    47     bool debugModeIsEnabled() const { return m_debugModeEnabled; }
    48     void setDebugModeIsEnabled(bool);
    49 
    50 private:
    51     OSObjectPtr<xpc_connection_t> m_xpcConnection;
    52 
    53     std::optional<audit_token_t> m_hostAppAuditToken;
    54     std::optional<String> m_hostAppCodeSigningIdentifier;
    55     std::optional<bool> m_hostAppHasPushEntitlement;
    56 
    57     bool m_debugModeEnabled { false };
    58 };
     45void PushAppBundle::detachFromClient()
     46{
     47    stop();
     48    m_client = nullptr;
     49}
    5950
    6051} // namespace WebPushD
  • trunk/Source/WebKit/webpushd/PushClientConnection.h

    r286075 r286273  
    2727
    2828#include <optional>
     29#include <wtf/Deque.h>
    2930#include <wtf/Forward.h>
    3031#include <wtf/OSObjectPtr.h>
     32#include <wtf/RefCounted.h>
     33#include <wtf/WeakPtr.h>
    3134#include <wtf/spi/darwin/XPCSPI.h>
    3235#include <wtf/text/WTFString.h>
     
    3437namespace WebPushD {
    3538
    36 class ClientConnection {
     39class AppBundleRequest;
     40
     41class ClientConnection : public RefCounted<ClientConnection>, public CanMakeWeakPtr<ClientConnection> {
    3742    WTF_MAKE_FAST_ALLOCATED;
    3843public:
    39     ClientConnection(xpc_connection_t);
     44    static Ref<ClientConnection> create(xpc_connection_t);
    4045
    4146    bool hasHostAppAuditToken() const { return !!m_hostAppAuditToken; }
     
    4853    void setDebugModeIsEnabled(bool);
    4954
     55    void enqueueAppBundleRequest(std::unique_ptr<AppBundleRequest>&&);
     56    void didCompleteAppBundleRequest(AppBundleRequest&);
     57
     58    void connectionClosed();
     59
    5060private:
     61    ClientConnection(xpc_connection_t);
     62
     63    void maybeStartNextAppBundleRequest();
     64   
    5165    OSObjectPtr<xpc_connection_t> m_xpcConnection;
    5266
     
    5569    std::optional<bool> m_hostAppHasPushEntitlement;
    5670
     71    Deque<std::unique_ptr<AppBundleRequest>> m_pendingBundleRequests;
     72    std::unique_ptr<AppBundleRequest> m_currentBundleRequest;
     73
    5774    bool m_debugModeEnabled { false };
    5875};
  • trunk/Source/WebKit/webpushd/PushClientConnection.mm

    r286075 r286273  
    2727#import "PushClientConnection.h"
    2828
     29#import "AppBundleRequest.h"
    2930#import "CodeSigning.h"
    3031#import "WebPushDaemon.h"
     
    3435
    3536namespace WebPushD {
     37
     38Ref<ClientConnection> ClientConnection::create(xpc_connection_t connection)
     39{
     40    return adoptRef(*new ClientConnection(connection));
     41}
    3642
    3743ClientConnection::ClientConnection(xpc_connection_t connection)
     
    94100}
    95101
     102void ClientConnection::enqueueAppBundleRequest(std::unique_ptr<AppBundleRequest>&& request)
     103{
     104    RELEASE_ASSERT(m_xpcConnection);
     105    m_pendingBundleRequests.append(WTFMove(request));
     106    maybeStartNextAppBundleRequest();
     107}
     108
     109void ClientConnection::maybeStartNextAppBundleRequest()
     110{
     111    RELEASE_ASSERT(m_xpcConnection);
     112
     113    if (m_currentBundleRequest || m_pendingBundleRequests.isEmpty())
     114        return;
     115
     116    m_currentBundleRequest = m_pendingBundleRequests.takeFirst();
     117    m_currentBundleRequest->start();
     118}
     119
     120void ClientConnection::didCompleteAppBundleRequest(AppBundleRequest& request)
     121{
     122    // If our connection was closed there should be no in-progress bundle requests.
     123    RELEASE_ASSERT(m_xpcConnection);
     124
     125    ASSERT(m_currentBundleRequest.get() == &request);
     126    m_currentBundleRequest = nullptr;
     127
     128    maybeStartNextAppBundleRequest();
     129}
     130
     131void ClientConnection::connectionClosed()
     132{
     133    RELEASE_ASSERT(m_xpcConnection);
     134    m_xpcConnection = nullptr;
     135
     136    if (m_currentBundleRequest) {
     137        m_currentBundleRequest->cancel();
     138        m_currentBundleRequest = nullptr;
     139    }
     140
     141    Deque<std::unique_ptr<AppBundleRequest>> pendingBundleRequests;
     142    pendingBundleRequests.swap(m_pendingBundleRequests);
     143    for (auto& requst : pendingBundleRequests)
     144        requst->cancel();
     145}
     146
    96147} // namespace WebPushD
  • trunk/Source/WebKit/webpushd/WebPushDaemon.h

    r286075 r286273  
    7272
    7373    ClientConnection* toClientConnection(xpc_connection_t);
    74 
    75     HashSet<String> m_inMemoryOriginStringsWithPermissionForTesting;
    76 
    77     HashMap<xpc_connection_t, std::unique_ptr<ClientConnection>> m_connectionMap;
     74    HashMap<xpc_connection_t, Ref<ClientConnection>> m_connectionMap;
    7875};
    7976
  • trunk/Source/WebKit/webpushd/WebPushDaemon.mm

    r286075 r286273  
    2727#import "WebPushDaemon.h"
    2828
     29#import "AppBundleRequest.h"
    2930#import "DaemonDecoder.h"
    3031#import "DaemonEncoder.h"
    3132#import "DaemonUtilities.h"
    3233#import "HandleMessage.h"
     34#import "MockAppBundleRegistry.h"
    3335#import "WebPushDaemonConstants.h"
    3436
     
    181183{
    182184    RELEASE_ASSERT(!m_connectionMap.contains(connection));
    183     m_connectionMap.set(connection, WTF::makeUnique<ClientConnection>(connection));
     185    m_connectionMap.set(connection, ClientConnection::create(connection));
    184186}
    185187
     
    187189{
    188190    RELEASE_ASSERT(m_connectionMap.contains(connection));
    189     m_connectionMap.remove(connection);
     191    auto clientConnection = m_connectionMap.take(connection);
     192    clientConnection->connectionClosed();
    190193}
    191194
     
    254257    }
    255258
    256     // FIXME: This is for an API testing checkpoint
    257     // Next step is actually perform a persistent permissions request on a per-platform basis
    258     m_inMemoryOriginStringsWithPermissionForTesting.add(originString);
    259     replySender(true);
     259    connection->enqueueAppBundleRequest(makeUnique<AppBundlePermissionsRequest>(*connection, originString, WTFMove(replySender)));
    260260}
    261261
     
    267267    }
    268268
    269     // FIXME: This is for an API testing checkpoint
    270     // Next step is actually gather persistent permissions from the system on a per-platform basis
    271     replySender(copyToVector(m_inMemoryOriginStringsWithPermissionForTesting));
     269    // FIXME: This will need platform-specific implementations for real world bundles once implemented.
     270    replySender(MockAppBundleRegistry::singleton().getOriginsWithRegistrations(connection->hostAppCodeSigningIdentifier()));
    272271}
    273272
     
    279278    }
    280279
    281     // FIXME: This is for an API testing checkpoint
    282     // Next step is actually delete any persistent permissions on a per-platform basis
    283     if (m_inMemoryOriginStringsWithPermissionForTesting.remove(originString))
    284         replySender("");
    285     else
    286         replySender(makeString("Origin ", originString, " not registered for push or notifications"));
     280    connection->enqueueAppBundleRequest(makeUnique<AppBundleDeletionRequest>(*connection, originString, WTFMove(replySender)));
    287281}
    288282
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebPushDaemon.mm

    r286075 r286273  
    159159
    160160// FIXME: Re-enable this test for Monterey+ once webkit.org/232857 is resolved.
    161 #if __MAC_OS_X_VERSION_MIN_REQUIRED < 110000 || __MAC_OS_X_VERSION_MIN_REQUIRED >= 120000
     161#if PLATFORM(MAC) && (__MAC_OS_X_VERSION_MIN_REQUIRED < 110000 || __MAC_OS_X_VERSION_MIN_REQUIRED >= 120000)
    162162TEST(WebPushD, DISABLED_BasicCommunication)
    163163#else
     
    256256
    257257// FIXME: Re-enable this test for Monterey+ once webkit.org/232857 is resolved.
    258 #if __MAC_OS_X_VERSION_MIN_REQUIRED < 110000 || __MAC_OS_X_VERSION_MIN_REQUIRED >= 120000
     258#if PLATFORM(MAC) && (__MAC_OS_X_VERSION_MIN_REQUIRED < 110000 || __MAC_OS_X_VERSION_MIN_REQUIRED >= 120000)
    259259TEST(WebPushD, DISABLED_PermissionManagement)
    260260#else
Note: See TracChangeset for help on using the changeset viewer.