Skip to content

Commit

Permalink
Merge pull request #16768 from Snuffleupagus/pr-15335-followup
Browse files Browse the repository at this point in the history
Ensure that failing to open the password dialog once won't permanently disable it (PR 15335 follow-up)
  • Loading branch information
timvandermeij committed Jul 30, 2023
2 parents 7ae5a0f + 930cbc4 commit 1ef6fbc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
23 changes: 11 additions & 12 deletions src/display/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2367,6 +2367,8 @@ class WorkerTransport {

#pagePromises = new Map();

#passwordCapability = null;

constructor(messageHandler, loadingTask, networkStream, params, factory) {
this.messageHandler = messageHandler;
this.loadingTask = loadingTask;
Expand All @@ -2384,7 +2386,6 @@ class WorkerTransport {

this.destroyed = false;
this.destroyCapability = null;
this._passwordCapability = null;

this._networkStream = networkStream;
this._fullReader = null;
Expand Down Expand Up @@ -2495,11 +2496,9 @@ class WorkerTransport {
this.destroyed = true;
this.destroyCapability = new PromiseCapability();

if (this._passwordCapability) {
this._passwordCapability.reject(
new Error("Worker was destroyed during onPassword callback")
);
}
this.#passwordCapability?.reject(
new Error("Worker was destroyed during onPassword callback")
);

const waitOn = [];
// We need to wait for all renderings to be completed, e.g.
Expand Down Expand Up @@ -2702,27 +2701,27 @@ class WorkerTransport {
});

messageHandler.on("PasswordRequest", exception => {
this._passwordCapability = new PromiseCapability();
this.#passwordCapability = new PromiseCapability();

if (loadingTask.onPassword) {
const updatePassword = password => {
if (password instanceof Error) {
this._passwordCapability.reject(password);
this.#passwordCapability.reject(password);
} else {
this._passwordCapability.resolve({ password });
this.#passwordCapability.resolve({ password });
}
};
try {
loadingTask.onPassword(updatePassword, exception.code);
} catch (ex) {
this._passwordCapability.reject(ex);
this.#passwordCapability.reject(ex);
}
} else {
this._passwordCapability.reject(
this.#passwordCapability.reject(
new PasswordException(exception.message, exception.code)
);
}
return this._passwordCapability.promise;
return this.#passwordCapability.promise;
});

messageHandler.on("DataLoaded", data => {
Expand Down
2 changes: 1 addition & 1 deletion web/password_prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class PasswordPrompt {
try {
await this.overlayManager.open(this.dialog);
} catch (ex) {
this.#activeCapability = null;
this.#activeCapability.resolve();
throw ex;
}

Expand Down

0 comments on commit 1ef6fbc

Please sign in to comment.