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/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/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/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 f6dd7f6e..75d075f4 100644 --- a/Plugin/Plugin.m +++ b/Plugin/Plugin.m @@ -39,6 +39,7 @@ of this software and associated documentation files (the "Software"), to deal static NSString *sHostSiteInfoDefaultsKey = @"ClickToFlash_siteInfo"; static NSString *sAllowSifrDefaultsKey = @"ClickToFlash_allowSifr"; static NSString *sUseYouTubeH264DefaultsKey = @"ClickToFlash_useYouTubeH264"; +static NSString *sAutoLoadInvisibleFlashViewsKey = @"ClickToFlash_autoLoadInvisibleViews"; // NSNotification names static NSString *sCTFWhitelistAdditionMade = @"CTFWhitelistAdditionMade"; @@ -189,6 +190,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]; @@ -196,6 +198,7 @@ - (id) initWithArguments:(NSDictionary *)arguments loadFromWhiteList = true; } } + // Check for sIFR - http://www.mikeindustries.com/sifr/ @@ -259,8 +262,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 { @@ -269,6 +273,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: @@ -289,6 +312,11 @@ - (id) initWithArguments:(NSDictionary *)arguments selector: @selector( _loadContentForWindow: ) name: kCTFLoadFlashViewsForWindow object: nil ]; + + [center addObserver: self + selector: @selector( _loadInvisibleContentForWindow: ) + name: kCTFLoadInvisibleFlashViewsForWindow + object: nil ]; } return self; @@ -297,6 +325,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; @@ -548,6 +583,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 @@ -793,6 +841,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 @@ -886,5 +942,6 @@ - (void) _disableSIFR @synthesize webView = _webView; @synthesize container = _container; @synthesize host = _host; +@synthesize baseURL = _baseURL; @end 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 +