@@ -115,6 +115,7 @@ - (id) initWithArguments:(NSDictionary *)arguments
115
115
_hasHDH264Version = NO ;
116
116
_contextMenuIsVisible = NO ;
117
117
_embeddedYouTubeView = NO ;
118
+ _delayingTimer = nil ;
118
119
defaultWhitelist = [NSArray arrayWithObjects: @" com.apple.frontrow" ,
119
120
@" com.apple.dashboard.client" ,
120
121
@" com.apple.ScreenSaver.Engine" ,
@@ -275,8 +276,8 @@ - (id) initWithArguments:(NSDictionary *)arguments
275
276
return self;
276
277
}
277
278
278
- BOOL loadFromWhiteList = [self _isHostWhitelisted ];
279
279
280
+ BOOL loadFromWhiteList = [self _isHostWhitelisted ];
280
281
281
282
// Check the SWF src URL itself against the whitelist (allows embbeded videos from whitelisted sites to play, e.g. YouTube)
282
283
@@ -297,7 +298,26 @@ - (id) initWithArguments:(NSDictionary *)arguments
297
298
298
299
if (loadFromWhiteList && ![self _isOptionPressed ]) {
299
300
_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
+
301
321
return self;
302
322
}
303
323
@@ -1131,6 +1151,12 @@ - (void) _checkForH264VideoVariants
1131
1151
waitUntilDone: NO ];
1132
1152
}
1133
1153
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
+
1134
1160
[pool drain ];
1135
1161
}
1136
1162
0 commit comments