diff options
author | Ryan VanderMeulen <ryanvm@gmail.com> | 2018-04-13 10:46:47 -0400 |
---|---|---|
committer | wolfbeast <mcwerewolf@gmail.com> | 2018-04-19 12:03:19 +0200 |
commit | e2403192f5088d3733762ba6ed4fd74fd0ab4a2d (patch) | |
tree | 1318f8b761a68374b87f961471329faa4a94d63e /browser/extensions/pdfjs/content | |
parent | 9472136272f01b858412f2d9d7854d2daa82496f (diff) | |
download | UXP-e2403192f5088d3733762ba6ed4fd74fd0ab4a2d.tar UXP-e2403192f5088d3733762ba6ed4fd74fd0ab4a2d.tar.gz UXP-e2403192f5088d3733762ba6ed4fd74fd0ab4a2d.tar.lz UXP-e2403192f5088d3733762ba6ed4fd74fd0ab4a2d.tar.xz UXP-e2403192f5088d3733762ba6ed4fd74fd0ab4a2d.zip |
Bug 1452075 - Backport some upstream pdf.js fixes.
Diffstat (limited to 'browser/extensions/pdfjs/content')
-rw-r--r-- | browser/extensions/pdfjs/content/PdfStreamConverter.jsm | 35 | ||||
-rw-r--r-- | browser/extensions/pdfjs/content/build/pdf.worker.js | 67 |
2 files changed, 60 insertions, 42 deletions
diff --git a/browser/extensions/pdfjs/content/PdfStreamConverter.jsm b/browser/extensions/pdfjs/content/PdfStreamConverter.jsm index 3b9f9de26..5e337bbc5 100644 --- a/browser/extensions/pdfjs/content/PdfStreamConverter.jsm +++ b/browser/extensions/pdfjs/content/PdfStreamConverter.jsm @@ -29,7 +29,8 @@ const MOZ_CENTRAL = JSON.parse('true'); const PDFJS_EVENT_ID = 'pdf.js.message'; const PDF_CONTENT_TYPE = 'application/pdf'; const PREF_PREFIX = 'pdfjs'; -const PDF_VIEWER_WEB_PAGE = 'resource://pdf.js/web/viewer.html'; +const PDF_VIEWER_ORIGIN = "resource://pdf.js"; +const PDF_VIEWER_WEB_PAGE = "resource://pdf.js/web/viewer.html"; const MAX_NUMBER_OF_PREFS = 50; const MAX_STRING_PREF_LENGTH = 128; @@ -110,11 +111,15 @@ function log(aMsg) { dump(msg + '\n'); } -function getDOMWindow(aChannel) { +function getDOMWindow(aChannel, aPrincipal) { var requestor = aChannel.notificationCallbacks ? aChannel.notificationCallbacks : aChannel.loadGroup.notificationCallbacks; var win = requestor.getInterface(Components.interfaces.nsIDOMWindow); + // Ensure the window wasn't navigated to something that is not PDF.js. + if (!win.document.nodePrincipal.equals(aPrincipal)) { + return null; + } return win; } @@ -632,7 +637,7 @@ var RangedChromeActions = (function RangedChromeActionsClosure() { loaded: loaded, total: total, chunk: self.dataListener.readData() - }, '*'); + }, PDF_VIEWER_ORIGIN); }; this.dataListener.oncomplete = function () { self.dataListener = null; @@ -646,7 +651,7 @@ var RangedChromeActions = (function RangedChromeActionsClosure() { pdfUrl: this.pdfUrl, length: this.contentLength, data: data - }, '*'); + }, PDF_VIEWER_ORIGIN); return true; }; @@ -668,13 +673,13 @@ var RangedChromeActions = (function RangedChromeActionsClosure() { pdfjsLoadAction: 'range', begin: args.begin, chunk: args.chunk - }, '*'); + }, PDF_VIEWER_ORIGIN); }, onProgress: function RangedChromeActions_onProgress(evt) { domWindow.postMessage({ pdfjsLoadAction: 'rangeProgress', loaded: evt.loaded, - }, '*'); + }, PDF_VIEWER_ORIGIN); } }); }; @@ -723,7 +728,7 @@ var StandardChromeActions = (function StandardChromeActionsClosure() { pdfjsLoadAction: 'progress', loaded: loaded, total: total - }, '*'); + }, PDF_VIEWER_ORIGIN); }; this.dataListener.oncomplete = @@ -732,7 +737,7 @@ var StandardChromeActions = (function StandardChromeActionsClosure() { pdfjsLoadAction: 'complete', data: data, errorCode: errorCode - }, '*'); + }, PDF_VIEWER_ORIGIN); self.dataListener = null; self.originalRequest = null; @@ -977,10 +982,14 @@ PdfStreamConverter.prototype = { listener.onDataAvailable(aRequest, aContext, inputStream, offset, count); }, - onStopRequest: function(request, context, statusCode) { - // We get the DOM window here instead of before the request since it - // may have changed during a redirect. - var domWindow = getDOMWindow(channel); + onStopRequest(request, context, statusCode) { + var domWindow = getDOMWindow(channel, resourcePrincipal); + if (!Components.isSuccessCode(statusCode) || !domWindow) { + // The request may have been aborted and the document may have been + // replaced with something that is not PDF.js, abort attaching. + listener.onStopRequest(aRequest, context, statusCode); + return; + } var actions; if (rangeRequest || streamRequest) { actions = new RangedChromeActions( @@ -991,7 +1000,7 @@ PdfStreamConverter.prototype = { domWindow, contentDispositionFilename, aRequest, dataListener); } var requestListener = new RequestListener(actions); - domWindow.addEventListener(PDFJS_EVENT_ID, function(event) { + domWindow.document.addEventListener(PDFJS_EVENT_ID, function(event) { requestListener.receive(event); }, false, true); if (actions.supportsIntegratedFind()) { diff --git a/browser/extensions/pdfjs/content/build/pdf.worker.js b/browser/extensions/pdfjs/content/build/pdf.worker.js index 4c35bd401..6ce519940 100644 --- a/browser/extensions/pdfjs/content/build/pdf.worker.js +++ b/browser/extensions/pdfjs/content/build/pdf.worker.js @@ -41653,6 +41653,22 @@ var isStream = corePrimitives.isStream; var PostScriptLexer = corePsParser.PostScriptLexer; var PostScriptParser = corePsParser.PostScriptParser; + function toNumberArray(arr) { + if (!Array.isArray(arr)) { + return null; + } + var length = arr.length; + for (var i = 0; i < length; i++) { + if (typeof arr[i] !== 'number') { + var result = new Array(length); + for (var j = 0; j < length; j++) { + result[j] = +arr[j]; + } + return result; + } + } + return arr; + } var PDFFunction = function PDFFunctionClosure() { var CONSTRUCT_SAMPLED = 0; var CONSTRUCT_INTERPOLATED = 2; @@ -41752,8 +41768,8 @@ } return out; } - var domain = dict.getArray('Domain'); - var range = dict.getArray('Range'); + var domain = toNumberArray(dict.getArray('Domain')); + var range = toNumberArray(dict.getArray('Range')); if (!domain || !range) { error('No domain or range'); } @@ -41761,7 +41777,7 @@ var outputSize = range.length / 2; domain = toMultiArray(domain); range = toMultiArray(range); - var size = dict.get('Size'); + var size = toNumberArray(dict.get('Size')); var bps = dict.get('BitsPerSample'); var order = dict.get('Order') || 1; if (order !== 1) { @@ -41769,16 +41785,16 @@ // As in poppler, ignoring order, linear interpolation may work as good info('No support for cubic spline interpolation: ' + order); } - var encode = dict.getArray('Encode'); + var encode = toNumberArray(dict.getArray('Encode')); if (!encode) { encode = []; for (var i = 0; i < inputSize; ++i) { - encode.push(0); - encode.push(size[i] - 1); + encode.push([0, size[i] - 1]); } + } else { + encode = toMultiArray(encode); } - encode = toMultiArray(encode); - var decode = dict.getArray('Decode'); + var decode = toNumberArray(dict.getArray('Decode')); if (!decode) { decode = range; } else { @@ -41873,12 +41889,9 @@ }; }, constructInterpolated: function PDFFunction_constructInterpolated(str, dict) { - var c0 = dict.getArray('C0') || [0]; - var c1 = dict.getArray('C1') || [1]; + var c0 = toNumberArray(dict.getArray('C0')) || [0]; + var c1 = toNumberArray(dict.getArray('C1')) || [1]; var n = dict.get('N'); - if (!isArray(c0) || !isArray(c1)) { - error('Illegal dictionary for interpolated function'); - } var length = c0.length; var diff = []; for (var i = 0; i < length; ++i) { @@ -41904,7 +41917,7 @@ }; }, constructStiched: function PDFFunction_constructStiched(fn, dict, xref) { - var domain = dict.getArray('Domain'); + var domain = toNumberArray(dict.getArray('Domain')); if (!domain) { error('No domain'); } @@ -41915,10 +41928,10 @@ var fnRefs = dict.get('Functions'); var fns = []; for (var i = 0, ii = fnRefs.length; i < ii; ++i) { - fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i]))); + fns.push(PDFFunction.parse(xref, xref.fetchIfRef(fnRefs[i]))); } - var bounds = dict.getArray('Bounds'); - var encode = dict.getArray('Encode'); + var bounds = toNumberArray(dict.getArray('Bounds')); + var encode = toNumberArray(dict.getArray('Encode')); return [ CONSTRUCT_STICHED, domain, @@ -41931,12 +41944,8 @@ var domain = IR[1]; var bounds = IR[2]; var encode = IR[3]; - var fnsIR = IR[4]; - var fns = []; + var fns = IR[4]; var tmpBuf = new Float32Array(1); - for (var i = 0, ii = fnsIR.length; i < ii; i++) { - fns.push(PDFFunction.fromIR(fnsIR[i])); - } return function constructStichedFromIRResult(src, srcOffset, dest, destOffset) { var clip = function constructStichedFromIRClip(v, min, max) { if (v > max) { @@ -41973,8 +41982,8 @@ }; }, constructPostScript: function PDFFunction_constructPostScript(fn, dict, xref) { - var domain = dict.getArray('Domain'); - var range = dict.getArray('Range'); + var domain = toNumberArray(dict.getArray('Domain')); + var range = toNumberArray(dict.getArray('Range')); if (!domain) { error('No domain.'); } @@ -42933,8 +42942,8 @@ case 'AlternateCS': var numComps = IR[1]; var alt = IR[2]; - var tintFnIR = IR[3]; - return new AlternateCS(numComps, ColorSpace.fromIR(alt), PDFFunction.fromIR(tintFnIR)); + var tintFn = IR[3]; + return new AlternateCS(numComps, ColorSpace.fromIR(alt), tintFn); case 'LabCS': whitePoint = IR[1]; blackPoint = IR[2]; @@ -43072,12 +43081,12 @@ numComps = name.length; } alt = ColorSpace.parseToIR(cs[2], xref, res); - var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3])); + var tintFn = PDFFunction.parse(xref, xref.fetchIfRef(cs[3])); return [ 'AlternateCS', numComps, alt, - tintFnIR + tintFn ]; case 'Lab': params = xref.fetchIfRef(cs[1]); @@ -52488,4 +52497,4 @@ })); }.call(pdfjsLibs)); exports.WorkerMessageHandler = pdfjsLibs.pdfjsCoreWorker.WorkerMessageHandler; -}));
\ No newline at end of file +})); |