From b8c0bfe02d0837af4834ca227e414261fcb6ae24 Mon Sep 17 00:00:00 2001 From: Ryan VanderMeulen Date: Thu, 12 Jan 2017 20:19:09 -0500 Subject: [PATCH] Bug 1330830 - Update pdf.js to version 1.6.454. r=bdahl --HG-- extra : rebase_source : 900da5f819a48343355172bd349333ef01415681 --- browser/extensions/pdfjs/README.mozilla | 2 +- browser/extensions/pdfjs/content/PdfJs.jsm | 10 +- .../pdfjs/content/PdfStreamConverter.jsm | 35 ++- .../pdfjs/content/PdfjsChromeUtils.jsm | 2 +- browser/extensions/pdfjs/content/build/pdf.js | 40 ++-- .../pdfjs/content/build/pdf.worker.js | 212 +++++++++--------- .../extensions/pdfjs/content/web/viewer.html | 1 - .../extensions/pdfjs/content/web/viewer.js | 114 +++++----- 8 files changed, 202 insertions(+), 214 deletions(-) diff --git a/browser/extensions/pdfjs/README.mozilla b/browser/extensions/pdfjs/README.mozilla index 2e82c74f2c6a..07316d1f77c6 100644 --- 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.6.418 +Current extension version is: 1.6.454 diff --git a/browser/extensions/pdfjs/content/PdfJs.jsm b/browser/extensions/pdfjs/content/PdfJs.jsm index b18532d2101f..d67a6c5f8486 100644 --- a/browser/extensions/pdfjs/content/PdfJs.jsm +++ b/browser/extensions/pdfjs/content/PdfJs.jsm @@ -197,11 +197,11 @@ var PdfJs = { uninit: function uninit() { if (this._initialized) { - Services.prefs.removeObserver(PREF_DISABLED, this); - Services.prefs.removeObserver(PREF_DISABLED_PLUGIN_TYPES, this); - Services.obs.removeObserver(this, TOPIC_PDFJS_HANDLER_CHANGED); - Services.obs.removeObserver(this, TOPIC_PLUGINS_LIST_UPDATED); - Services.obs.removeObserver(this, TOPIC_PLUGIN_INFO_UPDATED); + Services.prefs.removeObserver(PREF_DISABLED, this, false); + Services.prefs.removeObserver(PREF_DISABLED_PLUGIN_TYPES, this, false); + Services.obs.removeObserver(this, TOPIC_PDFJS_HANDLER_CHANGED, false); + Services.obs.removeObserver(this, TOPIC_PLUGINS_LIST_UPDATED, false); + Services.obs.removeObserver(this, TOPIC_PLUGIN_INFO_UPDATED, false); this._initialized = false; } this._ensureUnregistered(); diff --git a/browser/extensions/pdfjs/content/PdfStreamConverter.jsm b/browser/extensions/pdfjs/content/PdfStreamConverter.jsm index 989ab46a5e7b..41ecb44c4ff8 100644 --- a/browser/extensions/pdfjs/content/PdfStreamConverter.jsm +++ b/browser/extensions/pdfjs/content/PdfStreamConverter.jsm @@ -147,21 +147,6 @@ function getLocalizedString(strings, id, property) { return id; } -function createNewChannel(uri, node) { - return NetUtil.newChannel({ - uri: uri, - loadUsingSystemPrincipal: true, - }); -} - -function asyncOpenChannel(channel, listener, context) { - return channel.asyncOpen2(listener); -} - -function asyncFetchChannel(channel, callback) { - return NetUtil.asyncFetch(channel, callback); -} - // PDF data storage function PdfDataListener(length) { this.length = length; // less than 0, if length is unknown @@ -255,12 +240,15 @@ ChromeActions.prototype = { getService(Ci.nsIExternalHelperAppService); var docIsPrivate = this.isInPrivateBrowsing(); - var netChannel = createNewChannel(blobUri, this.domWindow.document); + var netChannel = NetUtil.newChannel({ + uri: blobUri, + loadUsingSystemPrincipal: true, + }); if ('nsIPrivateBrowsingChannel' in Ci && netChannel instanceof Ci.nsIPrivateBrowsingChannel) { netChannel.setPrivate(docIsPrivate); } - asyncFetchChannel(netChannel, function(aInputStream, aResult) { + NetUtil.asyncFetch(netChannel, function(aInputStream, aResult) { if (!Components.isSuccessCode(aResult)) { if (sendResponse) { sendResponse(true); @@ -318,7 +306,7 @@ ChromeActions.prototype = { } }; - asyncOpenChannel(channel, listener, null); + channel.asyncOpen2(listener); }); }, getLocale: function() { @@ -960,7 +948,10 @@ PdfStreamConverter.prototype = { .createInstance(Ci.nsIBinaryInputStream); // Create a new channel that is viewer loaded as a resource. - var channel = createNewChannel(PDF_VIEWER_WEB_PAGE, null); + var channel = NetUtil.newChannel({ + uri: PDF_VIEWER_WEB_PAGE, + loadUsingSystemPrincipal: true, + }); var listener = this.listener; var dataListener = this.dataListener; @@ -1018,11 +1009,11 @@ PdfStreamConverter.prototype = { var ssm = Cc['@mozilla.org/scriptsecuritymanager;1'] .getService(Ci.nsIScriptSecurityManager); var uri = NetUtil.newURI(PDF_VIEWER_WEB_PAGE); - var resourcePrincipal; - resourcePrincipal = + var resourcePrincipal = ssm.createCodebasePrincipal(uri, aRequest.loadInfo.originAttributes); aRequest.owner = resourcePrincipal; - asyncOpenChannel(channel, proxy, aContext); + + channel.asyncOpen2(proxy); }, // nsIRequestObserver::onStopRequest diff --git a/browser/extensions/pdfjs/content/PdfjsChromeUtils.jsm b/browser/extensions/pdfjs/content/PdfjsChromeUtils.jsm index d485a275bca9..2d97206f967e 100644 --- a/browser/extensions/pdfjs/content/PdfjsChromeUtils.jsm +++ b/browser/extensions/pdfjs/content/PdfjsChromeUtils.jsm @@ -110,7 +110,7 @@ var PdfjsChromeUtils = { this._mmg.removeMessageListener('PDFJS:Parent:removeEventListener', this); this._mmg.removeMessageListener('PDFJS:Parent:updateControlState', this); - Services.obs.removeObserver(this, 'quit-application'); + Services.obs.removeObserver(this, 'quit-application', false); this._mmg = null; this._ppmm = null; diff --git a/browser/extensions/pdfjs/content/build/pdf.js b/browser/extensions/pdfjs/content/build/pdf.js index 3183afb10e30..38b746b3e68e 100644 --- a/browser/extensions/pdfjs/content/build/pdf.js +++ b/browser/extensions/pdfjs/content/build/pdf.js @@ -23,8 +23,8 @@ } }(this, function (exports) { 'use strict'; - var pdfjsVersion = '1.6.418'; - var pdfjsBuild = '59afb4b9'; + var pdfjsVersion = '1.6.454'; + var pdfjsBuild = 'b8cd1433'; var pdfjsFilePath = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : null; var pdfjsLibs = {}; (function pdfjsWrapper() { @@ -1813,9 +1813,8 @@ return new RadioButtonWidgetAnnotationElement(parameters); } else if (parameters.data.checkBox) { return new CheckboxWidgetAnnotationElement(parameters); - } else { - warn('Unimplemented button widget annotation: pushbutton'); } + warn('Unimplemented button widget annotation: pushbutton'); break; case 'Ch': return new ChoiceWidgetAnnotationElement(parameters); @@ -6330,6 +6329,7 @@ this.fontLoader = new FontLoader(loadingTask.docId); this.destroyed = false; this.destroyCapability = null; + this._passwordCapability = null; this.pageCache = []; this.pagePromises = []; this.downloadInfoCapability = createPromiseCapability(); @@ -6342,6 +6342,9 @@ } this.destroyed = true; this.destroyCapability = createPromiseCapability(); + if (this._passwordCapability) { + this._passwordCapability.reject(new Error('Worker was destroyed during onPassword callback')); + } var waitOn = []; this.pageCache.forEach(function (page) { if (page) { @@ -6369,9 +6372,7 @@ }, setupMessageHandler: function WorkerTransport_setupMessageHandler() { var messageHandler = this.messageHandler; - function updatePassword(password) { - messageHandler.send('UpdatePassword', password); - } + var loadingTask = this.loadingTask; var pdfDataRangeTransport = this.pdfDataRangeTransport; if (pdfDataRangeTransport) { pdfDataRangeTransport.addRangeListener(function (begin, chunk) { @@ -6398,18 +6399,19 @@ this.pdfDocument = pdfDocument; loadingTask._capability.resolve(pdfDocument); }, this); - messageHandler.on('NeedPassword', function transportNeedPassword(exception) { - var loadingTask = this.loadingTask; + messageHandler.on('PasswordRequest', function transportPasswordRequest(exception) { + this._passwordCapability = createPromiseCapability(); if (loadingTask.onPassword) { - return loadingTask.onPassword(updatePassword, PasswordResponses.NEED_PASSWORD); + var updatePassword = function (password) { + this._passwordCapability.resolve({ password: password }); + }.bind(this); + loadingTask.onPassword(updatePassword, exception.code); + } else { + this._passwordCapability.reject(new PasswordException(exception.message, exception.code)); } - loadingTask._capability.reject(new PasswordException(exception.message, exception.code)); + return this._passwordCapability.promise; }, this); - messageHandler.on('IncorrectPassword', function transportIncorrectPassword(exception) { - var loadingTask = this.loadingTask; - if (loadingTask.onPassword) { - return loadingTask.onPassword(updatePassword, PasswordResponses.INCORRECT_PASSWORD); - } + messageHandler.on('PasswordException', function transportPasswordException(exception) { loadingTask._capability.reject(new PasswordException(exception.message, exception.code)); }, this); messageHandler.on('InvalidPDF', function transportInvalidPDF(exception) { @@ -6720,9 +6722,8 @@ var objs = this.objs; if (!objs[objId]) { return false; - } else { - return objs[objId].resolved; } + return objs[objId].resolved; }, hasData: function PDFObjects_hasData(objId) { return this.isResolved(objId); @@ -6731,9 +6732,8 @@ var objs = this.objs; if (!objs[objId] || !objs[objId].resolved) { return null; - } else { - return objs[objId].data; } + return objs[objId].data; }, clear: function PDFObjects_clear() { this.objs = Object.create(null); diff --git a/browser/extensions/pdfjs/content/build/pdf.worker.js b/browser/extensions/pdfjs/content/build/pdf.worker.js index 53587e11b279..3a1154d05472 100644 --- a/browser/extensions/pdfjs/content/build/pdf.worker.js +++ b/browser/extensions/pdfjs/content/build/pdf.worker.js @@ -23,8 +23,8 @@ } }(this, function (exports) { 'use strict'; - var pdfjsVersion = '1.6.418'; - var pdfjsBuild = '59afb4b9'; + var pdfjsVersion = '1.6.454'; + var pdfjsBuild = 'b8cd1433'; var pdfjsFilePath = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : null; var pdfjsLibs = {}; (function pdfjsWrapper() { @@ -4717,7 +4717,7 @@ return createBidiText(str, isLTR); } if (startLevel === -1) { - if (strLength / numBidi < 0.3) { + if (numBidi / strLength < 0.3) { isLTR = true; startLevel = 0; } else { @@ -5674,10 +5674,9 @@ return (value - 247) * 256 + dict[pos++] + 108; } else if (value >= 251 && value <= 254) { return -((value - 251) * 256) - dict[pos++] - 108; - } else { - warn('CFFParser_parseDict: "' + value + '" is a reserved command.'); - return NaN; } + warn('CFFParser_parseDict: "' + value + '" is a reserved command.'); + return NaN; } function parseFloatOperand() { var str = ''; @@ -6959,9 +6958,8 @@ encodeNumber: function CFFCompiler_encodeNumber(value) { if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { return this.encodeInteger(value); - } else { - return this.encodeFloat(value); } + return this.encodeFloat(value); }, encodeFloat: function CFFCompiler_encodeFloat(num) { var value = num.toString(); @@ -14249,12 +14247,11 @@ return false; } return true; - } else { - if (!this.adobe && this.colorTransform === 1) { - return true; - } - return false; } + if (!this.adobe && this.colorTransform === 1) { + return true; + } + return false; }, _convertYccToRgb: function convertYccToRgb(data) { var Y, Cb, Cr; @@ -14338,9 +14335,8 @@ if (this._isColorConversionNeeded()) { if (forceRGBoutput) { return this._convertYcckToRgb(data); - } else { - return this._convertYcckToCmyk(data); } + return this._convertYcckToCmyk(data); } else if (forceRGBoutput) { return this._convertCmykToRgb(data); } @@ -23529,12 +23525,14 @@ var inbits = 0, outbits = 0; var pos = bufferLength; var i; - if (bits === 1) { + if (bits === 1 && colors === 1) { for (i = 0; i < rowBytes; ++i) { - var c = rawBytes[i]; - inbuf = inbuf << 8 | c; - buffer[pos++] = (c ^ inbuf >> colors) & 0xFF; - inbuf &= 0xFFFF; + var c = rawBytes[i] ^ inbuf; + c ^= c >> 1; + c ^= c >> 2; + c ^= c >> 4; + inbuf = (c & 1) << 7; + buffer[pos++] = c; } } else if (bits === 8) { for (i = 0; i < colors; ++i) { @@ -33589,9 +33587,8 @@ 0 ]; return new TrueTypeCompiled(parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix); - } else { - return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap); } + return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap); } }; }(); @@ -38334,7 +38331,7 @@ } var isTrueType = !tables['CFF ']; if (!isTrueType) { - if (header.version === 'OTTO' && properties.type !== 'CIDFontType2' || !tables['head'] || !tables['hhea'] || !tables['maxp'] || !tables['post']) { + if (header.version === 'OTTO' && !properties.composite || !tables['head'] || !tables['hhea'] || !tables['maxp'] || !tables['post']) { cffFile = new Stream(tables['CFF '].data); cff = new CFFFont(cffFile, properties); adjustWidths(properties); @@ -38436,7 +38433,7 @@ } return false; } - if (properties.type === 'CIDFontType2') { + if (properties.composite) { var cidToGidMap = properties.cidToGidMap || []; var isCidToGidMapEmpty = cidToGidMap.length === 0; properties.cMap.forEach(function (charCode, cid) { @@ -41338,11 +41335,13 @@ } } function fn_g(x) { + var result; if (x >= 6 / 29) { - return x * x * x; + result = x * x * x; } else { - return 108 / 841 * (x - 4 / 29); + result = 108 / 841 * (x - 4 / 29); } + return result; } function decode(value, high1, low2, high2) { return low2 + value * (high2 - low2) / high1; @@ -41424,9 +41423,8 @@ function handleImageData(image, nativeDecoder) { if (nativeDecoder && nativeDecoder.canDecode(image)) { return nativeDecoder.decode(image); - } else { - return Promise.resolve(image); } + return Promise.resolve(image); } function decodeAndClamp(value, addend, coefficient, max) { value = addend + value * coefficient; @@ -42498,12 +42496,12 @@ return Catalog; }(); var XRef = function XRefClosure() { - function XRef(stream, password) { + function XRef(stream, pdfManager) { this.stream = stream; + this.pdfManager = pdfManager; this.entries = []; this.xrefstms = Object.create(null); this.cache = []; - this.password = password; this.stats = { streamTypes: [], fontTypes: [] @@ -42524,11 +42522,11 @@ trailerDict.assignXref(this); this.trailer = trailerDict; var encrypt = trailerDict.get('Encrypt'); - if (encrypt) { + if (isDict(encrypt)) { var ids = trailerDict.get('ID'); var fileId = ids && ids.length ? ids[0] : ''; encrypt.suppressEncryption = true; - this.encrypt = new CipherTransformFactory(encrypt, fileId, this.password); + this.encrypt = new CipherTransformFactory(encrypt, fileId, this.pdfManager.password); } if (!(this.root = trailerDict.get('Root'))) { error('Invalid root reference'); @@ -43178,9 +43176,8 @@ return dict.get('Mac'); } else if (dict.has('DOS')) { return dict.get('DOS'); - } else { - return null; } + return null; } FileSpec.prototype = { get filename() { @@ -44283,13 +44280,12 @@ var cs = ColorSpace.parse(dict.get('ColorSpace', 'CS'), xref, res); return (cs.numComps === 1 || cs.numComps === 3) && cs.isDefaultDecode(dict.getArray('Decode', 'D')); }; - function PartialEvaluator(pdfManager, xref, handler, pageIndex, uniquePrefix, idCounters, fontCache, options) { + function PartialEvaluator(pdfManager, xref, handler, pageIndex, idFactory, fontCache, options) { this.pdfManager = pdfManager; this.xref = xref; this.handler = handler; this.pageIndex = pageIndex; - this.uniquePrefix = uniquePrefix; - this.idCounters = idCounters; + this.idFactory = idFactory; this.fontCache = fontCache; this.options = options || DefaultPartialEvaluatorOptions; } @@ -44452,8 +44448,7 @@ operatorList.addOp(OPS.paintInlineImageXObject, [imgData]); return; } - var uniquePrefix = this.uniquePrefix || ''; - var objId = 'img_' + uniquePrefix + ++this.idCounters.obj; + var objId = 'img_' + this.idFactory.createObjId(); operatorList.addDependency(objId); args = [ objId, @@ -44737,7 +44732,7 @@ this.fontCache.put(fontRef, fontCapability.promise); } else { if (!fontID) { - fontID = (this.uniquePrefix || 'F_') + ++this.idCounters.obj; + fontID = this.idFactory.createObjId(); } this.fontCache.put('id_' + fontID, fontCapability.promise); } @@ -44803,9 +44798,8 @@ pattern = Pattern.parseShading(shading, matrix, xref, resources, this.handler); operatorList.addOp(fn, pattern.getIR()); return Promise.resolve(); - } else { - return Promise.reject('Unknown PatternType: ' + typeNum); } + return Promise.reject('Unknown PatternType: ' + typeNum); } operatorList.addOp(fn, args); return Promise.resolve(); @@ -46759,17 +46753,16 @@ operation.fn = fn; operation.args = args; return true; - } else { - if (isEOF(obj)) { - return false; - } - if (obj !== null) { - if (args === null) { - args = []; - } - args.push(obj); - assert(args.length <= 33, 'Too many arguments'); + } + if (isEOF(obj)) { + return false; + } + if (obj !== null) { + if (args === null) { + args = []; } + args.push(obj); + assert(args.length <= 33, 'Too many arguments'); } } }, @@ -47144,12 +47137,12 @@ function AnnotationFactory() { } AnnotationFactory.prototype = { - create: function AnnotationFactory_create(xref, ref, pdfManager, uniquePrefix, idCounters) { + create: function AnnotationFactory_create(xref, ref, pdfManager, idFactory) { var dict = xref.fetchIfRef(ref); if (!isDict(dict)) { return; } - var id = isRef(ref) ? ref.toString() : 'annot_' + (uniquePrefix || '') + ++idCounters.obj; + var id = isRef(ref) ? ref.toString() : 'annot_' + idFactory.createObjId(); var subtype = dict.get('Subtype'); subtype = isName(subtype) ? subtype.name : null; var parameters = { @@ -47849,10 +47842,15 @@ this.xref = xref; this.ref = ref; this.fontCache = fontCache; - this.uniquePrefix = 'p' + this.pageIndex + '_'; - this.idCounters = { obj: 0 }; this.evaluatorOptions = pdfManager.evaluatorOptions; this.resourcesPromise = null; + var uniquePrefix = 'p' + this.pageIndex + '_'; + var idCounters = { obj: 0 }; + this.idFactory = { + createObjId: function () { + return uniquePrefix + ++idCounters.obj; + } + }; } Page.prototype = { getPageProp: function Page_getPageProp(key) { @@ -47969,7 +47967,7 @@ 'XObject', 'Font' ]); - var partialEvaluator = new PartialEvaluator(pdfManager, this.xref, handler, this.pageIndex, this.uniquePrefix, this.idCounters, this.fontCache, this.evaluatorOptions); + var partialEvaluator = new PartialEvaluator(pdfManager, this.xref, handler, this.pageIndex, this.idFactory, this.fontCache, this.evaluatorOptions); var dataPromises = Promise.all([ contentStreamPromise, resourcesPromise @@ -48025,7 +48023,7 @@ ]); return dataPromises.then(function (data) { var contentStream = data[0]; - var partialEvaluator = new PartialEvaluator(pdfManager, self.xref, handler, self.pageIndex, self.uniquePrefix, self.idCounters, self.fontCache, self.evaluatorOptions); + var partialEvaluator = new PartialEvaluator(pdfManager, self.xref, handler, self.pageIndex, self.idFactory, self.fontCache, self.evaluatorOptions); return partialEvaluator.getTextContent(contentStream, task, self.resources, null, normalizeWhitespace, combineTextItems); }); }, @@ -48048,7 +48046,7 @@ var annotationFactory = new AnnotationFactory(); for (var i = 0, n = annotationRefs.length; i < n; ++i) { var annotationRef = annotationRefs[i]; - var annotation = annotationFactory.create(this.xref, annotationRef, this.pdfManager, this.uniquePrefix, this.idCounters); + var annotation = annotationFactory.create(this.xref, annotationRef, this.pdfManager, this.idFactory); if (annotation) { annotations.push(annotation); } @@ -48061,21 +48059,19 @@ 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 PDFDocument(pdfManager, arg, password) { + function PDFDocument(pdfManager, arg) { + var stream; if (isStream(arg)) { - init.call(this, pdfManager, arg, password); + stream = arg; } else if (isArrayBuffer(arg)) { - init.call(this, pdfManager, new Stream(arg), password); + stream = new Stream(arg); } else { error('PDFDocument: Unknown argument type'); } - } - function init(pdfManager, stream, password) { assert(stream.length > 0, 'stream must have data'); this.pdfManager = pdfManager; this.stream = stream; - var xref = new XRef(this.stream, password, pdfManager); - this.xref = xref; + this.xref = new XRef(stream, pdfManager); } function find(stream, needle, limit, backwards) { var pos = stream.pos; @@ -48308,6 +48304,9 @@ get docId() { return this._docId; }, + get password() { + return this._password; + }, get docBaseUrl() { var docBaseUrl = null; if (this._docBaseUrl) { @@ -48351,14 +48350,7 @@ return new NotImplementedException(); }, updatePassword: function BasePdfManager_updatePassword(password) { - this.pdfDocument.xref.password = this.password = password; - if (this._passwordChangedCapability) { - this._passwordChangedCapability.resolve(); - } - }, - passwordChanged: function BasePdfManager_passwordChanged() { - this._passwordChangedCapability = createPromiseCapability(); - return this._passwordChangedCapability.promise; + this._password = password; }, terminate: function BasePdfManager_terminate() { return new NotImplementedException(); @@ -48369,10 +48361,11 @@ var LocalPdfManager = function LocalPdfManagerClosure() { function LocalPdfManager(docId, data, password, evaluatorOptions, docBaseUrl) { this._docId = docId; + this._password = password; this._docBaseUrl = docBaseUrl; this.evaluatorOptions = evaluatorOptions; var stream = new Stream(data); - this.pdfDocument = new PDFDocument(this, stream, password); + this.pdfDocument = new PDFDocument(this, stream); this._loadedStreamCapability = createPromiseCapability(); this._loadedStreamCapability.resolve(stream); } @@ -48397,13 +48390,11 @@ return Promise.resolve(); }, requestLoadedStream: function LocalPdfManager_requestLoadedStream() { - return; }, onLoadedStream: function LocalPdfManager_onLoadedStream() { return this._loadedStreamCapability.promise; }, terminate: function LocalPdfManager_terminate() { - return; } }); return LocalPdfManager; @@ -48411,6 +48402,7 @@ var NetworkPdfManager = function NetworkPdfManagerClosure() { function NetworkPdfManager(docId, pdfNetworkStream, args, evaluatorOptions, docBaseUrl) { this._docId = docId; + this._password = args.password; this._docBaseUrl = docBaseUrl; this.msgHandler = args.msgHandler; this.evaluatorOptions = evaluatorOptions; @@ -48422,7 +48414,7 @@ rangeChunkSize: args.rangeChunkSize }; this.streamManager = new ChunkedStreamManager(pdfNetworkStream, params); - this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(), args.password); + this.pdfDocument = new PDFDocument(this, this.streamManager.getStream()); } Util.inherit(NetworkPdfManager, BasePdfManager, { ensure: function NetworkPdfManager_ensure(obj, prop, args) { @@ -48924,18 +48916,23 @@ }; return pdfManagerCapability.promise; } - var setupDoc = function (data) { - var onSuccess = function (doc) { + function setupDoc(data) { + function onSuccess(doc) { ensureNotTerminated(); handler.send('GetDoc', { pdfInfo: doc }); - }; - var onFailure = function (e) { + } + function onFailure(e) { if (e instanceof PasswordException) { - if (e.code === PasswordResponses.NEED_PASSWORD) { - handler.send('NeedPassword', e); - } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) { - handler.send('IncorrectPassword', e); - } + var task = new WorkerTask('PasswordException: response ' + e.code); + startWorkerTask(task); + handler.sendWithPromise('PasswordRequest', e).then(function (data) { + finishWorkerTask(task); + pdfManager.updatePassword(data.password); + pdfManagerReady(); + }).catch(function (ex) { + finishWorkerTask(task); + handler.send('PasswordException', ex); + }.bind(null, e)); } else if (e instanceof InvalidPDFException) { handler.send('InvalidPDF', e); } else if (e instanceof MissingPDFException) { @@ -48945,7 +48942,22 @@ } else { handler.send('UnknownError', new UnknownErrorException(e.message, e.toString())); } - }; + } + function pdfManagerReady() { + ensureNotTerminated(); + loadDocument(false).then(onSuccess, function loadFailure(ex) { + ensureNotTerminated(); + if (!(ex instanceof XRefParseException)) { + onFailure(ex); + return; + } + pdfManager.requestLoadedStream(); + pdfManager.onLoadedStream().then(function () { + ensureNotTerminated(); + loadDocument(true).then(onSuccess, onFailure); + }); + }, onFailure); + } ensureNotTerminated(); var cMapOptions = { url: data.cMapUrl === undefined ? null : data.cMapUrl, @@ -48967,25 +48979,8 @@ pdfManager.onLoadedStream().then(function (stream) { handler.send('DataLoaded', { length: stream.bytes.byteLength }); }); - }).then(function pdfManagerReady() { - ensureNotTerminated(); - loadDocument(false).then(onSuccess, function loadFailure(ex) { - ensureNotTerminated(); - if (!(ex instanceof XRefParseException)) { - if (ex instanceof PasswordException) { - pdfManager.passwordChanged().then(pdfManagerReady); - } - onFailure(ex); - return; - } - pdfManager.requestLoadedStream(); - pdfManager.onLoadedStream().then(function () { - ensureNotTerminated(); - loadDocument(true).then(onSuccess, onFailure); - }); - }, onFailure); - }, onFailure); - }; + }).then(pdfManagerReady, onFailure); + } handler.on('GetPage', function wphSetupGetPage(data) { return pdfManager.getPage(data.pageIndex).then(function (page) { var rotatePromise = pdfManager.ensure(page, 'rotate'); @@ -49045,9 +49040,6 @@ handler.on('GetStats', function wphSetupGetStats(data) { return pdfManager.pdfDocument.xref.stats; }); - handler.on('UpdatePassword', function wphSetupUpdatePassword(data) { - pdfManager.updatePassword(data); - }); handler.on('GetAnnotations', function wphSetupGetAnnotations(data) { return pdfManager.getPage(data.pageIndex).then(function (page) { return pdfManager.ensure(page, 'getAnnotationsData', [data.intent]); diff --git a/browser/extensions/pdfjs/content/web/viewer.html b/browser/extensions/pdfjs/content/web/viewer.html index 3a06aa7b1610..17ac030aa9eb 100644 --- a/browser/extensions/pdfjs/content/web/viewer.html +++ b/browser/extensions/pdfjs/content/web/viewer.html @@ -38,7 +38,6 @@ See https://github.com/adobe-type-tools/cmap-resources - diff --git a/browser/extensions/pdfjs/content/web/viewer.js b/browser/extensions/pdfjs/content/web/viewer.js index 1ee979322a8a..8a83a2485bc4 100644 --- a/browser/extensions/pdfjs/content/web/viewer.js +++ b/browser/extensions/pdfjs/content/web/viewer.js @@ -358,26 +358,31 @@ var pdfjsWebLibs; (function (root, factory) { factory(root.pdfjsWebPreferences = {}); }(this, function (exports) { - var defaultPreferences; - defaultPreferences = Promise.resolve({ - "showPreviousViewOnLoad": true, - "defaultZoomValue": "", - "sidebarViewOnLoad": 0, - "enableHandToolOnLoad": false, - "enableWebGL": false, - "pdfBugEnabled": false, - "disableRange": false, - "disableStream": false, - "disableAutoFetch": false, - "disableFontFace": false, - "disableTextLayer": false, - "useOnlyCssZoom": false, - "externalLinkTarget": 0, - "enhanceTextSelection": false, - "renderer": "canvas", - "renderInteractiveForms": false, - "disablePageLabels": false - }); + var defaultPreferences = null; + function getDefaultPreferences() { + if (!defaultPreferences) { + defaultPreferences = Promise.resolve({ + "showPreviousViewOnLoad": true, + "defaultZoomValue": "", + "sidebarViewOnLoad": 0, + "enableHandToolOnLoad": false, + "enableWebGL": false, + "pdfBugEnabled": false, + "disableRange": false, + "disableStream": false, + "disableAutoFetch": false, + "disableFontFace": false, + "disableTextLayer": false, + "useOnlyCssZoom": false, + "externalLinkTarget": 0, + "enhanceTextSelection": false, + "renderer": "canvas", + "renderInteractiveForms": false, + "disablePageLabels": false + }); + } + return defaultPreferences; + } function cloneObj(obj) { var result = {}; for (var i in obj) { @@ -392,7 +397,7 @@ var pdfjsWebLibs; isInitializedPromiseResolved: false, initializedPromise: null, initialize: function preferencesInitialize() { - return this.initializedPromise = defaultPreferences.then(function (defaults) { + return this.initializedPromise = getDefaultPreferences().then(function (defaults) { Object.defineProperty(this, 'defaults', { value: Object.freeze(defaults), writable: false, @@ -1132,8 +1137,9 @@ var pdfjsWebLibs; b = q; } } + var result; if (x_ - a / b < c / d - x_) { - return x_ === x ? [ + result = x_ === x ? [ a, b ] : [ @@ -1141,7 +1147,7 @@ var pdfjsWebLibs; a ]; } else { - return x_ === x ? [ + result = x_ === x ? [ c, d ] : [ @@ -1149,6 +1155,7 @@ var pdfjsWebLibs; c ]; } + return result; } function roundToDivide(x, div) { var r = x % div; @@ -1701,12 +1708,11 @@ var pdfjsWebLibs; size_kb: (+kb.toPrecision(3)).toLocaleString(), size_b: fileSize.toLocaleString() }, '{{size_kb}} KB ({{size_b}} bytes)'); - } else { - return mozL10n.get('document_properties_mb', { - size_mb: (+(kb / 1024).toPrecision(3)).toLocaleString(), - size_b: fileSize.toLocaleString() - }, '{{size_mb}} MB ({{size_b}} bytes)'); } + return mozL10n.get('document_properties_mb', { + size_mb: (+(kb / 1024).toPrecision(3)).toLocaleString(), + size_b: fileSize.toLocaleString() + }, '{{size_mb}} MB ({{size_b}} bytes)'); }, _parseDate: function PDFDocumentProperties_parseDate(inputDate) { var dateToParse = inputDate; @@ -2027,17 +2033,16 @@ var pdfjsWebLibs; offset.matchIdx = previous ? numMatches - 1 : 0; this.updateMatch(true); return true; - } else { - this.advanceOffsetPage(previous); - if (offset.wrapped) { - offset.matchIdx = null; - if (this.pagesToSearch < 0) { - this.updateMatch(false); - return true; - } - } - return false; } + this.advanceOffsetPage(previous); + if (offset.wrapped) { + offset.matchIdx = null; + if (this.pagesToSearch < 0) { + this.updateMatch(false); + return true; + } + } + return false; }, updateMatchPosition: function PDFFindController_updateMatchPosition(pageIndex, index, elements, beginIdx) { if (this.selected.matchIdx === index && this.selected.pageIdx === pageIndex) { @@ -3374,9 +3379,8 @@ var pdfjsWebLibs; this.nextHashParam = null; this.updatePreviousBookmark = true; return; - } else { - this.nextHashParam = null; } + this.nextHashParam = null; } if (params.hash) { if (this.current.hash) { @@ -3576,7 +3580,6 @@ var pdfjsWebLibs; goToDestination(destRef); }).catch(function () { console.error('PDFLinkService_navigateTo: "' + destRef + '" is not a valid page reference.'); - return; }); } }; @@ -5336,19 +5339,18 @@ var pdfjsWebLibs; _getVisiblePages: function () { if (!this.isInPresentationMode) { return getVisibleElements(this.container, this._pages, true); - } else { - var visible = []; - var currentPage = this._pages[this._currentPageNumber - 1]; - visible.push({ - id: currentPage.id, - view: currentPage - }); - return { - first: currentPage, - last: currentPage, - views: visible - }; } + var visible = []; + var currentPage = this._pages[this._currentPageNumber - 1]; + visible.push({ + id: currentPage.id, + view: currentPage + }); + return { + first: currentPage, + last: currentPage, + views: visible + }; }, cleanup: function () { for (var i = 0, ii = this._pages.length; i < ii; i++) { @@ -7362,4 +7364,8 @@ function webViewerLoad() { window.PDFViewerApplication = pdfjsWebLibs.pdfjsWebApp.PDFViewerApplication; pdfjsWebLibs.pdfjsWebApp.PDFViewerApplication.run(config); } -document.addEventListener('DOMContentLoaded', webViewerLoad, true); \ No newline at end of file +if (document.readyState === 'interactive' || document.readyState === 'complete') { + webViewerLoad(); +} else { + document.addEventListener('DOMContentLoaded', webViewerLoad, true); +} \ No newline at end of file