diff --git a/Plugin/CTFKiller.m b/Plugin/CTFKiller.m index a577c189..9a8a0689 100644 --- a/Plugin/CTFKiller.m +++ b/Plugin/CTFKiller.m @@ -37,15 +37,15 @@ @implementation CTFKiller // Class method returns an instantiated CTFKiller class for the URL/data/plugin passed to it. This is the call to use. -+ (CTFKiller*) killerForURL: (NSURL*) theURL src: (NSString*) theSrc attributes: (NSDictionary*) attributes forPlugin:(CTFClickToFlashPlugin*) thePlugin { ++ (CTFKiller*) killerForURL: (NSURL*) theURL src: (NSString*) theSrc attributes: (NSDictionary*) theAttributes forPlugin:(CTFClickToFlashPlugin*) thePlugin { CTFKiller * theKiller = nil; NSArray * killerArray = [NSArray arrayWithObjects: NSClassFromString(@"CTFKillerYouTube"), NSClassFromString(@"CTFKillerVimeo"), NSClassFromString(@"CTFKillerSIFR"),nil]; NSEnumerator * myEnum = [killerArray objectEnumerator]; Class killerClass; while ((killerClass = [myEnum nextObject])) { - if ([killerClass canHandleFlashAtURL: theURL src: theSrc attributes: attributes forPlugin: thePlugin]) { - theKiller = [[(CTFKiller*)[killerClass alloc] initWithURL:theURL src: theSrc attributes: attributes forPlugin: thePlugin] autorelease]; + if ([killerClass canHandleFlashAtURL: theURL src: theSrc attributes: theAttributes forPlugin: thePlugin]) { + theKiller = [[(CTFKiller*)[killerClass alloc] initWithURL:theURL src: theSrc attributes: theAttributes forPlugin: thePlugin] autorelease]; break; } } @@ -54,6 +54,7 @@ + (CTFKiller*) killerForURL: (NSURL*) theURL src: (NSString*) theSrc attributes: } + // Initialiser method doing the basic setup. There should be no need to use this. The +killerForULR:src:attributes:forPlugin class method should handle everything. - (id) initWithURL: (NSURL*) theURL src:(NSString*) theSrc attributes: (NSDictionary*) theAttributes forPlugin:(CTFClickToFlashPlugin*) thePlugin { self = [super init]; @@ -90,7 +91,7 @@ - (void) dealloc { #pragma mark Subclass overrides // Return whether this class can handle the Flash for the given URL and other data. -+ (BOOL) canHandleFlashAtURL: (NSURL*) theURL src: (NSString*) theSrc attributes: (NSDictionary*) attributes forPlugin:(CTFClickToFlashPlugin*) thePlugin { ++ (BOOL) canHandleFlashAtURL: (NSURL*) theURL src: (NSString*) theSrc attributes: (NSDictionary*) theAttributes forPlugin:(CTFClickToFlashPlugin*) thePlugin { return NO; } diff --git a/Plugin/CTFKillerVideo.h b/Plugin/CTFKillerVideo.h index 0e64d65e..bc7c5d30 100644 --- a/Plugin/CTFKillerVideo.h +++ b/Plugin/CTFKillerVideo.h @@ -28,11 +28,6 @@ #import #import "CTFKiller.h" -static NSString *sUseYouTubeH264DefaultsKey = @"useYouTubeH264"; -static NSString *sUseYouTubeHDH264DefaultsKey = @"useYouTubeHDH264"; -static NSString *sYouTubeAutoPlay = @"enableYouTubeAutoPlay"; - - @class DOMElement; enum CTFKVLookupStatus { @@ -90,6 +85,10 @@ enum CTFKVLookupStatus { + +// Helper ++ (BOOL) isActive; + // Actions - (IBAction) loadVideo:(id)sender; - (IBAction) loadVideoSD:(id)sender; diff --git a/Plugin/CTFKillerVideo.m b/Plugin/CTFKillerVideo.m index c45a6e31..cc31a75e 100644 --- a/Plugin/CTFKillerVideo.m +++ b/Plugin/CTFKillerVideo.m @@ -33,6 +33,9 @@ of this software and associated documentation files (the "Software"), to deal static NSString * divCSS = @"margin:auto;padding:0px;border:0px none;text-align:center;display:block;float:none;"; static NSString * sDisableVideoElement = @"disableVideoElement"; +static NSString * sUseYouTubeH264DefaultsKey = @"useYouTubeH264"; +static NSString * sUseYouTubeHDH264DefaultsKey = @"useYouTubeHDH264"; +static NSString * sYouTubeAutoPlay = @"enableYouTubeAutoPlay"; @implementation CTFKillerVideo @@ -126,6 +129,12 @@ - (NSString *) cleanURLString: (NSString*) URLString { } +// Helper method used by subclasses to determine whether we want to handle video without Flash. ++ (BOOL) isActive { + BOOL result = [[CTFUserDefaultsController standardUserDefaults] boolForKey: sUseYouTubeH264DefaultsKey]; + return result; +} + @@ -379,7 +388,7 @@ - (void) _convertElementForMP4: (DOMElement*) element atURL: (NSString*) URLStri [ element setAttribute: @"src" value: URLString ]; [ element setAttribute: @"type" value: @"video/mp4" ]; [ element setAttribute: @"scale" value: @"aspect" ]; - if (autoPlay) { + if ([self autoPlay]) { [ element setAttribute: @"autoplay" value: @"true" ]; } else { [ element setAttribute: @"autoplay" value: @"false" ]; @@ -395,7 +404,7 @@ - (void) _convertElementForVideoElement: (DOMElement*) element atURL: (NSString* { [ element setAttribute: @"src" value: URLString ]; [ element setAttribute: @"autobuffer" value:@"autobuffer"]; - if (autoPlay) { + if ([self autoPlay]) { [ element setAttribute: @"autoplay" value:@"autoplay" ]; } else { if ( [element hasAttribute:@"autoplay"] ) diff --git a/Plugin/CTFKillerVimeo.m b/Plugin/CTFKillerVimeo.m index facbc5c9..dd9e80f6 100644 --- a/Plugin/CTFKillerVimeo.m +++ b/Plugin/CTFKillerVimeo.m @@ -36,14 +36,16 @@ @implementation CTFKillerVimeo #pragma mark CTFKiller subclass overrides -+ (BOOL) canHandleFlashAtURL: (NSURL*) theURL src: (NSString*) theSrc attributes: (NSDictionary*) attributes forPlugin:(CTFClickToFlashPlugin*) thePlugin { ++ (BOOL) canHandleFlashAtURL: (NSURL*) theURL src: (NSString*) theSrc attributes: (NSDictionary*) theAttributes forPlugin:(CTFClickToFlashPlugin*) thePlugin { BOOL result = NO; - result = result || ([theSrc rangeOfString:@"/moogaloop" options:NSAnchoredSearch].location != NSNotFound); - - NSURL * srcURL = [NSURL URLWithString: theSrc]; - if (srcURL != nil && [srcURL host] != nil) { - result = result || ([[srcURL host] rangeOfString:@"vimeo.com" options:NSAnchoredSearch|NSBackwardsSearch].location != NSNotFound); + if ([CTFKillerVideo isActive]) { + result = ([theSrc rangeOfString:@"/moogaloop" options:NSAnchoredSearch].location != NSNotFound); + + NSURL * srcURL = [NSURL URLWithString: theSrc]; + if (srcURL != nil && [srcURL host] != nil) { + result = result || ([[srcURL host] rangeOfString:@"vimeo.com" options:NSAnchoredSearch|NSBackwardsSearch].location != NSNotFound); + } } return result; @@ -80,6 +82,7 @@ - (void) setup { } + - (void) dealloc { [self setClipID: nil]; [self setClipSignature: nil]; diff --git a/Plugin/CTFKillerYouTube.m b/Plugin/CTFKillerYouTube.m index 428cddb2..05eb4a3b 100644 --- a/Plugin/CTFKillerYouTube.m +++ b/Plugin/CTFKillerYouTube.m @@ -35,29 +35,31 @@ @implementation CTFKillerYouTube #pragma mark CTFKiller subclassing overrides -+ (BOOL) canHandleFlashAtURL: (NSURL*) theURL src: (NSString*) theSrc attributes: (NSDictionary*) attributes forPlugin:(CTFClickToFlashPlugin*) thePlugin { ++ (BOOL) canHandleFlashAtURL: (NSURL*) theURL src: (NSString*) theSrc attributes: (NSDictionary*) theAttributes forPlugin:(CTFClickToFlashPlugin*) thePlugin { BOOL result = NO; - - if (theSrc != nil) { - NSURL * srcURL = [NSURL URLWithString: theSrc]; - NSString * host = [srcURL host]; - if (host != nil ) { - result = result - || ( [host rangeOfString: @"youtube.com" options: NSAnchoredSearch|NSBackwardsSearch].location != NSNotFound ) - || ( [host rangeOfString: @"youtube-nocookie.com" options: NSAnchoredSearch|NSBackwardsSearch].location != NSNotFound ) - || ( [host rangeOfString: @"ytimg.com" options: NSAnchoredSearch|NSBackwardsSearch].location != NSNotFound ); - } - } - if (!result) { - NSString* fV = [attributes objectForKey: @"flashvars" ]; - if (fV != nil) { - NSDictionary * flashVars = [CTFClickToFlashPlugin flashVarDictionary:fV]; - NSString * URLString = [flashVars objectForKey:@"rv.0.url"]; - if (URLString != nil) { - result = result || ([URLString rangeOfString: @"youtube.com"].location != NSNotFound ) - || ([URLString rangeOfString: @"youtube-nocookie.com"].location != NSNotFound ); - } + if ([CTFKillerVideo isActive]) { + if (theSrc != nil) { + NSURL * srcURL = [NSURL URLWithString: theSrc]; + NSString * host = [srcURL host]; + if (host != nil ) { + result = result + || ( [host rangeOfString: @"youtube.com" options: NSAnchoredSearch|NSBackwardsSearch].location != NSNotFound ) + || ( [host rangeOfString: @"youtube-nocookie.com" options: NSAnchoredSearch|NSBackwardsSearch].location != NSNotFound ) + || ( [host rangeOfString: @"ytimg.com" options: NSAnchoredSearch|NSBackwardsSearch].location != NSNotFound ); + } + } + + if (!result) { + NSString* fV = [theAttributes objectForKey: @"flashvars" ]; + if (fV != nil) { + NSDictionary * flashVars = [CTFClickToFlashPlugin flashVarDictionary:fV]; + NSString * URLString = [flashVars objectForKey:@"rv.0.url"]; + if (URLString != nil) { + result = result || ([URLString rangeOfString: @"youtube.com"].location != NSNotFound ) + || ([URLString rangeOfString: @"youtube-nocookie.com"].location != NSNotFound ); + } + } } }