1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | "use strict";
|
23 |
|
24 | Object.defineProperty(exports, "__esModule", {
|
25 | value: true
|
26 | });
|
27 | exports.PasswordPrompt = void 0;
|
28 |
|
29 | var _pdf = require("../pdf");
|
30 |
|
31 | class PasswordPrompt {
|
32 | #updateCallback = null;
|
33 | #reason = null;
|
34 |
|
35 | constructor(options, overlayManager, l10n, isViewerEmbedded = false) {
|
36 | this.dialog = options.dialog;
|
37 | this.label = options.label;
|
38 | this.input = options.input;
|
39 | this.submitButton = options.submitButton;
|
40 | this.cancelButton = options.cancelButton;
|
41 | this.overlayManager = overlayManager;
|
42 | this.l10n = l10n;
|
43 | this._isViewerEmbedded = isViewerEmbedded;
|
44 | this.submitButton.addEventListener("click", this.#verify.bind(this));
|
45 | this.cancelButton.addEventListener("click", this.#cancel.bind(this));
|
46 | this.input.addEventListener("keydown", e => {
|
47 | if (e.keyCode === 13) {
|
48 | this.#verify();
|
49 | }
|
50 | });
|
51 | this.overlayManager.register(this.dialog, true);
|
52 | this.dialog.addEventListener("close", this.#cancel.bind(this));
|
53 | }
|
54 |
|
55 | async open() {
|
56 | await this.overlayManager.open(this.dialog);
|
57 | const passwordIncorrect = this.#reason === _pdf.PasswordResponses.INCORRECT_PASSWORD;
|
58 |
|
59 | if (!this._isViewerEmbedded || passwordIncorrect) {
|
60 | this.input.focus();
|
61 | }
|
62 |
|
63 | this.label.textContent = await this.l10n.get(`password_${passwordIncorrect ? "invalid" : "label"}`);
|
64 | }
|
65 |
|
66 | async close() {
|
67 | if (this.overlayManager.active === this.dialog) {
|
68 | this.overlayManager.close(this.dialog);
|
69 | }
|
70 | }
|
71 |
|
72 | #verify() {
|
73 | const password = this.input.value;
|
74 |
|
75 | if (password?.length > 0) {
|
76 | this.#invokeCallback(password);
|
77 | }
|
78 | }
|
79 |
|
80 | #cancel() {
|
81 | this.#invokeCallback(new Error("PasswordPrompt cancelled."));
|
82 | }
|
83 |
|
84 | #invokeCallback(password) {
|
85 | if (!this.#updateCallback) {
|
86 | return;
|
87 | }
|
88 |
|
89 | this.close();
|
90 | this.input.value = "";
|
91 | this.#updateCallback(password);
|
92 | this.#updateCallback = null;
|
93 | }
|
94 |
|
95 | setUpdateCallback(updateCallback, reason) {
|
96 | this.#updateCallback = updateCallback;
|
97 | this.#reason = reason;
|
98 | }
|
99 |
|
100 | }
|
101 |
|
102 | exports.PasswordPrompt = PasswordPrompt; |
\ | No newline at end of file |