From da4c7e7ed675c3bf405668739c3012d140856109 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 15 May 2024 05:34:42 +0200 Subject: Adding upstream version 126.0. Signed-off-by: Daniel Baumann --- toolkit/components/satchel/FillHelpers.sys.mjs | 48 ++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'toolkit/components/satchel/FillHelpers.sys.mjs') 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); +} -- cgit v1.2.3