@@ -167,35 +167,49 @@ if (typeof PDFJS === 'undefined') {
167167 // The worker will be using XHR, so we can save time and disable worker.
168168 PDFJS .disableWorker = true ;
169169
170+ Object .defineProperty (xhrPrototype , 'responseType' , {
171+ get : function xmlHttpRequestGetResponseType () {
172+ return this ._responseType || 'text' ;
173+ },
174+ set : function xmlHttpRequestSetResponseType (value ) {
175+ if (value === 'text' || value === 'arraybuffer' ) {
176+ this ._responseType = value ;
177+ if (value === 'arraybuffer' &&
178+ typeof this .overrideMimeType === 'function' ) {
179+ this .overrideMimeType ('text/plain; charset=x-user-defined' );
180+ }
181+ }
182+ }
183+ });
184+
170185 // Support: IE9
171186 if (typeof VBArray !== 'undefined' ) {
172187 Object .defineProperty (xhrPrototype , 'response' , {
173188 get : function xmlHttpRequestResponseGet () {
174- return new Uint8Array (new VBArray (this .responseBody ).toArray ());
189+ if (this .responseType === 'arraybuffer' ) {
190+ return new Uint8Array (new VBArray (this .responseBody ).toArray ());
191+ } else {
192+ return this .responseText ;
193+ }
175194 }
176195 });
177196 return ;
178197 }
179198
180- // other browsers
181- function responseTypeSetter () {
182- // will be only called to set "arraybuffer"
183- this .overrideMimeType ('text/plain; charset=x-user-defined' );
184- }
185- if (typeof xhr .overrideMimeType === 'function' ) {
186- Object .defineProperty (xhrPrototype , 'responseType' ,
187- { set : responseTypeSetter });
188- }
189- function responseGetter () {
190- var text = this .responseText ;
191- var i , n = text .length ;
192- var result = new Uint8Array (n );
193- for (i = 0 ; i < n ; ++i ) {
194- result [i ] = text .charCodeAt (i ) & 0xFF ;
199+ Object .defineProperty (xhrPrototype , 'response' , {
200+ get : function xmlHttpRequestResponseGet () {
201+ if (this .responseType !== 'arraybuffer' ) {
202+ return this .responseText ;
203+ }
204+ var text = this .responseText ;
205+ var i , n = text .length ;
206+ var result = new Uint8Array (n );
207+ for (i = 0 ; i < n ; ++i ) {
208+ result [i ] = text .charCodeAt (i ) & 0xFF ;
209+ }
210+ return result .buffer ;
195211 }
196- return result .buffer ;
197- }
198- Object .defineProperty (xhrPrototype , 'response' , { get : responseGetter });
212+ });
199213})();
200214
201215// window.btoa (base64 encode function) ?
@@ -237,7 +251,7 @@ if (typeof PDFJS === 'undefined') {
237251 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=' ;
238252 window .atob = function (input ) {
239253 input = input .replace (/=+$ /, '');
240- if (input .length % 4 == 1 ) {
254+ if (input .length % 4 === 1 ) {
241255 throw new Error ('bad atob input' );
242256 }
243257 for (
@@ -293,7 +307,7 @@ if (typeof PDFJS === 'undefined') {
293307 var dataset = {};
294308 for (var j = 0 , jj = this .attributes .length ; j < jj ; j ++) {
295309 var attribute = this .attributes [j ];
296- if (attribute .name .substring (0 , 5 ) != 'data-' ) {
310+ if (attribute .name .substring (0 , 5 ) !== 'data-' ) {
297311 continue ;
298312 }
299313 var key = attribute .name .substring (5 ).replace (/\-( [a -z ])/g ,
@@ -416,7 +430,7 @@ if (typeof PDFJS === 'undefined') {
416430 function isDisabled (node ) {
417431 return node .disabled || (node .parentNode && isDisabled (node .parentNode ));
418432 }
419- if (navigator .userAgent .indexOf ('Opera' ) != -1 ) {
433+ if (navigator .userAgent .indexOf ('Opera' ) !== -1 ) {
420434 // use browser detection since we cannot feature-check this bug
421435 document .addEventListener ('click' , ignoreIfTargetDisabled , true );
422436 }
@@ -467,6 +481,7 @@ if (typeof PDFJS === 'undefined') {
467481
468482 if (isSafari || isOldAndroid ) {
469483 PDFJS .disableRange = true ;
484+ PDFJS .disableStream = true ;
470485 }
471486})();
472487
@@ -481,7 +496,7 @@ if (typeof PDFJS === 'undefined') {
481496 }
482497})();
483498
484- // Support: IE<11, Chrome<21, Android<4.4
499+ // Support: IE<11, Chrome<21, Android<4.4, Safari<6
485500(function checkSetPresenceInImageData () {
486501 // IE < 11 will use window.CanvasPixelArray which lacks set function.
487502 if (window .CanvasPixelArray ) {
@@ -495,21 +510,21 @@ if (typeof PDFJS === 'undefined') {
495510 } else {
496511 // Old Chrome and Android use an inaccessible CanvasPixelArray prototype.
497512 // Because we cannot feature detect it, we rely on user agent parsing.
498- var polyfill = false ;
513+ var polyfill = false , versionMatch ;
499514 if (navigator .userAgent .indexOf ('Chrom' ) >= 0 ) {
500- var versionMatch = navigator .userAgent .match (/Chrom (e |ium )\/([0 -9 ]+)\./);
501- if (versionMatch && parseInt (versionMatch [2 ]) < 21 ) {
502- // Chrome < 21 lacks the set function.
503- polyfill = true ;
504- }
515+ versionMatch = navigator .userAgent .match (/Chrom (e |ium )\/([0 -9 ]+)\./);
516+ // Chrome < 21 lacks the set function.
517+ polyfill = versionMatch && parseInt (versionMatch [2 ]) < 21 ;
505518 } else if (navigator .userAgent .indexOf ('Android' ) >= 0 ) {
506519 // Android < 4.4 lacks the set function.
507520 // Android >= 4.4 will contain Chrome in the user agent,
508521 // thus pass the Chrome check above and not reach this block.
509- var isOldAndroid = /Android \s [0 -4 ][^\d]/g .test (navigator .userAgent );
510- if (isOldAndroid ) {
511- polyfill = true ;
512- }
522+ polyfill = /Android \s [0 -4 ][^\d]/g .test (navigator .userAgent );
523+ } else if (navigator .userAgent .indexOf ('Safari' ) >= 0 ) {
524+ versionMatch = navigator .userAgent .
525+ match (/Version \/([0 -9 ]+)\.( [0 -9 ]+)\.( [0 -9 ]+) Safari \//);
526+ // Safari < 6 lacks the set function.
527+ polyfill = versionMatch && parseInt (versionMatch [1 ]) < 6 ;
513528 }
514529
515530 if (polyfill ) {
0 commit comments