Permalink
Browse files

Simplified code to track living CTF views. Changed technique to find …

…views in front tab to use same views the observations use to actually load. Removed seemingly unused InvisibleItemMenu.xib. Updated settings panel to use + and - instead of words.
  • Loading branch information...
1 parent c12886a commit 16b844c96b6423629d6de707ee3fe69257dbd7ce Otyr Ugla committed Feb 13, 2009
@@ -43,7 +43,6 @@
6953E43C0F3EDEB50014ECF7 /* MenubarMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6953E43A0F3EDEB50014ECF7 /* MenubarMenu.xib */; };
69A26D0C0F302C10006648BC /* NSBezierPath-RoundedRectangle.m in Sources */ = {isa = PBXBuildFile; fileRef = 69A26D0B0F302C10006648BC /* NSBezierPath-RoundedRectangle.m */; };
79A21C4D0F30B735009424B8 /* CTFWhitelistWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 79A21C490F30B735009424B8 /* CTFWhitelistWindowController.m */; };
- A4501BC80F4439FB00D04D61 /* OSAKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A4501BC70F4439FB00D04D61 /* OSAKit.framework */; };
B5028E930F413553004886D7 /* HarnessAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = B5028E910F413553004886D7 /* HarnessAppDelegate.m */; };
B5CFF17A0F40EEF1005DB9CC /* WhitelistPanel.xib in Resources */ = {isa = PBXBuildFile; fileRef = 072189BC0F30D9C3008C8944 /* WhitelistPanel.xib */; };
B5CFF1870F40F000005DB9CC /* HarnessMain.xib in Resources */ = {isa = PBXBuildFile; fileRef = B5CFF1860F40F000005DB9CC /* HarnessMain.xib */; };
@@ -86,7 +85,6 @@
69A26D0B0F302C10006648BC /* NSBezierPath-RoundedRectangle.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSBezierPath-RoundedRectangle.m"; path = "Plugin/NSBezierPath-RoundedRectangle.m"; sourceTree = "<group>"; };
79A21C490F30B735009424B8 /* CTFWhitelistWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CTFWhitelistWindowController.m; path = Plugin/CTFWhitelistWindowController.m; sourceTree = "<group>"; };
79A21C4A0F30B735009424B8 /* CTFWhitelistWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CTFWhitelistWindowController.h; path = Plugin/CTFWhitelistWindowController.h; sourceTree = "<group>"; };
- A4501BC70F4439FB00D04D61 /* OSAKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OSAKit.framework; path = /System/Library/Frameworks/OSAKit.framework; sourceTree = "<absolute>"; };
B5028E910F413553004886D7 /* HarnessAppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = HarnessAppDelegate.m; path = "TestFiles/Debugging Harness/HarnessAppDelegate.m"; sourceTree = "<group>"; };
B5028E920F413553004886D7 /* HarnessAppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = HarnessAppDelegate.h; path = "TestFiles/Debugging Harness/HarnessAppDelegate.h"; sourceTree = "<group>"; };
B5CFF1740F40EEDB005DB9CC /* Whitelist Panel Harness.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Whitelist Panel Harness.app"; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -105,7 +103,6 @@
files = (
55EB70580E04A8B80016593D /* Cocoa.framework in Frameworks */,
55EB70590E04A8B80016593D /* WebKit.framework in Frameworks */,
- A4501BC80F4439FB00D04D61 /* OSAKit.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -164,7 +161,6 @@
children = (
55EB70560E04A8B80016593D /* Cocoa.framework */,
55EB70570E04A8B80016593D /* WebKit.framework */,
- A4501BC70F4439FB00D04D61 /* OSAKit.framework */,
);
name = Frameworks;
sourceTree = "<group>";
@@ -26,25 +26,22 @@ THE SOFTWARE.
#import <Cocoa/Cocoa.h>
-
@class CTFWhitelistWindowController;
+
extern NSString* kCTFLoadAllFlashViews;
extern NSString* kCTFLoadFlashViewsForWindow;
extern NSString* kCTFLoadInvisibleFlashViewsForWindow;
-extern NSString* sCTFNewViewNotification;
-extern NSString* sCTFDestroyedViewNotification;
+
extern NSUInteger maxInvisibleDimension;
@interface CTFMenubarMenuController : NSObject {
IBOutlet NSMenu* menu;
CTFWhitelistWindowController *_whitelistWindowController;
- NSMutableDictionary *_flashViews;
+ NSHashTable *_views;
}
-@property (retain) NSMutableDictionary *flashViews;
-
+ (CTFMenubarMenuController*) sharedController;
- (void) loadFlashForWindow: (NSWindow*) window;
@@ -54,4 +51,7 @@ extern NSUInteger maxInvisibleDimension;
- (IBAction) loadKeyWindowInvisibleFlash: (id) sender;
- (IBAction) showSettingsWindow: (id) sender;
+- (void) registerView: (NSView*) view;
+- (void) unregisterView: (NSView*) view;
+
@end
@@ -26,18 +26,15 @@ of this software and associated documentation files (the "Software"), to deal
#import "CTFMenubarMenuController.h"
#import "CTFWhitelistWindowController.h"
-#import <OSAKit/OSAKit.h>
-#import <WebKit/WebKit.h>
+#import "Plugin.h"
NSString* kCTFLoadAllFlashViews = @"CTFLoadAllFlashViews";
NSString* kCTFLoadFlashViewsForWindow = @"CTFLoadFlashViewsForWindow";
NSString* kCTFLoadInvisibleFlashViewsForWindow = @"CTFLoadInvisibleFlashViewsForWindow";
-NSString *sCTFNewViewNotification = @"CTFNewFlashView";
-NSString *sCTFDestroyedViewNotification = @"CTFDestroyedFlashView";
+
NSUInteger maxInvisibleDimension = 50;
-static CTFMenubarMenuController* sSingleton = nil;
static NSString* kApplicationsToInstallMenuInto[] = {
@"com.apple.Safari",
@@ -116,6 +113,9 @@ - (int) applicationMenuPrefsInsertionLocation
#pragma mark Lifetime management
+static CTFMenubarMenuController* sSingleton = nil;
+
+
- (id) init
{
if( sSingleton ) {
@@ -130,27 +130,19 @@ - (id) init
if( self ) {
if( ! [ NSBundle loadNibNamed: @"MenubarMenu" owner: self ] )
NSLog( @"ClickToFlash: Could not load menubar menu nib" );
+
+ _views = NSCreateHashTable( NSNonRetainedObjectHashCallBacks, 0 );
}
- NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
- [center addObserver: self
- selector: @selector( _trackNewView: )
- name: sCTFNewViewNotification
- object: nil ];
-
- [center addObserver: self
- selector: @selector( _stopTrackingView: )
- name: sCTFDestroyedViewNotification
- object: nil ];
-
return self;
}
- (void) dealloc
{
[ _whitelistWindowController release ];
-
+ NSFreeHashTable( _views );
+
[ super dealloc ];
}
@@ -196,167 +188,69 @@ + (CTFMenubarMenuController*) sharedController
#pragma mark -
#pragma mark View Management
-- (void) _trackNewView: (NSNotification*) notification
-{
- NSMutableDictionary *flashViewsDict = nil;
- if ([self flashViews])
- flashViewsDict = [[self flashViews] copy];
-
- if (! flashViewsDict) flashViewsDict = [NSMutableDictionary dictionary];
-
- NSString *newViewBaseURL = [[[notification userInfo] objectForKey:@"baseURL"] absoluteString];
- NSString *newViewSrc = [[notification userInfo] objectForKey:@"src"];
- NSNumber *newViewHeight = [[notification userInfo] objectForKey:@"height"];
- NSNumber *newViewWidth = [[notification userInfo] objectForKey:@"width"];
- id newTarget = [notification object];
-
- NSDictionary *newTargetDict = [NSDictionary dictionaryWithObjectsAndKeys:newTarget,@"target",newViewSrc,@"src",newViewHeight,@"height",newViewWidth,@"width",nil];
-
- NSMutableArray *baseURLArray = [flashViewsDict objectForKey:newViewBaseURL];
-
- if (! baseURLArray) {
- baseURLArray = [NSMutableArray arrayWithObject:newTargetDict];
- [flashViewsDict setObject:baseURLArray forKey:newViewBaseURL];
- } else {
- [baseURLArray addObject:newTargetDict];
- }
-
- [self setFlashViews:flashViewsDict];
-
- // not sure why, but the following lines causes crashes and unexpected behavior
- //[flashViewsDict release];
-}
-- (void) _stopTrackingView: (NSNotification*) notification
+- (void) registerView: (NSView*) view
{
- NSMutableDictionary *flashViewsDict = nil;
- if ([self flashViews])
- flashViewsDict = [[self flashViews] copy];
-
- if (! flashViewsDict) flashViewsDict = [NSMutableDictionary dictionary];
-
- NSString *baseURL = [[notification userInfo] objectForKey:@"baseURL"];
- NSMutableArray *baseURLArray = [flashViewsDict objectForKey:baseURL];
- id flashView = [notification object];
-
- if (! baseURLArray) {
- // we're apparently not tracking this view
- return;
- }
-
- NSDictionary *currentDictionary;
- BOOL foundView = NO;
- for (currentDictionary in baseURLArray) {
- if ([currentDictionary objectForKey:@"target"] == flashView) {
- foundView = YES;
- break;
- }
- }
-
- if (foundView) {
- // only do this stuff if we actually find the view we want to stop tracking
-
- [baseURLArray removeObject:currentDictionary];
- if ([baseURLArray count] == 0) [flashViewsDict removeObjectForKey:baseURL];
- [self setFlashViews:flashViewsDict];
- }
+ NSHashInsertIfAbsent( _views, view );
}
-- (NSString *)_baseURLOfKeyWindow;
-{
- // [[NSBundle mainBundle] bundleIdentifier|executablePath|bundlePath] all return stuff for Safari
- // even if called from WebKit
-
- // the following line crashes WebKit, so we can't use the Scripting Bridge until that is fixed
- // SafariApplication *safari = [SBApplication applicationWithProcessIdentifier:getpid()];
-
- NSString *webKitFrameworkBundlePath = [[NSBundle bundleForClass:[WebView class]] bundlePath];
-
- BOOL isWebKit = NO;
- if (! [webKitFrameworkBundlePath hasPrefix:@"/System/Library/Frameworks"]) {
- // we're not using the system version of WebKit, so it's the WebKit app
- isWebKit = YES;
- };
-
- // the following line doesn't seem to work reliably
- // BOOL isWebKit = [[[NSProcessInfo processInfo] arguments] containsObject:@"-WebKitDeveloperExtras"];
- NSString *appString = @"";
- if (isWebKit) {
- appString = @"WebKit";
- } else {
- appString = @"Safari";
- }
-
- NSString *appleScriptSourceString = [NSString stringWithFormat:@"tell application \"%@\"\nURL of current tab of front window\nend tell",appString];
-
-
- // I didn't want to bring OSACrashyScript into this, but I had to; sorry guys, Scripting Bridge
- // just totally crashes WebKit and that's unacceptable
-
- NSDictionary *errorDict = nil;
- OSAScript *browserNameScript = [[OSAScript alloc] initWithSource:appleScriptSourceString];
- NSAppleEventDescriptor *aeDesc = [browserNameScript executeAndReturnError:&errorDict];
- [browserNameScript release];
-
- NSString *baseURL = nil;
-
- if (! errorDict) baseURL = [aeDesc stringValue];
-
- return baseURL;
-}
-- (BOOL) _atLeastOneFlashViewExists;
+- (void) unregisterView: (NSView*) view
{
- NSLog(@"%@",[self flashViews]);
- return ([[[self flashViews] allKeys] count] >= 1);
+ NSHashRemove( _views, view );
}
-- (BOOL) _flashViewExistsForKeyWindow;
+- (BOOL) _atLeastOneFlashViewExists
{
- NSString *baseURL = [self _baseURLOfKeyWindow];
-
- // if there's an array for the base URL, there is at least one view
- // with that base URL
- return ([[self flashViews] objectForKey:baseURL] != nil);
+ return NSCountHashTable( _views ) > 0;
}
-- (BOOL) _invisibleFlashViewExistsForKeyWindow;
+
+- (BOOL) _flashViewExistsForKeyWindowWithInvisibleOnly: (BOOL) mustBeInvisible
{
- BOOL returnValue = NO;
- NSString *baseURL = [self _baseURLOfKeyWindow];
+ BOOL rslt = NO;
- NSMutableArray *baseURLArray = [[self flashViews] objectForKey:baseURL];
+ NSWindow* keyWindow = [ NSApp keyWindow ];
- if (baseURLArray) {
- NSDictionary *currentDictionary = nil;
-
- for (currentDictionary in baseURLArray) {
- NSUInteger height = [[currentDictionary objectForKey:@"height"] intValue];
- NSUInteger width = [[currentDictionary objectForKey:@"width"] intValue];
-
- if ((height <= maxInvisibleDimension) && (width <= maxInvisibleDimension)) {
- returnValue = YES;
+ NSHashEnumerator enumerator = NSEnumerateHashTable( _views );
+ CTFClickToFlashPlugin* item;
+ while( item = NSNextHashEnumeratorItem( &enumerator ) ) {
+ if( [ item window ] == keyWindow ) {
+ if( !mustBeInvisible || [ item isConsideredInvisible ] ) {
+ rslt = YES;
break;
}
}
}
+ NSEndHashTableEnumeration( &enumerator );
- return returnValue;
+ return rslt;
}
-- (BOOL)validateMenuItem:(NSMenuItem *)item {
- BOOL returnValue = YES;
-
- if ([item action] == @selector(loadAllFlash:)) {
- returnValue = [self _atLeastOneFlashViewExists];
- } else if ([item action] == @selector(loadKeyWindowFlash:)) {
- returnValue = [self _flashViewExistsForKeyWindow];
- } else if ([item action] == @selector(loadKeyWindowInvisibleFlash:)) {
- returnValue = [self _invisibleFlashViewExistsForKeyWindow];
+- (BOOL) _flashViewExistsForKeyWindow
+{
+ return [ self _flashViewExistsForKeyWindowWithInvisibleOnly: NO ];
+}
+
+- (BOOL) _invisibleFlashViewExistsForKeyWindow;
+{
+ return [ self _flashViewExistsForKeyWindowWithInvisibleOnly: YES ];
+}
+
+- (BOOL) validateMenuItem: (NSMenuItem*) item
+{
+ if ( [ item action ] == @selector( loadAllFlash: ) ) {
+ return [ self _atLeastOneFlashViewExists ];
+ }
+ else if( [ item action ] == @selector( loadKeyWindowFlash: ) ) {
+ return [ self _flashViewExistsForKeyWindow ];
+ }
+ else if( [ item action ] == @selector(loadKeyWindowInvisibleFlash: ) ) {
+ return [ self _invisibleFlashViewExistsForKeyWindow ];
}
- return returnValue;
+ return YES;
}
#pragma mark -
@@ -408,6 +302,4 @@ - (IBAction) showSettingsWindow: (id) sender
[ _whitelistWindowController showWindow: sender ];
}
-@synthesize flashViews = _flashViews;
-
@end
@@ -2,14 +2,8 @@
@interface CTFWhitelistWindowController : NSWindowController {
- IBOutlet NSArrayController *_controller;
-// NSMutableArray *_sites;
+ IBOutlet NSArrayController *_controller;
}
-//
-//- (IBAction) addWhitelistSite: (id) sender;
-//- (IBAction) removeWhitelistSite: (id) sender;
-//
-//- (void) saveWhitelist: (id) sender;
-//- (void) whitelistChanged: (NSNotification *) note;
+
@end
Oops, something went wrong.

0 comments on commit 16b844c

Please sign in to comment.