Skip to content

Commit 32aacf1

Browse files
Simone Manganellirentzsch
Simone Manganelli
authored andcommitted
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 <[email protected]>
1 parent f6c5948 commit 32aacf1

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

Plugin/Plugin.h

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ THE SOFTWARE.
5454
NSString *_launchedAppBundleIdentifier;
5555

5656
BOOL _contextMenuIsVisible;
57+
NSTimer *_delayingTimer;
5758
}
5859

5960
+ (NSView *)plugInViewWithArguments:(NSDictionary *)arguments;

Plugin/Plugin.m

+28-2
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ - (id) initWithArguments:(NSDictionary *)arguments
115115
_hasHDH264Version = NO;
116116
_contextMenuIsVisible = NO;
117117
_embeddedYouTubeView = NO;
118+
_delayingTimer = nil;
118119
defaultWhitelist = [NSArray arrayWithObjects: @"com.apple.frontrow",
119120
@"com.apple.dashboard.client",
120121
@"com.apple.ScreenSaver.Engine",
@@ -275,8 +276,8 @@ - (id) initWithArguments:(NSDictionary *)arguments
275276
return self;
276277
}
277278

278-
BOOL loadFromWhiteList = [self _isHostWhitelisted];
279279

280+
BOOL loadFromWhiteList = [self _isHostWhitelisted];
280281

281282
// Check the SWF src URL itself against the whitelist (allows embbeded videos from whitelisted sites to play, e.g. YouTube)
282283

@@ -297,7 +298,26 @@ - (id) initWithArguments:(NSDictionary *)arguments
297298

298299
if(loadFromWhiteList && ![self _isOptionPressed]) {
299300
_isLoadingFromWhitelist = YES;
300-
[self _convertTypesForContainer];
301+
302+
if (_fromYouTube) {
303+
// we do this because checking for H.264 variants is handled
304+
// on another thread, so the results of that check may not have
305+
// been returned yet; if the user has this site on a whitelist
306+
// and the results haven't been returned, then the *Flash* will
307+
// load (ewwwwwww!) instead of the H.264, even if the user's
308+
// preferences are for the H.264
309+
310+
// the _checkForH264VideoVariants method will manually fire
311+
// this timer if it finishes before the 3 seconds are up
312+
_delayingTimer = [NSTimer scheduledTimerWithTimeInterval:3
313+
target:self
314+
selector:@selector(_convertTypesForContainer)
315+
userInfo:nil
316+
repeats:NO];
317+
} else {
318+
[self _convertTypesForContainer];
319+
}
320+
301321
return self;
302322
}
303323

@@ -1131,6 +1151,12 @@ - (void) _checkForH264VideoVariants
11311151
waitUntilDone:NO];
11321152
}
11331153

1154+
// without doing this on the main thread, it causes the DOM conversion
1155+
// on a secondary thread which WebKit does not like and will cause a crash
1156+
if (_delayingTimer) [_delayingTimer performSelectorOnMainThread:@selector(fire)
1157+
withObject:nil
1158+
waitUntilDone:NO];
1159+
11341160
[pool drain];
11351161
}
11361162

0 commit comments

Comments
 (0)