Modified: trunk/Source/WebKit/ChangeLog (272208 => 272209)
--- trunk/Source/WebKit/ChangeLog 2021-02-02 16:11:38 UTC (rev 272208)
+++ trunk/Source/WebKit/ChangeLog 2021-02-02 16:31:11 UTC (rev 272209)
@@ -1,3 +1,41 @@
+2021-02-02 Chris Dumez <[email protected]>
+
+ [macOS] Regression(r271897) Prewarmed WebProcesses no longer get a user-friendly process name in Activity Monitor
+ https://bugs.webkit.org/show_bug.cgi?id=221094
+ <rdar://73658122>
+
+ Reviewed by Per Arne Vollan.
+
+ Prewarmed WebProcesses currently do not have a network process connection because they do not have a sessionID yet
+ and initiating a connection to the network process currently requires a sessionID. r271897 made it so that
+ WebProcess::updateProcessName() early returns when there is no network process connection, which means that our
+ prewarmed WebProcesses no longer get the "Safari Web Content (prewarmed)" user-friendly name in activity monitor.
+
+ This patch relies on the fact that we are allowed to talk to launchservices when WebProcess::updateProcessName()
+ gets called during process initialization (The sandbox extension gets revoked during process initialization right
+ after calling updateProcessName). As a result, if updateProcessName() gets called during process initialization,
+ we now set the process name directly within the process instead of messaging the network process. This fixes the
+ issue with prewarmed WebProcesses.
+
+ This patch also gets rid of the early returns when the network connection is not present and calls
+ ensureNetworkProcessConnection() instead. We want to make sure to set the process name even if the process does
+ not have a network process connection yet (either because none has been initiated yet or because the network
+ process crashed).
+
+ Finally, this patch replaces some WTFLogAlways() for error cases with RELEASE_LOG_ERROR() so that the errors
+ stand out in the logs.
+
+ * UIProcess/WebProcessPool.cpp:
+ (WebKit::WebProcessPool::tryTakePrewarmedProcess):
+ * WebProcess/WebProcess.cpp:
+ (WebKit::WebProcess::setIsInProcessCache):
+ (WebKit::WebProcess::markIsNoLongerPrewarmed):
+ * WebProcess/WebProcess.h:
+ * WebProcess/cocoa/WebProcessCocoa.mm:
+ (WebKit::WebProcess::platformInitializeWebProcess):
+ (WebKit::WebProcess::updateProcessName):
+ (WebKit::WebProcess::updateActivePages):
+
2021-02-02 Frédéric Wang <[email protected]>
[GTK] Initialize PrintInfo::PrintMode
Modified: trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm (272208 => 272209)
--- trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm 2021-02-02 16:11:38 UTC (rev 272208)
+++ trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm 2021-02-02 16:31:11 UTC (rev 272209)
@@ -325,7 +325,7 @@
[NSApplication _accessibilityInitialize];
// Update process name while holding the Launch Services sandbox extension
- updateProcessName();
+ updateProcessName(IsInProcessInitialization::Yes);
#if ENABLE(SET_WEBCONTENT_PROCESS_INFORMATION_IN_NETWORK_PROCESS)
auto method = class_getInstanceMethod([NSApplication class], @selector(_updateCanQuitQuietlyAndSafely));
@@ -444,7 +444,7 @@
#endif
}
-void WebProcess::updateProcessName()
+void WebProcess::updateProcessName(IsInProcessInitialization isInProcessInitialization)
{
#if PLATFORM(MAC)
RetainPtr<NSString> applicationName;
@@ -467,35 +467,37 @@
}
#if ENABLE(SET_WEBCONTENT_PROCESS_INFORMATION_IN_NETWORK_PROCESS)
- if (!m_networkProcessConnection) {
- WTFLogAlways("Unable to update process name since there is no Network process connection.");
+ // During WebProcess initialization, we are still able to talk to LaunchServices to set the process name so there is no need to go
+ // via the NetworkProcess. Prewarmed WebProcesses also do not have a network process connection until they are actually used by
+ // a page.
+ if (isInProcessInitialization == IsInProcessInitialization::No) {
+ audit_token_t auditToken = { 0 };
+ mach_msg_type_number_t info_size = TASK_AUDIT_TOKEN_COUNT;
+ kern_return_t kr = task_info(mach_task_self(), TASK_AUDIT_TOKEN, reinterpret_cast<integer_t *>(&auditToken), &info_size);
+ if (kr != KERN_SUCCESS) {
+ RELEASE_LOG_ERROR_IF_ALLOWED(Process, "updateProcessName: Unable to get audit token for self. Error: %{public}s (%x)", mach_error_string(kr), kr);
+ return;
+ }
+ String displayName = applicationName.get();
+ ensureNetworkProcessConnection().connection().send(Messages::NetworkConnectionToWebProcess::UpdateActivePages(displayName, Vector<String>(), auditToken), 0);
return;
}
- audit_token_t auditToken = { 0 };
- mach_msg_type_number_t info_size = TASK_AUDIT_TOKEN_COUNT;
- kern_return_t err = task_info(mach_task_self(), TASK_AUDIT_TOKEN, reinterpret_cast<integer_t *>(&auditToken), &info_size);
- if (err != KERN_SUCCESS) {
- WTFLogAlways("Unable to get audit token for self: 0x%x", err);
+#endif // ENABLE(SET_WEBCONTENT_PROCESS_INFORMATION_IN_NETWORK_PROCESS)
+
+ // Note that it is important for _RegisterApplication() to have been called before setting the display name.
+ auto error = _LSSetApplicationInformationItem(kLSDefaultSessionID, _LSGetCurrentApplicationASN(), _kLSDisplayNameKey, (CFStringRef)applicationName.get(), nullptr);
+ ASSERT(!error);
+ if (error) {
+ RELEASE_LOG_ERROR_IF_ALLOWED(Process, "updateProcessName: Failed to set the display name of the WebContent process, error code: %ld", static_cast<long>(error));
return;
}
- String displayName = applicationName.get();
- m_networkProcessConnection->connection().send(Messages::NetworkConnectionToWebProcess::UpdateActivePages(displayName, Vector<String>(), auditToken), 0);
-#else
- RunLoop::main().dispatch([this, applicationName = WTFMove(applicationName)] {
- // Note that it is important for _RegisterApplication() to have been called before setting the display name.
- auto error = _LSSetApplicationInformationItem(kLSDefaultSessionID, _LSGetCurrentApplicationASN(), _kLSDisplayNameKey, (CFStringRef)applicationName.get(), nullptr);
- ASSERT(!error);
- if (error) {
- RELEASE_LOG_ERROR_IF_ALLOWED(Process, "updateProcessName: Failed to set the display name of the WebContent process, error code: %ld", static_cast<long>(error));
- return;
- }
#if ASSERT_ENABLED
- // It is possible for _LSSetApplicationInformationItem() to return 0 and yet fail to set the display name so we make sure the display name has actually been set.
- String actualApplicationName = adoptCF((CFStringRef)_LSCopyApplicationInformationItem(kLSDefaultSessionID, _LSGetCurrentApplicationASN(), _kLSDisplayNameKey)).get();
- ASSERT(!actualApplicationName.isEmpty());
+ // It is possible for _LSSetApplicationInformationItem() to return 0 and yet fail to set the display name so we make sure the display name has actually been set.
+ String actualApplicationName = adoptCF((CFStringRef)_LSCopyApplicationInformationItem(kLSDefaultSessionID, _LSGetCurrentApplicationASN(), _kLSDisplayNameKey)).get();
+ ASSERT(!actualApplicationName.isEmpty());
#endif
- });
-#endif // ENABLE(SET_WEBCONTENT_PROCESS_INFORMATION_IN_NETWORK_PROCESS)
+#else
+ UNUSED_PARAM(isInProcessInitialization);
#endif // PLATFORM(MAC)
}
@@ -756,19 +758,15 @@
{
#if PLATFORM(MAC)
#if ENABLE(SET_WEBCONTENT_PROCESS_INFORMATION_IN_NETWORK_PROCESS)
- if (!m_networkProcessConnection) {
- WTFLogAlways("Unable to update active pages since there is no Network process connection.");
- return;
- }
audit_token_t auditToken = { 0 };
mach_msg_type_number_t info_size = TASK_AUDIT_TOKEN_COUNT;
- kern_return_t err = task_info(mach_task_self(), TASK_AUDIT_TOKEN, reinterpret_cast<integer_t *>(&auditToken), &info_size);
- if (err != KERN_SUCCESS) {
- WTFLogAlways("Unable to get audit token for self: 0x%x", err);
+ kern_return_t kr = task_info(mach_task_self(), TASK_AUDIT_TOKEN, reinterpret_cast<integer_t *>(&auditToken), &info_size);
+ if (kr != KERN_SUCCESS) {
+ RELEASE_LOG_ERROR_IF_ALLOWED(Process, "updateActivePages: Unable to get audit token for self. Error: %{public}s (%x)", mach_error_string(kr), kr);
return;
}
- m_networkProcessConnection->connection().send(Messages::NetworkConnectionToWebProcess::UpdateActivePages(overrideDisplayName, activePagesOrigins(m_pageMap), auditToken), 0);
+ ensureNetworkProcessConnection().connection().send(Messages::NetworkConnectionToWebProcess::UpdateActivePages(overrideDisplayName, activePagesOrigins(m_pageMap), auditToken), 0);
#else
if (!overrideDisplayName) {
RunLoop::main().dispatch([activeOrigins = activePagesOrigins(m_pageMap)] {