diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:44:51 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:44:51 +0000 |
commit | 9e3c08db40b8916968b9f30096c7be3f00ce9647 (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /mobile/android/modules/geckoview/GeckoViewAutofill.sys.mjs | |
parent | Initial commit. (diff) | |
download | thunderbird-9e3c08db40b8916968b9f30096c7be3f00ce9647.tar.xz thunderbird-9e3c08db40b8916968b9f30096c7be3f00ce9647.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'mobile/android/modules/geckoview/GeckoViewAutofill.sys.mjs')
-rw-r--r-- | mobile/android/modules/geckoview/GeckoViewAutofill.sys.mjs | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/mobile/android/modules/geckoview/GeckoViewAutofill.sys.mjs b/mobile/android/modules/geckoview/GeckoViewAutofill.sys.mjs new file mode 100644 index 0000000000..1249685aaa --- /dev/null +++ b/mobile/android/modules/geckoview/GeckoViewAutofill.sys.mjs @@ -0,0 +1,96 @@ +/* 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/. */ + +import { GeckoViewUtils } from "resource://gre/modules/GeckoViewUtils.sys.mjs"; + +class Autofill { + constructor(sessionId, eventDispatcher) { + this.eventDispatcher = eventDispatcher; + this.sessionId = sessionId; + } + + start() { + this.eventDispatcher.sendRequest({ + type: "GeckoView:StartAutofill", + sessionId: this.sessionId, + }); + } + + add(node) { + return this.eventDispatcher.sendRequestForResult({ + type: "GeckoView:AddAutofill", + node, + }); + } + + focus(node) { + this.eventDispatcher.sendRequest({ + type: "GeckoView:OnAutofillFocus", + node, + }); + } + + update(node) { + this.eventDispatcher.sendRequest({ + type: "GeckoView:UpdateAutofill", + node, + }); + } + + commit(node) { + this.eventDispatcher.sendRequest({ + type: "GeckoView:CommitAutofill", + node, + }); + } + + clear() { + this.eventDispatcher.sendRequest({ + type: "GeckoView:ClearAutofill", + }); + } +} + +class AutofillManager { + sessions = new Set(); + autofill = null; + + ensure(sessionId, eventDispatcher) { + if (!this.sessions.has(sessionId)) { + this.autofill = new Autofill(sessionId, eventDispatcher); + this.sessions.add(sessionId); + this.autofill.start(); + } + // This could be called for an outdated session, in which case we will just + // ignore the autofill call. + if (sessionId !== this.autofill.sessionId) { + return null; + } + return this.autofill; + } + + get(sessionId) { + if (!this.autofill || sessionId !== this.autofill.sessionId) { + warn`Disregarding old session ${sessionId}`; + // We disregard old sessions + return null; + } + return this.autofill; + } + + delete(sessionId) { + this.sessions.delete(sessionId); + if (!this.autofill || sessionId !== this.autofill.sessionId) { + // this delete call might happen *after* the next session already + // started, in that case, we can safely ignore this call. + return; + } + this.autofill.clear(); + this.autofill = null; + } +} + +export var gAutofillManager = new AutofillManager(); + +const { debug, warn } = GeckoViewUtils.initLogging("Autofill"); |