Bug 1287211 - Update pdf.js to version 1.5.337. r=bdahl
authorRyan VanderMeulen <ryanvm@gmail.com>
Fri, 15 Jul 2016 17:44:34 -0400
changeset 388640 4b8678f2b325a599093351e9adcb52fdcd146ccb
parent 388639 3db372da6fe108ddb0727003447f22c2483fb86d
child 388641 a2a083903b00b08f108616cffe894507606d7ed4
push id23215
push userluca.greco@alcacoop.it
push dateSat, 16 Jul 2016 20:37:12 +0000
reviewersbdahl
bugs1287211
milestone50.0a1
Bug 1287211 - Update pdf.js to version 1.5.337. r=bdahl
browser/extensions/pdfjs/README.mozilla
browser/extensions/pdfjs/content/build/pdf.js
browser/extensions/pdfjs/content/build/pdf.worker.js
browser/extensions/pdfjs/content/web/images/texture.png
browser/extensions/pdfjs/content/web/images/toolbarButton-menuArrows.png
browser/extensions/pdfjs/content/web/images/toolbarButton-viewAttachments@2x.png
browser/extensions/pdfjs/content/web/images/toolbarButton-viewThumbnail@2x.png
browser/extensions/pdfjs/content/web/images/treeitem-collapsed-rtl.png
browser/extensions/pdfjs/content/web/images/treeitem-collapsed-rtl@2x.png
browser/extensions/pdfjs/content/web/viewer.js
--- a/browser/extensions/pdfjs/README.mozilla
+++ b/browser/extensions/pdfjs/README.mozilla
@@ -1,3 +1,3 @@
 This is the pdf.js project output, https://github.com/mozilla/pdf.js
 
