mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-09 09:45:42 +02:00
[api-minor] Ensure that the getDocument
Promise is rejected if the loadingTask
is destroyed, or an Error
is thrown, inside of the onPassword
callback (issue 7806)
This patch also removes the `UpdatePassword` message, in favour of using the `sendWithPromise` method of `MessageHandler`. Furthermore, the patch also refactors the `BasePdfManager_updatePassword`/`BasePdfManager_passwordChanged` methods (in pdf_manager.js), and the `pdfManagerReady` function (in worker.js).
This commit is contained in:
parent
59afb4b9f0
commit
27513cd23b
4 changed files with 112 additions and 71 deletions
|
@ -1419,6 +1419,7 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|||
|
||||
this.destroyed = false;
|
||||
this.destroyCapability = null;
|
||||
this._passwordCapability = null;
|
||||
|
||||
this.pageCache = [];
|
||||
this.pagePromises = [];
|
||||
|
@ -1435,6 +1436,11 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|||
this.destroyed = true;
|
||||
this.destroyCapability = createPromiseCapability();
|
||||
|
||||
if (this._passwordCapability) {
|
||||
this._passwordCapability.reject(
|
||||
new Error('Worker was destroyed during onPassword callback'));
|
||||
}
|
||||
|
||||
var waitOn = [];
|
||||
// We need to wait for all renderings to be completed, e.g.
|
||||
// timeout/rAF can take a long time.
|
||||
|
@ -1464,13 +1470,9 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|||
return this.destroyCapability.promise;
|
||||
},
|
||||
|
||||
setupMessageHandler:
|
||||
function WorkerTransport_setupMessageHandler() {
|
||||
setupMessageHandler: function WorkerTransport_setupMessageHandler() {
|
||||
var messageHandler = this.messageHandler;
|
||||
|
||||
function updatePassword(password) {
|
||||
messageHandler.send('UpdatePassword', password);
|
||||
}
|
||||
var loadingTask = this.loadingTask;
|
||||
|
||||
var pdfDataRangeTransport = this.pdfDataRangeTransport;
|
||||
if (pdfDataRangeTransport) {
|
||||
|
@ -1508,24 +1510,27 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|||
loadingTask._capability.resolve(pdfDocument);
|
||||
}, this);
|
||||
|
||||
messageHandler.on('NeedPassword',
|
||||
function transportNeedPassword(exception) {
|
||||
var loadingTask = this.loadingTask;
|
||||
messageHandler.on('PasswordRequest',
|
||||
function transportPasswordRequest(exception) {
|
||||
this._passwordCapability = createPromiseCapability();
|
||||
|
||||
if (loadingTask.onPassword) {
|
||||
return loadingTask.onPassword(updatePassword,
|
||||
PasswordResponses.NEED_PASSWORD);
|
||||
var updatePassword = function (password) {
|
||||
this._passwordCapability.resolve({
|
||||
password: password,
|
||||
});
|
||||
}.bind(this);
|
||||
|
||||
loadingTask.onPassword(updatePassword, exception.code);
|
||||
} else {
|
||||
this._passwordCapability.reject(
|
||||
new PasswordException(exception.message, exception.code));
|
||||
}
|
||||
loadingTask._capability.reject(
|
||||
new PasswordException(exception.message, exception.code));
|
||||
return this._passwordCapability.promise;
|
||||
}, this);
|
||||
|
||||
messageHandler.on('IncorrectPassword',
|
||||
function transportIncorrectPassword(exception) {
|
||||
var loadingTask = this.loadingTask;
|
||||
if (loadingTask.onPassword) {
|
||||
return loadingTask.onPassword(updatePassword,
|
||||
PasswordResponses.INCORRECT_PASSWORD);
|
||||
}
|
||||
messageHandler.on('PasswordException',
|
||||
function transportPasswordException(exception) {
|
||||
loadingTask._capability.reject(
|
||||
new PasswordException(exception.message, exception.code));
|
||||
}, this);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue