Skip to content

Commit

Permalink
Bug 1868967 - Update strings of os prompt dialog before showing payme…
Browse files Browse the repository at this point in the history
…nt method r=credential-management-reviewers,fluent-reviewers,bolsson,issammani

Depends on D195659

Differential Revision: https://phabricator.services.mozilla.com/D195857
  • Loading branch information
1rneh committed Dec 14, 2023
1 parent 857d15c commit 2f4d810
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ var gExceptionPaths = [
// Exclude the form autofill path that has been moved out of the extensions to
// toolkit, see bug 1691821.
"resource://gre-resources/autofill/",
// Localization file added programatically in FormAutofillSection.sys.mjs
// Localization file added programatically in FormAutofillUtils.sys.mjs
"resource://gre/localization/en-US/toolkit/formautofill",

// Exclude all search-extensions because they aren't referenced by filename
Expand Down
22 changes: 6 additions & 16 deletions browser/extensions/formautofill/content/manageDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,6 @@ ChromeUtils.defineESModuleGetters(this, {
formAutofillStorage: "resource://autofill/FormAutofillStorage.sys.mjs",
});

const lazy = {};
ChromeUtils.defineLazyGetter(
lazy,
"l10n",
() =>
new Localization([
"browser/preferences/formAutofill.ftl",
"branding/brand.ftl",
])
);

this.log = null;
ChromeUtils.defineLazyGetter(this, "log", () =>
FormAutofill.defineLogGetter(this, "manageAddresses")
Expand Down Expand Up @@ -363,12 +352,13 @@ class ManageCreditCards extends ManageRecords {
async openEditDialog(creditCard) {
// Ask for reauth if user is trying to edit an existing credit card.
if (creditCard) {
const reauthPasswordPromptMessage = await lazy.l10n.formatValue(
"autofill-edit-card-password-prompt"
);
const loggedIn = await FormAutofillUtils.ensureLoggedIn(
reauthPasswordPromptMessage
const promptMessage = FormAutofillUtils.reauthOSPromptMessage(
"autofill-edit-payment-method-os-prompt-macos",
"autofill-edit-payment-method-os-prompt-windows",
"autofill-edit-payment-method-os-prompt-other"
);

const loggedIn = await FormAutofillUtils.ensureLoggedIn(promptMessage);
if (!loggedIn.authenticated) {
return;
}
Expand Down
8 changes: 0 additions & 8 deletions browser/locales/en-US/browser/preferences/formAutofill.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,6 @@ autofill-add-card-title = Add card
# The dialog title for editing credit cards in browser preferences.
autofill-edit-card-title2 = Edit card
# In macOS, this string is preceded by the operating system with "Firefox is trying to ",
# and has a period added to its end. Make sure to test in your locale.
autofill-edit-card-password-prompt = { PLATFORM() ->
[macos] show credit card information
[windows] { -brand-short-name } is trying to show credit card information. Confirm access to this Windows account below.
*[other] { -brand-short-name } is trying to show credit card information.
}
autofill-card-number = Card Number
autofill-card-invalid-number = Please enter a valid card number
autofill-card-name-on-card = Name on Card
Expand Down
36 changes: 6 additions & 30 deletions toolkit/components/formautofill/shared/FormAutofillSection.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* 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 { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs";
import { FormAutofillUtils } from "resource://gre/modules/shared/FormAutofillUtils.sys.mjs";
import { FormAutofill } from "resource://autofill/FormAutofill.sys.mjs";

Expand All @@ -15,16 +14,6 @@ ChromeUtils.defineESModuleGetters(lazy, {
LabelUtils: "resource://gre/modules/shared/LabelUtils.sys.mjs",
});

ChromeUtils.defineLazyGetter(
lazy,
"l10n",
() =>
new Localization(
["toolkit/formautofill/formautofill.ftl", "branding/brand.ftl"],
true
)
);

const { FIELD_STATES } = FormAutofillUtils;

export class FormAutofillSection {
Expand All @@ -43,24 +32,6 @@ export class FormAutofillSection {
this.handler = handler;
this.filledRecordGUID = null;

ChromeUtils.defineLazyGetter(this, "reauthPasswordPromptMessage", () => {
// The string name for Mac is changed because the value needed updating.
const platform = AppConstants.platform;
let messageID;

switch (platform) {
case "win":
messageID = "autofill-use-payment-method-os-prompt-windows";
break;
case "macosx":
messageID = "autofill-use-payment-method-os-prompt-macos";
break;
default:
messageID = "autofill-use-payment-method-os-prompt-other";
}
return lazy.l10n.formatValueSync(messageID);
});

ChromeUtils.defineLazyGetter(this, "log", () =>
FormAutofill.defineLogGetter(this, "FormAutofillHandler")
);
Expand Down Expand Up @@ -1295,9 +1266,14 @@ export class FormAutofillCreditCardSection extends FormAutofillSection {
async prepareFillingProfile(profile) {
// Prompt the OS login dialog to get the decrypted credit card number.
if (profile["cc-number-encrypted"]) {
const promptMessage = FormAutofillUtils.reauthOSPromptMessage(
"autofill-use-payment-method-os-prompt-macos",
"autofill-use-payment-method-os-prompt-windows",
"autofill-use-payment-method-os-prompt-other"
);
let decrypted = await this._decrypt(
profile["cc-number-encrypted"],
this.reauthPasswordPromptMessage
promptMessage
);

if (!decrypted) {
Expand Down
39 changes: 39 additions & 0 deletions toolkit/components/formautofill/shared/FormAutofillUtils.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import { FormAutofill } from "resource://autofill/FormAutofill.sys.mjs";
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs";

const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
Expand All @@ -12,6 +13,15 @@ ChromeUtils.defineESModuleGetters(lazy, {
"resource://gre/modules/shared/FormAutofillNameUtils.sys.mjs",
OSKeyStore: "resource://gre/modules/OSKeyStore.sys.mjs",
});
ChromeUtils.defineLazyGetter(
lazy,
"l10n",
() =>
new Localization(
["toolkit/formautofill/formautofill.ftl", "branding/brand.ftl"],
true
)
);

export let FormAutofillUtils;

Expand Down Expand Up @@ -1187,6 +1197,35 @@ FormAutofillUtils = {
};
return MAP[key];
},
/**
* Generates the localized os dialog message that
* prompts the user to reauthenticate
*
* @param {string} msgMac fluent message id for macos clients
* @param {string} msgWin fluent message id for windows clients
* @param {string} msgOther fluent message id for other clients
* @param {string} msgLin (optional) fluent message id for linux clients
* @returns {string} localized os prompt message
*/
reauthOSPromptMessage(msgMac, msgWin, msgOther, msgLin = null) {
const platform = AppConstants.platform;
let messageID;

switch (platform) {
case "win":
messageID = msgWin;
break;
case "macosx":
messageID = msgMac;
break;
case "linux":
messageID = msgLin ?? msgOther;
break;
default:
messageID = msgOther;
}
return lazy.l10n.formatValueSync(messageID);
},
};

ChromeUtils.defineLazyGetter(FormAutofillUtils, "stringBundle", function () {
Expand Down
7 changes: 7 additions & 0 deletions toolkit/locales/en-US/toolkit/formautofill/formautofill.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,10 @@
autofill-use-payment-method-os-prompt-macos = use stored payment method information
autofill-use-payment-method-os-prompt-windows = { -brand-short-name } is trying to use stored payment method information. Confirm access to this Windows account below.
autofill-use-payment-method-os-prompt-other = { -brand-short-name } is trying to use stored payment method information.
# In macOS, this string is preceded by the operating system with "Firefox is trying to ",
# and has a period added to its end. Make sure to test in your locale.
autofill-edit-payment-method-os-prompt-macos = show stored payment method information
autofill-edit-payment-method-os-prompt-windows = { -brand-short-name } is trying to show stored payment method information. Confirm access to this Windows account below.
autofill-edit-payment-method-os-prompt-other = { -brand-short-name } is trying to show stored payment method information.

0 comments on commit 2f4d810

Please sign in to comment.