Commit 673b2b68 authored by hcarmona's avatar hcarmona Committed by Commit bot
Browse files

[MD Settings] Add a menu option to clear a cached credit card.

This only applies to credit cards that were imported from Google
Payments and saved locally. Does not delete the credit card info from
the Google Payments servers.

BUG=622174
CQ_INCLUDE_TRYBOTS=tryserver.chromium.linux:closure_compilation

Review-Url: https://codereview.chromium.org/2092323002
Cr-Commit-Position: refs/heads/master@{#402336}
parent f8a9be71
......@@ -254,6 +254,9 @@
<message name="IDS_SETTINGS_CREDIT_CARD_REMOVE" desc="Label for a context menu item that removes the selected credit card." meaning="Remove selected credit card.">
Remove
</message>
<message name="IDS_SETTINGS_CREDIT_CARD_CLEAR" desc="Label for a context menu item clears the locally cached credit card that is also saved on Google Payments. Clicking this will NOT remove the credit card from Google Payments.">
Clear copy
</message>
<message name="IDS_SETTINGS_EDIT_CREDIT_CARD_TITLE" desc="The title for the dialog that's shown when editing a credit card.">
Edit credit card
</message>
......
......@@ -107,6 +107,8 @@
on-tap="onMenuEditCreditCardTap_">$i18n{editCreditCard}</div>
<div id="menuRemoveCreditCard" class="list-item menu-item"
on-tap="onMenuRemoveCreditCardTap_">$i18n{removeCreditCard}</div>
<div id="menuClearCreditCard" class="list-item menu-item"
on-tap="onMenuClearCreditCardTap_">$i18n{clearCreditCard}</div>
</cr-shared-menu>
<settings-credit-card-edit-dialog id="editCreditCardDialog">
</settings-credit-card-edit-dialog>
......
......@@ -119,6 +119,7 @@
var creditCard = /** @type {!chrome.autofillPrivate.CreditCardEntry} */(
menuEvent.model.item);
this.$.menuRemoveCreditCard.hidden = !creditCard.metadata.isLocal;
this.$.menuClearCreditCard.hidden = !creditCard.metadata.isCached;
this.$.creditCardSharedMenu.toggleMenu(
Polymer.dom(e).localTarget, creditCard);
e.stopPropagation(); // Prevent the tap event from closing the menu.
......@@ -167,6 +168,16 @@
menu.closeMenu();
},
/**
* Handles tapping on the "Clear copy" button for cached credit cards.
* @private
*/
onMenuClearCreditCardTap_: function() {
var menu = this.$.creditCardSharedMenu;
this.fire('clear-credit-card', menu.itemData);
menu.closeMenu();
},
/**
* Closes the overflow menus.
* @private
......
......@@ -116,7 +116,7 @@ AutofillManager.prototype = {
*/
getAddressList: assertNotReached,
/** @param {!AutofillManager.AddressEntry} address The address to remove. */
/** @param {string} guid The guid of the address to remove. */
removeAddress: assertNotReached,
/**
......@@ -137,12 +137,12 @@ AutofillManager.prototype = {
*/
getCreditCardList: assertNotReached,
/**
* @param {!AutofillManager.CreditCardEntry} creditCard The credit card to
* remove.
*/
/** @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
......@@ -247,8 +247,9 @@ AutofillManagerImpl.prototype = {
},
/** @override */
removeAddress: function(address) {
chrome.autofillPrivate.removeEntry(/** @type {string} */(address.guid));
removeAddress: function(guid) {
assert(guid);
chrome.autofillPrivate.removeEntry(guid);
},
/** @override */
......@@ -267,8 +268,15 @@ AutofillManagerImpl.prototype = {
},
/** @override */
removeCreditCard: function(creditCard) {
chrome.autofillPrivate.removeEntry(/** @type {string} */(creditCard.guid));
removeCreditCard: function(guid) {
assert(guid);
chrome.autofillPrivate.removeEntry(guid);
},
/** @override */
clearCachedCreditCard: function(guid) {
assert(guid);
chrome.autofillPrivate.maskCreditCard(guid);
},
/** @override */
......@@ -326,6 +334,7 @@ Polymer({
},
listeners: {
'clear-credit-card': 'clearCreditCard_',
'remove-address': 'removeAddress_',
'remove-credit-card': 'removeCreditCard_',
'remove-password-exception': 'removePasswordException_',
......@@ -422,7 +431,7 @@ Polymer({
* @private
*/
removeAddress_: function(event) {
this.autofillManager_.removeAddress(event.detail);
this.autofillManager_.removeAddress(event.detail.guid);
},
/**
......@@ -431,7 +440,16 @@ Polymer({
* @private
*/
removeCreditCard_: function(event) {
this.autofillManager_.removeCreditCard(event.detail);
this.autofillManager_.removeCreditCard(event.detail.guid);
},
/**
* Listens for the clear-credit-card event, and calls the private API.
* @param {!Event} event
* @private
*/
clearCreditCard_: function(event) {
this.autofillManager_.clearCachedCreditCard(event.detail.guid);
},
/**
......
......@@ -688,6 +688,7 @@ void AddPasswordsAndFormsStrings(content::WebUIDataSource* html_source) {
{"addCreditCard", IDS_SETTINGS_AUTOFILL_ADD_CREDIT_CARD_BUTTON},
{"editCreditCard", IDS_SETTINGS_CREDIT_CARD_EDIT},
{"removeCreditCard", IDS_SETTINGS_CREDIT_CARD_REMOVE},
{"clearCreditCard", IDS_SETTINGS_CREDIT_CARD_CLEAR},
{"creditCardType", IDS_SETTINGS_AUTOFILL_CREDIT_CARD_TYPE_COLUMN_LABEL},
{"creditCardExpiration", IDS_SETTINGS_CREDIT_CARD_EXPIRATION_DATE},
{"creditCardName", IDS_SETTINGS_NAME_ON_CREDIT_CARD},
......
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