Timestamp:
Dec 9, 2021, 10:58:34 AM (3 years ago)
Author:
beidson@apple.com
Message:

Add ability to inject messages into webpushd
https://bugs.webkit.org/show_bug.cgi?id=233988

Reviewed by Alex Christensen.

Source/WebKit:

Covered by API tests.

This patch:

  • Adds WKWebsiteDataStore SPI to fetch pending push messages for the embedding application
  • Gives webpushd code to inject a push message for a given bundle identifier
  • Gives webpushtool the ability to send one of these fake messages
  • Gives webpushtool the ability to reconnect to the next daemon instance after the current connection is dropped
  • Tests the injection and fetching of push messages via TestWebKitAPI
  • Configurations/webpushtool.xcconfig:
  • WebKit.xcodeproj/project.pbxproj:
  • Resources/webpushtool.entitlements:
  • NetworkProcess/NetworkProcess.cpp:

(WebKit::NetworkProcess::getPendingPushMessages):
(WebKit::NetworkProcess::processPushMessage):

  • NetworkProcess/NetworkProcess.h:
  • NetworkProcess/NetworkProcess.messages.in:
  • NetworkProcess/Notifications/NetworkNotificationManager.cpp:

(WebKit::NetworkNotificationManager::getPendingPushMessages):
(WebKit::ReplyCaller<Vector<WebPushMessage>::callReply):

  • NetworkProcess/Notifications/NetworkNotificationManager.h:
  • Shared/Cocoa/WebPushMessageCocoa.mm: Copied from Source/WebKit/webpushd/webpushtool/WebPushToolConnection.h.

(WebKit::WebPushMessage::fromDictionary):
(WebKit::WebPushMessage::toDictionary const):

  • Shared/PushMessageForTesting.h: Copied from Source/WebKit/Shared/WebPushDaemonConstants.h.

(WebKit::WebPushD::PushMessageForTesting::encode const):
(WebKit::WebPushD::PushMessageForTesting::decode):

  • Shared/WebPushDaemonConstants.h:

(WebKit::WebPushD::messageTypeSendsReply):

  • Shared/WebPushMessage.h: Copied from Source/WebKit/webpushd/webpushtool/WebPushToolConnection.h.

(WebKit::WebPushMessage::encode const):
(WebKit::WebPushMessage::decode):

  • UIProcess/API/Cocoa/WKWebsiteDataStore.mm:

(-[WKWebsiteDataStore _getPendingPushMessages:]):
(-[WKWebsiteDataStore _processPushMessage:completionHandler:]):
(-[WKWebsiteDataStore _processPushMessage:registration:completionHandler:]): Deleted.

  • UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h:
  • UIProcess/Network/NetworkProcessProxy.cpp:

(WebKit::NetworkProcessProxy::getPendingPushMessages):
(WebKit::NetworkProcessProxy::processPushMessage):

  • UIProcess/Network/NetworkProcessProxy.h:
  • webpushd/PushClientConnection.h:
  • webpushd/PushClientConnection.mm:

(WebPushD::ClientConnection::hostAppHasPushEntitlement):
(WebPushD::ClientConnection::hostAppHasPushInjectEntitlement):
(WebPushD::ClientConnection::hostHasEntitlement):
(WebPushD::ClientConnection::broadcastDebugMessage):

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

(WebPushD::MessageInfo::injectPushMessageForTesting::encodeReply):
(WebPushD::MessageInfo::getPendingPushMessages::encodeReply):
(WebPushD::Daemon::decodeAndHandleMessage):
(WebPushD::Daemon::injectPushMessageForTesting):
(WebPushD::Daemon::getPendingPushMessages):

  • webpushd/webpushtool/WebPushToolConnection.h:

(WebPushTool::Connection::setPushMessage):

  • webpushd/webpushtool/WebPushToolConnection.mm:

(WebPushTool::Connection::startAction):
(WebPushTool::Connection::sendPushMessage):

  • webpushd/webpushtool/WebPushToolMain.mm:

