Changeset 286579 in webkit
- Timestamp:
- Dec 6, 2021, 4:38:11 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 10 edited
-
Source/WebKit/ChangeLog (modified) (1 diff)
-
Source/WebKit/webpushd/AppBundleRequest.mm (modified) (4 diffs)
-
Source/WebKit/webpushd/PushClientConnection.h (modified) (1 diff)
-
Source/WebKit/webpushd/PushClientConnection.mm (modified) (3 diffs)
-
Source/WebKit/webpushd/WebPushDaemon.mm (modified) (2 diffs)
-
Source/WebKit/webpushd/webpushtool/WebPushToolConnection.h (modified) (2 diffs)
-
Source/WebKit/webpushd/webpushtool/WebPushToolConnection.mm (modified) (5 diffs)
-
Source/WebKit/webpushd/webpushtool/WebPushToolMain.mm (modified) (5 diffs)
-
Tools/ChangeLog (modified) (1 diff)
-
Tools/TestWebKitAPI/Tests/WebKitCocoa/WebPushDaemon.mm (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r286574 r286579 1 2021-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 1 40 2021-12-06 Chris Dumez <cdumez@apple.com> 2 41 -
trunk/Source/WebKit/webpushd/AppBundleRequest.mm
r286355 r286579 48 48 ASSERT(m_connection); 49 49 50 m_connection->broadcastDebugMessage(makeString("Starting ", transactionDescription(), " request for origin ", m_originString)); 51 50 52 m_transaction = adoptOSObject(os_transaction_create(transactionDescription())); 51 53 … … 92 94 ASSERT_UNUSED(bundle, &bundle == m_appBundle.get()); 93 95 96 m_connection->broadcastDebugMessage(makeString("Origin ", m_originString, " app bundle request: didCheckForExistingBundle - ", exists == PushAppBundleExists::Yes ? "Exists" : "Does not exist")); 97 94 98 if (exists == PushAppBundleExists::Yes) 95 99 return callCompletionHandlerAndCleanup(true); … … 101 105 { 102 106 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")); 103 109 104 110 if (result == PushAppBundleCreationResult::Failure) … … 119 125 ASSERT_UNUSED(bundle, &bundle == m_appBundle.get()); 120 126 127 m_connection->broadcastDebugMessage(makeString("Origin ", m_originString, " app bundle request: didDeleteExistingBundleWithError")); 128 121 129 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]))); 123 131 124 132 callCompletionHandlerAndCleanup(error ? String([error description]) : ""); -
trunk/Source/WebKit/webpushd/PushClientConnection.h
r286355 r286579 68 68 void connectionClosed(); 69 69 70 void broadcastDebugMessage(const String&); 71 70 72 private: 71 73 ClientConnection(xpc_connection_t); -
trunk/Source/WebKit/webpushd/PushClientConnection.mm
r286355 r286579 32 32 #import "WebPushDaemonConnectionConfiguration.h" 33 33 #import <JavaScriptCore/ConsoleTypes.h> 34 #import <wtf/HexNumber.h> 34 35 #import <wtf/Vector.h> 35 36 #import <wtf/cocoa/Entitlements.h> … … 104 105 105 106 m_debugModeEnabled = enabled; 107 broadcastDebugMessage(makeString("Turned Debug Mode ", m_debugModeEnabled ? "on" : "off")); 108 } 106 109 107 auto identifier = hostAppCodeSigningIdentifier(); 108 String message; 109 if (!identifier.isEmpty()) 110 message = makeString("[webpushd - ", identifier, "] Turned Debug Mode ", m_debugModeEnabled ? "on" : "off"); 110 void 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), ")] "); 111 116 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), ")] "); 113 118 114 Daemon::singleton().broadcastDebugMessage( MessageLevel::Info, message);119 Daemon::singleton().broadcastDebugMessage(JSC::MessageLevel::Info, makeString(messageIdentifier, message)); 115 120 } 116 121 … … 146 151 void ClientConnection::connectionClosed() 147 152 { 153 broadcastDebugMessage("Connection closed"); 154 148 155 RELEASE_ASSERT(m_xpcConnection); 149 156 m_xpcConnection = nullptr; -
trunk/Source/WebKit/webpushd/WebPushDaemon.mm
r286355 r286579 35 35 36 36 #import <wtf/CompletionHandler.h> 37 #import <wtf/HexNumber.h> 37 38 #import <wtf/NeverDestroyed.h> 38 39 #import <wtf/Span.h> … … 181 182 void Daemon::connectionAdded(xpc_connection_t connection) 182 183 { 184 broadcastDebugMessage((JSC::MessageLevel)0, makeString("New connection: 0x", hex(reinterpret_cast<uint64_t>(connection), WTF::HexConversionMode::Lowercase))); 185 183 186 RELEASE_ASSERT(!m_connectionMap.contains(connection)); 184 187 m_connectionMap.set(connection, ClientConnection::create(connection)); -
trunk/Source/WebKit/webpushd/webpushtool/WebPushToolConnection.h
r286533 r286579 37 37 }; 38 38 39 enum class PreferTestService : bool { 40 Yes, 41 No, 42 }; 43 44 enum class Reconnect : bool { 45 Yes, 46 No, 47 }; 48 39 49 class Connection : public CanMakeWeakPtr<Connection> { 40 50 WTF_MAKE_FAST_ALLOCATED; 41 51 public: 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); 44 54 45 55 void connectToService(); … … 55 65 56 66 Action m_action; 67 bool m_reconnect { false }; 57 68 RetainPtr<xpc_connection_t> m_connection; 58 69 const char* m_serviceName; -
trunk/Source/WebKit/webpushd/webpushtool/WebPushToolConnection.mm
r286533 r286579 30 30 #import <mach/task.h> 31 31 #import <pal/spi/cocoa/ServersSPI.h> 32 #import <wtf/MainThread.h> 32 33 #import <wtf/RetainPtr.h> 33 34 34 35 namespace WebPushTool { 35 36 36 std::unique_ptr<Connection> Connection::create(Action action, bool preferTestService)37 std::unique_ptr<Connection> Connection::create(Action action, PreferTestService preferTestService, Reconnect reconnect) 37 38 { 38 return makeUnique<Connection>(action, preferTestService );39 return makeUnique<Connection>(action, preferTestService, reconnect); 39 40 } 40 41 … … 53 54 } 54 55 55 Connection::Connection(Action action, bool preferTestService)56 Connection::Connection(Action action, PreferTestService preferTestService, Reconnect reconnect) 56 57 : m_action(action) 58 , m_reconnect(reconnect == Reconnect::Yes) 57 59 { 58 if (preferTestService )60 if (preferTestService == PreferTestService::Yes) 59 61 m_serviceName = "org.webkit.webpushtestdaemon.service"; 60 62 else 61 63 m_serviceName = "com.apple.webkit.webpushd.service"; 64 } 65 66 void Connection::connectToService() 67 { 68 if (m_connection) 69 return; 62 70 63 71 m_connection = adoptNS(xpc_connection_create_mach_service(m_serviceName, dispatch_get_main_queue(), 0)); … … 75 83 if (event == XPC_ERROR_CONNECTION_INTERRUPTED) { 76 84 printf("Connection closed\n"); 85 if (m_reconnect) 86 printf("===============\nReconnecting...\n"); 77 87 connectionDropped(); 78 88 return; … … 86 96 RELEASE_ASSERT_NOT_REACHED(); 87 97 }); 88 }89 90 void Connection::connectToService()91 {92 if (!m_connection)93 return;94 98 95 99 auto result = maybeConnectToService(m_serviceName); … … 155 159 { 156 160 m_connection = nullptr; 161 if (m_reconnect) { 162 callOnMainRunLoop([this, weakThis = WeakPtr { this }] { 163 if (weakThis) 164 connectToService(); 165 }); 166 return; 167 } 168 157 169 CFRunLoopStop(CFRunLoopGetCurrent()); 158 170 } -
trunk/Source/WebKit/webpushd/webpushtool/WebPushToolMain.mm
r286533 r286579 28 28 #import <Foundation/Foundation.h> 29 29 #import <optional> 30 #import <wtf/MainThread.h> 30 31 31 32 __attribute__((__noreturn__)) … … 39 40 fprintf(stderr, " --production Connects to mach service \"com.apple.webkit.webpushd.service\"\n"); 40 41 fprintf(stderr, " --streamDebugMessages Stream debug messages from webpushd\n"); 42 fprintf(stderr, " --reconnect Reconnect after connection is lost\n"); 41 43 fprintf(stderr, "\n"); 42 44 … … 46 48 int main(int, const char **) 47 49 { 48 bool preferTestService = true; 50 WTF::initializeMainThread(); 51 52 auto preferTestService = WebPushTool::PreferTestService::Yes; 53 auto reconnect = WebPushTool::Reconnect::No; 49 54 std::optional<WebPushTool::Action> action; 50 55 … … 56 61 for (NSString *argument in [arguments subarrayWithRange:NSMakeRange(1, arguments.count - 1)]) { 57 62 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; 61 66 else if ([argument isEqualToString:@"--streamDebugMessages"]) 62 67 action = WebPushTool::Action::StreamDebugMessages; 68 else if ([argument isEqualToString:@"--reconnect"]) 69 reconnect = WebPushTool::Reconnect::Yes; 63 70 else 64 71 printUsageAndTerminate([NSString stringWithFormat:@"Invalid option provided: %@", argument]); … … 69 76 printUsageAndTerminate(@"No action provided"); 70 77 71 auto connection = WebPushTool::Connection::create(*action, preferTestService );78 auto connection = WebPushTool::Connection::create(*action, preferTestService, reconnect); 72 79 connection->connectToService(); 73 80 -
trunk/Tools/ChangeLog
r286576 r286579 1 2021-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 1 11 2021-12-04 Jonathan Bedard <jbedard@apple.com> 2 12 -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebPushDaemon.mm
r286476 r286579 182 182 return; 183 183 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"]; 187 192 188 193 EXPECT_TRUE(stringMatches);
Note:
See TracChangeset
for help on using the changeset viewer.