[Pkg-javascript-commits] [pdf.js] 28/157: Feature-test moz-chunked-arraybuffer before use

David Prévot taffit at moszumanska.debian.org
Tue Aug 11 06:46:29 UTC 2015


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

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

commit 2e63dcdcf55b17e08b1783b3f58dd64cae6d2c6c
Author: Rob Wu <rob at robwu.nl>
Date:   Wed Oct 29 16:31:15 2014 +0100

    Feature-test moz-chunked-arraybuffer before use
---
 src/core/network.js | 46 +++++++++++++++++++++++++++++++++++-----------
 1 file changed, 35 insertions(+), 11 deletions(-)

diff --git a/src/core/network.js b/src/core/network.js
index c030f71..e3a9b63 100644
--- a/src/core/network.js
+++ b/src/core/network.js
@@ -75,6 +75,28 @@ var NetworkManager = (function NetworkManagerClosure() {
     return array.buffer;
   }
 
+//#if !(CHROME || FIREFOX || MOZCENTRAL)
+  var supportsMozChunked = (function supportsMozChunkedClosure() {
+    var x = new XMLHttpRequest();
+    try {
+      // Firefox 37- required .open() to be called before setting responseType.
+      // https://bugzilla.mozilla.org/show_bug.cgi?id=707484
+      x.open('GET', 'https://example.com');
+    } catch (e) {
+      // Even though the URL is not visited, .open() could fail if the URL is
+      // blocked, e.g. via the connect-src CSP directive or the NoScript addon.
+      // When this error occurs, this feature detection method will mistakenly
+      // report that moz-chunked-arraybuffer is not supported in Firefox 37-.
+    }
+    try {
+      x.responseType = 'moz-chunked-arraybuffer';
+      return x.responseType === 'moz-chunked-arraybuffer';
+    } catch (e) {
+      return false;
+    }
+  })();
+//#endif
+
   NetworkManager.prototype = {
     requestRange: function NetworkManager_requestRange(begin, end, listeners) {
       var args = {
@@ -115,17 +137,19 @@ var NetworkManager = (function NetworkManagerClosure() {
         pendingRequest.expectedStatus = 200;
       }
 
-      if (args.onProgressiveData) {
-        // Some legacy browsers might throw an exception.
-        try {
-          xhr.responseType = 'moz-chunked-arraybuffer';
-        } catch(e) {}
-        if (xhr.responseType === 'moz-chunked-arraybuffer') {
-          pendingRequest.onProgressiveData = args.onProgressiveData;
-          pendingRequest.mozChunked = true;
-        } else {
-          xhr.responseType = 'arraybuffer';
-        }
+//#if CHROME
+//    var useMozChunkedLoading = false;
+//#endif
+//#if (FIREFOX || MOZCENTRAL)
+//    var useMozChunkedLoading = !!args.onProgressiveData;
+//#endif
+//#if !(CHROME || FIREFOX || MOZCENTRAL)
+      var useMozChunkedLoading = supportsMozChunked && !!args.onProgressiveData;
+//#endif
+      if (useMozChunkedLoading) {
+        xhr.responseType = 'moz-chunked-arraybuffer';
+        pendingRequest.onProgressiveData = args.onProgressiveData;
+        pendingRequest.mozChunked = true;
       } else {
         xhr.responseType = 'arraybuffer';
       }

-- 
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