r62236 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62235‎ | r62236 | r62237 >
Date:11:28, 10 February 2010
Author:tstarling
Status:deferred (Comments)
Tags:
Comment:
* Various style, whitespace and documentation fixes
* Renamed supportedMimeType() to hasPlugin() and made it go forwards instead of backwards
* Fixed quoting of MIME types
* Rewrote the Safari version check from r53648, it was ugly-looking code lifted from Apple without following their MIT-style license (which requires attribution). We only really need the major webkit version, maybe there are about two months of updates in mid-2009 where this would be inaccurate, but that's a small price to pay for deleting 40 lines of nasty code.
* Safari parts are mostly untested, working on testing now.
Modified paths:
  • /trunk/extensions/OggHandler/OggPlayer.js (modified) (history)

Diff [purge]

Index: trunk/extensions/OggHandler/OggPlayer.js
@@ -5,6 +5,7 @@
66 'safari' : false,
77 'opera' : false,
88 'mozilla': false,
 9+ 'safariControlsBug': false,
910
1011 // List of players in order of preference
1112 // Downpreffed VLC because it crashes my browser all the damn time -- TS
@@ -71,7 +72,7 @@
7273 }
7374 }
7475
75 - if ( !this.clientSupports[player] ) {
 76+ if ( !this.clientSupports[player] ) {
7677 player = false;
7778 }
7879
@@ -134,17 +135,22 @@
135136 elt.appendChild( div );
136137 }
137138 },
 139+
