From f880e3efcaa0e924349dd0ee0cdc7214d5ba76ad Mon Sep 17 00:00:00 2001 From: Ryan VanderMeulen Date: Mon, 8 Apr 2019 08:51:19 -0400 Subject: [PATCH] Bug 1542737 - Update pdf.js to version 2.2.129. r=bdahl --- browser/extensions/pdfjs/README.mozilla | 4 +- browser/extensions/pdfjs/content/build/pdf.js | 48 ++++++++++++++----- .../pdfjs/content/build/pdf.worker.js | 28 +++++++++-- .../extensions/pdfjs/content/web/viewer.js | 26 +++++++++- browser/extensions/pdfjs/moz.yaml | 2 +- 5 files changed, 88 insertions(+), 20 deletions(-) diff --git a/browser/extensions/pdfjs/README.mozilla b/browser/extensions/pdfjs/README.mozilla index f9b9c10b11bd..f2e596d2a094 100644 --- a/browser/extensions/pdfjs/README.mozilla +++ b/browser/extensions/pdfjs/README.mozilla @@ -1,5 +1,5 @@ This is the PDF.js project output, https://github.com/mozilla/pdf.js -Current extension version is: 2.2.117 +Current extension version is: 2.2.129 -Taken from upstream commit: 57abddc9 +Taken from upstream commit: 725a6959 diff --git a/browser/extensions/pdfjs/content/build/pdf.js b/browser/extensions/pdfjs/content/build/pdf.js index 95ec071bc733..7e08f5b03e7e 100644 --- a/browser/extensions/pdfjs/content/build/pdf.js +++ b/browser/extensions/pdfjs/content/build/pdf.js @@ -123,8 +123,8 @@ return /******/ (function(modules) { // webpackBootstrap "use strict"; -var pdfjsVersion = '2.2.117'; -var pdfjsBuild = '57abddc9'; +var pdfjsVersion = '2.2.129'; +var pdfjsBuild = '725a6959'; var pdfjsSharedUtil = __w_pdfjs_require__(1); @@ -1303,7 +1303,7 @@ function _fetchDocument(worker, source, pdfDataRangeTransport, docId) { return worker.messageHandler.sendWithPromise('GetDocRequest', { docId, - apiVersion: '2.2.117', + apiVersion: '2.2.129', source: { data: source.data, url: source.url, @@ -1406,10 +1406,10 @@ class PDFDataRangeTransport { } } - onDataProgress(loaded) { + onDataProgress(loaded, total) { this._readyCapability.promise.then(() => { for (const listener of this._progressListeners) { - listener(loaded); + listener(loaded, total); } }); } @@ -1478,6 +1478,10 @@ class PDFDocumentProxy { return this._transport.getPageLabels(); } + getPageLayout() { + return this._transport.getPageLayout(); + } + getPageMode() { return this._transport.getPageMode(); } @@ -2761,6 +2765,10 @@ class WorkerTransport { return this.messageHandler.sendWithPromise('GetPageLabels', null); } + getPageLayout() { + return this.messageHandler.sendWithPromise('GetPageLayout', null); + } + getPageMode() { return this.messageHandler.sendWithPromise('GetPageMode', null); } @@ -3075,9 +3083,9 @@ const InternalRenderTask = function InternalRenderTaskClosure() { return InternalRenderTask; }(); -const version = '2.2.117'; +const version = '2.2.129'; exports.version = version; -const build = '57abddc9'; +const build = '725a6959'; exports.build = build; /***/ }), @@ -4591,8 +4599,11 @@ var CanvasGraphics = function CanvasGraphicsClosure() { ctx.lineDashOffset = dashPhase; } }, - setRenderingIntent: function CanvasGraphics_setRenderingIntent(intent) {}, - setFlatness: function CanvasGraphics_setFlatness(flatness) {}, + + setRenderingIntent(intent) {}, + + setFlatness(flatness) {}, + setGState: function CanvasGraphics_setGState(states) { for (var i = 0, ii = states.length; i < ii; i++) { var state = states[i]; @@ -7337,9 +7348,10 @@ var PDFDataTransportStream = function PDFDataTransportStreamClosure() { }); }); - this._pdfDataRangeTransport.addProgressListener(loaded => { + this._pdfDataRangeTransport.addProgressListener((loaded, total) => { this._onProgress({ - loaded + loaded, + total }); }); @@ -7381,15 +7393,25 @@ var PDFDataTransportStream = function PDFDataTransportStreamClosure() { } }, _onProgress: function PDFDataTransportStream_onDataProgress(evt) { - if (this._rangeReaders.length > 0) { + if (evt.total === undefined && this._rangeReaders.length > 0) { var firstReader = this._rangeReaders[0]; if (firstReader.onProgress) { firstReader.onProgress({ loaded: evt.loaded }); + return; } } + + let fullReader = this._fullRequestReader; + + if (fullReader && fullReader.onProgress) { + fullReader.onProgress({ + loaded: evt.loaded, + total: evt.total + }); + } }, _onProgressiveDone() { @@ -9730,7 +9752,7 @@ var _is_node = _interopRequireDefault(__w_pdfjs_require__(21)); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } -var SVGGraphics = function () { +let SVGGraphics = function () { throw new Error('Not implemented: SVGGraphics'); }; diff --git a/browser/extensions/pdfjs/content/build/pdf.worker.js b/browser/extensions/pdfjs/content/build/pdf.worker.js index 7268779243d0..0859d18039ea 100644 --- a/browser/extensions/pdfjs/content/build/pdf.worker.js +++ b/browser/extensions/pdfjs/content/build/pdf.worker.js @@ -123,8 +123,8 @@ return /******/ (function(modules) { // webpackBootstrap "use strict"; -const pdfjsVersion = '2.2.117'; -const pdfjsBuild = '57abddc9'; +const pdfjsVersion = '2.2.129'; +const pdfjsBuild = '725a6959'; const pdfjsCoreWorker = __w_pdfjs_require__(1); @@ -378,7 +378,7 @@ var WorkerMessageHandler = { var WorkerTasks = []; const verbosity = (0, _util.getVerbosityLevel)(); let apiVersion = docParams.apiVersion; - let workerVersion = '2.2.117'; + let workerVersion = '2.2.129'; if (apiVersion !== workerVersion) { throw new Error(`The API version "${apiVersion}" does not match ` + `the Worker version "${workerVersion}".`); @@ -644,6 +644,9 @@ var WorkerMessageHandler = { handler.on('GetPageLabels', function wphSetupGetPageLabels(data) { return pdfManager.ensureCatalog('pageLabels'); }); + handler.on('GetPageLayout', function wphSetupGetPageLayout(data) { + return pdfManager.ensureCatalog('pageLayout'); + }); handler.on('GetPageMode', function wphSetupGetPageMode(data) { return pdfManager.ensureCatalog('pageMode'); }); @@ -3747,6 +3750,25 @@ class Catalog { return pageLabels; } + get pageLayout() { + const obj = this.catDict.get('PageLayout'); + let pageLayout = ''; + + if ((0, _primitives.isName)(obj)) { + switch (obj.name) { + case 'SinglePage': + case 'OneColumn': + case 'TwoColumnLeft': + case 'TwoColumnRight': + case 'TwoPageLeft': + case 'TwoPageRight': + pageLayout = obj.name; + } + } + + return (0, _util.shadow)(this, 'pageLayout', pageLayout); + } + get pageMode() { const obj = this.catDict.get('PageMode'); let pageMode = 'UseNone'; diff --git a/browser/extensions/pdfjs/content/web/viewer.js b/browser/extensions/pdfjs/content/web/viewer.js index 31000c880eff..65627260c834 100644 --- a/browser/extensions/pdfjs/content/web/viewer.js +++ b/browser/extensions/pdfjs/content/web/viewer.js @@ -1017,6 +1017,7 @@ let PDFViewerApplication = { }); }); }); + const pageLayoutPromise = pdfDocument.getPageLayout().catch(function () {}); const pageModePromise = pdfDocument.getPageMode().catch(function () {}); const openActionDestPromise = pdfDocument.getOpenActionDestination().catch(function () {}); this.toolbar.setPagesCount(pdfDocument.numPages, false); @@ -1045,7 +1046,7 @@ let PDFViewerApplication = { scrollMode: _ui_utils.ScrollMode.UNKNOWN, spreadMode: _ui_utils.SpreadMode.UNKNOWN }).catch(() => {}); - Promise.all([storePromise, pageModePromise, openActionDestPromise]).then(async ([values = {}, pageMode, openActionDest]) => { + Promise.all([storePromise, pageLayoutPromise, pageModePromise, openActionDestPromise]).then(async ([values = {}, pageLayout, pageMode, openActionDest]) => { const viewOnLoad = _app_options.AppOptions.get('viewOnLoad'); this._initializePdfHistory({ @@ -1088,6 +1089,10 @@ let PDFViewerApplication = { sidebarView = apiPageModeToSidebarView(pageMode); } + if (pageLayout && spreadMode === _ui_utils.SpreadMode.UNKNOWN) { + spreadMode = apiPageLayoutToSpreadMode(pageLayout); + } + this.setInitialView(hash, { rotation, sidebarView, @@ -2340,6 +2345,24 @@ function webViewerKeyDown(evt) { } } +function apiPageLayoutToSpreadMode(layout) { + switch (layout) { + case 'SinglePage': + case 'OneColumn': + return _ui_utils.SpreadMode.NONE; + + case 'TwoColumnLeft': + case 'TwoPageLeft': + return _ui_utils.SpreadMode.ODD; + + case 'TwoColumnRight': + case 'TwoPageRight': + return _ui_utils.SpreadMode.EVEN; + } + + return _ui_utils.SpreadMode.NONE; +} + function apiPageModeToSidebarView(mode) { switch (mode) { case 'UseNone': @@ -11405,6 +11428,7 @@ _app.PDFViewerApplication.externalServices = { case 'progressiveRead': pdfDataRangeTransport.onDataProgressiveRead(args.chunk); + pdfDataRangeTransport.onDataProgress(args.loaded, args.total); break; case 'progressiveDone': diff --git a/browser/extensions/pdfjs/moz.yaml b/browser/extensions/pdfjs/moz.yaml index 1856197c301a..2a4f320368b3 100644 --- a/browser/extensions/pdfjs/moz.yaml +++ b/browser/extensions/pdfjs/moz.yaml @@ -20,7 +20,7 @@ origin: # Human-readable identifier for this version/release # Generally "version NNN", "tag SSS", "bookmark SSS" - release: version 2.2.117 + release: version 2.2.129 # The package's license, where possible using the mnemonic from # https://spdx.org/licenses/