Commit 0fe86d0b authored by Demetrios Papadopoulos's avatar Demetrios Papadopoulos Committed by Commit Bot

Settings: Move PaymentsManager and AutofillManager under a namespace.

Previously these were defined at the global scope, which does not play well with
the tools used for migrating to Polymer3. It also pollutes the global namespace.

Bug: 1026426
Change-Id: I8e99c6f83e78a8ac8e1a4073102f60abe70c6448
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2002002
Auto-Submit: Demetrios Papadopoulos <dpapad@chromium.org>
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Reviewed-by: default avatarRebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#732215}
parent 13fdde75
......@@ -7,248 +7,252 @@
* addresses for use in autofill and payments APIs.
*/
/**
* Interface for all callbacks to the autofill API.
* @interface
*/
class AutofillManager {
/**
* Add an observer to the list of personal data.
* @param {function(!Array<!AutofillManager.AddressEntry>,
* !Array<!PaymentsManager.CreditCardEntry>):void} listener
*/
setPersonalDataManagerListener(listener) {}
cr.define('settings', function() {
/**
* Remove an observer from the list of personal data.
* @param {function(!Array<!AutofillManager.AddressEntry>,
* !Array<!PaymentsManager.CreditCardEntry>):void} listener
* Interface for all callbacks to the autofill API.
* @interface
*/
removePersonalDataManagerListener(listener) {}
/**
* Request the list of addresses.
* @param {function(!Array<!AutofillManager.AddressEntry>):void} callback
*/
getAddressList(callback) {}
class AutofillManager {
/**
* Add an observer to the list of personal data.
* @param {function(!Array<!settings.AutofillManager.AddressEntry>,
* !Array<!settings.PaymentsManager.CreditCardEntry>):void} listener
*/
setPersonalDataManagerListener(listener) {}
/**
* Saves the given address.
* @param {!AutofillManager.AddressEntry} address
*/
saveAddress(address) {}
/**
* Remove an observer from the list of personal data.
* @param {function(!Array<!settings.AutofillManager.AddressEntry>,
* !Array<!settings.PaymentsManager.CreditCardEntry>):void} listener
*/
removePersonalDataManagerListener(listener) {}
/** @param {string} guid The guid of the address to remove. */
removeAddress(guid) {}
}
/**
* Request the list of addresses.
* @param {function(!Array<!settings.AutofillManager.AddressEntry>):void}
* callback
*/
getAddressList(callback) {}
/** @typedef {chrome.autofillPrivate.AddressEntry} */
AutofillManager.AddressEntry;
/**
* Saves the given address.
* @param {!settings.AutofillManager.AddressEntry} address
*/
saveAddress(address) {}
/**
* Implementation that accesses the private API.
* @implements {AutofillManager}
*/
class AutofillManagerImpl {
/** @override */
setPersonalDataManagerListener(listener) {
chrome.autofillPrivate.onPersonalDataChanged.addListener(listener);
/** @param {string} guid The guid of the address to remove. */
removeAddress(guid) {}
}
/** @override */
removePersonalDataManagerListener(listener) {
chrome.autofillPrivate.onPersonalDataChanged.removeListener(listener);
}
/** @typedef {chrome.autofillPrivate.AddressEntry} */
AutofillManager.AddressEntry;
/** @override */
getAddressList(callback) {
chrome.autofillPrivate.getAddressList(callback);
/**
* Implementation that accesses the private API.
* @implements {settings.AutofillManager}
*/
class AutofillManagerImpl {
/** @override */
setPersonalDataManagerListener(listener) {
chrome.autofillPrivate.onPersonalDataChanged.addListener(listener);
}
/** @override */
removePersonalDataManagerListener(listener) {
chrome.autofillPrivate.onPersonalDataChanged.removeListener(listener);
}
/** @override */
getAddressList(callback) {
chrome.autofillPrivate.getAddressList(callback);
}
/** @override */
saveAddress(address) {
chrome.autofillPrivate.saveAddress(address);
}
/** @override */
removeAddress(guid) {
chrome.autofillPrivate.removeEntry(assert(guid));
}
}
/** @override */
saveAddress(address) {
chrome.autofillPrivate.saveAddress(address);
}
cr.addSingletonGetter(AutofillManagerImpl);
/** @override */
removeAddress(guid) {
chrome.autofillPrivate.removeEntry(assert(guid));
}
}
Polymer({
is: 'settings-autofill-section',
cr.addSingletonGetter(AutofillManagerImpl);
properties: {
/**
* An array of saved addresses.
* @type {!Array<!settings.AutofillManager.AddressEntry>}
*/
addresses: Array,
(function() {
'use strict';
/**
* The model for any address related action menus or dialogs.
* @private {?chrome.autofillPrivate.AddressEntry}
*/
activeAddress: Object,
Polymer({
is: 'settings-autofill-section',
/** @private */
showAddressDialog_: Boolean,
},
listeners: {
'save-address': 'saveAddress_',
},
properties: {
/**
* An array of saved addresses.
* @type {!Array<!AutofillManager.AddressEntry>}
* The element to return focus to, when the currently active dialog is
* closed.
* @private {?HTMLElement}
*/
addresses: Array,
activeDialogAnchor_: null,
/**
* The model for any address related action menus or dialogs.
* @private {?chrome.autofillPrivate.AddressEntry}
* @type {settings.AutofillManager}
* @private
*/
activeAddress: Object,
/** @private */
showAddressDialog_: Boolean,
},
listeners: {
'save-address': 'saveAddress_',
},
/**
* The element to return focus to, when the currently active dialog is
* closed.
* @private {?HTMLElement}
*/
activeDialogAnchor_: null,
/**
* @type {AutofillManager}
* @private
*/
autofillManager_: null,
/**
* @type {?function(!Array<!AutofillManager.AddressEntry>,
* !Array<!PaymentsManager.CreditCardEntry>)}
* @private
*/
setPersonalDataListener_: null,
/** @override */
attached() {
// Create listener functions.
/** @type {function(!Array<!AutofillManager.AddressEntry>)} */
const setAddressesListener = addressList => {
this.addresses = addressList;
};
autofillManager_: null,
/**
* @type {function(!Array<!AutofillManager.AddressEntry>,
* !Array<!PaymentsManager.CreditCardEntry>)}
* @type {?function(!Array<!settings.AutofillManager.AddressEntry>,
* !Array<!settings.PaymentsManager.CreditCardEntry>)}
* @private
*/
const setPersonalDataListener = (addressList, cardList) => {
this.addresses = addressList;
};
// Remember the bound reference in order to detach.
this.setPersonalDataListener_ = setPersonalDataListener;
// Set the managers. These can be overridden by tests.
this.autofillManager_ = AutofillManagerImpl.getInstance();
// Request initial data.
this.autofillManager_.getAddressList(setAddressesListener);
// Listen for changes.
this.autofillManager_.setPersonalDataManagerListener(
setPersonalDataListener);
// Record that the user opened the address settings.
chrome.metricsPrivate.recordUserAction('AutofillAddressesViewed');
},
setPersonalDataListener_: null,
/** @override */
attached() {
// Create listener functions.
/** @type {function(!Array<!settings.AutofillManager.AddressEntry>)} */
const setAddressesListener = addressList => {
this.addresses = addressList;
};
/**
* @type {function(!Array<!settings.AutofillManager.AddressEntry>,
* !Array<!settings.PaymentsManager.CreditCardEntry>)}
*/
const setPersonalDataListener = (addressList, cardList) => {
this.addresses = addressList;
};
// Remember the bound reference in order to detach.
this.setPersonalDataListener_ = setPersonalDataListener;
// Set the managers. These can be overridden by tests.
this.autofillManager_ = AutofillManagerImpl.getInstance();
// Request initial data.
this.autofillManager_.getAddressList(setAddressesListener);
// Listen for changes.
this.autofillManager_.setPersonalDataManagerListener(
setPersonalDataListener);
// Record that the user opened the address settings.
chrome.metricsPrivate.recordUserAction('AutofillAddressesViewed');
},
/** @override */
detached() {
this.autofillManager_.removePersonalDataManagerListener(
/**
@type {function(!Array<!settings.AutofillManager.AddressEntry>,
!Array<!settings.PaymentsManager.CreditCardEntry>)}
*/
(this.setPersonalDataListener_));
},
/** @override */
detached() {
this.autofillManager_.removePersonalDataManagerListener(
/**
@type {function(!Array<!AutofillManager.AddressEntry>,
!Array<!PaymentsManager.CreditCardEntry>)}
*/
(this.setPersonalDataListener_));
},
/**
* Open the address action menu.
* @param {!Event} e The polymer event.
* @private
*/
onAddressMenuTap_(e) {
const menuEvent = /** @type {!{model: !{item: !Object}}} */ (e);
const item = menuEvent.model.item;
/**
* Open the address action menu.
* @param {!Event} e The polymer event.
* @private
*/
onAddressMenuTap_(e) {
const menuEvent = /** @type {!{model: !{item: !Object}}} */ (e);
const item = menuEvent.model.item;
// Copy item so dialog won't update model on cancel.
this.activeAddress = /** @type {!chrome.autofillPrivate.AddressEntry} */ (
Object.assign({}, item));
// Copy item so dialog won't update model on cancel.
this.activeAddress = /** @type {!chrome.autofillPrivate.AddressEntry} */ (
Object.assign({}, item));
const dotsButton = /** @type {!HTMLElement} */ (e.target);
/** @type {!CrActionMenuElement} */ (this.$.addressSharedMenu)
.showAt(dotsButton);
this.activeDialogAnchor_ = dotsButton;
},
const dotsButton = /** @type {!HTMLElement} */ (e.target);
/** @type {!CrActionMenuElement} */ (this.$.addressSharedMenu)
.showAt(dotsButton);
this.activeDialogAnchor_ = dotsButton;
},
/**
* Handles tapping on the "Add address" button.
* @param {!Event} e The polymer event.
* @private
*/
onAddAddressTap_(e) {
e.preventDefault();
this.activeAddress = {};
this.showAddressDialog_ = true;
this.activeDialogAnchor_ = this.$.addAddress;
},
/**
* Handles tapping on the "Add address" button.
* @param {!Event} e The polymer event.
* @private
*/
onAddAddressTap_(e) {
e.preventDefault();
this.activeAddress = {};
this.showAddressDialog_ = true;
this.activeDialogAnchor_ = this.$.addAddress;
},
/** @private */
onAddressDialogClose_() {
this.showAddressDialog_ = false;
cr.ui.focusWithoutInk(assert(this.activeDialogAnchor_));
this.activeDialogAnchor_ = null;
},
/** @private */
onAddressDialogClose_() {
this.showAddressDialog_ = false;
cr.ui.focusWithoutInk(assert(this.activeDialogAnchor_));
this.activeDialogAnchor_ = null;
},
/**
* Handles tapping on the "Edit" address button.
* @param {!Event} e The polymer event.
* @private
*/
onMenuEditAddressTap_(e) {
e.preventDefault();
this.showAddressDialog_ = true;
this.$.addressSharedMenu.close();
},
/**
* Handles tapping on the "Edit" address button.
* @param {!Event} e The polymer event.
* @private
*/
onMenuEditAddressTap_(e) {
e.preventDefault();
this.showAddressDialog_ = true;
this.$.addressSharedMenu.close();
},
/** @private */
onRemoteEditAddressTap_() {
window.open(loadTimeData.getString('manageAddressesUrl'));
},
/** @private */
onRemoteEditAddressTap_() {
window.open(loadTimeData.getString('manageAddressesUrl'));
},
/**
* Handles tapping on the "Remove" address button.
* @private
*/
onMenuRemoveAddressTap_() {
this.autofillManager_.removeAddress(
/** @type {string} */ (this.activeAddress.guid));
this.$.addressSharedMenu.close();
},
/**
* Handles tapping on the "Remove" address button.
* @private
*/
onMenuRemoveAddressTap_() {
this.autofillManager_.removeAddress(
/** @type {string} */ (this.activeAddress.guid));
this.$.addressSharedMenu.close();
},
/**
* Returns true if the list exists and has items.
* @param {Array<Object>} list
* @return {boolean}
* @private
*/
hasSome_(list) {
return !!(list && list.length);
},
/**
* Returns true if the list exists and has items.
* @param {Array<Object>} list
* @return {boolean}
* @private
*/
hasSome_(list) {
return !!(list && list.length);
},
/**
* Listens for the save-address event, and calls the private API.
* @param {!Event} event
* @private
*/
saveAddress_(event) {
this.autofillManager_.saveAddress(event.detail);
},
/**
* Listens for the save-address event, and calls the private API.
* @param {!Event} event
* @private
*/
saveAddress_(event) {
this.autofillManager_.saveAddress(event.detail);
},
});
return {
AutofillManager,
AutofillManagerImpl,
};
});
})();
......@@ -13,7 +13,7 @@ Polymer({
properties: {
/**
* An array of all saved credit cards.
* @type {!Array<!PaymentsManager.CreditCardEntry>}
* @type {!Array<!settings.PaymentsManager.CreditCardEntry>}
*/
creditCards: Array,
},
......
......@@ -17,7 +17,7 @@ Polymer({
properties: {
/**
* A saved credit card.
* @type {!PaymentsManager.CreditCardEntry}
* @type {!settings.PaymentsManager.CreditCardEntry}
*/
creditCard: Object,
},
......
......@@ -7,405 +7,413 @@
* credit cards for use in autofill and payments APIs.
*/
/**
* Interface for all callbacks to the payments autofill API.
* @interface
*/
class PaymentsManager {
cr.define('settings', function() {
/**
* Add an observer to the list of personal data.
* @param {function(!Array<!AutofillManager.AddressEntry>,
* !Array<!PaymentsManager.CreditCardEntry>):void} listener
* Interface for all callbacks to the payments autofill API.
* @interface
*/
setPersonalDataManagerListener(listener) {}
class PaymentsManager {
/**
* Add an observer to the list of personal data.
* @param {function(!Array<!settings.AutofillManager.AddressEntry>,
* !Array<!settings.PaymentsManager.CreditCardEntry>):void} listener
*/
setPersonalDataManagerListener(listener) {}
/**
* Remove an observer from the list of personal data.
* @param {function(!Array<!AutofillManager.AddressEntry>,
* !Array<!PaymentsManager.CreditCardEntry>):void} listener
*/
removePersonalDataManagerListener(listener) {}
/**
* Remove an observer from the list of personal data.
* @param {function(!Array<!settings.AutofillManager.AddressEntry>,
* !Array<!settings.PaymentsManager.CreditCardEntry>):void} listener
*/
removePersonalDataManagerListener(listener) {}
/**
* Request the list of credit cards.
* @param {function(!Array<!PaymentsManager.CreditCardEntry>):void} callback
*/
getCreditCardList(callback) {}
/**
* Request the list of credit cards.
* @param {function(!Array<!settings.PaymentsManager.CreditCardEntry>):void}
* callback
*/
getCreditCardList(callback) {}
/** @param {string} guid The GUID of the credit card to remove. */
removeCreditCard(guid) {}
/** @param {string} guid The GUID of the credit card to remove. */
removeCreditCard(guid) {}
/** @param {string} guid The GUID to credit card to remove from the cache. */
clearCachedCreditCard(guid) {}
/**
* @param {string} guid The GUID to credit card to remove from the cache.
*/
clearCachedCreditCard(guid) {}
/**
* Saves the given credit card.
* @param {!PaymentsManager.CreditCardEntry} creditCard
*/
saveCreditCard(creditCard) {}
/**
* Saves the given credit card.
* @param {!settings.PaymentsManager.CreditCardEntry} creditCard
*/
saveCreditCard(creditCard) {}
/**
* Migrate the local credit cards.
*/
migrateCreditCards() {}
/**
* Migrate the local credit cards.
*/
migrateCreditCards() {}
/**
* Logs that the server cards edit link was clicked.
*/
logServerCardLinkClicked() {}
/**
* Logs that the server cards edit link was clicked.
*/
logServerCardLinkClicked() {}
/**
* Enables FIDO authentication for card unmasking.
*/
setCreditCardFIDOAuthEnabledState(enabled) {}
}
/** @typedef {chrome.autofillPrivate.CreditCardEntry} */
PaymentsManager.CreditCardEntry;
/**
* Enables FIDO authentication for card unmasking.
* Implementation that accesses the private API.
* @implements {settings.PaymentsManager}
*/
setCreditCardFIDOAuthEnabledState(enabled) {}
}
class PaymentsManagerImpl {
/** @override */
setPersonalDataManagerListener(listener) {
chrome.autofillPrivate.onPersonalDataChanged.addListener(listener);
}
/** @typedef {chrome.autofillPrivate.CreditCardEntry} */
PaymentsManager.CreditCardEntry;
/** @override */
removePersonalDataManagerListener(listener) {
chrome.autofillPrivate.onPersonalDataChanged.removeListener(listener);
}
/**
* Implementation that accesses the private API.
* @implements {PaymentsManager}
*/
class PaymentsManagerImpl {
/** @override */
setPersonalDataManagerListener(listener) {
chrome.autofillPrivate.onPersonalDataChanged.addListener(listener);
}
/** @override */
getCreditCardList(callback) {
chrome.autofillPrivate.getCreditCardList(callback);
}
/** @override */
removePersonalDataManagerListener(listener) {
chrome.autofillPrivate.onPersonalDataChanged.removeListener(listener);
}
/** @override */
removeCreditCard(guid) {
chrome.autofillPrivate.removeEntry(assert(guid));
}
/** @override */
getCreditCardList(callback) {
chrome.autofillPrivate.getCreditCardList(callback);
}
/** @override */
clearCachedCreditCard(guid) {
chrome.autofillPrivate.maskCreditCard(assert(guid));
}
/** @override */
removeCreditCard(guid) {
chrome.autofillPrivate.removeEntry(assert(guid));
}
/** @override */
saveCreditCard(creditCard) {
chrome.autofillPrivate.saveCreditCard(creditCard);
}
/** @override */
clearCachedCreditCard(guid) {
chrome.autofillPrivate.maskCreditCard(assert(guid));
}
/** @override */
migrateCreditCards() {
chrome.autofillPrivate.migrateCreditCards();
}
/** @override */
saveCreditCard(creditCard) {
chrome.autofillPrivate.saveCreditCard(creditCard);
}
/** @override */
logServerCardLinkClicked() {
chrome.autofillPrivate.logServerCardLinkClicked();
}
/** @override */
migrateCreditCards() {
chrome.autofillPrivate.migrateCreditCards();
/** @override */
setCreditCardFIDOAuthEnabledState(enabled) {
chrome.autofillPrivate.setCreditCardFIDOAuthEnabledState(enabled);
}
}
/** @override */
logServerCardLinkClicked() {
chrome.autofillPrivate.logServerCardLinkClicked();
}
cr.addSingletonGetter(PaymentsManagerImpl);
/** @override */
setCreditCardFIDOAuthEnabledState(enabled) {
chrome.autofillPrivate.setCreditCardFIDOAuthEnabledState(enabled);
}
}
Polymer({
is: 'settings-payments-section',
cr.addSingletonGetter(PaymentsManagerImpl);
behaviors: [
WebUIListenerBehavior,
I18nBehavior,
],
(function() {
'use strict';
properties: {
/**
* An array of all saved credit cards.
* @type {!Array<!settings.PaymentsManager.CreditCardEntry>}
*/
creditCards: {
type: Array,
value: () => [],
},
Polymer({
is: 'settings-payments-section',
/**
* Set to true if user can be verified through FIDO authentication.
* @private
*/
userIsFidoVerifiable_: {
type: Boolean,
value() {
return loadTimeData.getBoolean(
'fidoAuthenticationAvailableForAutofill');
},
},
behaviors: [
WebUIListenerBehavior,
I18nBehavior,
],
/**
* The model for any credit card related action menus or dialogs.
* @private {?chrome.autofillPrivate.CreditCardEntry}
*/
activeCreditCard: Object,
/** @private */
showCreditCardDialog_: Boolean,
/** @private */
migratableCreditCardsInfo_: String,
/**
* Whether migration local card on settings page is enabled.
* @private
*/
migrationEnabled_: {
type: Boolean,
value() {
return loadTimeData.getBoolean('migrationEnabled');
},
readOnly: true,
},
},
properties: {
/**
* An array of all saved credit cards.
* @type {!Array<!PaymentsManager.CreditCardEntry>}
*/
creditCards: {
type: Array,
value: () => [],
listeners: {
'save-credit-card': 'saveCreditCard_',
'dots-card-menu-click': 'onCreditCardDotsMenuTap_',
'remote-card-menu-click': 'onRemoteEditCreditCardTap_',
},
/**
* Set to true if user can be verified through FIDO authentication.
* @private
* The element to return focus to, when the currently active dialog is
* closed.
* @private {?HTMLElement}
*/
userIsFidoVerifiable_: {
type: Boolean,
value() {
return loadTimeData.getBoolean(
'fidoAuthenticationAvailableForAutofill');
},
},
activeDialogAnchor_: null,
/**
* The model for any credit card related action menus or dialogs.
* @private {?chrome.autofillPrivate.CreditCardEntry}
* @type {settings.PaymentsManager}
* @private
*/
activeCreditCard: Object,
/** @private */
showCreditCardDialog_: Boolean,
/** @private */
migratableCreditCardsInfo_: String,
PaymentsManager_: null,
/**
* Whether migration local card on settings page is enabled.
* @type {?function(!Array<!settings.AutofillManager.AddressEntry>,
* !Array<!settings.PaymentsManager.CreditCardEntry>)}
* @private
*/
migrationEnabled_: {
type: Boolean,
value() {
return loadTimeData.getBoolean('migrationEnabled');
},
readOnly: true,
setPersonalDataListener_: null,
/** @override */
attached() {
// Create listener function.
/** @type {function(!Array<!settings.PaymentsManager.CreditCardEntry>)} */
const setCreditCardsListener = cardList => {
this.creditCards = cardList;
};
// Update |userIsFidoVerifiable_| based on the availability of a platform
// authenticator.
if (window.PublicKeyCredential) {
window.PublicKeyCredential
.isUserVerifyingPlatformAuthenticatorAvailable()
.then(r => {
this.userIsFidoVerifiable_ = this.userIsFidoVerifiable_ && r;
});
}
/**
* @type {function(!Array<!settings.AutofillManager.AddressEntry>,
* !Array<!settings.PaymentsManager.CreditCardEntry>)}
*/
const setPersonalDataListener = (addressList, cardList) => {
this.creditCards = cardList;
};
// Remember the bound reference in order to detach.
this.setPersonalDataListener_ = setPersonalDataListener;
// Set the managers. These can be overridden by tests.
this.paymentsManager_ = PaymentsManagerImpl.getInstance();
// Request initial data.
this.paymentsManager_.getCreditCardList(setCreditCardsListener);
// Listen for changes.
this.paymentsManager_.setPersonalDataManagerListener(
setPersonalDataListener);
// Record that the user opened the payments settings.
chrome.metricsPrivate.recordUserAction('AutofillCreditCardsViewed');
},
},
listeners: {
'save-credit-card': 'saveCreditCard_',
'dots-card-menu-click': 'onCreditCardDotsMenuTap_',
'remote-card-menu-click': 'onRemoteEditCreditCardTap_',
},
/**
* The element to return focus to, when the currently active dialog is
* closed.
* @private {?HTMLElement}
*/
activeDialogAnchor_: null,
/**
* @type {PaymentsManager}
* @private
*/
PaymentsManager_: null,
/**
* @type {?function(!Array<!AutofillManager.AddressEntry>,
* !Array<!PaymentsManager.CreditCardEntry>)}
* @private
*/
setPersonalDataListener_: null,
/** @override */
attached() {
// Create listener function.
/** @type {function(!Array<!PaymentsManager.CreditCardEntry>)} */
const setCreditCardsListener = cardList => {
this.creditCards = cardList;
};
// Update |userIsFidoVerifiable_| based on the availability of a platform
// authenticator.
if (window.PublicKeyCredential) {
window.PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable()
.then(r => {
this.userIsFidoVerifiable_ = this.userIsFidoVerifiable_ && r;
});
}
/** @override */
detached() {
this.paymentsManager_.removePersonalDataManagerListener(
/**
@type {function(!Array<!settings.AutofillManager.AddressEntry>,
!Array<!settings.PaymentsManager.CreditCardEntry>)}
*/
(this.setPersonalDataListener_));
},
/**
* @type {function(!Array<!AutofillManager.AddressEntry>,
* !Array<!PaymentsManager.CreditCardEntry>)}
* Opens the credit card action menu.
* @param {!CustomEvent<{creditCard:
* !chrome.autofillPrivate.CreditCardEntry, anchorElement:
* !HTMLElement}>} e
* @private
*/
const setPersonalDataListener = (addressList, cardList) => {
this.creditCards = cardList;
};
// Remember the bound reference in order to detach.
this.setPersonalDataListener_ = setPersonalDataListener;
// Set the managers. These can be overridden by tests.
this.paymentsManager_ = PaymentsManagerImpl.getInstance();
// Request initial data.
this.paymentsManager_.getCreditCardList(setCreditCardsListener);
// Listen for changes.
this.paymentsManager_.setPersonalDataManagerListener(
setPersonalDataListener);
// Record that the user opened the payments settings.
chrome.metricsPrivate.recordUserAction('AutofillCreditCardsViewed');
},
/** @override */
detached() {
this.paymentsManager_.removePersonalDataManagerListener(
/**
@type {function(!Array<!AutofillManager.AddressEntry>,
!Array<!PaymentsManager.CreditCardEntry>)}
*/
(this.setPersonalDataListener_));
},
/**
* Opens the credit card action menu.
* @param {!CustomEvent<{creditCard: !chrome.autofillPrivate.CreditCardEntry,
* anchorElement: !HTMLElement}>} e
* @private
*/
onCreditCardDotsMenuTap_(e) {
// Copy item so dialog won't update model on cancel.
this.activeCreditCard = e.detail.creditCard;
onCreditCardDotsMenuTap_(e) {
// Copy item so dialog won't update model on cancel.
this.activeCreditCard = e.detail.creditCard;
/** @type {!CrActionMenuElement} */ (this.$.creditCardSharedMenu)
.showAt(e.detail.anchorElement);
this.activeDialogAnchor_ = e.detail.anchorElement;
},
/**
* Handles tapping on the "Add credit card" button.
* @param {!Event} e
* @private
*/
onAddCreditCardTap_(e) {
e.preventDefault();
const date = new Date(); // Default to current month/year.
const expirationMonth = date.getMonth() + 1; // Months are 0 based.
this.activeCreditCard = {
expirationMonth: expirationMonth.toString(),
expirationYear: date.getFullYear().toString(),
};
this.showCreditCardDialog_ = true;
this.activeDialogAnchor_ = this.$.addCreditCard;
},
/** @private */
onCreditCardDialogClose_() {
this.showCreditCardDialog_ = false;
cr.ui.focusWithoutInk(assert(this.activeDialogAnchor_));
this.activeDialogAnchor_ = null;
this.activeCreditCard = null;
},
/**
* Handles tapping on the "Edit" credit card button.
* @param {!Event} e The polymer event.
* @private
*/
onMenuEditCreditCardTap_(e) {
e.preventDefault();
/** @type {!CrActionMenuElement} */ (this.$.creditCardSharedMenu)
.showAt(e.detail.anchorElement);
this.activeDialogAnchor_ = e.detail.anchorElement;
},
if (this.activeCreditCard.metadata.isLocal) {
/**
* Handles tapping on the "Add credit card" button.
* @param {!Event} e
* @private
*/
onAddCreditCardTap_(e) {
e.preventDefault();
const date = new Date(); // Default to current month/year.
const expirationMonth = date.getMonth() + 1; // Months are 0 based.
this.activeCreditCard = {
expirationMonth: expirationMonth.toString(),
expirationYear: date.getFullYear().toString(),
};
this.showCreditCardDialog_ = true;
} else {
this.onRemoteEditCreditCardTap_();
}
this.activeDialogAnchor_ = this.$.addCreditCard;
},
this.$.creditCardSharedMenu.close();
},
/** @private */
onCreditCardDialogClose_() {
this.showCreditCardDialog_ = false;
cr.ui.focusWithoutInk(assert(this.activeDialogAnchor_));
this.activeDialogAnchor_ = null;
this.activeCreditCard = null;
},
/** @private */
onRemoteEditCreditCardTap_() {
this.paymentsManager_.logServerCardLinkClicked();
window.open(loadTimeData.getString('manageCreditCardsUrl'));
},
/**
* Handles tapping on the "Edit" credit card button.
* @param {!Event} e The polymer event.
* @private
*/
onMenuEditCreditCardTap_(e) {
e.preventDefault();
/**
* Handles tapping on the "Remove" credit card button.
* @private
*/
onMenuRemoveCreditCardTap_() {
this.paymentsManager_.removeCreditCard(
/** @type {string} */ (this.activeCreditCard.guid));
this.$.creditCardSharedMenu.close();
this.activeCreditCard = null;
},
if (this.activeCreditCard.metadata.isLocal) {
this.showCreditCardDialog_ = true;
} else {
this.onRemoteEditCreditCardTap_();
}
/**
* Handles tapping on the "Clear copy" button for cached credit cards.
* @private
*/
onMenuClearCreditCardTap_() {
this.paymentsManager_.clearCachedCreditCard(
/** @type {string} */ (this.activeCreditCard.guid));
this.$.creditCardSharedMenu.close();
this.activeCreditCard = null;
},
this.$.creditCardSharedMenu.close();
},
/**
* Handles clicking on the "Migrate" button for migrate local credit
* cards.
* @private
*/
onMigrateCreditCardsClick_() {
this.paymentsManager_.migrateCreditCards();
},
/** @private */
onRemoteEditCreditCardTap_() {
this.paymentsManager_.logServerCardLinkClicked();
window.open(loadTimeData.getString('manageCreditCardsUrl'));
},
/**
* Listens for the save-credit-card event, and calls the private API.
* @param {!Event} event
* @private
*/
saveCreditCard_(event) {
this.paymentsManager_.saveCreditCard(event.detail);
},
/**
* Handles tapping on the "Remove" credit card button.
* @private
*/
onMenuRemoveCreditCardTap_() {
this.paymentsManager_.removeCreditCard(
/** @type {string} */ (this.activeCreditCard.guid));
this.$.creditCardSharedMenu.close();
this.activeCreditCard = null;
},
/**
* @param {boolean} creditCardEnabled
* @return {boolean} Whether or not the user is verifiable through FIDO
* authentication.
* @private
*/
shouldShowFidoToggle_(creditCardEnabled, userIsFidoVerifiable) {
return creditCardEnabled && userIsFidoVerifiable;
},
/**
* Handles tapping on the "Clear copy" button for cached credit cards.
* @private
*/
onMenuClearCreditCardTap_() {
this.paymentsManager_.clearCachedCreditCard(
/** @type {string} */ (this.activeCreditCard.guid));
this.$.creditCardSharedMenu.close();
this.activeCreditCard = null;
},
/**
* Listens for the enable-authentication event, and calls the private API.
* @private
*/
setFIDOAuthenticationEnabledState_() {
this.paymentsManager_.setCreditCardFIDOAuthEnabledState(
this.$$('#autofillCreditCardFIDOAuthToggle').checked);
},
/**
* Handles clicking on the "Migrate" button for migrate local credit
* cards.
* @private
*/
onMigrateCreditCardsClick_() {
this.paymentsManager_.migrateCreditCards();
},
/**
* @param {!Array<!PaymentsManager.CreditCardEntry>} creditCards
* @param {boolean} creditCardEnabled
* @return {boolean} Whether to show the migration button.
* @private
*/
checkIfMigratable_(creditCards, creditCardEnabled) {
// If migration prerequisites are not met, return false.
if (!this.migrationEnabled_) {
return false;
}
/**
* Listens for the save-credit-card event, and calls the private API.
* @param {!Event} event
* @private
*/
saveCreditCard_(event) {
this.paymentsManager_.saveCreditCard(event.detail);
},
// If credit card enabled pref is false, return false.
if (!creditCardEnabled) {
return false;
}
/**
* @param {boolean} creditCardEnabled
* @return {boolean} Whether or not the user is verifiable through FIDO
* authentication.
* @private
*/
shouldShowFidoToggle_(creditCardEnabled, userIsFidoVerifiable) {
return creditCardEnabled && userIsFidoVerifiable;
},
const numberOfMigratableCreditCard =
creditCards.filter(card => card.metadata.isMigratable).length;
// Check whether exist at least one local valid card for migration.
if (numberOfMigratableCreditCard == 0) {
return false;
}
/**
* Listens for the enable-authentication event, and calls the private API.
* @private
*/
setFIDOAuthenticationEnabledState_() {
this.paymentsManager_.setCreditCardFIDOAuthEnabledState(
this.$$('#autofillCreditCardFIDOAuthToggle').checked);
},
// Update the display text depends on the number of migratable credit
// cards.
this.migratableCreditCardsInfo_ = numberOfMigratableCreditCard == 1 ?
this.i18n('migratableCardsInfoSingle') :
this.i18n('migratableCardsInfoMultiple');
/**
* @param {!Array<!settings.PaymentsManager.CreditCardEntry>} creditCards
* @param {boolean} creditCardEnabled
* @return {boolean} Whether to show the migration button.
* @private
*/
checkIfMigratable_(creditCards, creditCardEnabled) {
// If migration prerequisites are not met, return false.
if (!this.migrationEnabled_) {
return false;
}
// If credit card enabled pref is false, return false.
if (!creditCardEnabled) {
return false;
}
const numberOfMigratableCreditCard =
creditCards.filter(card => card.metadata.isMigratable).length;
// Check whether exist at least one local valid card for migration.
if (numberOfMigratableCreditCard == 0) {
return false;
}
// Update the display text depends on the number of migratable credit
// cards.
this.migratableCreditCardsInfo_ = numberOfMigratableCreditCard == 1 ?
this.i18n('migratableCardsInfoSingle') :
this.i18n('migratableCardsInfoMultiple');
return true;
},
return true;
},
});
return {
PaymentsManager,
PaymentsManagerImpl,
};
});
})();
......@@ -62,7 +62,7 @@ AccessibilityTest.define('SettingsA11yPasswords', {
'object or string', 'Test', settings.routes.PASSWORDS.path);
PasswordManagerImpl.instance_ = new TestPasswordManagerProxy();
this.passwordManager = PasswordManagerImpl.instance_;
this.passwordManager = PasswordManagerImpl.getInstance();
const settingsUi = document.createElement('settings-ui');
......
......@@ -126,11 +126,11 @@ cr.define('settings_autofill_page', function() {
// Override the AutofillManagerImpl for testing.
autofillManager = new TestAutofillManager();
AutofillManagerImpl.instance_ = autofillManager;
settings.AutofillManagerImpl.instance_ = autofillManager;
// Override the PaymentsManagerImpl for testing.
paymentsManager = new TestPaymentsManager();
PaymentsManagerImpl.instance_ = paymentsManager;
settings.PaymentsManagerImpl.instance_ = paymentsManager;
});
test('baseLoadAndRemove', function() {
......
......@@ -60,7 +60,7 @@ cr.define('settings_autofill_section', function() {
// Override the AutofillManagerImpl for testing.
this.autofillManager = new TestAutofillManager();
this.autofillManager.data.addresses = addresses;
AutofillManagerImpl.instance_ = this.autofillManager;
settings.AutofillManagerImpl.instance_ = this.autofillManager;
const section = document.createElement('settings-autofill-section');
section.prefs = {autofill: prefValues};
......
......@@ -42,7 +42,7 @@ cr.define('settings_payments_section', function() {
// Override the PaymentsManagerImpl for testing.
const paymentsManager = new TestPaymentsManager();
paymentsManager.data.creditCards = creditCards;
PaymentsManagerImpl.instance_ = paymentsManager;
settings.PaymentsManagerImpl.instance_ = paymentsManager;
const section = document.createElement('settings-payments-section');
section.prefs = {autofill: prefValues};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment