WebKit2: Set the visible name for the web process
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 10 Sep 2010 22:52:29 +0000 (22:52 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 10 Sep 2010 22:52:29 +0000 (22:52 +0000)
https://bugs.webkit.org/show_bug.cgi?id=45564
<rdar://problem/8416970>

Reviewed by Mark Rowe and Darin Adler.

* UIProcess/Launcher/mac/ProcessLauncherMac.mm:
(WebKit::processName):
Add a thread safe implementation of -[NSProcessInfo processName].

(WebKit::ProcessLauncher::launchProcess):
Pass the process name to the child process.

* WebProcess/mac/WebProcessMainMac.mm:
(WebKit::WebProcessMain):
Set the visible name.

WebKitLibraries: WebKitSystemInterface part of:
Set the visible name for the web process
https://bugs.webkit.org/show_bug.cgi?id=45564
<rdar://problem/8416970>

* WebKitSystemInterface.h:
* libWebKitSystemInterfaceLeopard.a:
* libWebKitSystemInterfaceSnowLeopard.a:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@67247 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebKit2/ChangeLog
WebKit2/UIProcess/Launcher/mac/ProcessLauncherMac.mm
WebKit2/WebProcess/mac/WebProcessMainMac.mm
WebKitLibraries/ChangeLog
WebKitLibraries/WebKitSystemInterface.h
WebKitLibraries/libWebKitSystemInterfaceLeopard.a
WebKitLibraries/libWebKitSystemInterfaceSnowLeopard.a

index cfcae42..ebfdc5d 100644 (file)
@@ -1,3 +1,22 @@
+2010-09-10  Anders Carlsson  <andersca@apple.com>
+
+        Reviewed by Mark Rowe and Darin Adler.
+
+        Set the visible name for the web process
+        https://bugs.webkit.org/show_bug.cgi?id=45564
+        <rdar://problem/8416970>
+
+        * UIProcess/Launcher/mac/ProcessLauncherMac.mm:
+        (WebKit::processName):
+        Add a thread safe implementation of -[NSProcessInfo processName].
+
+        (WebKit::ProcessLauncher::launchProcess):
+        Pass the process name to the child process.
+
+        * WebProcess/mac/WebProcessMainMac.mm:
+        (WebKit::WebProcessMain):
+        Set the visible name.
+
 2010-09-10  Adam Barth  <abarth@webkit.org>
 
         Reviewed by Eric Seidel.
index b0c9afb..b0f61c4 100644 (file)
 #include "WebProcess.h"
 #include "WebSystemInterface.h"
 #include <crt_externs.h>
+#include <mach-o/dyld.h>
 #include <mach/machine.h>
 #include <runtime/InitializeThreading.h>
 #include <servers/bootstrap.h>
 #include <spawn.h>
+#include <sys/param.h>
 #include <wtf/PassRefPtr.h>
 #include <wtf/Threading.h>
 #include <wtf/text/CString.h>
@@ -45,6 +47,32 @@ extern "C" kern_return_t bootstrap_register2(mach_port_t, name_t, mach_port_t, u
 
 namespace WebKit {
 
+#if !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)
+static const char* processName()
+{
+    return [[[NSProcessInfo processInfo] processName] fileSystemRepresentation];
+}
+#else
+// -[NSProcessInfo processName] isn't thread-safe on Leopard and Snow Leopard so we have our own implementation.
+static const char* createProcessName()
+{
+    uint32_t bufferSize = MAXPATHLEN;
+    char executablePath[bufferSize];
+    
+    if (_NSGetExecutablePath(executablePath, &bufferSize))
+        return "";
+    
+    const char *processName = strrchr(executablePath, '/') + 1;
+    return strdup(processName);
+}
+
+static const char* processName()
+{
+    static const char* processName = createProcessName();
+    return processName;
+}
+#endif
+
 void ProcessLauncher::launchProcess()
 {
     // Create the listening port.
@@ -61,7 +89,7 @@ void ProcessLauncher::launchProcess()
     CString serviceName = String::format("com.apple.WebKit.WebProcess-%d-%p", getpid(), this).utf8();
 
     const char* path = [webProcessAppExecutablePath fileSystemRepresentation];
-    const char* args[] = { path, "-mode", "legacywebprocess", "-servicename", serviceName.data(), 0 };
+    const char* args[] = { path, "-mode", "legacywebprocess", "-servicename", serviceName.data(), "-parentprocessname", processName(), 0 };
 
     // Register ourselves.
     kern_return_t kr = bootstrap_register2(bootstrap_port, const_cast<char*>(serviceName.data()), listeningPort, 0);
index dece49a..4b49921 100644 (file)
@@ -30,6 +30,7 @@
 #import "WebProcess.h"
 #import "WebSystemInterface.h"
 #import <WebKit2/WKView.h>
+#import <WebKitSystemInterface.h>
 #import <objc/objc-auto.h>
 #import <runtime/InitializeThreading.h>
 #import <servers/bootstrap.h>
@@ -37,6 +38,7 @@
 #import <stdio.h>
 #import <sysexits.h>
 #import <unistd.h>
+#import <wtf/RetainPtr.h>
 #import <wtf/Threading.h>
 #import <wtf/text/CString.h>
 
@@ -80,7 +82,6 @@ int WebProcessMain(CommandLine* commandLine)
         printf("bootstrap_look_up2 result: %x", kr);
         return 2;
     }
-    
 
 #if !SHOW_CRASH_REPORTER
     // Installs signal handlers that exit on a crash so that CrashReporter does not show up.
@@ -95,6 +96,14 @@ int WebProcessMain(CommandLine* commandLine)
     WTF::initializeMainThread();
     RunLoop::initializeMainRunLoop();
 
+    // Set the visible application name.
+    String parentProcessName = (*commandLine)["parentprocessname"];
+    if (!parentProcessName.isNull()) {
+        // FIXME: Localization!
+        NSString *applicationName = [NSString stringWithFormat:@"%@ Web Content", (NSString *)parentProcessName];
+        WKSetVisibleApplicationName((CFStringRef)applicationName);
+    }
+    
     // Create the connection.
     WebProcess::shared().initialize(serverPort, RunLoop::main());
     
index 3d603d9..e1e53e6 100644 (file)
@@ -1,3 +1,14 @@
+2010-09-10  Anders Carlsson  <andersca@apple.com>
+
+        WebKitSystemInterface part of:
+        Set the visible name for the web process
+        https://bugs.webkit.org/show_bug.cgi?id=45564
+        <rdar://problem/8416970>
+
+        * WebKitSystemInterface.h:
+        * libWebKitSystemInterfaceLeopard.a:
+        * libWebKitSystemInterfaceSnowLeopard.a:
+
 2010-08-05  Jian Li  <jianli@chromium.org>
 
         Reviewed by David Levin.
index 5f6dcdb..48e2954 100644 (file)
@@ -205,6 +205,8 @@ void WKQTMovieDisableComponent(uint32_t[5]);
 
 CFStringRef WKCopyFoundationCacheDirectory(void);
 
+void WKSetVisibleApplicationName(CFStringRef);
+
 typedef enum {
     WKMediaUIPartFullscreenButton   = 0,
     WKMediaUIPartMuteButton,
index 39ceb4a..b5de039 100644 (file)
Binary files a/WebKitLibraries/libWebKitSystemInterfaceLeopard.a and b/WebKitLibraries/libWebKitSystemInterfaceLeopard.a differ
index 6dd8afc..1e6ec8c 100644 (file)
Binary files a/WebKitLibraries/libWebKitSystemInterfaceSnowLeopard.a and b/WebKitLibraries/libWebKitSystemInterfaceSnowLeopard.a differ