Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 78ff024

Browse files
committed
Bug 1948481 - Correctly set the observer used to be aware of the changes in the signature storage for PDF.js r=marco
Differential Revision: https://phabricator.services.mozilla.com/D238375
1 parent 5b303b6 commit 78ff024

2 files changed

Lines changed: 38 additions & 22 deletions

File tree

toolkit/components/pdfjs/content/PdfjsParent.sys.mjs

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ export class PdfjsParent extends JSWindowActorParent {
8484

8585
didDestroy() {
8686
this._removeEventListener();
87+
if (this.#signatureStorageChangedObserver) {
88+
Services.obs.removeObserver(
89+
this.#signatureStorageChangedObserver,
90+
PDFJS_SIGNATURE_STORAGE_CHANGED_TOPIC
91+
);
92+
this.#signatureStorageChangedObserver = null;
93+
}
8794
}
8895

8996
receiveMessage(aMsg) {
@@ -148,29 +155,27 @@ export class PdfjsParent extends JSWindowActorParent {
148155
async #getSignatures() {
149156
if (!this.#signatureStorageChangedObserver) {
150157
const self = this;
151-
this.#signatureStorageChangedObserver = Services.obs.addObserver(
152-
{
153-
observe(aSubject, aTopic) {
154-
if (
155-
aTopic === PDFJS_SIGNATURE_STORAGE_CHANGED_TOPIC &&
156-
// No need to send an event to the viewer which triggered the
157-
// change because it already knows about it.
158-
aSubject !== self &&
159-
!Cu.isInAutomation
160-
) {
161-
// The child will dispatch an event in the pdf.js window.
162-
// This way the viewer is able to update the UI (add/remove some
163-
// signatures).
164-
self.sendAsyncMessage("PDFJS:Child:handleEvent", {
165-
type: "storedSignaturesChanged",
166-
detail: null,
167-
});
168-
}
169-
},
170-
QueryInterface: ChromeUtils.generateQI([Ci.nsISupportsWeakReference]),
158+
this.#signatureStorageChangedObserver = {
159+
observe(aSubject, aTopic) {
160+
if (
161+
aTopic === PDFJS_SIGNATURE_STORAGE_CHANGED_TOPIC &&
162+
// No need to send an event to the viewer which triggered the
163+
// change because it already knows about it.
164+
(aSubject !== self || Cu.isInAutomation)
165+
) {
166+
// The child will dispatch an event in the pdf.js window.
167+
// This way the viewer is able to update the UI (add/remove some
168+
// signatures).
169+
self.sendAsyncMessage("PDFJS:Child:handleEvent", {
170+
type: "storedSignaturesChanged",
171+
detail: null,
172+
});
173+
}
171174
},
172-
PDFJS_SIGNATURE_STORAGE_CHANGED_TOPIC,
173-
true
175+
};
176+
Services.obs.addObserver(
177+
this.#signatureStorageChangedObserver,
178+
PDFJS_SIGNATURE_STORAGE_CHANGED_TOPIC
174179
);
175180
}
176181

toolkit/components/pdfjs/test/browser_pdfjs_signature_storage.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ add_task(async function test_js_signature_storage() {
1515
);
1616

1717
await SpecialPowers.spawn(browser, [], async () => {
18+
function getStoredSignaturesChangedPromise() {
19+
const { promise, resolve } = Promise.withResolvers();
20+
content.addEventListener("storedSignaturesChanged", resolve, {
21+
once: true,
22+
});
23+
return promise;
24+
}
1825
const HANDLE_SIGNATURE = "PDFJS:Parent:handleSignature";
1926

2027
const actor = content.windowGlobalChild.getActor("Pdfjs");
@@ -23,11 +30,13 @@ add_task(async function test_js_signature_storage() {
2330
});
2431
is(all.length, 0, "No signature should be present");
2532

33+
let promise = getStoredSignaturesChangedPromise();
2634
const uuid = await actor.sendQuery(HANDLE_SIGNATURE, {
2735
action: "create",
2836
description: "test",
2937
signatureData: "1234",
3038
});
39+
await promise;
3140

3241
all = await actor.sendQuery(HANDLE_SIGNATURE, {
3342
action: "get",
@@ -37,10 +46,12 @@ add_task(async function test_js_signature_storage() {
3746
is(all[0].description, "test", "Must have the correct description");
3847
is(all[0].signatureData, "1234", "Must have the correct signatureData");
3948

49+
promise = getStoredSignaturesChangedPromise();
4050
await actor.sendQuery(HANDLE_SIGNATURE, {
4151
action: "delete",
4252
uuid,
4353
});
54+
await promise;
4455

4556
all = await actor.sendQuery(HANDLE_SIGNATURE, {
4657
action: "get",

0 commit comments

Comments
 (0)