Skip to content

Commit

Permalink
Fixes CanvasPixelArray set polyfillfor chrome < 21 (mozilla#4974)
Browse files Browse the repository at this point in the history
  • Loading branch information
CodingFabian committed Jun 24, 2014
1 parent 10db93b commit 94f1390
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions web/compatibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,17 +481,35 @@ if (typeof PDFJS === 'undefined') {
}
})();

// TODO CanvasPixelArray is deprecated; use Uint8ClampedArray
// once it's supported.
// Support: IE<11, Chrome<21
(function checkSetPresenceInImageData() {
if (window.CanvasPixelArray) {
if (typeof window.CanvasPixelArray.prototype.set !== 'function') {
window.CanvasPixelArray.prototype.set = function(arr) {
// because the availability of a set function on ImageData.data is not
// feature-detectable, we have to rely on user agents:
// IE<11 contains MSIE - starting from 11 it no longer does
var polyfill = false;
if (navigator.userAgent.indexOf('MSIE') >= 0) {
polyfill = true;
}
// chrome user agent contains Chrome/major.minor
if (navigator.userAgent.indexOf('Chrom') >= 0) {
var version = navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./)[2];
if (parseInt(version) < 21) {
polyfill = true;
}
}

if (polyfill) {
var contextPrototype = window.CanvasRenderingContext2D.prototype;
contextPrototype._createImageData = contextPrototype.createImageData;
contextPrototype.createImageData = function(w, h) {
var imageData = this._createImageData(w, h);
imageData.data.set = function(arr) {
for (var i = 0, ii = this.length; i < ii; i++) {
this[i] = arr[i];
}
};
}
return imageData;
};
}
})();

Expand Down

0 comments on commit 94f1390

Please sign in to comment.