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,49 +7,51 @@ ...@@ -7,49 +7,51 @@
* addresses for use in autofill and payments APIs. * addresses for use in autofill and payments APIs.
*/ */
/** cr.define('settings', function() {
/**
* Interface for all callbacks to the autofill API. * Interface for all callbacks to the autofill API.
* @interface * @interface
*/ */
class AutofillManager { class AutofillManager {
/** /**
* Add an observer to the list of personal data. * Add an observer to the list of personal data.
* @param {function(!Array<!AutofillManager.AddressEntry>, * @param {function(!Array<!settings.AutofillManager.AddressEntry>,
* !Array<!PaymentsManager.CreditCardEntry>):void} listener * !Array<!settings.PaymentsManager.CreditCardEntry>):void} listener
*/ */
setPersonalDataManagerListener(listener) {} setPersonalDataManagerListener(listener) {}
/** /**
* Remove an observer from the list of personal data. * Remove an observer from the list of personal data.
* @param {function(!Array<!AutofillManager.AddressEntry>, * @param {function(!Array<!settings.AutofillManager.AddressEntry>,
* !Array<!PaymentsManager.CreditCardEntry>):void} listener * !Array<!settings.PaymentsManager.CreditCardEntry>):void} listener
*/ */
removePersonalDataManagerListener(listener) {} removePersonalDataManagerListener(listener) {}
/** /**
* Request the list of addresses. * Request the list of addresses.
* @param {function(!Array<!AutofillManager.AddressEntry>):void} callback * @param {function(!Array<!settings.AutofillManager.AddressEntry>):void}
* callback
*/ */
getAddressList(callback) {} getAddressList(callback) {}
/** /**
* Saves the given address. * Saves the given address.
* @param {!AutofillManager.AddressEntry} address * @param {!settings.AutofillManager.AddressEntry} address
*/ */
saveAddress(address) {} saveAddress(address) {}
/** @param {string} guid The guid of the address to remove. */ /** @param {string} guid The guid of the address to remove. */
removeAddress(guid) {} removeAddress(guid) {}
} }
/** @typedef {chrome.autofillPrivate.AddressEntry} */ /** @typedef {chrome.autofillPrivate.AddressEntry} */
AutofillManager.AddressEntry; AutofillManager.AddressEntry;
/** /**
* Implementation that accesses the private API. * Implementation that accesses the private API.
* @implements {AutofillManager} * @implements {settings.AutofillManager}
*/ */
class AutofillManagerImpl { class AutofillManagerImpl {
/** @override */ /** @override */
setPersonalDataManagerListener(listener) { setPersonalDataManagerListener(listener) {
chrome.autofillPrivate.onPersonalDataChanged.addListener(listener); chrome.autofillPrivate.onPersonalDataChanged.addListener(listener);
...@@ -74,20 +76,17 @@ class AutofillManagerImpl { ...@@ -74,20 +76,17 @@ class AutofillManagerImpl {
removeAddress(guid) { removeAddress(guid) {
chrome.autofillPrivate.removeEntry(assert(guid)); chrome.autofillPrivate.removeEntry(assert(guid));
} }
} }
cr.addSingletonGetter(AutofillManagerImpl);
(function() { cr.addSingletonGetter(AutofillManagerImpl);
'use strict';
Polymer({ Polymer({
is: 'settings-autofill-section', is: 'settings-autofill-section',
properties: { properties: {
/** /**
* An array of saved addresses. * An array of saved addresses.
* @type {!Array<!AutofillManager.AddressEntry>} * @type {!Array<!settings.AutofillManager.AddressEntry>}
*/ */
addresses: Array, addresses: Array,
...@@ -113,14 +112,14 @@ Polymer({ ...@@ -113,14 +112,14 @@ Polymer({
activeDialogAnchor_: null, activeDialogAnchor_: null,
/** /**
* @type {AutofillManager} * @type {settings.AutofillManager}
* @private * @private
*/ */
autofillManager_: null, autofillManager_: null,
/** /**
* @type {?function(!Array<!AutofillManager.AddressEntry>, * @type {?function(!Array<!settings.AutofillManager.AddressEntry>,
* !Array<!PaymentsManager.CreditCardEntry>)} * !Array<!settings.PaymentsManager.CreditCardEntry>)}
* @private * @private
*/ */
setPersonalDataListener_: null, setPersonalDataListener_: null,
...@@ -128,14 +127,14 @@ Polymer({ ...@@ -128,14 +127,14 @@ Polymer({
/** @override */ /** @override */
attached() { attached() {
// Create listener functions. // Create listener functions.
/** @type {function(!Array<!AutofillManager.AddressEntry>)} */ /** @type {function(!Array<!settings.AutofillManager.AddressEntry>)} */
const setAddressesListener = addressList => { const setAddressesListener = addressList => {
this.addresses = addressList; this.addresses = addressList;
}; };
/** /**
* @type {function(!Array<!AutofillManager.AddressEntry>, * @type {function(!Array<!settings.AutofillManager.AddressEntry>,
* !Array<!PaymentsManager.CreditCardEntry>)} * !Array<!settings.PaymentsManager.CreditCardEntry>)}
*/ */
const setPersonalDataListener = (addressList, cardList) => { const setPersonalDataListener = (addressList, cardList) => {
this.addresses = addressList; this.addresses = addressList;
...@@ -162,8 +161,8 @@ Polymer({ ...@@ -162,8 +161,8 @@ Polymer({
detached() { detached() {
this.autofillManager_.removePersonalDataManagerListener( this.autofillManager_.removePersonalDataManagerListener(
/** /**
@type {function(!Array<!AutofillManager.AddressEntry>, @type {function(!Array<!settings.AutofillManager.AddressEntry>,
!Array<!PaymentsManager.CreditCardEntry>)} !Array<!settings.PaymentsManager.CreditCardEntry>)}
*/ */
(this.setPersonalDataListener_)); (this.setPersonalDataListener_));
}, },
...@@ -250,5 +249,10 @@ Polymer({ ...@@ -250,5 +249,10 @@ Polymer({
saveAddress_(event) { saveAddress_(event) {
this.autofillManager_.saveAddress(event.detail); this.autofillManager_.saveAddress(event.detail);
}, },
});
return {
AutofillManager,
AutofillManagerImpl,
};
}); });
})();
...@@ -13,7 +13,7 @@ Polymer({ ...@@ -13,7 +13,7 @@ Polymer({
properties: { properties: {
/** /**
* An array of all saved credit cards. * An array of all saved credit cards.
* @type {!Array<!PaymentsManager.CreditCardEntry>} * @type {!Array<!settings.PaymentsManager.CreditCardEntry>}
*/ */
creditCards: Array, creditCards: Array,
}, },
......
...@@ -17,7 +17,7 @@ Polymer({ ...@@ -17,7 +17,7 @@ Polymer({
properties: { properties: {
/** /**
* A saved credit card. * A saved credit card.
* @type {!PaymentsManager.CreditCardEntry} * @type {!settings.PaymentsManager.CreditCardEntry}
*/ */
creditCard: Object, creditCard: Object,
}, },
......
...@@ -7,40 +7,44 @@ ...@@ -7,40 +7,44 @@
* credit cards for use in autofill and payments APIs. * credit cards for use in autofill and payments APIs.
*/ */
/** cr.define('settings', function() {
/**
* Interface for all callbacks to the payments autofill API. * Interface for all callbacks to the payments autofill API.
* @interface * @interface
*/ */
class PaymentsManager { class PaymentsManager {
/** /**
* Add an observer to the list of personal data. * Add an observer to the list of personal data.
* @param {function(!Array<!AutofillManager.AddressEntry>, * @param {function(!Array<!settings.AutofillManager.AddressEntry>,
* !Array<!PaymentsManager.CreditCardEntry>):void} listener * !Array<!settings.PaymentsManager.CreditCardEntry>):void} listener
*/ */
setPersonalDataManagerListener(listener) {} setPersonalDataManagerListener(listener) {}
/** /**
* Remove an observer from the list of personal data. * Remove an observer from the list of personal data.
* @param {function(!Array<!AutofillManager.AddressEntry>, * @param {function(!Array<!settings.AutofillManager.AddressEntry>,
* !Array<!PaymentsManager.CreditCardEntry>):void} listener * !Array<!settings.PaymentsManager.CreditCardEntry>):void} listener
*/ */
removePersonalDataManagerListener(listener) {} removePersonalDataManagerListener(listener) {}
/** /**
* Request the list of credit cards. * Request the list of credit cards.
* @param {function(!Array<!PaymentsManager.CreditCardEntry>):void} callback * @param {function(!Array<!settings.PaymentsManager.CreditCardEntry>):void}
* callback
*/ */
getCreditCardList(callback) {} getCreditCardList(callback) {}
/** @param {string} guid The GUID of the credit card to remove. */ /** @param {string} guid The GUID of the credit card to remove. */
removeCreditCard(guid) {} removeCreditCard(guid) {}
/** @param {string} guid The GUID to credit card to remove from the cache. */ /**
* @param {string} guid The GUID to credit card to remove from the cache.
*/
clearCachedCreditCard(guid) {} clearCachedCreditCard(guid) {}
/** /**
* Saves the given credit card. * Saves the given credit card.
* @param {!PaymentsManager.CreditCardEntry} creditCard * @param {!settings.PaymentsManager.CreditCardEntry} creditCard
*/ */
saveCreditCard(creditCard) {} saveCreditCard(creditCard) {}
...@@ -58,16 +62,16 @@ class PaymentsManager { ...@@ -58,16 +62,16 @@ class PaymentsManager {
* Enables FIDO authentication for card unmasking. * Enables FIDO authentication for card unmasking.
*/ */
setCreditCardFIDOAuthEnabledState(enabled) {} setCreditCardFIDOAuthEnabledState(enabled) {}
} }
/** @typedef {chrome.autofillPrivate.CreditCardEntry} */ /** @typedef {chrome.autofillPrivate.CreditCardEntry} */
PaymentsManager.CreditCardEntry; PaymentsManager.CreditCardEntry;
/** /**
* Implementation that accesses the private API. * Implementation that accesses the private API.
* @implements {PaymentsManager} * @implements {settings.PaymentsManager}
*/ */
class PaymentsManagerImpl { class PaymentsManagerImpl {
/** @override */ /** @override */
setPersonalDataManagerListener(listener) { setPersonalDataManagerListener(listener) {
chrome.autofillPrivate.onPersonalDataChanged.addListener(listener); chrome.autofillPrivate.onPersonalDataChanged.addListener(listener);
...@@ -112,14 +116,11 @@ class PaymentsManagerImpl { ...@@ -112,14 +116,11 @@ class PaymentsManagerImpl {
setCreditCardFIDOAuthEnabledState(enabled) { setCreditCardFIDOAuthEnabledState(enabled) {
chrome.autofillPrivate.setCreditCardFIDOAuthEnabledState(enabled); chrome.autofillPrivate.setCreditCardFIDOAuthEnabledState(enabled);
} }
} }
cr.addSingletonGetter(PaymentsManagerImpl);
(function() { cr.addSingletonGetter(PaymentsManagerImpl);
'use strict';
Polymer({ Polymer({
is: 'settings-payments-section', is: 'settings-payments-section',
behaviors: [ behaviors: [
...@@ -130,7 +131,7 @@ Polymer({ ...@@ -130,7 +131,7 @@ Polymer({
properties: { properties: {
/** /**
* An array of all saved credit cards. * An array of all saved credit cards.
* @type {!Array<!PaymentsManager.CreditCardEntry>} * @type {!Array<!settings.PaymentsManager.CreditCardEntry>}
*/ */
creditCards: { creditCards: {
type: Array, type: Array,
...@@ -188,14 +189,14 @@ Polymer({ ...@@ -188,14 +189,14 @@ Polymer({
activeDialogAnchor_: null, activeDialogAnchor_: null,
/** /**
* @type {PaymentsManager} * @type {settings.PaymentsManager}
* @private * @private
*/ */
PaymentsManager_: null, PaymentsManager_: null,
/** /**
* @type {?function(!Array<!AutofillManager.AddressEntry>, * @type {?function(!Array<!settings.AutofillManager.AddressEntry>,
* !Array<!PaymentsManager.CreditCardEntry>)} * !Array<!settings.PaymentsManager.CreditCardEntry>)}
* @private * @private
*/ */
setPersonalDataListener_: null, setPersonalDataListener_: null,
...@@ -203,7 +204,7 @@ Polymer({ ...@@ -203,7 +204,7 @@ Polymer({
/** @override */ /** @override */
attached() { attached() {
// Create listener function. // Create listener function.
/** @type {function(!Array<!PaymentsManager.CreditCardEntry>)} */ /** @type {function(!Array<!settings.PaymentsManager.CreditCardEntry>)} */
const setCreditCardsListener = cardList => { const setCreditCardsListener = cardList => {
this.creditCards = cardList; this.creditCards = cardList;
}; };
...@@ -211,15 +212,16 @@ Polymer({ ...@@ -211,15 +212,16 @@ Polymer({
// Update |userIsFidoVerifiable_| based on the availability of a platform // Update |userIsFidoVerifiable_| based on the availability of a platform
// authenticator. // authenticator.
if (window.PublicKeyCredential) { if (window.PublicKeyCredential) {
window.PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable() window.PublicKeyCredential
.isUserVerifyingPlatformAuthenticatorAvailable()
.then(r => { .then(r => {
this.userIsFidoVerifiable_ = this.userIsFidoVerifiable_ && r; this.userIsFidoVerifiable_ = this.userIsFidoVerifiable_ && r;
}); });
} }
/** /**
* @type {function(!Array<!AutofillManager.AddressEntry>, * @type {function(!Array<!settings.AutofillManager.AddressEntry>,
* !Array<!PaymentsManager.CreditCardEntry>)} * !Array<!settings.PaymentsManager.CreditCardEntry>)}
*/ */
const setPersonalDataListener = (addressList, cardList) => { const setPersonalDataListener = (addressList, cardList) => {
this.creditCards = cardList; this.creditCards = cardList;
...@@ -246,16 +248,17 @@ Polymer({ ...@@ -246,16 +248,17 @@ Polymer({
detached() { detached() {
this.paymentsManager_.removePersonalDataManagerListener( this.paymentsManager_.removePersonalDataManagerListener(
/** /**
@type {function(!Array<!AutofillManager.AddressEntry>, @type {function(!Array<!settings.AutofillManager.AddressEntry>,
!Array<!PaymentsManager.CreditCardEntry>)} !Array<!settings.PaymentsManager.CreditCardEntry>)}
*/ */
(this.setPersonalDataListener_)); (this.setPersonalDataListener_));
}, },
/** /**
* Opens the credit card action menu. * Opens the credit card action menu.
* @param {!CustomEvent<{creditCard: !chrome.autofillPrivate.CreditCardEntry, * @param {!CustomEvent<{creditCard:
* anchorElement: !HTMLElement}>} e * !chrome.autofillPrivate.CreditCardEntry, anchorElement:
* !HTMLElement}>} e
* @private * @private
*/ */
onCreditCardDotsMenuTap_(e) { onCreditCardDotsMenuTap_(e) {
...@@ -375,7 +378,7 @@ Polymer({ ...@@ -375,7 +378,7 @@ Polymer({
}, },
/** /**
* @param {!Array<!PaymentsManager.CreditCardEntry>} creditCards * @param {!Array<!settings.PaymentsManager.CreditCardEntry>} creditCards
* @param {boolean} creditCardEnabled * @param {boolean} creditCardEnabled
* @return {boolean} Whether to show the migration button. * @return {boolean} Whether to show the migration button.
* @private * @private
...@@ -407,5 +410,10 @@ Polymer({ ...@@ -407,5 +410,10 @@ Polymer({
return true; return true;
}, },
});
return {
PaymentsManager,
PaymentsManagerImpl,
};
}); });
})();
...@@ -62,7 +62,7 @@ AccessibilityTest.define('SettingsA11yPasswords', { ...@@ -62,7 +62,7 @@ AccessibilityTest.define('SettingsA11yPasswords', {
'object or string', 'Test', settings.routes.PASSWORDS.path); 'object or string', 'Test', settings.routes.PASSWORDS.path);
PasswordManagerImpl.instance_ = new TestPasswordManagerProxy(); PasswordManagerImpl.instance_ = new TestPasswordManagerProxy();
this.passwordManager = PasswordManagerImpl.instance_; this.passwordManager = PasswordManagerImpl.getInstance();
const settingsUi = document.createElement('settings-ui'); const settingsUi = document.createElement('settings-ui');
......
...@@ -126,11 +126,11 @@ cr.define('settings_autofill_page', function() { ...@@ -126,11 +126,11 @@ cr.define('settings_autofill_page', function() {
// Override the AutofillManagerImpl for testing. // Override the AutofillManagerImpl for testing.
autofillManager = new TestAutofillManager(); autofillManager = new TestAutofillManager();
AutofillManagerImpl.instance_ = autofillManager; settings.AutofillManagerImpl.instance_ = autofillManager;
// Override the PaymentsManagerImpl for testing. // Override the PaymentsManagerImpl for testing.
paymentsManager = new TestPaymentsManager(); paymentsManager = new TestPaymentsManager();
PaymentsManagerImpl.instance_ = paymentsManager; settings.PaymentsManagerImpl.instance_ = paymentsManager;
}); });
test('baseLoadAndRemove', function() { test('baseLoadAndRemove', function() {
......
...@@ -60,7 +60,7 @@ cr.define('settings_autofill_section', function() { ...@@ -60,7 +60,7 @@ cr.define('settings_autofill_section', function() {
// Override the AutofillManagerImpl for testing. // Override the AutofillManagerImpl for testing.
this.autofillManager = new TestAutofillManager(); this.autofillManager = new TestAutofillManager();
this.autofillManager.data.addresses = addresses; this.autofillManager.data.addresses = addresses;
AutofillManagerImpl.instance_ = this.autofillManager; settings.AutofillManagerImpl.instance_ = this.autofillManager;
const section = document.createElement('settings-autofill-section'); const section = document.createElement('settings-autofill-section');
section.prefs = {autofill: prefValues}; section.prefs = {autofill: prefValues};
......
...@@ -42,7 +42,7 @@ cr.define('settings_payments_section', function() { ...@@ -42,7 +42,7 @@ cr.define('settings_payments_section', function() {
// Override the PaymentsManagerImpl for testing. // Override the PaymentsManagerImpl for testing.
const paymentsManager = new TestPaymentsManager(); const paymentsManager = new TestPaymentsManager();
paymentsManager.data.creditCards = creditCards; paymentsManager.data.creditCards = creditCards;
PaymentsManagerImpl.instance_ = paymentsManager; settings.PaymentsManagerImpl.instance_ = paymentsManager;
const section = document.createElement('settings-payments-section'); const section = document.createElement('settings-payments-section');
section.prefs = {autofill: prefValues}; 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