summaryrefslogtreecommitdiffstats
path: root/toolkit/components/formautofill/android/FormAutofillPrompter.jsm
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /toolkit/components/formautofill/android/FormAutofillPrompter.jsm
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/formautofill/android/FormAutofillPrompter.jsm')
-rw-r--r--toolkit/components/formautofill/android/FormAutofillPrompter.jsm75
1 files changed, 75 insertions, 0 deletions
diff --git a/toolkit/components/formautofill/android/FormAutofillPrompter.jsm b/toolkit/components/formautofill/android/FormAutofillPrompter.jsm
new file mode 100644
index 0000000000..f869ad851e
--- /dev/null
+++ b/toolkit/components/formautofill/android/FormAutofillPrompter.jsm
@@ -0,0 +1,75 @@
+/* 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/. */
+
+/*
+ * Implements doorhanger singleton that wraps up the PopupNotifications and handles
+ * the doorhager UI for formautofill related features.
+ */
+
+"use strict";
+
+var EXPORTED_SYMBOLS = ["FormAutofillPrompter"];
+
+const { XPCOMUtils } = ChromeUtils.importESModule(
+ "resource://gre/modules/XPCOMUtils.sys.mjs"
+);
+
+const lazy = {};
+
+ChromeUtils.defineESModuleGetters(lazy, {
+ GeckoViewPrompter: "resource://gre/modules/GeckoViewPrompter.sys.mjs",
+});
+
+XPCOMUtils.defineLazyModuleGetters(lazy, {
+ CreditCard: "resource://gre/modules/GeckoViewAutocomplete.jsm",
+ GeckoViewAutocomplete: "resource://gre/modules/GeckoViewAutocomplete.jsm",
+});
+
+// Sync with Autocomplete.SaveOption.Hint in Autocomplete.java
+const CreditCardStorageHint = {
+ NONE: 0,
+ GENERATED: 1 << 0,
+ LOW_CONFIDENCE: 1 << 1,
+};
+
+let FormAutofillPrompter = {
+ _createMessage(creditCards) {
+ let hint = CreditCardStorageHint.NONE;
+ return {
+ // Sync with PromptController
+ type: "Autocomplete:Save:CreditCard",
+ hint,
+ creditCards,
+ };
+ },
+
+ async promptToSaveAddress(browser, type, description) {
+ throw Components.Exception("", Cr.NS_ERROR_NOT_IMPLEMENTED);
+ },
+
+ async promptToSaveCreditCard(browser, creditCard, storage) {
+ const prompt = new lazy.GeckoViewPrompter(browser.ownerGlobal);
+
+ let newCreditCard;
+ if (creditCard.guid) {
+ let originalCCData = await storage.creditCards.get(creditCard.guid);
+ newCreditCard = { ...originalCCData, ...creditCard.record };
+ } else {
+ newCreditCard = creditCard.record;
+ }
+
+ prompt.asyncShowPrompt(
+ this._createMessage([lazy.CreditCard.fromGecko(newCreditCard)]),
+ result => {
+ const selectedCreditCard = result?.selection?.value;
+
+ if (!selectedCreditCard) {
+ return;
+ }
+
+ lazy.GeckoViewAutocomplete.onCreditCardSave(selectedCreditCard);
+ }
+ );
+ },
+};