(printUsageAndTerminate):
(pushMessageFromArguments):
(main):

Tools:

  • TestWebKitAPI/Configurations/TestWebKitAPI-iOS.entitlements:
  • TestWebKitAPI/Configurations/TestWebKitAPI-macOS-internal.entitlements:
  • TestWebKitAPI/Configurations/TestWebKitAPI-macOS.entitlements:
  • TestWebKitAPI/Tests/WebKitCocoa/PushAPI.mm:

(messageDictionary):

  • TestWebKitAPI/Tests/WebKitCocoa/WebPushDaemon.mm:

(TestWebKitAPI::createMessageDictionary):
(TestWebKitAPI::sendMessageToDaemon):
(TestWebKitAPI::sendMessageToDaemonWaitingForReply):
(TestWebKitAPI::sendConfigurationWithAuditToken):
(TestWebKitAPI::createAndConfigureConnectionToService):
(TestWebKitAPI::encodeString):
(TestWebKitAPI::TEST):
(TestWebKitAPI::function):

  • TestWebKitAPI/cocoa/TestWKWebView.h:
File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/Shared/PushMessageForTesting.h

    r286787 r286788  
    2626#pragma once
    2727
     28
     29
     30
    2831namespace WebKit::WebPushD {
    2932
    30 constexpr const char* protocolVersionKey = "protocol version";
    31 constexpr uint64_t protocolVersionValue = 1;
    32 constexpr const char* protocolEncodedMessageKey = "encoded message";
     33struct PushMessageForTesting {
     34;
     35;
    3336
    34 constexpr const char* protocolDebugMessageKey { "debug message" };
    35 constexpr const char* protocolDebugMessageLevelKey { "debug message level" };
    36 
    37 constexpr const char* protocolMessageTypeKey { "message type" };
    38 enum class MessageType : uint8_t {
    39     EchoTwice = 1,
    40     RequestSystemNotificationPermission,
    41     DeletePushAndNotificationRegistration,
    42     GetOriginsWithPushAndNotificationPermissions,
    43     SetDebugModeIsEnabled,
    44     UpdateConnectionConfiguration,
     37    String targetAppCodeSigningIdentifier;
     38    URL registrationURL;
     39    String message;
    4540};
    4641
    47 inline bool messageTypeSendsReply(MessageType messageType)
     42template<class Encoder>
     43void PushMessageForTesting::encode(Encoder& encoder) const
    4844{
    49     switch (messageType) {
    50     case MessageType::EchoTwice:
    51     case MessageType::GetOriginsWithPushAndNotificationPermissions:
    52     case MessageType::DeletePushAndNotificationRegistration:
    53     case MessageType::RequestSystemNotificationPermission:
    54         return true;
    55     case MessageType::SetDebugModeIsEnabled:
    56     case MessageType::UpdateConnectionConfiguration:
    57         return false;
    58     }
    59     ASSERT_NOT_REACHED();
    60     return false;
     45    encoder << targetAppCodeSigningIdentifier << registrationURL << message;
     46}
     47
     48template<class Decoder>
     49std::optional<PushMessageForTesting> PushMessageForTesting::decode(Decoder& decoder)
     50{
     51    std::optional<String> targetAppCodeSigningIdentifier;
     52    decoder >> targetAppCodeSigningIdentifier;
     53    if (!targetAppCodeSigningIdentifier)
     54        return std::nullopt;
     55
     56    std::optional<URL> registrationURL;
     57    decoder >> registrationURL;
     58    if (!registrationURL)
     59        return std::nullopt;
     60
     61    std::optional<String> message;
     62    decoder >> message;
     63    if (!message)
     64        return std::nullopt;
     65
     66    return { {
     67        WTFMove(*targetAppCodeSigningIdentifier),
     68        WTFMove(*registrationURL),
     69        WTFMove(*message),
     70    } };
    6171}
    6272
Note: See TracChangeset for help on using the changeset viewer.