From 32aacf1279ccbabb53a41932c65d647475c1fdd4 Mon Sep 17 00:00:00 2001 From: Simone Manganelli Date: Wed, 15 Jul 2009 14:03:05 +0800 Subject: [PATCH] whitelisted YouTube views will wait up to 3 seconds before automatically converting to wait for the H.264 video variant checks Signed-off-by: Jonathan 'Wolf' Rentzsch --- Plugin/Plugin.h | 1 + Plugin/Plugin.m | 30 ++++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Plugin/Plugin.h b/Plugin/Plugin.h index 849df271..2dbae5a3 100755 --- a/Plugin/Plugin.h +++ b/Plugin/Plugin.h @@ -54,6 +54,7 @@ THE SOFTWARE. NSString *_launchedAppBundleIdentifier; BOOL _contextMenuIsVisible; + NSTimer *_delayingTimer; } + (NSView *)plugInViewWithArguments:(NSDictionary *)arguments; diff --git a/Plugin/Plugin.m b/Plugin/Plugin.m index f577db6d..20ded357 100755 --- a/Plugin/Plugin.m +++ b/Plugin/Plugin.m @@ -115,6 +115,7 @@ - (id) initWithArguments:(NSDictionary *)arguments _hasHDH264Version = NO; _contextMenuIsVisible = NO; _embeddedYouTubeView = NO; + _delayingTimer = nil; defaultWhitelist = [NSArray arrayWithObjects: @"com.apple.frontrow", @"com.apple.dashboard.client", @"com.apple.ScreenSaver.Engine", @@ -275,8 +276,8 @@ - (id) initWithArguments:(NSDictionary *)arguments return self; } - BOOL loadFromWhiteList = [self _isHostWhitelisted]; + BOOL loadFromWhiteList = [self _isHostWhitelisted]; // Check the SWF src URL itself against the whitelist (allows embbeded videos from whitelisted sites to play, e.g. YouTube) @@ -297,7 +298,26 @@ - (id) initWithArguments:(NSDictionary *)arguments if(loadFromWhiteList && ![self _isOptionPressed]) { _isLoadingFromWhitelist = YES; - [self _convertTypesForContainer]; + + if (_fromYouTube) { + // we do this because checking for H.264 variants is handled + // on another thread, so the results of that check may not have + // been returned yet; if the user has this site on a whitelist + // and the results haven't been returned, then the *Flash* will + // load (ewwwwwww!) instead of the H.264, even if the user's + // preferences are for the H.264 + + // the _checkForH264VideoVariants method will manually fire + // this timer if it finishes before the 3 seconds are up + _delayingTimer = [NSTimer scheduledTimerWithTimeInterval:3 + target:self + selector:@selector(_convertTypesForContainer) + userInfo:nil + repeats:NO]; + } else { + [self _convertTypesForContainer]; + } + return self; } @@ -1131,6 +1151,12 @@ - (void) _checkForH264VideoVariants waitUntilDone:NO]; } + // without doing this on the main thread, it causes the DOM conversion + // on a secondary thread which WebKit does not like and will cause a crash + if (_delayingTimer) [_delayingTimer performSelectorOnMainThread:@selector(fire) + withObject:nil + waitUntilDone:NO]; + [pool drain]; }