From 9edff62f364b175d9a634c503a74c3acd81d81bc Mon Sep 17 00:00:00 2001 From: Ryan VanderMeulen Date: Mon, 12 Aug 2019 17:54:22 +0000 Subject: [PATCH] Bug 1573149 - Update pdf.js to version 2.3.86. r=bdahl Differential Revision: https://phabricator.services.mozilla.com/D41542 --HG-- extra : moz-landing-system : lando --- browser/extensions/pdfjs/README.mozilla | 4 +- browser/extensions/pdfjs/content/build/pdf.js | 219 +++++++------- .../pdfjs/content/build/pdf.worker.js | 285 ++++++++++-------- .../extensions/pdfjs/content/web/viewer.js | 6 +- browser/extensions/pdfjs/moz.yaml | 2 +- 5 files changed, 265 insertions(+), 251 deletions(-) diff --git a/browser/extensions/pdfjs/README.mozilla b/browser/extensions/pdfjs/README.mozilla index fadaa101fb66..4136e62b66e8 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.3.71 +Current extension version is: 2.3.86 -Taken from upstream commit: e1aed05c +Taken from upstream commit: 02dcd202 diff --git a/browser/extensions/pdfjs/content/build/pdf.js b/browser/extensions/pdfjs/content/build/pdf.js index eaf189defe43..0ab7263ff7cc 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.3.71'; -var pdfjsBuild = 'e1aed05c'; +var pdfjsVersion = '2.3.86'; +var pdfjsBuild = '02dcd202'; var pdfjsSharedUtil = __w_pdfjs_require__(1); @@ -537,13 +537,13 @@ function getVerbosityLevel() { function info(msg) { if (verbosity >= VerbosityLevel.INFOS) { - console.log('Info: ' + msg); + console.log(`Info: ${msg}`); } } function warn(msg) { if (verbosity >= VerbosityLevel.WARNINGS) { - console.log('Warning: ' + msg); + console.log(`Warning: ${msg}`); } } @@ -558,8 +558,10 @@ function assert(cond, msg) { } function isSameOrigin(baseUrl, otherUrl) { + let base; + try { - var base = new _url_polyfill.URL(baseUrl); + base = new _url_polyfill.URL(baseUrl); if (!base.origin || base.origin === 'null') { return false; @@ -568,7 +570,7 @@ function isSameOrigin(baseUrl, otherUrl) { return false; } - var other = new _url_polyfill.URL(otherUrl, base); + const other = new _url_polyfill.URL(otherUrl, base); return base.origin === other.origin; } @@ -596,7 +598,7 @@ function createValidAbsoluteUrl(url, baseUrl) { } try { - var absoluteUrl = baseUrl ? new _url_polyfill.URL(url, baseUrl) : new _url_polyfill.URL(url); + const absoluteUrl = baseUrl ? new _url_polyfill.URL(url, baseUrl) : new _url_polyfill.URL(url); if (_isValidProtocol(absoluteUrl)) { return absoluteUrl; @@ -616,7 +618,7 @@ function shadow(obj, prop, value) { return value; } -var PasswordException = function PasswordExceptionClosure() { +const PasswordException = function PasswordExceptionClosure() { function PasswordException(msg, code) { this.name = 'PasswordException'; this.message = msg; @@ -630,7 +632,7 @@ var PasswordException = function PasswordExceptionClosure() { exports.PasswordException = PasswordException; -var UnknownErrorException = function UnknownErrorExceptionClosure() { +const UnknownErrorException = function UnknownErrorExceptionClosure() { function UnknownErrorException(msg, details) { this.name = 'UnknownErrorException'; this.message = msg; @@ -644,7 +646,7 @@ var UnknownErrorException = function UnknownErrorExceptionClosure() { exports.UnknownErrorException = UnknownErrorException; -var InvalidPDFException = function InvalidPDFExceptionClosure() { +const InvalidPDFException = function InvalidPDFExceptionClosure() { function InvalidPDFException(msg) { this.name = 'InvalidPDFException'; this.message = msg; @@ -657,7 +659,7 @@ var InvalidPDFException = function InvalidPDFExceptionClosure() { exports.InvalidPDFException = InvalidPDFException; -var MissingPDFException = function MissingPDFExceptionClosure() { +const MissingPDFException = function MissingPDFExceptionClosure() { function MissingPDFException(msg) { this.name = 'MissingPDFException'; this.message = msg; @@ -670,7 +672,7 @@ var MissingPDFException = function MissingPDFExceptionClosure() { exports.MissingPDFException = MissingPDFException; -var UnexpectedResponseException = function UnexpectedResponseExceptionClosure() { +const UnexpectedResponseException = function UnexpectedResponseExceptionClosure() { function UnexpectedResponseException(msg, status) { this.name = 'UnexpectedResponseException'; this.message = msg; @@ -684,7 +686,7 @@ var UnexpectedResponseException = function UnexpectedResponseExceptionClosure() exports.UnexpectedResponseException = UnexpectedResponseException; -let FormatError = function FormatErrorClosure() { +const FormatError = function FormatErrorClosure() { function FormatError(msg) { this.message = msg; } @@ -697,7 +699,7 @@ let FormatError = function FormatErrorClosure() { exports.FormatError = FormatError; -let AbortException = function AbortExceptionClosure() { +const AbortException = function AbortExceptionClosure() { function AbortException(msg) { this.name = 'AbortException'; this.message = msg; @@ -709,7 +711,7 @@ let AbortException = function AbortExceptionClosure() { }(); exports.AbortException = AbortException; -var NullCharactersRegExp = /\x00/g; +const NullCharactersRegExp = /\x00/g; function removeNullCharacters(str) { if (typeof str !== 'string') { @@ -722,18 +724,18 @@ function removeNullCharacters(str) { function bytesToString(bytes) { assert(bytes !== null && typeof bytes === 'object' && bytes.length !== undefined, 'Invalid argument for bytesToString'); - var length = bytes.length; - var MAX_ARGUMENT_COUNT = 8192; + const length = bytes.length; + const MAX_ARGUMENT_COUNT = 8192; if (length < MAX_ARGUMENT_COUNT) { return String.fromCharCode.apply(null, bytes); } - var strBuf = []; + const strBuf = []; - for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) { - var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length); - var chunk = bytes.subarray(i, chunkEnd); + for (let i = 0; i < length; i += MAX_ARGUMENT_COUNT) { + const chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length); + const chunk = bytes.subarray(i, chunkEnd); strBuf.push(String.fromCharCode.apply(null, chunk)); } @@ -742,10 +744,10 @@ function bytesToString(bytes) { function stringToBytes(str) { assert(typeof str === 'string', 'Invalid argument for stringToBytes'); - var length = str.length; - var bytes = new Uint8Array(length); + const length = str.length; + const bytes = new Uint8Array(length); - for (var i = 0; i < length; ++i) { + for (let i = 0; i < length; ++i) { bytes[i] = str.charCodeAt(i) & 0xFF; } @@ -762,26 +764,23 @@ function arrayByteLength(arr) { } function arraysToBytes(arr) { - if (arr.length === 1 && arr[0] instanceof Uint8Array) { + const length = arr.length; + + if (length === 1 && arr[0] instanceof Uint8Array) { return arr[0]; } - var resultLength = 0; - var i, - ii = arr.length; - var item, itemLength; + let resultLength = 0; - for (i = 0; i < ii; i++) { - item = arr[i]; - itemLength = arrayByteLength(item); - resultLength += itemLength; + for (let i = 0; i < length; i++) { + resultLength += arrayByteLength(arr[i]); } - var pos = 0; - var data = new Uint8Array(resultLength); + let pos = 0; + const data = new Uint8Array(resultLength); - for (i = 0; i < ii; i++) { - item = arr[i]; + for (let i = 0; i < length; i++) { + let item = arr[i]; if (!(item instanceof Uint8Array)) { if (typeof item === 'string') { @@ -791,7 +790,7 @@ function arraysToBytes(arr) { } } - itemLength = item.byteLength; + const itemLength = item.byteLength; data.set(item, pos); pos += itemLength; } @@ -824,9 +823,9 @@ function readUint32(data, offset) { } function isLittleEndian() { - var buffer8 = new Uint8Array(4); + const buffer8 = new Uint8Array(4); buffer8[0] = 1; - var view32 = new Uint32Array(buffer8.buffer, 0, 1); + const view32 = new Uint32Array(buffer8.buffer, 0, 1); return view32[0] === 1; } @@ -839,67 +838,65 @@ function isEvalSupported() { } } -var Util = function UtilClosure() { - function Util() {} +const rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')']; - var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')']; - - Util.makeCssRgb = function Util_makeCssRgb(r, g, b) { +class Util { + static makeCssRgb(r, g, b) { rgbBuf[1] = r; rgbBuf[3] = g; rgbBuf[5] = b; return rgbBuf.join(''); - }; + } - Util.transform = function Util_transform(m1, m2) { + static transform(m1, m2) { return [m1[0] * m2[0] + m1[2] * m2[1], m1[1] * m2[0] + m1[3] * m2[1], m1[0] * m2[2] + m1[2] * m2[3], m1[1] * m2[2] + m1[3] * m2[3], m1[0] * m2[4] + m1[2] * m2[5] + m1[4], m1[1] * m2[4] + m1[3] * m2[5] + m1[5]]; - }; + } - Util.applyTransform = function Util_applyTransform(p, m) { - var xt = p[0] * m[0] + p[1] * m[2] + m[4]; - var yt = p[0] * m[1] + p[1] * m[3] + m[5]; + static applyTransform(p, m) { + const xt = p[0] * m[0] + p[1] * m[2] + m[4]; + const yt = p[0] * m[1] + p[1] * m[3] + m[5]; return [xt, yt]; - }; + } - Util.applyInverseTransform = function Util_applyInverseTransform(p, m) { - var d = m[0] * m[3] - m[1] * m[2]; - var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d; - var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d; + static applyInverseTransform(p, m) { + const d = m[0] * m[3] - m[1] * m[2]; + const xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d; + const yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d; return [xt, yt]; - }; + } - Util.getAxialAlignedBoundingBox = function Util_getAxialAlignedBoundingBox(r, m) { - var p1 = Util.applyTransform(r, m); - var p2 = Util.applyTransform(r.slice(2, 4), m); - var p3 = Util.applyTransform([r[0], r[3]], m); - var p4 = Util.applyTransform([r[2], r[1]], m); + static getAxialAlignedBoundingBox(r, m) { + const p1 = Util.applyTransform(r, m); + const p2 = Util.applyTransform(r.slice(2, 4), m); + const p3 = Util.applyTransform([r[0], r[3]], m); + const p4 = Util.applyTransform([r[2], r[1]], m); return [Math.min(p1[0], p2[0], p3[0], p4[0]), Math.min(p1[1], p2[1], p3[1], p4[1]), Math.max(p1[0], p2[0], p3[0], p4[0]), Math.max(p1[1], p2[1], p3[1], p4[1])]; - }; + } - Util.inverseTransform = function Util_inverseTransform(m) { - var d = m[0] * m[3] - m[1] * m[2]; + static inverseTransform(m) { + const d = m[0] * m[3] - m[1] * m[2]; return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d, (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d]; - }; + } - Util.apply3dTransform = function Util_apply3dTransform(m, v) { + static apply3dTransform(m, v) { return [m[0] * v[0] + m[1] * v[1] + m[2] * v[2], m[3] * v[0] + m[4] * v[1] + m[5] * v[2], m[6] * v[0] + m[7] * v[1] + m[8] * v[2]]; - }; + } - Util.singularValueDecompose2dScale = function Util_singularValueDecompose2dScale(m) { - var transpose = [m[0], m[2], m[1], m[3]]; - var a = m[0] * transpose[0] + m[1] * transpose[2]; - var b = m[0] * transpose[1] + m[1] * transpose[3]; - var c = m[2] * transpose[0] + m[3] * transpose[2]; - var d = m[2] * transpose[1] + m[3] * transpose[3]; - var first = (a + d) / 2; - var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2; - var sx = first + second || 1; - var sy = first - second || 1; + static singularValueDecompose2dScale(m) { + const transpose = [m[0], m[2], m[1], m[3]]; + const a = m[0] * transpose[0] + m[1] * transpose[2]; + const b = m[0] * transpose[1] + m[1] * transpose[3]; + const c = m[2] * transpose[0] + m[3] * transpose[2]; + const d = m[2] * transpose[1] + m[3] * transpose[3]; + const first = (a + d) / 2; + const second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2; + const sx = first + second || 1; + const sy = first - second || 1; return [Math.sqrt(sx), Math.sqrt(sy)]; - }; + } - Util.normalizeRect = function Util_normalizeRect(rect) { - var r = rect.slice(0); + static normalizeRect(rect) { + const r = rect.slice(0); if (rect[0] > rect[2]) { r[0] = rect[2]; @@ -912,16 +909,16 @@ var Util = function UtilClosure() { } return r; - }; + } - Util.intersect = function Util_intersect(rect1, rect2) { + static intersect(rect1, rect2) { function compare(a, b) { return a - b; } - var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare), - orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare), - result = []; + const orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare); + const orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare); + const result = []; rect1 = Util.normalizeRect(rect1); rect2 = Util.normalizeRect(rect2); @@ -929,37 +926,35 @@ var Util = function UtilClosure() { result[0] = orderedX[1]; result[2] = orderedX[2]; } else { - return false; + return null; } if (orderedY[0] === rect1[1] && orderedY[1] === rect2[1] || orderedY[0] === rect2[1] && orderedY[1] === rect1[1]) { result[1] = orderedY[1]; result[3] = orderedY[2]; } else { - return false; + return null; } return result; - }; + } - return Util; -}(); +} exports.Util = Util; const PDFStringTranslateTable = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014, 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C, 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160, 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC]; function stringToPDFString(str) { - var i, - n = str.length, - strBuf = []; + const length = str.length, + strBuf = []; if (str[0] === '\xFE' && str[1] === '\xFF') { - for (i = 2; i < n; i += 2) { + for (let i = 2; i < length; i += 2) { strBuf.push(String.fromCharCode(str.charCodeAt(i) << 8 | str.charCodeAt(i + 1))); } } else { - for (i = 0; i < n; ++i) { - var code = PDFStringTranslateTable[str.charCodeAt(i)]; + for (let i = 0; i < length; ++i) { + const code = PDFStringTranslateTable[str.charCodeAt(i)]; strBuf.push(code ? String.fromCharCode(code) : str.charAt(i)); } } @@ -976,7 +971,7 @@ function utf8StringToString(str) { } function isEmptyObj(obj) { - for (var key in obj) { + for (let key in obj) { return false; } @@ -1036,8 +1031,8 @@ function createPromiseCapability() { return capability; } -var createObjectURL = function createObjectURLClosure() { - var digits = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; +const createObjectURL = function createObjectURLClosure() { + const digits = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; return function createObjectURL(data, contentType, forceDataSchema = false) { if (!forceDataSchema && _url_polyfill.URL.createObjectURL) { const blob = new Blob([data], { @@ -1046,16 +1041,16 @@ var createObjectURL = function createObjectURLClosure() { return _url_polyfill.URL.createObjectURL(blob); } - var buffer = 'data:' + contentType + ';base64,'; + let buffer = `data:${contentType};base64,`; - for (var i = 0, ii = data.length; i < ii; i += 3) { - var b1 = data[i] & 0xFF; - var b2 = data[i + 1] & 0xFF; - var b3 = data[i + 2] & 0xFF; - var d1 = b1 >> 2, - d2 = (b1 & 3) << 4 | b2 >> 4; - var d3 = i + 1 < ii ? (b2 & 0xF) << 2 | b3 >> 6 : 64; - var d4 = i + 2 < ii ? b3 & 0x3F : 64; + for (let i = 0, ii = data.length; i < ii; i += 3) { + const b1 = data[i] & 0xFF; + const b2 = data[i + 1] & 0xFF; + const b3 = data[i + 2] & 0xFF; + const d1 = b1 >> 2, + d2 = (b1 & 3) << 4 | b2 >> 4; + const d3 = i + 1 < ii ? (b2 & 0xF) << 2 | b3 >> 6 : 64; + const d4 = i + 2 < ii ? b3 & 0x3F : 64; buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4]; } @@ -1327,7 +1322,7 @@ function _fetchDocument(worker, source, pdfDataRangeTransport, docId) { return worker.messageHandler.sendWithPromise('GetDocRequest', { docId, - apiVersion: '2.3.71', + apiVersion: '2.3.86', source: { data: source.data, url: source.url, @@ -3123,9 +3118,9 @@ const InternalRenderTask = function InternalRenderTaskClosure() { return InternalRenderTask; }(); -const version = '2.3.71'; +const version = '2.3.86'; exports.version = version; -const build = 'e1aed05c'; +const build = '02dcd202'; exports.build = build; /***/ }), diff --git a/browser/extensions/pdfjs/content/build/pdf.worker.js b/browser/extensions/pdfjs/content/build/pdf.worker.js index 152fb9373e5f..3bd3e87de48a 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.3.71'; -const pdfjsBuild = 'e1aed05c'; +const pdfjsVersion = '2.3.86'; +const pdfjsBuild = '02dcd202'; const pdfjsCoreWorker = __w_pdfjs_require__(1); @@ -240,7 +240,7 @@ var WorkerMessageHandler = { var WorkerTasks = []; const verbosity = (0, _util.getVerbosityLevel)(); let apiVersion = docParams.apiVersion; - let workerVersion = '2.3.71'; + let workerVersion = '2.3.86'; if (apiVersion !== workerVersion) { throw new Error(`The API version "${apiVersion}" does not match ` + `the Worker version "${workerVersion}".`); @@ -1054,13 +1054,13 @@ function getVerbosityLevel() { function info(msg) { if (verbosity >= VerbosityLevel.INFOS) { - console.log('Info: ' + msg); + console.log(`Info: ${msg}`); } } function warn(msg) { if (verbosity >= VerbosityLevel.WARNINGS) { - console.log('Warning: ' + msg); + console.log(`Warning: ${msg}`); } } @@ -1075,8 +1075,10 @@ function assert(cond, msg) { } function isSameOrigin(baseUrl, otherUrl) { + let base; + try { - var base = new _url_polyfill.URL(baseUrl); + base = new _url_polyfill.URL(baseUrl); if (!base.origin || base.origin === 'null') { return false; @@ -1085,7 +1087,7 @@ function isSameOrigin(baseUrl, otherUrl) { return false; } - var other = new _url_polyfill.URL(otherUrl, base); + const other = new _url_polyfill.URL(otherUrl, base); return base.origin === other.origin; } @@ -1113,7 +1115,7 @@ function createValidAbsoluteUrl(url, baseUrl) { } try { - var absoluteUrl = baseUrl ? new _url_polyfill.URL(url, baseUrl) : new _url_polyfill.URL(url); + const absoluteUrl = baseUrl ? new _url_polyfill.URL(url, baseUrl) : new _url_polyfill.URL(url); if (_isValidProtocol(absoluteUrl)) { return absoluteUrl; @@ -1133,7 +1135,7 @@ function shadow(obj, prop, value) { return value; } -var PasswordException = function PasswordExceptionClosure() { +const PasswordException = function PasswordExceptionClosure() { function PasswordException(msg, code) { this.name = 'PasswordException'; this.message = msg; @@ -1147,7 +1149,7 @@ var PasswordException = function PasswordExceptionClosure() { exports.PasswordException = PasswordException; -var UnknownErrorException = function UnknownErrorExceptionClosure() { +const UnknownErrorException = function UnknownErrorExceptionClosure() { function UnknownErrorException(msg, details) { this.name = 'UnknownErrorException'; this.message = msg; @@ -1161,7 +1163,7 @@ var UnknownErrorException = function UnknownErrorExceptionClosure() { exports.UnknownErrorException = UnknownErrorException; -var InvalidPDFException = function InvalidPDFExceptionClosure() { +const InvalidPDFException = function InvalidPDFExceptionClosure() { function InvalidPDFException(msg) { this.name = 'InvalidPDFException'; this.message = msg; @@ -1174,7 +1176,7 @@ var InvalidPDFException = function InvalidPDFExceptionClosure() { exports.InvalidPDFException = InvalidPDFException; -var MissingPDFException = function MissingPDFExceptionClosure() { +const MissingPDFException = function MissingPDFExceptionClosure() { function MissingPDFException(msg) { this.name = 'MissingPDFException'; this.message = msg; @@ -1187,7 +1189,7 @@ var MissingPDFException = function MissingPDFExceptionClosure() { exports.MissingPDFException = MissingPDFException; -var UnexpectedResponseException = function UnexpectedResponseExceptionClosure() { +const UnexpectedResponseException = function UnexpectedResponseExceptionClosure() { function UnexpectedResponseException(msg, status) { this.name = 'UnexpectedResponseException'; this.message = msg; @@ -1201,7 +1203,7 @@ var UnexpectedResponseException = function UnexpectedResponseExceptionClosure() exports.UnexpectedResponseException = UnexpectedResponseException; -let FormatError = function FormatErrorClosure() { +const FormatError = function FormatErrorClosure() { function FormatError(msg) { this.message = msg; } @@ -1214,7 +1216,7 @@ let FormatError = function FormatErrorClosure() { exports.FormatError = FormatError; -let AbortException = function AbortExceptionClosure() { +const AbortException = function AbortExceptionClosure() { function AbortException(msg) { this.name = 'AbortException'; this.message = msg; @@ -1226,7 +1228,7 @@ let AbortException = function AbortExceptionClosure() { }(); exports.AbortException = AbortException; -var NullCharactersRegExp = /\x00/g; +const NullCharactersRegExp = /\x00/g; function removeNullCharacters(str) { if (typeof str !== 'string') { @@ -1239,18 +1241,18 @@ function removeNullCharacters(str) { function bytesToString(bytes) { assert(bytes !== null && typeof bytes === 'object' && bytes.length !== undefined, 'Invalid argument for bytesToString'); - var length = bytes.length; - var MAX_ARGUMENT_COUNT = 8192; + const length = bytes.length; + const MAX_ARGUMENT_COUNT = 8192; if (length < MAX_ARGUMENT_COUNT) { return String.fromCharCode.apply(null, bytes); } - var strBuf = []; + const strBuf = []; - for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) { - var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length); - var chunk = bytes.subarray(i, chunkEnd); + for (let i = 0; i < length; i += MAX_ARGUMENT_COUNT) { + const chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length); + const chunk = bytes.subarray(i, chunkEnd); strBuf.push(String.fromCharCode.apply(null, chunk)); } @@ -1259,10 +1261,10 @@ function bytesToString(bytes) { function stringToBytes(str) { assert(typeof str === 'string', 'Invalid argument for stringToBytes'); - var length = str.length; - var bytes = new Uint8Array(length); + const length = str.length; + const bytes = new Uint8Array(length); - for (var i = 0; i < length; ++i) { + for (let i = 0; i < length; ++i) { bytes[i] = str.charCodeAt(i) & 0xFF; } @@ -1279,26 +1281,23 @@ function arrayByteLength(arr) { } function arraysToBytes(arr) { - if (arr.length === 1 && arr[0] instanceof Uint8Array) { + const length = arr.length; + + if (length === 1 && arr[0] instanceof Uint8Array) { return arr[0]; } - var resultLength = 0; - var i, - ii = arr.length; - var item, itemLength; + let resultLength = 0; - for (i = 0; i < ii; i++) { - item = arr[i]; - itemLength = arrayByteLength(item); - resultLength += itemLength; + for (let i = 0; i < length; i++) { + resultLength += arrayByteLength(arr[i]); } - var pos = 0; - var data = new Uint8Array(resultLength); + let pos = 0; + const data = new Uint8Array(resultLength); - for (i = 0; i < ii; i++) { - item = arr[i]; + for (let i = 0; i < length; i++) { + let item = arr[i]; if (!(item instanceof Uint8Array)) { if (typeof item === 'string') { @@ -1308,7 +1307,7 @@ function arraysToBytes(arr) { } } - itemLength = item.byteLength; + const itemLength = item.byteLength; data.set(item, pos); pos += itemLength; } @@ -1341,9 +1340,9 @@ function readUint32(data, offset) { } function isLittleEndian() { - var buffer8 = new Uint8Array(4); + const buffer8 = new Uint8Array(4); buffer8[0] = 1; - var view32 = new Uint32Array(buffer8.buffer, 0, 1); + const view32 = new Uint32Array(buffer8.buffer, 0, 1); return view32[0] === 1; } @@ -1356,67 +1355,65 @@ function isEvalSupported() { } } -var Util = function UtilClosure() { - function Util() {} +const rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')']; - var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')']; - - Util.makeCssRgb = function Util_makeCssRgb(r, g, b) { +class Util { + static makeCssRgb(r, g, b) { rgbBuf[1] = r; rgbBuf[3] = g; rgbBuf[5] = b; return rgbBuf.join(''); - }; + } - Util.transform = function Util_transform(m1, m2) { + static transform(m1, m2) { return [m1[0] * m2[0] + m1[2] * m2[1], m1[1] * m2[0] + m1[3] * m2[1], m1[0] * m2[2] + m1[2] * m2[3], m1[1] * m2[2] + m1[3] * m2[3], m1[0] * m2[4] + m1[2] * m2[5] + m1[4], m1[1] * m2[4] + m1[3] * m2[5] + m1[5]]; - }; + } - Util.applyTransform = function Util_applyTransform(p, m) { - var xt = p[0] * m[0] + p[1] * m[2] + m[4]; - var yt = p[0] * m[1] + p[1] * m[3] + m[5]; + static applyTransform(p, m) { + const xt = p[0] * m[0] + p[1] * m[2] + m[4]; + const yt = p[0] * m[1] + p[1] * m[3] + m[5]; return [xt, yt]; - }; + } - Util.applyInverseTransform = function Util_applyInverseTransform(p, m) { - var d = m[0] * m[3] - m[1] * m[2]; - var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d; - var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d; + static applyInverseTransform(p, m) { + const d = m[0] * m[3] - m[1] * m[2]; + const xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d; + const yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d; return [xt, yt]; - }; + } - Util.getAxialAlignedBoundingBox = function Util_getAxialAlignedBoundingBox(r, m) { - var p1 = Util.applyTransform(r, m); - var p2 = Util.applyTransform(r.slice(2, 4), m); - var p3 = Util.applyTransform([r[0], r[3]], m); - var p4 = Util.applyTransform([r[2], r[1]], m); + static getAxialAlignedBoundingBox(r, m) { + const p1 = Util.applyTransform(r, m); + const p2 = Util.applyTransform(r.slice(2, 4), m); + const p3 = Util.applyTransform([r[0], r[3]], m); + const p4 = Util.applyTransform([r[2], r[1]], m); return [Math.min(p1[0], p2[0], p3[0], p4[0]), Math.min(p1[1], p2[1], p3[1], p4[1]), Math.max(p1[0], p2[0], p3[0], p4[0]), Math.max(p1[1], p2[1], p3[1], p4[1])]; - }; + } - Util.inverseTransform = function Util_inverseTransform(m) { - var d = m[0] * m[3] - m[1] * m[2]; + static inverseTransform(m) { + const d = m[0] * m[3] - m[1] * m[2]; return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d, (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d]; - }; + } - Util.apply3dTransform = function Util_apply3dTransform(m, v) { + static apply3dTransform(m, v) { return [m[0] * v[0] + m[1] * v[1] + m[2] * v[2], m[3] * v[0] + m[4] * v[1] + m[5] * v[2], m[6] * v[0] + m[7] * v[1] + m[8] * v[2]]; - }; + } - Util.singularValueDecompose2dScale = function Util_singularValueDecompose2dScale(m) { - var transpose = [m[0], m[2], m[1], m[3]]; - var a = m[0] * transpose[0] + m[1] * transpose[2]; - var b = m[0] * transpose[1] + m[1] * transpose[3]; - var c = m[2] * transpose[0] + m[3] * transpose[2]; - var d = m[2] * transpose[1] + m[3] * transpose[3]; - var first = (a + d) / 2; - var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2; - var sx = first + second || 1; - var sy = first - second || 1; + static singularValueDecompose2dScale(m) { + const transpose = [m[0], m[2], m[1], m[3]]; + const a = m[0] * transpose[0] + m[1] * transpose[2]; + const b = m[0] * transpose[1] + m[1] * transpose[3]; + const c = m[2] * transpose[0] + m[3] * transpose[2]; + const d = m[2] * transpose[1] + m[3] * transpose[3]; + const first = (a + d) / 2; + const second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2; + const sx = first + second || 1; + const sy = first - second || 1; return [Math.sqrt(sx), Math.sqrt(sy)]; - }; + } - Util.normalizeRect = function Util_normalizeRect(rect) { - var r = rect.slice(0); + static normalizeRect(rect) { + const r = rect.slice(0); if (rect[0] > rect[2]) { r[0] = rect[2]; @@ -1429,16 +1426,16 @@ var Util = function UtilClosure() { } return r; - }; + } - Util.intersect = function Util_intersect(rect1, rect2) { + static intersect(rect1, rect2) { function compare(a, b) { return a - b; } - var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare), - orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare), - result = []; + const orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare); + const orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare); + const result = []; rect1 = Util.normalizeRect(rect1); rect2 = Util.normalizeRect(rect2); @@ -1446,37 +1443,35 @@ var Util = function UtilClosure() { result[0] = orderedX[1]; result[2] = orderedX[2]; } else { - return false; + return null; } if (orderedY[0] === rect1[1] && orderedY[1] === rect2[1] || orderedY[0] === rect2[1] && orderedY[1] === rect1[1]) { result[1] = orderedY[1]; result[3] = orderedY[2]; } else { - return false; + return null; } return result; - }; + } - return Util; -}(); +} exports.Util = Util; const PDFStringTranslateTable = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014, 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C, 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160, 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC]; function stringToPDFString(str) { - var i, - n = str.length, - strBuf = []; + const length = str.length, + strBuf = []; if (str[0] === '\xFE' && str[1] === '\xFF') { - for (i = 2; i < n; i += 2) { + for (let i = 2; i < length; i += 2) { strBuf.push(String.fromCharCode(str.charCodeAt(i) << 8 | str.charCodeAt(i + 1))); } } else { - for (i = 0; i < n; ++i) { - var code = PDFStringTranslateTable[str.charCodeAt(i)]; + for (let i = 0; i < length; ++i) { + const code = PDFStringTranslateTable[str.charCodeAt(i)]; strBuf.push(code ? String.fromCharCode(code) : str.charAt(i)); } } @@ -1493,7 +1488,7 @@ function utf8StringToString(str) { } function isEmptyObj(obj) { - for (var key in obj) { + for (let key in obj) { return false; } @@ -1553,8 +1548,8 @@ function createPromiseCapability() { return capability; } -var createObjectURL = function createObjectURLClosure() { - var digits = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; +const createObjectURL = function createObjectURLClosure() { + const digits = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; return function createObjectURL(data, contentType, forceDataSchema = false) { if (!forceDataSchema && _url_polyfill.URL.createObjectURL) { const blob = new Blob([data], { @@ -1563,16 +1558,16 @@ var createObjectURL = function createObjectURLClosure() { return _url_polyfill.URL.createObjectURL(blob); } - var buffer = 'data:' + contentType + ';base64,'; + let buffer = `data:${contentType};base64,`; - for (var i = 0, ii = data.length; i < ii; i += 3) { - var b1 = data[i] & 0xFF; - var b2 = data[i + 1] & 0xFF; - var b3 = data[i + 2] & 0xFF; - var d1 = b1 >> 2, - d2 = (b1 & 3) << 4 | b2 >> 4; - var d3 = i + 1 < ii ? (b2 & 0xF) << 2 | b3 >> 6 : 64; - var d4 = i + 2 < ii ? b3 & 0x3F : 64; + for (let i = 0, ii = data.length; i < ii; i += 3) { + const b1 = data[i] & 0xFF; + const b2 = data[i + 1] & 0xFF; + const b3 = data[i + 2] & 0xFF; + const d1 = b1 >> 2, + d2 = (b1 & 3) << 4 | b2 >> 4; + const d3 = i + 1 < ii ? (b2 & 0xF) << 2 | b3 >> 6 : 64; + const d4 = i + 2 < ii ? b3 & 0x3F : 64; buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4]; } @@ -2993,24 +2988,26 @@ class Page { return (0, _util.shadow)(this, 'resources', this._getInheritableProperty('Resources') || _primitives.Dict.empty); } - get mediaBox() { - const mediaBox = this._getInheritableProperty('MediaBox', true); + _getBoundingBox(name) { + const box = this._getInheritableProperty(name, true); - if (!Array.isArray(mediaBox) || mediaBox.length !== 4) { - return (0, _util.shadow)(this, 'mediaBox', LETTER_SIZE_MEDIABOX); + if (Array.isArray(box) && box.length === 4) { + if (box[2] - box[0] !== 0 && box[3] - box[1] !== 0) { + return box; + } + + (0, _util.warn)(`Empty /${name} entry.`); } - return (0, _util.shadow)(this, 'mediaBox', mediaBox); + return null; + } + + get mediaBox() { + return (0, _util.shadow)(this, 'mediaBox', this._getBoundingBox('MediaBox') || LETTER_SIZE_MEDIABOX); } get cropBox() { - const cropBox = this._getInheritableProperty('CropBox', true); - - 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', this._getBoundingBox('CropBox') || this.mediaBox); } get userUnit() { @@ -3024,16 +3021,25 @@ class Page { } get view() { - const mediaBox = this.mediaBox, - cropBox = this.cropBox; + const { + cropBox, + mediaBox + } = this; + let view; - if (mediaBox === cropBox) { - return (0, _util.shadow)(this, 'view', mediaBox); + if (cropBox === mediaBox || (0, _util.isArrayEqual)(cropBox, mediaBox)) { + view = mediaBox; + } else { + const box = _util.Util.intersect(cropBox, mediaBox); + + if (box && box[2] - box[0] !== 0 && box[3] - box[1] !== 0) { + view = box; + } else { + (0, _util.warn)('Empty /CropBox and /MediaBox intersection.'); + } } - const intersection = _util.Util.intersect(cropBox, mediaBox); - - return (0, _util.shadow)(this, 'view', intersection || mediaBox); + return (0, _util.shadow)(this, 'view', view || mediaBox); } get rotate() { @@ -12370,7 +12376,9 @@ var JpegImage = function JpegImageClosure() { bitsCount = 0; fileMarker = findNextFileMarker(data, offset); - if (fileMarker && fileMarker.invalid) { + if (!fileMarker) { + break; + } else if (fileMarker.invalid) { (0, _util.warn)('decodeScan - unexpected MCU data, current marker is: ' + fileMarker.invalid); offset = fileMarker.offset; } @@ -12378,7 +12386,7 @@ var JpegImage = function JpegImageClosure() { var marker = fileMarker && fileMarker.marker; if (!marker || marker <= 0xFF00) { - throw new JpegError('marker was not found'); + throw new JpegError('decodeScan - a valid marker was not found.'); } if (marker >= 0xFFD0 && marker <= 0xFFD7) { @@ -12895,7 +12903,12 @@ var JpegImage = function JpegImageClosure() { break; } - throw new JpegError('unknown marker ' + fileMarker.toString(16)); + if (offset > data.length - 2) { + (0, _util.warn)('JpegImage.parse - reached the end of the image data ' + 'without finding an EOI marker (0xFFD9).'); + break markerLoop; + } + + throw new JpegError('JpegImage.parse - unknown marker: ' + fileMarker.toString(16)); } fileMarker = readUint16(); @@ -20194,7 +20207,13 @@ var PartialEvaluator = function PartialEvaluatorClosure() { groupOptions.knockout = group.get('K') || false; if (group.has('CS')) { - colorSpace = _colorspace.ColorSpace.parse(group.get('CS'), this.xref, resources, this.pdfFunctionFactory); + colorSpace = group.get('CS'); + + if (colorSpace) { + colorSpace = _colorspace.ColorSpace.parse(colorSpace, this.xref, resources, this.pdfFunctionFactory); + } else { + (0, _util.warn)('buildFormXObject - invalid/non-existent Group /CS entry: ' + group.getRaw('CS')); + } } } diff --git a/browser/extensions/pdfjs/content/web/viewer.js b/browser/extensions/pdfjs/content/web/viewer.js index 712cb6c07c46..3856e43e06a5 100644 --- a/browser/extensions/pdfjs/content/web/viewer.js +++ b/browser/extensions/pdfjs/content/web/viewer.js @@ -1638,9 +1638,6 @@ function webViewerInitialized() { }); } }, true); - appConfig.sidebar.toggleButton.addEventListener('click', function () { - PDFViewerApplication.pdfSidebar.toggle(); - }); try { webViewerOpenFileViaURL(file); @@ -4165,6 +4162,9 @@ class PDFSidebar { this.outerContainer.classList.remove('sidebarMoving'); } }); + this.toggleButton.addEventListener('click', () => { + this.toggle(); + }); this.thumbnailButton.addEventListener('click', () => { this.switchView(SidebarView.THUMBS); }); diff --git a/browser/extensions/pdfjs/moz.yaml b/browser/extensions/pdfjs/moz.yaml index 5caa15521c2d..e225a522c0e4 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.3.71 + release: version 2.3.86 # The package's license, where possible using the mnemonic from # https://spdx.org/licenses/