From 16b844c96b6423629d6de707ee3fe69257dbd7ce Mon Sep 17 00:00:00 2001 From: Otyr Ugla Date: Fri, 13 Feb 2009 00:21:49 -0600 Subject: [PATCH] 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. --- ClickToFlash.xcodeproj/project.pbxproj | 4 - Plugin/CTFMenubarMenuController.h | 12 +- Plugin/CTFMenubarMenuController.m | 204 +++++-------------- Plugin/CTFWhitelistWindowController.h | 10 +- Plugin/English.lproj/InvisibleItemMenu.xib | 215 --------------------- Plugin/English.lproj/WhitelistPanel.xib | 114 ++++++++--- Plugin/Plugin.h | 2 + Plugin/Plugin.m | 49 ++--- 8 files changed, 168 insertions(+), 442 deletions(-) delete mode 100644 Plugin/English.lproj/InvisibleItemMenu.xib diff --git a/ClickToFlash.xcodeproj/project.pbxproj b/ClickToFlash.xcodeproj/project.pbxproj index 190b105c..a6149e8d 100644 --- a/ClickToFlash.xcodeproj/project.pbxproj +++ b/ClickToFlash.xcodeproj/project.pbxproj @@ -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 = ""; }; 79A21C490F30B735009424B8 /* CTFWhitelistWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CTFWhitelistWindowController.m; path = Plugin/CTFWhitelistWindowController.m; sourceTree = ""; }; 79A21C4A0F30B735009424B8 /* CTFWhitelistWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CTFWhitelistWindowController.h; path = Plugin/CTFWhitelistWindowController.h; sourceTree = ""; }; - A4501BC70F4439FB00D04D61 /* OSAKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OSAKit.framework; path = /System/Library/Frameworks/OSAKit.framework; sourceTree = ""; }; B5028E910F413553004886D7 /* HarnessAppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = HarnessAppDelegate.m; path = "TestFiles/Debugging Harness/HarnessAppDelegate.m"; sourceTree = ""; }; B5028E920F413553004886D7 /* HarnessAppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = HarnessAppDelegate.h; path = "TestFiles/Debugging Harness/HarnessAppDelegate.h"; sourceTree = ""; }; 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 = ""; diff --git a/Plugin/CTFMenubarMenuController.h b/Plugin/CTFMenubarMenuController.h index b367c2c4..14d3d86b 100644 --- a/Plugin/CTFMenubarMenuController.h +++ b/Plugin/CTFMenubarMenuController.h @@ -26,25 +26,22 @@ THE SOFTWARE. #import - @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 diff --git a/Plugin/CTFMenubarMenuController.m b/Plugin/CTFMenubarMenuController.m index c9d015cf..bf7c745b 100644 --- a/Plugin/CTFMenubarMenuController.m +++ b/Plugin/CTFMenubarMenuController.m @@ -26,18 +26,15 @@ of this software and associated documentation files (the "Software"), to deal #import "CTFMenubarMenuController.h" #import "CTFWhitelistWindowController.h" -#import -#import +#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,19 +130,10 @@ - (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; } @@ -150,7 +141,8 @@ - (id) init - (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 diff --git a/Plugin/CTFWhitelistWindowController.h b/Plugin/CTFWhitelistWindowController.h index e92224d1..847f073f 100755 --- a/Plugin/CTFWhitelistWindowController.h +++ b/Plugin/CTFWhitelistWindowController.h @@ -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 diff --git a/Plugin/English.lproj/InvisibleItemMenu.xib b/Plugin/English.lproj/InvisibleItemMenu.xib deleted file mode 100644 index 8fce368b..00000000 --- a/Plugin/English.lproj/InvisibleItemMenu.xib +++ /dev/null @@ -1,215 +0,0 @@ - - - - 1050 - 9G55 - 667 - 949.43 - 353.00 - - YES - - - YES - com.apple.InterfaceBuilderKit - com.apple.InterfaceBuilder.CocoaPlugin - - - YES - - CTFInvisibleItemMenuController - - - FirstResponder - - - NSApplication - - - ClickToFlash - - 2147483647 - - NSImage - NSMenuCheckmark - - - NSImage - NSMenuMixedState - - submenuAction: - - ClickToFlash - - YES - - - - - Load Invisible Flash Content - - 2147483647 - - - - - - - YES - - - theMenu - - - - 12 - - - - loadInvisibleFlashContent: - - - - 22 - - - - loadInvisibleContentMenuItem - - - - 31 - - - - - YES - - 0 - - YES - - - - - - -2 - - - RmlsZSdzIE93bmVyA - - - -1 - - - First Responder - - - -3 - - - Application - - - 2 - - - - - 8 - - - YES - - - - - - 9 - - - - - - - YES - - YES - -1.IBPluginDependency - -2.IBPluginDependency - -3.IBPluginDependency - 2.IBPluginDependency - 8.IBPluginDependency - 9.IBEditorWindowLastContentRect - 9.IBPluginDependency - - - YES - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilderKit - com.apple.InterfaceBuilderKit - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - {{330, 521}, {64, 6}} - com.apple.InterfaceBuilder.CocoaPlugin - - - - YES - - YES - - - YES - - - - - YES - - YES - - - YES - - - - 31 - - - - YES - - CTFInvisibleItemMenuController - NSObject - - loadInvisibleFlashContent: - id - - - YES - - YES - loadInvisibleContentMenuItem - plugin - theMenu - - - YES - NSMenuItem - id - NSMenuItem - - - - IBProjectSource - CTFInvisibleItemMenuController.h - - - - - 0 - ../ClickToFlash.xcodeproj - 3 - - diff --git a/Plugin/English.lproj/WhitelistPanel.xib b/Plugin/English.lproj/WhitelistPanel.xib index 7a1061fc..fe1fc9ec 100755 --- a/Plugin/English.lproj/WhitelistPanel.xib +++ b/Plugin/English.lproj/WhitelistPanel.xib @@ -38,7 +38,7 @@ 15 2 - {{80, 361}, {527, 342}} + {{80, 343}, {527, 360}} -534248448 Q2xpY2sgdG8gRmxhc2gg4oCUIFNldHRpbmdzA NSPanel @@ -89,7 +89,7 @@ 75628032 134217728 Whitelisted Sites - + LucidaGrande 1.100000e+01 3100 @@ -204,7 +204,7 @@ - {{20, 47}, {487, 169}} + {{20, 41}, {487, 169}} 530 @@ -218,14 +218,18 @@ 292 - {{82, 19}, {63, 26}} + {{48, 13}, {29, 26}} YES 67239424 134348800 - Remove - + 4oiSA + + Courier + 1.400000e+01 + 16 + -2038284033 162 @@ -238,14 +242,14 @@ 292 - {{20, 19}, {63, 26}} + {{20, 13}, {29, 26}} YES 67239424 134348800 - Add - + + + -2038284033 162 @@ -258,7 +262,7 @@ 289 - {{227, 22}, {283, 17}} + {{227, 14}, {283, 17}} YES @@ -284,7 +288,7 @@ 268 - {{93, 77}, {236, 18}} + {{93, 104}, {236, 18}} YES @@ -299,11 +303,11 @@ 1211912703 130 - + NSImage NSSwitch - + NSSwitch @@ -312,10 +316,32 @@ 25 + + + 268 + {{93, 84}, {271, 18}} + + YES + + -2080244224 + 0 + Automatically load invisible Flash views + + + 1211912703 + 130 + + + + + 200 + 25 + + 268 - {{26, 78}, {58, 17}} + {{26, 105}, {58, 17}} YES @@ -331,7 +357,7 @@ 268 - {{93, 2}, {285, 58}} + {{93, 9}, {285, 58}} YES 3 @@ -602,7 +628,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA 268 - {{17, 43}, {67, 17}} + {{17, 50}, {67, 17}} YES @@ -616,12 +642,12 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA - {{65, 231}, {397, 115}} + {{65, 222}, {397, 142}} NSView - {527, 342} + {527, 360} {{0, 0}, {1280, 778}} @@ -772,6 +798,22 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA 130 + + + value: values.ClickToFlash_autoLoadInvisibleViews + + + + + + value: values.ClickToFlash_autoLoadInvisibleViews + value + values.ClickToFlash_autoLoadInvisibleViews + 2 + + + 136 + @@ -818,9 +860,9 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA YES - + @@ -922,6 +964,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA + @@ -1013,6 +1056,20 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA + + 131 + + + YES + + + + + + 132 + + + @@ -1044,6 +1101,9 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA 114.IBPluginDependency 12.IBPluginDependency 13.IBPluginDependency + 131.IBAttributePlaceholdersKey + 131.IBPluginDependency + 132.IBPluginDependency 14.IBPluginDependency 17.IBPluginDependency 2.IBPluginDependency @@ -1064,9 +1124,9 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilderKit com.apple.InterfaceBuilderKit - {{38, 380}, {527, 342}} + {{46, 1154}, {527, 360}} com.apple.InterfaceBuilder.CocoaPlugin - {{38, 380}, {527, 342}} + {{46, 1154}, {527, 360}} {196, 240} {{202, 428}, {480, 270}} @@ -1100,6 +1160,16 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + + ToolTip + + ToolTip + + Loads H.264 movie version of YouTube videos by default when possible. + + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -1143,7 +1213,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA - 130 + 136 diff --git a/Plugin/Plugin.h b/Plugin/Plugin.h index ff166341..d4f22a23 100644 --- a/Plugin/Plugin.h +++ b/Plugin/Plugin.h @@ -61,4 +61,6 @@ THE SOFTWARE. - (IBAction)loadH264:(id)sender; - (IBAction)loadAllOnPage:(id)sender; +- (BOOL) isConsideredInvisible; + @end diff --git a/Plugin/Plugin.m b/Plugin/Plugin.m index 75d075f4..6a906663 100644 --- a/Plugin/Plugin.m +++ b/Plugin/Plugin.m @@ -276,28 +276,20 @@ - (id) initWithArguments:(NSDictionary *)arguments // send a notification so that all flash objects can be tracked - DOMElement *clonedElement = (DOMElement *)[self.container cloneNode:YES]; - int height = [[clonedElement getAttribute:@"height"] intValue]; - int width = [[clonedElement getAttribute:@"width"] intValue]; - - if ([ [ NSUserDefaults standardUserDefaults ] boolForKey: sAutoLoadInvisibleFlashViewsKey ] && - ((height <= maxInvisibleDimension) && (width <= maxInvisibleDimension) ) ) { + if ( [ [ NSUserDefaults standardUserDefaults ] boolForKey: sAutoLoadInvisibleFlashViewsKey ] + && [ self isConsideredInvisible ] ) { // auto-loading is on and this view meets the size constraints [self _convertTypesForContainer]; } else { // we only want to track it if we don't auto-load it - [[NSNotificationCenter defaultCenter] postNotificationName:sCTFNewViewNotification - object:self - userInfo:[NSDictionary dictionaryWithObjectsAndKeys:base,@"baseURL",src,@"src", - [NSNumber numberWithInt:height],@"height",[NSNumber numberWithInt:width],@"width",nil] - ]; + [[CTFMenubarMenuController sharedController] registerView: self]; } // Observe various things: NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; - // Observe for additions to the whitelist (can't use KVO due to the dot in the pref key): + // Observe for additions to the whitelist: [center addObserver: self selector: @selector( _whitelistAdditionMade: ) name: sCTFWhitelistAdditionMade @@ -327,11 +319,7 @@ - (void) dealloc [self _abortAlert]; // to be on the safe side // notify that this ClickToFlash plugin is going away - [[NSNotificationCenter defaultCenter] postNotificationName:sCTFDestroyedViewNotification - object:self - userInfo:[NSDictionary dictionaryWithObject:[self baseURL] - forKey:@"baseURL"] - ]; + [[CTFMenubarMenuController sharedController] unregisterView: self]; self.container = nil; self.host = nil; @@ -487,6 +475,16 @@ - (void) _whitelistAdditionMade: (NSNotification*) notification [self _convertTypesForContainer]; } +- (BOOL) isConsideredInvisible +{ + DOMElement* clonedElement = (DOMElement*) [ self.container cloneNode: NO ]; + + int height = [[clonedElement getAttribute:@"height"] intValue]; + int width = [[clonedElement getAttribute:@"width"] intValue]; + + return (height <= maxInvisibleDimension) && (width <= maxInvisibleDimension); +} + #pragma mark - #pragma mark Contextual menu @@ -585,14 +583,8 @@ - (void) _loadContentForWindow: (NSNotification*) notification - (void) _loadInvisibleContentForWindow: (NSNotification*) notification { - if( [ notification object ] == [ self window ] ) { - DOMElement* clonedElement = (DOMElement*) [ self.container cloneNode: NO ]; - int height = [[clonedElement getAttribute:@"height"] intValue]; - int width = [[clonedElement getAttribute:@"width"] intValue]; - - if ( (height <= maxInvisibleDimension) || (width <= maxInvisibleDimension) ) { - [ self _convertTypesForContainer ]; - } + if( [ notification object ] == [ self window ] && [ self isConsideredInvisible ] ) { + [ self _convertTypesForContainer ]; } } @@ -842,12 +834,7 @@ - (void) _convertTypesForElement:(DOMElement *)element - (void) _convertTypesForContainer { // notify that this ClickToFlash plugin is going away - [[NSNotificationCenter defaultCenter] postNotificationName:sCTFDestroyedViewNotification - object:self - userInfo:[NSDictionary dictionaryWithObject:[self baseURL] - forKey:@"baseURL"] - ]; - + [[CTFMenubarMenuController sharedController] unregisterView: self]; if ([self _useH264Version]) [self _convertToMP4Container];