138140 'debug': function( s ) {
139141 //alert(s);
140142 },
141 - 'supportedMimeType': function(mimetype) {
142 - for (var i = navigator.plugins.length; i-- > 0; ) {
143 - var plugin = navigator.plugins[i];
144 - if (typeof plugin[mimetype] != "undefined")
145 - return true;
 143+
 144+ // Search for a plugin in navigator.plugins
 145+ 'hasPlugin': function( mimeType ) {
 146+ for ( var i = 0; i < navigator.plugins.length; i++ ) {
 147+ var plugin = navigator.plugins[i];
 148+ if ( typeof plugin[mimeType] != "undefined" ) {
 149+ return true;
 150+ }
146151 }
147152 return false;
148153 },
 154+
149155 // Detect client capabilities
150156 'detect': function() {
151157 if (this.detectionDone) {
@@ -172,11 +178,22 @@
173179 }
174180
175181 if ( this.konqueror ) {
176 - // Bugged as of 3.5.9
 182+ // Java is bugged as of 3.5.9
177183 // Applet freezes shortly after starting
178184 javaEnabled = false;
179185 }
180186
 187+ if ( this.safari ) {
 188+ // Detect https://bugs.webkit.org/show_bug.cgi?id=25575
 189+ var match = /AppleWebKit\/([0-9]+)/.exec( navigator.userAgent );
 190+ if ( match ) {
 191+ var major = parseInt( match[1] );
 192+ if ( major < 531 ) {
 193+ this.safariControlsBug = true;
 194+ }
 195+ }
 196+ }
 197+
181198 // ActiveX plugins
182199 // VLC
183200 if ( this.testActiveX( 'VideoLAN.VLCPlugin.2' ) ) {
@@ -195,24 +212,22 @@
196213 if ( typeof HTMLVideoElement == 'object' // Firefox, Safari
197214 || typeof HTMLVideoElement == 'function' ) // Opera
198215 {
199 - //do another test for safari:
200 - if( wgOggPlayer.safari ){
201 - try{
202 - var dummyvid = document.createElement("video");
203 - if (dummyvid.canPlayType && dummyvid.canPlayType("video/ogg;codecs=\"theora,vorbis\"") == "probably")
 216+ // Safari does not support Theora by default, but later versions implement canPlayType()
 217+ if ( this.safari ) {
 218+ try {
 219+ var video = document.createElement( 'video' );
 220+ if ( video.canPlayType
 221+ && video.canPlayType( 'video/ogg;codecs="theora,vorbis"' ) == 'probably' )
204222 {
205223 this.clientSupports['videoElement'] = true;
206 - } else if(this.supportedMimeType('video/ogg')) {
207 - /* older versions of safari do not support canPlayType,
208 - but xiph qt registers mimetype via quicktime plugin */
 224+ } else if ( this.supportedMimeType( 'video/ogg' ) ) {
 225+ // On older versions, XiphQT registers a plugin type and also handles <video>
209226 this.clientSupports['videoElement'] = true;
210227 } else {
211 - /* could add some user nagging to install the xiph qt */
 228+ // TODO: prompt for XiphQT install
212229 }
213 - }catch(e){
214 - //could not use canPlayType
215 - }
216 - }else{
 230+ } catch ( e ) {}
 231+ } else {
217232 this.clientSupports['videoElement'] = true;
218233 }
219234 }
@@ -270,7 +285,9 @@
271286 // Note: Totem and KMPlayer also use this pluginName, which is
272287 // why we check for them first
273288 player = 'quicktime-mozilla';
274 - } else if ( (pluginName.toLowerCase() == 'vlc multimedia plugin') || (pluginName.toLowerCase() == 'vlc multimedia plug-in') ) {
 289+ } else if ( (pluginName.toLowerCase() == 'vlc multimedia plugin')
 290+ || (pluginName.toLowerCase() == 'vlc multimedia plug-in') )
 291+ {
275292 player = 'vlc-mozilla';
276293 } else if ( type == 'application/ogg' ) {
277294 player = 'oggPlugin';
@@ -345,52 +362,7 @@
346363 }
347364 return hasObj;
348365 },
349 - 'webkitVersionIsAtLeast' : function ( minimumString ) {
350 - var version = function() {
351 - // grab (AppleWebKit/)(xxx.x.x)
352 - var webKitFields = RegExp("( AppleWebKit/)([^ ]+)").exec(navigator.userAgent);
353 - if (!webKitFields || webKitFields.length < 3)
354 - return null;
355 - var versionString = webKitFields[2];
356 - var isNightlyBuild = versionString.indexOf("+") != -1;
357366
358 - // Remove '+' or any other stray characters
359 - var invalidCharacter = RegExp("[^\\.0-9]").exec(versionString);
360 - if (invalidCharacter)
361 - versionString = versionString.slice(0, invalidCharacter.index);
362 -
363 - var version = versionString.split(".");
364 - version.isNightlyBuild = isNightlyBuild;
365 - return version;
366 - }
367 - var toIntOrZero = function (s) {
368 - var toInt = parseInt(s);
369 - return isNaN(toInt) ? 0 : toInt;
370 - }
371 -
372 - if (minimumString === undefined)
373 - minimumString = "";
374 -
375 - var minimum = minimumString.split(".");
376 - var version = version();
377 -
378 - if (!version)
379 - return false;
380 -
381 - if (version.isNightlyBuild)
382 - return true;
383 -
384 - for (var i = 0; i < minimum.length; i++) {
385 - var versionField = toIntOrZero(version[i]);
386 - var minimumField = toIntOrZero(minimum[i]);
387 -
388 - if (versionField > minimumField)
389 - return true;
390 - if (versionField < minimumField)
391 - return false;
392 - }
393 - return true;
394 - },
395367 'addOption' : function ( select, value, text, selected ) {
396368 var option = document.createElement( 'option' );
397369 option.value = value;
@@ -586,17 +558,18 @@
587559
588560 'embedVideoElement': function ( elt, params ) {
589561 var id = elt.id + "_obj";
590 - var mtag = (params.isVideo?'video':'audio');
 562+ var tagName = params.isVideo ? 'video' : 'audio';
591563 var html =
592 - '<div><' + mtag +
 564+ '<div><' + tagName +
593565 ' id=' + this.hq( id ) +
594566 ' width=' + this.hq( params.width ) +
595567 ' height=' + this.hq( (params.height>0)?params.height:this.controlsHeightGuess ) +
596568 ' src=' + this.hq( params.videoUrl ) +
597569 ' autoplay';
598 - if (!this.safari || this.webkitVersionIsAtLeast('530.19.2'))
 570+ if ( !this.safariControlsBug ) {
599571 html += ' controls';
600 - html += ' ></' + mtag + '></div>';
 572+ }
 573+ html += ' ></' + tagName + '></div>';
601574 elt.innerHTML = html;
602575 },
603576
@@ -604,7 +577,7 @@
605578 var id = elt.id + "_obj";
606579 elt.innerHTML +=
607580 "<div><object id=" + this.hq( id ) +
608 - " type='" + this.mimeTypes[player] + "'" +
 581+ " type=" + this.hq( this.mimeTypes[player] ) +
609582 " width=" + this.hq( params.width ) +
610583 " height=" + this.hq( params.height + this.controlsHeightGuess ) +
611584 " data=" + this.hq( params.videoUrl ) + "></object></div>";
@@ -614,7 +587,7 @@
615588 var id = elt.id + "_obj";
616589 elt.innerHTML +=
617590 "<div><object id=" + this.hq( id ) +
618 - " type='" + this.mimeTypes['vlc-mozilla'] + "'" +
 591+ " type=" + this.hq( this.mimeTypes['vlc-mozilla'] ) +
619592 " width=" + this.hq( params.width ) +
620593 " height=" + this.hq( params.height ) +
621594 " data=" + this.hq( params.videoUrl ) + "></object></div>";

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r53648Safari 4.0.2 no longer crashes if <video controls> is dynamicaly injected int...j15:48, 22 July 2009

Comments

#Comment by Tim Starling (talk | contribs)   12:54, 10 February 2010

Werdna tested it on Safari Mac OS X:

  • No XiphQT, Cortado default, canPlayType() suppresses video element as expected
  • QuickTime plugin, no XiphQT
  • QuickTime plugin with XiphQT
  • Video element with XiphQT

The branches for old Safari versions (this.safariControlsBug==true etc.) are untested.

Status & tagging log