Skip to content

Commit

Permalink
whitelisted YouTube views will wait up to 3 seconds before automatica…
Browse files Browse the repository at this point in the history
…lly converting to wait for the H.264 video variant checks

Signed-off-by: Jonathan 'Wolf' Rentzsch <jwr.git@redshed.net>
  • Loading branch information
Simone Manganelli authored and rentzsch committed Jul 15, 2009
1 parent f6c5948 commit 32aacf1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions Plugin/Plugin.h
Expand Up @@ -54,6 +54,7 @@ THE SOFTWARE.
NSString *_launchedAppBundleIdentifier;

BOOL _contextMenuIsVisible;
NSTimer *_delayingTimer;
}

+ (NSView *)plugInViewWithArguments:(NSDictionary *)arguments;
Expand Down
30 changes: 28 additions & 2 deletions Plugin/Plugin.m
Expand Up @@ -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",
Expand Down Expand Up @@ -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)

Expand All @@ -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;
}

Expand Down Expand Up @@ -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];
}

Expand Down

0 comments on commit 32aacf1

Please sign in to comment.