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

Changeset 286579 in webkit


Ignore:
Timestamp:
Dec 6, 2021, 4:38:11 PM (5 years ago)
Author:
beidson@apple.com
Message:

webpushd/webpushtool debugging additions
https://bugs.webkit.org/show_bug.cgi?id=233864

Reviewed by Alex Christensen.

Source/WebKit:

Covered by API tests.

This patch:

  • Teaches webpushtool the ability to wait for a reconnect after losing its connection
  • Starts actually broadcasting meaningful debug messages from webpushd
  • webpushd/AppBundleRequest.mm:

(WebPushD::AppBundleRequest::start):
(WebPushD::AppBundlePermissionsRequest::didCheckForExistingBundle):
(WebPushD::AppBundlePermissionsRequest::didCreateAppBundle):
(WebPushD::AppBundleDeletionRequest::didDeleteExistingBundleWithError):

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

(WebPushD::ClientConnection::setDebugModeIsEnabled):
(WebPushD::ClientConnection::broadcastDebugMessage):
(WebPushD::ClientConnection::connectionClosed):

  • webpushd/WebPushDaemon.mm:

(WebPushD::Daemon::connectionAdded):

  • webpushd/webpushtool/WebPushToolConnection.h:
  • webpushd/webpushtool/WebPushToolConnection.mm:

(WebPushTool::Connection::create):
(WebPushTool::Connection::Connection):
(WebPushTool::Connection::connectToService):
(WebPushTool::Connection::connectionDropped):

  • webpushd/webpushtool/WebPushToolMain.mm:

(printUsageAndTerminate):
(main):

Tools:

  • TestWebKitAPI/Tests/WebKitCocoa/WebPushDaemon.mm:

