Bug 1504268 - Show proper OS login dialog labels when filling/editing credit cards r=MattN
authorTimothy Guan-tin Chien <timdream@gmail.com>
Mon, 19 Nov 2018 21:00:02 +0000
changeset 503502 bc720a5a993c624de10dd325d69f71334d1670d6
parent 503501 853889cec3ab4718caf3d291bce3374f1f54ce96
child 503503 104d7f34de53a9359d6a1983b8d421a60a649592
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMattN
bugs1504268
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1504268 - Show proper OS login dialog labels when filling/editing credit cards r=MattN Differential Revision: https://phabricator.services.mozilla.com/D11095
browser/components/payments/content/paymentDialogWrapper.js
browser/extensions/formautofill/FormAutofillHandler.jsm
browser/extensions/formautofill/content/manageDialog.js
browser/extensions/formautofill/locales/en-US/formautofill.properties
--- a/browser/components/payments/content/paymentDialogWrapper.js
+++ b/browser/components/payments/content/paymentDialogWrapper.js
@@ -12,21 +12,24 @@
 "use strict";
 
 const paymentSrv = Cc["@mozilla.org/dom/payments/payment-request-service;1"]
                      .getService(Ci.nsIPaymentRequestService);
 
 const paymentUISrv = Cc["@mozilla.org/dom/payments/payment-ui-service;1"]
                      .getService(Ci.nsIPaymentUIService);
 
+ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 
 ChromeUtils.defineModuleGetter(this, "BrowserWindowTracker",
                                "resource:///modules/BrowserWindowTracker.jsm");