-Current extension version is: 1.5.322
+Current extension version is: 1.5.337
--- a/browser/extensions/pdfjs/content/build/pdf.js
+++ b/browser/extensions/pdfjs/content/build/pdf.js
@@ -23,18 +23,18 @@ define('pdfjs-dist/build/pdf', ['exports
     factory(exports);
   } else {
 factory((root.pdfjsDistBuildPdf = {}));
   }
 }(this, function (exports) {
   // Use strict in our context only - users might not want it
   'use strict';
 
-var pdfjsVersion = '1.5.322';
-var pdfjsBuild = 'b6826a4';
+var pdfjsVersion = '1.5.337';
+var pdfjsBuild = '11381cd';
 
   var pdfjsFilePath =
     typeof document !== 'undefined' && document.currentScript ?
       document.currentScript.src : null;
 
   var pdfjsLibs = {};
 
   (function pdfjsWrapper() {
@@ -1217,20 +1217,17 @@ var StatTimer = (function StatTimerClosu
   };
   return StatTimer;
 })();
 
 var createBlob = function createBlob(data, contentType) {
   if (typeof Blob !== 'undefined') {
     return new Blob([data], { type: contentType });
   }
-  // Blob builder is deprecated in FF14 and removed in FF18.
-  var bb = new MozBlobBuilder();
-  bb.append(data);
-  return bb.getBlob(contentType);
+  warn('The "Blob" constructor is not supported.');
 };
 
 var createObjectURL = (function createObjectURLClosure() {
   // Blob/createObjectURL is not available, falling back to data schema.
   var digits =
     'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
 
   return function createObjectURL(data, contentType, forceDataSchema) {
--- a/browser/extensions/pdfjs/content/build/pdf.worker.js
+++ b/browser/extensions/pdfjs/content/build/pdf.worker.js
@@ -23,18 +23,18 @@ define('pdfjs-dist/build/pdf.worker', ['
     factory(exports);
   } else {
 factory((root.pdfjsDistBuildPdfWorker = {}));
   }
 }(this, function (exports) {
   // Use strict in our context only - users might not want it
   'use strict';
 
-var pdfjsVersion = '1.5.322';
-var pdfjsBuild = 'b6826a4';
+var pdfjsVersion = '1.5.337';
+var pdfjsBuild = '11381cd';
 
   var pdfjsFilePath =
     typeof document !== 'undefined' && document.currentScript ?
       document.currentScript.src : null;
 
   var pdfjsLibs = {};
 
   (function pdfjsWrapper() {
@@ -3238,20 +3238,17 @@ var StatTimer = (function StatTimerClosu
   };
   return StatTimer;
 })();
 
 var createBlob = function createBlob(data, contentType) {
   if (typeof Blob !== 'undefined') {
     return new Blob([data], { type: contentType });
   }
-  // Blob builder is deprecated in FF14 and removed in FF18.
-  var bb = new MozBlobBuilder();
-  bb.append(data);
-  return bb.getBlob(contentType);
+  warn('The "Blob" constructor is not supported.');
 };
 
 var createObjectURL = (function createObjectURLClosure() {
   // Blob/createObjectURL is not available, falling back to data schema.
   var digits =
     'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
 
   return function createObjectURL(data, contentType, forceDataSchema) {
@@ -27031,17 +27028,17 @@ function recoverGlyphName(name, glyphsUn
   var unicode = getUnicodeForGlyph(name, glyphsUnicodeMap);
   if (unicode !== -1) {
     for (var key in glyphsUnicodeMap) {
       if (glyphsUnicodeMap[key] === unicode) {
         return key;
       }
     }
   }
-  warn('Unable to recover a standard glyph name for: ' + name);
+  info('Unable to recover a standard glyph name for: ' + name);
   return name;
 }
 
 var Glyph = (function GlyphClosure() {
   function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId,
                  isSpace, isInFont) {
     this.fontChar = fontChar;
     this.unicode = unicode;
index eb5ccb5ec3cdf7f20c344483958a2684e11e6df5..12bae83a910277a30f57e8e30a5a4ed2f17e2c37
GIT binary patch
literal 2417
zc$}S<`9Bkk1IOnaW{$8iGq>4>OiamK)66yGYVJF7geJondK^pQiyV=V%6;W3=Bm*1
zLLr${&Jgh+PjWs_&%f~fyk76m``6EpAEqtY3@iW>0001BbCT)h-!}RWKCa*Wpd;z~
zZ#CFjIb8Z}H8nL!Nl7g&Ee#C~adB~FWo0-VuC1+YXlRH;B4IF?rlzL6yu7TeEDD9f
z;c$wIiWe?i0E597FJ6Q|Ab339*w~mzB#MfPT3A?+NF-rlVGsxe1OlzBtoZr)O-)U?
zxw*+?va_?Zot>SBhX*Gor=z2zo12@xy*-6O@$&NW@$m@?3JMJk_4D(Kh=>RX2)KUz
z`pug+X*61JaBxaW3YAKYjg3Wa%={h<(4$@^+YA5SN$@C>1pxTYo0}Rt&^S^Gc=Gp1
zXKpDLjgL5{R-`iW*G{3cW?ZAl?Pn&3mE2V=aX~<X9-{``hy;ZRF>)}6(Fo0Q^RkVO
z#RwKhjTRXqs2}d>zRKIZHj62wbw`yC)xSSvXNE}?C^$cdKeUDs?p?Y!PSw66<ckBP
zb9DN>4)41*r72GWz+-?RgDcHrf<J$_8$fEg96LZ3QbAXYPF4_00^}RIKr}A09Bg48
zB)pm<Rt(hN6cKp$gb~)z9O!2p8y8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t)6~2BOQpGDhwF*DX_4U#%nh@;fvCA=6><X(6
ztz7qznQ{Y1ckYzJEn^1xCFKc@f<`OXLfVs`V>x0a1J|~xn0QWio#?%GaBmD*9k9$f
z2QAR^?*9d9EmytYy*S$4fur{d4KE!<Wvi(jXKx8Q1ELpi<csp*nA2u)>_9BRt;s{@
z9PbxkR_wqjLT(p1b$oPS9>t%~*S`dWEA{d5HvO1s=h2f@XXU)}*nX|rBsOQ!t6F1I
z67lp|+`<GOjdUaUpPj6j){s_48h1SF*PHc#^Qt9EV~vEki~hsdPYzuC0>V51b@y4K
zm~KTLcOYqo6Ya#E<$%mHQ~da1(&H<v5Vxi846)7_T<Wm*P)sy**{#iI>2rN2_d(T<
Z7%JA_k&jlwe*aw&^GjsY1{1I3e*tEYGdlnP
index 306eb43b86861ffd83ab17541d64a4e8d240c86a..e50ca4eee46e25d92e06847004f323d616237f85
GIT binary patch
literal 107
zc%17D@N?(olHy`uVBq!ia0vp^>_9BQ!3HF6HKu+5QbwLGjv*C{$r2tP{{OG9Q;1_&
zbWt^;p+Z-{zWI{QiAmlEggExJ)R+qxP213Hu-B-8fx+-v^k(la_imtW22WQ%mvv4F
FO#tGFAX@+c
index b979e523e742027645e980d8a27c54d0060ebf21..4a5e2b8a3775facabbf7e93d8b9b1b30297632be
GIT binary patch
literal 859
zc$@)S1El<kP)<h;3K|Lk000e1NJLTq001BW001Be1ONa4*>kdg0009bNkl<Zcmdta
zLxAM~0E6MIZQHhO+qP}nwr$(C{l>O!qs?nO>`2G`bN+(=Af|T(S(@31n57R7<0pDb
zv*kV(PVYe$9;O?e1ONJb6Yc5BKP*8IY3C>D9Hdz{87<JX-$0k=bQGU6bIJ$Z_=Fv!
z`3X7&{u$mI`5>30PBZ^sbmXX%4tmg@4vsUTxntmOiRVB}nLn<lUGS4&B+ErR+Sos+
zQ(of7=@9s9L@(s{fOs27n{fSbB*$%OZGXRXqYqhy<FpI<F;wD?P;COO1HK0!Dc+sd
zv~;*Da~`8@z;~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uJuqQ=h+0s&Q|8XcH
zQZcqHt;Xt;AX($W(hNvYp9a~%9?pjKyaM_q)Sr>Ai1Yx4!(rbx9*stQkf2`I11D?x
VwzoOr^jH7@002ovPDHLkV1mA0TJZn?
index 1c8b9f7010cae8edd6ca3a1146c6f07f68f5931e..0496b3577555195f96498932403c030411769159
GIT binary patch
literal 143
zc%17D@N?(olHy`uVBq!ia0vp^oFL4>1|%O$WD@{VVV*9IAr*|t6(1k5>aAfpGT9*~
zXOfab4D%87#veSpl*$zRm>xL?oHRbsHKXB%c*k}H6$4SxhZAg?^X4iGtUtb-qb;)0
qg018G<FJ+kOb#)9&#VtUWMR17`s11Z)ixoZ4Gf;HelF{r5}E*k#W1e`
index 84279368d985d74ba324ea3433b08ea5974bcc62..6ad9ebcdf5df5a2aa8d39e01371fc8a5e4663db4
GIT binary patch
literal 167
zc%17D@N?(olHy`uVBq!ia0vp^LLkh+1|-AI^@RheJWm(LkP61+ijR+2cScBc{7$GT
z;z?kCWTIflbtL_S=?Sq8a|d1v=S7Yj`3fe<QZAFsPZ)DtmTuuydc%8&?co<TNw&nQ
zW})Uc4He3pni#)ISxsYnRF@^;a$@%v{|Od*y&D}{_IkfhYS~bpSi`{YeP_|4`&u?Y
Pn;AS^{an^LB{Ts58u&Pg
--- a/browser/extensions/pdfjs/content/web/viewer.js
+++ b/browser/extensions/pdfjs/content/web/viewer.js
@@ -6417,17 +6417,17 @@ var PDFViewer = (function pdfViewer() {
     },
 
     /**
      * @param val - The scale of the pages (in percent or predefined value).
      */
     set currentScaleValue(val) {
       if (!this.pdfDocument) {
         this._currentScale = isNaN(val) ? UNKNOWN_SCALE : val;
-        this._currentScaleValue = val;
+        this._currentScaleValue = val.toString();
         return;
       }
       this._setScale(val, false);
     },
 
     /**
      * @returns {number}
      */
@@ -6604,17 +6604,17 @@ var PDFViewer = (function pdfViewer() {
         presetValue: preset ? newValue : undefined
       };
       this.eventBus.dispatch('scalechanging', arg);
       this.eventBus.dispatch('scalechange', arg);
     },
 
     _setScaleUpdatePages: function pdfViewer_setScaleUpdatePages(
         newScale, newValue, noScroll, preset) {
-      this._currentScaleValue = newValue;
+      this._currentScaleValue = newValue.toString();
 
       if (isSameScale(this._currentScale, newScale)) {
         if (preset) {
           this._setScaleDispatchEvent(newScale, newValue, true);
         }
         return;
       }
 
@@ -7499,59 +7499,47 @@ var PDFViewerApplication = {
    * @param {string|TypedArray|ArrayBuffer} file - PDF location or binary data.
    * @param {Object} args - (optional) Additional arguments for the getDocument
    *                        call, e.g. HTTP headers ('httpHeaders') or
    *                        alternative data transport ('range').
    * @returns {Promise} - Returns the promise, which is resolved when document
    *                      is opened.
    */
   open: function pdfViewOpen(file, args) {
-    var scale = 0;
-    if (arguments.length > 2 || typeof args === 'number') {
-      console.warn('Call of open() with obsolete signature.');
-      if (typeof args === 'number') {
-        scale = args; // scale argument was found
-      }
-      args = arguments[4] || null;
-      if (arguments[3] && typeof arguments[3] === 'object') {
-        // The pdfDataRangeTransport argument is present.
-        args = Object.create(args);
-        args.range = arguments[3];
-      }
-      if (typeof arguments[2] === 'string') {
-        // The password argument is present.
-        args = Object.create(args);
-        args.password = arguments[2];
-      }
-    }
-
     if (this.pdfLoadingTask) {
       // We need to destroy already opened document.
       return this.close().then(function () {
         // Reload the preferences if a document was previously opened.
         Preferences.reload();
         // ... and repeat the open() call.
         return this.open(file, args);
       }.bind(this));
     }
 
-    var parameters = Object.create(null);
+    var parameters = Object.create(null), scale;
     if (typeof file === 'string') { // URL
       this.setTitleUsingUrl(file);
       parameters.url = file;
     } else if (file && 'byteLength' in file) { // ArrayBuffer
       parameters.data = file;
     } else if (file.url && file.originalUrl) {
       this.setTitleUsingUrl(file.originalUrl);
       parameters.url = file.url;
     }
     if (args) {
       for (var prop in args) {
         parameters[prop] = args[prop];
       }
+
+      if (args.scale) {
+        scale = args.scale;
+      }
+      if (args.length) {
+        this.pdfDocumentProperties.setFileSize(args.length);
+      }
     }
 
     var self = this;
     self.downloadComplete = false;
 
     var loadingTask = pdfjsLib.getDocument(parameters);
     this.pdfLoadingTask = loadingTask;
 
@@ -7562,17 +7550,17 @@ var PDFViewerApplication = {
 
     loadingTask.onProgress = function getDocumentProgress(progressData) {
       self.progress(progressData.loaded / progressData.total);
     };
 
     // Listen for unsupported features to trigger the fallback UI.
     loadingTask.onUnsupportedFeature = this.fallback.bind(this);
 
-    var result = loadingTask.promise.then(
+    return loadingTask.promise.then(
       function getDocumentCallback(pdfDocument) {
         self.load(pdfDocument, scale);
       },
       function getDocumentError(exception) {
         var message = exception && exception.message;
         var loadingErrorMessage = mozL10n.get('loading_error', null,
           'An error occurred while loading the PDF.');
 
@@ -7592,21 +7580,16 @@ var PDFViewerApplication = {
         var moreInfo = {
           message: message
         };
         self.error(loadingErrorMessage, moreInfo);
 
         throw new Error(loadingErrorMessage);
       }
     );
-
-    if (args && args.length) {
-      PDFViewerApplication.pdfDocumentProperties.setFileSize(args.length);
-    }
-    return result;
   },
 
   download: function pdfViewDownload() {
     function downloadByUrl() {
       downloadManager.downloadUrl(url, filename);
     }
 
     var url = this.url.split('#')[0];
@@ -7728,21 +7711,19 @@ var PDFViewerApplication = {
 
     this.pdfDocumentProperties.setDocumentAndUrl(pdfDocument, this.url);
 
     var downloadedPromise = pdfDocument.getDownloadInfo().then(function() {
       self.downloadComplete = true;
       self.loadingBar.hide();
     });
 
-    var pagesCount = pdfDocument.numPages;
-    var toolbarConfig = this.appConfig.toolbar;
-    toolbarConfig.numPages.textContent =
-      mozL10n.get('page_of', {pageCount: pagesCount}, 'of {{pageCount}}');
-    toolbarConfig.pageNumber.max = pagesCount;
+    this._updateUIToolbar({
+      resetNumPages: true,
+    });
 
     var id = this.documentFingerprint = pdfDocument.fingerprint;
     var store = this.store = new ViewHistory(id);
 
     var baseDocumentUrl = this.url.split('#')[0];
     this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl);
 
     var pdfViewer = this.pdfViewer;
@@ -7930,20 +7911,16 @@ var PDFViewerApplication = {
   },
 
   setInitialView: function pdfViewSetInitialView(storedHash, options) {
     var scale = options && options.scale;
     var sidebarView = options && options.sidebarView;
 
     this.isInitialViewSet = true;
 
-    // When opening a new file, when one is already loaded in the viewer,
-    // ensure that the 'pageNumber' element displays the correct value.
-    this.appConfig.toolbar.pageNumber.value = this.pdfViewer.currentPageNumber;
-
     this.pdfSidebar.setInitialView(this.preferenceSidebarViewOnLoad ||
                                    (sidebarView | 0));
 
     if (this.initialDestination) {
       this.pdfLinkService.navigateTo(this.initialDestination);
       this.initialDestination = null;
     } else if (this.initialBookmark) {
       this.pdfLinkService.setHash(this.initialBookmark);
@@ -8097,16 +8074,77 @@ var PDFViewerApplication = {
    */
   scrollPresentationMode: function pdfViewScrollPresentationMode(delta) {
     if (!this.pdfPresentationMode) {
       return;
     }
     this.pdfPresentationMode.mouseScroll(delta);
   },
 
+  /**
+   * @typedef UpdateUIToolbarParameters
+   * @property {number} pageNumber
+   * @property {string} scaleValue
+   * @property {scale} scale
+   * @property {boolean} resetNumPages
+   */
+
+  /**
+   * @param {Object} UpdateUIToolbarParameters
+   * @private
+   */
+  _updateUIToolbar: function (params) {
+    function selectScaleOption(value, scale) {
+      var options = toolbarConfig.scaleSelect.options;
+      var predefinedValueFound = false;
+      for (var i = 0, ii = options.length; i < ii; i++) {
+        var option = options[i];
+        if (option.value !== value) {
+          option.selected = false;
+          continue;
+        }
+        option.selected = true;
+        predefinedValueFound = true;
+      }
+      if (!predefinedValueFound) {
+        var customScale = Math.round(scale * 10000) / 100;
+        toolbarConfig.customScaleOption.textContent =
+          mozL10n.get('page_scale_percent', {scale: customScale}, '{{scale}}%');
+        toolbarConfig.customScaleOption.selected = true;
+      }
+    }
+
+    var pageNumber = params.pageNumber || this.pdfViewer.currentPageNumber;
+    var scaleValue = (params.scaleValue || params.scale ||
+      this.pdfViewer.currentScaleValue || DEFAULT_SCALE_VALUE).toString();
+    var scale = params.scale || this.pdfViewer.currentScale;
+    var resetNumPages = params.resetNumPages || false;
+
+    var toolbarConfig = this.appConfig.toolbar;
+    var pagesCount = this.pagesCount;
+
+    if (resetNumPages) {
+      toolbarConfig.numPages.textContent =
+        mozL10n.get('page_of', { pageCount: pagesCount }, 'of {{pageCount}}');
+      toolbarConfig.pageNumber.max = pagesCount;
+    }
+    toolbarConfig.pageNumber.value = pageNumber;
+
+    toolbarConfig.previous.disabled = (pageNumber <= 1);
+    toolbarConfig.next.disabled = (pageNumber >= pagesCount);
+
+    toolbarConfig.firstPage.disabled = (pageNumber <= 1);
+    toolbarConfig.lastPage.disabled = (pageNumber >= pagesCount);
+
+    toolbarConfig.zoomOut.disabled = (scale === MIN_SCALE);
+    toolbarConfig.zoomIn.disabled = (scale === MAX_SCALE);
+
+    selectScaleOption(scaleValue, scale);
+  },
+
   bindEvents: function pdfViewBindEvents() {
     var eventBus = this.eventBus;
 
     eventBus.on('resize', webViewerResize);
     eventBus.on('localized', webViewerLocalized);
     eventBus.on('hashchange', webViewerHashchange);
     eventBus.on('beforeprint', this.beforePrint.bind(this));
     eventBus.on('afterprint', this.afterPrint.bind(this));
@@ -8532,31 +8570,16 @@ function webViewerHashchange(e) {
       PDFViewerApplication.initialBookmark = hash;
     } else {
       PDFViewerApplication.pdfLinkService.setHash(hash);
     }
   }
 }
 
 
-function selectScaleOption(value) {
-  var options = PDFViewerApplication.appConfig.toolbar.scaleSelect.options;
-  var predefinedValueFound = false;
-  for (var i = 0, ii = options.length; i < ii; i++) {
-    var option = options[i];
-    if (option.value !== value) {
-      option.selected = false;
-      continue;
-    }
-    option.selected = true;
-    predefinedValueFound = true;
-  }
-  return predefinedValueFound;
-}
-
 window.addEventListener('localized', function localized(evt) {
   PDFViewerApplication.eventBus.dispatch('localized');
 });
 
 function webViewerLocalized() {
   document.getElementsByTagName('html')[0].dir = mozL10n.getDirection();
 
   PDFViewerApplication.animationStartedPromise.then(function() {
@@ -8632,52 +8655,37 @@ function webViewerFindFromUrlHash(e) {
     phraseSearch: e.phraseSearch,
     caseSensitive: false,
     highlightAll: true,
     findPrevious: false
   });
 }
 
 function webViewerScaleChanging(e) {
-  var appConfig = PDFViewerApplication.appConfig;
-  appConfig.toolbar.zoomOut.disabled = (e.scale === MIN_SCALE);
-  appConfig.toolbar.zoomIn.disabled = (e.scale === MAX_SCALE);
-
-  // Update the 'scaleSelect' DOM element.
-  var predefinedValueFound = selectScaleOption(e.presetValue ||
-                                               '' + e.scale);
-  if (!predefinedValueFound) {
-    var customScaleOption = appConfig.toolbar.customScaleOption;
-    var customScale = Math.round(e.scale * 10000) / 100;
-    customScaleOption.textContent =
-      mozL10n.get('page_scale_percent', { scale: customScale }, '{{scale}}%');
-    customScaleOption.selected = true;
-  }
+  PDFViewerApplication._updateUIToolbar({
+    scaleValue: e.presetValue,
+    scale: e.scale,
+  });
+
   if (!PDFViewerApplication.initialized) {
     return;
   }
   PDFViewerApplication.pdfViewer.update();
 }
 
 function webViewerPageChanging(e) {
   var page = e.pageNumber;
-  if (e.previousPageNumber !== page) {
-    PDFViewerApplication.appConfig.toolbar.pageNumber.value = page;
-
-    if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
-      PDFViewerApplication.pdfThumbnailViewer.scrollThumbnailIntoView(page);
-    }
-  }
-  var numPages = PDFViewerApplication.pagesCount;
-
-  PDFViewerApplication.appConfig.toolbar.previous.disabled = (page <= 1);
-  PDFViewerApplication.appConfig.toolbar.next.disabled = (page >= numPages);
-
-  PDFViewerApplication.appConfig.toolbar.firstPage.disabled = (page <= 1);
-  PDFViewerApplication.appConfig.toolbar.lastPage.disabled = (page >= numPages);
+
+  PDFViewerApplication._updateUIToolbar({
+    pageNumber: page,
+  });
+  if (e.previousPageNumber !== page &&
+      PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
+    PDFViewerApplication.pdfThumbnailViewer.scrollThumbnailIntoView(page);
+  }
 
   // we need to update stats
   if (pdfjsLib.PDFJS.pdfBug && Stats.enabled) {
     var pageView = PDFViewerApplication.pdfViewer.getPageView(page - 1);
     if (pageView.stats) {
       Stats.add(page, pageView.stats);
     }
   }