From ef9be0b8697a2c88f1eccc5be8502fec1511f07a Mon Sep 17 00:00:00 2001 From: Jeff Johnson Date: Wed, 9 Sep 2009 17:08:27 -0500 Subject: [PATCH] Possible fix for http://rentzsch.lighthouseapp.com/projects/24342/tickets/261-crash-in-15b5-under-106 --- Plugin/Plugin.m | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/Plugin/Plugin.m b/Plugin/Plugin.m index 0d9901d9..ed293562 100755 --- a/Plugin/Plugin.m +++ b/Plugin/Plugin.m @@ -79,6 +79,7 @@ - (void) _loadContentForWindow: (NSNotification*) notification; - (NSDictionary*) _flashVarDictionary: (NSString*) flashvarString; - (NSDictionary*) _flashVarDictionaryFromYouTubePageHTML: (NSString*) youTubePageHTML; +- (void)_didRetrieveEmbeddedPlayerFlashVars:(NSDictionary *)flashVars; - (void)_getEmbeddedPlayerFlashVarsAndCheckForVariantsWithVideoId:(NSString *)videoId; - (NSString*) flashvarWithName: (NSString*) argName; - (void) _checkForH264VideoVariants; @@ -1160,7 +1161,7 @@ - (NSDictionary*) _flashVarDictionaryFromYouTubePageHTML: (NSString*) youTubePag - (NSString*) flashvarWithName: (NSString*) argName { - return [ _flashVars objectForKey: argName ]; + return [[[ _flashVars objectForKey: argName ] retain] autorelease]; } /*- (NSString*) _videoId @@ -1468,6 +1469,18 @@ - (IBAction)openFullscreenInQTPlayer:(id)sender; [openInQTPlayerScript release]; } +- (void)_didRetrieveEmbeddedPlayerFlashVars:(NSDictionary *)flashVars +{ + if (flashVars) + { + _flashVars = [flashVars retain]; + NSString *videoId = [self flashvarWithName:@"video_id"]; + [self setVideoId:videoId]; + } + + [self _checkForH264VideoVariants]; +} + - (void)_retrieveEmbeddedPlayerFlashVarsAndCheckForVariantsWithVideoId:(NSString *)videoId { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; @@ -1478,13 +1491,13 @@ - (void)_retrieveEmbeddedPlayerFlashVarsAndCheckForVariantsWithVideoId:(NSString NSString *pageSourceString = [NSString stringWithContentsOfURL:YouTubePageURL usedEncoding:nil error:&pageSourceError]; - if (! pageSourceError) { - _flashVars = [[self _flashVarDictionaryFromYouTubePageHTML:pageSourceString] retain]; - _videoId = [self flashvarWithName:@"video_id"]; + NSDictionary *flashVars = nil; + if (pageSourceString && !pageSourceError) { + flashVars = [self _flashVarDictionaryFromYouTubePageHTML:pageSourceString]; } - [self performSelectorOnMainThread:@selector(_checkForH264VideoVariants) - withObject:nil + [self performSelectorOnMainThread:@selector(_didRetrieveEmbeddedPlayerFlashVars:) + withObject:flashVars waitUntilDone:NO]; [pool drain]; @@ -1673,7 +1686,7 @@ - (void)setSrc:(NSString *)newValue - (NSString *)videoId { - return _videoId; + return [[_videoId retain] autorelease]; } - (void)setVideoId:(NSString *)newValue {