Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3898)

Unified Diff: chrome/browser/resources/settings/passwords_and_forms_page/autofill_section.js

Issue 2627123002: Load Passwords and Autofill in the corresponding sub page. (Closed)
Patch Set: rebase Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/resources/settings/passwords_and_forms_page/passwords_and_forms_page.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/settings/passwords_and_forms_page/autofill_section.js
diff --git a/chrome/browser/resources/settings/passwords_and_forms_page/autofill_section.js b/chrome/browser/resources/settings/passwords_and_forms_page/autofill_section.js
index a064ef9217cfe347ef7f2c2011176d10126d72ee..ebda21bd5ebe471047a38d43f11c03c6a81fe746 100644
--- a/chrome/browser/resources/settings/passwords_and_forms_page/autofill_section.js
+++ b/chrome/browser/resources/settings/passwords_and_forms_page/autofill_section.js
@@ -6,6 +6,145 @@
* @fileoverview 'settings-autofill-section' is the section containing saved
* addresses and credit cards for use in autofill.
*/
+
+/**
+ * Interface for all callbacks to the autofill API.
+ * @interface
+ */
+function AutofillManager() {}
+
+/** @typedef {chrome.autofillPrivate.AddressEntry} */
+AutofillManager.AddressEntry;
+
+/** @typedef {chrome.autofillPrivate.CreditCardEntry} */
+AutofillManager.CreditCardEntry;
+
+AutofillManager.prototype = {
+ /**
+ * Add an observer to the list of addresses.
+ * @param {function(!Array<!AutofillManager.AddressEntry>):void} listener
+ */
+ addAddressListChangedListener: assertNotReached,
+
+ /**
+ * Remove an observer from the list of addresses.
+ * @param {function(!Array<!AutofillManager.AddressEntry>):void} listener
+ */
+ removeAddressListChangedListener: assertNotReached,
+
+ /**
+ * Request the list of addresses.
+ * @param {function(!Array<!AutofillManager.AddressEntry>):void} callback
+ */
+ getAddressList: assertNotReached,
+
+ /**
+ * Saves the given address.
+ * @param {!AutofillManager.AddressEntry} address
+ */
+ saveAddress: assertNotReached,
+
+ /** @param {string} guid The guid of the address to remove. */
+ removeAddress: assertNotReached,
+
+ /**
+ * Add an observer to the list of credit cards.
+ * @param {function(!Array<!AutofillManager.CreditCardEntry>):void} listener
+ */
+ addCreditCardListChangedListener: assertNotReached,
+
+ /**
+ * Remove an observer from the list of credit cards.
+ * @param {function(!Array<!AutofillManager.CreditCardEntry>):void} listener
+ */
+ removeCreditCardListChangedListener: assertNotReached,
+
+ /**
+ * Request the list of credit cards.
+ * @param {function(!Array<!AutofillManager.CreditCardEntry>):void} callback
+ */
+ getCreditCardList: assertNotReached,
+
+ /** @param {string} guid The GUID of the credit card to remove. */
+ removeCreditCard: assertNotReached,
+
+ /** @param {string} guid The GUID to credit card to remove from the cache. */
+ clearCachedCreditCard: assertNotReached,
+
+ /**
+ * Saves the given credit card.
+ * @param {!AutofillManager.CreditCardEntry} creditCard
+ */
+ saveCreditCard: assertNotReached,
+};
+
+/**
+ * Implementation that accesses the private API.
+ * @implements {AutofillManager}
+ * @constructor
+ */
+function AutofillManagerImpl() {}
+cr.addSingletonGetter(AutofillManagerImpl);
+
+AutofillManagerImpl.prototype = {
+ __proto__: AutofillManager,
+
+ /** @override */
+ addAddressListChangedListener: function(listener) {
+ chrome.autofillPrivate.onAddressListChanged.addListener(listener);
+ },
+
+ /** @override */
+ removeAddressListChangedListener: function(listener) {
+ chrome.autofillPrivate.onAddressListChanged.removeListener(listener);
+ },
+
+ /** @override */
+ getAddressList: function(callback) {
+ chrome.autofillPrivate.getAddressList(callback);
+ },
+
+ /** @override */
+ saveAddress: function(address) {
+ chrome.autofillPrivate.saveAddress(address);
+ },
+
+ /** @override */
+ removeAddress: function(guid) {
+ chrome.autofillPrivate.removeEntry(assert(guid));
+ },
+
+ /** @override */
+ addCreditCardListChangedListener: function(listener) {
+ chrome.autofillPrivate.onCreditCardListChanged.addListener(listener);
+ },
+
+ /** @override */
+ removeCreditCardListChangedListener: function(listener) {
+ chrome.autofillPrivate.onCreditCardListChanged.removeListener(listener);
+ },
+
+ /** @override */
+ getCreditCardList: function(callback) {
+ chrome.autofillPrivate.getCreditCardList(callback);
+ },
+
+ /** @override */
+ removeCreditCard: function(guid) {
+ chrome.autofillPrivate.removeEntry(assert(guid));
+ },
+
+ /** @override */
+ clearCachedCreditCard: function(guid) {
+ chrome.autofillPrivate.maskCreditCard(assert(guid));
+ },
+
+ /** @override */
+ saveCreditCard: function(creditCard) {
+ chrome.autofillPrivate.saveCreditCard(creditCard);
+ }
+};
+
(function() {
'use strict';
@@ -17,7 +156,7 @@
properties: {
/**
* An array of saved addresses.
- * @type {!Array<!chrome.autofillPrivate.AddressEntry>}
+ * @type {!Array<!AutofillManager.AddressEntry>}
*/
addresses: Array,
@@ -32,7 +171,7 @@
/**
* An array of saved credit cards.
- * @type {!Array<!chrome.autofillPrivate.CreditCardEntry>}
+ * @type {!Array<!AutofillManager.CreditCardEntry>}
*/
creditCards: Array,
@@ -46,10 +185,74 @@
showCreditCardDialog_: Boolean,
},
+ listeners: {
+ 'save-address': 'saveAddress_',
+ 'save-credit-card': 'saveCreditCard_',
+ },
+
+ /**
+ * @type {AutofillManager}
+ * @private
+ */
+ autofillManager_: null,
+
+ /**
+ * @type {?function(!Array<!AutofillManager.AddressEntry>)}
+ * @private
+ */
+ setAddressesListener_: null,
+
+ /**
+ * @type {?function(!Array<!AutofillManager.CreditCardEntry>)}
+ * @private
+ */
+ setCreditCardsListener_: null,
+
+ /** @override */
+ ready: function() {
+ // Create listener functions.
+ /** @type {function(!Array<!AutofillManager.AddressEntry>)} */
+ var setAddressesListener = function(list) {
+ this.addresses = list;
+ }.bind(this);
+
+ /** @type {function(!Array<!AutofillManager.CreditCardEntry>)} */
+ var setCreditCardsListener = function(list) {
+ this.creditCards = list;
+ }.bind(this);
+
+ // Remember the bound reference in order to detach.
+ this.setAddressesListener_ = setAddressesListener;
+ this.setCreditCardsListener_ = setCreditCardsListener;
+
+ // Set the managers. These can be overridden by tests.
+ this.autofillManager_ = AutofillManagerImpl.getInstance();
+
+ // Request initial data.
+ this.autofillManager_.getAddressList(setAddressesListener);
+ this.autofillManager_.getCreditCardList(setCreditCardsListener);
+
+ // Listen for changes.
+ this.autofillManager_.addAddressListChangedListener(setAddressesListener);
+ this.autofillManager_.addCreditCardListChangedListener(
+ setCreditCardsListener);
+ },
+
+ /** @override */
+ detached: function() {
+ this.autofillManager_.removeAddressListChangedListener(
+ /** @type {function(!Array<!AutofillManager.AddressEntry>)} */(
+ this.setAddressesListener_));
+ this.autofillManager_.removeCreditCardListChangedListener(
+ /** @type {function(!Array<!AutofillManager.CreditCardEntry>)} */(
+ this.setCreditCardsListener_));
+ },
+
/**
* Formats the expiration date so it's displayed as MM/YYYY.
* @param {!chrome.autofillPrivate.CreditCardEntry} item
* @return {string}
+ * @private
*/
expiration_: function(item) {
return item.expirationMonth + '/' + item.expirationYear;
@@ -113,7 +316,8 @@
* @private
*/
onMenuRemoveAddressTap_: function() {
- this.fire('remove-address', this.activeAddress);
+ this.autofillManager_.removeAddress(
+ /** @type {string} */(this.activeAddress.guid));
this.$.addressSharedMenu.close();
},
@@ -181,7 +385,8 @@
* @private
*/
onMenuRemoveCreditCardTap_: function() {
- this.fire('remove-credit-card', this.activeCreditCard);
+ this.autofillManager_.removeCreditCard(
+ /** @type {string} */(this.activeCreditCard.guid));
this.$.creditCardSharedMenu.close();
},
@@ -190,7 +395,8 @@
* @private
*/
onMenuClearCreditCardTap_: function() {
- this.fire('clear-credit-card', this.activeCreditCard);
+ this.autofillManager_.clearCachedCreditCard(
+ /** @type {string} */(this.activeCreditCard.guid));
this.$.creditCardSharedMenu.close();
},
@@ -203,5 +409,23 @@
hasSome_: function(list) {
return !!(list && list.length);
},
+
+ /**
+ * Listens for the save-address event, and calls the private API.
+ * @param {!Event} event
+ * @private
+ */
+ saveAddress_: function(event) {
+ this.autofillManager_.saveAddress(event.detail);
+ },
+
+ /**
+ * Listens for the save-credit-card event, and calls the private API.
+ * @param {!Event} event
+ * @private
+ */
+ saveCreditCard_: function(event) {
+ this.autofillManager_.saveCreditCard(event.detail);
+ },
});
})();
« no previous file with comments | « no previous file | chrome/browser/resources/settings/passwords_and_forms_page/passwords_and_forms_page.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698