summaryrefslogtreecommitdiffstats
path: root/toolkit/components/satchel/FillHelpers.sys.mjs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:34:42 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:34:42 +0000
commitda4c7e7ed675c3bf405668739c3012d140856109 (patch)
treecdd868dba063fecba609a1d819de271f0d51b23e /toolkit/components/satchel/FillHelpers.sys.mjs
parentAdding upstream version 125.0.3. (diff)
downloadfirefox-da4c7e7ed675c3bf405668739c3012d140856109.tar.xz
firefox-da4c7e7ed675c3bf405668739c3012d140856109.zip
Adding upstream version 126.0.upstream/126.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/satchel/FillHelpers.sys.mjs')
-rw-r--r--toolkit/components/satchel/FillHelpers.sys.mjs48
1 files changed, 48 insertions, 0 deletions
diff --git a/toolkit/components/satchel/FillHelpers.sys.mjs b/toolkit/components/satchel/FillHelpers.sys.mjs
index 88a248adba..fd335f271e 100644
--- a/toolkit/components/satchel/FillHelpers.sys.mjs
+++ b/toolkit/components/satchel/FillHelpers.sys.mjs
@@ -39,3 +39,51 @@ export function showConfirmation(
const anchor = browser.ownerDocument.getElementById(anchorId);
anchor.ownerGlobal.ConfirmationHint.show(anchor, messageId, {});
}
+
+let fillRequestId = 0;
+
+/**
+ * Send a message encoded in the comment from an autocomplete item
+ * to the parent.
+ *
+ * @param {string} actorName name of the actor to send to
+ * @param {object} autocompleteInput current nsIAutoCompleteInput
+ * @param {string} comment serialized JSON comment containing fillMessageName and
+ * fillMessageData to send to the actor
+ */
+export async function sendFillRequestToParent(
+ actorName,
+ autocompleteInput,
+ comment
+) {
+ if (!comment) {
+ return;
+ }
+
+ const { fillMessageName, fillMessageData } = JSON.parse(comment);
+ if (!fillMessageName) {
+ return;
+ }
+
+ fillRequestId++;
+ const currentFillRequestId = fillRequestId;
+ const actor =
+ autocompleteInput.focusedInput.ownerGlobal?.windowGlobalChild?.getActor(
+ actorName
+ );
+ const value = await actor.sendQuery(fillMessageName, fillMessageData ?? {});
+
+ // skip fill if another fill operation started during await
+ if (currentFillRequestId != fillRequestId) {
+ return;
+ }
+
+ if (typeof value !== "string") {
+ return;
+ }
+
+ // If the parent returned a string to fill, we must do it here because
+ // nsAutoCompleteController.cpp already finished it's work before we finished await.
+ autocompleteInput.textValue = value;
+ autocompleteInput.selectTextRange(value.length, value.length);
+}