f658c6c0 by David LaPalomento

Merge pull request #551 from dmlap/null-check-computed-style

Avoid Firefox issue 548397
2 parents 1c31597b c553bc5d
......@@ -17,6 +17,7 @@ var
// The amount of time to wait between checking the state of the buffer
bufferCheckInterval = 500,
safeGetComputedStyle,
keyFailed,
resolveUrl;
......@@ -683,6 +684,27 @@ videojs.HlsHandler.prototype.cancelSegmentXhr = function() {
};
/**
* Returns the CSS value for the specified property on an element
* using `getComputedStyle`. Firefox has a long-standing issue where
* getComputedStyle() may return null when running in an iframe with
* `display: none`.
* @see https://bugzilla.mozilla.org/show_bug.cgi?id=548397
*/
safeGetComputedStyle = function(el, property) {
var result;
if (!el) {
return '';
}
result = getComputedStyle(el);
if (!result) {
return '';
}
return result[property];
};
/**
* Abort all outstanding work and cleanup.
*/
videojs.HlsHandler.prototype.dispose = function() {
......@@ -760,8 +782,8 @@ videojs.HlsHandler.prototype.selectPlaylist = function () {
// (this could be the lowest bitrate rendition as we go through all of them above)
variant = null;
width = parseInt(getComputedStyle(this.tech_.el()).width, 10);
height = parseInt(getComputedStyle(this.tech_.el()).height, 10);
width = parseInt(safeGetComputedStyle(this.tech_.el(), 'width'), 10);
height = parseInt(safeGetComputedStyle(this.tech_.el(), 'height'), 10);
// iterate through the bandwidth-filtered playlists and find
// best rendition by player dimension
......
......@@ -3079,12 +3079,12 @@ test('does not process update end until buffered value has been set', function()
src: 'master.m3u8',
type: 'application/vnd.apple.mpegurl'
});
openMediaSource(player);
origDrainBuffer = player.tech_.hls.drainBuffer;
player.tech_.hls.drainBuffer = function() {
drainBufferCallCount++;
};
openMediaSource(player);
standardXHRResponse(requests.shift()); // master
standardXHRResponse(requests.shift()); // media
......@@ -3106,6 +3106,26 @@ test('does not process update end until buffered value has been set', function()
ok(!player.tech_.hls.pendingSegment_, 'pending segment cleared out');
});
// workaround https://bugzilla.mozilla.org/show_bug.cgi?id=548397
test('selectPlaylist does not fail if getComputedStyle returns null', function() {
var oldGetComputedStyle = window.getComputedStyle;
window.getComputedStyle = function() {
return null;
};
player.src({
src: 'master.m3u8',
type: 'application/vnd.apple.mpegurl'
});
openMediaSource(player);
standardXHRResponse(requests.shift()); // master
standardXHRResponse(requests.shift()); // media
player.tech_.hls.selectPlaylist();
ok(true, 'should not throw');
window.getComputedStyle = oldGetComputedStyle;
});
module('Buffer Inspection');
test('detects time range end-point changed by updates', function() {
......