(TestWebKitAPI::TEST): Adapt to debug message changes.

Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r286574 r286579  
     12021-12-06  Brady Eidson  <beidson@apple.com>
     2
     3        webpushd/webpushtool debugging additions
     4        https://bugs.webkit.org/show_bug.cgi?id=233864
     5
     6        Reviewed by Alex Christensen.
     7
     8        Covered by API tests.
     9       
     10        This patch:
     11        - Teaches webpushtool the ability to wait for a reconnect after losing its connection
     12        - Starts actually broadcasting meaningful debug messages from webpushd
     13
     14        * webpushd/AppBundleRequest.mm:
     15        (WebPushD::AppBundleRequest::start):
     16        (WebPushD::AppBundlePermissionsRequest::didCheckForExistingBundle):
     17        (WebPushD::AppBundlePermissionsRequest::didCreateAppBundle):
     18        (WebPushD::AppBundleDeletionRequest::didDeleteExistingBundleWithError):
     19
     20        * webpushd/PushClientConnection.h:
     21        * webpushd/PushClientConnection.mm:
     22        (WebPushD::ClientConnection::setDebugModeIsEnabled):
     23        (WebPushD::ClientConnection::broadcastDebugMessage):
     24        (WebPushD::ClientConnection::connectionClosed):
     25
     26        * webpushd/WebPushDaemon.mm:
     27        (WebPushD::Daemon::connectionAdded):
     28
     29        * webpushd/webpushtool/WebPushToolConnection.h:
     30        * webpushd/webpushtool/WebPushToolConnection.mm:
     31        (WebPushTool::Connection::create):
     32        (WebPushTool::Connection::Connection):
     33        (WebPushTool::Connection::connectToService):
     34        (WebPushTool::Connection::connectionDropped):
     35
     36        * webpushd/webpushtool/WebPushToolMain.mm:
     37        (printUsageAndTerminate):
     38        (main):
     39
    1402021-12-06  Chris Dumez  <cdumez@apple.com>
    241
  • trunk/Source/WebKit/webpushd/AppBundleRequest.mm

    r286355 r286579  
    4848    ASSERT(m_connection);
    4949
     50    m_connection->broadcastDebugMessage(makeString("Starting ", transactionDescription(), " request for origin ", m_originString));
     51
    5052    m_transaction = adoptOSObject(os_transaction_create(transactionDescription()));
    5153
     
    9294    ASSERT_UNUSED(bundle, &bundle == m_appBundle.get());
    9395
     96    m_connection->broadcastDebugMessage(makeString("Origin ", m_originString, " app bundle request: didCheckForExistingBundle - ", exists == PushAppBundleExists::Yes ? "Exists" : "Does not exist"));
     97
    9498    if (exists == PushAppBundleExists::Yes)
    9599        return callCompletionHandlerAndCleanup(true);
     
    101105{
    102106    ASSERT_UNUSED(bundle, &bundle == m_appBundle.get());
     107
     108    m_connection->broadcastDebugMessage(makeString("Origin ", m_originString, " app bundle request: didCreateAppBundle - ", result == PushAppBundleCreationResult::Success ? "Created" : "Failed to create"));
    103109
    104110    if (result == PushAppBundleCreationResult::Failure)
     
    119125    ASSERT_UNUSED(bundle, &bundle == m_appBundle.get());
    120126
     127    m_connection->broadcastDebugMessage(makeString("Origin ", m_originString, " app bundle request: didDeleteExistingBundleWithError"));
     128
    121129    if (error)
    122         Daemon::singleton().broadcastDebugMessage(MessageLevel::Info, makeString("Failed to delete app bundle: ", String([error description])));
     130        m_connection->broadcastDebugMessage(makeString("Failed to delete app bundle: ", String([error description])));
    123131
    124132    callCompletionHandlerAndCleanup(error ? String([error description]) : "");
  • trunk/Source/WebKit/webpushd/PushClientConnection.h

    r286355 r286579  
    6868    void connectionClosed();
    6969
     70    void broadcastDebugMessage(const String&);
     71
    7072private:
    7173    ClientConnection(xpc_connection_t);
  • trunk/Source/WebKit/webpushd/PushClientConnection.mm

    r286355 r286579  
    3232#import "WebPushDaemonConnectionConfiguration.h"
    3333#import <JavaScriptCore/ConsoleTypes.h>
     34#import <wtf/HexNumber.h>
    3435#import <wtf/Vector.h>
    3536#import <wtf/cocoa/Entitlements.h>
     
    104105
    105106    m_debugModeEnabled = enabled;
     107    broadcastDebugMessage(makeString("Turned Debug Mode ", m_debugModeEnabled ? "on" : "off"));
     108}
    106109
    107     auto identifier = hostAppCodeSigningIdentifier();
    108     String message;
    109     if (!identifier.isEmpty())
    110         message = makeString("[webpushd - ", identifier, "] Turned Debug Mode ", m_debugModeEnabled ? "on" : "off");
     110void ClientConnection::broadcastDebugMessage(const String& message)
     111{
     112    String messageIdentifier;
     113    auto signingIdentifer = hostAppCodeSigningIdentifier();
     114    if (signingIdentifer.isEmpty())
     115        messageIdentifier = makeString ("[(0x", hex(reinterpret_cast<uint64_t>(m_xpcConnection.get()), WTF::HexConversionMode::Lowercase), ")] ");
    111116    else
    112         message = makeString("[webpushd] Turned Debug Mode ", m_debugModeEnabled ? "on" : "off");
     117        messageIdentifier = makeString ("[", signingIdentifer, " (0x", hex(reinterpret_cast<uint64_t>(m_xpcConnection.get()), WTF::HexConversionMode::Lowercase), ")] ");
    113118
    114     Daemon::singleton().broadcastDebugMessage(MessageLevel::Info, message);
     119    Daemon::singleton().broadcastDebugMessage(JSC::MessageLevel::Info, makeString(messageIdentifier, message));
    115120}
    116121
     
    146151void ClientConnection::connectionClosed()
    147152{
     153    broadcastDebugMessage("Connection closed");
     154
    148155    RELEASE_ASSERT(m_xpcConnection);
    149156    m_xpcConnection = nullptr;
  • trunk/Source/WebKit/webpushd/WebPushDaemon.mm

    r286355 r286579  
    3535
    3636#import <wtf/CompletionHandler.h>
     37#import <wtf/HexNumber.h>
    3738#import <wtf/NeverDestroyed.h>
    3839#import <wtf/Span.h>
     
    181182void Daemon::connectionAdded(xpc_connection_t connection)
    182183{
     184    broadcastDebugMessage((JSC::MessageLevel)0, makeString("New connection: 0x", hex(reinterpret_cast<uint64_t>(connection), WTF::HexConversionMode::Lowercase)));
     185
    183186    RELEASE_ASSERT(!m_connectionMap.contains(connection));
    184187    m_connectionMap.set(connection, ClientConnection::create(connection));
  • trunk/Source/WebKit/webpushd/webpushtool/WebPushToolConnection.h

    r286533 r286579  
    3737};
    3838
     39enum class PreferTestService : bool {
     40    Yes,
     41    No,
     42};
     43
     44enum class Reconnect : bool {
     45    Yes,
     46    No,
     47};
     48
    3949class Connection : public CanMakeWeakPtr<Connection> {
    4050    WTF_MAKE_FAST_ALLOCATED;
    4151public:
    42     static std::unique_ptr<Connection> create(Action, bool preferTestService);
    43     Connection(Action, bool preferTestService);
     52    static std::unique_ptr<Connection> create(Action, PreferTestService, Reconnect);
     53    Connection(Action, PreferTestService, Reconnect);
    4454
    4555    void connectToService();
     
    5565   
    5666    Action m_action;
     67    bool m_reconnect { false };
    5768    RetainPtr<xpc_connection_t> m_connection;
    5869    const char* m_serviceName;
  • trunk/Source/WebKit/webpushd/webpushtool/WebPushToolConnection.mm

    r286533 r286579  
    3030#import <mach/task.h>
    3131#import <pal/spi/cocoa/ServersSPI.h>
     32#import <wtf/MainThread.h>
    3233#import <wtf/RetainPtr.h>
    3334
    3435namespace WebPushTool {
    3536
    36 std::unique_ptr<Connection> Connection::create(Action action, bool preferTestService)
     37std::unique_ptr<Connection> Connection::create(Action action, PreferTestService preferTestService, Reconnect reconnect)
    3738{
    38     return makeUnique<Connection>(action, preferTestService);
     39    return makeUnique<Connection>(action, preferTestService, reconnect);
    3940}
    4041
     
    5354}
    5455
    55 Connection::Connection(Action action, bool preferTestService)
     56Connection::Connection(Action action, PreferTestService preferTestService, Reconnect reconnect)
    5657    : m_action(action)
     58    , m_reconnect(reconnect == Reconnect::Yes)
    5759{
    58     if (preferTestService)
     60    if (preferTestService == PreferTestService::Yes)
    5961        m_serviceName = "org.webkit.webpushtestdaemon.service";
    6062    else
    6163        m_serviceName = "com.apple.webkit.webpushd.service";
     64}
     65
     66void Connection::connectToService()
     67{
     68    if (m_connection)
     69        return;
    6270
    6371    m_connection = adoptNS(xpc_connection_create_mach_service(m_serviceName, dispatch_get_main_queue(), 0));
     
    7583        if (event == XPC_ERROR_CONNECTION_INTERRUPTED) {
    7684            printf("Connection closed\n");
     85            if (m_reconnect)
     86                printf("===============\nReconnecting...\n");
    7787            connectionDropped();
    7888            return;
     
    8696        RELEASE_ASSERT_NOT_REACHED();
    8797    });
    88 }
    89 
    90 void Connection::connectToService()
    91 {
    92     if (!m_connection)
    93         return;
    9498
    9599    auto result = maybeConnectToService(m_serviceName);
     
    155159{
    156160    m_connection = nullptr;
     161    if (m_reconnect) {
     162        callOnMainRunLoop([this, weakThis = WeakPtr { this }] {
     163            if (weakThis)
     164                connectToService();
     165        });
     166        return;
     167    }
     168
    157169    CFRunLoopStop(CFRunLoopGetCurrent());
    158170}
  • trunk/Source/WebKit/webpushd/webpushtool/WebPushToolMain.mm

    r286533 r286579  
    2828#import <Foundation/Foundation.h>
    2929#import <optional>
     30#import <wtf/MainThread.h>
    3031
    3132__attribute__((__noreturn__))
     
    3940    fprintf(stderr, "  --production               Connects to mach service \"com.apple.webkit.webpushd.service\"\n");
    4041    fprintf(stderr, "  --streamDebugMessages      Stream debug messages from webpushd\n");
     42    fprintf(stderr, "  --reconnect                Reconnect after connection is lost\n");
    4143    fprintf(stderr, "\n");
    4244
     
    4648int main(int, const char **)
    4749{
    48     bool preferTestService = true;
     50    WTF::initializeMainThread();
     51
     52    auto preferTestService = WebPushTool::PreferTestService::Yes;
     53    auto reconnect = WebPushTool::Reconnect::No;
    4954    std::optional<WebPushTool::Action> action;
    5055
     
    5661        for (NSString *argument in [arguments subarrayWithRange:NSMakeRange(1, arguments.count - 1)]) {
    5762            if ([argument isEqualToString:@"--production"])
    58                 preferTestService = false;
    59             if ([argument isEqualToString:@"--development"])
    60                 preferTestService = true;
     63                preferTestService = WebPushTool::PreferTestService::No;
     64            else if ([argument isEqualToString:@"--development"])
     65                preferTestService = WebPushTool::PreferTestService::Yes;
    6166            else if ([argument isEqualToString:@"--streamDebugMessages"])
    6267                action = WebPushTool::Action::StreamDebugMessages;
     68            else if ([argument isEqualToString:@"--reconnect"])
     69                reconnect = WebPushTool::Reconnect::Yes;
    6370            else
    6471                printUsageAndTerminate([NSString stringWithFormat:@"Invalid option provided: %@", argument]);
     
    6976        printUsageAndTerminate(@"No action provided");
    7077
    71     auto connection = WebPushTool::Connection::create(*action, preferTestService);
     78    auto connection = WebPushTool::Connection::create(*action, preferTestService, reconnect);
    7279    connection->connectToService();
    7380
  • trunk/Tools/ChangeLog

    r286576 r286579  
     12021-12-06  Brady Eidson  <beidson@apple.com>
     2
     3        webpushd/webpushtool debugging additions
     4        https://bugs.webkit.org/show_bug.cgi?id=233864
     5
     6        Reviewed by Alex Christensen.
     7
     8        * TestWebKitAPI/Tests/WebKitCocoa/WebPushDaemon.mm:
     9        (TestWebKitAPI::TEST): Adapt to debug message changes.
     10
    1112021-12-04  Jonathan Bedard  <jbedard@apple.com>
    212
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebPushDaemon.mm

    r286476 r286579  
    182182            return;
    183183
    184         bool stringMatches = !strcmp(debugMessage, "[webpushd - TestWebKitAPI] Turned Debug Mode on");
    185         if (!stringMatches)
    186             stringMatches = !strcmp(debugMessage, "[webpushd - com.apple.WebKit.TestWebKitAPI] Turned Debug Mode on");
     184        NSString *nsMessage = [NSString stringWithUTF8String:debugMessage];
     185
     186        // Ignore possible connections/messages from webpushtool
     187        if ([nsMessage hasPrefix:@"[webpushtool "])
     188            return;
     189
     190        bool stringMatches = [nsMessage hasPrefix:@"[com.apple.WebKit.TestWebKitAPI"] || [nsMessage hasPrefix:@"[TestWebKitAPI"];
     191        stringMatches = stringMatches && [nsMessage hasSuffix:@" Turned Debug Mode on"];
    187192
    188193        EXPECT_TRUE(stringMatches);
Note: See TracChangeset for help on using the changeset viewer.