Merge pull request #6546 from yurydelendik/destroy
[api-minor] Adds controlled destruction of the worker.
This commit is contained in:
commit
2a5616c2aa
@ -662,8 +662,8 @@ var RangedChromeActions = (function RangedChromeActionsClosure() {
|
|||||||
// If we are in range request mode, this means we manually issued xhr
|
// If we are in range request mode, this means we manually issued xhr
|
||||||
// requests, which we need to abort when we leave the page
|
// requests, which we need to abort when we leave the page
|
||||||
domWindow.addEventListener('unload', function unload(e) {
|
domWindow.addEventListener('unload', function unload(e) {
|
||||||
self.networkManager.abortAllRequests();
|
|
||||||
domWindow.removeEventListener(e.type, unload);
|
domWindow.removeEventListener(e.type, unload);
|
||||||
|
self.abortLoading();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -691,7 +691,7 @@ var RangedChromeActions = (function RangedChromeActionsClosure() {
|
|||||||
}, '*');
|
}, '*');
|
||||||
};
|
};
|
||||||
this.dataListener.oncomplete = function () {
|
this.dataListener.oncomplete = function () {
|
||||||
delete self.dataListener;
|
self.dataListener = null;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -735,6 +735,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;
|
return RangedChromeActions;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
@ -744,9 +753,10 @@ var StandardChromeActions = (function StandardChromeActionsClosure() {
|
|||||||
* This is for a single network stream
|
* This is for a single network stream
|
||||||
*/
|
*/
|
||||||
function StandardChromeActions(domWindow, contentDispositionFilename,
|
function StandardChromeActions(domWindow, contentDispositionFilename,
|
||||||
dataListener) {
|
originalRequest, dataListener) {
|
||||||
|
|
||||||
ChromeActions.call(this, domWindow, contentDispositionFilename);
|
ChromeActions.call(this, domWindow, contentDispositionFilename);
|
||||||
|
this.originalRequest = originalRequest;
|
||||||
this.dataListener = dataListener;
|
this.dataListener = dataListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -772,20 +782,29 @@ var StandardChromeActions = (function StandardChromeActionsClosure() {
|
|||||||
}, '*');
|
}, '*');
|
||||||
};
|
};
|
||||||
|
|
||||||
this.dataListener.oncomplete = function ChromeActions_dataListenerComplete(
|
this.dataListener.oncomplete =
|
||||||
data, errorCode) {
|
function StandardChromeActions_dataListenerComplete(data, errorCode) {
|
||||||
self.domWindow.postMessage({
|
self.domWindow.postMessage({
|
||||||
pdfjsLoadAction: 'complete',
|
pdfjsLoadAction: 'complete',
|
||||||
data: data,
|
data: data,
|
||||||
errorCode: errorCode
|
errorCode: errorCode
|
||||||
}, '*');
|
}, '*');
|
||||||
|
|
||||||
delete self.dataListener;
|
self.dataListener = null;
|
||||||
|
self.originalRequest = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
return true;
|
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;
|
return StandardChromeActions;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
@ -1029,7 +1048,7 @@ PdfStreamConverter.prototype = {
|
|||||||
rangeRequest, streamRequest, dataListener);
|
rangeRequest, streamRequest, dataListener);
|
||||||
} else {
|
} else {
|
||||||
actions = new StandardChromeActions(
|
actions = new StandardChromeActions(
|
||||||
domWindow, contentDispositionFilename, dataListener);
|
domWindow, contentDispositionFilename, aRequest, dataListener);
|
||||||
}
|
}
|
||||||
var requestListener = new RequestListener(actions);
|
var requestListener = new RequestListener(actions);
|
||||||
domWindow.addEventListener(PDFJS_EVENT_ID, function(event) {
|
domWindow.addEventListener(PDFJS_EVENT_ID, function(event) {
|
||||||
|
@ -281,7 +281,7 @@ var Annotation = (function AnnotationClosure() {
|
|||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
|
|
||||||
getOperatorList: function Annotation_getOperatorList(evaluator) {
|
getOperatorList: function Annotation_getOperatorList(evaluator, task) {
|
||||||
|
|
||||||
if (!this.appearance) {
|
if (!this.appearance) {
|
||||||
return Promise.resolve(new OperatorList());
|
return Promise.resolve(new OperatorList());
|
||||||
@ -308,7 +308,8 @@ var Annotation = (function AnnotationClosure() {
|
|||||||
return resourcesPromise.then(function(resources) {
|
return resourcesPromise.then(function(resources) {
|
||||||
var opList = new OperatorList();
|
var opList = new OperatorList();
|
||||||
opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
|
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 () {
|
then(function () {
|
||||||
opList.addOp(OPS.endAnnotation, []);
|
opList.addOp(OPS.endAnnotation, []);
|
||||||
self.appearance.reset();
|
self.appearance.reset();
|
||||||
@ -319,7 +320,7 @@ var Annotation = (function AnnotationClosure() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
|
Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
|
||||||
annotations, opList, pdfManager, partialEvaluator, intent) {
|
annotations, opList, pdfManager, partialEvaluator, task, intent) {
|
||||||
|
|
||||||
function reject(e) {
|
function reject(e) {
|
||||||
annotationsReadyCapability.reject(e);
|
annotationsReadyCapability.reject(e);
|
||||||
@ -332,7 +333,7 @@ var Annotation = (function AnnotationClosure() {
|
|||||||
if (intent === 'display' && annotations[i].isViewable() ||
|
if (intent === 'display' && annotations[i].isViewable() ||
|
||||||
intent === 'print' && annotations[i].isPrintable()) {
|
intent === 'print' && annotations[i].isPrintable()) {
|
||||||
annotationPromises.push(
|
annotationPromises.push(
|
||||||
annotations[i].getOperatorList(partialEvaluator));
|
annotations[i].getOperatorList(partialEvaluator, task));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Promise.all(annotationPromises).then(function(datas) {
|
Promise.all(annotationPromises).then(function(datas) {
|
||||||
@ -564,9 +565,10 @@ var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
|
Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
|
||||||
getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator) {
|
getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator,
|
||||||
|
task) {
|
||||||
if (this.appearance) {
|
if (this.appearance) {
|
||||||
return Annotation.prototype.getOperatorList.call(this, evaluator);
|
return Annotation.prototype.getOperatorList.call(this, evaluator, task);
|
||||||
}
|
}
|
||||||
|
|
||||||
var opList = new OperatorList();
|
var opList = new OperatorList();
|
||||||
@ -579,7 +581,8 @@ var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var stream = new Stream(stringToBytes(data.defaultAppearance));
|
var stream = new Stream(stringToBytes(data.defaultAppearance));
|
||||||
return evaluator.getOperatorList(stream, this.fieldResources, opList).
|
return evaluator.getOperatorList(stream, task,
|
||||||
|
this.fieldResources, opList).
|
||||||
then(function () {
|
then(function () {
|
||||||
return opList;
|
return opList;
|
||||||
});
|
});
|
||||||
|
@ -301,7 +301,7 @@ var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
|
|||||||
|
|
||||||
this.chunksNeededByRequest = {};
|
this.chunksNeededByRequest = {};
|
||||||
this.requestsByChunk = {};
|
this.requestsByChunk = {};
|
||||||
this.callbacksByRequest = {};
|
this.promisesByRequest = {};
|
||||||
this.progressiveDataLength = 0;
|
this.progressiveDataLength = 0;
|
||||||
|
|
||||||
this._loadedStreamCapability = createPromiseCapability();
|
this._loadedStreamCapability = createPromiseCapability();
|
||||||
@ -320,12 +320,11 @@ var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
|
|||||||
// contiguous ranges to load in as few requests as possible
|
// contiguous ranges to load in as few requests as possible
|
||||||
requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
|
requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
|
||||||
var missingChunks = this.stream.getMissingChunks();
|
var missingChunks = this.stream.getMissingChunks();
|
||||||
this.requestChunks(missingChunks);
|
this._requestChunks(missingChunks);
|
||||||
return this._loadedStreamCapability.promise;
|
return this._loadedStreamCapability.promise;
|
||||||
},
|
},
|
||||||
|
|
||||||
requestChunks: function ChunkedStreamManager_requestChunks(chunks,
|
_requestChunks: function ChunkedStreamManager_requestChunks(chunks) {
|
||||||
callback) {
|
|
||||||
var requestId = this.currRequestId++;
|
var requestId = this.currRequestId++;
|
||||||
|
|
||||||
var chunksNeeded;
|
var chunksNeeded;
|
||||||
@ -338,13 +337,11 @@ var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isEmptyObj(chunksNeeded)) {
|
if (isEmptyObj(chunksNeeded)) {
|
||||||
if (callback) {
|
return Promise.resolve();
|
||||||
callback();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.callbacksByRequest[requestId] = callback;
|
var capability = createPromiseCapability();
|
||||||
|
this.promisesByRequest[requestId] = capability;
|
||||||
|
|
||||||
var chunksToRequest = [];
|
var chunksToRequest = [];
|
||||||
for (var chunk in chunksNeeded) {
|
for (var chunk in chunksNeeded) {
|
||||||
@ -357,7 +354,7 @@ var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!chunksToRequest.length) {
|
if (!chunksToRequest.length) {
|
||||||
return;
|
return capability.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
var groupedChunksToRequest = this.groupChunks(chunksToRequest);
|
var groupedChunksToRequest = this.groupChunks(chunksToRequest);
|
||||||
@ -368,6 +365,8 @@ var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
|
|||||||
var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
|
var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
|
||||||
this.sendRequest(begin, end);
|
this.sendRequest(begin, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return capability.promise;
|
||||||
},
|
},
|
||||||
|
|
||||||
getStream: function ChunkedStreamManager_getStream() {
|
getStream: function ChunkedStreamManager_getStream() {
|
||||||
@ -375,8 +374,7 @@ var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Loads any chunks in the requested range that are not yet loaded
|
// Loads any chunks in the requested range that are not yet loaded
|
||||||
requestRange: function ChunkedStreamManager_requestRange(
|
requestRange: function ChunkedStreamManager_requestRange(begin, end) {
|
||||||
begin, end, callback) {
|
|
||||||
|
|
||||||
end = Math.min(end, this.length);
|
end = Math.min(end, this.length);
|
||||||
|
|
||||||
@ -388,11 +386,10 @@ var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
|
|||||||
chunks.push(chunk);
|
chunks.push(chunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.requestChunks(chunks, callback);
|
return this._requestChunks(chunks);
|
||||||
},
|
},
|
||||||
|
|
||||||
requestRanges: function ChunkedStreamManager_requestRanges(ranges,
|
requestRanges: function ChunkedStreamManager_requestRanges(ranges) {
|
||||||
callback) {
|
|
||||||
ranges = ranges || [];
|
ranges = ranges || [];
|
||||||
var chunksToRequest = [];
|
var chunksToRequest = [];
|
||||||
|
|
||||||
@ -407,7 +404,7 @@ var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
chunksToRequest.sort(function(a, b) { return a - b; });
|
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
|
// Groups a sorted array of chunks into as few contiguous larger
|
||||||
@ -506,17 +503,15 @@ var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
|
|||||||
nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
|
nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
|
||||||
}
|
}
|
||||||
if (isInt(nextEmptyChunk)) {
|
if (isInt(nextEmptyChunk)) {
|
||||||
this.requestChunks([nextEmptyChunk]);
|
this._requestChunks([nextEmptyChunk]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < loadedRequests.length; ++i) {
|
for (i = 0; i < loadedRequests.length; ++i) {
|
||||||
requestId = loadedRequests[i];
|
requestId = loadedRequests[i];
|
||||||
var callback = this.callbacksByRequest[requestId];
|
var capability = this.promisesByRequest[requestId];
|
||||||
delete this.callbacksByRequest[requestId];
|
delete this.promisesByRequest[requestId];
|
||||||
if (callback) {
|
capability.resolve();
|
||||||
callback();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.msgHandler.send('DocProgress', {
|
this.msgHandler.send('DocProgress', {
|
||||||
@ -537,6 +532,16 @@ var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
|
|||||||
getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
|
getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
|
||||||
var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
|
var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
|
||||||
return chunk;
|
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'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -161,7 +161,7 @@ var Page = (function PageClosure() {
|
|||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
|
|
||||||
getOperatorList: function Page_getOperatorList(handler, intent) {
|
getOperatorList: function Page_getOperatorList(handler, task, intent) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
var pdfManager = this.pdfManager;
|
var pdfManager = this.pdfManager;
|
||||||
@ -194,8 +194,8 @@ var Page = (function PageClosure() {
|
|||||||
pageIndex: self.pageIndex,
|
pageIndex: self.pageIndex,
|
||||||
intent: intent
|
intent: intent
|
||||||
});
|
});
|
||||||
return partialEvaluator.getOperatorList(contentStream, self.resources,
|
return partialEvaluator.getOperatorList(contentStream, task,
|
||||||
opList).then(function () {
|
self.resources, opList).then(function () {
|
||||||
return opList;
|
return opList;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -212,7 +212,7 @@ var Page = (function PageClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var annotationsReadyPromise = Annotation.appendToOperatorList(
|
var annotationsReadyPromise = Annotation.appendToOperatorList(
|
||||||
annotations, pageOpList, pdfManager, partialEvaluator, intent);
|
annotations, pageOpList, pdfManager, partialEvaluator, task, intent);
|
||||||
return annotationsReadyPromise.then(function () {
|
return annotationsReadyPromise.then(function () {
|
||||||
pageOpList.flush(true);
|
pageOpList.flush(true);
|
||||||
return pageOpList;
|
return pageOpList;
|
||||||
@ -220,7 +220,7 @@ var Page = (function PageClosure() {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
extractTextContent: function Page_extractTextContent() {
|
extractTextContent: function Page_extractTextContent(task) {
|
||||||
var handler = {
|
var handler = {
|
||||||
on: function nullHandlerOn() {},
|
on: function nullHandlerOn() {},
|
||||||
send: function nullHandlerSend() {}
|
send: function nullHandlerSend() {}
|
||||||
@ -249,6 +249,7 @@ var Page = (function PageClosure() {
|
|||||||
self.fontCache);
|
self.fontCache);
|
||||||
|
|
||||||
return partialEvaluator.getTextContent(contentStream,
|
return partialEvaluator.getTextContent(contentStream,
|
||||||
|
task,
|
||||||
self.resources);
|
self.resources);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -125,6 +125,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
|
buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
|
||||||
xobj, smask,
|
xobj, smask,
|
||||||
operatorList,
|
operatorList,
|
||||||
|
task,
|
||||||
initialState) {
|
initialState) {
|
||||||
var matrix = xobj.dict.getArray('Matrix');
|
var matrix = xobj.dict.getArray('Matrix');
|
||||||
var bbox = xobj.dict.getArray('BBox');
|
var bbox = xobj.dict.getArray('BBox');
|
||||||
@ -157,7 +158,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
|
|
||||||
operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
|
operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
|
||||||
|
|
||||||
return this.getOperatorList(xobj,
|
return this.getOperatorList(xobj, task,
|
||||||
(xobj.dict.get('Resources') || resources), operatorList, initialState).
|
(xobj.dict.get('Resources') || resources), operatorList, initialState).
|
||||||
then(function () {
|
then(function () {
|
||||||
operatorList.addOp(OPS.paintFormXObjectEnd, []);
|
operatorList.addOp(OPS.paintFormXObjectEnd, []);
|
||||||
@ -269,7 +270,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
},
|
},
|
||||||
|
|
||||||
handleSMask: function PartialEvaluator_handleSmask(smask, resources,
|
handleSMask: function PartialEvaluator_handleSmask(smask, resources,
|
||||||
operatorList,
|
operatorList, task,
|
||||||
stateManager) {
|
stateManager) {
|
||||||
var smaskContent = smask.get('G');
|
var smaskContent = smask.get('G');
|
||||||
var smaskOptions = {
|
var smaskOptions = {
|
||||||
@ -277,13 +278,13 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
backdrop: smask.get('BC')
|
backdrop: smask.get('BC')
|
||||||
};
|
};
|
||||||
return this.buildFormXObject(resources, smaskContent, smaskOptions,
|
return this.buildFormXObject(resources, smaskContent, smaskOptions,
|
||||||
operatorList, stateManager.state.clone());
|
operatorList, task, stateManager.state.clone());
|
||||||
},
|
},
|
||||||
|
|
||||||
handleTilingType:
|
handleTilingType:
|
||||||
function PartialEvaluator_handleTilingType(fn, args, resources,
|
function PartialEvaluator_handleTilingType(fn, args, resources,
|
||||||
pattern, patternDict,
|
pattern, patternDict,
|
||||||
operatorList) {
|
operatorList, task) {
|
||||||
// Create an IR of the pattern code.
|
// Create an IR of the pattern code.
|
||||||
var tilingOpList = new OperatorList();
|
var tilingOpList = new OperatorList();
|
||||||
// Merge the available resources, to prevent issues when the patternDict
|
// Merge the available resources, to prevent issues when the patternDict
|
||||||
@ -291,8 +292,8 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
var resourcesArray = [patternDict.get('Resources'), resources];
|
var resourcesArray = [patternDict.get('Resources'), resources];
|
||||||
var patternResources = Dict.merge(this.xref, resourcesArray);
|
var patternResources = Dict.merge(this.xref, resourcesArray);
|
||||||
|
|
||||||
return this.getOperatorList(pattern, patternResources, tilingOpList).then(
|
return this.getOperatorList(pattern, task, patternResources,
|
||||||
function () {
|
tilingOpList).then(function () {
|
||||||
// Add the dependencies to the parent operator list so they are
|
// Add the dependencies to the parent operator list so they are
|
||||||
// resolved before sub operator list is executed synchronously.
|
// resolved before sub operator list is executed synchronously.
|
||||||
operatorList.addDependencies(tilingOpList.dependencies);
|
operatorList.addDependencies(tilingOpList.dependencies);
|
||||||
@ -305,7 +306,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
|
|
||||||
handleSetFont:
|
handleSetFont:
|
||||||
function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
|
function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
|
||||||
operatorList, state) {
|
operatorList, task, state) {
|
||||||
// TODO(mack): Not needed?
|
// TODO(mack): Not needed?
|
||||||
var fontName;
|
var fontName;
|
||||||
if (fontArgs) {
|
if (fontArgs) {
|
||||||
@ -319,8 +320,8 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
if (!translated.font.isType3Font) {
|
if (!translated.font.isType3Font) {
|
||||||
return translated;
|
return translated;
|
||||||
}
|
}
|
||||||
return translated.loadType3Data(self, resources, operatorList).then(
|
return translated.loadType3Data(self, resources, operatorList, task).
|
||||||
function () {
|
then(function () {
|
||||||
return translated;
|
return translated;
|
||||||
});
|
});
|
||||||
}).then(function (translated) {
|
}).then(function (translated) {
|
||||||
@ -367,8 +368,8 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
},
|
},
|
||||||
|
|
||||||
setGState: function PartialEvaluator_setGState(resources, gState,
|
setGState: function PartialEvaluator_setGState(resources, gState,
|
||||||
operatorList, xref,
|
operatorList, task,
|
||||||
stateManager) {
|
xref, stateManager) {
|
||||||
// This array holds the converted/processed state data.
|
// This array holds the converted/processed state data.
|
||||||
var gStateObj = [];
|
var gStateObj = [];
|
||||||
var gStateMap = gState.map;
|
var gStateMap = gState.map;
|
||||||
@ -392,8 +393,8 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
break;
|
break;
|
||||||
case 'Font':
|
case 'Font':
|
||||||
promise = promise.then(function () {
|
promise = promise.then(function () {
|
||||||
return self.handleSetFont(resources, null, value[0],
|
return self.handleSetFont(resources, null, value[0], operatorList,
|
||||||
operatorList, stateManager.state).
|
task, stateManager.state).
|
||||||
then(function (loadedName) {
|
then(function (loadedName) {
|
||||||
operatorList.addDependency(loadedName);
|
operatorList.addDependency(loadedName);
|
||||||
gStateObj.push([key, [loadedName, value[1]]]);
|
gStateObj.push([key, [loadedName, value[1]]]);
|
||||||
@ -412,7 +413,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
if (isDict(dict)) {
|
if (isDict(dict)) {
|
||||||
promise = promise.then(function () {
|
promise = promise.then(function () {
|
||||||
return self.handleSMask(dict, resources, operatorList,
|
return self.handleSMask(dict, resources, operatorList,
|
||||||
stateManager);
|
task, stateManager);
|
||||||
});
|
});
|
||||||
gStateObj.push([key, true]);
|
gStateObj.push([key, true]);
|
||||||
} else {
|
} else {
|
||||||
@ -593,7 +594,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
},
|
},
|
||||||
|
|
||||||
handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
|
handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
|
||||||
cs, patterns, resources, xref) {
|
cs, patterns, resources, task, xref) {
|
||||||
// compile tiling patterns
|
// compile tiling patterns
|
||||||
var patternName = args[args.length - 1];
|
var patternName = args[args.length - 1];
|
||||||
// SCN/scn applies patterns along with normal colors
|
// SCN/scn applies patterns along with normal colors
|
||||||
@ -606,7 +607,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
if (typeNum === TILING_PATTERN) {
|
if (typeNum === TILING_PATTERN) {
|
||||||
var color = cs.base ? cs.base.getRgb(args, 0) : null;
|
var color = cs.base ? cs.base.getRgb(args, 0) : null;
|
||||||
return this.handleTilingType(fn, color, resources, pattern,
|
return this.handleTilingType(fn, color, resources, pattern,
|
||||||
dict, operatorList);
|
dict, operatorList, task);
|
||||||
} else if (typeNum === SHADING_PATTERN) {
|
} else if (typeNum === SHADING_PATTERN) {
|
||||||
var shading = dict.get('Shading');
|
var shading = dict.get('Shading');
|
||||||
var matrix = dict.get('Matrix');
|
var matrix = dict.get('Matrix');
|
||||||
@ -623,6 +624,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
},
|
},
|
||||||
|
|
||||||
getOperatorList: function PartialEvaluator_getOperatorList(stream,
|
getOperatorList: function PartialEvaluator_getOperatorList(stream,
|
||||||
|
task,
|
||||||
resources,
|
resources,
|
||||||
operatorList,
|
operatorList,
|
||||||
initialState) {
|
initialState) {
|
||||||
@ -641,6 +643,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
var timeSlotManager = new TimeSlotManager();
|
var timeSlotManager = new TimeSlotManager();
|
||||||
|
|
||||||
return new Promise(function next(resolve, reject) {
|
return new Promise(function next(resolve, reject) {
|
||||||
|
task.ensureNotTerminated();
|
||||||
timeSlotManager.reset();
|
timeSlotManager.reset();
|
||||||
var stop, operation = {}, i, ii, cs;
|
var stop, operation = {}, i, ii, cs;
|
||||||
while (!(stop = timeSlotManager.check())) {
|
while (!(stop = timeSlotManager.check())) {
|
||||||
@ -683,7 +686,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
if (type.name === 'Form') {
|
if (type.name === 'Form') {
|
||||||
stateManager.save();
|
stateManager.save();
|
||||||
return self.buildFormXObject(resources, xobj, null,
|
return self.buildFormXObject(resources, xobj, null,
|
||||||
operatorList,
|
operatorList, task,
|
||||||
stateManager.state.clone()).
|
stateManager.state.clone()).
|
||||||
then(function () {
|
then(function () {
|
||||||
stateManager.restore();
|
stateManager.restore();
|
||||||
@ -707,8 +710,8 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
case OPS.setFont:
|
case OPS.setFont:
|
||||||
var fontSize = args[1];
|
var fontSize = args[1];
|
||||||
// eagerly collect all fonts
|
// eagerly collect all fonts
|
||||||
return self.handleSetFont(resources, args, null,
|
return self.handleSetFont(resources, args, null, operatorList,
|
||||||
operatorList, stateManager.state).
|
task, stateManager.state).
|
||||||
then(function (loadedName) {
|
then(function (loadedName) {
|
||||||
operatorList.addDependency(loadedName);
|
operatorList.addDependency(loadedName);
|
||||||
operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
|
operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
|
||||||
@ -814,7 +817,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
cs = stateManager.state.fillColorSpace;
|
cs = stateManager.state.fillColorSpace;
|
||||||
if (cs.name === 'Pattern') {
|
if (cs.name === 'Pattern') {
|
||||||
return self.handleColorN(operatorList, OPS.setFillColorN,
|
return self.handleColorN(operatorList, OPS.setFillColorN,
|
||||||
args, cs, patterns, resources, xref).then(function() {
|
args, cs, patterns, resources, task, xref).then(function() {
|
||||||
next(resolve, reject);
|
next(resolve, reject);
|
||||||
}, reject);
|
}, reject);
|
||||||
}
|
}
|
||||||
@ -825,7 +828,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
cs = stateManager.state.strokeColorSpace;
|
cs = stateManager.state.strokeColorSpace;
|
||||||
if (cs.name === 'Pattern') {
|
if (cs.name === 'Pattern') {
|
||||||
return self.handleColorN(operatorList, OPS.setStrokeColorN,
|
return self.handleColorN(operatorList, OPS.setStrokeColorN,
|
||||||
args, cs, patterns, resources, xref).then(function() {
|
args, cs, patterns, resources, task, xref).then(function() {
|
||||||
next(resolve, reject);
|
next(resolve, reject);
|
||||||
}, reject);
|
}, reject);
|
||||||
}
|
}
|
||||||
@ -859,8 +862,8 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var gState = extGState.get(dictName.name);
|
var gState = extGState.get(dictName.name);
|
||||||
return self.setGState(resources, gState, operatorList, xref,
|
return self.setGState(resources, gState, operatorList, task,
|
||||||
stateManager).then(function() {
|
xref, stateManager).then(function() {
|
||||||
next(resolve, reject);
|
next(resolve, reject);
|
||||||
}, reject);
|
}, reject);
|
||||||
case OPS.moveTo:
|
case OPS.moveTo:
|
||||||
@ -898,7 +901,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
if (stop) {
|
if (stop) {
|
||||||
deferred.then(function () {
|
deferred.then(function () {
|
||||||
next(resolve, reject);
|
next(resolve, reject);
|
||||||
});
|
}, reject);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Some PDFs don't close all restores inside object/form.
|
// Some PDFs don't close all restores inside object/form.
|
||||||
@ -910,7 +913,8 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
getTextContent: function PartialEvaluator_getTextContent(stream, resources,
|
getTextContent: function PartialEvaluator_getTextContent(stream, task,
|
||||||
|
resources,
|
||||||
stateManager) {
|
stateManager) {
|
||||||
|
|
||||||
stateManager = (stateManager || new StateManager(new TextState()));
|
stateManager = (stateManager || new StateManager(new TextState()));
|
||||||
@ -1088,6 +1092,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
var timeSlotManager = new TimeSlotManager();
|
var timeSlotManager = new TimeSlotManager();
|
||||||
|
|
||||||
return new Promise(function next(resolve, reject) {
|
return new Promise(function next(resolve, reject) {
|
||||||
|
task.ensureNotTerminated();
|
||||||
timeSlotManager.reset();
|
timeSlotManager.reset();
|
||||||
var stop, operation = {}, args = [];
|
var stop, operation = {}, args = [];
|
||||||
while (!(stop = timeSlotManager.check())) {
|
while (!(stop = timeSlotManager.check())) {
|
||||||
@ -1243,7 +1248,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
stateManager.transform(matrix);
|
stateManager.transform(matrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
return self.getTextContent(xobj,
|
return self.getTextContent(xobj, task,
|
||||||
xobj.dict.get('Resources') || resources, stateManager).
|
xobj.dict.get('Resources') || resources, stateManager).
|
||||||
then(function (formTextContent) {
|
then(function (formTextContent) {
|
||||||
Util.appendToArray(bidiTexts, formTextContent.items);
|
Util.appendToArray(bidiTexts, formTextContent.items);
|
||||||
@ -1283,7 +1288,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
if (stop) {
|
if (stop) {
|
||||||
deferred.then(function () {
|
deferred.then(function () {
|
||||||
next(resolve, reject);
|
next(resolve, reject);
|
||||||
});
|
}, reject);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
resolve(textContent);
|
resolve(textContent);
|
||||||
@ -1848,7 +1853,7 @@ var TranslatedFont = (function TranslatedFontClosure() {
|
|||||||
]);
|
]);
|
||||||
this.sent = true;
|
this.sent = true;
|
||||||
},
|
},
|
||||||
loadType3Data: function (evaluator, resources, parentOperatorList) {
|
loadType3Data: function (evaluator, resources, parentOperatorList, task) {
|
||||||
assert(this.font.isType3Font);
|
assert(this.font.isType3Font);
|
||||||
|
|
||||||
if (this.type3Loaded) {
|
if (this.type3Loaded) {
|
||||||
@ -1865,7 +1870,7 @@ var TranslatedFont = (function TranslatedFontClosure() {
|
|||||||
loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
|
loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
|
||||||
var glyphStream = charProcs[key];
|
var glyphStream = charProcs[key];
|
||||||
var operatorList = new OperatorList();
|
var operatorList = new OperatorList();
|
||||||
return evaluator.getOperatorList(glyphStream, fontResources,
|
return evaluator.getOperatorList(glyphStream, task, fontResources,
|
||||||
operatorList).then(function () {
|
operatorList).then(function () {
|
||||||
charProcOperatorList[key] = operatorList.getIR();
|
charProcOperatorList[key] = operatorList.getIR();
|
||||||
|
|
||||||
|
@ -1378,9 +1378,9 @@ var XRef = (function XRefClosure() {
|
|||||||
resolve(xref.fetch(ref, suppressEncryption));
|
resolve(xref.fetch(ref, suppressEncryption));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof MissingDataException) {
|
if (e instanceof MissingDataException) {
|
||||||
streamManager.requestRange(e.begin, e.end, function () {
|
streamManager.requestRange(e.begin, e.end).then(function () {
|
||||||
tryFetch(resolve, reject);
|
tryFetch(resolve, reject);
|
||||||
});
|
}, reject);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
reject(e);
|
reject(e);
|
||||||
@ -1656,6 +1656,7 @@ var ObjectLoader = (function() {
|
|||||||
this.keys = keys;
|
this.keys = keys;
|
||||||
this.xref = xref;
|
this.xref = xref;
|
||||||
this.refSet = null;
|
this.refSet = null;
|
||||||
|
this.capability = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjectLoader.prototype = {
|
ObjectLoader.prototype = {
|
||||||
@ -1676,11 +1677,11 @@ var ObjectLoader = (function() {
|
|||||||
nodesToVisit.push(this.obj[keys[i]]);
|
nodesToVisit.push(this.obj[keys[i]]);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.walk(nodesToVisit);
|
this._walk(nodesToVisit);
|
||||||
return this.capability.promise;
|
return this.capability.promise;
|
||||||
},
|
},
|
||||||
|
|
||||||
walk: function ObjectLoader_walk(nodesToVisit) {
|
_walk: function ObjectLoader_walk(nodesToVisit) {
|
||||||
var nodesToRevisit = [];
|
var nodesToRevisit = [];
|
||||||
var pendingRequests = [];
|
var pendingRequests = [];
|
||||||
// DFS walk of the object graph.
|
// DFS walk of the object graph.
|
||||||
@ -1727,7 +1728,7 @@ var ObjectLoader = (function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (pendingRequests.length) {
|
if (pendingRequests.length) {
|
||||||
this.xref.stream.manager.requestRanges(pendingRequests,
|
this.xref.stream.manager.requestRanges(pendingRequests).then(
|
||||||
function pendingRequestCallback() {
|
function pendingRequestCallback() {
|
||||||
nodesToVisit = nodesToRevisit;
|
nodesToVisit = nodesToRevisit;
|
||||||
for (var i = 0; i < nodesToRevisit.length; i++) {
|
for (var i = 0; i < nodesToRevisit.length; i++) {
|
||||||
@ -1738,8 +1739,8 @@ var ObjectLoader = (function() {
|
|||||||
this.refSet.remove(node);
|
this.refSet.remove(node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.walk(nodesToVisit);
|
this._walk(nodesToVisit);
|
||||||
}.bind(this));
|
}.bind(this), this.capability.reject);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Everything is loaded.
|
// Everything is loaded.
|
||||||
|
@ -183,7 +183,8 @@ var NetworkPdfManager = (function NetworkPdfManagerClosure() {
|
|||||||
reject(e);
|
reject(e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pdfManager.streamManager.requestRange(e.begin, e.end, ensureHelper);
|
pdfManager.streamManager.requestRange(e.begin, e.end).
|
||||||
|
then(ensureHelper, reject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,11 +194,7 @@ var NetworkPdfManager = (function NetworkPdfManagerClosure() {
|
|||||||
|
|
||||||
NetworkPdfManager.prototype.requestRange =
|
NetworkPdfManager.prototype.requestRange =
|
||||||
function NetworkPdfManager_requestRange(begin, end) {
|
function NetworkPdfManager_requestRange(begin, end) {
|
||||||
return new Promise(function (resolve) {
|
return this.streamManager.requestRange(begin, end);
|
||||||
this.streamManager.requestRange(begin, end, function() {
|
|
||||||
resolve();
|
|
||||||
});
|
|
||||||
}.bind(this));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
NetworkPdfManager.prototype.requestLoadedStream =
|
NetworkPdfManager.prototype.requestLoadedStream =
|
||||||
@ -217,7 +214,7 @@ var NetworkPdfManager = (function NetworkPdfManagerClosure() {
|
|||||||
|
|
||||||
NetworkPdfManager.prototype.terminate =
|
NetworkPdfManager.prototype.terminate =
|
||||||
function NetworkPdfManager_terminate() {
|
function NetworkPdfManager_terminate() {
|
||||||
this.streamManager.networkManager.abortAllRequests();
|
this.streamManager.abort();
|
||||||
};
|
};
|
||||||
|
|
||||||
return NetworkPdfManager;
|
return NetworkPdfManager;
|
||||||
|
@ -22,9 +22,58 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
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 = {
|
var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
|
||||||
setup: function wphSetup(handler) {
|
setup: function wphSetup(handler) {
|
||||||
var pdfManager;
|
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) {
|
function loadDocument(recoveryMode) {
|
||||||
var loadDocumentCapability = createPromiseCapability();
|
var loadDocumentCapability = createPromiseCapability();
|
||||||
@ -61,13 +110,14 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
|
|||||||
|
|
||||||
function getPdfManager(data) {
|
function getPdfManager(data) {
|
||||||
var pdfManagerCapability = createPromiseCapability();
|
var pdfManagerCapability = createPromiseCapability();
|
||||||
|
var pdfManager;
|
||||||
|
|
||||||
var source = data.source;
|
var source = data.source;
|
||||||
var disableRange = data.disableRange;
|
var disableRange = data.disableRange;
|
||||||
if (source.data) {
|
if (source.data) {
|
||||||
try {
|
try {
|
||||||
pdfManager = new LocalPdfManager(source.data, source.password);
|
pdfManager = new LocalPdfManager(source.data, source.password);
|
||||||
pdfManagerCapability.resolve();
|
pdfManagerCapability.resolve(pdfManager);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
pdfManagerCapability.reject(ex);
|
pdfManagerCapability.reject(ex);
|
||||||
}
|
}
|
||||||
@ -75,7 +125,7 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
|
|||||||
} else if (source.chunkedViewerLoading) {
|
} else if (source.chunkedViewerLoading) {
|
||||||
try {
|
try {
|
||||||
pdfManager = new NetworkPdfManager(source, handler);
|
pdfManager = new NetworkPdfManager(source, handler);
|
||||||
pdfManagerCapability.resolve();
|
pdfManagerCapability.resolve(pdfManager);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
pdfManagerCapability.reject(ex);
|
pdfManagerCapability.reject(ex);
|
||||||
}
|
}
|
||||||
@ -136,6 +186,7 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
|
|||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
pdfManagerCapability.reject(ex);
|
pdfManagerCapability.reject(ex);
|
||||||
}
|
}
|
||||||
|
cancelXHRs = null;
|
||||||
},
|
},
|
||||||
|
|
||||||
onProgressiveData: source.disableStream ? null :
|
onProgressiveData: source.disableStream ? null :
|
||||||
@ -176,10 +227,11 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
|
|||||||
// the data is array, instantiating directly from it
|
// the data is array, instantiating directly from it
|
||||||
try {
|
try {
|
||||||
pdfManager = new LocalPdfManager(pdfFile, source.password);
|
pdfManager = new LocalPdfManager(pdfFile, source.password);
|
||||||
pdfManagerCapability.resolve();
|
pdfManagerCapability.resolve(pdfManager);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
pdfManagerCapability.reject(ex);
|
pdfManagerCapability.reject(ex);
|
||||||
}
|
}
|
||||||
|
cancelXHRs = null;
|
||||||
},
|
},
|
||||||
|
|
||||||
onError: function onError(status) {
|
onError: function onError(status) {
|
||||||
@ -194,6 +246,7 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
|
|||||||
') while retrieving PDF "' + source.url + '".', status);
|
') while retrieving PDF "' + source.url + '".', status);
|
||||||
handler.send('UnexpectedResponse', exception);
|
handler.send('UnexpectedResponse', exception);
|
||||||
}
|
}
|
||||||
|
cancelXHRs = null;
|
||||||
},
|
},
|
||||||
|
|
||||||
onProgress: function onProgress(evt) {
|
onProgress: function onProgress(evt) {
|
||||||
@ -204,6 +257,10 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
cancelXHRs = function () {
|
||||||
|
networkManager.abortRequest(fullRequestXhrId);
|
||||||
|
};
|
||||||
|
|
||||||
return pdfManagerCapability.promise;
|
return pdfManagerCapability.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,8 +293,8 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
handler.on('GetDocRequest', function wphSetupDoc(data) {
|
handler.on('GetDocRequest', function wphSetupDoc(data) {
|
||||||
|
|
||||||
var onSuccess = function(doc) {
|
var onSuccess = function(doc) {
|
||||||
|
ensureNotTerminated();
|
||||||
handler.send('GetDoc', { pdfInfo: doc });
|
handler.send('GetDoc', { pdfInfo: doc });
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -260,6 +317,8 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ensureNotTerminated();
|
||||||
|
|
||||||
PDFJS.maxImageSize = data.maxImageSize === undefined ?
|
PDFJS.maxImageSize = data.maxImageSize === undefined ?
|
||||||
-1 : data.maxImageSize;
|
-1 : data.maxImageSize;
|
||||||
PDFJS.disableFontFace = data.disableFontFace;
|
PDFJS.disableFontFace = data.disableFontFace;
|
||||||
@ -269,13 +328,26 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
|
|||||||
null : data.cMapUrl;
|
null : data.cMapUrl;
|
||||||
PDFJS.cMapPacked = data.cMapPacked === true;
|
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);
|
handler.send('PDFManagerReady', null);
|
||||||
pdfManager.onLoadedStream().then(function(stream) {
|
pdfManager.onLoadedStream().then(function(stream) {
|
||||||
handler.send('DataLoaded', { length: stream.bytes.byteLength });
|
handler.send('DataLoaded', { length: stream.bytes.byteLength });
|
||||||
});
|
});
|
||||||
}).then(function pdfManagerReady() {
|
}).then(function pdfManagerReady() {
|
||||||
|
ensureNotTerminated();
|
||||||
|
|
||||||
loadDocument(false).then(onSuccess, function loadFailure(ex) {
|
loadDocument(false).then(onSuccess, function loadFailure(ex) {
|
||||||
|
ensureNotTerminated();
|
||||||
|
|
||||||
// Try again with recoveryMode == true
|
// Try again with recoveryMode == true
|
||||||
if (!(ex instanceof XRefParseException)) {
|
if (!(ex instanceof XRefParseException)) {
|
||||||
if (ex instanceof PasswordException) {
|
if (ex instanceof PasswordException) {
|
||||||
@ -290,6 +362,8 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
|
|||||||
|
|
||||||
pdfManager.requestLoadedStream();
|
pdfManager.requestLoadedStream();
|
||||||
pdfManager.onLoadedStream().then(function() {
|
pdfManager.onLoadedStream().then(function() {
|
||||||
|
ensureNotTerminated();
|
||||||
|
|
||||||
loadDocument(true).then(onSuccess, onFailure);
|
loadDocument(true).then(onSuccess, onFailure);
|
||||||
});
|
});
|
||||||
}, onFailure);
|
}, onFailure);
|
||||||
@ -380,17 +454,25 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
|
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();
|
var start = Date.now();
|
||||||
// Pre compile the pdf page and fetch the fonts/images.
|
// 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=' +
|
info('page=' + pageNum + ' - getOperatorList: time=' +
|
||||||
(Date.now() - start) + 'ms, len=' + operatorList.fnArray.length);
|
(Date.now() - start) + 'ms, len=' + operatorList.fnArray.length);
|
||||||
|
|
||||||
}, function(e) {
|
}, function(e) {
|
||||||
|
finishWorkerTask(task);
|
||||||
|
if (task.terminated) {
|
||||||
|
return; // ignoring errors from the terminated thread
|
||||||
|
}
|
||||||
|
|
||||||
var minimumStackMessage =
|
var minimumStackMessage =
|
||||||
'worker.js: while trying to getPage() and getOperatorList()';
|
'worker.js: while trying to getPage() and getOperatorList()';
|
||||||
@ -425,13 +507,23 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
|
|||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
handler.on('GetTextContent', function wphExtractText(data) {
|
handler.on('GetTextContent', function wphExtractText(data) {
|
||||||
return pdfManager.getPage(data.pageIndex).then(function(page) {
|
var pageIndex = data.pageIndex;
|
||||||
var pageNum = data.pageIndex + 1;
|
return pdfManager.getPage(pageIndex).then(function(page) {
|
||||||
|
var task = new WorkerTask('GetTextContent: page ' + pageIndex);
|
||||||
|
startWorkerTask(task);
|
||||||
|
var pageNum = pageIndex + 1;
|
||||||
var start = Date.now();
|
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=' +
|
info('text indexing: page=' + pageNum + ' - time=' +
|
||||||
(Date.now() - start) + 'ms');
|
(Date.now() - start) + 'ms');
|
||||||
return textContent;
|
return textContent;
|
||||||
|
}, function (reason) {
|
||||||
|
finishWorkerTask(task);
|
||||||
|
if (task.terminated) {
|
||||||
|
return; // ignoring errors from the terminated thread
|
||||||
|
}
|
||||||
|
throw reason;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -441,7 +533,22 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
handler.on('Terminate', function wphTerminate(data) {
|
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 () {});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
Promise, PasswordResponses, PasswordException, InvalidPDFException,
|
Promise, PasswordResponses, PasswordException, InvalidPDFException,
|
||||||
MissingPDFException, UnknownErrorException, FontFaceObject,
|
MissingPDFException, UnknownErrorException, FontFaceObject,
|
||||||
loadJpegStream, createScratchCanvas, CanvasGraphics, stringToBytes,
|
loadJpegStream, createScratchCanvas, CanvasGraphics, stringToBytes,
|
||||||
UnexpectedResponseException */
|
UnexpectedResponseException, deprecated */
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
@ -259,12 +259,19 @@ PDFJS.getDocument = function getDocument(src,
|
|||||||
var task = new PDFDocumentLoadingTask();
|
var task = new PDFDocumentLoadingTask();
|
||||||
|
|
||||||
// Support of the obsolete arguments (for compatibility with API v1.0)
|
// 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) {
|
||||||
if (!(pdfDataRangeTransport instanceof PDFDataRangeTransport)) {
|
if (!(pdfDataRangeTransport instanceof PDFDataRangeTransport)) {
|
||||||
// Not a PDFDataRangeTransport instance, trying to add missing properties.
|
// Not a PDFDataRangeTransport instance, trying to add missing properties.
|
||||||
pdfDataRangeTransport = Object.create(pdfDataRangeTransport);
|
pdfDataRangeTransport = Object.create(pdfDataRangeTransport);
|
||||||
pdfDataRangeTransport.length = src.length;
|
pdfDataRangeTransport.length = src.length;
|
||||||
pdfDataRangeTransport.initialData = src.initialData;
|
pdfDataRangeTransport.initialData = src.initialData;
|
||||||
|
if (!pdfDataRangeTransport.abort) {
|
||||||
|
pdfDataRangeTransport.abort = function () {};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
src = Object.create(src);
|
src = Object.create(src);
|
||||||
src.range = pdfDataRangeTransport;
|
src.range = pdfDataRangeTransport;
|
||||||
@ -324,6 +331,7 @@ PDFJS.getDocument = function getDocument(src,
|
|||||||
workerInitializedCapability.promise.then(function transportInitialized() {
|
workerInitializedCapability.promise.then(function transportInitialized() {
|
||||||
transport.fetchDocument(task, params);
|
transport.fetchDocument(task, params);
|
||||||
});
|
});
|
||||||
|
task._transport = transport;
|
||||||
|
|
||||||
return task;
|
return task;
|
||||||
};
|
};
|
||||||
@ -336,6 +344,7 @@ var PDFDocumentLoadingTask = (function PDFDocumentLoadingTaskClosure() {
|
|||||||
/** @constructs PDFDocumentLoadingTask */
|
/** @constructs PDFDocumentLoadingTask */
|
||||||
function PDFDocumentLoadingTask() {
|
function PDFDocumentLoadingTask() {
|
||||||
this._capability = createPromiseCapability();
|
this._capability = createPromiseCapability();
|
||||||
|
this._transport = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Callback to request a password if wrong or no password was provided.
|
* Callback to request a password if wrong or no password was provided.
|
||||||
@ -361,7 +370,14 @@ var PDFDocumentLoadingTask = (function PDFDocumentLoadingTaskClosure() {
|
|||||||
return this._capability.promise;
|
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.
|
* Registers callbacks to indicate the document loading completion.
|
||||||
@ -448,6 +464,9 @@ var PDFDataRangeTransport = (function pdfDataRangeTransportClosure() {
|
|||||||
requestDataRange:
|
requestDataRange:
|
||||||
function PDFDataRangeTransport_requestDataRange(begin, end) {
|
function PDFDataRangeTransport_requestDataRange(begin, end) {
|
||||||
throw new Error('Abstract method PDFDataRangeTransport.requestDataRange');
|
throw new Error('Abstract method PDFDataRangeTransport.requestDataRange');
|
||||||
|
},
|
||||||
|
|
||||||
|
abort: function PDFDataRangeTransport_abort() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return PDFDataRangeTransport;
|
return PDFDataRangeTransport;
|
||||||
@ -461,9 +480,10 @@ PDFJS.PDFDataRangeTransport = PDFDataRangeTransport;
|
|||||||
* @class
|
* @class
|
||||||
*/
|
*/
|
||||||
var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
|
var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
|
||||||
function PDFDocumentProxy(pdfInfo, transport) {
|
function PDFDocumentProxy(pdfInfo, transport, loadingTask) {
|
||||||
this.pdfInfo = pdfInfo;
|
this.pdfInfo = pdfInfo;
|
||||||
this.transport = transport;
|
this.transport = transport;
|
||||||
|
this.loadingTask = loadingTask;
|
||||||
}
|
}
|
||||||
PDFDocumentProxy.prototype = /** @lends PDFDocumentProxy.prototype */ {
|
PDFDocumentProxy.prototype = /** @lends PDFDocumentProxy.prototype */ {
|
||||||
/**
|
/**
|
||||||
@ -586,7 +606,7 @@ var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
|
|||||||
* Destroys current document instance and terminates worker.
|
* Destroys current document instance and terminates worker.
|
||||||
*/
|
*/
|
||||||
destroy: function PDFDocumentProxy_destroy() {
|
destroy: function PDFDocumentProxy_destroy() {
|
||||||
this.transport.destroy();
|
return this.transport.destroy();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return PDFDocumentProxy;
|
return PDFDocumentProxy;
|
||||||
@ -663,8 +683,9 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
|
|||||||
this.commonObjs = transport.commonObjs;
|
this.commonObjs = transport.commonObjs;
|
||||||
this.objs = new PDFObjects();
|
this.objs = new PDFObjects();
|
||||||
this.cleanupAfterRender = false;
|
this.cleanupAfterRender = false;
|
||||||
this.pendingDestroy = false;
|
this.pendingCleanup = false;
|
||||||
this.intentStates = {};
|
this.intentStates = {};
|
||||||
|
this.destroyed = false;
|
||||||
}
|
}
|
||||||
PDFPageProxy.prototype = /** @lends PDFPageProxy.prototype */ {
|
PDFPageProxy.prototype = /** @lends PDFPageProxy.prototype */ {
|
||||||
/**
|
/**
|
||||||
@ -728,7 +749,7 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
|
|||||||
|
|
||||||
// If there was a pending destroy cancel it so no cleanup happens during
|
// If there was a pending destroy cancel it so no cleanup happens during
|
||||||
// this call to render.
|
// this call to render.
|
||||||
this.pendingDestroy = false;
|
this.pendingCleanup = false;
|
||||||
|
|
||||||
var renderingIntent = (params.intent === 'print' ? 'print' : 'display');
|
var renderingIntent = (params.intent === 'print' ? 'print' : 'display');
|
||||||
|
|
||||||
@ -769,13 +790,14 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
|
|||||||
|
|
||||||
// Obsolete parameter support
|
// Obsolete parameter support
|
||||||
if (params.continueCallback) {
|
if (params.continueCallback) {
|
||||||
|
deprecated('render is used with continueCallback parameter');
|
||||||
renderTask.onContinue = params.continueCallback;
|
renderTask.onContinue = params.continueCallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
intentState.displayReadyCapability.promise.then(
|
intentState.displayReadyCapability.promise.then(
|
||||||
function pageDisplayReadyPromise(transparency) {
|
function pageDisplayReadyPromise(transparency) {
|
||||||
if (self.pendingDestroy) {
|
if (self.pendingCleanup) {
|
||||||
complete();
|
complete();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -795,9 +817,9 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (self.cleanupAfterRender) {
|
if (self.cleanupAfterRender) {
|
||||||
self.pendingDestroy = true;
|
self.pendingCleanup = true;
|
||||||
}
|
}
|
||||||
self._tryDestroy();
|
self._tryCleanup();
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
internalRenderTask.capability.reject(error);
|
internalRenderTask.capability.reject(error);
|
||||||
@ -858,20 +880,52 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
|
|||||||
pageIndex: this.pageNumber - 1
|
pageIndex: this.pageNumber - 1
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroys resources allocated by the page.
|
* Destroys page object.
|
||||||
*/
|
*/
|
||||||
destroy: function PDFPageProxy_destroy() {
|
_destroy: function PDFPageProxy_destroy() {
|
||||||
this.pendingDestroy = true;
|
this.destroyed = true;
|
||||||
this._tryDestroy();
|
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
|
* For internal use only. Attempts to clean up if rendering is in a state
|
||||||
* where that's possible.
|
* where that's possible.
|
||||||
* @ignore
|
* @ignore
|
||||||
*/
|
*/
|
||||||
_tryDestroy: function PDFPageProxy__destroy() {
|
_tryCleanup: function PDFPageProxy_tryCleanup() {
|
||||||
if (!this.pendingDestroy ||
|
if (!this.pendingCleanup ||
|
||||||
Object.keys(this.intentStates).some(function(intent) {
|
Object.keys(this.intentStates).some(function(intent) {
|
||||||
var intentState = this.intentStates[intent];
|
var intentState = this.intentStates[intent];
|
||||||
return (intentState.renderTasks.length !== 0 ||
|
return (intentState.renderTasks.length !== 0 ||
|
||||||
@ -885,7 +939,7 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
|
|||||||
}, this);
|
}, this);
|
||||||
this.objs.clear();
|
this.objs.clear();
|
||||||
this.annotationsPromise = null;
|
this.annotationsPromise = null;
|
||||||
this.pendingDestroy = false;
|
this.pendingCleanup = false;
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* For internal use only.
|
* For internal use only.
|
||||||
@ -923,7 +977,7 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
|
|||||||
|
|
||||||
if (operatorListChunk.lastChunk) {
|
if (operatorListChunk.lastChunk) {
|
||||||
intentState.receivingOperatorList = false;
|
intentState.receivingOperatorList = false;
|
||||||
this._tryDestroy();
|
this._tryCleanup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -941,6 +995,8 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|||||||
this.commonObjs = new PDFObjects();
|
this.commonObjs = new PDFObjects();
|
||||||
|
|
||||||
this.loadingTask = null;
|
this.loadingTask = null;
|
||||||
|
this.destroyed = false;
|
||||||
|
this.destroyCapability = null;
|
||||||
|
|
||||||
this.pageCache = [];
|
this.pageCache = [];
|
||||||
this.pagePromises = [];
|
this.pagePromises = [];
|
||||||
@ -1001,15 +1057,40 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|||||||
}
|
}
|
||||||
WorkerTransport.prototype = {
|
WorkerTransport.prototype = {
|
||||||
destroy: function WorkerTransport_destroy() {
|
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.pageCache = [];
|
||||||
this.pagePromises = [];
|
this.pagePromises = [];
|
||||||
var self = this;
|
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();
|
FontLoader.clear();
|
||||||
if (self.worker) {
|
if (self.worker) {
|
||||||
self.worker.terminate();
|
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() {
|
setupFakeWorker: function WorkerTransport_setupFakeWorker() {
|
||||||
@ -1091,9 +1172,10 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|||||||
messageHandler.on('GetDoc', function transportDoc(data) {
|
messageHandler.on('GetDoc', function transportDoc(data) {
|
||||||
var pdfInfo = data.pdfInfo;
|
var pdfInfo = data.pdfInfo;
|
||||||
this.numPages = data.pdfInfo.numPages;
|
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.pdfDocument = pdfDocument;
|
||||||
this.loadingTask._capability.resolve(pdfDocument);
|
loadingTask._capability.resolve(pdfDocument);
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
messageHandler.on('NeedPassword',
|
messageHandler.on('NeedPassword',
|
||||||
@ -1294,6 +1376,12 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|||||||
},
|
},
|
||||||
|
|
||||||
fetchDocument: function WorkerTransport_fetchDocument(loadingTask, source) {
|
fetchDocument: function WorkerTransport_fetchDocument(loadingTask, source) {
|
||||||
|
if (this.destroyed) {
|
||||||
|
loadingTask._capability.reject(new Error('Loading aborted'));
|
||||||
|
this.destroyCapability.resolve();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.loadingTask = loadingTask;
|
this.loadingTask = loadingTask;
|
||||||
|
|
||||||
source.disableAutoFetch = PDFJS.disableAutoFetch;
|
source.disableAutoFetch = PDFJS.disableAutoFetch;
|
||||||
@ -1332,6 +1420,9 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|||||||
var promise = this.messageHandler.sendWithPromise('GetPage', {
|
var promise = this.messageHandler.sendWithPromise('GetPage', {
|
||||||
pageIndex: pageIndex
|
pageIndex: pageIndex
|
||||||
}).then(function (pageInfo) {
|
}).then(function (pageInfo) {
|
||||||
|
if (this.destroyed) {
|
||||||
|
throw new Error('Transport destroyed');
|
||||||
|
}
|
||||||
var page = new PDFPageProxy(pageIndex, pageInfo, this);
|
var page = new PDFPageProxy(pageIndex, pageInfo, this);
|
||||||
this.pageCache[pageIndex] = page;
|
this.pageCache[pageIndex] = page;
|
||||||
return page;
|
return page;
|
||||||
@ -1389,7 +1480,7 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|||||||
for (var i = 0, ii = this.pageCache.length; i < ii; i++) {
|
for (var i = 0, ii = this.pageCache.length; i < ii; i++) {
|
||||||
var page = this.pageCache[i];
|
var page = this.pageCache[i];
|
||||||
if (page) {
|
if (page) {
|
||||||
page.destroy();
|
page.cleanup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.commonObjs.clear();
|
this.commonObjs.clear();
|
||||||
|
@ -213,6 +213,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
|
// Fatal errors that should trigger the fallback UI and halt execution by
|
||||||
// throwing an exception.
|
// throwing an exception.
|
||||||
function error(msg) {
|
function error(msg) {
|
||||||
|
@ -11,31 +11,31 @@ describe('api', function() {
|
|||||||
var basicApiUrl = combineUrl(window.location.href, '../pdfs/basicapi.pdf');
|
var basicApiUrl = combineUrl(window.location.href, '../pdfs/basicapi.pdf');
|
||||||
var basicApiFileLength = 105779; // bytes
|
var basicApiFileLength = 105779; // bytes
|
||||||
function waitsForPromiseResolved(promise, successCallback) {
|
function waitsForPromiseResolved(promise, successCallback) {
|
||||||
var data;
|
var resolved = false;
|
||||||
promise.then(function(val) {
|
promise.then(function(val) {
|
||||||
data = val;
|
resolved = true;
|
||||||
successCallback(data);
|
successCallback(val);
|
||||||
},
|
},
|
||||||
function(error) {
|
function(error) {
|
||||||
// Shouldn't get here.
|
// Shouldn't get here.
|
||||||
expect(false).toEqual(true);
|
expect(false).toEqual(true);
|
||||||
});
|
});
|
||||||
waitsFor(function() {
|
waitsFor(function() {
|
||||||
return data !== undefined;
|
return resolved;
|
||||||
}, 20000);
|
}, 20000);
|
||||||
}
|
}
|
||||||
function waitsForPromiseRejected(promise, failureCallback) {
|
function waitsForPromiseRejected(promise, failureCallback) {
|
||||||
var data;
|
var rejected = false;
|
||||||
promise.then(function(val) {
|
promise.then(function(val) {
|
||||||
// Shouldn't get here.
|
// Shouldn't get here.
|
||||||
expect(false).toEqual(true);
|
expect(false).toEqual(true);
|
||||||
},
|
},
|
||||||
function(error) {
|
function(error) {
|
||||||
data = error;
|
rejected = true;
|
||||||
failureCallback(data);
|
failureCallback(error);
|
||||||
});
|
});
|
||||||
waitsFor(function() {
|
waitsFor(function() {
|
||||||
return data !== undefined;
|
return rejected;
|
||||||
}, 20000);
|
}, 20000);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,6 +63,28 @@ describe('api', function() {
|
|||||||
waitsForPromiseResolved(Promise.all(promises), function (data) {
|
waitsForPromiseResolved(Promise.all(promises), function (data) {
|
||||||
expect((data[0].loaded / data[0].total) > 0).toEqual(true);
|
expect((data[0].loaded / data[0].total) > 0).toEqual(true);
|
||||||
expect(data[1] instanceof PDFDocumentProxy).toEqual(true);
|
expect(data[1] instanceof PDFDocumentProxy).toEqual(true);
|
||||||
|
expect(loadingTask).toEqual(data[1].loadingTask);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('creates pdf doc from URL and aborts before worker initialized',
|
||||||
|
function() {
|
||||||
|
var loadingTask = PDFJS.getDocument(basicApiUrl);
|
||||||
|
loadingTask.destroy();
|
||||||
|
waitsForPromiseRejected(loadingTask.promise, function(reason) {
|
||||||
|
expect(true).toEqual(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('creates pdf doc from URL and aborts loading after worker initialized',
|
||||||
|
function() {
|
||||||
|
var loadingTask = PDFJS.getDocument(basicApiUrl);
|
||||||
|
// This can be somewhat random -- we cannot guarantee perfect
|
||||||
|
// 'Terminate' message to the worker before/after setting up pdfManager.
|
||||||
|
var destroyed = loadingTask._transport.workerInitializedCapability.
|
||||||
|
promise.then(function () {
|
||||||
|
return loadingTask.destroy();
|
||||||
|
});
|
||||||
|
waitsForPromiseResolved(destroyed, function (data) {
|
||||||
|
expect(true).toEqual(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('creates pdf doc from typed array', function() {
|
it('creates pdf doc from typed array', function() {
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||||
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
||||||
/* globals expect, it, describe, PartialEvaluator, StringStream, OPS,
|
/* globals expect, it, describe, PartialEvaluator, StringStream, OPS,
|
||||||
OperatorList, waitsFor, runs, Dict, Name, Stream */
|
OperatorList, waitsFor, runs, Dict, Name, Stream, WorkerTask */
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
describe('evaluator', function() {
|
describe('evaluator', function() {
|
||||||
function XrefMock(queue) {
|
function XrefMock(queue) {
|
||||||
this.queue = queue;
|
this.queue = queue || [];
|
||||||
}
|
}
|
||||||
XrefMock.prototype = {
|
XrefMock.prototype = {
|
||||||
fetchIfRef: function() {
|
fetchIfRef: function() {
|
||||||
@ -35,7 +35,9 @@ describe('evaluator', function() {
|
|||||||
var done = false;
|
var done = false;
|
||||||
runs(function () {
|
runs(function () {
|
||||||
var result = new OperatorList();
|
var result = new OperatorList();
|
||||||
evaluator.getOperatorList(stream, resources, result).then(function () {
|
var task = new WorkerTask('OperatorListCheck');
|
||||||
|
evaluator.getOperatorList(stream, task, resources, result).then(
|
||||||
|
function () {
|
||||||
check(result);
|
check(result);
|
||||||
done = true;
|
done = true;
|
||||||
});
|
});
|
||||||
@ -259,4 +261,48 @@ describe('evaluator', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('thread control', function() {
|
||||||
|
it('should abort operator list parsing', function () {
|
||||||
|
var evaluator = new PartialEvaluator(new PdfManagerMock(),
|
||||||
|
new XrefMock(), new HandlerMock(),
|
||||||
|
'prefix');
|
||||||
|
var stream = new StringStream('qqQQ');
|
||||||
|
var resources = new ResourcesMock();
|
||||||
|
var done = false;
|
||||||
|
runs(function () {
|
||||||
|
var result = new OperatorList();
|
||||||
|
var task = new WorkerTask('OperatorListAbort');
|
||||||
|
task.terminate();
|
||||||
|
evaluator.getOperatorList(stream, task, resources, result).catch(
|
||||||
|
function () {
|
||||||
|
done = true;
|
||||||
|
expect(!!result.fnArray && !!result.argsArray).toEqual(true);
|
||||||
|
expect(result.fnArray.length).toEqual(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
waitsFor(function () {
|
||||||
|
return done;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('should abort text parsing parsing', function () {
|
||||||
|
var resources = new ResourcesMock();
|
||||||
|
var evaluator = new PartialEvaluator(new PdfManagerMock(),
|
||||||
|
new XrefMock(), new HandlerMock(),
|
||||||
|
'prefix');
|
||||||
|
var stream = new StringStream('qqQQ');
|
||||||
|
var done = false;
|
||||||
|
runs(function () {
|
||||||
|
var task = new WorkerTask('TextContentAbort');
|
||||||
|
task.terminate();
|
||||||
|
evaluator.getTextContent(stream, task, resources).catch(
|
||||||
|
function () {
|
||||||
|
done = true;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
waitsFor(function () {
|
||||||
|
return done;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
<script src="../../src/core/parser.js"></script>
|
<script src="../../src/core/parser.js"></script>
|
||||||
<script src="../../src/core/ps_parser.js"></script>
|
<script src="../../src/core/ps_parser.js"></script>
|
||||||
<script src="../../src/display/pattern_helper.js"></script>
|
<script src="../../src/display/pattern_helper.js"></script>
|
||||||
|
<script src="../../src/display/font_loader.js"></script>
|
||||||
<script src="../../src/display/annotation_helper.js"></script>
|
<script src="../../src/display/annotation_helper.js"></script>
|
||||||
<script src="../../src/core/stream.js"></script>
|
<script src="../../src/core/stream.js"></script>
|
||||||
<script src="../../src/core/worker.js"></script>
|
<script src="../../src/core/worker.js"></script>
|
||||||
|
@ -64,7 +64,7 @@ var ChromeCom = (function ChromeComClosure() {
|
|||||||
var streamUrl = response.streamUrl;
|
var streamUrl = response.streamUrl;
|
||||||
if (streamUrl) {
|
if (streamUrl) {
|
||||||
console.log('Found data stream for ' + file);
|
console.log('Found data stream for ' + file);
|
||||||
PDFViewerApplication.open(streamUrl, 0, undefined, undefined, {
|
PDFViewerApplication.open(streamUrl, {
|
||||||
length: response.contentLength
|
length: response.contentLength
|
||||||
});
|
});
|
||||||
PDFViewerApplication.setTitleUsingUrl(file);
|
PDFViewerApplication.setTitleUsingUrl(file);
|
||||||
@ -91,7 +91,7 @@ var ChromeCom = (function ChromeComClosure() {
|
|||||||
resolveLocalFileSystemURL(file, function onResolvedFSURL(fileEntry) {
|
resolveLocalFileSystemURL(file, function onResolvedFSURL(fileEntry) {
|
||||||
fileEntry.file(function(fileObject) {
|
fileEntry.file(function(fileObject) {
|
||||||
var blobUrl = URL.createObjectURL(fileObject);
|
var blobUrl = URL.createObjectURL(fileObject);
|
||||||
PDFViewerApplication.open(blobUrl, 0, undefined, undefined, {
|
PDFViewerApplication.open(blobUrl, {
|
||||||
length: fileObject.size
|
length: fileObject.size
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -100,7 +100,7 @@ var ChromeCom = (function ChromeComClosure() {
|
|||||||
// usual way of getting the File's data (via the Web worker).
|
// usual way of getting the File's data (via the Web worker).
|
||||||
console.warn('Cannot resolve file ' + file + ', ' + error.name + ' ' +
|
console.warn('Cannot resolve file ' + file + ', ' + error.name + ' ' +
|
||||||
error.message);
|
error.message);
|
||||||
PDFViewerApplication.open(file, 0);
|
PDFViewerApplication.open(file);
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -109,7 +109,7 @@ var ChromeCom = (function ChromeComClosure() {
|
|||||||
// There is no UI to input a different URL, so this assumption will hold
|
// There is no UI to input a different URL, so this assumption will hold
|
||||||
// for now.
|
// for now.
|
||||||
setReferer(file, function() {
|
setReferer(file, function() {
|
||||||
PDFViewerApplication.open(file, 0);
|
PDFViewerApplication.open(file);
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -122,14 +122,14 @@ var ChromeCom = (function ChromeComClosure() {
|
|||||||
}
|
}
|
||||||
isAllowedFileSchemeAccess(function(isAllowedAccess) {
|
isAllowedFileSchemeAccess(function(isAllowedAccess) {
|
||||||
if (isAllowedAccess) {
|
if (isAllowedAccess) {
|
||||||
PDFViewerApplication.open(file, 0);
|
PDFViewerApplication.open(file);
|
||||||
} else {
|
} else {
|
||||||
requestAccessToLocalFile(file);
|
requestAccessToLocalFile(file);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PDFViewerApplication.open(file, 0);
|
PDFViewerApplication.open(file);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ var PDFPageView = (function PDFPageViewClosure() {
|
|||||||
this.zoomLayer = null;
|
this.zoomLayer = null;
|
||||||
this.reset();
|
this.reset();
|
||||||
if (this.pdfPage) {
|
if (this.pdfPage) {
|
||||||
this.pdfPage.destroy();
|
this.pdfPage.cleanup();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -457,9 +457,9 @@ var PDFPageView = (function PDFPageViewClosure() {
|
|||||||
canvasContext: ctx,
|
canvasContext: ctx,
|
||||||
viewport: this.viewport,
|
viewport: this.viewport,
|
||||||
// intent: 'default', // === 'display'
|
// intent: 'default', // === 'display'
|
||||||
continueCallback: renderContinueCallback
|
|
||||||
};
|
};
|
||||||
var renderTask = this.renderTask = this.pdfPage.render(renderContext);
|
var renderTask = this.renderTask = this.pdfPage.render(renderContext);
|
||||||
|
renderTask.onContinue = renderContinueCallback;
|
||||||
|
|
||||||
this.renderTask.promise.then(
|
this.renderTask.promise.then(
|
||||||
function pdfPageRenderCallback() {
|
function pdfPageRenderCallback() {
|
||||||
|
@ -285,10 +285,10 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
|
|||||||
|
|
||||||
var renderContext = {
|
var renderContext = {
|
||||||
canvasContext: ctx,
|
canvasContext: ctx,
|
||||||
viewport: drawViewport,
|
viewport: drawViewport
|
||||||
continueCallback: renderContinueCallback
|
|
||||||
};
|
};
|
||||||
var renderTask = this.renderTask = this.pdfPage.render(renderContext);
|
var renderTask = this.renderTask = this.pdfPage.render(renderContext);
|
||||||
|
renderTask.onContinue = renderContinueCallback;
|
||||||
|
|
||||||
renderTask.promise.then(
|
renderTask.promise.then(
|
||||||
function pdfPageRenderCallback() {
|
function pdfPageRenderCallback() {
|
||||||
|
108
web/viewer.js
108
web/viewer.js
@ -92,6 +92,7 @@ var PDFViewerApplication = {
|
|||||||
initialized: false,
|
initialized: false,
|
||||||
fellback: false,
|
fellback: false,
|
||||||
pdfDocument: null,
|
pdfDocument: null,
|
||||||
|
pdfLoadingTask: null,
|
||||||
sidebarOpen: false,
|
sidebarOpen: false,
|
||||||
printing: false,
|
printing: false,
|
||||||
/** @type {PDFViewer} */
|
/** @type {PDFViewer} */
|
||||||
@ -410,6 +411,11 @@ var PDFViewerApplication = {
|
|||||||
function FirefoxComDataRangeTransport_requestDataRange(begin, end) {
|
function FirefoxComDataRangeTransport_requestDataRange(begin, end) {
|
||||||
FirefoxCom.request('requestDataRange', { begin: begin, end: 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;
|
var pdfDataRangeTransport;
|
||||||
|
|
||||||
@ -429,8 +435,8 @@ var PDFViewerApplication = {
|
|||||||
pdfDataRangeTransport =
|
pdfDataRangeTransport =
|
||||||
new FirefoxComDataRangeTransport(args.length, args.data);
|
new FirefoxComDataRangeTransport(args.length, args.data);
|
||||||
|
|
||||||
PDFViewerApplication.open(args.pdfUrl, 0, undefined,
|
PDFViewerApplication.open(args.pdfUrl,
|
||||||
pdfDataRangeTransport);
|
{range: pdfDataRangeTransport});
|
||||||
|
|
||||||
if (args.length) {
|
if (args.length) {
|
||||||
PDFViewerApplication.pdfDocumentProperties
|
PDFViewerApplication.pdfDocumentProperties
|
||||||
@ -455,7 +461,7 @@ var PDFViewerApplication = {
|
|||||||
'An error occurred while loading the PDF.'), e);
|
'An error occurred while loading the PDF.'), e);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
PDFViewerApplication.open(args.data, 0);
|
PDFViewerApplication.open(args.data);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -482,36 +488,76 @@ var PDFViewerApplication = {
|
|||||||
document.title = title;
|
document.title = title;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes opened PDF document.
|
||||||
|
* @returns {Promise} - Returns the promise, which is resolved when all
|
||||||
|
* destruction is completed.
|
||||||
|
*/
|
||||||
close: function pdfViewClose() {
|
close: function pdfViewClose() {
|
||||||
var errorWrapper = document.getElementById('errorWrapper');
|
var errorWrapper = document.getElementById('errorWrapper');
|
||||||
errorWrapper.setAttribute('hidden', 'true');
|
errorWrapper.setAttribute('hidden', 'true');
|
||||||
|
|
||||||
if (!this.pdfDocument) {
|
if (!this.pdfLoadingTask) {
|
||||||
return;
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.pdfDocument.destroy();
|
var promise = this.pdfLoadingTask.destroy();
|
||||||
this.pdfDocument = null;
|
this.pdfLoadingTask = null;
|
||||||
|
|
||||||
this.pdfThumbnailViewer.setDocument(null);
|
if (this.pdfDocument) {
|
||||||
this.pdfViewer.setDocument(null);
|
this.pdfDocument = null;
|
||||||
this.pdfLinkService.setDocument(null, null);
|
|
||||||
|
this.pdfThumbnailViewer.setDocument(null);
|
||||||
|
this.pdfViewer.setDocument(null);
|
||||||
|
this.pdfLinkService.setDocument(null, null);
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof PDFBug !== 'undefined') {
|
if (typeof PDFBug !== 'undefined') {
|
||||||
PDFBug.cleanup();
|
PDFBug.cleanup();
|
||||||
}
|
}
|
||||||
|
return promise;
|
||||||
},
|
},
|
||||||
|
|
||||||
// TODO(mack): This function signature should really be pdfViewOpen(url, args)
|
/**
|
||||||
open: function pdfViewOpen(file, scale, password,
|
* Opens PDF document specified by URL or array with additional arguments.
|
||||||
pdfDataRangeTransport, args) {
|
* @param {string|TypedArray|ArrayBuffer} file - PDF location or binary data.
|
||||||
if (this.pdfDocument) {
|
* @param {Object} args - (optional) Additional arguments for the getDocument
|
||||||
// Reload the preferences if a document was previously opened.
|
* call, e.g. HTTP headers ('httpHeaders') or
|
||||||
Preferences.reload();
|
* 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
|
if (typeof file === 'string') { // URL
|
||||||
this.setTitleUsingUrl(file);
|
this.setTitleUsingUrl(file);
|
||||||
parameters.url = file;
|
parameters.url = file;
|
||||||
@ -530,18 +576,20 @@ var PDFViewerApplication = {
|
|||||||
var self = this;
|
var self = this;
|
||||||
self.downloadComplete = false;
|
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.updatePassword = updatePassword;
|
||||||
PasswordPrompt.reason = reason;
|
PasswordPrompt.reason = reason;
|
||||||
PasswordPrompt.open();
|
PasswordPrompt.open();
|
||||||
};
|
};
|
||||||
|
|
||||||
function getDocumentProgress(progressData) {
|
loadingTask.onProgress = function getDocumentProgress(progressData) {
|
||||||
self.progress(progressData.loaded / progressData.total);
|
self.progress(progressData.loaded / progressData.total);
|
||||||
}
|
};
|
||||||
|
|
||||||
PDFJS.getDocument(parameters, pdfDataRangeTransport, passwordNeeded,
|
var result = loadingTask.promise.then(
|
||||||
getDocumentProgress).then(
|
|
||||||
function getDocumentCallback(pdfDocument) {
|
function getDocumentCallback(pdfDocument) {
|
||||||
self.load(pdfDocument, scale);
|
self.load(pdfDocument, scale);
|
||||||
},
|
},
|
||||||
@ -567,12 +615,15 @@ var PDFViewerApplication = {
|
|||||||
message: message
|
message: message
|
||||||
};
|
};
|
||||||
self.error(loadingErrorMessage, moreInfo);
|
self.error(loadingErrorMessage, moreInfo);
|
||||||
|
|
||||||
|
throw new Error(loadingErrorMessage);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
if (args && args.length) {
|
if (args && args.length) {
|
||||||
PDFViewerApplication.pdfDocumentProperties.setFileSize(args.length);
|
PDFViewerApplication.pdfDocumentProperties.setFileSize(args.length);
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
},
|
},
|
||||||
|
|
||||||
download: function pdfViewDownload() {
|
download: function pdfViewDownload() {
|
||||||
@ -999,6 +1050,9 @@ var PDFViewerApplication = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
cleanup: function pdfViewCleanup() {
|
cleanup: function pdfViewCleanup() {
|
||||||
|
if (!this.pdfDocument) {
|
||||||
|
return; // run cleanup when document is loaded
|
||||||
|
}
|
||||||
this.pdfViewer.cleanup();
|
this.pdfViewer.cleanup();
|
||||||
this.pdfThumbnailViewer.cleanup();
|
this.pdfThumbnailViewer.cleanup();
|
||||||
this.pdfDocument.cleanup();
|
this.pdfDocument.cleanup();
|
||||||
@ -1493,7 +1547,7 @@ function webViewerInitialized() {
|
|||||||
PDFViewerApplication.setTitleUsingUrl(file);
|
PDFViewerApplication.setTitleUsingUrl(file);
|
||||||
var xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest();
|
||||||
xhr.onload = function() {
|
xhr.onload = function() {
|
||||||
PDFViewerApplication.open(new Uint8Array(xhr.response), 0);
|
PDFViewerApplication.open(new Uint8Array(xhr.response));
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
xhr.open('GET', file);
|
xhr.open('GET', file);
|
||||||
@ -1507,7 +1561,7 @@ function webViewerInitialized() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (file) {
|
if (file) {
|
||||||
PDFViewerApplication.open(file, 0);
|
PDFViewerApplication.open(file);
|
||||||
}
|
}
|
||||||
//#endif
|
//#endif
|
||||||
//#if CHROME
|
//#if CHROME
|
||||||
@ -1722,14 +1776,14 @@ window.addEventListener('change', function webViewerChange(evt) {
|
|||||||
|
|
||||||
if (!PDFJS.disableCreateObjectURL &&
|
if (!PDFJS.disableCreateObjectURL &&
|
||||||
typeof URL !== 'undefined' && URL.createObjectURL) {
|
typeof URL !== 'undefined' && URL.createObjectURL) {
|
||||||
PDFViewerApplication.open(URL.createObjectURL(file), 0);
|
PDFViewerApplication.open(URL.createObjectURL(file));
|
||||||
} else {
|
} else {
|
||||||
// Read the local file into a Uint8Array.
|
// Read the local file into a Uint8Array.
|
||||||
var fileReader = new FileReader();
|
var fileReader = new FileReader();
|
||||||
fileReader.onload = function webViewerChangeFileReaderOnload(evt) {
|
fileReader.onload = function webViewerChangeFileReaderOnload(evt) {
|
||||||
var buffer = evt.target.result;
|
var buffer = evt.target.result;
|
||||||
var uint8Array = new Uint8Array(buffer);
|
var uint8Array = new Uint8Array(buffer);
|
||||||
PDFViewerApplication.open(uint8Array, 0);
|
PDFViewerApplication.open(uint8Array);
|
||||||
};
|
};
|
||||||
fileReader.readAsArrayBuffer(file);
|
fileReader.readAsArrayBuffer(file);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user