Skip to content

Commit

Permalink
Fixes CanvasPixelArray set polyfill for 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 7faa27e
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions web/compatibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,16 +481,35 @@ if (typeof PDFJS === 'undefined') {
}
})();

// TODO CanvasPixelArray is deprecated; use Uint8ClampedArray
// once it's supported.
// Support: IE<11, Chrome<21
(function checkSetPresenceInImageData() {
// IE < 11 will use window.CanvasPixelArray which lacks set function.
if (window.CanvasPixelArray) {
if (typeof window.CanvasPixelArray.prototype.set !== 'function') {
window.CanvasPixelArray.prototype.set = function(arr) {
for (var i = 0, ii = this.length; i < ii; i++) {
this[i] = arr[i];
}
};
}
}
} else {
// Chrome < 21 uses an inaccessible CanvasPixelArray prototype.
// be cause we cannot feature detect it, we rely on user agent.
if (navigator.userAgent.indexOf('Chrom') >= 0) {
var version = navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./)[2];
if (parseInt(version) < 21) {
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 7faa27e

Please sign in to comment.