WebKitTools:
authorddkilzer <ddkilzer@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 2 Jul 2006 12:02:38 +0000 (12:02 +0000)
committerddkilzer <ddkilzer@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 2 Jul 2006 12:02:38 +0000 (12:02 +0000)
        Reviewed by Timothy Hatcher.  Patch by Mark Rowe.

        Bug 9689: Nightly builds should warn a user about potential problems when using
        "Safari extensions"
        http://bugzilla.opendarwin.org/show_bug.cgi?id=9689

        * WebKitLauncher/WebKitLauncher.xcodeproj/project.pbxproj:
        * WebKitLauncher/WebKitNightlyEnabler.m:
        (myBundleDidLoad): Keep track of if any bundles that are loaded.
        (myApplicationWillFinishLaunching):  Notify user if any bundles are loaded.
        (cleanUpAfterOurselves): Register for NSBundleDidLoadNotification and
        NSApplicationWillFinishLaunchingNotification notifications so that we can
        track bundle loads and notify the user at launch completion.

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

WebKitTools/ChangeLog
WebKitTools/WebKitLauncher/WebKitLauncher.xcodeproj/project.pbxproj
WebKitTools/WebKitLauncher/WebKitNightlyEnabler.m

index 39bde8f..ea6daf1 100644 (file)
@@ -1,3 +1,19 @@
+2006-07-02  Mark Rowe  <opendarwin.org@bdash.net.nz>
+
+        Reviewed by Timothy Hatcher.
+
+        Bug 9689: Nightly builds should warn a user about potential problems when using
+        "Safari extensions"
+        http://bugzilla.opendarwin.org/show_bug.cgi?id=9689
+
+        * WebKitLauncher/WebKitLauncher.xcodeproj/project.pbxproj:
+        * WebKitLauncher/WebKitNightlyEnabler.m:
+        (myBundleDidLoad): Keep track of if any bundles that are loaded.
+        (myApplicationWillFinishLaunching):  Notify user if any bundles are loaded.
+        (cleanUpAfterOurselves): Register for NSBundleDidLoadNotification and
+        NSApplicationWillFinishLaunchingNotification notifications so that we can
+        track bundle loads and notify the user at launch completion.
+
 2006-06-30  Mike Emmel  <mike.emmel@gmail.com>
 
         Reviewed by Darin.
index f765dfa..0efda66 100644 (file)
@@ -11,7 +11,7 @@
                5D4DF982097F89FB0083D5E5 /* start.html in Resources */ = {isa = PBXBuildFile; fileRef = 5D4DF981097F89FB0083D5E5 /* start.html */; };
                5D650F3609DB8B370075E9A8 /* WebKitNightlyEnabler.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D650F3509DB8B370075E9A8 /* WebKitNightlyEnabler.m */; };
                5D650F3A09DB8B410075E9A8 /* WebKitNightlyEnabler.dylib in Resources */ = {isa = PBXBuildFile; fileRef = 5D650F3409DB8B280075E9A8 /* WebKitNightlyEnabler.dylib */; };
-               5D650F7609DB8CB40075E9A8 /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5D650F7509DB8CB40075E9A8 /* CoreFoundation.framework */; };
+               5D877FCD0A5795F200D0C67B /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; };
                5DB70525097B94CD009875EC /* webkit.icns in Resources */ = {isa = PBXBuildFile; fileRef = 5DB70524097B94CD009875EC /* webkit.icns */; };
                8D11072D0486CEB800E47090 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; };
                8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; };
@@ -48,7 +48,7 @@
                        isa = PBXFrameworksBuildPhase;
                        buildActionMask = 2147483647;
                        files = (
-                               5D650F7609DB8CB40075E9A8 /* CoreFoundation.framework in Frameworks */,
+                               5D877FCD0A5795F200D0C67B /* Cocoa.framework in Frameworks */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index 5898267..d04fc4d 100644 (file)
 #include <string.h>
 
 static void cleanUpAfterOurselves(void) __attribute__ ((constructor));
+static void *symbol_lookup(char *symbol);
 
-void *symbol_lookup(char *symbol);
+static bool extensionBundlesWereLoaded = NO;
+static NSSet *extensionPaths = nil;
+
+static void myBundleDidLoad(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo)
+{
+    // Break out early if we have already detected an extension
+    if (extensionBundlesWereLoaded)
+        return;
+
+    NSBundle *bundle = (NSBundle *)object;
+    NSString *bundlePath = [[bundle bundlePath] stringByAbbreviatingWithTildeInPath];
+    NSString *bundleFileName = [bundlePath lastPathComponent];
+
+    // Explicitly ignore SIMBL.bundle, as its only purpose is to load extensions
+    // on a per-application basis.  It's presence indicates a user has application
+    // extensions, but not that any will be loaded into Safari
+    if ([bundleFileName isEqualToString:@"SIMBL.bundle"])
+        return;
+
+    // If the bundle lives inside a known extension path, flag it as an extension
+    NSEnumerator *e = [extensionPaths objectEnumerator];
+    NSString *path = nil;
+    while (path = [e nextObject]) {
+        if ([bundlePath length] < [path length])
+            continue;
+
+        if ([[bundlePath substringToIndex:[path length]] isEqualToString:path]) {
+            extensionBundlesWereLoaded = YES;
+            break;
+        }
+    }
+}
+
+static void myApplicationWillFinishLaunching(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo)
+{
+    CFNotificationCenterRemoveObserver(CFNotificationCenterGetLocalCenter(), &myApplicationWillFinishLaunching, NULL, NULL);
+    CFNotificationCenterRemoveObserver(CFNotificationCenterGetLocalCenter(), &myBundleDidLoad, NULL, NULL);
+    [extensionPaths release];
+    extensionPaths = nil;
+
+    if (extensionBundlesWereLoaded)
+        NSRunInformationalAlertPanel(@"Safari extensions detected",
+                                     @"Safari extensions were detected on your system. They are incompatible with nightly builds of WebKit, and may cause crashes or incorrect behavior.  Please disable them if you experience such behavior.", @"Continue", nil, nil);
+}
 
 void cleanUpAfterOurselves(void)
 {
@@ -48,6 +92,18 @@ void cleanUpAfterOurselves(void)
     *procPath = procPathBackup;
     unsetenv("DYLD_INSERT_LIBRARIES");
     unsetenv("CFProcessPath");
+
+    extensionPaths = [[NSSet alloc] initWithObjects:@"~/Library/InputManagers/", @"/Library/InputManagers/",
+                                                    @"~/Library/Application Support/SIMBL/Plugins/", @"/Library/Application Support/SIMBL/Plugins/",
+                                                    @"~/Library/Application Enhancers/", @"/Library/Application Enhancers/",
+                                                    nil];
+
+    CFNotificationCenterAddObserver(CFNotificationCenterGetLocalCenter(), &myBundleDidLoad,
+                                    myBundleDidLoad, (CFStringRef) NSBundleDidLoadNotification,
+                                    NULL, CFNotificationSuspensionBehaviorDeliverImmediately);
+    CFNotificationCenterAddObserver(CFNotificationCenterGetLocalCenter(), &myApplicationWillFinishLaunching,
+                                    myApplicationWillFinishLaunching, (CFStringRef) NSApplicationWillFinishLaunchingNotification,
+                                    NULL, CFNotificationSuspensionBehaviorDeliverImmediately);
 }
 
 #if __LP64__