+ChromeUtils.defineModuleGetter(this, "FormAutofillUtils",
+                               "resource://formautofill/FormAutofillUtils.jsm");
 ChromeUtils.defineModuleGetter(this, "OSKeyStore",
                                "resource://formautofill/OSKeyStore.jsm");
 ChromeUtils.defineModuleGetter(this, "PrivateBrowsingUtils",
                                "resource://gre/modules/PrivateBrowsingUtils.jsm");
 
 XPCOMUtils.defineLazyGetter(this, "formAutofillStorage", () => {
   let storage;
   try {
@@ -36,16 +39,22 @@ XPCOMUtils.defineLazyGetter(this, "formA
   } catch (ex) {
     storage = null;
     Cu.reportError(ex);
   }
 
   return storage;
 });
 
+XPCOMUtils.defineLazyGetter(this, "reauthPasswordPromptMessage", () => {
+  const brandShortName = FormAutofillUtils.brandBundle.GetStringFromName("brandShortName");
+  return FormAutofillUtils.stringBundle.formatStringFromName(
+    `useCreditCardPasswordPrompt.${AppConstants.platform}`, [brandShortName], 1);
+});
+
 /**
  * Temporary/transient storage for address and credit card records
  *
  * Implements a subset of the FormAutofillStorage collection class interface, and delegates to
  * those classes for some utility methods
  */
 class TempCollection {
   constructor(type, data = {}) {
@@ -173,17 +182,18 @@ var paymentDialogWrapper = {
     let cardData = this.temporaryStore.creditCards.get(guid) ||
                    await formAutofillStorage.creditCards.get(guid);
     if (!cardData) {
       throw new Error(`Basic card not found in storage: ${guid}`);
     }
 
     let cardNumber;
     try {
-      cardNumber = await OSKeyStore.decrypt(cardData["cc-number-encrypted"], true);
+      cardNumber = await OSKeyStore.decrypt(
+        cardData["cc-number-encrypted"], reauthPasswordPromptMessage);
     } catch (ex) {
       if (ex.result != Cr.NS_ERROR_ABORT) {
         throw ex;
       }
       // User canceled master password entry
       return null;
     }
 
--- a/browser/extensions/formautofill/FormAutofillHandler.jsm
+++ b/browser/extensions/formautofill/FormAutofillHandler.jsm
@@ -5,27 +5,34 @@
 /*
  * Defines a handler object to represent forms that autofill can handle.
  */
 
 "use strict";
 
 var EXPORTED_SYMBOLS = ["FormAutofillHandler"];
 
+ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
 ChromeUtils.import("resource://gre/modules/Services.jsm");
-
+ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 ChromeUtils.import("resource://formautofill/FormAutofill.jsm");
 
 ChromeUtils.defineModuleGetter(this, "FormAutofillUtils",
                                "resource://formautofill/FormAutofillUtils.jsm");
 ChromeUtils.defineModuleGetter(this, "FormAutofillHeuristics",
                                "resource://formautofill/FormAutofillHeuristics.jsm");
 ChromeUtils.defineModuleGetter(this, "FormLikeFactory",
                                "resource://gre/modules/FormLikeFactory.jsm");
 
+XPCOMUtils.defineLazyGetter(this, "reauthPasswordPromptMessage", () => {
+  const brandShortName = FormAutofillUtils.brandBundle.GetStringFromName("brandShortName");
+  return FormAutofillUtils.stringBundle.formatStringFromName(
+    `useCreditCardPasswordPrompt.${AppConstants.platform}`, [brandShortName], 1);
+});
+
 this.log = null;
 FormAutofill.defineLazyLogGetter(this, EXPORTED_SYMBOLS[0]);
 
 const {FIELD_STATES} = FormAutofillUtils;
 
 class FormAutofillSection {
   constructor(fieldDetails, winUtils) {
     this.fieldDetails = fieldDetails;
@@ -862,22 +869,20 @@ class FormAutofillCreditCardSection exte
    * Customize for filling prorifle.
    *
    * @param {Object} profile
    *        A profile for pre-processing before filling values.
    * @returns {boolean} Whether the profile should be filled.
    * @override
    */
   async prepareFillingProfile(profile) {
-    // When Master Password is enabled by users, the decryption process
-    // should prompt Master Password dialog to get the decrypted credit
-    // card number. Otherwise, the number can be decrypted with the default
-    // password.
+    // Prompt the OS login dialog to get the decrypted credit
+    // card number.
     if (profile["cc-number-encrypted"]) {
-      let decrypted = await this._decrypt(profile["cc-number-encrypted"], true);
+      let decrypted = await this._decrypt(profile["cc-number-encrypted"], reauthPasswordPromptMessage);
 
       if (!decrypted) {
         // Early return if the decrypted is empty or undefined
         return false;
       }
 
       profile["cc-number"] = decrypted;
     }
--- a/browser/extensions/formautofill/content/manageDialog.js
+++ b/browser/extensions/formautofill/content/manageDialog.js
@@ -4,29 +4,36 @@
 
 /* exported ManageAddresses, ManageCreditCards */
 
 "use strict";
 
 const EDIT_ADDRESS_URL = "chrome://formautofill/content/editAddress.xhtml";
 const EDIT_CREDIT_CARD_URL = "chrome://formautofill/content/editCreditCard.xhtml";
 
+ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
 ChromeUtils.import("resource://gre/modules/Services.jsm");
+ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 ChromeUtils.import("resource://formautofill/FormAutofill.jsm");
-ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
 
 ChromeUtils.defineModuleGetter(this, "CreditCard",
                                "resource://gre/modules/CreditCard.jsm");
 ChromeUtils.defineModuleGetter(this, "formAutofillStorage",
                                "resource://formautofill/FormAutofillStorage.jsm");
 ChromeUtils.defineModuleGetter(this, "FormAutofillUtils",
                                "resource://formautofill/FormAutofillUtils.jsm");
 ChromeUtils.defineModuleGetter(this, "OSKeyStore",
                                "resource://formautofill/OSKeyStore.jsm");
 
+XPCOMUtils.defineLazyGetter(this, "reauthPasswordPromptMessage", () => {
+  const brandShortName = FormAutofillUtils.brandBundle.GetStringFromName("brandShortName");
+  return FormAutofillUtils.stringBundle.formatStringFromName(
+    `editCreditCardPasswordPrompt.${AppConstants.platform}`, [brandShortName], 1);
+});
+
 this.log = null;
 FormAutofill.defineLazyLogGetter(this, "manageAddresses");
 
 class ManageRecords {
   constructor(subStorageName, elements) {
     this._storageInitPromise = formAutofillStorage.initialize();
     this._subStorageName = subStorageName;
     this._elements = elements;
@@ -322,17 +329,17 @@ class ManageCreditCards extends ManageRe
 
   /**
    * Open the edit address dialog to create/edit a credit card.
    *
    * @param  {object} creditCard [optional]
    */
   async openEditDialog(creditCard) {
     // Ask for reauth if user is trying to edit an existing credit card.
-    if (!creditCard || await OSKeyStore.ensureLoggedIn(true)) {
+    if (!creditCard || await OSKeyStore.ensureLoggedIn(reauthPasswordPromptMessage)) {
       let decryptedCCNumObj = {};
       if (creditCard && creditCard["cc-number-encrypted"]) {
         try {
           decryptedCCNumObj["cc-number"] = await OSKeyStore.decrypt(creditCard["cc-number-encrypted"]);
         } catch (ex) {
           if (ex.result == Cr.NS_ERROR_ABORT) {
             // User shouldn't be ask to reauth here, but it could happen.
             // Return here and skip opening the dialog.
--- a/browser/extensions/formautofill/locales/en-US/formautofill.properties
+++ b/browser/extensions/formautofill/locales/en-US/formautofill.properties
@@ -194,8 +194,16 @@ cardNetwork.amex = American Express
 cardNetwork.cartebancaire = Carte Bancaire
 cardNetwork.diners = Diners Club
 cardNetwork.discover = Discover
 cardNetwork.jcb = JCB
 cardNetwork.mastercard = MasterCard
 cardNetwork.mir = MIR
 cardNetwork.unionpay = Union Pay
 cardNetwork.visa = Visa
+
+# LOCALIZATION NOTE (editCreditCardPasswordPrompt.*, useCreditCardPasswordPrompt.*): %S is brandShortName.
+editCreditCardPasswordPrompt.win = %S is trying to show credit card information. Confirm access to this Windows account below.
+editCreditCardPasswordPrompt.macosx = %S is trying to show credit card information.
+editCreditCardPasswordPrompt.linux = %S is trying to show credit card information.
+useCreditCardPasswordPrompt.win = %S is trying to use stored credit card information. Confirm access to this Windows account below.
+useCreditCardPasswordPrompt.macosx = %S is trying to use stored credit card information.
+useCreditCardPasswordPrompt.linux = %S is trying to use stored credit card information.