Merge pull request #15335 from Snuffleupagus/PasswordPrompt-activeCapability

Ensure that we don't try to re-open, or update the password-callback, when the password dialog is already open
This commit is contained in:
Tim van der Meij 2022-08-21 12:52:34 +02:00 committed by GitHub
commit 14e8167df9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,7 +13,7 @@
* limitations under the License.
*/
import { PasswordResponses } from "pdfjs-lib";
import { createPromiseCapability, PasswordResponses } from "pdfjs-lib";
/**
* @typedef {Object} PasswordPromptOptions
@ -28,6 +28,8 @@ import { PasswordResponses } from "pdfjs-lib";
*/
class PasswordPrompt {
#activeCapability = null;
#updateCallback = null;
#reason = null;
@ -64,7 +66,17 @@ class PasswordPrompt {
}
async open() {
await this.overlayManager.open(this.dialog);
if (this.#activeCapability) {
await this.#activeCapability.promise;
}
this.#activeCapability = createPromiseCapability();
try {
await this.overlayManager.open(this.dialog);
} catch (ex) {
this.#activeCapability = null;
throw ex;
}
const passwordIncorrect =
this.#reason === PasswordResponses.INCORRECT_PASSWORD;
@ -92,6 +104,7 @@ class PasswordPrompt {
#cancel() {
this.#invokeCallback(new Error("PasswordPrompt cancelled."));
this.#activeCapability.resolve();
}
#invokeCallback(password) {
@ -105,7 +118,10 @@ class PasswordPrompt {
this.#updateCallback = null;
}
setUpdateCallback(updateCallback, reason) {
async setUpdateCallback(updateCallback, reason) {
if (this.#activeCapability) {
await this.#activeCapability.promise;
}
this.#updateCallback = updateCallback;
this.#reason = reason;
}