Change how WebKitNightlyEnabler.dylib lies about Safari's identity to LaunchServices.
authormrowe@apple.com <mrowe@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 1 Jul 2009 21:41:04 +0000 (21:41 +0000)
committermrowe@apple.com <mrowe@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 1 Jul 2009 21:41:04 +0000 (21:41 +0000)
This makes WebKit.app behave as expected when set as the default web browser on a wider
range of OS versions.

Reviewed by Simon Fraser.

* WebKitLauncher/WebKitNightlyEnabler.m:
(poseAsWebKitApp):
(enableWebKitNightlyBehaviour):

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

WebKitTools/ChangeLog
WebKitTools/WebKitLauncher/WebKitNightlyEnabler.m

index e06ecd0..901cccf 100644 (file)
@@ -2,6 +2,18 @@
 
         Reviewed by Simon Fraser.
 
+        Change how WebKitNightlyEnabler.dylib lies about Safari's identity to LaunchServices.
+        This makes WebKit.app behave as expected when set as the default web browser on a wider
+        range of OS versions.
+
+        * WebKitLauncher/WebKitNightlyEnabler.m:
+        (poseAsWebKitApp):
+        (enableWebKitNightlyBehaviour):
+
+2009-07-01  Mark Rowe  <mrowe@apple.com>
+
+        Reviewed by Simon Fraser.
+
         Shuffle some code around in preparation for a change to how poseAsWebKitApp works.
 
         * WebKitLauncher/WebKitNightlyEnabler.m:
index 6501d2e..eef0f8c 100644 (file)
@@ -117,25 +117,42 @@ NSBundle *webKitLauncherBundle()
 }
 
 extern char **_CFGetProcessPath() __attribute__((weak));
+extern OSStatus _RegisterApplication(CFDictionaryRef additionalAppInfoRef, ProcessSerialNumber* myPSN) __attribute__((weak));
 
 static void poseAsWebKitApp()
 {
     webKitAppPath = strdup(getenv("WebKitAppPath"));
-    if (!webKitAppPath || !_CFGetProcessPath)
+    if (!webKitAppPath)
         return;
 
+    unsetenv("WebKitAppPath");
+
     // Set up the main bundle early so it points at Safari.app
     CFBundleGetMainBundle();
 
-    // Fiddle with CoreFoundation to have it pick up the executable path as being within WebKit.app
-    char **processPath = _CFGetProcessPath();
-    *processPath = NULL;
-    setenv("CFProcessPath", webKitAppPath, 1);
-    _CFGetProcessPath();
-
-    // Clean up
-    unsetenv("CFProcessPath");
-    unsetenv("WebKitAppPath");
+    if (systemVersion() < 0x1060) {
+        if (!_CFGetProcessPath)
+            return;
+
+        // Fiddle with CoreFoundation to have it pick up the executable path as being within WebKit.app
+        char **processPath = _CFGetProcessPath();
+        *processPath = NULL;
+        setenv("CFProcessPath", webKitAppPath, 1);
+        _CFGetProcessPath();
+        unsetenv("CFProcessPath");
+    } else {
+        if (!_RegisterApplication)
+            return;
+
+        // Register the application with LaunchServices, passing a customized registration dictionary that
+        // uses the WebKit launcher as the application bundle.
+        NSBundle *bundle = webKitLauncherBundle();
+        NSMutableDictionary *checkInDictionary = [[bundle infoDictionary] mutableCopy];
+        [checkInDictionary setObject:[bundle bundlePath] forKey:@"LSBundlePath"];
+        [checkInDictionary setObject:[checkInDictionary objectForKey:(NSString *)kCFBundleNameKey] forKey:@"LSDisplayName"];
+        _RegisterApplication((CFDictionaryRef)checkInDictionary, 0);
+        [checkInDictionary release];
+    }
 }
 
 static BOOL insideSafari4OnTigerTrampoline()
@@ -167,10 +184,11 @@ static void enableWebKitNightlyBehaviour()
     if (insideSafari4OnTigerTrampoline())
         return;
 
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
     unsetenv("DYLD_INSERT_LIBRARIES");
     poseAsWebKitApp();
 
-    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
     extensionPaths = [[NSSet alloc] initWithObjects:@"~/Library/InputManagers/", @"/Library/InputManagers/",
                                                     @"~/Library/Application Support/SIMBL/Plugins/", @"/Library/Application Support/SIMBL/Plugins/",
                                                     @"~/Library/Application Enhancers/", @"/Library/Application Enhancers/",