Bug 1217930 - Update pdf.js to version 1.1.551. r=bdahl, r=Mossop

This commit is contained in:
Ryan VanderMeulen 2015-10-23 13:57:59 -04:00
parent c145aa0da2
commit f130bf377c
5 changed files with 478 additions and 156 deletions

View File

@ -1,3 +1,3 @@
This is the pdf.js project output, https://github.com/mozilla/pdf.js
Current extension version is: 1.1.527
Current extension version is: 1.1.551

View File

@ -607,8 +607,8 @@ var RangedChromeActions = (function RangedChromeActionsClosure() {
// If we are in range request mode, this means we manually issued xhr
// requests, which we need to abort when we leave the page
domWindow.addEventListener('unload', function unload(e) {
self.networkManager.abortAllRequests();
domWindow.removeEventListener(e.type, unload);
self.abortLoading();
});
}
@ -636,7 +636,7 @@ var RangedChromeActions = (function RangedChromeActionsClosure() {
}, '*');
};
this.dataListener.oncomplete = function () {
delete self.dataListener;
self.dataListener = null;
};
}
@ -680,6 +680,15 @@ var RangedChromeActions = (function RangedChromeActionsClosure() {
});
};
proto.abortLoading = function RangedChromeActions_abortLoading() {
this.networkManager.abortAllRequests();
if (this.originalRequest) {
this.originalRequest.cancel(Cr.NS_BINDING_ABORTED);
this.originalRequest = null;
}
this.dataListener = null;
};
return RangedChromeActions;
})();
@ -689,9 +698,10 @@ var StandardChromeActions = (function StandardChromeActionsClosure() {
* This is for a single network stream
*/
function StandardChromeActions(domWindow, contentDispositionFilename,
dataListener) {
originalRequest, dataListener) {
ChromeActions.call(this, domWindow, contentDispositionFilename);
this.originalRequest = originalRequest;
this.dataListener = dataListener;
}
@ -717,20 +727,29 @@ var StandardChromeActions = (function StandardChromeActionsClosure() {
}, '*');
};
this.dataListener.oncomplete = function ChromeActions_dataListenerComplete(
data, errorCode) {
this.dataListener.oncomplete =
function StandardChromeActions_dataListenerComplete(data, errorCode) {
self.domWindow.postMessage({
pdfjsLoadAction: 'complete',
data: data,
errorCode: errorCode
}, '*');
delete self.dataListener;
self.dataListener = null;
self.originalRequest = null;
};
return true;
};
proto.abortLoading = function StandardChromeActions_abortLoading() {
if (this.originalRequest) {
this.originalRequest.cancel(Cr.NS_BINDING_ABORTED);
this.originalRequest = null;
}
this.dataListener = null;
};
return StandardChromeActions;
})();
@ -969,7 +988,7 @@ PdfStreamConverter.prototype = {
rangeRequest, streamRequest, dataListener);
} else {
actions = new StandardChromeActions(
domWindow, contentDispositionFilename, dataListener);
domWindow, contentDispositionFilename, aRequest, dataListener);
}
var requestListener = new RequestListener(actions);
domWindow.addEventListener(PDFJS_EVENT_ID, function(event) {

View File

@ -22,8 +22,8 @@ if (typeof PDFJS === 'undefined') {
(typeof window !== 'undefined' ? window : this).PDFJS = {};
}
PDFJS.version = '1.1.527';
PDFJS.build = '2096a2a';
PDFJS.version = '1.1.551';
PDFJS.build = '2a5616c';
(function pdfjsWrapper() {
// Use strict in our context only - users might not want it
@ -225,6 +225,11 @@ function warn(msg) {
}
}
// Deprecated API function -- treated as warnings.
function deprecated(details) {
warn('Deprecated API usage: ' + details);
}
// Fatal errors that should trigger the fallback UI and halt execution by
// throwing an exception.
function error(msg) {
@ -1557,12 +1562,19 @@ PDFJS.getDocument = function getDocument(src,
var task = new PDFDocumentLoadingTask();
// Support of the obsolete arguments (for compatibility with API v1.0)
if (arguments.length > 1) {
deprecated('getDocument is called with pdfDataRangeTransport, ' +
'passwordCallback or progressCallback argument');
}
if (pdfDataRangeTransport) {
if (!(pdfDataRangeTransport instanceof PDFDataRangeTransport)) {
// Not a PDFDataRangeTransport instance, trying to add missing properties.
pdfDataRangeTransport = Object.create(pdfDataRangeTransport);
pdfDataRangeTransport.length = src.length;
pdfDataRangeTransport.initialData = src.initialData;
if (!pdfDataRangeTransport.abort) {
pdfDataRangeTransport.abort = function () {};
}
}
src = Object.create(src);
src.range = pdfDataRangeTransport;
@ -1622,6 +1634,7 @@ PDFJS.getDocument = function getDocument(src,
workerInitializedCapability.promise.then(function transportInitialized() {
transport.fetchDocument(task, params);
});
task._transport = transport;
return task;
};
@ -1634,6 +1647,7 @@ var PDFDocumentLoadingTask = (function PDFDocumentLoadingTaskClosure() {
/** @constructs PDFDocumentLoadingTask */
function PDFDocumentLoadingTask() {
this._capability = createPromiseCapability();
this._transport = null;
/**
* Callback to request a password if wrong or no password was provided.
@ -1659,7 +1673,14 @@ var PDFDocumentLoadingTask = (function PDFDocumentLoadingTaskClosure() {
return this._capability.promise;
},
// TODO add cancel or abort method
/**
* Aborts all network requests and destroys worker.
* @return {Promise} A promise that is resolved after destruction activity
* is completed.
*/
destroy: function () {
return this._transport.destroy();
},
/**
* Registers callbacks to indicate the document loading completion.
@ -1746,6 +1767,9 @@ var PDFDataRangeTransport = (function pdfDataRangeTransportClosure() {
requestDataRange:
function PDFDataRangeTransport_requestDataRange(begin, end) {
throw new Error('Abstract method PDFDataRangeTransport.requestDataRange');
},
abort: function PDFDataRangeTransport_abort() {
}
};
return PDFDataRangeTransport;
@ -1759,9 +1783,10 @@ PDFJS.PDFDataRangeTransport = PDFDataRangeTransport;
* @class
*/
var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
function PDFDocumentProxy(pdfInfo, transport) {
function PDFDocumentProxy(pdfInfo, transport, loadingTask) {
this.pdfInfo = pdfInfo;
this.transport = transport;
this.loadingTask = loadingTask;
}
PDFDocumentProxy.prototype = /** @lends PDFDocumentProxy.prototype */ {
/**
@ -1884,7 +1909,7 @@ var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
* Destroys current document instance and terminates worker.
*/
destroy: function PDFDocumentProxy_destroy() {
this.transport.destroy();
return this.transport.destroy();
}
};
return PDFDocumentProxy;
@ -1961,8 +1986,9 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
this.commonObjs = transport.commonObjs;
this.objs = new PDFObjects();
this.cleanupAfterRender = false;
this.pendingDestroy = false;
this.pendingCleanup = false;
this.intentStates = {};
this.destroyed = false;
}
PDFPageProxy.prototype = /** @lends PDFPageProxy.prototype */ {
/**
@ -2026,7 +2052,7 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
// If there was a pending destroy cancel it so no cleanup happens during
// this call to render.
this.pendingDestroy = false;
this.pendingCleanup = false;
var renderingIntent = (params.intent === 'print' ? 'print' : 'display');
@ -2067,13 +2093,14 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
// Obsolete parameter support
if (params.continueCallback) {
deprecated('render is used with continueCallback parameter');
renderTask.onContinue = params.continueCallback;
}
var self = this;
intentState.displayReadyCapability.promise.then(
function pageDisplayReadyPromise(transparency) {
if (self.pendingDestroy) {
if (self.pendingCleanup) {
complete();
return;
}
@ -2093,9 +2120,9 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
}
if (self.cleanupAfterRender) {
self.pendingDestroy = true;
self.pendingCleanup = true;
}
self._tryDestroy();
self._tryCleanup();
if (error) {
internalRenderTask.capability.reject(error);
@ -2156,20 +2183,52 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
pageIndex: this.pageNumber - 1
});
},
/**
* Destroys resources allocated by the page.
* Destroys page object.
*/
destroy: function PDFPageProxy_destroy() {
this.pendingDestroy = true;
this._tryDestroy();
_destroy: function PDFPageProxy_destroy() {
this.destroyed = true;
this.transport.pageCache[this.pageIndex] = null;
var waitOn = [];
Object.keys(this.intentStates).forEach(function(intent) {
var intentState = this.intentStates[intent];
intentState.renderTasks.forEach(function(renderTask) {
var renderCompleted = renderTask.capability.promise.
catch(function () {}); // ignoring failures
waitOn.push(renderCompleted);
renderTask.cancel();
});
}, this);
this.objs.clear();
this.annotationsPromise = null;
this.pendingCleanup = false;
return Promise.all(waitOn);
},
/**
* Cleans up resources allocated by the page. (deprecated)
*/
destroy: function() {
deprecated('page destroy method, use cleanup() instead');
this.cleanup();
},
/**
* Cleans up resources allocated by the page.
*/
cleanup: function PDFPageProxy_cleanup() {
this.pendingCleanup = true;
this._tryCleanup();
},
/**
* For internal use only. Attempts to clean up if rendering is in a state
* where that's possible.
* @ignore
*/
_tryDestroy: function PDFPageProxy__destroy() {
if (!this.pendingDestroy ||
_tryCleanup: function PDFPageProxy_tryCleanup() {
if (!this.pendingCleanup ||
Object.keys(this.intentStates).some(function(intent) {
var intentState = this.intentStates[intent];
return (intentState.renderTasks.length !== 0 ||
@ -2183,7 +2242,7 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
}, this);
this.objs.clear();
this.annotationsPromise = null;
this.pendingDestroy = false;
this.pendingCleanup = false;
},
/**
* For internal use only.
@ -2221,7 +2280,7 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
if (operatorListChunk.lastChunk) {
intentState.receivingOperatorList = false;
this._tryDestroy();
this._tryCleanup();
}
}
};
@ -2239,6 +2298,8 @@ var WorkerTransport = (function WorkerTransportClosure() {
this.commonObjs = new PDFObjects();
this.loadingTask = null;
this.destroyed = false;
this.destroyCapability = null;
this.pageCache = [];
this.pagePromises = [];
@ -2297,15 +2358,40 @@ var WorkerTransport = (function WorkerTransportClosure() {
}
WorkerTransport.prototype = {
destroy: function WorkerTransport_destroy() {
if (this.destroyCapability) {
return this.destroyCapability.promise;
}
this.destroyed = true;
this.destroyCapability = createPromiseCapability();
var waitOn = [];
// We need to wait for all renderings to be completed, e.g.
// timeout/rAF can take a long time.
this.pageCache.forEach(function (page) {
if (page) {
waitOn.push(page._destroy());
}
});
this.pageCache = [];
this.pagePromises = [];
var self = this;
this.messageHandler.sendWithPromise('Terminate', null).then(function () {
// We also need to wait for the worker to finish its long running tasks.
var terminated = this.messageHandler.sendWithPromise('Terminate', null);
waitOn.push(terminated);
Promise.all(waitOn).then(function () {
FontLoader.clear();
if (self.worker) {
self.worker.terminate();
}
});
if (self.pdfDataRangeTransport) {
self.pdfDataRangeTransport.abort();
self.pdfDataRangeTransport = null;
}
self.messageHandler = null;
self.destroyCapability.resolve();
}, this.destroyCapability.reject);
return this.destroyCapability.promise;
},
setupFakeWorker: function WorkerTransport_setupFakeWorker() {
@ -2379,9 +2465,10 @@ var WorkerTransport = (function WorkerTransportClosure() {
messageHandler.on('GetDoc', function transportDoc(data) {
var pdfInfo = data.pdfInfo;
this.numPages = data.pdfInfo.numPages;
var pdfDocument = new PDFDocumentProxy(pdfInfo, this);
var loadingTask = this.loadingTask;
var pdfDocument = new PDFDocumentProxy(pdfInfo, this, loadingTask);
this.pdfDocument = pdfDocument;
this.loadingTask._capability.resolve(pdfDocument);
loadingTask._capability.resolve(pdfDocument);
}, this);
messageHandler.on('NeedPassword',
@ -2582,6 +2669,12 @@ var WorkerTransport = (function WorkerTransportClosure() {
},
fetchDocument: function WorkerTransport_fetchDocument(loadingTask, source) {
if (this.destroyed) {
loadingTask._capability.reject(new Error('Loading aborted'));
this.destroyCapability.resolve();
return;
}
this.loadingTask = loadingTask;
source.disableAutoFetch = PDFJS.disableAutoFetch;
@ -2620,6 +2713,9 @@ var WorkerTransport = (function WorkerTransportClosure() {
var promise = this.messageHandler.sendWithPromise('GetPage', {
pageIndex: pageIndex
}).then(function (pageInfo) {
if (this.destroyed) {
throw new Error('Transport destroyed');
}
var page = new PDFPageProxy(pageIndex, pageInfo, this);
this.pageCache[pageIndex] = page;
return page;
@ -2677,7 +2773,7 @@ var WorkerTransport = (function WorkerTransportClosure() {
for (var i = 0, ii = this.pageCache.length; i < ii; i++) {
var page = this.pageCache[i];
if (page) {
page.destroy();
page.cleanup();
}
}
this.commonObjs.clear();
@ -5101,6 +5197,11 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
this.ctx.fillRect(0, 0, 1, 1);
},
paintXObject: function CanvasGraphics_paintXObject() {
UnsupportedManager.notify(UNSUPPORTED_FEATURES.unknown);
warn('Unsupported \'paintXObject\' command.');
},
// Marked content
markPoint: function CanvasGraphics_markPoint(tag) {

View File

@ -22,8 +22,8 @@ if (typeof PDFJS === 'undefined') {
(typeof window !== 'undefined' ? window : this).PDFJS = {};
}
PDFJS.version = '1.1.527';
PDFJS.build = '2096a2a';
PDFJS.version = '1.1.551';
PDFJS.build = '2a5616c';
(function pdfjsWrapper() {
// Use strict in our context only - users might not want it
@ -225,6 +225,11 @@ function warn(msg) {
}
}
// Deprecated API function -- treated as warnings.
function deprecated(details) {
warn('Deprecated API usage: ' + details);
}
// Fatal errors that should trigger the fallback UI and halt execution by
// throwing an exception.
function error(msg) {
@ -1603,7 +1608,7 @@ var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
this.chunksNeededByRequest = {};
this.requestsByChunk = {};
this.callbacksByRequest = {};
this.promisesByRequest = {};
this.progressiveDataLength = 0;
this._loadedStreamCapability = createPromiseCapability();
@ -1622,12 +1627,11 @@ var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
// contiguous ranges to load in as few requests as possible
requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
var missingChunks = this.stream.getMissingChunks();
this.requestChunks(missingChunks);
this._requestChunks(missingChunks);
return this._loadedStreamCapability.promise;
},
requestChunks: function ChunkedStreamManager_requestChunks(chunks,
callback) {
_requestChunks: function ChunkedStreamManager_requestChunks(chunks) {
var requestId = this.currRequestId++;
var chunksNeeded;
@ -1640,13 +1644,11 @@ var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
}
if (isEmptyObj(chunksNeeded)) {
if (callback) {
callback();
}
return;
return Promise.resolve();
}
this.callbacksByRequest[requestId] = callback;
var capability = createPromiseCapability();
this.promisesByRequest[requestId] = capability;
var chunksToRequest = [];
for (var chunk in chunksNeeded) {
@ -1659,7 +1661,7 @@ var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
}
if (!chunksToRequest.length) {
return;
return capability.promise;
}
var groupedChunksToRequest = this.groupChunks(chunksToRequest);
@ -1670,6 +1672,8 @@ var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
this.sendRequest(begin, end);
}
return capability.promise;
},
getStream: function ChunkedStreamManager_getStream() {
@ -1677,8 +1681,7 @@ var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
},
// Loads any chunks in the requested range that are not yet loaded
requestRange: function ChunkedStreamManager_requestRange(
begin, end, callback) {
requestRange: function ChunkedStreamManager_requestRange(begin, end) {
end = Math.min(end, this.length);
@ -1690,11 +1693,10 @@ var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
chunks.push(chunk);
}
this.requestChunks(chunks, callback);
return this._requestChunks(chunks);
},
requestRanges: function ChunkedStreamManager_requestRanges(ranges,
callback) {
requestRanges: function ChunkedStreamManager_requestRanges(ranges) {
ranges = ranges || [];
var chunksToRequest = [];
@ -1709,7 +1711,7 @@ var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
}
chunksToRequest.sort(function(a, b) { return a - b; });
this.requestChunks(chunksToRequest, callback);
return this._requestChunks(chunksToRequest);
},
// Groups a sorted array of chunks into as few contiguous larger
@ -1808,17 +1810,15 @@ var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
}
if (isInt(nextEmptyChunk)) {
this.requestChunks([nextEmptyChunk]);
this._requestChunks([nextEmptyChunk]);
}
}
for (i = 0; i < loadedRequests.length; ++i) {
requestId = loadedRequests[i];
var callback = this.callbacksByRequest[requestId];
delete this.callbacksByRequest[requestId];
if (callback) {
callback();
}
var capability = this.promisesByRequest[requestId];
delete this.promisesByRequest[requestId];
capability.resolve();
}
this.msgHandler.send('DocProgress', {
@ -1839,6 +1839,16 @@ var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
return chunk;
},
abort: function ChunkedStreamManager_abort() {
if (this.networkManager) {
this.networkManager.abortAllRequests();
}
for(var requestId in this.promisesByRequest) {
var capability = this.promisesByRequest[requestId];
capability.reject(new Error('Request was aborted'));
}
}
};
@ -2010,7 +2020,8 @@ var NetworkPdfManager = (function NetworkPdfManagerClosure() {
reject(e);
return;
}
pdfManager.streamManager.requestRange(e.begin, e.end, ensureHelper);
pdfManager.streamManager.requestRange(e.begin, e.end).
then(ensureHelper, reject);
}
}
@ -2020,11 +2031,7 @@ var NetworkPdfManager = (function NetworkPdfManagerClosure() {
NetworkPdfManager.prototype.requestRange =
function NetworkPdfManager_requestRange(begin, end) {
return new Promise(function (resolve) {
this.streamManager.requestRange(begin, end, function() {
resolve();
});
}.bind(this));
return this.streamManager.requestRange(begin, end);
};
NetworkPdfManager.prototype.requestLoadedStream =
@ -2044,7 +2051,7 @@ var NetworkPdfManager = (function NetworkPdfManagerClosure() {
NetworkPdfManager.prototype.terminate =
function NetworkPdfManager_terminate() {
this.streamManager.networkManager.abortAllRequests();
this.streamManager.abort();
};
return NetworkPdfManager;
@ -2189,7 +2196,7 @@ var Page = (function PageClosure() {
}.bind(this));
},
getOperatorList: function Page_getOperatorList(handler, intent) {
getOperatorList: function Page_getOperatorList(handler, task, intent) {
var self = this;
var pdfManager = this.pdfManager;
@ -2222,8 +2229,8 @@ var Page = (function PageClosure() {
pageIndex: self.pageIndex,
intent: intent
});
return partialEvaluator.getOperatorList(contentStream, self.resources,
opList).then(function () {
return partialEvaluator.getOperatorList(contentStream, task,
self.resources, opList).then(function () {
return opList;
});
});
@ -2240,7 +2247,7 @@ var Page = (function PageClosure() {
}
var annotationsReadyPromise = Annotation.appendToOperatorList(
annotations, pageOpList, pdfManager, partialEvaluator, intent);
annotations, pageOpList, pdfManager, partialEvaluator, task, intent);
return annotationsReadyPromise.then(function () {
pageOpList.flush(true);
return pageOpList;
@ -2248,7 +2255,7 @@ var Page = (function PageClosure() {
});
},
extractTextContent: function Page_extractTextContent() {
extractTextContent: function Page_extractTextContent(task) {
var handler = {
on: function nullHandlerOn() {},
send: function nullHandlerSend() {}
@ -2277,6 +2284,7 @@ var Page = (function PageClosure() {
self.fontCache);
return partialEvaluator.getTextContent(contentStream,
task,
self.resources);
});
},
@ -2689,7 +2697,8 @@ var Dict = (function DictClosure() {
// Same as get(), but dereferences all elements if the result is an Array.
getArray: function Dict_getArray(key1, key2, key3) {
var value = this.get(key1, key2, key3);
if (!isArray(value)) {
var xref = this.xref;
if (!isArray(value) || !xref) {
return value;
}
value = value.slice(); // Ensure that we don't modify the Dict data.
@ -2697,7 +2706,7 @@ var Dict = (function DictClosure() {
if (!isRef(value[i])) {
continue;
}
value[i] = this.xref.fetch(value[i]);
value[i] = xref.fetch(value[i]);
}
return value;
},
@ -3928,9 +3937,9 @@ var XRef = (function XRefClosure() {
resolve(xref.fetch(ref, suppressEncryption));
} catch (e) {
if (e instanceof MissingDataException) {
streamManager.requestRange(e.begin, e.end, function () {
streamManager.requestRange(e.begin, e.end).then(function () {
tryFetch(resolve, reject);
});
}, reject);
return;
}
reject(e);
@ -4206,6 +4215,7 @@ var ObjectLoader = (function() {
this.keys = keys;
this.xref = xref;
this.refSet = null;
this.capability = null;
}
ObjectLoader.prototype = {
@ -4226,11 +4236,11 @@ var ObjectLoader = (function() {
nodesToVisit.push(this.obj[keys[i]]);
}
this.walk(nodesToVisit);
this._walk(nodesToVisit);
return this.capability.promise;
},
walk: function ObjectLoader_walk(nodesToVisit) {
_walk: function ObjectLoader_walk(nodesToVisit) {
var nodesToRevisit = [];
var pendingRequests = [];
// DFS walk of the object graph.
@ -4277,7 +4287,7 @@ var ObjectLoader = (function() {
}
if (pendingRequests.length) {
this.xref.stream.manager.requestRanges(pendingRequests,
this.xref.stream.manager.requestRanges(pendingRequests).then(
function pendingRequestCallback() {
nodesToVisit = nodesToRevisit;
for (var i = 0; i < nodesToRevisit.length; i++) {
@ -4288,8 +4298,8 @@ var ObjectLoader = (function() {
this.refSet.remove(node);
}
}
this.walk(nodesToVisit);
}.bind(this));
this._walk(nodesToVisit);
}.bind(this), this.capability.reject);
return;
}
// Everything is loaded.
@ -4663,7 +4673,7 @@ var Annotation = (function AnnotationClosure() {
}.bind(this));
},
getOperatorList: function Annotation_getOperatorList(evaluator) {
getOperatorList: function Annotation_getOperatorList(evaluator, task) {
if (!this.appearance) {
return Promise.resolve(new OperatorList());
@ -4690,7 +4700,8 @@ var Annotation = (function AnnotationClosure() {
return resourcesPromise.then(function(resources) {
var opList = new OperatorList();
opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
return evaluator.getOperatorList(self.appearance, resources, opList).
return evaluator.getOperatorList(self.appearance, task,
resources, opList).
then(function () {
opList.addOp(OPS.endAnnotation, []);
self.appearance.reset();
@ -4701,7 +4712,7 @@ var Annotation = (function AnnotationClosure() {
};
Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
annotations, opList, pdfManager, partialEvaluator, intent) {
annotations, opList, pdfManager, partialEvaluator, task, intent) {
function reject(e) {
annotationsReadyCapability.reject(e);
@ -4714,7 +4725,7 @@ var Annotation = (function AnnotationClosure() {
if (intent === 'display' && annotations[i].isViewable() ||
intent === 'print' && annotations[i].isPrintable()) {
annotationPromises.push(
annotations[i].getOperatorList(partialEvaluator));
annotations[i].getOperatorList(partialEvaluator, task));
}
}
Promise.all(annotationPromises).then(function(datas) {
@ -4946,9 +4957,10 @@ var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
}
Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator) {
getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator,
task) {
if (this.appearance) {
return Annotation.prototype.getOperatorList.call(this, evaluator);
return Annotation.prototype.getOperatorList.call(this, evaluator, task);
}
var opList = new OperatorList();
@ -4961,7 +4973,8 @@ var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
}
var stream = new Stream(stringToBytes(data.defaultAppearance));
return evaluator.getOperatorList(stream, this.fieldResources, opList).
return evaluator.getOperatorList(stream, task,
this.fieldResources, opList).
then(function () {
return opList;
});
@ -9176,9 +9189,10 @@ var CipherTransformFactory = (function CipherTransformFactoryClosure() {
if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
userPassword)) {
return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
} else if (pdfAlgorithm.checkOwnerPassword(password, ownerValidationSalt,
uBytes,
ownerPassword)) {
} else if (password.length && pdfAlgorithm.checkOwnerPassword(password,
ownerValidationSalt,
uBytes,
ownerPassword)) {
return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
ownerEncryption);
}
@ -10348,6 +10362,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
xobj, smask,
operatorList,
task,
initialState) {
var matrix = xobj.dict.getArray('Matrix');
var bbox = xobj.dict.getArray('BBox');
@ -10380,7 +10395,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
return this.getOperatorList(xobj,
return this.getOperatorList(xobj, task,
(xobj.dict.get('Resources') || resources), operatorList, initialState).
then(function () {
operatorList.addOp(OPS.paintFormXObjectEnd, []);
@ -10492,7 +10507,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
},
handleSMask: function PartialEvaluator_handleSmask(smask, resources,
operatorList,
operatorList, task,
stateManager) {
var smaskContent = smask.get('G');
var smaskOptions = {
@ -10500,18 +10515,22 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
backdrop: smask.get('BC')
};
return this.buildFormXObject(resources, smaskContent, smaskOptions,
operatorList, stateManager.state.clone());
operatorList, task, stateManager.state.clone());
},
handleTilingType:
function PartialEvaluator_handleTilingType(fn, args, resources,
pattern, patternDict,
operatorList) {
operatorList, task) {
// Create an IR of the pattern code.
var tilingOpList = new OperatorList();
return this.getOperatorList(pattern,
(patternDict.get('Resources') || resources), tilingOpList).
then(function () {
// Merge the available resources, to prevent issues when the patternDict
// is missing some /Resources entries (fixes issue6541.pdf).
var resourcesArray = [patternDict.get('Resources'), resources];
var patternResources = Dict.merge(this.xref, resourcesArray);
return this.getOperatorList(pattern, task, patternResources,
tilingOpList).then(function () {
// Add the dependencies to the parent operator list so they are
// resolved before sub operator list is executed synchronously.
operatorList.addDependencies(tilingOpList.dependencies);
@ -10524,7 +10543,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
handleSetFont:
function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
operatorList, state) {
operatorList, task, state) {
// TODO(mack): Not needed?
var fontName;
if (fontArgs) {
@ -10538,8 +10557,8 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
if (!translated.font.isType3Font) {
return translated;
}
return translated.loadType3Data(self, resources, operatorList).then(
function () {
return translated.loadType3Data(self, resources, operatorList, task).
then(function () {
return translated;
});
}).then(function (translated) {
@ -10586,8 +10605,8 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
},
setGState: function PartialEvaluator_setGState(resources, gState,
operatorList, xref,
stateManager) {
operatorList, task,
xref, stateManager) {
// This array holds the converted/processed state data.
var gStateObj = [];
var gStateMap = gState.map;
@ -10611,8 +10630,8 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
break;
case 'Font':
promise = promise.then(function () {
return self.handleSetFont(resources, null, value[0],
operatorList, stateManager.state).
return self.handleSetFont(resources, null, value[0], operatorList,
task, stateManager.state).
then(function (loadedName) {
operatorList.addDependency(loadedName);
gStateObj.push([key, [loadedName, value[1]]]);
@ -10631,7 +10650,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
if (isDict(dict)) {
promise = promise.then(function () {
return self.handleSMask(dict, resources, operatorList,
stateManager);
task, stateManager);
});
gStateObj.push([key, true]);
} else {
@ -10812,7 +10831,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
},
handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
cs, patterns, resources, xref) {
cs, patterns, resources, task, xref) {
// compile tiling patterns
var patternName = args[args.length - 1];
// SCN/scn applies patterns along with normal colors
@ -10825,7 +10844,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
if (typeNum === TILING_PATTERN) {
var color = cs.base ? cs.base.getRgb(args, 0) : null;
return this.handleTilingType(fn, color, resources, pattern,
dict, operatorList);
dict, operatorList, task);
} else if (typeNum === SHADING_PATTERN) {
var shading = dict.get('Shading');
var matrix = dict.get('Matrix');
@ -10842,6 +10861,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
},
getOperatorList: function PartialEvaluator_getOperatorList(stream,
task,
resources,
operatorList,
initialState) {
@ -10860,6 +10880,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
var timeSlotManager = new TimeSlotManager();
return new Promise(function next(resolve, reject) {
task.ensureNotTerminated();
timeSlotManager.reset();
var stop, operation = {}, i, ii, cs;
while (!(stop = timeSlotManager.check())) {
@ -10902,7 +10923,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
if (type.name === 'Form') {
stateManager.save();
return self.buildFormXObject(resources, xobj, null,
operatorList,
operatorList, task,
stateManager.state.clone()).
then(function () {
stateManager.restore();
@ -10926,8 +10947,8 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
case OPS.setFont:
var fontSize = args[1];
// eagerly collect all fonts
return self.handleSetFont(resources, args, null,
operatorList, stateManager.state).
return self.handleSetFont(resources, args, null, operatorList,
task, stateManager.state).
then(function (loadedName) {
operatorList.addDependency(loadedName);
operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
@ -11033,7 +11054,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
cs = stateManager.state.fillColorSpace;
if (cs.name === 'Pattern') {
return self.handleColorN(operatorList, OPS.setFillColorN,
args, cs, patterns, resources, xref).then(function() {
args, cs, patterns, resources, task, xref).then(function() {
next(resolve, reject);
}, reject);
}
@ -11044,7 +11065,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
cs = stateManager.state.strokeColorSpace;
if (cs.name === 'Pattern') {
return self.handleColorN(operatorList, OPS.setStrokeColorN,
args, cs, patterns, resources, xref).then(function() {
args, cs, patterns, resources, task, xref).then(function() {
next(resolve, reject);
}, reject);
}
@ -11078,8 +11099,8 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
}
var gState = extGState.get(dictName.name);
return self.setGState(resources, gState, operatorList, xref,
stateManager).then(function() {
return self.setGState(resources, gState, operatorList, task,
xref, stateManager).then(function() {
next(resolve, reject);
}, reject);
case OPS.moveTo:
@ -11093,13 +11114,31 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
case OPS.rectangle:
self.buildPath(operatorList, fn, args);
continue;
case OPS.markPoint:
case OPS.markPointProps:
case OPS.beginMarkedContent:
case OPS.beginMarkedContentProps:
case OPS.endMarkedContent:
case OPS.beginCompat:
case OPS.endCompat:
// Ignore operators where the corresponding handlers are known to
// be no-op in CanvasGraphics (display/canvas.js). This prevents
// serialization errors and is also a bit more efficient.
// We could also try to serialize all objects in a general way,
// e.g. as done in https://github.com/mozilla/pdf.js/pull/6266,
// but doing so is meaningless without knowing the semantics.
continue;
default:
// Note: Let's hope that the ignored operator does not have any
// non-serializable arguments, otherwise postMessage will throw
// "An object could not be cloned.".
}
operatorList.addOp(fn, args);
}
if (stop) {
deferred.then(function () {
next(resolve, reject);
});
}, reject);
return;
}
// Some PDFs don't close all restores inside object/form.
@ -11111,7 +11150,8 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
});
},
getTextContent: function PartialEvaluator_getTextContent(stream, resources,
getTextContent: function PartialEvaluator_getTextContent(stream, task,
resources,
stateManager) {
stateManager = (stateManager || new StateManager(new TextState()));
@ -11289,6 +11329,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
var timeSlotManager = new TimeSlotManager();
return new Promise(function next(resolve, reject) {
task.ensureNotTerminated();
timeSlotManager.reset();
var stop, operation = {}, args = [];
while (!(stop = timeSlotManager.check())) {
@ -11444,7 +11485,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
stateManager.transform(matrix);
}
return self.getTextContent(xobj,
return self.getTextContent(xobj, task,
xobj.dict.get('Resources') || resources, stateManager).
then(function (formTextContent) {
Util.appendToArray(bidiTexts, formTextContent.items);
@ -11484,7 +11525,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
if (stop) {
deferred.then(function () {
next(resolve, reject);
});
}, reject);
return;
}
resolve(textContent);
@ -12049,7 +12090,7 @@ var TranslatedFont = (function TranslatedFontClosure() {
]);
this.sent = true;
},
loadType3Data: function (evaluator, resources, parentOperatorList) {
loadType3Data: function (evaluator, resources, parentOperatorList, task) {
assert(this.font.isType3Font);
if (this.type3Loaded) {
@ -12066,7 +12107,7 @@ var TranslatedFont = (function TranslatedFontClosure() {
loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
var glyphStream = charProcs[key];
var operatorList = new OperatorList();
return evaluator.getOperatorList(glyphStream, fontResources,
return evaluator.getOperatorList(glyphStream, task, fontResources,
operatorList).then(function () {
charProcOperatorList[key] = operatorList.getIR();
@ -33629,9 +33670,58 @@ var NullStream = (function NullStreamClosure() {
})();
var WorkerTask = (function WorkerTaskClosure() {
function WorkerTask(name) {
this.name = name;
this.terminated = false;
this._capability = createPromiseCapability();
}
WorkerTask.prototype = {
get finished() {
return this._capability.promise;
},
finish: function () {
this._capability.resolve();
},
terminate: function () {
this.terminated = true;
},
ensureNotTerminated: function () {
if (this.terminated) {
throw new Error('Worker task was terminated');
}
}
};
return WorkerTask;
})();
var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
setup: function wphSetup(handler) {
var pdfManager;
var terminated = false;
var cancelXHRs = null;
var WorkerTasks = [];
function ensureNotTerminated() {
if (terminated) {
throw new Error('Worker was terminated');
}
}
function startWorkerTask(task) {
WorkerTasks.push(task);
}
function finishWorkerTask(task) {
task.finish();
var i = WorkerTasks.indexOf(task);
WorkerTasks.splice(i, 1);
}
function loadDocument(recoveryMode) {
var loadDocumentCapability = createPromiseCapability();
@ -33668,13 +33758,14 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
function getPdfManager(data) {
var pdfManagerCapability = createPromiseCapability();
var pdfManager;
var source = data.source;
var disableRange = data.disableRange;
if (source.data) {
try {
pdfManager = new LocalPdfManager(source.data, source.password);
pdfManagerCapability.resolve();
pdfManagerCapability.resolve(pdfManager);
} catch (ex) {
pdfManagerCapability.reject(ex);
}
@ -33682,7 +33773,7 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
} else if (source.chunkedViewerLoading) {
try {
pdfManager = new NetworkPdfManager(source, handler);
pdfManagerCapability.resolve();
pdfManagerCapability.resolve(pdfManager);
} catch (ex) {
pdfManagerCapability.reject(ex);
}
@ -33743,6 +33834,7 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
} catch (ex) {
pdfManagerCapability.reject(ex);
}
cancelXHRs = null;
},
onProgressiveData: source.disableStream ? null :
@ -33783,10 +33875,11 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
// the data is array, instantiating directly from it
try {
pdfManager = new LocalPdfManager(pdfFile, source.password);
pdfManagerCapability.resolve();
pdfManagerCapability.resolve(pdfManager);
} catch (ex) {
pdfManagerCapability.reject(ex);
}
cancelXHRs = null;
},
onError: function onError(status) {
@ -33801,6 +33894,7 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
') while retrieving PDF "' + source.url + '".', status);
handler.send('UnexpectedResponse', exception);
}
cancelXHRs = null;
},
onProgress: function onProgress(evt) {
@ -33811,6 +33905,10 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
}
});
cancelXHRs = function () {
networkManager.abortRequest(fullRequestXhrId);
};
return pdfManagerCapability.promise;
}
@ -33843,8 +33941,8 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
});
handler.on('GetDocRequest', function wphSetupDoc(data) {
var onSuccess = function(doc) {
ensureNotTerminated();
handler.send('GetDoc', { pdfInfo: doc });
};
@ -33867,6 +33965,8 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
}
};
ensureNotTerminated();
PDFJS.maxImageSize = data.maxImageSize === undefined ?
-1 : data.maxImageSize;
PDFJS.disableFontFace = data.disableFontFace;
@ -33876,13 +33976,26 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
null : data.cMapUrl;
PDFJS.cMapPacked = data.cMapPacked === true;
getPdfManager(data).then(function () {
getPdfManager(data).then(function (newPdfManager) {
if (terminated) {
// We were in a process of setting up the manager, but it got
// terminated in the middle.
newPdfManager.terminate();
throw new Error('Worker was terminated');
}
pdfManager = newPdfManager;
handler.send('PDFManagerReady', null);
pdfManager.onLoadedStream().then(function(stream) {
handler.send('DataLoaded', { length: stream.bytes.byteLength });
});
}).then(function pdfManagerReady() {
ensureNotTerminated();
loadDocument(false).then(onSuccess, function loadFailure(ex) {
ensureNotTerminated();
// Try again with recoveryMode == true
if (!(ex instanceof XRefParseException)) {
if (ex instanceof PasswordException) {
@ -33897,6 +34010,8 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
pdfManager.requestLoadedStream();
pdfManager.onLoadedStream().then(function() {
ensureNotTerminated();
loadDocument(true).then(onSuccess, onFailure);
});
}, onFailure);
@ -33987,17 +34102,25 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
});
handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
pdfManager.getPage(data.pageIndex).then(function(page) {
var pageIndex = data.pageIndex;
pdfManager.getPage(pageIndex).then(function(page) {
var task = new WorkerTask('RenderPageRequest: page ' + pageIndex);
startWorkerTask(task);
var pageNum = data.pageIndex + 1;
var pageNum = pageIndex + 1;
var start = Date.now();
// Pre compile the pdf page and fetch the fonts/images.
page.getOperatorList(handler, data.intent).then(function(operatorList) {
page.getOperatorList(handler, task, data.intent).then(
function(operatorList) {
finishWorkerTask(task);
info('page=' + pageNum + ' - getOperatorList: time=' +
(Date.now() - start) + 'ms, len=' + operatorList.fnArray.length);
}, function(e) {
finishWorkerTask(task);
if (task.terminated) {
return; // ignoring errors from the terminated thread
}
var minimumStackMessage =
'worker.js: while trying to getPage() and getOperatorList()';
@ -34032,13 +34155,23 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
}, this);
handler.on('GetTextContent', function wphExtractText(data) {
return pdfManager.getPage(data.pageIndex).then(function(page) {
var pageNum = data.pageIndex + 1;
var pageIndex = data.pageIndex;
return pdfManager.getPage(pageIndex).then(function(page) {
var task = new WorkerTask('GetTextContent: page ' + pageIndex);
startWorkerTask(task);
var pageNum = pageIndex + 1;
var start = Date.now();
return page.extractTextContent().then(function(textContent) {
return page.extractTextContent(task).then(function(textContent) {
finishWorkerTask(task);
info('text indexing: page=' + pageNum + ' - time=' +
(Date.now() - start) + 'ms');
return textContent;
}, function (reason) {
finishWorkerTask(task);
if (task.terminated) {
return; // ignoring errors from the terminated thread
}
throw reason;
});
});
});
@ -34048,7 +34181,22 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
});
handler.on('Terminate', function wphTerminate(data) {
pdfManager.terminate();
terminated = true;
if (pdfManager) {
pdfManager.terminate();
pdfManager = null;
}
if (cancelXHRs) {
cancelXHRs();
}
var waitOn = [];
WorkerTasks.forEach(function (task) {
waitOn.push(task.finished);
task.terminate();
});
return Promise.all(waitOn).then(function () {});
});
}
};

View File

@ -3491,7 +3491,7 @@ var PDFPageView = (function PDFPageViewClosure() {
this.zoomLayer = null;
this.reset();
if (this.pdfPage) {
this.pdfPage.destroy();
this.pdfPage.cleanup();
}
},
@ -3834,9 +3834,9 @@ var PDFPageView = (function PDFPageViewClosure() {
canvasContext: ctx,
viewport: this.viewport,
// intent: 'default', // === 'display'
continueCallback: renderContinueCallback
};
var renderTask = this.renderTask = this.pdfPage.render(renderContext);
renderTask.onContinue = renderContinueCallback;
this.renderTask.promise.then(
function pdfPageRenderCallback() {
@ -5541,10 +5541,10 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
var renderContext = {
canvasContext: ctx,
viewport: drawViewport,
continueCallback: renderContinueCallback
viewport: drawViewport
};
var renderTask = this.renderTask = this.pdfPage.render(renderContext);
renderTask.onContinue = renderContinueCallback;
renderTask.promise.then(
function pdfPageRenderCallback() {
@ -6036,6 +6036,7 @@ var PDFViewerApplication = {
initialized: false,
fellback: false,
pdfDocument: null,
pdfLoadingTask: null,
sidebarOpen: false,
printing: false,
/** @type {PDFViewer} */
@ -6347,6 +6348,11 @@ var PDFViewerApplication = {
function FirefoxComDataRangeTransport_requestDataRange(begin, end) {
FirefoxCom.request('requestDataRange', { begin: begin, end: end });
};
FirefoxComDataRangeTransport.prototype.abort =
function FirefoxComDataRangeTransport_abort() {
// Sync call to ensure abort is really started.
FirefoxCom.requestSync('abortLoading', null);
};
var pdfDataRangeTransport;
@ -6366,8 +6372,8 @@ var PDFViewerApplication = {
pdfDataRangeTransport =
new FirefoxComDataRangeTransport(args.length, args.data);
PDFViewerApplication.open(args.pdfUrl, 0, undefined,
pdfDataRangeTransport);
PDFViewerApplication.open(args.pdfUrl,
{range: pdfDataRangeTransport});
if (args.length) {
PDFViewerApplication.pdfDocumentProperties
@ -6392,7 +6398,7 @@ var PDFViewerApplication = {
'An error occurred while loading the PDF.'), e);
break;
}
PDFViewerApplication.open(args.data, 0);
PDFViewerApplication.open(args.data);
break;
}
});
@ -6418,36 +6424,76 @@ var PDFViewerApplication = {
document.title = title;
},
/**
* Closes opened PDF document.
* @returns {Promise} - Returns the promise, which is resolved when all
* destruction is completed.
*/
close: function pdfViewClose() {
var errorWrapper = document.getElementById('errorWrapper');
errorWrapper.setAttribute('hidden', 'true');
if (!this.pdfDocument) {
return;
if (!this.pdfLoadingTask) {
return Promise.resolve();
}
this.pdfDocument.destroy();
this.pdfDocument = null;
var promise = this.pdfLoadingTask.destroy();
this.pdfLoadingTask = null;
this.pdfThumbnailViewer.setDocument(null);
this.pdfViewer.setDocument(null);
this.pdfLinkService.setDocument(null, null);
if (this.pdfDocument) {
this.pdfDocument = null;
this.pdfThumbnailViewer.setDocument(null);
this.pdfViewer.setDocument(null);
this.pdfLinkService.setDocument(null, null);
}
if (typeof PDFBug !== 'undefined') {
PDFBug.cleanup();
}
return promise;
},
// TODO(mack): This function signature should really be pdfViewOpen(url, args)
open: function pdfViewOpen(file, scale, password,
pdfDataRangeTransport, args) {
if (this.pdfDocument) {
// Reload the preferences if a document was previously opened.
Preferences.reload();
/**
* Opens PDF document specified by URL or array with additional arguments.
* @param {string|TypedArray|ArrayBuffer} file - PDF location or binary data.
* @param {Object} args - (optional) Additional arguments for the getDocument
* call, e.g. HTTP headers ('httpHeaders') or
* alternative data transport ('range').
* @returns {Promise} - Returns the promise, which is resolved when document
* is opened.
*/
open: function pdfViewOpen(file, args) {
var scale = 0;
if (arguments.length > 2 || typeof args === 'number') {
console.warn('Call of open() with obsolete signature.');
if (typeof args === 'number') {
scale = args; // scale argument was found
}
args = arguments[4] || null;
if (arguments[3] && typeof arguments[3] === 'object') {
// The pdfDataRangeTransport argument is present.
args = Object.create(args);
args.range = arguments[3];
}
if (typeof arguments[2] === 'string') {
// The password argument is present.
args = Object.create(args);
args.password = arguments[2];
}
}
this.close();
var parameters = {password: password};
if (this.pdfLoadingTask) {
// We need to destroy already opened document.
return this.close().then(function () {
// Reload the preferences if a document was previously opened.
Preferences.reload();
// ... and repeat the open() call.
return this.open(file, args);
}.bind(this));
}
var parameters = Object.create(null);
if (typeof file === 'string') { // URL
this.setTitleUsingUrl(file);
parameters.url = file;
@ -6466,18 +6512,20 @@ var PDFViewerApplication = {
var self = this;
self.downloadComplete = false;
var passwordNeeded = function passwordNeeded(updatePassword, reason) {
var loadingTask = PDFJS.getDocument(parameters);
this.pdfLoadingTask = loadingTask;
loadingTask.onPassword = function passwordNeeded(updatePassword, reason) {
PasswordPrompt.updatePassword = updatePassword;
PasswordPrompt.reason = reason;
PasswordPrompt.open();
};
function getDocumentProgress(progressData) {
loadingTask.onProgress = function getDocumentProgress(progressData) {
self.progress(progressData.loaded / progressData.total);
}
};
PDFJS.getDocument(parameters, pdfDataRangeTransport, passwordNeeded,
getDocumentProgress).then(
var result = loadingTask.promise.then(
function getDocumentCallback(pdfDocument) {
self.load(pdfDocument, scale);
},
@ -6503,12 +6551,15 @@ var PDFViewerApplication = {
message: message
};
self.error(loadingErrorMessage, moreInfo);
throw new Error(loadingErrorMessage);
}
);
if (args && args.length) {
PDFViewerApplication.pdfDocumentProperties.setFileSize(args.length);
}
return result;
},
download: function pdfViewDownload() {
@ -6879,6 +6930,9 @@ var PDFViewerApplication = {
},
cleanup: function pdfViewCleanup() {
if (!this.pdfDocument) {
return; // run cleanup when document is loaded
}
this.pdfViewer.cleanup();
this.pdfThumbnailViewer.cleanup();
this.pdfDocument.cleanup();