Skip to content

Commit

Permalink
Merge commit 'antifuchs/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
rentzsch committed Aug 15, 2009
2 parents 0268771 + 10dbf8b commit 5e3deaf
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 14 deletions.
2 changes: 2 additions & 0 deletions Plugin/Plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ THE SOFTWARE.
- (BOOL)_hasH264Version;
- (void)_setHasH264Version:(BOOL)newValue;
- (BOOL)_hasHDH264Version;
- (NSString*)_h264VersionUrl;
- (BOOL)_isVideoElementAvailable;
- (void)_setHasHDH264Version:(BOOL)newValue;
- (NSString *)launchedAppBundleIdentifier;
- (void)setLaunchedAppBundleIdentifier:(NSString *)newValue;
Expand Down
73 changes: 59 additions & 14 deletions Plugin/Plugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -1260,35 +1260,76 @@ - (BOOL) _useH264Version
&& [ [ CTFUserDefaultsController standardUserDefaults ] boolForKey: sPluginEnabled ];
}

- (void) _convertElementForMP4: (DOMElement*) element
- (BOOL)_isVideoElementAvailable
{
/* <video> element compatibility was added to WebKit in or shortly before version 525. */

NSBundle* webKitBundle;
webKitBundle = [ NSBundle bundleForClass: [ WebView class ] ];
if (webKitBundle) {
/* ref. http://lists.apple.com/archives/webkitsdk-dev/2008/Nov/msg00003.html:
* CFBundleVersion is 5xxx.y on WebKits built to run on Leopard, 4xxx.y on Tiger.
* Unspecific builds (such as the ones in OmniWeb) get xxx.y numbers without a prefix.
*/
int normalizedVersion;
float wkVersion = [ (NSString*) [ [ webKitBundle infoDictionary ]
valueForKey: @"CFBundleVersion" ]
floatValue ];
if (wkVersion > 4000)
normalizedVersion = (int)wkVersion % 1000;
else
normalizedVersion = wkVersion;
return normalizedVersion >= 525;
}
return NO;
}

- (NSString*) _h264VersionUrl
{
NSString* video_id = [self videoId];
NSString* video_hash = [ self _videoHash ];

NSString* src;
if ([self _hasHDH264Version]) {
if ([ self _hasHDH264Version ]) {
src = [ NSString stringWithFormat: @"http://www.youtube.com/get_video?fmt=22&video_id=%@&t=%@",
video_id, video_hash ];
video_id, video_hash ];
} else {
src = [ NSString stringWithFormat: @"http://www.youtube.com/get_video?fmt=18&video_id=%@&t=%@",
video_id, video_hash ];
video_id, video_hash ];
}

[ element setAttribute: @"src" value: src ];
return src;
}

- (void) _convertElementForMP4: (DOMElement*) element
{
[ element setAttribute: @"src" value: [ self _h264VersionUrl ]];
[ element setAttribute: @"type" value: @"video/mp4" ];
[ element setAttribute: @"scale" value: @"aspect" ];
[ element setAttribute: @"autoplay" value: @"true" ];
[ element setAttribute: @"cache" value: @"false" ];
if( ! [ element hasAttribute: @"width" ] )
[ element setAttribute: @"width" value: @"640" ];
if( ! [ element hasAttribute: @"height" ] )
[ element setAttribute: @"height" value: @"500" ];

[ element setAttribute: @"height" value: @"500" ];
[ element setAttribute: @"flashvars" value: nil ];
}

- (void) _convertElementForVideoElement: (DOMElement*) element
{
[ element setAttribute: @"src" value: [ self _h264VersionUrl ] ];
[ element setAttribute: @"autobuffer" value:@"autobuffer"];
[ element setAttribute: @"autoplay" value:@"autoplay"];
[ element setAttribute: @"controls" value:@"controls"];

DOMElement* container = [self container];

[ element setAttribute:@"width" value:[ NSString stringWithFormat:@"%dpx", [ container clientWidth ]]];
[ element setAttribute:@"height" value:[ NSString stringWithFormat:@"%dpx", [ container clientHeight ]]];
}

- (void) _convertToMP4Container
{
[self _revertToOriginalOpacityAttributes];
Expand All @@ -1300,10 +1341,14 @@ - (void) _convertToMP4Container

- (void) _convertToMP4ContainerAfterDelay
{
DOMElement* newElement = (DOMElement*) [ [self container] cloneNode: NO ];

[ self _convertElementForMP4: newElement ];

DOMElement* newElement;
if ([ self _isVideoElementAvailable ]) {
newElement = [[[self container] ownerDocument] createElement:@"video"];
[ self _convertElementForVideoElement: newElement ];
} else {
newElement = (DOMElement*) [ [self container] cloneNode: NO ];
[ self _convertElementForMP4:newElement ];
}
// Just to be safe, since we are about to replace our containing element
[[self retain] autorelease];

Expand Down

0 comments on commit 5e3deaf

Please sign in to comment.