diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:37 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:37 +0000 |
commit | a90a5cba08fdf6c0ceb95101c275108a152a3aed (patch) | |
tree | 532507288f3defd7f4dcf1af49698bcb76034855 /browser/components/backup/actors/BackupUIChild.sys.mjs | |
parent | Adding debian version 126.0.1-1. (diff) | |
download | firefox-a90a5cba08fdf6c0ceb95101c275108a152a3aed.tar.xz firefox-a90a5cba08fdf6c0ceb95101c275108a152a3aed.zip |
Merging upstream version 127.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/components/backup/actors/BackupUIChild.sys.mjs')
-rw-r--r-- | browser/components/backup/actors/BackupUIChild.sys.mjs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/browser/components/backup/actors/BackupUIChild.sys.mjs b/browser/components/backup/actors/BackupUIChild.sys.mjs new file mode 100644 index 0000000000..25d013fa8e --- /dev/null +++ b/browser/components/backup/actors/BackupUIChild.sys.mjs @@ -0,0 +1,54 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/** + * A JSWindowActor that is responsible for marshalling information between + * the BackupService singleton and any registered UI widgets that need to + * represent data from that service. Any UI widgets that want to receive + * state updates from BackupService should emit a BackupUI:InitWidget + * event in a document that this actor pair is registered for. + */ +export class BackupUIChild extends JSWindowActorChild { + #inittedWidgets = new WeakSet(); + + /** + * Handles BackupUI:InitWidget custom events fired by widgets that want to + * register with BackupUIChild. Firing this event sends a message to the + * parent to request the BackupService state which will result in a + * `backupServiceState` property of the widget to be set when that state is + * received. Subsequent state updates will also cause that state property to + * be set. + * + * @param {Event} event + * The BackupUI:InitWidget custom event that the widget fired. + */ + handleEvent(event) { + if (event.type == "BackupUI:InitWidget") { + this.#inittedWidgets.add(event.target); + this.sendAsyncMessage("RequestState"); + } + } + + /** + * Handles messages sent by BackupUIParent. + * + * @param {ReceiveMessageArgument} message + * The message received from the BackupUIParent. + */ + receiveMessage(message) { + if (message.name == "StateUpdate") { + let widgets = ChromeUtils.nondeterministicGetWeakSetKeys( + this.#inittedWidgets + ); + for (let widget of widgets) { + if (widget.isConnected) { + // Note: we might need to switch to using Cu.cloneInto here in the + // event that these widgets are embedded in a non-parent-process + // context, like in an onboarding card. + widget.backupServiceState = message.data.state; + } + } + } + } +} |