From 57732f6f6bfe0cf96eaa029786148b423b2e5da1 Mon Sep 17 00:00:00 2001 From: Simone Manganelli Date: Tue, 3 Feb 2009 00:35:26 -0800 Subject: [PATCH 1/6] Added a menu for flash objects which have a height or width less than 8 pixels --- Plugin/CTFInvisibleItemMenuController.h | 26 +++ Plugin/CTFInvisibleItemMenuController.m | 60 +++++ Plugin/English.lproj/InvisibleItemMenu.xib | 215 +++++++++++++++++ Plugin/Safari.h | 258 +++++++++++++++++++++ 4 files changed, 559 insertions(+) create mode 100644 Plugin/CTFInvisibleItemMenuController.h create mode 100644 Plugin/CTFInvisibleItemMenuController.m create mode 100644 Plugin/English.lproj/InvisibleItemMenu.xib create mode 100644 Plugin/Safari.h diff --git a/Plugin/CTFInvisibleItemMenuController.h b/Plugin/CTFInvisibleItemMenuController.h new file mode 100644 index 00000000..c5f68bf8 --- /dev/null +++ b/Plugin/CTFInvisibleItemMenuController.h @@ -0,0 +1,26 @@ +// +// CTFInvisibleItemMenuController.h +// ClickToFlash +// +// Created by Simone Manganelli on 2009-02-02. +// Copyright 2009 __MyCompanyName__. All rights reserved. +// + +#import +@class CTFClickToFlashPlugin; + +@interface CTFInvisibleItemMenuController : NSObject { + IBOutlet NSMenuItem *theMenu; + IBOutlet NSMenuItem *loadInvisibleContentMenuItem; + id plugin; + NSMutableArray *targets; +} + +@property (retain) CTFClickToFlashPlugin *plugin; +@property (retain) NSMutableArray *targets; + +- (IBAction)loadInvisibleFlashContent:(id)sender; +- (NSMenuItem *)menu; +- (NSMenuItem *)loadInvisibleContentMenuItem; + +@end diff --git a/Plugin/CTFInvisibleItemMenuController.m b/Plugin/CTFInvisibleItemMenuController.m new file mode 100644 index 00000000..1aa4b946 --- /dev/null +++ b/Plugin/CTFInvisibleItemMenuController.m @@ -0,0 +1,60 @@ +// +// CTFInvisibleItemMenuController.m +// ClickToFlash +// +// Created by Simone Manganelli on 2009-02-02. +// Copyright 2009 __MyCompanyName__. All rights reserved. +// + +#import "CTFInvisibleItemMenuController.h" +#import "Plugin.h" +#import "Safari.h" +#include +#include +#import + +@implementation CTFInvisibleItemMenuController + +@synthesize plugin; +@synthesize targets; + +- (IBAction)loadInvisibleFlashContent:(id)sender; +{ + // [[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()]; + + 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]; + + [plugin performSelector:@selector(loadInvisibleFlashContentForBaseURL:) withObject:[aeDesc stringValue] afterDelay:0]; +} + +- (NSMenuItem *)menu; +{ + return theMenu; +} + +- (NSMenuItem *)loadInvisibleContentMenuItem; +{ + return loadInvisibleContentMenuItem; +} + +@end diff --git a/Plugin/English.lproj/InvisibleItemMenu.xib b/Plugin/English.lproj/InvisibleItemMenu.xib new file mode 100644 index 00000000..8fce368b --- /dev/null +++ b/Plugin/English.lproj/InvisibleItemMenu.xib @@ -0,0 +1,215 @@ + + + + 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/Safari.h b/Plugin/Safari.h new file mode 100644 index 00000000..57c302f3 --- /dev/null +++ b/Plugin/Safari.h @@ -0,0 +1,258 @@ +/* + * Safari.h + */ + +#import +#import + + +@class SafariItem, SafariApplication, SafariColor, SafariDocument, SafariWindow, SafariAttributeRun, SafariCharacter, SafariParagraph, SafariText, SafariAttachment, SafariWord, SafariDocument, SafariTab, SafariWindow, SafariPrintSettings; + +typedef enum { + SafariSavoAsk = 'ask ' /* Ask the user whether or not to save the file. */, + SafariSavoNo = 'no ' /* Do not save the file. */, + SafariSavoYes = 'yes ' /* Save the file. */ +} SafariSavo; + +typedef enum { + SafariEnumStandard = 'lwst' /* Standard PostScript error handling */, + SafariEnumDetailed = 'lwdt' /* print a detailed report of PostScript errors */ +} SafariEnum; + + + +/* + * Standard Suite + */ + +// A scriptable object. +@interface SafariItem : SBObject + +@property (copy) NSDictionary *properties; // All of the object's properties. + +- (void) closeSaving:(SafariSavo)saving savingIn:(NSURL *)savingIn; // Close an object. +- (void) delete; // Delete an object. +- (void) duplicateTo:(SBObject *)to withProperties:(NSDictionary *)withProperties; // Copy object(s) and put the copies at a new location. +- (BOOL) exists; // Verify if an object exists. +- (void) moveTo:(SBObject *)to; // Move object(s) to a new location. +- (void) saveAs:(NSString *)as in:(NSURL *)in_; // Save an object. + +@end + +// An application's top level scripting object. +@interface SafariApplication : SBApplication + +- (SBElementArray *) documents; +- (SBElementArray *) windows; + +@property (readonly) BOOL frontmost; // Is this the frontmost (active) application? +@property (copy, readonly) NSString *name; // The name of the application. +@property (copy, readonly) NSString *version; // The version of the application. + +- (SafariDocument *) open:(NSURL *)x; // Open an object. +- (void) print:(NSURL *)x printDialog:(BOOL)printDialog withProperties:(SafariPrintSettings *)withProperties; // Print an object. +- (void) quitSaving:(SafariSavo)saving; // Quit an application. +- (id) doJavaScript:(NSString *)x in:(SafariTab *)in_; // Applies a string of JavaScript code to a document. +- (void) emailContentsOf:(SafariTab *)of; // Emails the contents of a tab. +- (void) showBookmarks; // Shows Safari's bookmarks. + +@end + +// A color. +@interface SafariColor : SafariItem + + +@end + +// A document. +@interface SafariDocument : SafariItem + +@property (readonly) BOOL modified; // Has the document been modified since the last save? +@property (copy) NSString *name; // The document's name. +@property (copy) NSString *path; // The document's path. + + +@end + +// A window. +@interface SafariWindow : SafariItem + +@property NSRect bounds; // The bounding rectangle of the window. +@property (readonly) BOOL closeable; // Whether the window has a close box. +@property (copy, readonly) SafariDocument *document; // The document whose contents are being displayed in the window. +@property (readonly) BOOL floating; // Whether the window floats. +- (NSInteger) id; // The unique identifier of the window. +@property NSInteger index; // The index of the window, ordered front to back. +@property (readonly) BOOL miniaturizable; // Whether the window can be miniaturized. +@property BOOL miniaturized; // Whether the window is currently miniaturized. +@property (readonly) BOOL modal; // Whether the window is the application's current modal window. +@property (copy) NSString *name; // The full title of the window. +@property (readonly) BOOL resizable; // Whether the window can be resized. +@property (readonly) BOOL titled; // Whether the window has a title bar. +@property BOOL visible; // Whether the window is currently visible. +@property (readonly) BOOL zoomable; // Whether the window can be zoomed. +@property BOOL zoomed; // Whether the window is currently zoomed. + + +@end + + + +/* + * Text Suite + */ + +// This subdivides the text into chunks that all have the same attributes. +@interface SafariAttributeRun : SafariItem + +- (SBElementArray *) attachments; +- (SBElementArray *) attributeRuns; +- (SBElementArray *) characters; +- (SBElementArray *) paragraphs; +- (SBElementArray *) words; + +@property (copy) NSColor *color; // The color of the first character. +@property (copy) NSString *font; // The name of the font of the first character. +@property NSInteger size; // The size in points of the first character. + + +@end + +// This subdivides the text into characters. +@interface SafariCharacter : SafariItem + +- (SBElementArray *) attachments; +- (SBElementArray *) attributeRuns; +- (SBElementArray *) characters; +- (SBElementArray *) paragraphs; +- (SBElementArray *) words; + +@property (copy) NSColor *color; // The color of the first character. +@property (copy) NSString *font; // The name of the font of the first character. +@property NSInteger size; // The size in points of the first character. + + +@end + +// This subdivides the text into paragraphs. +@interface SafariParagraph : SafariItem + +- (SBElementArray *) attachments; +- (SBElementArray *) attributeRuns; +- (SBElementArray *) characters; +- (SBElementArray *) paragraphs; +- (SBElementArray *) words; + +@property (copy) NSColor *color; // The color of the first character. +@property (copy) NSString *font; // The name of the font of the first character. +@property NSInteger size; // The size in points of the first character. + + +@end + +// Rich (styled) text +@interface SafariText : SafariItem + +- (SBElementArray *) attachments; +- (SBElementArray *) attributeRuns; +- (SBElementArray *) characters; +- (SBElementArray *) paragraphs; +- (SBElementArray *) words; + +@property (copy) NSColor *color; // The color of the first character. +@property (copy) NSString *font; // The name of the font of the first character. +@property NSInteger size; // The size in points of the first character. + +- (id) doJavaScriptIn:(SafariTab *)in_; // Applies a string of JavaScript code to a document. + +@end + +// Represents an inline text attachment. This class is used mainly for make commands. +@interface SafariAttachment : SafariText + +@property (copy) NSString *fileName; // The path to the file for the attachment + + +@end + +// This subdivides the text into words. +@interface SafariWord : SafariItem + +- (SBElementArray *) attachments; +- (SBElementArray *) attributeRuns; +- (SBElementArray *) characters; +- (SBElementArray *) paragraphs; +- (SBElementArray *) words; + +@property (copy) NSColor *color; // The color of the first character. +@property (copy) NSString *font; // The name of the font of the first character. +@property NSInteger size; // The size in points of the first character. + + +@end + + + +/* + * Safari suite + */ + +// A Safari document representing the active tab in a window. +@interface SafariDocument (SafariSuite) + +@property (copy, readonly) NSString *source; // The HTML source of the web page currently loaded in the document. +@property (copy, readonly) SafariText *text; // The text of the web page currently loaded in the document. Modifications to text aren't reflected on the web page. +@property (copy) NSString *URL; // The current URL of the document. + +@end + +// A Safari window tab. +@interface SafariTab : SafariItem + +@property (readonly) NSInteger index; // The index of the tab, ordered left to right. +@property (copy, readonly) NSString *name; // The name of the tab. +@property (copy, readonly) NSString *source; // The HTML source of the web page currently loaded in the tab. +@property (copy, readonly) SafariText *text; // The text of the web page currently loaded in the tab. Modifications to text aren't reflected on the web page. +@property (copy) NSString *URL; // The current URL of the tab. +@property (readonly) BOOL visible; // Whether the tab is currently visible. + + +@end + +// A Safari window. +@interface SafariWindow (SafariSuite) + +- (SBElementArray *) tabs; + +@property (copy) SafariTab *currentTab; // The current tab. + +@end + + + +/* + * Type Definitions + */ + +@interface SafariPrintSettings : SBObject + +@property NSInteger copies; // the number of copies of a document to be printed +@property BOOL collating; // Should printed copies be collated? +@property NSInteger startingPage; // the first page of the document to be printed +@property NSInteger endingPage; // the last page of the document to be printed +@property NSInteger pagesAcross; // number of logical pages laid across a physical page +@property NSInteger pagesDown; // number of logical pages laid out down a physical page +@property (copy) NSDate *requestedPrintTime; // the time at which the desktop printer should print the document +@property SafariEnum errorHandling; // how errors are handled +@property (copy) NSString *faxNumber; // for fax number +@property (copy) NSString *targetPrinter; // for target printer + +- (void) closeSaving:(SafariSavo)saving savingIn:(NSURL *)savingIn; // Close an object. +- (void) delete; // Delete an object. +- (void) duplicateTo:(SBObject *)to withProperties:(NSDictionary *)withProperties; // Copy object(s) and put the copies at a new location. +- (BOOL) exists; // Verify if an object exists. +- (void) moveTo:(SBObject *)to; // Move object(s) to a new location. +- (void) saveAs:(NSString *)as in:(NSURL *)in_; // Save an object. + +@end + From d8483a1eab3f52bc7d2377b20b86ff5723a5dc8a Mon Sep 17 00:00:00 2001 From: Simone Manganelli Date: Tue, 3 Feb 2009 00:58:42 -0800 Subject: [PATCH 2/6] Added a menu for flash objects which have a height or width less than 8 pixels --- ClickToFlash.xcodeproj/project.pbxproj | 36 +++++- Plugin/Plugin.h | 10 ++ Plugin/Plugin.m | 171 ++++++++++++++++++++++++- 3 files changed, 212 insertions(+), 5 deletions(-) diff --git a/ClickToFlash.xcodeproj/project.pbxproj b/ClickToFlash.xcodeproj/project.pbxproj index 839667be..389b6565 100644 --- a/ClickToFlash.xcodeproj/project.pbxproj +++ b/ClickToFlash.xcodeproj/project.pbxproj @@ -47,6 +47,9 @@ 55EB70590E04A8B80016593D /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 55EB70570E04A8B80016593D /* WebKit.framework */; }; 69A26D0C0F302C10006648BC /* NSBezierPath-RoundedRectangle.m in Sources */ = {isa = PBXBuildFile; fileRef = 69A26D0B0F302C10006648BC /* NSBezierPath-RoundedRectangle.m */; }; 79A21C4D0F30B735009424B8 /* CTFWhitelistWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 79A21C490F30B735009424B8 /* CTFWhitelistWindowController.m */; }; + A4BB102B0F383697005D000F /* CTFInvisibleItemMenuController.m in Sources */ = {isa = PBXBuildFile; fileRef = A4BB10280F383697005D000F /* CTFInvisibleItemMenuController.m */; }; + A4BB102D0F38369B005D000F /* InvisibleItemMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = A4BB102C0F38369B005D000F /* InvisibleItemMenu.xib */; }; + A4BB103D0F383721005D000F /* OSAKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A4BB103C0F383721005D000F /* OSAKit.framework */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -99,6 +102,12 @@ 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 = ""; }; + A4BB10260F383697005D000F /* Safari.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Safari.h; sourceTree = ""; }; + A4BB10270F383697005D000F /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/InvisibleItemMenu.xib; sourceTree = ""; }; + A4BB10280F383697005D000F /* CTFInvisibleItemMenuController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CTFInvisibleItemMenuController.m; sourceTree = ""; }; + A4BB10290F383697005D000F /* CTFInvisibleItemMenuController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CTFInvisibleItemMenuController.h; sourceTree = ""; }; + A4BB103C0F383721005D000F /* OSAKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OSAKit.framework; path = /System/Library/Frameworks/OSAKit.framework; sourceTree = ""; }; + A4BB10E30F38374E005D000F /* ScriptingBridge.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ScriptingBridge.framework; path = /System/Library/Frameworks/ScriptingBridge.framework; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -116,6 +125,7 @@ files = ( 55EB70580E04A8B80016593D /* Cocoa.framework in Frameworks */, 55EB70590E04A8B80016593D /* WebKit.framework in Frameworks */, + A4BB103D0F383721005D000F /* OSAKit.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -156,15 +166,19 @@ 55EB70540E04A89C0016593D /* Plugin */ = { isa = PBXGroup; children = ( - 072189BA0F30D9C3008C8944 /* ContextualMenu.xib */, - 79A21C490F30B735009424B8 /* CTFWhitelistWindowController.m */, - 79A21C4A0F30B735009424B8 /* CTFWhitelistWindowController.h */, 55EB70610E04A8D00016593D /* Info-Plugin.plist */, 55EB703C0E04A84F0016593D /* Plugin.h */, 55EB703D0E04A84F0016593D /* Plugin.m */, + 072189BA0F30D9C3008C8944 /* ContextualMenu.xib */, + 79A21C4A0F30B735009424B8 /* CTFWhitelistWindowController.h */, + 79A21C490F30B735009424B8 /* CTFWhitelistWindowController.m */, + 072189BC0F30D9C3008C8944 /* WhitelistPanel.xib */, + A4BB10260F383697005D000F /* Safari.h */, + A4BB10290F383697005D000F /* CTFInvisibleItemMenuController.h */, + A4BB10280F383697005D000F /* CTFInvisibleItemMenuController.m */, + A4BB102C0F38369B005D000F /* InvisibleItemMenu.xib */, 69A26D0A0F302C10006648BC /* NSBezierPath-RoundedRectangle.h */, 69A26D0B0F302C10006648BC /* NSBezierPath-RoundedRectangle.m */, - 072189BC0F30D9C3008C8944 /* WhitelistPanel.xib */, ); name = Plugin; sourceTree = ""; @@ -174,6 +188,8 @@ children = ( 55EB70560E04A8B80016593D /* Cocoa.framework */, 55EB70570E04A8B80016593D /* WebKit.framework */, + A4BB103C0F383721005D000F /* OSAKit.framework */, + A4BB10E30F38374E005D000F /* ScriptingBridge.framework */, ); name = Frameworks; sourceTree = ""; @@ -254,6 +270,7 @@ files = ( 072189BE0F30D9C3008C8944 /* ContextualMenu.xib in Resources */, 072189BF0F30D9C3008C8944 /* WhitelistPanel.xib in Resources */, + A4BB102D0F38369B005D000F /* InvisibleItemMenu.xib in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -304,6 +321,7 @@ 69A26D0C0F302C10006648BC /* NSBezierPath-RoundedRectangle.m in Sources */, 79A21C4D0F30B735009424B8 /* CTFWhitelistWindowController.m in Sources */, 55EB70480E04A8850016593D /* Plugin.m in Sources */, + A4BB102B0F383697005D000F /* CTFInvisibleItemMenuController.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -365,6 +383,14 @@ name = WhitelistPanel.xib; sourceTree = ""; }; + A4BB102C0F38369B005D000F /* InvisibleItemMenu.xib */ = { + isa = PBXVariantGroup; + children = ( + A4BB10270F383697005D000F /* English */, + ); + name = InvisibleItemMenu.xib; + sourceTree = ""; + }; /* End PBXVariantGroup section */ /* Begin XCBuildConfiguration section */ @@ -501,6 +527,7 @@ ); PREBINDING = NO; PRODUCT_NAME = ClickToFlash; + PRODUCT_VERSION = "1.3+simx"; SDKROOT = /Developer/SDKs/MacOSX10.5.sdk; WRAPPER_EXTENSION = plugin; ZERO_LINK = NO; @@ -526,6 +553,7 @@ ); PREBINDING = NO; PRODUCT_NAME = ClickToFlash; + PRODUCT_VERSION = "1.3+simX"; SDKROOT = /Developer/SDKs/MacOSX10.5.sdk; WRAPPER_EXTENSION = plugin; ZERO_LINK = NO; diff --git a/Plugin/Plugin.h b/Plugin/Plugin.h index c3f06c1b..93da6be4 100644 --- a/Plugin/Plugin.h +++ b/Plugin/Plugin.h @@ -29,28 +29,38 @@ THE SOFTWARE. #import @class CTFWhitelistWindowController; +@class CTFInvisibleItemMenuController; @interface CTFClickToFlashPlugin : NSView { DOMElement *_container; NSString *_host; + NSString *baseURL; CTFWhitelistWindowController *_whitelistWindowController; + CTFInvisibleItemMenuController *_invisibleItemMenuController; NSTrackingArea *trackingArea; BOOL mouseIsDown; BOOL mouseInside; BOOL _isLoadingFromWhitelist; + BOOL _isKeepingTrackOfInvisibleFlashTargets; + NSMutableDictionary *invisibleFlashTargets; } + (NSView *)plugInViewWithArguments:(NSDictionary *)arguments; - (id) initWithArguments:(NSDictionary *)arguments; +@property (assign) NSString *baseURL; @property (nonatomic, retain) DOMElement *container; @property (nonatomic, retain) NSString *host; @property (readonly, nonatomic, retain) NSString *addToWhiteListMenuTitle; +@property (retain) NSMutableDictionary *invisibleFlashTargets; - (IBAction)addToWhitelist:(id)sender; - (IBAction)removeFromWhitelist:(id)sender; - (IBAction)editWhitelist:(id)sender; - (IBAction)loadFlash:(id)sender; +- (void)startTrackingInvisibleFlashTargets:(NSMutableDictionary *)newInvisibleFlashTargets; +- (void)removeSelfFromInvisibleFlashTargetDict; + @end diff --git a/Plugin/Plugin.m b/Plugin/Plugin.m index 82d7c90f..23a0ae47 100644 --- a/Plugin/Plugin.m +++ b/Plugin/Plugin.m @@ -28,11 +28,13 @@ of this software and associated documentation files (the "Software"), to deal #import "Plugin.h" #import "NSBezierPath-RoundedRectangle.h" #import "CTFWhitelistWindowController.h" +#import "CTFInvisibleItemMenuController.h" static NSString *sFlashOldMIMEType = @"application/x-shockwave-flash"; static NSString *sFlashNewMIMEType = @"application/futuresplash"; static NSString *sHostWhitelistDefaultsKey = @"ClickToFlash.whitelist"; static NSString *sCTFWhitelistAdditionMade = @"CTFWhitelistAdditionMade"; +static NSString *sCTFInvisibleContentNotification = @"CTFNewInvisibleContent"; @interface CTFClickToFlashPlugin (Internal) - (void) _convertTypesForContainer; @@ -66,9 +68,11 @@ - (id) initWithArguments:(NSDictionary *)arguments { self = [super init]; if (self) { + _isKeepingTrackOfInvisibleFlashTargets = NO; self.container = [arguments objectForKey:WebPlugInContainingElementKey]; NSURL *base = [arguments objectForKey:WebPlugInBaseURLKey]; + [self setBaseURL:[base absoluteString]]; if (base) { self.host = [base host]; if ([self _isHostWhitelisted] && ![self _isOptionPressed]) { @@ -76,13 +80,17 @@ - (id) initWithArguments:(NSDictionary *)arguments [self performSelector:@selector(_convertTypesForContainer) withObject:nil afterDelay:0]; } } + + if (![NSBundle loadNibNamed:@"ContextualMenu" owner:self]) NSLog(@"Could not load conextual menu plugin"); + NSDictionary *attributes = [arguments objectForKey:WebPlugInAttributesKey]; + NSString *src = nil; if (attributes != nil) { - NSString *src = [attributes objectForKey:@"src"]; + src = [attributes objectForKey:@"src"]; if (src) [self setToolTip:src]; else { @@ -92,12 +100,39 @@ - (id) initWithArguments:(NSDictionary *)arguments } } + DOMElement *clonedElement = (DOMElement *)[self.container cloneNode:YES]; + int height = [[clonedElement getAttribute:@"height"] intValue]; + int width = [[clonedElement getAttribute:@"width"] intValue]; + + // thanks @rentzsch for the nice round powers of 2 + if ( (height < 8) || (width < 8) ) { + NSMenu *mainMenu = [NSApp mainMenu]; + NSMenuItem *clickToFlashMenu = [mainMenu itemWithTitle:@"ClickToFlash"]; + + if (! clickToFlashMenu) { + [self startTrackingInvisibleFlashTargets:nil]; + } + + + // this seems to be the only possible of way of communicating with the first plugin instance; + // the first ClickToFlash plugin instance w/"invisible" flash content to load will keep an array + // of other "invisible" flash plugin instances, so that there can be one menu item that will load + // *all* "invisible" flash content for a single page + + [[NSNotificationCenter defaultCenter] postNotificationName:sCTFInvisibleContentNotification + object:self + userInfo:[NSDictionary dictionaryWithObjectsAndKeys:base,@"baseURL",src,@"src",nil]]; + + } + + // Observe for additions to the whitelist (can't use KVO due to the dot in the pref key): [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector( _whitelistAdditionMade: ) name: sCTFWhitelistAdditionMade object: nil ]; + } return self; @@ -106,9 +141,33 @@ - (id) initWithArguments:(NSDictionary *)arguments - (void) dealloc { + // it looks like ClickToFlash bundles may not unload themselves even + // when the content they are controlling is closed, so this code here to pass + // off handling to a different plugin may be entirely unnecessary + + [self removeSelfFromInvisibleFlashTargetDict]; + + if (_isKeepingTrackOfInvisibleFlashTargets) { + // we need to pass off "invisible" plugin handling to a different instance + NSArray *invisibleKeyArray = [[self invisibleFlashTargets] allKeys]; + if ([invisibleKeyArray count] == 0) { + // we can get rid of the menu; no more invisible content + + NSMenu *mainMenu = [NSApp mainMenu]; + [mainMenu removeItem:[mainMenu itemWithTitle:@"ClickToFlash"]]; + } else { + NSArray *firstKeyArray = [[self invisibleFlashTargets] objectForKey:[invisibleKeyArray objectAtIndex:0]]; + CTFClickToFlashPlugin *target = [[firstKeyArray objectAtIndex:0] objectForKey:@"target"]; + + [target startTrackingInvisibleFlashTargets:[self invisibleFlashTargets]]; + } + + } + self.container = nil; self.host = nil; [_whitelistWindowController release]; + [_invisibleItemMenuController release]; [[NSNotificationCenter defaultCenter] removeObserver: self]; [super dealloc]; } @@ -309,6 +368,112 @@ - (IBAction)loadFlash:(id)sender; [self _convertTypesForContainer]; } +#pragma mark - +#pragma mark Invisble Flash Content Menu + +// this method stores info about every single plugin that's managing an "invisible" +// flash object. the invisibleFlashTargets property is a dictionary which stores +// the objects by base URL, since when we choose the menu item, we want to load all +// invisible objects of the frontmost tab's base URL -- this makes for easy retrieval + +// EVERY. SINGLE. INSTANCE. of ClickToFlash that deals with "invisible" flash object +// stores the info about all others. Because we don't know which plugin instance will +// be the first to load (and therefore the one that's handling the menu item), all +// plugins need this info and observe for notifications + +- (void)_newInvisibleFlashPluginInitialized:(NSNotification *)notification; +{ + NSMutableDictionary *invisibleFlashTargetsDict = nil; + if ([self invisibleFlashTargets]) + invisibleFlashTargetsDict = [[self invisibleFlashTargets] copy]; + + if (! invisibleFlashTargetsDict) invisibleFlashTargetsDict = [NSMutableDictionary dictionary]; + + NSString *newPluginBaseURL = [[[notification userInfo] objectForKey:@"baseURL"] absoluteString]; + NSString *newPluginSrc = [[notification userInfo] objectForKey:@"src"]; + id newTarget = [notification object]; + + NSDictionary *newTargetDict = [NSDictionary dictionaryWithObjectsAndKeys:newTarget,@"target",newPluginSrc,@"src",nil]; + + NSMutableArray *baseURLArray = [invisibleFlashTargetsDict objectForKey:newPluginBaseURL]; + + if (! baseURLArray) { + baseURLArray = [NSMutableArray arrayWithObject:newTargetDict]; + [invisibleFlashTargetsDict setObject:baseURLArray forKey:newPluginBaseURL]; + } else { + [baseURLArray addObject:newTargetDict]; + } + + [self setInvisibleFlashTargets:invisibleFlashTargetsDict]; + + // not sure why, but the following lines causes crashes and unexpected behavior + //[invisibleFlashTargetsDict release]; +} + +- (void)loadInvisibleFlashContentForBaseURL:(NSString *)desiredBaseURL; +{ + NSMutableArray *baseURLTargets = [[self invisibleFlashTargets] objectForKey:desiredBaseURL]; + + NSDictionary *targetDict = nil; + for (targetDict in baseURLTargets) { + id target = [targetDict objectForKey:@"target"]; + [target performSelector:@selector(_convertTypesForContainer) withObject:nil afterDelay:0]; + } +} + +- (void)startTrackingInvisibleFlashTargets:(NSMutableDictionary *)newInvisibleFlashTargets; +{ + // remove any existing menu and add back our own so that we start getting the + // sent actions rather than the released ClickToFlash plugin + NSMenu *mainMenu = [NSApp mainMenu]; + NSMenuItem *clickToFlashMenu = [mainMenu itemWithTitle:@"ClickToFlash"]; + if (clickToFlashMenu) + [mainMenu removeItem:clickToFlashMenu]; + + + if (newInvisibleFlashTargets) + [self setInvisibleFlashTargets:newInvisibleFlashTargets]; + + // the plugin instance that first finds no ClickToFlash menu will be the one + // that handles the loading of *all* invisible flash content, so we only want + // that one to observe + _isKeepingTrackOfInvisibleFlashTargets = YES; + + [[NSNotificationCenter defaultCenter] addObserver: self + selector: @selector( _newInvisibleFlashPluginInitialized: ) + name: sCTFInvisibleContentNotification + object: nil ]; + + _invisibleItemMenuController = [[CTFInvisibleItemMenuController alloc] init]; + [_invisibleItemMenuController setPlugin:self]; + [NSBundle loadNibNamed:@"InvisibleItemMenu" owner:_invisibleItemMenuController]; + + clickToFlashMenu = [_invisibleItemMenuController menu]; + [mainMenu addItem:clickToFlashMenu]; + NSMenu *submenu = [clickToFlashMenu submenu]; + NSMenuItem *loadInvisibleContentMenuItem = [_invisibleItemMenuController loadInvisibleContentMenuItem]; + [submenu addItem:loadInvisibleContentMenuItem]; +} + +- (void)removeSelfFromInvisibleFlashTargetDict +{ + // find and remove ourselves from the dictionary of invisible ClickToFlash + // plugins + + NSArray *targetDictArray = [[self invisibleFlashTargets] objectForKey:[self baseURL]]; + NSDictionary *currentTargetDict = nil; + for (currentTargetDict in targetDictArray) { + if ([currentTargetDict objectForKey:@"target"] == self) { + break; + } + } + + NSMutableDictionary *invisibleTargetsCopy = [[self invisibleFlashTargets] copy]; + [[invisibleTargetsCopy objectForKey:[self baseURL]] removeObject:currentTargetDict]; + [self setInvisibleFlashTargets:invisibleTargetsCopy]; + [invisibleTargetsCopy release]; +} + #pragma mark - #pragma mark Drawing @@ -454,6 +619,8 @@ - (void) _convertTypesForElement:(DOMElement *)element - (void) _convertTypesForContainer { + [self removeSelfFromInvisibleFlashTargetDict]; + DOMElement *newElement = (DOMElement *)[self.container cloneNode:YES]; DOMNodeList *nodeList = nil; @@ -481,5 +648,7 @@ - (void) _convertTypesForContainer @synthesize container = _container; @synthesize host = _host; +@synthesize invisibleFlashTargets; +@synthesize baseURL; @end From 4689fe5d23aa7d530fa556eb46d948b5788b0d7e Mon Sep 17 00:00:00 2001 From: Simone Manganelli Date: Tue, 3 Feb 2009 01:17:32 -0800 Subject: [PATCH 3/6] Fixed leaky script object --- ClickToFlash.xcodeproj/project.pbxproj | 16 ++++++++-------- Plugin/CTFInvisibleItemMenuController.m | 1 + 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/ClickToFlash.xcodeproj/project.pbxproj b/ClickToFlash.xcodeproj/project.pbxproj index 389b6565..89d41e33 100644 --- a/ClickToFlash.xcodeproj/project.pbxproj +++ b/ClickToFlash.xcodeproj/project.pbxproj @@ -47,9 +47,9 @@ 55EB70590E04A8B80016593D /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 55EB70570E04A8B80016593D /* WebKit.framework */; }; 69A26D0C0F302C10006648BC /* NSBezierPath-RoundedRectangle.m in Sources */ = {isa = PBXBuildFile; fileRef = 69A26D0B0F302C10006648BC /* NSBezierPath-RoundedRectangle.m */; }; 79A21C4D0F30B735009424B8 /* CTFWhitelistWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 79A21C490F30B735009424B8 /* CTFWhitelistWindowController.m */; }; - A4BB102B0F383697005D000F /* CTFInvisibleItemMenuController.m in Sources */ = {isa = PBXBuildFile; fileRef = A4BB10280F383697005D000F /* CTFInvisibleItemMenuController.m */; }; A4BB102D0F38369B005D000F /* InvisibleItemMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = A4BB102C0F38369B005D000F /* InvisibleItemMenu.xib */; }; A4BB103D0F383721005D000F /* OSAKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A4BB103C0F383721005D000F /* OSAKit.framework */; }; + A4BB11270F3842C1005D000F /* CTFInvisibleItemMenuController.m in Sources */ = {isa = PBXBuildFile; fileRef = A4BB11240F3842C1005D000F /* CTFInvisibleItemMenuController.m */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -102,12 +102,12 @@ 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 = ""; }; - A4BB10260F383697005D000F /* Safari.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Safari.h; sourceTree = ""; }; A4BB10270F383697005D000F /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/InvisibleItemMenu.xib; sourceTree = ""; }; - A4BB10280F383697005D000F /* CTFInvisibleItemMenuController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CTFInvisibleItemMenuController.m; sourceTree = ""; }; - A4BB10290F383697005D000F /* CTFInvisibleItemMenuController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CTFInvisibleItemMenuController.h; sourceTree = ""; }; A4BB103C0F383721005D000F /* OSAKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OSAKit.framework; path = /System/Library/Frameworks/OSAKit.framework; sourceTree = ""; }; A4BB10E30F38374E005D000F /* ScriptingBridge.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ScriptingBridge.framework; path = /System/Library/Frameworks/ScriptingBridge.framework; sourceTree = ""; }; + A4BB11240F3842C1005D000F /* CTFInvisibleItemMenuController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CTFInvisibleItemMenuController.m; path = Plugin/CTFInvisibleItemMenuController.m; sourceTree = ""; }; + A4BB11250F3842C1005D000F /* CTFInvisibleItemMenuController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CTFInvisibleItemMenuController.h; path = Plugin/CTFInvisibleItemMenuController.h; sourceTree = ""; }; + A4BB11260F3842C1005D000F /* Safari.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Safari.h; path = Plugin/Safari.h; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -173,10 +173,10 @@ 79A21C4A0F30B735009424B8 /* CTFWhitelistWindowController.h */, 79A21C490F30B735009424B8 /* CTFWhitelistWindowController.m */, 072189BC0F30D9C3008C8944 /* WhitelistPanel.xib */, - A4BB10260F383697005D000F /* Safari.h */, - A4BB10290F383697005D000F /* CTFInvisibleItemMenuController.h */, - A4BB10280F383697005D000F /* CTFInvisibleItemMenuController.m */, A4BB102C0F38369B005D000F /* InvisibleItemMenu.xib */, + A4BB11250F3842C1005D000F /* CTFInvisibleItemMenuController.h */, + A4BB11240F3842C1005D000F /* CTFInvisibleItemMenuController.m */, + A4BB11260F3842C1005D000F /* Safari.h */, 69A26D0A0F302C10006648BC /* NSBezierPath-RoundedRectangle.h */, 69A26D0B0F302C10006648BC /* NSBezierPath-RoundedRectangle.m */, ); @@ -321,7 +321,7 @@ 69A26D0C0F302C10006648BC /* NSBezierPath-RoundedRectangle.m in Sources */, 79A21C4D0F30B735009424B8 /* CTFWhitelistWindowController.m in Sources */, 55EB70480E04A8850016593D /* Plugin.m in Sources */, - A4BB102B0F383697005D000F /* CTFInvisibleItemMenuController.m in Sources */, + A4BB11270F3842C1005D000F /* CTFInvisibleItemMenuController.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Plugin/CTFInvisibleItemMenuController.m b/Plugin/CTFInvisibleItemMenuController.m index 1aa4b946..7c05ac80 100644 --- a/Plugin/CTFInvisibleItemMenuController.m +++ b/Plugin/CTFInvisibleItemMenuController.m @@ -43,6 +43,7 @@ - (IBAction)loadInvisibleFlashContent:(id)sender; NSDictionary *errorDict = nil; OSAScript *browserNameScript = [[OSAScript alloc] initWithSource:appleScriptSourceString]; NSAppleEventDescriptor *aeDesc = [browserNameScript executeAndReturnError:&errorDict]; + [browserNameScript release]; [plugin performSelector:@selector(loadInvisibleFlashContentForBaseURL:) withObject:[aeDesc stringValue] afterDelay:0]; } From dd4c10ce56df4a20486eb96519566c2f81bad6c7 Mon Sep 17 00:00:00 2001 From: Troy Gaul Date: Thu, 12 Feb 2009 12:51:00 +0800 Subject: [PATCH 4/6] Tweaked formatting of settings window. Changed title to remove hyphens. Signed-off-by: Jonathan 'Wolf' Rentzsch --- Plugin/English.lproj/WhitelistPanel.xib | 45 +++++++++++++++---------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/Plugin/English.lproj/WhitelistPanel.xib b/Plugin/English.lproj/WhitelistPanel.xib index 71b2da71..768aee34 100755 --- a/Plugin/English.lproj/WhitelistPanel.xib +++ b/Plugin/English.lproj/WhitelistPanel.xib @@ -8,7 +8,7 @@ 353.00 YES - + YES @@ -38,9 +38,9 @@ 31 2 - {{87, 617}, {527, 333}} + {{80, 360}, {527, 343}} -534248448 - Click-to-Flash Settings + Q2xpY2sgdG8gRmxhc2gg4oCUIFNldHRpbmdzA NSPanel {3.40282e+38, 3.40282e+38} @@ -63,7 +63,7 @@ 4352 - {470, 152} + {470, 151} YES @@ -161,7 +161,7 @@ YES - {{1, 17}, {470, 152}} + {{1, 17}, {470, 151}} @@ -171,7 +171,7 @@ 256 - {{471, 17}, {15, 152}} + {{471, 17}, {15, 151}} _doScroller: @@ -204,7 +204,7 @@ - {{20, 51}, {487, 170}} + {{20, 47}, {487, 169}} 18 @@ -218,7 +218,7 @@ 289 - {{345, 19}, {162, 26}} + {{345, 15}, {162, 26}} YES @@ -238,7 +238,7 @@ 292 - {{18, 24}, {283, 17}} + {{18, 20}, {283, 17}} YES @@ -264,7 +264,7 @@ 268 - {{93, 64}, {236, 18}} + {{93, 77}, {236, 18}} YES @@ -295,7 +295,7 @@ 268 - {{26, 65}, {58, 17}} + {{26, 78}, {58, 17}} YES @@ -311,7 +311,7 @@ 268 - {{92, 0}, {285, 58}} + {{93, 2}, {285, 58}} YES 3 @@ -582,7 +582,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA 268 - {{17, 41}, {67, 17}} + {{17, 43}, {67, 17}} YES @@ -596,15 +596,15 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA - {{65, 235}, {397, 102}} + {{65, 232}, {397, 115}} NSView - {527, 333} + {527, 343} - {{0, 0}, {1680, 1028}} + {{0, 0}, {1280, 778}} {420, 216} {3.40282e+38, 3.40282e+38} ClickToFlash_settingsWindow @@ -975,6 +975,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA 102.IBPluginDependency 103.IBPluginDependency 104.IBPluginDependency + 106.IBAttributePlaceholdersKey 106.IBPluginDependency 107.IBPluginDependency 11.IBPluginDependency @@ -1000,9 +1001,9 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilderKit com.apple.InterfaceBuilderKit - {{87, 617}, {527, 333}} + {{47, 390}, {527, 343}} com.apple.InterfaceBuilder.CocoaPlugin - {{87, 617}, {527, 333}} + {{47, 390}, {527, 343}} {196, 240} {{202, 428}, {480, 270}} @@ -1021,6 +1022,14 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + + ToolTip + + ToolTip + + sIFR (Scalable Inman Flash Replacement) replaces text on HTML pages with Flash equivalents to provide better typography. + + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin From aa6e11f6111f2b17dda898c10a00afb54b412391 Mon Sep 17 00:00:00 2001 From: Simone Manganelli Date: Thu, 12 Feb 2009 03:58:20 -0800 Subject: [PATCH 5/6] again added view tracking, invisible flash content loading, auto-load pref item --- ClickToFlash.xcodeproj/project.pbxproj | 5 + Plugin/CTFMenubarMenuController.h | 8 + Plugin/CTFMenubarMenuController.m | 200 +++++++++++++++++++++++- Plugin/English.lproj/MenubarMenu.xib | 45 ++++-- Plugin/English.lproj/WhitelistPanel.xib | 153 ++++++++++++------ Plugin/Plugin.h | 2 + Plugin/Plugin.m | 59 ++++++- 7 files changed, 408 insertions(+), 64 deletions(-) diff --git a/ClickToFlash.xcodeproj/project.pbxproj b/ClickToFlash.xcodeproj/project.pbxproj index b682746b..190b105c 100644 --- a/ClickToFlash.xcodeproj/project.pbxproj +++ b/ClickToFlash.xcodeproj/project.pbxproj @@ -43,6 +43,7 @@ 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 */; }; @@ -85,6 +86,7 @@ 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; }; @@ -103,6 +105,7 @@ files = ( 55EB70580E04A8B80016593D /* Cocoa.framework in Frameworks */, 55EB70590E04A8B80016593D /* WebKit.framework in Frameworks */, + A4501BC80F4439FB00D04D61 /* OSAKit.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -161,6 +164,7 @@ children = ( 55EB70560E04A8B80016593D /* Cocoa.framework */, 55EB70570E04A8B80016593D /* WebKit.framework */, + A4501BC70F4439FB00D04D61 /* OSAKit.framework */, ); name = Frameworks; sourceTree = ""; @@ -437,6 +441,7 @@ GCC_MODEL_TUNING = G5; GCC_PRECOMPILE_PREFIX_HEADER = NO; GCC_PREFIX_HEADER = ""; + GCC_PREPROCESSOR_DEFINITIONS = ""; INFOPLIST_FILE = "Plugin/Info-Plugin.plist"; INSTALL_PATH = "$(HOME)/Library/Bundles"; OTHER_LDFLAGS = ( diff --git a/Plugin/CTFMenubarMenuController.h b/Plugin/CTFMenubarMenuController.h index 6c3df633..b367c2c4 100644 --- a/Plugin/CTFMenubarMenuController.h +++ b/Plugin/CTFMenubarMenuController.h @@ -31,19 +31,27 @@ THE SOFTWARE. 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; } +@property (retain) NSMutableDictionary *flashViews; + + (CTFMenubarMenuController*) sharedController; - (void) loadFlashForWindow: (NSWindow*) window; - (IBAction) loadAllFlash: (id) sender; - (IBAction) loadKeyWindowFlash: (id) sender; +- (IBAction) loadKeyWindowInvisibleFlash: (id) sender; - (IBAction) showSettingsWindow: (id) sender; @end diff --git a/Plugin/CTFMenubarMenuController.m b/Plugin/CTFMenubarMenuController.m index 7e88402a..c9d015cf 100644 --- a/Plugin/CTFMenubarMenuController.m +++ b/Plugin/CTFMenubarMenuController.m @@ -25,12 +25,17 @@ of this software and associated documentation files (the "Software"), to deal */ #import "CTFMenubarMenuController.h" - #import "CTFWhitelistWindowController.h" +#import +#import NSString* kCTFLoadAllFlashViews = @"CTFLoadAllFlashViews"; NSString* kCTFLoadFlashViewsForWindow = @"CTFLoadFlashViewsForWindow"; +NSString* kCTFLoadInvisibleFlashViewsForWindow = @"CTFLoadInvisibleFlashViewsForWindow"; +NSString *sCTFNewViewNotification = @"CTFNewFlashView"; +NSString *sCTFDestroyedViewNotification = @"CTFDestroyedFlashView"; +NSUInteger maxInvisibleDimension = 50; static CTFMenubarMenuController* sSingleton = nil; @@ -127,6 +132,17 @@ - (id) init NSLog( @"ClickToFlash: Could not load menubar menu nib" ); } + 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; } @@ -177,6 +193,172 @@ + (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 +{ + 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]; + } +} + +- (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; +{ + NSLog(@"%@",[self flashViews]); + return ([[[self flashViews] allKeys] count] >= 1); +} + + +- (BOOL) _flashViewExistsForKeyWindow; +{ + 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); +} + +- (BOOL) _invisibleFlashViewExistsForKeyWindow; +{ + BOOL returnValue = NO; + NSString *baseURL = [self _baseURLOfKeyWindow]; + + NSMutableArray *baseURLArray = [[self flashViews] objectForKey:baseURL]; + + 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; + break; + } + } + } + + return returnValue; +} + +- (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]; + } + + return returnValue; +} + #pragma mark - #pragma mark Actions @@ -188,6 +370,13 @@ - (void) loadFlashForWindow: (NSWindow*) window } +- (void) loadInvisibleFlashForWindow: (NSWindow*) window +{ + [ [ NSNotificationCenter defaultCenter ] postNotificationName: kCTFLoadInvisibleFlashViewsForWindow + object: window ]; +} + + - (IBAction) loadAllFlash: (id) sender { [ [ NSNotificationCenter defaultCenter ] postNotificationName: kCTFLoadAllFlashViews @@ -203,6 +392,14 @@ - (IBAction) loadKeyWindowFlash: (id) sender } +- (IBAction) loadKeyWindowInvisibleFlash: (id) sender +{ + NSWindow* window = [ NSApp keyWindow ]; + if( window ) + [ self loadInvisibleFlashForWindow: window ]; +} + + - (IBAction) showSettingsWindow: (id) sender { if( _whitelistWindowController == nil ) @@ -211,5 +408,6 @@ - (IBAction) showSettingsWindow: (id) sender [ _whitelistWindowController showWindow: sender ]; } +@synthesize flashViews = _flashViews; @end diff --git a/Plugin/English.lproj/MenubarMenu.xib b/Plugin/English.lproj/MenubarMenu.xib index 6c08b159..6b774d70 100755 --- a/Plugin/English.lproj/MenubarMenu.xib +++ b/Plugin/English.lproj/MenubarMenu.xib @@ -1,29 +1,20 @@ - + 1050 9G55 - 677 + 667 949.43 353.00 YES - + YES com.apple.InterfaceBuilderKit com.apple.InterfaceBuilder.CocoaPlugin - - YES - - YES - - - YES - - YES @@ -54,6 +45,14 @@ NSMenuMixedState + + + Load Invisible Flash for Frontmost Page + + 2147483647 + + + Load Flash for All Pages @@ -118,6 +117,14 @@ 24 + + + loadKeyWindowInvisibleFlash: + + + + 26 + @@ -157,6 +164,7 @@ + @@ -180,6 +188,11 @@ + + 25 + + + @@ -194,6 +207,7 @@ 10.IBPluginDependency 16.IBPluginDependency 22.IBPluginDependency + 25.IBPluginDependency 3.IBPluginDependency @@ -201,7 +215,8 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilderKit com.apple.InterfaceBuilderKit - {{144, 683}, {297, 73}} + {{131, 442}, {358, 93}} + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -229,7 +244,7 @@ - 24 + 26 @@ -243,6 +258,7 @@ YES loadAllFlash: loadKeyWindowFlash: + loadKeyWindowInvisibleFlash: showSettingsWindow: @@ -250,6 +266,7 @@ id id id + id diff --git a/Plugin/English.lproj/WhitelistPanel.xib b/Plugin/English.lproj/WhitelistPanel.xib index 768aee34..178240a4 100755 --- a/Plugin/English.lproj/WhitelistPanel.xib +++ b/Plugin/English.lproj/WhitelistPanel.xib @@ -1,9 +1,9 @@ - + 1050 9G55 - 677 + 667 949.43 353.00 @@ -15,15 +15,6 @@ com.apple.InterfaceBuilderKit com.apple.InterfaceBuilder.CocoaPlugin - - YES - - YES - - - YES - - YES @@ -38,7 +29,7 @@ 31 2 - {{80, 360}, {527, 343}} + {{80, 330}, {527, 373}} -534248448 Q2xpY2sgdG8gRmxhc2gg4oCUIFNldHRpbmdzA NSPanel @@ -204,7 +195,7 @@ - {{20, 47}, {487, 169}} + {{20, 51}, {487, 169}} 18 @@ -218,7 +209,7 @@ 289 - {{345, 15}, {162, 26}} + {{345, 19}, {162, 26}} YES @@ -238,7 +229,7 @@ 292 - {{18, 20}, {283, 17}} + {{18, 24}, {283, 17}} YES @@ -264,7 +255,7 @@ 268 - {{93, 77}, {236, 18}} + {{93, 95}, {236, 18}} YES @@ -279,11 +270,11 @@ 1211912703 130 - + NSImage NSSwitch - + NSSwitch @@ -292,10 +283,32 @@ 25 + + + 268 + {{93, 75}, {236, 18}} + + YES + + -2080244224 + 0 + Automatically load invisible views + + + 1211912703 + 130 + + + + + 200 + 25 + + 268 - {{26, 78}, {58, 17}} + {{26, 96}, {58, 17}} YES @@ -311,7 +324,7 @@ 268 - {{93, 2}, {285, 58}} + {{93, 0}, {285, 58}} YES 3 @@ -582,7 +595,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA 268 - {{17, 43}, {67, 17}} + {{17, 41}, {67, 17}} YES @@ -596,12 +609,12 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA - {{65, 232}, {397, 115}} + {{65, 240}, {397, 133}} NSView - {527, 343} + {527, 373} {{0, 0}, {1280, 778}} @@ -726,6 +739,22 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA 112 + + + value: values.ClickToFlash_autoLoadInvisibleViews + + + + + + value: values.ClickToFlash_autoLoadInvisibleViews + value + values.ClickToFlash_autoLoadInvisibleViews + 2 + + + 116 + @@ -770,10 +799,10 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA YES + - - + @@ -871,10 +900,11 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA YES - + + @@ -906,51 +936,65 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA + + 106 + + + YES + + + + + + 107 + + + 101 YES - - - + + + - 102 - + 105 + - 103 - + 104 + - 104 - + 103 + - 105 - + 102 + - 106 - + 113 + YES - + - 107 - - + 114 + + @@ -979,6 +1023,9 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA 106.IBPluginDependency 107.IBPluginDependency 11.IBPluginDependency + 113.IBAttributePlaceholdersKey + 113.IBPluginDependency + 114.IBPluginDependency 12.IBPluginDependency 13.IBPluginDependency 14.IBPluginDependency @@ -1001,13 +1048,13 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilderKit com.apple.InterfaceBuilderKit - {{47, 390}, {527, 343}} + {{47, 360}, {527, 373}} com.apple.InterfaceBuilder.CocoaPlugin - {{47, 390}, {527, 343}} - + {{47, 360}, {527, 373}} + {196, 240} {{202, 428}, {480, 270}} - + {420, 200} com.apple.InterfaceBuilder.CocoaPlugin @@ -1033,6 +1080,16 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + + ToolTip + + ToolTip + + Loads very small Flash views automatically. + + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -1078,7 +1135,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA - 112 + 116 diff --git a/Plugin/Plugin.h b/Plugin/Plugin.h index 45ddefd3..ff166341 100644 --- a/Plugin/Plugin.h +++ b/Plugin/Plugin.h @@ -41,6 +41,7 @@ THE SOFTWARE. BOOL _fromYouTube; WebView *_webView; NSUInteger _sifrVersion; + NSString *_baseURL; } + (NSView *)plugInViewWithArguments:(NSDictionary *)arguments; @@ -51,6 +52,7 @@ THE SOFTWARE. @property (nonatomic, retain) NSString *host; @property (nonatomic, retain) WebView *webView; @property (readonly, nonatomic, retain) NSString *addToWhiteListMenuTitle; +@property (retain) NSString *baseURL; - (IBAction)addToWhitelist:(id)sender; - (IBAction)removeFromWhitelist:(id)sender; diff --git a/Plugin/Plugin.m b/Plugin/Plugin.m index e764ba18..7bc17d25 100644 --- a/Plugin/Plugin.m +++ b/Plugin/Plugin.m @@ -39,6 +39,7 @@ of this software and associated documentation files (the "Software"), to deal NSString *sHostWhitelistDefaultsKey = @"ClickToFlash_whitelist"; static NSString *sAllowSifrDefaultsKey = @"ClickToFlash_allowSifr"; static NSString *sUseYouTubeH264DefaultsKey = @"ClickToFlash_useYouTubeH264"; +static NSString *sAutoLoadInvisibleFlashViewsKey = @"ClickToFlash_autoLoadInvisibleViews"; // NSNotification names NSString *sCTFWhitelistAdditionMade = @"CTFWhitelistAdditionMade"; @@ -138,6 +139,7 @@ - (id) initWithArguments:(NSDictionary *)arguments // Get URL and test against the whitelist NSURL *base = [arguments objectForKey:WebPlugInBaseURLKey]; + [self setBaseURL:[base absoluteString]]; if (base) { self.host = [base host]; @@ -145,6 +147,7 @@ - (id) initWithArguments:(NSDictionary *)arguments loadFromWhiteList = true; } } + // Check for sIFR - http://www.mikeindustries.com/sifr/ @@ -208,8 +211,9 @@ - (id) initWithArguments:(NSDictionary *)arguments // Set tooltip NSDictionary *attributes = [arguments objectForKey:WebPlugInAttributesKey]; + NSString *src = nil; if (attributes != nil) { - NSString *src = [attributes objectForKey:@"src"]; + src = [attributes objectForKey:@"src"]; if (src) [self setToolTip:src]; else { @@ -218,6 +222,25 @@ - (id) initWithArguments:(NSDictionary *)arguments [self setToolTip:src]; } } + + // 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) ) ) { + // 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] + ]; + } // Observe various things: @@ -238,6 +261,11 @@ - (id) initWithArguments:(NSDictionary *)arguments selector: @selector( _loadContentForWindow: ) name: kCTFLoadFlashViewsForWindow object: nil ]; + + [center addObserver: self + selector: @selector( _loadInvisibleContentForWindow: ) + name: kCTFLoadInvisibleFlashViewsForWindow + object: nil ]; } return self; @@ -246,6 +274,13 @@ - (id) initWithArguments:(NSDictionary *)arguments - (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"] + ]; self.container = nil; self.host = nil; @@ -493,6 +528,19 @@ - (void) _loadContentForWindow: (NSNotification*) notification [ self _convertTypesForContainer ]; } +- (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 ]; + } + } +} + #pragma mark - #pragma mark Drawing @@ -740,6 +788,14 @@ - (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"] + ]; + + if ([self _useH264Version]) [self _convertToMP4Container]; else @@ -833,5 +889,6 @@ - (void) _disableSIFR @synthesize webView = _webView; @synthesize container = _container; @synthesize host = _host; +@synthesize baseURL = _baseURL; @end From cc7253776dc17914437d109b68cca2577b364336 Mon Sep 17 00:00:00 2001 From: Simone Manganelli Date: Thu, 12 Feb 2009 04:04:35 -0800 Subject: [PATCH 6/6] Removed unnecessary files --- Plugin/CTFInvisibleItemMenuController.h | 26 ----------- Plugin/CTFInvisibleItemMenuController.m | 61 ------------------------- 2 files changed, 87 deletions(-) delete mode 100644 Plugin/CTFInvisibleItemMenuController.h delete mode 100644 Plugin/CTFInvisibleItemMenuController.m diff --git a/Plugin/CTFInvisibleItemMenuController.h b/Plugin/CTFInvisibleItemMenuController.h deleted file mode 100644 index c5f68bf8..00000000 --- a/Plugin/CTFInvisibleItemMenuController.h +++ /dev/null @@ -1,26 +0,0 @@ -// -// CTFInvisibleItemMenuController.h -// ClickToFlash -// -// Created by Simone Manganelli on 2009-02-02. -// Copyright 2009 __MyCompanyName__. All rights reserved. -// - -#import -@class CTFClickToFlashPlugin; - -@interface CTFInvisibleItemMenuController : NSObject { - IBOutlet NSMenuItem *theMenu; - IBOutlet NSMenuItem *loadInvisibleContentMenuItem; - id plugin; - NSMutableArray *targets; -} - -@property (retain) CTFClickToFlashPlugin *plugin; -@property (retain) NSMutableArray *targets; - -- (IBAction)loadInvisibleFlashContent:(id)sender; -- (NSMenuItem *)menu; -- (NSMenuItem *)loadInvisibleContentMenuItem; - -@end diff --git a/Plugin/CTFInvisibleItemMenuController.m b/Plugin/CTFInvisibleItemMenuController.m deleted file mode 100644 index 7c05ac80..00000000 --- a/Plugin/CTFInvisibleItemMenuController.m +++ /dev/null @@ -1,61 +0,0 @@ -// -// CTFInvisibleItemMenuController.m -// ClickToFlash -// -// Created by Simone Manganelli on 2009-02-02. -// Copyright 2009 __MyCompanyName__. All rights reserved. -// - -#import "CTFInvisibleItemMenuController.h" -#import "Plugin.h" -#import "Safari.h" -#include -#include -#import - -@implementation CTFInvisibleItemMenuController - -@synthesize plugin; -@synthesize targets; - -- (IBAction)loadInvisibleFlashContent:(id)sender; -{ - // [[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()]; - - 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]; - - [plugin performSelector:@selector(loadInvisibleFlashContentForBaseURL:) withObject:[aeDesc stringValue] afterDelay:0]; -} - -- (NSMenuItem *)menu; -{ - return theMenu; -} - -- (NSMenuItem *)loadInvisibleContentMenuItem; -{ - return loadInvisibleContentMenuItem; -} - -@end