diff --git a/browser/extensions/pdfjs/README.mozilla b/browser/extensions/pdfjs/README.mozilla index e6f17173aa17..15117b725ce3 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.1.132 +Current extension version is: 2.1.145 -Taken from upstream commit: d3868e1b +Taken from upstream commit: d8f201ea diff --git a/browser/extensions/pdfjs/content/build/pdf.js b/browser/extensions/pdfjs/content/build/pdf.js index df3fa5f3b85b..13c8c4244f1e 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.1.132'; -var pdfjsBuild = 'd3868e1b'; +var pdfjsVersion = '2.1.145'; +var pdfjsBuild = 'd8f201ea'; var pdfjsSharedUtil = __w_pdfjs_require__(1); @@ -235,7 +235,7 @@ Object.defineProperty(exports, "URL", { return _url_polyfill.URL; } }); -exports.createObjectURL = exports.FormatError = exports.XRefParseException = exports.Util = exports.UnknownErrorException = exports.UnexpectedResponseException = exports.TextRenderingMode = exports.StreamType = exports.PermissionFlag = exports.PasswordResponses = exports.PasswordException = exports.NativeImageDecoding = exports.MissingPDFException = exports.MissingDataException = exports.InvalidPDFException = exports.AbortException = exports.CMapCompressionType = exports.ImageKind = exports.FontType = exports.AnnotationType = exports.AnnotationFlag = exports.AnnotationFieldFlag = exports.AnnotationBorderStyleType = exports.UNSUPPORTED_FEATURES = exports.VerbosityLevel = exports.OPS = exports.IDENTITY_MATRIX = exports.FONT_IDENTITY_MATRIX = void 0; +exports.createObjectURL = exports.FormatError = exports.XRefParseException = exports.XRefEntryException = exports.Util = exports.UnknownErrorException = exports.UnexpectedResponseException = exports.TextRenderingMode = exports.StreamType = exports.PermissionFlag = exports.PasswordResponses = exports.PasswordException = exports.NativeImageDecoding = exports.MissingPDFException = exports.MissingDataException = exports.InvalidPDFException = exports.AbortException = exports.CMapCompressionType = exports.ImageKind = exports.FontType = exports.AnnotationType = exports.AnnotationFlag = exports.AnnotationFieldFlag = exports.AnnotationBorderStyleType = exports.UNSUPPORTED_FEATURES = exports.VerbosityLevel = exports.OPS = exports.IDENTITY_MATRIX = exports.FONT_IDENTITY_MATRIX = void 0; __w_pdfjs_require__(2); @@ -695,6 +695,19 @@ var MissingDataException = function MissingDataExceptionClosure() { exports.MissingDataException = MissingDataException; +const XRefEntryException = function XRefEntryExceptionClosure() { + function XRefEntryException(msg) { + this.message = msg; + } + + XRefEntryException.prototype = new Error(); + XRefEntryException.prototype.name = 'XRefEntryException'; + XRefEntryException.constructor = XRefEntryException; + return XRefEntryException; +}(); + +exports.XRefEntryException = XRefEntryException; + var XRefParseException = function XRefParseExceptionClosure() { function XRefParseException(msg) { this.message = msg; @@ -5141,7 +5154,7 @@ function _fetchDocument(worker, source, pdfDataRangeTransport, docId) { return worker.messageHandler.sendWithPromise('GetDocRequest', { docId, - apiVersion: '2.1.132', + apiVersion: '2.1.145', source: { data: source.data, url: source.url, @@ -6872,9 +6885,9 @@ const InternalRenderTask = function InternalRenderTaskClosure() { return InternalRenderTask; }(); -const version = '2.1.132'; +const version = '2.1.145'; exports.version = version; -const build = 'd3868e1b'; +const build = 'd8f201ea'; exports.build = build; /***/ }), @@ -8784,11 +8797,10 @@ var CanvasGraphics = function CanvasGraphicsClosure() { var name = fontObj.loadedName || 'sans-serif'; var bold = fontObj.black ? '900' : fontObj.bold ? 'bold' : 'normal'; var italic = fontObj.italic ? 'italic' : 'normal'; - var typeface = '"' + name + '", ' + fontObj.fallbackName; + var typeface = `"${name}", ${fontObj.fallbackName}`; var browserFontSize = size < MIN_FONT_SIZE ? MIN_FONT_SIZE : size > MAX_FONT_SIZE ? MAX_FONT_SIZE : size; this.current.fontSizeScale = size / browserFontSize; - var rule = italic + ' ' + bold + ' ' + browserFontSize + 'px ' + typeface; - this.ctx.font = rule; + this.ctx.font = `${italic} ${bold} ${browserFontSize}px ${typeface}`; }, setTextRenderingMode: function CanvasGraphics_setTextRenderingMode(mode) { this.current.textRenderingMode = mode; @@ -12344,14 +12356,14 @@ var renderTextLayer = function renderTextLayerClosure() { if (textDivProperties.canvasWidth !== 0 && width > 0) { textDivProperties.scale = textDivProperties.canvasWidth / width; - transform = 'scaleX(' + textDivProperties.scale + ')'; + transform = `scaleX(${textDivProperties.scale})`; } if (textDivProperties.angle !== 0) { - transform = 'rotate(' + textDivProperties.angle + 'deg) ' + transform; + transform = `rotate(${textDivProperties.angle}deg) ${transform}`; } - if (transform !== '') { + if (transform.length > 0) { textDivProperties.originalTransform = transform; textDiv.style.transform = transform; } diff --git a/browser/extensions/pdfjs/content/build/pdf.worker.js b/browser/extensions/pdfjs/content/build/pdf.worker.js index 76eb4042fd76..93d4c0f864eb 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"; -var pdfjsVersion = '2.1.132'; -var pdfjsBuild = 'd3868e1b'; +var pdfjsVersion = '2.1.145'; +var pdfjsBuild = 'd8f201ea'; var pdfjsCoreWorker = __w_pdfjs_require__(1); @@ -375,7 +375,7 @@ var WorkerMessageHandler = { var cancelXHRs = null; var WorkerTasks = []; let apiVersion = docParams.apiVersion; - let workerVersion = '2.1.132'; + let workerVersion = '2.1.145'; if (apiVersion !== workerVersion) { throw new Error(`The API version "${apiVersion}" does not match ` + `the Worker version "${workerVersion}".`); @@ -403,28 +403,20 @@ var WorkerMessageHandler = { WorkerTasks.splice(i, 1); } - function loadDocument(recoveryMode) { - var loadDocumentCapability = (0, _util.createPromiseCapability)(); + async function loadDocument(recoveryMode) { + await pdfManager.ensureDoc('checkHeader'); + await pdfManager.ensureDoc('parseStartXRef'); + await pdfManager.ensureDoc('parse', [recoveryMode]); - var parseSuccess = function parseSuccess() { - Promise.all([pdfManager.ensureDoc('numPages'), pdfManager.ensureDoc('fingerprint')]).then(function ([numPages, fingerprint]) { - loadDocumentCapability.resolve({ - numPages, - fingerprint - }); - }, parseFailure); + if (!recoveryMode) { + await pdfManager.ensureDoc('checkFirstPage'); + } + + const [numPages, fingerprint] = await Promise.all([pdfManager.ensureDoc('numPages'), pdfManager.ensureDoc('fingerprint')]); + return { + numPages, + fingerprint }; - - var parseFailure = function parseFailure(e) { - loadDocumentCapability.reject(e); - }; - - pdfManager.ensureDoc('checkHeader', []).then(function () { - pdfManager.ensureDoc('parseStartXRef', []).then(function () { - pdfManager.ensureDoc('parse', [recoveryMode]).then(parseSuccess, parseFailure); - }, parseFailure); - }, parseFailure); - return loadDocumentCapability.promise; } function getPdfManager(data, evaluatorOptions) { @@ -880,7 +872,7 @@ Object.defineProperty(exports, "URL", { return _url_polyfill.URL; } }); -exports.createObjectURL = exports.FormatError = exports.XRefParseException = exports.Util = exports.UnknownErrorException = exports.UnexpectedResponseException = exports.TextRenderingMode = exports.StreamType = exports.PermissionFlag = exports.PasswordResponses = exports.PasswordException = exports.NativeImageDecoding = exports.MissingPDFException = exports.MissingDataException = exports.InvalidPDFException = exports.AbortException = exports.CMapCompressionType = exports.ImageKind = exports.FontType = exports.AnnotationType = exports.AnnotationFlag = exports.AnnotationFieldFlag = exports.AnnotationBorderStyleType = exports.UNSUPPORTED_FEATURES = exports.VerbosityLevel = exports.OPS = exports.IDENTITY_MATRIX = exports.FONT_IDENTITY_MATRIX = void 0; +exports.createObjectURL = exports.FormatError = exports.XRefParseException = exports.XRefEntryException = exports.Util = exports.UnknownErrorException = exports.UnexpectedResponseException = exports.TextRenderingMode = exports.StreamType = exports.PermissionFlag = exports.PasswordResponses = exports.PasswordException = exports.NativeImageDecoding = exports.MissingPDFException = exports.MissingDataException = exports.InvalidPDFException = exports.AbortException = exports.CMapCompressionType = exports.ImageKind = exports.FontType = exports.AnnotationType = exports.AnnotationFlag = exports.AnnotationFieldFlag = exports.AnnotationBorderStyleType = exports.UNSUPPORTED_FEATURES = exports.VerbosityLevel = exports.OPS = exports.IDENTITY_MATRIX = exports.FONT_IDENTITY_MATRIX = void 0; __w_pdfjs_require__(3); @@ -1340,6 +1332,19 @@ var MissingDataException = function MissingDataExceptionClosure() { exports.MissingDataException = MissingDataException; +const XRefEntryException = function XRefEntryExceptionClosure() { + function XRefEntryException(msg) { + this.message = msg; + } + + XRefEntryException.prototype = new Error(); + XRefEntryException.prototype.name = 'XRefEntryException'; + XRefEntryException.constructor = XRefEntryException; + return XRefEntryException; +}(); + +exports.XRefEntryException = XRefEntryException; + var XRefParseException = function XRefParseExceptionClosure() { function XRefParseException(msg) { this.message = msg; @@ -6372,15 +6377,15 @@ var _evaluator = __w_pdfjs_require__(28); var _function = __w_pdfjs_require__(42); -var Page = function PageClosure() { - var DEFAULT_USER_UNIT = 1.0; - var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792]; +const DEFAULT_USER_UNIT = 1.0; +const LETTER_SIZE_MEDIABOX = [0, 0, 612, 792]; - function isAnnotationRenderable(annotation, intent) { - return intent === 'display' && annotation.viewable || intent === 'print' && annotation.printable; - } +function isAnnotationRenderable(annotation, intent) { + return intent === 'display' && annotation.viewable || intent === 'print' && annotation.printable; +} - function Page({ +class Page { + constructor({ pdfManager, xref, pageIndex, @@ -6400,8 +6405,8 @@ var Page = function PageClosure() { this.pdfFunctionFactory = pdfFunctionFactory; this.evaluatorOptions = pdfManager.evaluatorOptions; this.resourcesPromise = null; - var uniquePrefix = 'p' + this.pageIndex + '_'; - var idCounters = { + const uniquePrefix = `p${this.pageIndex}_`; + const idCounters = { obj: 0 }; this.idFactory = { @@ -6412,134 +6417,199 @@ var Page = function PageClosure() { }; } - Page.prototype = { - _getInheritableProperty(key, getArray = false) { - let value = (0, _util.getInheritableProperty)({ - dict: this.pageDict, - key, - getArray, - stopWhenFound: false - }); + _getInheritableProperty(key, getArray = false) { + const value = (0, _util.getInheritableProperty)({ + dict: this.pageDict, + key, + getArray, + stopWhenFound: false + }); - if (!Array.isArray(value)) { - return value; - } + if (!Array.isArray(value)) { + return value; + } - if (value.length === 1 || !(0, _primitives.isDict)(value[0])) { - return value[0]; - } + if (value.length === 1 || !(0, _primitives.isDict)(value[0])) { + return value[0]; + } - return _primitives.Dict.merge(this.xref, value); - }, + return _primitives.Dict.merge(this.xref, value); + } - get content() { - return this.pageDict.get('Contents'); - }, + get content() { + return this.pageDict.get('Contents'); + } - get resources() { - return (0, _util.shadow)(this, 'resources', this._getInheritableProperty('Resources') || _primitives.Dict.empty); - }, + get resources() { + return (0, _util.shadow)(this, 'resources', this._getInheritableProperty('Resources') || _primitives.Dict.empty); + } - get mediaBox() { - var mediaBox = this._getInheritableProperty('MediaBox', true); + get mediaBox() { + const mediaBox = this._getInheritableProperty('MediaBox', true); - if (!Array.isArray(mediaBox) || mediaBox.length !== 4) { - return (0, _util.shadow)(this, 'mediaBox', LETTER_SIZE_MEDIABOX); - } + if (!Array.isArray(mediaBox) || mediaBox.length !== 4) { + return (0, _util.shadow)(this, 'mediaBox', LETTER_SIZE_MEDIABOX); + } - return (0, _util.shadow)(this, 'mediaBox', mediaBox); - }, + return (0, _util.shadow)(this, 'mediaBox', mediaBox); + } - get cropBox() { - var cropBox = this._getInheritableProperty('CropBox', true); + get cropBox() { + const cropBox = this._getInheritableProperty('CropBox', true); - if (!Array.isArray(cropBox) || cropBox.length !== 4) { - return (0, _util.shadow)(this, 'cropBox', this.mediaBox); - } + if (!Array.isArray(cropBox) || cropBox.length !== 4) { + return (0, _util.shadow)(this, 'cropBox', this.mediaBox); + } - return (0, _util.shadow)(this, 'cropBox', cropBox); - }, + return (0, _util.shadow)(this, 'cropBox', cropBox); + } - get userUnit() { - var obj = this.pageDict.get('UserUnit'); + get userUnit() { + let obj = this.pageDict.get('UserUnit'); - if (!(0, _util.isNum)(obj) || obj <= 0) { - obj = DEFAULT_USER_UNIT; - } + if (!(0, _util.isNum)(obj) || obj <= 0) { + obj = DEFAULT_USER_UNIT; + } - return (0, _util.shadow)(this, 'userUnit', obj); - }, + return (0, _util.shadow)(this, 'userUnit', obj); + } - get view() { - var mediaBox = this.mediaBox, + get view() { + const mediaBox = this.mediaBox, cropBox = this.cropBox; - if (mediaBox === cropBox) { - return (0, _util.shadow)(this, 'view', mediaBox); + if (mediaBox === cropBox) { + return (0, _util.shadow)(this, 'view', mediaBox); + } + + const intersection = _util.Util.intersect(cropBox, mediaBox); + + return (0, _util.shadow)(this, 'view', intersection || mediaBox); + } + + get rotate() { + let rotate = this._getInheritableProperty('Rotate') || 0; + + if (rotate % 90 !== 0) { + rotate = 0; + } else if (rotate >= 360) { + rotate = rotate % 360; + } else if (rotate < 0) { + rotate = (rotate % 360 + 360) % 360; + } + + return (0, _util.shadow)(this, 'rotate', rotate); + } + + getContentStream() { + const content = this.content; + let stream; + + if (Array.isArray(content)) { + const xref = this.xref; + const streams = []; + + for (const stream of content) { + streams.push(xref.fetchIfRef(stream)); } - var intersection = _util.Util.intersect(cropBox, mediaBox); + stream = new _stream.StreamsSequenceStream(streams); + } else if ((0, _primitives.isStream)(content)) { + stream = content; + } else { + stream = new _stream.NullStream(); + } - return (0, _util.shadow)(this, 'view', intersection || mediaBox); - }, + return stream; + } - get rotate() { - var rotate = this._getInheritableProperty('Rotate') || 0; + loadResources(keys) { + if (!this.resourcesPromise) { + this.resourcesPromise = this.pdfManager.ensure(this, 'resources'); + } - if (rotate % 90 !== 0) { - rotate = 0; - } else if (rotate >= 360) { - rotate = rotate % 360; - } else if (rotate < 0) { - rotate = (rotate % 360 + 360) % 360; + return this.resourcesPromise.then(() => { + const objectLoader = new _obj.ObjectLoader(this.resources, keys, this.xref); + return objectLoader.load(); + }); + } + + getOperatorList({ + handler, + task, + intent, + renderInteractiveForms + }) { + const contentStreamPromise = this.pdfManager.ensure(this, 'getContentStream'); + const resourcesPromise = this.loadResources(['ExtGState', 'ColorSpace', 'Pattern', 'Shading', 'XObject', 'Font']); + const partialEvaluator = new _evaluator.PartialEvaluator({ + pdfManager: this.pdfManager, + xref: this.xref, + handler, + pageIndex: this.pageIndex, + idFactory: this.idFactory, + fontCache: this.fontCache, + builtInCMapCache: this.builtInCMapCache, + options: this.evaluatorOptions, + pdfFunctionFactory: this.pdfFunctionFactory + }); + const dataPromises = Promise.all([contentStreamPromise, resourcesPromise]); + const pageListPromise = dataPromises.then(([contentStream]) => { + const opList = new _operator_list.OperatorList(intent, handler, this.pageIndex); + handler.send('StartRenderPage', { + transparency: partialEvaluator.hasBlendModes(this.resources), + pageIndex: this.pageIndex, + intent + }); + return partialEvaluator.getOperatorList({ + stream: contentStream, + task, + resources: this.resources, + operatorList: opList + }).then(function () { + return opList; + }); + }); + return Promise.all([pageListPromise, this._parsedAnnotations]).then(function ([pageOpList, annotations]) { + if (annotations.length === 0) { + pageOpList.flush(true); + return pageOpList; } - return (0, _util.shadow)(this, 'rotate', rotate); - }, + const opListPromises = []; - getContentStream: function Page_getContentStream() { - var content = this.content; - var stream; + for (const annotation of annotations) { + if (isAnnotationRenderable(annotation, intent)) { + opListPromises.push(annotation.getOperatorList(partialEvaluator, task, renderInteractiveForms)); + } + } - if (Array.isArray(content)) { - var xref = this.xref; - var i, - n = content.length; - var streams = []; + return Promise.all(opListPromises).then(function (opLists) { + pageOpList.addOp(_util.OPS.beginAnnotations, []); - for (i = 0; i < n; ++i) { - streams.push(xref.fetchIfRef(content[i])); + for (const opList of opLists) { + pageOpList.addOpList(opList); } - stream = new _stream.StreamsSequenceStream(streams); - } else if ((0, _primitives.isStream)(content)) { - stream = content; - } else { - stream = new _stream.NullStream(); - } - - return stream; - }, - loadResources: function Page_loadResources(keys) { - if (!this.resourcesPromise) { - this.resourcesPromise = this.pdfManager.ensure(this, 'resources'); - } - - return this.resourcesPromise.then(() => { - let objectLoader = new _obj.ObjectLoader(this.resources, keys, this.xref); - return objectLoader.load(); + pageOpList.addOp(_util.OPS.endAnnotations, []); + pageOpList.flush(true); + return pageOpList; }); - }, + }); + } - getOperatorList({ - handler, - task, - intent, - renderInteractiveForms - }) { - var contentStreamPromise = this.pdfManager.ensure(this, 'getContentStream'); - var resourcesPromise = this.loadResources(['ExtGState', 'ColorSpace', 'Pattern', 'Shading', 'XObject', 'Font']); - var partialEvaluator = new _evaluator.PartialEvaluator({ + extractTextContent({ + handler, + task, + normalizeWhitespace, + sink, + combineTextItems + }) { + const contentStreamPromise = this.pdfManager.ensure(this, 'getContentStream'); + const resourcesPromise = this.loadResources(['ExtGState', 'XObject', 'Font']); + const dataPromises = Promise.all([contentStreamPromise, resourcesPromise]); + return dataPromises.then(([contentStream]) => { + const partialEvaluator = new _evaluator.PartialEvaluator({ pdfManager: this.pdfManager, xref: this.xref, handler, @@ -6550,137 +6620,91 @@ var Page = function PageClosure() { options: this.evaluatorOptions, pdfFunctionFactory: this.pdfFunctionFactory }); - var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]); - var pageListPromise = dataPromises.then(([contentStream]) => { - var opList = new _operator_list.OperatorList(intent, handler, this.pageIndex); - handler.send('StartRenderPage', { - transparency: partialEvaluator.hasBlendModes(this.resources), - pageIndex: this.pageIndex, - intent - }); - return partialEvaluator.getOperatorList({ - stream: contentStream, - task, - resources: this.resources, - operatorList: opList - }).then(function () { - return opList; - }); + return partialEvaluator.getTextContent({ + stream: contentStream, + task, + resources: this.resources, + normalizeWhitespace, + combineTextItems, + sink }); - return Promise.all([pageListPromise, this._parsedAnnotations]).then(function ([pageOpList, annotations]) { - if (annotations.length === 0) { - pageOpList.flush(true); - return pageOpList; + }); + } + + getAnnotationsData(intent) { + return this._parsedAnnotations.then(function (annotations) { + const annotationsData = []; + + for (let i = 0, ii = annotations.length; i < ii; i++) { + if (!intent || isAnnotationRenderable(annotations[i], intent)) { + annotationsData.push(annotations[i].data); } + } - var i, - ii, - opListPromises = []; + return annotationsData; + }); + } - for (i = 0, ii = annotations.length; i < ii; i++) { - if (isAnnotationRenderable(annotations[i], intent)) { - opListPromises.push(annotations[i].getOperatorList(partialEvaluator, task, renderInteractiveForms)); - } - } + get annotations() { + return (0, _util.shadow)(this, 'annotations', this._getInheritableProperty('Annots') || []); + } - return Promise.all(opListPromises).then(function (opLists) { - pageOpList.addOp(_util.OPS.beginAnnotations, []); + get _parsedAnnotations() { + const parsedAnnotations = this.pdfManager.ensure(this, 'annotations').then(() => { + const annotationRefs = this.annotations; + const annotationPromises = []; - for (i = 0, ii = opLists.length; i < ii; i++) { - pageOpList.addOpList(opLists[i]); - } + for (let i = 0, ii = annotationRefs.length; i < ii; i++) { + annotationPromises.push(_annotation.AnnotationFactory.create(this.xref, annotationRefs[i], this.pdfManager, this.idFactory)); + } - pageOpList.addOp(_util.OPS.endAnnotations, []); - pageOpList.flush(true); - return pageOpList; + return Promise.all(annotationPromises).then(function (annotations) { + return annotations.filter(function isDefined(annotation) { + return !!annotation; }); + }, function (reason) { + (0, _util.warn)(`_parsedAnnotations: "${reason}".`); + return []; }); - }, + }); + return (0, _util.shadow)(this, '_parsedAnnotations', parsedAnnotations); + } - extractTextContent({ - handler, - task, - normalizeWhitespace, - sink, - combineTextItems - }) { - var contentStreamPromise = this.pdfManager.ensure(this, 'getContentStream'); - var resourcesPromise = this.loadResources(['ExtGState', 'XObject', 'Font']); - var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]); - return dataPromises.then(([contentStream]) => { - var partialEvaluator = new _evaluator.PartialEvaluator({ - pdfManager: this.pdfManager, - xref: this.xref, - handler, - pageIndex: this.pageIndex, - idFactory: this.idFactory, - fontCache: this.fontCache, - builtInCMapCache: this.builtInCMapCache, - options: this.evaluatorOptions, - pdfFunctionFactory: this.pdfFunctionFactory - }); - return partialEvaluator.getTextContent({ - stream: contentStream, - task, - resources: this.resources, - normalizeWhitespace, - combineTextItems, - sink - }); - }); - }, - - getAnnotationsData(intent) { - return this._parsedAnnotations.then(function (annotations) { - let annotationsData = []; - - for (let i = 0, ii = annotations.length; i < ii; i++) { - if (!intent || isAnnotationRenderable(annotations[i], intent)) { - annotationsData.push(annotations[i].data); - } - } - - return annotationsData; - }); - }, - - get annotations() { - return (0, _util.shadow)(this, 'annotations', this._getInheritableProperty('Annots') || []); - }, - - get _parsedAnnotations() { - const parsedAnnotations = this.pdfManager.ensure(this, 'annotations').then(() => { - const annotationRefs = this.annotations; - const annotationPromises = []; - - for (let i = 0, ii = annotationRefs.length; i < ii; i++) { - annotationPromises.push(_annotation.AnnotationFactory.create(this.xref, annotationRefs[i], this.pdfManager, this.idFactory)); - } - - return Promise.all(annotationPromises).then(function (annotations) { - return annotations.filter(function isDefined(annotation) { - return !!annotation; - }); - }, function (reason) { - (0, _util.warn)(`_parsedAnnotations: "${reason}".`); - return []; - }); - }); - return (0, _util.shadow)(this, '_parsedAnnotations', parsedAnnotations); - } - - }; - return Page; -}(); +} exports.Page = Page; +const FINGERPRINT_FIRST_BYTES = 1024; +const EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' + '\x00\x00\x00\x00\x00\x00\x00\x00\x00'; -var PDFDocument = function PDFDocumentClosure() { - var FINGERPRINT_FIRST_BYTES = 1024; - var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' + '\x00\x00\x00\x00\x00\x00\x00\x00\x00'; +function find(stream, needle, limit, backwards) { + const pos = stream.pos; + const end = stream.end; - function PDFDocument(pdfManager, arg) { - var stream; + if (pos + limit > end) { + limit = end - pos; + } + + const strBuf = []; + + for (let i = 0; i < limit; ++i) { + strBuf.push(String.fromCharCode(stream.getByte())); + } + + const str = strBuf.join(''); + stream.pos = pos; + const index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle); + + if (index === -1) { + return false; + } + + stream.pos += index; + return true; +} + +class PDFDocument { + constructor(pdfManager, arg) { + let stream; if ((0, _primitives.isStream)(arg)) { stream = arg; @@ -6691,325 +6715,308 @@ var PDFDocument = function PDFDocumentClosure() { } if (stream.length <= 0) { - throw new Error('PDFDocument: stream must have data'); + throw new Error('PDFDocument: Stream must have data'); } this.pdfManager = pdfManager; this.stream = stream; this.xref = new _obj.XRef(stream, pdfManager); - let evaluatorOptions = pdfManager.evaluatorOptions; this.pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: this.xref, - isEvalSupported: evaluatorOptions.isEvalSupported + isEvalSupported: pdfManager.evaluatorOptions.isEvalSupported }); this._pagePromises = []; } - function find(stream, needle, limit, backwards) { - var pos = stream.pos; - var end = stream.end; - var strBuf = []; + parse(recoveryMode) { + this.setup(recoveryMode); + const version = this.catalog.catDict.get('Version'); - if (pos + limit > end) { - limit = end - pos; + if ((0, _primitives.isName)(version)) { + this.pdfFormatVersion = version.name; } - for (var n = 0; n < limit; ++n) { - strBuf.push(String.fromCharCode(stream.getByte())); + try { + this.acroForm = this.catalog.catDict.get('AcroForm'); + + if (this.acroForm) { + this.xfa = this.acroForm.get('XFA'); + const fields = this.acroForm.get('Fields'); + + if ((!fields || !Array.isArray(fields) || fields.length === 0) && !this.xfa) { + this.acroForm = null; + } + } + } catch (ex) { + if (ex instanceof _util.MissingDataException) { + throw ex; + } + + (0, _util.info)('Cannot fetch AcroForm entry; assuming no AcroForms are present'); + this.acroForm = null; } - - var str = strBuf.join(''); - stream.pos = pos; - var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle); - - if (index === -1) { - return false; - } - - stream.pos += index; - return true; } - const DocumentInfoValidators = { - Title: _util.isString, - Author: _util.isString, - Subject: _util.isString, - Keywords: _util.isString, - Creator: _util.isString, - Producer: _util.isString, - CreationDate: _util.isString, - ModDate: _util.isString, - Trapped: _primitives.isName - }; - PDFDocument.prototype = { - parse: function PDFDocument_parse(recoveryMode) { - this.setup(recoveryMode); - var version = this.catalog.catDict.get('Version'); + get linearization() { + let linearization = null; - if ((0, _primitives.isName)(version)) { - this.pdfFormatVersion = version.name; + try { + linearization = _parser.Linearization.create(this.stream); + } catch (err) { + if (err instanceof _util.MissingDataException) { + throw err; } - try { - this.acroForm = this.catalog.catDict.get('AcroForm'); + (0, _util.info)(err); + } - if (this.acroForm) { - this.xfa = this.acroForm.get('XFA'); - var fields = this.acroForm.get('Fields'); + return (0, _util.shadow)(this, 'linearization', linearization); + } - if ((!fields || !Array.isArray(fields) || fields.length === 0) && !this.xfa) { - this.acroForm = null; - } - } - } catch (ex) { - if (ex instanceof _util.MissingDataException) { - throw ex; - } + get startXRef() { + const stream = this.stream; + let startXRef = 0; - (0, _util.info)('Something wrong with AcroForm entry'); - this.acroForm = null; - } - }, - - get linearization() { - let linearization = null; - - try { - linearization = _parser.Linearization.create(this.stream); - } catch (err) { - if (err instanceof _util.MissingDataException) { - throw err; - } - - (0, _util.info)(err); - } - - return (0, _util.shadow)(this, 'linearization', linearization); - }, - - get startXRef() { - var stream = this.stream; - var startXRef = 0; - var linearization = this.linearization; - - if (linearization) { - stream.reset(); - - if (find(stream, 'endobj', 1024)) { - startXRef = stream.pos + 6; - } - } else { - var step = 1024; - var found = false, - pos = stream.end; - - while (!found && pos > 0) { - pos -= step - 'startxref'.length; - - if (pos < 0) { - pos = 0; - } - - stream.pos = pos; - found = find(stream, 'startxref', step, true); - } - - if (found) { - stream.skip(9); - var ch; - - do { - ch = stream.getByte(); - } while ((0, _util.isSpace)(ch)); - - var str = ''; - - while (ch >= 0x20 && ch <= 0x39) { - str += String.fromCharCode(ch); - ch = stream.getByte(); - } - - startXRef = parseInt(str, 10); - - if (isNaN(startXRef)) { - startXRef = 0; - } - } - } - - return (0, _util.shadow)(this, 'startXRef', startXRef); - }, - - checkHeader: function PDFDocument_checkHeader() { - var stream = this.stream; + if (this.linearization) { stream.reset(); - if (find(stream, '%PDF-', 1024)) { - stream.moveStart(); - var MAX_VERSION_LENGTH = 12; - var version = '', - ch; + if (find(stream, 'endobj', 1024)) { + startXRef = stream.pos + 6; + } + } else { + const step = 1024; + const startXRefLength = 'startxref'.length; + let found = false, + pos = stream.end; - while ((ch = stream.getByte()) > 0x20) { - if (version.length >= MAX_VERSION_LENGTH) { - break; - } + while (!found && pos > 0) { + pos -= step - startXRefLength; - version += String.fromCharCode(ch); + if (pos < 0) { + pos = 0; } - if (!this.pdfFormatVersion) { - this.pdfFormatVersion = version.substring(5); + stream.pos = pos; + found = find(stream, 'startxref', step, true); + } + + if (found) { + stream.skip(9); + let ch; + + do { + ch = stream.getByte(); + } while ((0, _util.isSpace)(ch)); + + let str = ''; + + while (ch >= 0x20 && ch <= 0x39) { + str += String.fromCharCode(ch); + ch = stream.getByte(); } - return; - } - }, - parseStartXRef: function PDFDocument_parseStartXRef() { - var startXRef = this.startXRef; - this.xref.setStartXRef(startXRef); - }, - setup: function PDFDocument_setup(recoveryMode) { - this.xref.parse(recoveryMode); - this.catalog = new _obj.Catalog(this.pdfManager, this.xref); - }, + startXRef = parseInt(str, 10); - get numPages() { - var linearization = this.linearization; - var num = linearization ? linearization.numPages : this.catalog.numPages; - return (0, _util.shadow)(this, 'numPages', num); - }, - - get documentInfo() { - const docInfo = { - PDFFormatVersion: this.pdfFormatVersion, - IsLinearized: !!this.linearization, - IsAcroFormPresent: !!this.acroForm, - IsXFAPresent: !!this.xfa - }; - let infoDict; - - try { - infoDict = this.xref.trailer.get('Info'); - } catch (err) { - if (err instanceof _util.MissingDataException) { - throw err; - } - - (0, _util.info)('The document information dictionary is invalid.'); - } - - if ((0, _primitives.isDict)(infoDict)) { - for (let key of infoDict.getKeys()) { - const value = infoDict.get(key); - - if (DocumentInfoValidators[key]) { - if (DocumentInfoValidators[key](value)) { - docInfo[key] = typeof value !== 'string' ? value : (0, _util.stringToPDFString)(value); - } else { - (0, _util.info)(`Bad value in document info for "${key}".`); - } - } else if (typeof key === 'string') { - let customValue; - - if ((0, _util.isString)(value)) { - customValue = (0, _util.stringToPDFString)(value); - } else if ((0, _primitives.isName)(value) || (0, _util.isNum)(value) || (0, _util.isBool)(value)) { - customValue = value; - } else { - (0, _util.info)(`Unsupported value in document info for (custom) "${key}".`); - continue; - } - - if (!docInfo['Custom']) { - docInfo['Custom'] = Object.create(null); - } - - docInfo['Custom'][key] = customValue; - } + if (isNaN(startXRef)) { + startXRef = 0; } } - - return (0, _util.shadow)(this, 'documentInfo', docInfo); - }, - - get fingerprint() { - var xref = this.xref, - hash, - fileID = ''; - var idArray = xref.trailer.get('ID'); - - if (Array.isArray(idArray) && idArray[0] && (0, _util.isString)(idArray[0]) && idArray[0] !== EMPTY_FINGERPRINT) { - hash = (0, _util.stringToBytes)(idArray[0]); - } else { - if (this.stream.ensureRange) { - this.stream.ensureRange(0, Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end)); - } - - hash = (0, _crypto.calculateMD5)(this.stream.bytes.subarray(0, FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES); - } - - for (var i = 0, n = hash.length; i < n; i++) { - var hex = hash[i].toString(16); - fileID += hex.length === 1 ? '0' + hex : hex; - } - - return (0, _util.shadow)(this, 'fingerprint', fileID); - }, - - _getLinearizationPage(pageIndex) { - const { - catalog, - linearization - } = this; - (0, _util.assert)(linearization && linearization.pageFirst === pageIndex); - const ref = new _primitives.Ref(linearization.objectNumberFirst, 0); - return this.xref.fetchAsync(ref).then(obj => { - if ((0, _primitives.isDict)(obj, 'Page') || (0, _primitives.isDict)(obj) && !obj.has('Type') && obj.has('Contents')) { - if (ref && !catalog.pageKidsCountCache.has(ref)) { - catalog.pageKidsCountCache.put(ref, 1); - } - - return [obj, ref]; - } - - throw new _util.FormatError('The Linearization dictionary doesn\'t point ' + 'to a valid Page dictionary.'); - }).catch(reason => { - (0, _util.info)(reason); - return catalog.getPageDict(pageIndex); - }); - }, - - getPage(pageIndex) { - if (this._pagePromises[pageIndex] !== undefined) { - return this._pagePromises[pageIndex]; - } - - const { - catalog, - linearization - } = this; - const promise = linearization && linearization.pageFirst === pageIndex ? this._getLinearizationPage(pageIndex) : catalog.getPageDict(pageIndex); - return this._pagePromises[pageIndex] = promise.then(([pageDict, ref]) => { - return new Page({ - pdfManager: this.pdfManager, - xref: this.xref, - pageIndex, - pageDict, - ref, - fontCache: catalog.fontCache, - builtInCMapCache: catalog.builtInCMapCache, - pdfFunctionFactory: this.pdfFunctionFactory - }); - }); - }, - - cleanup: function PDFDocument_cleanup() { - return this.catalog.cleanup(); } - }; - return PDFDocument; -}(); + + return (0, _util.shadow)(this, 'startXRef', startXRef); + } + + checkHeader() { + const stream = this.stream; + stream.reset(); + + if (!find(stream, '%PDF-', 1024)) { + return; + } + + stream.moveStart(); + const MAX_PDF_VERSION_LENGTH = 12; + let version = '', + ch; + + while ((ch = stream.getByte()) > 0x20) { + if (version.length >= MAX_PDF_VERSION_LENGTH) { + break; + } + + version += String.fromCharCode(ch); + } + + if (!this.pdfFormatVersion) { + this.pdfFormatVersion = version.substring(5); + } + } + + parseStartXRef() { + this.xref.setStartXRef(this.startXRef); + } + + setup(recoveryMode) { + this.xref.parse(recoveryMode); + this.catalog = new _obj.Catalog(this.pdfManager, this.xref); + } + + get numPages() { + const linearization = this.linearization; + const num = linearization ? linearization.numPages : this.catalog.numPages; + return (0, _util.shadow)(this, 'numPages', num); + } + + get documentInfo() { + const DocumentInfoValidators = { + Title: _util.isString, + Author: _util.isString, + Subject: _util.isString, + Keywords: _util.isString, + Creator: _util.isString, + Producer: _util.isString, + CreationDate: _util.isString, + ModDate: _util.isString, + Trapped: _primitives.isName + }; + const docInfo = { + PDFFormatVersion: this.pdfFormatVersion, + IsLinearized: !!this.linearization, + IsAcroFormPresent: !!this.acroForm, + IsXFAPresent: !!this.xfa + }; + let infoDict; + + try { + infoDict = this.xref.trailer.get('Info'); + } catch (err) { + if (err instanceof _util.MissingDataException) { + throw err; + } + + (0, _util.info)('The document information dictionary is invalid.'); + } + + if ((0, _primitives.isDict)(infoDict)) { + for (const key of infoDict.getKeys()) { + const value = infoDict.get(key); + + if (DocumentInfoValidators[key]) { + if (DocumentInfoValidators[key](value)) { + docInfo[key] = typeof value !== 'string' ? value : (0, _util.stringToPDFString)(value); + } else { + (0, _util.info)(`Bad value in document info for "${key}".`); + } + } else if (typeof key === 'string') { + let customValue; + + if ((0, _util.isString)(value)) { + customValue = (0, _util.stringToPDFString)(value); + } else if ((0, _primitives.isName)(value) || (0, _util.isNum)(value) || (0, _util.isBool)(value)) { + customValue = value; + } else { + (0, _util.info)(`Unsupported value in document info for (custom) "${key}".`); + continue; + } + + if (!docInfo['Custom']) { + docInfo['Custom'] = Object.create(null); + } + + docInfo['Custom'][key] = customValue; + } + } + } + + return (0, _util.shadow)(this, 'documentInfo', docInfo); + } + + get fingerprint() { + let hash; + const idArray = this.xref.trailer.get('ID'); + + if (Array.isArray(idArray) && idArray[0] && (0, _util.isString)(idArray[0]) && idArray[0] !== EMPTY_FINGERPRINT) { + hash = (0, _util.stringToBytes)(idArray[0]); + } else { + if (this.stream.ensureRange) { + this.stream.ensureRange(0, Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end)); + } + + hash = (0, _crypto.calculateMD5)(this.stream.bytes.subarray(0, FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES); + } + + let fingerprint = ''; + + for (const hashPart of hash) { + const hex = hashPart.toString(16); + fingerprint += hex.length === 1 ? '0' + hex : hex; + } + + return (0, _util.shadow)(this, 'fingerprint', fingerprint); + } + + _getLinearizationPage(pageIndex) { + const { + catalog, + linearization + } = this; + (0, _util.assert)(linearization && linearization.pageFirst === pageIndex); + const ref = new _primitives.Ref(linearization.objectNumberFirst, 0); + return this.xref.fetchAsync(ref).then(obj => { + if ((0, _primitives.isDict)(obj, 'Page') || (0, _primitives.isDict)(obj) && !obj.has('Type') && obj.has('Contents')) { + if (ref && !catalog.pageKidsCountCache.has(ref)) { + catalog.pageKidsCountCache.put(ref, 1); + } + + return [obj, ref]; + } + + throw new _util.FormatError('The Linearization dictionary doesn\'t point ' + 'to a valid Page dictionary.'); + }).catch(reason => { + (0, _util.info)(reason); + return catalog.getPageDict(pageIndex); + }); + } + + getPage(pageIndex) { + if (this._pagePromises[pageIndex] !== undefined) { + return this._pagePromises[pageIndex]; + } + + const { + catalog, + linearization + } = this; + const promise = linearization && linearization.pageFirst === pageIndex ? this._getLinearizationPage(pageIndex) : catalog.getPageDict(pageIndex); + return this._pagePromises[pageIndex] = promise.then(([pageDict, ref]) => { + return new Page({ + pdfManager: this.pdfManager, + xref: this.xref, + pageIndex, + pageDict, + ref, + fontCache: catalog.fontCache, + builtInCMapCache: catalog.builtInCMapCache, + pdfFunctionFactory: this.pdfFunctionFactory + }); + }); + } + + checkFirstPage() { + return this.getPage(0).catch(reason => { + if (reason instanceof _util.XRefEntryException) { + this._pagePromises.length = 0; + this.cleanup(); + throw new _util.XRefParseException(); + } + }); + } + + cleanup() { + return this.catalog.cleanup(); + } + +} exports.PDFDocument = PDFDocument; @@ -8503,7 +8510,7 @@ var XRef = function XRefClosure() { if (xrefEntry.uncompressed) { xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption); } else { - xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption); + xrefEntry = this.fetchCompressed(ref, xrefEntry, suppressEncryption); } if ((0, _primitives.isDict)(xrefEntry)) { @@ -8514,12 +8521,13 @@ var XRef = function XRefClosure() { return xrefEntry; }, - fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry, suppressEncryption) { + + fetchUncompressed(ref, xrefEntry, suppressEncryption = false) { var gen = ref.gen; var num = ref.num; if (xrefEntry.gen !== gen) { - throw new _util.FormatError('inconsistent generation in XRef'); + throw new _util.XRefEntryException(`Inconsistent generation in XRef: ${ref}`); } var stream = this.stream.makeSubStream(xrefEntry.offset + this.stream.start); @@ -8537,7 +8545,7 @@ var XRef = function XRefClosure() { } if (obj1 !== num || obj2 !== gen || !(0, _primitives.isCmd)(obj3)) { - throw new _util.FormatError('bad XRef entry'); + throw new _util.XRefEntryException(`Bad (uncompressed) XRef entry: ${ref}`); } if (obj3.cmd !== 'obj') { @@ -8549,7 +8557,7 @@ var XRef = function XRefClosure() { } } - throw new _util.FormatError('bad XRef entry'); + throw new _util.XRefEntryException(`Bad (uncompressed) XRef entry: ${ref}`); } if (this.encrypt && !suppressEncryption) { @@ -8564,7 +8572,8 @@ var XRef = function XRefClosure() { return xrefEntry; }, - fetchCompressed: function XRef_fetchCompressed(xrefEntry, suppressEncryption) { + + fetchCompressed(ref, xrefEntry, suppressEncryption = false) { var tableOffset = xrefEntry.offset; var stream = this.fetch(new _primitives.Ref(tableOffset, 0)); @@ -8619,7 +8628,7 @@ var XRef = function XRefClosure() { xrefEntry = entries[xrefEntry.gen]; if (xrefEntry === undefined) { - throw new _util.FormatError('bad XRef entry for compressed object'); + throw new _util.XRefEntryException(`Bad (compressed) XRef entry: ${ref}`); } return xrefEntry; @@ -9240,13 +9249,11 @@ var Ref = function RefClosure() { Ref.prototype = { toString: function Ref_toString() { - var str = this.num + 'R'; - if (this.gen !== 0) { - str += this.gen; + return `${this.num}R${this.gen}`; } - return str; + return `${this.num}R`; } }; return Ref; @@ -21977,13 +21984,17 @@ class AnnotationBorderStyle { } setWidth(width) { + if ((0, _primitives.isName)(width)) { + width = parseFloat(width.name); + } + if (Number.isInteger(width)) { this.width = width; } } setStyle(style) { - if (!style) { + if (!(0, _primitives.isName)(style)) { return; } diff --git a/browser/extensions/pdfjs/content/web/viewer.css b/browser/extensions/pdfjs/content/web/viewer.css index 6bac222ff165..5b2d7bb39beb 100644 --- a/browser/extensions/pdfjs/content/web/viewer.css +++ b/browser/extensions/pdfjs/content/web/viewer.css @@ -56,6 +56,8 @@ background-color: rgb(0, 100, 0); } +.textLayer ::-moz-selection { background: rgb(0,0,255); } + .textLayer ::selection { background: rgb(0,0,255); } .textLayer .endOfContent { @@ -1675,6 +1677,7 @@ html[dir='rtl'] .outlineItemToggler::before { /* TODO: file FF bug to support ::-moz-selection:window-inactive so we can override the opaque grey background when the window is inactive; see https://bugzilla.mozilla.org/show_bug.cgi?id=706209 */ +::-moz-selection { background: rgba(0,0,255,0.3); } ::selection { background: rgba(0,0,255,0.3); } #errorWrapper { diff --git a/browser/extensions/pdfjs/moz.yaml b/browser/extensions/pdfjs/moz.yaml index 4931518c9bca..5403971586f2 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.1.132 + release: version 2.1.145 # The package's license, where possible using the mnemonic from # https://spdx.org/licenses/