[Pkg-javascript-commits] [pdf.js] 164/207: Improving CanvasPixelArray polyfill for Android

David Prévot taffit at moszumanska.debian.org
Mon Jul 28 15:36:44 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository pdf.js.

commit 54fb1f7226a897fdebca7c8d9ea8eab15b0ea359
Author: Fabian Lange <lange.fabian at gmail.com>
Date:   Wed Jun 25 12:52:06 2014 +0200

    Improving CanvasPixelArray polyfill for Android
---
 web/compatibility.js | 42 ++++++++++++++++++++++++++++--------------
 1 file changed, 28 insertions(+), 14 deletions(-)

diff --git a/web/compatibility.js b/web/compatibility.js
index 3bb4377..73f7882 100644
--- a/web/compatibility.js
+++ b/web/compatibility.js
@@ -481,7 +481,7 @@ if (typeof PDFJS === 'undefined') {
   }
 })();
 
-// Support: IE<11, Chrome<21
+// Support: IE<11, Chrome<21, Android<4.4
 (function checkSetPresenceInImageData() {
   // IE < 11 will use window.CanvasPixelArray which lacks set function.
   if (window.CanvasPixelArray) {
@@ -493,24 +493,38 @@ if (typeof PDFJS === 'undefined') {
       };
     }
   } else {
-    // Chrome < 21 uses an inaccessible CanvasPixelArray prototype.
-    // Because we cannot feature detect it, we rely on user agent.
+    // Old Chrome and Android use an inaccessible CanvasPixelArray prototype.
+    // Because we cannot feature detect it, we rely on user agent parsing.
+    var polyfill = false;
     if (navigator.userAgent.indexOf('Chrom') >= 0) {
       var versionMatch = navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./);
       if (versionMatch && parseInt(versionMatch[2]) < 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;
-        };
+        // Chrome < 21 lacks the set function.
+        polyfill = true;
+      }
+    } else if (navigator.userAgent.indexOf('Android') >= 0) {
+      // Android < 4.4 lacks the set function.
+      // Android >= 4.4 will contain Chrome in the user agent,
+      // thus pass the Chrome check above and not reach this block.
+      var isOldAndroid = /Android\s[0-4][^\d]/g.test(navigator.userAgent);
+      if (isOldAndroid) {
+        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;
+      };
+    }
   }
 })();
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/pdf.js.git



More information about the Pkg-javascript-commits mailing list