Ignore:
Timestamp:
04/18/08 16:48:19 (12 years ago)
Author:
Nicholas Riley
Message:

Services in PDFView/WebPDFView; activate on dynamic WebKit?/PDFKit loading.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ICeCoffEE/ICeCoffEE/APEMain.m

    r456 r469  
    1515#import <ApplicationEnhancer/ApplicationEnhancer.h>
    1616#import <ApplicationEnhancer/APETools.h>
     17#import <mach-o/dyld.h>
    1718#import <objc/objc-runtime.h>
    1819#import "ICeCoffEE.h"
     
    6667
    6768// With APE 1.3, if we're in the exclude list, APEBundleMainEarlyLoad doesn't get invoked; don't need to use APETools.  But we need to do our own management to avoid loading in background-only applications.
    68 Boolean ICCF_shouldLoad;
     69static Boolean ICCF_shouldLoad;
    6970
    7071static Boolean ICCF_IsOne(CFTypeRef value) {
     
    9091
    9192    UInt32 icVersion = CFBundleGetVersionNumber(inBundle);
    92     ICapeprintf("ICeCoffEE APE: bundle version is %ld (0x%x)\n", icVersion, icVersion);
     93    ICapeprintf("bundle version is %ld (0x%x)\n", icVersion, icVersion);
    9394    CFNumberRef icVersionRef = CFNumberCreate(NULL, kCFNumberLongType, &icVersion);
    9495    CFPreferencesSetAppValue(kICLastLoadedVersion, icVersionRef, kICBundleIdentifier);
     
    99100    CFBundleRef appBundle = CFBundleGetMainBundle();
    100101    if (appBundle == NULL) {
    101         apeprintf("ICeCoffEE APE: Can't get CFBundle for current process; not loading\n");
     102        apeprintf("can't get CFBundle for current process; not loading\n");
    102103        return;
    103104    }
     
    107108        ICCF_IsOne(CFBundleGetValueForInfoDictionaryKey(appBundle, CFSTR("LSBackgroundOnly"))) ||
    108109        ICCF_IsOne(CFBundleGetValueForInfoDictionaryKey(appBundle, CFSTR("NSBackgroundOnly")))) {
    109         ICapeprintf("ICeCoffEE APE: not loading as this application is background-only\n");
     110        ICapeprintf("not loading as this application is background-only\n");
    110111        return;
    111112    }
     
    115116static Boolean ICCF_CFBundleIDMatches(CFStringRef bundleID, CFStringRef test) {
    116117    return CFStringCompare(bundleID, test, kCFCompareCaseInsensitive) == kCFCompareEqualTo;
     118}
     119
     120static Boolean ICCF_tryLoading = false;
     121static Boolean ICCF_loadedInWebKit = false;
     122static Boolean ICCF_loadedInPDFKit = false;
     123
     124static void ICCF_OnAddImage(const struct mach_header *mh, intptr_t vmaddr_slide) {
     125    if (!ICCF_tryLoading) // when initially registered, called a lot
     126        return;
     127    if (!ICCF_loadedInWebKit &&
     128        ICCF_PatchMethod("WebHTMLView", "ICeCoffEEWebKit", "ICeCoffEEWebKitSuper", "mouseUp:") &&
     129        ICCF_PatchMethod("WebHTMLView", "ICeCoffEEWebKit", "ICeCoffEEWebKitSuper", "mouseDown:") &&
     130        ICCF_PatchMethod("WebHTMLView", "ICeCoffEEWebKit", "ICeCoffEEWebKitSuper", "menuForEvent:") &&
     131        ICCF_PatchMethod("WebPDFView", "ICeCoffEEWebPDFView", "ICeCoffEEWebPDFViewSuper", "menuForEvent:")) {
     132        ICapeprintf("loaded in WebHTMLView/WebPDFView for WebKit/Safari 3\n");
     133        ICCF_loadedInWebKit = true;
     134    }
     135    if (!ICCF_loadedInPDFKit &&
     136        ICCF_PatchMethod("PDFView", "ICeCoffEEPDFView", "ICeCoffEEPDFViewSuper", "menuForEvent:")) {
     137        ICapeprintf("loaded in PDFView for PDFKit\n");
     138        ICCF_loadedInPDFKit = true;
     139    }   
    117140}
    118141
     
    136159                ICCF_PatchMethod("PBXTextView", "ICeCoffEEMenuOnly", "ICeCoffEEMenuSuper", "menuForEvent:");
    137160            }
    138             ICapeprintf("ICeCoffEE APE: loaded in PBXTextView / XCTextView for Xcode\n");
     161            ICapeprintf("loaded in PBXTextView / XCTextView for Xcode\n");
    139162            shouldLoadInNSTextView = NO;
    140163        } else if (ICCF_CFBundleIDMatches(bundleID, CFSTR("com.apple.terminal"))) {
     
    143166                ICCF_PatchMethod("TTView", "ICeCoffEETTView", "ICeCoffEETTViewSuper", "mouseUp:") &&
    144167                ICCF_PatchMethod("TTView", "ICeCoffEETTView", "ICeCoffEETTViewSuper", "draggingEntered:");
    145                 ICapeprintf("ICeCoffEE APE: loaded in TTView for Terminal\n");
     168                ICapeprintf("loaded in TTView for Terminal\n");
    146169            } else {
    147170                ICCF_PatchMethod("TermSubview", "ICeCoffEEMenuOnly", "ICeCoffEEMenuSuper", "menuForEvent:") &&
     
    152175                ICCF_PatchMethod("TermSubview", "ICeCoffEETerminal", "ICeCoffEETermSubviewSuper", "draggingEntered:") &&
    153176                ICCF_PatchMethod("TermSubview", "ICeCoffEETerminal", "ICeCoffEETermSubviewSuper", "_optionClickEvent:::");
    154                 ICapeprintf("ICeCoffEE APE: loaded in TermSubview for Terminal\n");
     177                ICapeprintf("loaded in TermSubview for Terminal\n");
    155178            }
    156179        } else if (ICCF_CFBundleIDMatches(bundleID, CFSTR("org.mozilla.camino"))) {
    157180            ICCF_PatchMethod("ChildView", "ICeCoffEEMenuOnly", "ICeCoffEEMenuSuper", "menuForEvent:");
    158             ICapeprintf("ICeCoffEE APE: loaded in ChildView for Camino\n");
     181            ICapeprintf("loaded in ChildView for Camino\n");
    159182        }
    160183    }
    161184
    162     ICCF_PatchMethod("WebHTMLView", "ICeCoffEEWebKit", "ICeCoffEEWebKitSuper", "mouseUp:") &&
    163         ICCF_PatchMethod("WebHTMLView", "ICeCoffEEWebKit", "ICeCoffEEWebKitSuper", "mouseDown:") &&
    164         ICCF_PatchMethod("WebHTMLView", "ICeCoffEEWebKit", "ICeCoffEEWebKitSuper", "menuForEvent:");
    165     ICapeprintf("ICeCoffEE APE: loaded in WebHTMLView for WebKit/Safari 3\n");
    166    
    167185    if (shouldLoadInNSTextView) {
    168186        ICCF_PatchMethod("NSTextView", "ICeCoffEE", "ICeCoffEESuper", "mouseDown:") &&
    169187        ICCF_PatchMethod("NSTextView", "ICeCoffEE", "ICeCoffEESuper", "clickedOnLink:atIndex:") &&
    170188        ICCF_PatchMethod("NSTextView", "ICeCoffEE", "ICeCoffEESuper", "menuForEvent:");
    171         ICapeprintf("ICeCoffEE APE: loaded generic NSTextView support\n");
    172     }
    173    
    174     ICCF_PatchMethod("PDFView", "ICeCoffEEMenuOnly", "ICeCoffEEMenuSuper", "menuForEvent:");
    175     ICapeprintf("ICeCoffEE APE: loaded in PDFView for PDFKit\n");
     189        ICapeprintf("loaded generic NSTextView support\n");
     190    }
     191   
     192    _dyld_register_func_for_add_image(ICCF_OnAddImage);
     193    ICCF_tryLoading = true;
     194    ICCF_OnAddImage(NULL, 0L);
    176195
    177196    ICCF_ReloadPrefs();
     
    183202OSStatus APEBundleMessage(CFStringRef message,CFDataRef inData,CFDataRef *outData)
    184203{
    185     ICapeprintf("ICeCoffEE APE: message '%@' (inData = %@)\n", message, inData);
     204    ICapeprintf("message '%@' (inData = %@)\n", message, inData);
    186205   
    187206    if (CFStringCompare(message, kICPreferencesChanged, 0) == kCFCompareEqualTo)               
Note: See TracChangeset for help on using the changeset viewer.